Antiloveg 8 anni fa
parent
commit
b3a5e0d203

+ 78 - 27
src/main/java/com/goafanti/admin/controller/AdminLectureApiController.java

@@ -18,6 +18,8 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
 import com.goafanti.common.enums.AttachmentType;
+import com.goafanti.common.enums.LectureDynamicType;
+import com.goafanti.common.enums.LectureHotType;
 import com.goafanti.common.enums.PatentInfoFields;
 import com.goafanti.common.model.Lecture;
 import com.goafanti.lecture.bo.InputLecture;
@@ -31,16 +33,40 @@ import com.goafanti.user.service.UserService;
 @RequestMapping(value = "/api/admin/lecture")
 public class AdminLectureApiController extends BaseApiController {
 	@Resource
-	private LectureService lectureService;
+	private LectureService			lectureService;
 	@Resource
-	private UserService userService;
+	private UserService				userService;
+
+	private static final Integer	HOT_MAX_NUM		= 4;
+
+	private static final Integer	DYNAMIC_MAX_NUM	= 9;
+
+	/**
+	 * 大咖说页面展示列表
+	 */
+	@RequestMapping(value = "/hotList", method = RequestMethod.GET)
+	public Result hotList() {
+		Result res = new Result();
+		res.setData(lectureService.listHot());
+		return res;
+	}
 	
 	/**
+	 * 科技明星页面展示列表
+	 */
+	@RequestMapping(value = "/dynamic", method = RequestMethod.GET)
+	public Result dynamic(){
+		Result res = new Result();
+		res.setData(lectureService.listDynamic());
+		return res;
+	}
+
+	/**
 	 * 专家及明星列表
 	 */
-	@RequestMapping(value= "/starAndExpertList", method = RequestMethod.GET)
+	@RequestMapping(value = "/starAndExpertList", method = RequestMethod.GET)
 	public Result starAndExpertList(Integer number, String engagedField, String username, String professionalTitle,
-			String workUnit, String pageNo, String pageSize){
+			String workUnit, String pageNo, String pageSize) {
 		Result res = new Result();
 		Integer pNo = 1;
 		Integer pSize = 10;
@@ -51,7 +77,8 @@ public class AdminLectureApiController extends BaseApiController {
 		if (StringUtils.isNumeric(pageNo)) {
 			pNo = Integer.parseInt(pageNo);
 		}
-		res.setData(userService.listStarAndExpert(number, engagedField, username, professionalTitle, workUnit, pNo, pSize));
+		res.setData(
+				userService.listStarAndExpert(number, engagedField, username, professionalTitle, workUnit, pNo, pSize));
 		return res;
 	}
 
@@ -67,20 +94,10 @@ public class AdminLectureApiController extends BaseApiController {
 			return res;
 		}
 
-		if (StringUtils.isBlank(il.getUid())) {
-			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "讲堂开展人ID"));
-			return res;
-		}
-
-		if (StringUtils.isBlank(il.getName())) {
-			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "讲堂名称"));
+		if (!disposeLecture(res, il, lectureTimeFormattedDate).getError().isEmpty()) {
 			return res;
 		}
 
-		if (StringUtils.isBlank(lectureTimeFormattedDate)) {
-			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "讲堂开展时间"));
-			return res;
-		}
 		Lecture l = new Lecture();
 		BeanUtils.copyProperties(il, l);
 		lectureService.save(l, lectureTimeFormattedDate);
@@ -104,20 +121,10 @@ public class AdminLectureApiController extends BaseApiController {
 			return res;
 		}
 
-		if (StringUtils.isBlank(il.getUid())) {
-			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "讲堂开展人ID"));
-			return res;
-		}
-
-		if (StringUtils.isBlank(il.getName())) {
-			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "讲堂名称"));
+		if (!disposeLecture(res, il, lectureTimeFormattedDate).getError().isEmpty()) {
 			return res;
 		}
 
-		if (StringUtils.isBlank(lectureTimeFormattedDate)) {
-			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "讲堂开展时间"));
-			return res;
-		}
 		Lecture l = new Lecture();
 		BeanUtils.copyProperties(il, l);
 		lectureService.update(l, lectureTimeFormattedDate);
@@ -176,4 +183,48 @@ public class AdminLectureApiController extends BaseApiController {
 		}
 		return res;
 	}
+
+	private Result disposeLecture(Result res, InputLecture il, String lectureTimeFormattedDate) {
+		if (StringUtils.isBlank(il.getUid())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "讲堂开展人ID"));
+			return res;
+		}
+
+		if (StringUtils.isBlank(il.getName())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "讲堂名称"));
+			return res;
+		}
+
+		if (StringUtils.isBlank(lectureTimeFormattedDate)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "讲堂开展时间"));
+			return res;
+		}
+
+		if (null == il.getHot()) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "是否展示在大咖说页面标记"));
+			return res;
+		}
+
+		if (null == il.getDynamic()) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "是否展示在科技明星页面标记"));
+			return res;
+		}
+
+		if (LectureDynamicType.DYNAMIC.getCode().equals(il.getDynamic())) {
+			Integer dynamicNum = lectureService.countDynamicNum();
+			if (null != dynamicNum && DYNAMIC_MAX_NUM == dynamicNum) {
+				res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "展示在科技明星页面数量"));
+				return res;
+			}
+		}
+
+		if (LectureHotType.HOT.getCode().equals(il.getHot())) {
+			Integer hotNum = lectureService.countHotNum();
+			if (null != hotNum && HOT_MAX_NUM == hotNum) {
+				res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "展示在大咖说页面数量"));
+				return res;
+			}
+		}
+		return res;
+	}
 }

+ 9 - 0
src/main/java/com/goafanti/common/dao/LectureMapper.java

@@ -3,6 +3,7 @@ package com.goafanti.common.dao;
 import java.util.List;
 
 import com.goafanti.common.model.Lecture;
+import com.goafanti.lecture.bo.LectureListBo;
 
 public interface LectureMapper {
     int deleteByPrimaryKey(String id);
@@ -18,4 +19,12 @@ public interface LectureMapper {
     int updateByPrimaryKey(Lecture record);
 
 	int batchDeleteByPrimaryKey(List<String> id);
+
+	Integer countDynamicNum();
+
+	Integer countHotNum();
+
+	LectureListBo listHot();
+
+	LectureListBo listDynamic();
 }

+ 53 - 0
src/main/java/com/goafanti/common/enums/LectureDynamicType.java

@@ -0,0 +1,53 @@
+package com.goafanti.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+
+public enum LectureDynamicType {
+	UNDYNAMIC(0, "科技明星页面不展示"), DYNAMIC(1, "科技明星页面展示"), OTHER(2, "其他");
+
+	private LectureDynamicType(Integer code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+
+	private static Map<Integer, LectureDynamicType> status = new HashMap<Integer, LectureDynamicType>();
+
+	static {
+		for (LectureDynamicType value : LectureDynamicType.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+
+	public static LectureDynamicType getStatus(Integer code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+
+	public static LectureDynamicType 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;
+	}
+
+}

+ 53 - 0
src/main/java/com/goafanti/common/enums/LectureHotType.java

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

+ 48 - 0
src/main/java/com/goafanti/common/mapper/LectureMapper.xml

@@ -227,4 +227,52 @@
 	  	 and l.lecture_time <![CDATA[ < ]]> #{endL,jdbcType=TIMESTAMP}
 	  	</if>
   </select>
+  
+  <select id="countHotNum" resultType="java.lang.Integer">
+  	select 
+  		count(1)
+  	from lecture
+  	where hot = 1
+  	and deleted_sign = 0
+  </select>
+  
+   <select id="countDynamicNum" resultType="java.lang.Integer">
+  	select 
+  		count(1)
+  	from lecture
+  	where dynamic = 1
+  	and deleted_sign = 0
+  </select>
+  
+  <select id="listHot" resultType="com.goafanti.lecture.bo.LectureListBo">
+  		select 
+	  		l.id,
+	  		l.uid,
+	  		l.name,
+	  		l.lecture_time as lectureTime,
+	  		l.summary,
+	  		l.lecture_url as lectureUrl,
+	  		ui.username 
+	  	from lecture l
+	  	left join  user_identity ui on ui.uid = l.uid
+	  	where 
+	  		l.deleted_sign = 0
+	  	and l.hot = 1
+  </select>
+  
+   <select id="listDynamic" resultType="com.goafanti.lecture.bo.LectureListBo">
+  		select 
+	  		l.id,
+	  		l.uid,
+	  		l.name,
+	  		l.lecture_time as lectureTime,
+	  		l.summary,
+	  		l.lecture_url as lectureUrl,
+	  		ui.username 
+	  	from lecture l
+	  	left join  user_identity ui on ui.uid = l.uid
+	  	where 
+	  		l.deleted_sign = 0
+	  	and l.dynamic = 1
+  </select>
 </mapper>

+ 26 - 0
src/main/java/com/goafanti/lecture/bo/InputLecture.java

@@ -1,5 +1,7 @@
 package com.goafanti.lecture.bo;
 
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
 import javax.validation.constraints.Size;
 
 import com.goafanti.common.constant.ErrorConstants;
@@ -19,6 +21,14 @@ public class InputLecture {
 
 	@Size(min = 0, max = 255, message = "{" + ErrorConstants.PARAM_SIZE_ERROR + "}")
 	private String	lectureUrl;
+	
+	@Max(value = 1, message = "{" + ErrorConstants.PARAM_ERROR + "}")
+	@Min(value = 0, message = "{" + ErrorConstants.PARAM_ERROR + "}")
+	private Integer	hot;
+	
+	@Max(value = 1, message = "{" + ErrorConstants.PARAM_ERROR + "}")
+	@Min(value = 0, message = "{" + ErrorConstants.PARAM_ERROR + "}")
+	private Integer	dynamic;
 
 	public String getId() {
 		return id;
@@ -60,4 +70,20 @@ public class InputLecture {
 		this.lectureUrl = lectureUrl;
 	}
 
+	public Integer getHot() {
+		return hot;
+	}
+
+	public void setHot(Integer hot) {
+		this.hot = hot;
+	}
+
+	public Integer getDynamic() {
+		return dynamic;
+	}
+
+	public void setDynamic(Integer dynamic) {
+		this.dynamic = dynamic;
+	}
+
 }

+ 8 - 0
src/main/java/com/goafanti/lecture/service/LectureService.java

@@ -17,4 +17,12 @@ public interface LectureService {
 	Pagination<LectureListBo> listLecture(String uid, String username, String name, String startLectureTime, String endLectureTime,
 			Integer pNo, Integer pSize);
 
+	Integer countDynamicNum();
+
+	Integer countHotNum();
+
+	LectureListBo listHot();
+
+	LectureListBo listDynamic();
+
 }

+ 20 - 0
src/main/java/com/goafanti/lecture/service/impl/LectureServiceImpl.java

@@ -95,4 +95,24 @@ public class LectureServiceImpl extends BaseMybatisDao<LectureMapper> implements
 				pageSize);
 	}
 
+	@Override
+	public Integer countDynamicNum() {
+		return lectureMapper.countDynamicNum();
+	}
+
+	@Override
+	public Integer countHotNum() {
+		return lectureMapper.countHotNum();
+	}
+
+	@Override
+	public LectureListBo listHot() {
+		return lectureMapper.listHot();
+	}
+
+	@Override
+	public LectureListBo listDynamic() {
+		return lectureMapper.listDynamic();
+	}
+
 }