Sfoglia il codice sorgente

删除节目时自动删除推荐结果,避免重复添加节目,接口错误时返回消息

yaobo 7 anni fa
parent
commit
279351252a

+ 2 - 0
src/main/java/cn/efunbox/controller/ClickController.java

@@ -66,6 +66,7 @@ public class ClickController {
 		String film_code = request.getParameter("film_code")==null?"":request.getParameter("film_code").trim();
 		if(film_code.isEmpty()){
 			map.put("code", 301);
+			map.put("msg", "film_code参数错误");
 			return map;
 		}
 		
@@ -109,6 +110,7 @@ public class ClickController {
 		Film film = filmService.get(film_code, Integer.valueOf(type));
 		if(film==null){
 			map.put("code", 302);
+			map.put("msg", "film_code或type参数错误,节目不存在");
 			return map;
 		}
 		click.setAge_group(film.getAge_group());

+ 10 - 0
src/main/java/cn/efunbox/controller/FilmController.java

@@ -59,9 +59,11 @@ public class FilmController {
         String type = request.getParameter("type")==null?"1":request.getParameter("type").trim();
 		if(film_code.isEmpty() || type.isEmpty()){
 			map.put("code", 301);
+			map.put("msg", "film_code或type参数错误");
 			return map;
 		}
     	filmService.delete(film_code, Integer.valueOf(type));
+    	recmdService.delete(Integer.valueOf(type), film_code, 0, 0);
         map.put("code", 200);
         return map;
     }
@@ -88,9 +90,17 @@ public class FilmController {
 		String duration = request.getParameter("duration")==null?"0":request.getParameter("duration").trim();
 		if(film_code.isEmpty() || type.isEmpty()){
 			map.put("code", 301);
+			map.put("msg", "film_code或type参数错误");
 			return map;
 		}
 		int curTime = (int)(System.currentTimeMillis()/1000);
+		
+		Film old = filmService.get(film_code, Integer.valueOf(type));
+		if(old!=null){
+			map.put("code", 302);
+			map.put("msg", "节目已存在,不能重复添加");
+			return map;
+		}
 		Film film = new Film();
 		film.setType(Integer.valueOf(type));
 		film.setAge_group(Integer.valueOf(age_group));

+ 6 - 0
src/main/java/cn/efunbox/dao/RecommendMapper.java

@@ -31,6 +31,12 @@ public interface RecommendMapper {
      * @return
      */
 	Recommend get(@Param("age") int age, @Param("sex") int sex, @Param("type") int type, @Param("film_code") String film_code);
+
+    /**
+     * 删除推荐结果
+     * @return
+     */
+	int delete(@Param("type") int type, @Param("film_code") String film_code, @Param("age") int age, @Param("sex") int sex);
 	
     /**
      * 更新一条记录的排序积分

+ 10 - 0
src/main/java/cn/efunbox/mapping/RecommendMapper.xml

@@ -25,6 +25,16 @@
         where age=#{age} and sex=#{sex} and type=#{type} and film_code=#{film_code} limit 1
     </select>
     
+    <!-- 删除推荐结果 -->  
+    <update id="delete">  
+       	delete from film_recmd where 
+       	type=#{type} and film_code=#{film_code}
+       	<set>
+			<if test="null!=age and ''!=age and 0!=age"> and age = #{age }</if>
+			<if test="null!=sex and ''!=sex and 0!=sex"> and sex = #{sex }</if>
+		</set> 
+    </update>
+    
     <!-- 更新一条记录的排序积分 -->  
     <update id="updateScore">  
        	update film_recmd set score=#{score},updated=#{updated} where id=#{id} limit 1

+ 6 - 0
src/main/java/cn/efunbox/service/IRecommendService.java

@@ -32,6 +32,12 @@ public interface IRecommendService {
     Recommend get(int age, int sex, int type, String film_code);
 
     /**
+     * 删除推荐结果
+     * @return
+     */
+	int delete(int type, String film_code, int age, int sex);
+	
+    /**
      * 更新一条记录的排序积分
      * @param 
      */

+ 5 - 0
src/main/java/cn/efunbox/service/impl/RecommendServiceImpl.java

@@ -45,6 +45,11 @@ public class RecommendServiceImpl implements IRecommendService {
 		return recmdMapper.get(age, sex, type, film_code);
 	}
 
+	public int delete(int type, String film_code, int age, int sex) {
+		// TODO Auto-generated method stub
+		return recmdMapper.delete(type, film_code, age, sex);
+	}
+
     /**
      * 更新一条记录的排序积分
      * @param 

+ 2 - 2
src/main/resources/mybatis-spring.xml

@@ -15,9 +15,9 @@
     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
         <!-- 基本属性 url、user、password -->  
         <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
-        <property name="url" value="jdbc:mysql://127.0.0.1:3306/efunbox_recmd" />  
+        <property name="url" value="jdbc:mysql://192.168.1.87:3306/efunbox_recmd" />  
         <property name="username" value="root" />  
-        <property name="password" value="223732" /> 
+        <property name="password" value="admin123" /> 
         <property name="initialSize" value="1" />  
         <property name="minIdle" value="1" />   
         <property name="maxActive" value="20" />