Ver código fonte

大咖说--科技明星

Antiloveg 8 anos atrás
pai
commit
e59457eae4

+ 68 - 1
src/main/java/com/goafanti/admin/controller/AdminStarApiController.java

@@ -4,11 +4,15 @@ import javax.annotation.Resource;
 
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.goafanti.common.bo.Result;
+import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.model.Star;
 import com.goafanti.common.utils.StringUtils;
+import com.goafanti.star.service.StarService;
 import com.goafanti.user.service.UserService;
 
 /**
@@ -18,7 +22,13 @@ import com.goafanti.user.service.UserService;
 @RequestMapping(value = "/api/admin/star")
 public class AdminStarApiController extends BaseApiController {
 	@Resource
-	private UserService userService;
+	private UserService				userService;
+	@Resource
+	private StarService				starService;
+
+	private static final Integer	STAR_MAX_NUM	= 6;
+
+	private static final Integer	HOT_MAX_NUM		= 4;
 
 	/**
 	 * 科技明星列表
@@ -39,4 +49,61 @@ public class AdminStarApiController extends BaseApiController {
 		res.setData(userService.listStar(number, engagedField, username, professionalTitle, workUnit, pNo, pSize));
 		return res;
 	}
+
+	/**
+	 * 大咖说首页展示明星列表
+	 */
+	@RequestMapping(value = "/hotList", method = RequestMethod.GET)
+	public Result hotList() {
+		Result res = new Result();
+		res.setData(starService.listHotStar());
+		return res;
+	}
+
+	/**
+	 * 科技明星页面展示列表
+	 */
+	@RequestMapping(value = "/starList", method = RequestMethod.GET)
+	public Result starList() {
+		Result res = new Result();
+		res.setData(starService.listStarList());
+		return res;
+	}
+
+	/**
+	 * 保存展示科技明星
+	 */
+	@RequestMapping(value = "/save", method = RequestMethod.POST)
+	public Result save(@RequestParam(name = "star[]", required = false) Star[] star,
+			@RequestParam(name = "hot[]", required = false) String[] hot) {
+		Result res = new Result();
+		if (null == star || star.length < 1) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "科技明星列表"));
+			return res;
+		}
+
+		if (null == hot || hot.length < 1) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "大咖说科技明星列表"));
+			return res;
+		}
+
+		if (star.length > STAR_MAX_NUM) {
+			res.getError().add(buildError("", "科技明星数量过多!"));
+			return res;
+		}
+
+		if (hot.length > HOT_MAX_NUM) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "大咖说科技明星数量过多!"));
+			return res;
+		}
+
+		for (Star s : star) {
+			if (StringUtils.isBlank(s.getUid())) {
+				res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "科技明星ID"));
+				return res;
+			}
+		}
+		starService.save(star, hot);
+		return res;
+	}
 }

+ 28 - 0
src/main/java/com/goafanti/common/dao/StarMapper.java

@@ -0,0 +1,28 @@
+package com.goafanti.common.dao;
+
+import java.util.List;
+
+import com.goafanti.common.model.Star;
+import com.goafanti.star.bo.HotStarListBo;
+
+public interface StarMapper {
+    int deleteByPrimaryKey(String id);
+
+    int insert(Star record);
+
+    int insertSelective(Star record);
+
+    Star selectByPrimaryKey(String id);
+
+    int updateByPrimaryKeySelective(Star record);
+
+    int updateByPrimaryKey(Star record);
+
+	List<HotStarListBo> listHostStar();
+
+	List<HotStarListBo> listStarList();
+
+	void deleteAll();
+
+	void insertBatch(List<Star> startList);
+}

+ 52 - 0
src/main/java/com/goafanti/common/enums/StarHotType.java

@@ -0,0 +1,52 @@
+package com.goafanti.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+
+public enum StarHotType {
+	UNHOT(0, "大咖说页面不展示"), HOT(1, "大咖说页面展示"), OTHER(2, "其他");
+
+	private StarHotType(Integer code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+
+	private static Map<Integer, StarHotType> status = new HashMap<Integer, StarHotType>();
+
+	static {
+		for (StarHotType value : StarHotType.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+
+	public static StarHotType getStatus(Integer code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+
+	public static StarHotType getStatus(String code) {
+		if (StringUtils.isNumeric(code)) {
+			return getStatus(Integer.parseInt(code));
+		}
+		return OTHER;
+	}
+
+	public static boolean containsType(Integer code) {
+		return status.containsKey(code);
+	}
+
+	private Integer	code;
+	private String	desc;
+
+	public Integer getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+}

+ 142 - 0
src/main/java/com/goafanti/common/mapper/StarMapper.xml

@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.goafanti.common.dao.StarMapper" >
+  <resultMap id="BaseResultMap" type="com.goafanti.common.model.Star" >
+    <id column="id" property="id" jdbcType="VARCHAR" />
+    <result column="uid" property="uid" jdbcType="VARCHAR" />
+    <result column="hot" property="hot" jdbcType="INTEGER" />
+    <result column="star" property="star" jdbcType="INTEGER" />
+    <result column="portal_url" property="portalUrl" jdbcType="VARCHAR" />
+  </resultMap>
+  <sql id="Base_Column_List" >
+    id, uid, hot, star, portal_url
+  </sql>
+  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
+    select 
+    <include refid="Base_Column_List" />
+    from star
+    where id = #{id,jdbcType=VARCHAR}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
+    delete from star
+    where id = #{id,jdbcType=VARCHAR}
+  </delete>
+  <insert id="insert" parameterType="com.goafanti.common.model.Star" >
+    insert into star (id, uid, hot, 
+      star, portal_url)
+    values (#{id,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, #{hot,jdbcType=INTEGER}, 
+      #{star,jdbcType=INTEGER}, #{portalUrl,jdbcType=VARCHAR})
+  </insert>
+  <insert id="insertSelective" parameterType="com.goafanti.common.model.Star" >
+    insert into star
+    <trim prefix="(" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        id,
+      </if>
+      <if test="uid != null" >
+        uid,
+      </if>
+      <if test="hot != null" >
+        hot,
+      </if>
+      <if test="star != null" >
+        star,
+      </if>
+      <if test="portalUrl != null" >
+        portal_url,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        #{id,jdbcType=VARCHAR},
+      </if>
+      <if test="uid != null" >
+        #{uid,jdbcType=VARCHAR},
+      </if>
+      <if test="hot != null" >
+        #{hot,jdbcType=INTEGER},
+      </if>
+      <if test="star != null" >
+        #{star,jdbcType=INTEGER},
+      </if>
+      <if test="portalUrl != null" >
+        #{portalUrl,jdbcType=VARCHAR},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.Star" >
+    update star
+    <set >
+      <if test="uid != null" >
+        uid = #{uid,jdbcType=VARCHAR},
+      </if>
+      <if test="hot != null" >
+        hot = #{hot,jdbcType=INTEGER},
+      </if>
+      <if test="star != null" >
+        star = #{star,jdbcType=INTEGER},
+      </if>
+      <if test="portalUrl != null" >
+        portal_url = #{portalUrl,jdbcType=VARCHAR},
+      </if>
+    </set>
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.Star" >
+    update star
+    set uid = #{uid,jdbcType=VARCHAR},
+      hot = #{hot,jdbcType=INTEGER},
+      star = #{star,jdbcType=INTEGER},
+      portal_url = #{portalUrl,jdbcType=VARCHAR}
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  
+  <select id="listHostStar"  resultType="com.goafanti.star.bo.HotStarListBo">
+  	select
+  		u.id as uid,
+  		u.number,
+  		ui.username,
+  		uc.engaged_field as engagedField,
+  		uc.professional_title as professionalTitle,
+  		uc.work_unit as workUnit,
+  		adc.achievement_count as achievementNum
+  	from star s
+  	left join user u on u.id = s.uid
+  	left join user_identity ui on ui.uid = s.uid
+  	left join user_career uc on uc.uid = s.uid
+  	left join achievement_demand_count adc on adc.uid = s.uid 
+  	where s.hot = 1 and ui.celebrity = 1
+  </select>
+  
+  <select id="listStarList"  resultType="com.goafanti.star.bo.HotStarListBo">
+  	select
+  		u.id as uid,
+  		u.number,
+  		ui.username,
+  		uc.engaged_field as engagedField,
+  		uc.professional_title as professionalTitle,
+  		uc.work_unit as workUnit,
+  		adc.achievement_count as achievementNum
+  	from star s
+  	left join user u on u.id = s.uid
+  	left join user_identity ui on ui.uid = s.uid
+  	left join user_career uc on uc.uid = s.uid
+  	left join achievement_demand_count adc on adc.uid = s.uid 
+  	where s.star = 1 and ui.celebrity = 1
+  </select>
+  
+  <delete id="deleteAll">
+  	delete from star
+  </delete>
+  
+   <insert id="insertBatch" parameterType="com.goafanti.common.model.Star">
+    insert into star (id, uid, hot, star, portal_url)
+    values 
+    <foreach item="item" index="index" collection="list" separator=",">
+      (
+      	#{item.id,jdbcType=VARCHAR}, #{item.uid,jdbcType=VARCHAR}, #{item.hot,jdbcType=INTEGER},
+      	#{item.star,jdbcType=INTEGER}, #{item.portalUrl,jdbcType=VARCHAR}
+      )
+    </foreach>
+  </insert>
+</mapper>

+ 5 - 0
src/main/java/com/goafanti/common/mapper/UserMapper.xml

@@ -829,6 +829,11 @@
   	<if test="workUnit != null">
   		and uc.work_unit like CONCAT('%',#{workUnit,jdbcType=VARCHAR},'%')
   	</if>
+  	ORDER BY adc.achievement_count DESC
+	<if test="page_sql!=null">
+		${page_sql}
+	</if>
+  	
   </select>
   
   <select id="findStarCount" parameterType="String" resultType="java.lang.Integer">

+ 65 - 0
src/main/java/com/goafanti/common/model/Star.java

@@ -0,0 +1,65 @@
+package com.goafanti.common.model;
+
+public class Star {
+    private String id;
+
+    /**
+    * 明星用户ID
+    */
+    private String uid;
+
+    /**
+    * 是否在首页显示(0--否,1--是)
+    */
+    private Integer hot;
+
+    /**
+    * 是否在科技明星页显示(0--不显示,1--显示)
+    */
+    private Integer star;
+
+    /**
+    * 个人主页URL
+    */
+    private String portalUrl;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getUid() {
+        return uid;
+    }
+
+    public void setUid(String uid) {
+        this.uid = uid;
+    }
+
+    public Integer getHot() {
+        return hot;
+    }
+
+    public void setHot(Integer hot) {
+        this.hot = hot;
+    }
+
+    public Integer getStar() {
+        return star;
+    }
+
+    public void setStar(Integer star) {
+        this.star = star;
+    }
+
+    public String getPortalUrl() {
+        return portalUrl;
+    }
+
+    public void setPortalUrl(String portalUrl) {
+        this.portalUrl = portalUrl;
+    }
+}

+ 7 - 0
src/main/java/com/goafanti/star/bo/HotStarListBo.java

@@ -0,0 +1,7 @@
+package com.goafanti.star.bo;
+
+import com.goafanti.user.bo.StarListBo;
+
+public class HotStarListBo extends StarListBo{
+
+}

+ 17 - 0
src/main/java/com/goafanti/star/service/StarService.java

@@ -0,0 +1,17 @@
+package com.goafanti.star.service;
+
+import java.util.List;
+
+import com.goafanti.common.model.Star;
+import com.goafanti.star.bo.HotStarListBo;
+
+
+public interface StarService {
+
+	List<HotStarListBo> listHotStar();
+
+	List<HotStarListBo> listStarList();
+
+	void save(Star[] star, String[] hot);
+
+}

+ 43 - 0
src/main/java/com/goafanti/star/service/impl/StarServiceImpl.java

@@ -0,0 +1,43 @@
+package com.goafanti.star.service.impl;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.goafanti.common.dao.StarMapper;
+import com.goafanti.common.enums.StarHotType;
+import com.goafanti.common.model.Star;
+import com.goafanti.star.bo.HotStarListBo;
+import com.goafanti.star.service.StarService;
+@Service
+public class StarServiceImpl implements StarService {
+	@Autowired
+	private StarMapper starMapper;
+	@Override
+	public List<HotStarListBo> listHotStar() {
+		return starMapper.listHostStar();
+	}
+	@Override
+	public List<HotStarListBo> listStarList() {
+		return starMapper.listStarList();
+	}
+	@Override
+	public void save(Star[] star, String[] hot) {
+		starMapper.deleteAll();
+		List<Star> startList = Arrays.asList(star);
+		List<String> hotList = Arrays.asList(hot);
+		for (Star s : startList){
+			s.setId(UUID.randomUUID().toString());
+			for (String h : hotList){
+				if (s.getUid().equals(h)){
+					s.setHot(StarHotType.HOT.getCode());
+				}
+			}
+		}
+		starMapper.insertBatch(startList);
+	}
+
+}