Parcourir la source

feat:长三角比赛

Joburgess il y a 5 ans
Parent
commit
714fcf4bd5

+ 11 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentCompetitionDao.java

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 public interface StudentCompetitionDao extends BaseDAO<Long, StudentCompetition> {
 
@@ -29,5 +30,14 @@ public interface StudentCompetitionDao extends BaseDAO<Long, StudentCompetition>
      * @return java.util.List<com.ym.mec.biz.dal.dto.StudentCompetitionRankingDto>
      */
     List<StudentCompetition> getWinnerList();
-	
+
+    /**
+     * @describe 获取指定奖项级别的作品编号列表
+     * @author Joburgess
+     * @date 2020.11.10
+     * @param prizeLevel:
+     * @return java.util.Set<java.lang.Long>
+     */
+    Set<Long> getCompetitionsWithPrizeLevel(@Param("prizeLevel") Integer prizeLevel);
+
 }

+ 8 - 8
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentCompetition.java

@@ -44,7 +44,7 @@ public class StudentCompetition {
 	private java.math.BigDecimal score;
 
 	@ApiModelProperty(value = "获奖等级")
-	private java.math.BigDecimal prizeLevel;
+	private Integer prizeLevel;
 
 	@ApiModelProperty(value = "是否展示")
 	private boolean isShow;
@@ -159,15 +159,15 @@ public class StudentCompetition {
 	public java.math.BigDecimal getScore(){
 		return this.score;
 	}
-			
-	public void setPrizeLevel(java.math.BigDecimal prizeLevel){
-		this.prizeLevel = prizeLevel;
+
+	public Integer getPrizeLevel() {
+		return prizeLevel;
 	}
-	
-	public java.math.BigDecimal getPrizeLevel(){
-		return this.prizeLevel;
+
+	public void setPrizeLevel(Integer prizeLevel) {
+		this.prizeLevel = prizeLevel;
 	}
-			
+
 	public void setIsShow(boolean isShow){
 		this.isShow = isShow;
 	}

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentCompetitionService.java

@@ -30,4 +30,13 @@ public interface StudentCompetitionService extends BaseService<Long, StudentComp
     List<StudentCompetitionRankingDto> getWinnerList();
 
     StudentCompetition checkIsUpload(Integer userId);
+
+    /**
+     * @describe 更新参赛作品信息
+     * @author Joburgess
+     * @date 2020.11.10
+     * @param studentCompetition:
+     * @return void
+     */
+    void updateCompetition(StudentCompetition studentCompetition);
 }

+ 27 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentCompetitionServiceImpl.java

@@ -86,4 +86,31 @@ public class StudentCompetitionServiceImpl extends BaseServiceImpl<Long, Student
 		}
 		return winnerSimpleInfoList;
 	}
+
+	@Override
+	public void updateCompetition(StudentCompetition studentCompetition) {
+		if(Objects.nonNull(studentCompetition.getPrizeLevel())){
+			Set<Long> competitionsWithPrizeLevel = studentCompetitionDao.getCompetitionsWithPrizeLevel(studentCompetition.getPrizeLevel());
+			int maxPrizeLevelUserNum = 0;
+			switch (studentCompetition.getPrizeLevel()){
+				case 0:
+					maxPrizeLevelUserNum = 1;
+					break;
+				case 1:
+				case 2:
+					maxPrizeLevelUserNum = 12;
+					break;
+				case 3:
+					maxPrizeLevelUserNum = 24;
+					break;
+				case 4:
+					maxPrizeLevelUserNum = 50;
+					break;
+			}
+			if(competitionsWithPrizeLevel.size()>=maxPrizeLevelUserNum&&!competitionsWithPrizeLevel.contains(studentCompetition.getId())){
+				throw new BizException("该奖项名额已达上线");
+			}
+		}
+		studentCompetitionDao.update(studentCompetition);
+	}
 }

+ 4 - 0
mec-biz/src/main/resources/config/mybatis/StudentCompetitionMapper.xml

@@ -155,4 +155,8 @@
 	<select id="getCompetitionWithUser" resultMap="StudentCompetition">
 		SELECT * FROM student_competition WHERE user_id_ = #{userId}
 	</select>
+
+	<select id="getCompetitionsWithPrizeLevel" resultType="long">
+		SELECT id_ FROM student_competition WHERE prize_level_ = #{prizeLevel} FOR UPDATE
+	</select>
 </mapper>

+ 7 - 1
mec-web/src/main/java/com/ym/mec/web/controller/StudentCompetitionController.java

@@ -5,6 +5,7 @@ import com.ym.mec.biz.dal.page.StudentCompetitionQueryInfo;
 import com.ym.mec.biz.service.StudentCompetitionService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
+import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -15,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Objects;
+
 /**
  * @Author Joburgess
  * @Date 2020.11.10
@@ -37,7 +40,10 @@ public class StudentCompetitionController extends BaseController {
     @PostMapping("/update")
     @PreAuthorize("@pcs.hasPermissions('studentCompetition/update')")
     public HttpResponseResult update(@RequestBody StudentCompetition studentCompetition){
-        studentCompetitionService.update(studentCompetition);
+        if(Objects.isNull(studentCompetition.getId())){
+            throw new BizException("请指定参赛作品");
+        }
+        studentCompetitionService.updateCompetition(studentCompetition);
         return succeed();
     }