Browse Source

创建节目、搜索推荐时,支持限定年龄、节目标签,如经典、热门

yaobo 6 years ago
parent
commit
683a658c66

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

@@ -123,6 +123,7 @@ public class ClickController {
 		click.setLanguage(film.getLanguage());
 		click.setMark_type(film.getMark_type());
 		click.setMovie_type(film.getMovie_type());
+		click.setMovie_tag(film.getMovie_tag());
 		click.setOnline_date(film.getOnline_date());
 		click.setPublish_date(film.getPublish_date());
 		click.setSeries_count(film.getSeries_count());

+ 6 - 2
src/main/java/cn/efunbox/controller/FilmController.java

@@ -85,6 +85,7 @@ public class FilmController {
 		String online_date = request.getParameter("online_date")==null?"0":request.getParameter("online_date").trim();
 		String area = request.getParameter("area")==null?"0":request.getParameter("area").trim();
 		String movie_type = request.getParameter("movie_type")==null?"0":request.getParameter("movie_type").trim();
+		String movie_tag = request.getParameter("movie_tag")==null?"":request.getParameter("movie_tag").trim();
 		String target_people = request.getParameter("target_people")==null?"0":request.getParameter("target_people").trim();
 		String language = request.getParameter("language")==null?"0":request.getParameter("language").trim();
 		String duration = request.getParameter("duration")==null?"0":request.getParameter("duration").trim();
@@ -115,6 +116,7 @@ public class FilmController {
 		film.setLanguage(Integer.valueOf(language));
 		film.setMark_type(Integer.valueOf(mark_type));
 		film.setMovie_type(Integer.valueOf(movie_type));
+		film.setMovie_tag(movie_tag);
 		film.setOnline_date(Integer.valueOf(online_date));
 		film.setPublish_date(Integer.valueOf(publish_date));
 		film.setSeries_count(Integer.valueOf(series_count));
@@ -128,6 +130,8 @@ public class FilmController {
 			recmd.setAge(age);
 			recmd.setCreated(curTime);
 			recmd.setFilm_code(film_code);
+			recmd.setAge_group(Integer.valueOf(age_group));
+			recmd.setMovie_tag(movie_tag);
 			recmd.setScore(score);
 			recmd.setSex(1);
 			recmd.setType(Integer.valueOf(type));
@@ -148,8 +152,8 @@ public class FilmController {
     	score += film.getMark_type()==1?5:0;				//最多5分
 		score += film.getFilm_type()==1?5:0;				//5
 		score += film.getIs_vip()==1?5:0;					//5
-		score += 3 * Math.ceil(Float.valueOf(film.getFilm_grade()));//15
-		score += 2 * Math.ceil(Float.valueOf(film.getFilm_star()));	//10
+		score += 1 * Math.ceil(Float.valueOf(film.getFilm_grade()));//10
+		score += 1 * Math.ceil(Float.valueOf(film.getFilm_star()));	//10
 		int ageDis =  age - film.getAge_group();
 		if(ageDis==0)
 			ageDis = 1;

+ 5 - 2
src/main/java/cn/efunbox/controller/RecommendController.java

@@ -65,11 +65,14 @@ public class RecommendController {
 		String typeStr = request.getParameter("type")==null?"1":request.getParameter("type").trim();
 		String pageStr = request.getParameter("page")==null?"1":request.getParameter("page").trim();
 		String sizeStr = request.getParameter("size")==null?"10":request.getParameter("size").trim();
-		int age = Integer.valueOf(ageStr);
+        String age_groupStr = request.getParameter("age_group")==null?"0":request.getParameter("age_group").trim();
+        String movie_tag = request.getParameter("movie_tag")==null?"":request.getParameter("movie_tag").trim();
+        int age = Integer.valueOf(ageStr);
 		int sex = Integer.valueOf(sexStr);
 		int type = Integer.valueOf(typeStr);
 		int page = Integer.valueOf(pageStr);
 		int size = Integer.valueOf(sizeStr);
+        int age_group = Integer.valueOf(age_groupStr);
 		if(age<0 || age>20)
 			age = 5;
 		if(sex!=1 && sex!=0)
@@ -79,7 +82,7 @@ public class RecommendController {
 		if(size<10)
 			size = 10;
 		int offset = Math.max(0, (page-1)) * size;
-        List<Map> rows = recmdService.search(age, sex, type, size, offset);
+        List<Map> rows = recmdService.search(age, sex, type, size, offset, age_group, movie_tag);
         Map<String, Object> map = new HashMap<String, Object>(2);
         map.put("code", 200);
         map.put("rows", rows);

+ 1 - 1
src/main/java/cn/efunbox/dao/RecommendMapper.java

@@ -25,7 +25,7 @@ public interface RecommendMapper {
      * 搜索
      * @return
      */
-	List<Map> search(@Param("age") int age, @Param("sex") int sex, @Param("type") int type, @Param("limit") int limit, @Param("offset") int offset);
+	List<Map> search(@Param("age") int age, @Param("sex") int sex, @Param("type") int type, @Param("limit") int limit, @Param("offset") int offset, @Param("age_group") int age_group, @Param("movie_tag") String movie_tag);
 
     /**
      * 搜索单个

+ 11 - 2
src/main/java/cn/efunbox/model/Click.java

@@ -23,12 +23,13 @@ public class Click {
     private int publish_date;//发行时间
     private int online_date;//上线时间
     private int area;		//地区
-    private int movie_type;	//类型
+    private int movie_type;	//类型,如经典、搞笑、奇幻等标签
+	private String movie_tag;	//类型,与movie_type对应的字符串标签
     private int target_people;//适合人群
     private int language;	//语言
     private int duration;	//电影时长,分钟
     private int created;	//创建时间
-    
+
     /*
      CREATE TABLE `film_click` (
                   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一编号',
@@ -47,6 +48,7 @@ public class Click {
                   `online_date` int(10) DEFAULT '0' COMMENT '上线时间',
                   `area` int(5) DEFAULT '0' COMMENT '地区',
                   `movie_type` int(5) DEFAULT '0' COMMENT '类型',
+                  `movie_tag` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '类型,与movie_type对应的字符串标签',
                   `target_people` int(5) DEFAULT '0' COMMENT '适合人群',
                   `language` int(5) DEFAULT '0' COMMENT '语言',
                   `duration` int(5) DEFAULT '0' COMMENT '电影时长,分钟',
@@ -268,6 +270,13 @@ public class Click {
 		this.movie_type = movie_type;
 	}
 
+	public String getMovie_tag() {
+		return movie_tag;
+	}
+
+	public void setMovie_tag(String movie_tag) {
+		this.movie_tag = movie_tag;
+	}
 	/**
 	 * @return the target_people
 	 */

+ 11 - 2
src/main/java/cn/efunbox/model/Film.java

@@ -21,12 +21,13 @@ public class Film {
     private int publish_date;//发行时间
     private int online_date;//上线时间
     private int area;		//地区
-    private int movie_type;	//类型
+    private int movie_type;	//类型,如经典、搞笑、奇幻等标签
+	private String movie_tag;	//类型,与movie_type对应的字符串标签
     private int target_people;//适合人群
     private int language;	//语言
     private int duration;	//电影时长,分钟
     private int created;	//创建时间
-    
+
     /*
      CREATE TABLE `film_info` (
                   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一编号',
@@ -43,6 +44,7 @@ public class Film {
                   `online_date` int(10) DEFAULT '0' COMMENT '上线时间',
                   `area` int(5) DEFAULT '0' COMMENT '地区',
                   `movie_type` int(5) DEFAULT '0' COMMENT '类型',
+                  `movie_tag` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '类型,与movie_type对应的字符串标签',
                   `target_people` int(5) DEFAULT '0' COMMENT '适合人群',
                   `language` int(5) DEFAULT '0' COMMENT '语言',
                   `duration` int(5) DEFAULT '0' COMMENT '电影时长,分钟',
@@ -235,6 +237,13 @@ public class Film {
 		this.movie_type = movie_type;
 	}
 
+	public String getMovie_tag() {
+		return movie_tag;
+	}
+
+	public void setMovie_tag(String movie_tag) {
+		this.movie_tag = movie_tag;
+	}
 	/**
 	 * @return the target_people
 	 */

+ 20 - 1
src/main/java/cn/efunbox/model/Recommend.java

@@ -14,12 +14,14 @@ public class Recommend {
     private int age;		//年龄:1-99
     private int sex;		//性别:1为男,0为女
     private String film_code;//电影编号
+	private int age_group;	//适用年龄段
+	private String movie_tag;//类型,与movie_type对应的字符串标签
     private int times;		//点击次数
     private int score;		//排序得分
     private int status;		//是否显示:1为显示,-1为隐藏
     private int updated;	//上次更新排序时间
     private int created;	//创建时间
-    
+
     /*
      CREATE TABLE `film_recmd` (
                   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '唯一编号',
@@ -27,6 +29,8 @@ public class Recommend {
                   `age` int(5) DEFAULT '5' COMMENT '年龄:1-99',
                   `sex` int(2) DEFAULT '1' COMMENT '性别:1为男,2为女',
                   `film_code` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '电影编号',
+                  `age_group` int(5) DEFAULT '0' COMMENT '适用年龄段',
+                  `movie_tag` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '类型,与movie_type对应的字符串标签',
                   `times` int(10) DEFAULT '1' COMMENT '点击次数',
                   `score` int(10) DEFAULT '1' COMMENT '排序得分',
                   `status` int(5) DEFAULT '1' COMMENT '是否显示:1为显示,-1为隐藏',
@@ -117,6 +121,21 @@ public class Recommend {
 		this.film_code = film_code;
 	}
 
+	public int getAge_group() {
+		return age_group;
+	}
+
+	public void setAge_group(int age_group) {
+		this.age_group = age_group;
+	}
+
+	public String getMovie_tag() {
+		return movie_tag;
+	}
+
+	public void setMovie_tag(String movie_tag) {
+		this.movie_tag = movie_tag;
+	}
 
 	/**
 	 * @return the times

+ 1 - 1
src/main/java/cn/efunbox/service/IRecommendService.java

@@ -24,7 +24,7 @@ public interface IRecommendService {
      * 搜索特定年龄、性别的推荐节目
      * @return
      */
-    List<Map> search(int age, int sex, int type, int limit, int offset);
+    List<Map> search(int age, int sex, int type, int limit, int offset, int age_group, String movie_tag);
 
     /**
      * 搜索单个推荐节目

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

@@ -35,9 +35,9 @@ public class RecommendServiceImpl implements IRecommendService {
 		return recmdMapper.queryAll();
 	}
 
-	public List<Map> search(int age, int sex, int type, int limit, int offset) {
+	public List<Map> search(int age, int sex, int type, int limit, int offset, int age_group, String movie_tag) {
 		// TODO Auto-generated method stub
-		return recmdMapper.search(age, sex, type, limit, offset);
+		return recmdMapper.search(age, sex, type, limit, offset, age_group, movie_tag);
 	}
 
 	public Recommend get(int age, int sex, int type, String film_code) {

+ 3 - 3
src/main/java/cn/efunbox/mapping/ClickMapper.xml

@@ -3,12 +3,12 @@
 <mapper namespace="cn.efunbox.dao.ClickMapper">
     <!-- 查询所有结果 -->  
      <insert id="insert">
-		insert into film_click(type,age,sex,film_code,film_type,mark_type,is_vip,film_grade,film_star,age_group,series_count,publish_date,online_date,area,movie_type,target_people,language,duration,created) 
-		values(#{type},#{age},#{sex},#{film_code},#{film_type},#{mark_type},#{is_vip},#{film_grade},#{film_star},#{age_group},#{series_count},#{publish_date},#{online_date},#{area},#{movie_type},#{target_people},#{language},#{duration},#{created}) 
+		insert into film_click(type,age,sex,film_code,film_type,mark_type,is_vip,film_grade,film_star,age_group,series_count,publish_date,online_date,area,movie_type,movie_tag,target_people,language,duration,created)
+		values(#{type},#{age},#{sex},#{film_code},#{film_type},#{mark_type},#{is_vip},#{film_grade},#{film_star},#{age_group},#{series_count},#{publish_date},#{online_date},#{area},#{movie_type},#{movie_tag},#{target_people},#{language},#{duration},#{created})
 	</insert>
      
     <!-- 查询所有结果 -->  
-    <select id="queryAll" resultType="Click" >  
+    <select id="queryAll" resultType="cn.efunbox.model.Click" >
         select * from film_click 
     </select>
     

+ 4 - 4
src/main/java/cn/efunbox/mapping/FilmMapper.xml

@@ -3,12 +3,12 @@
 <mapper namespace="cn.efunbox.dao.FilmMapper">
     <!-- 新增 -->  
      <insert id="insert">
-		insert into film_info(type,film_code,film_type,mark_type,is_vip,film_grade,film_star,age_group,series_count,publish_date,online_date,area,movie_type,target_people,language,duration,created) 
-		values(#{type},#{film_code},#{film_type},#{mark_type},#{is_vip},#{film_grade},#{film_star},#{age_group},#{series_count},#{publish_date},#{online_date},#{area},#{movie_type},#{target_people},#{language},#{duration},#{created}) 
+		insert into film_info(type,film_code,film_type,mark_type,is_vip,film_grade,film_star,age_group,series_count,publish_date,online_date,area,movie_type,movie_tag,target_people,language,duration,created)
+		values(#{type},#{film_code},#{film_type},#{mark_type},#{is_vip},#{film_grade},#{film_star},#{age_group},#{series_count},#{publish_date},#{online_date},#{area},#{movie_type},#{movie_tag},#{target_people},#{language},#{duration},#{created})
 	</insert>
     
     <!-- 查询 -->  
-    <select id="queryAll" resultType="Film" >  
+    <select id="queryAll" resultType="cn.efunbox.model.Film" >
         select * from film_info
     </select>
     
@@ -18,7 +18,7 @@
     </select>
     
     <!-- 搜索 -->  
-    <select id="get" resultType="Film" >  
+    <select id="get" resultType="cn.efunbox.model.Film" >
         select * from film_info where film_code=#{film_code} and type=#{type} limit 1 
     </select>
     

+ 1 - 1
src/main/java/cn/efunbox/mapping/PersonMapper.xml

@@ -2,7 +2,7 @@
  <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.efunbox.dao.PersonMapper">
     <!-- 查询所有person -->  
-    <select id="queryAll" resultType="Person" >  
+    <select id="queryAll" resultType="cn.efunbox.model.Person" >
         select * from person  
     </select>
 </mapper> 

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

@@ -3,24 +3,26 @@
 <mapper namespace="cn.efunbox.dao.RecommendMapper">
 	<!-- 新增 -->  
      <insert id="insert">
-		insert into film_recmd(type,age,sex,film_code,score,created) 
-		values(#{type},#{age},#{sex},#{film_code},#{score},#{created}) 
+		insert into film_recmd(type,age,sex,film_code,age_group,movie_tag,score,created)
+		values(#{type},#{age},#{sex},#{film_code},#{age_group},#{movie_tag},#{score},#{created})
 	</insert>
    
     <!-- 查询所有结果 -->  
-    <select id="queryAll" resultType="Recommend" >  
+    <select id="queryAll" resultType="cn.efunbox.model.Recommend" >
         select * from film_recmd  
     </select>
-     
+
     <!-- 搜索 -->  
     <select id="search" resultType="Map" >  
-        select id,age,sex,type,film_code,times,score from film_recmd 
+        select id,age,sex,type,film_code,age_group,movie_tag,times,score from film_recmd
         where age=#{age} and sex=#{sex} and type=#{type}
-		order by score desc limit #{limit} offset #{offset}
+        <if test="null!=age_group and ''!=age_group and 0!=age_group"> and age_group &lt;= #{age_group }</if>
+        <if test="null!=movie_tag and ''!=movie_tag "> and movie_tag like concat(concat('%',#{movie_tag}),'%')</if>
+        order by score desc limit #{limit} offset #{offset}
     </select>
-    
+
     <!-- 搜索 -->  
-    <select id="get" resultType="Recommend" >  
+    <select id="get" resultType="cn.efunbox.model.Recommend" >
         select * from film_recmd 
         where age=#{age} and sex=#{sex} and type=#{type} and film_code=#{film_code} limit 1
     </select>
@@ -29,10 +31,8 @@
     <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> 
+		<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>
     </update>
     
     <!-- 更新一条记录的排序积分 -->  

+ 1 - 7
src/main/resources/mybatis-config.xml

@@ -10,11 +10,5 @@
          <typeAlias type="cn.efunbox.model.Recommend" alias="Recommend"/> 
          <typeAlias type="cn.efunbox.model.Click" alias="Click"/>   
          <typeAlias type="cn.efunbox.model.Film" alias="Film"/>  
-    </typeAliases>     
-      <mappers>  
-        <mapper resource="cn/efunbox/mapping/PersonMapper.xml" />  
-        <mapper resource="cn/efunbox/mapping/RecommendMapper.xml" />  
-        <mapper resource="cn/efunbox/mapping/ClickMapper.xml" />  
-        <mapper resource="cn/efunbox/mapping/FilmMapper.xml" />  
-    </mappers>
+    </typeAliases>
 </configuration>

+ 4 - 4
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://192.168.1.87: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="admin123" /> 
+        <property name="password" value="admin123" />
         <property name="initialSize" value="1" />  
         <property name="minIdle" value="1" />   
         <property name="maxActive" value="20" />  
@@ -42,10 +42,10 @@
 
     <!-- Mybatis文件 -->
     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
-        <property name="configLocation" value="classpath:mybatis-config.xml" /> 
+        <property name="configLocation" value="classpath:mybatis-config.xml" />
         <property name="dataSource" ref="dataSource" />
         <!-- 映射文件路径 -->
-        <!--  <property name="mapperLocations" value="cn/efunbox/mapping/*.xml" />-->
+        <property name="mapperLocations" value="classpath*:dbmappers/*.xml" />
     </bean>
 
     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">