Joburgess 5 years ago
parent
commit
d46c125c35

+ 0 - 3
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/ExamSongController.java

@@ -48,9 +48,6 @@ public class ExamSongController extends BaseController {
     @ApiOperation("新增曲库")
     @PostMapping(value = "/add")
     public HttpResponseResult add(ExamSong examSong) {
-        if(StringUtils.isBlank(examSong.getSubjectList())){
-            throw new BizException("请选择专业");
-        }
         examSong.setTenantId(TenantContextHolder.getTenantId().toString());
         examSongService.insert(examSong);
         return succeed();

+ 14 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/dao/ExamSongDao.java

@@ -2,7 +2,9 @@ package com.keao.edu.user.dao;
 
 import com.keao.edu.common.dal.BaseDAO;
 import com.keao.edu.user.entity.ExamSong;
+import com.keao.edu.user.enums.SongTypeEnum;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.security.core.parameters.P;
 
 import java.util.List;
 
@@ -25,4 +27,16 @@ public interface ExamSongDao extends BaseDAO<Integer, ExamSong> {
      */
     List<ExamSong> getWithSubject(@Param("subjectId") Integer subjectId);
 
+    /**
+     * @describe 根据级别和类型获取曲库
+     * @author Joburgess
+     * @date 2020.07.03
+     * @param level:
+     * @param songType:
+     * @return java.util.List<com.keao.edu.user.entity.ExamSong>
+     */
+    List<ExamSong> getWithLevelAndType(@Param("tenantId") String tenantId,
+                                       @Param("level") String level,
+                                       @Param("songType")SongTypeEnum songType);
+
 }

+ 17 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExamSongServiceImpl.java

@@ -9,9 +9,11 @@ import com.keao.edu.user.dao.ExamSongDao;
 import com.keao.edu.user.entity.ExamSong;
 import com.keao.edu.user.service.ExamSongService;
 import com.keao.edu.util.collection.MapUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.util.*;
 
@@ -27,6 +29,21 @@ public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> impl
 	}
 
     @Override
+    public long insert(ExamSong examSong) {
+        if(StringUtils.isBlank(examSong.getSubjectList())){
+            throw new BizException("请选择专业");
+        }
+	    if(Objects.isNull(examSong.getType())){
+	        throw new BizException("请选择曲库类别");
+        }
+        List<ExamSong> existsExamSongs = examSongDao.getWithLevelAndType(examSong.getTenantId(), examSong.getLevelList(), examSong.getType());
+	    if(!CollectionUtils.isEmpty(existsExamSongs)){
+	        throw new BizException("{}级别的{}已存在",examSong.getLevelList(), examSong.getType().getMsg());
+        }
+        return super.insert(examSong);
+    }
+
+    @Override
     public PageInfo<ExamSong> queryPage(QueryInfo queryInfo) {
         PageInfo<ExamSong> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
         Map<String, Object> params = new HashMap<String, Object>();

+ 7 - 0
edu-user/edu-user-server/src/main/resources/config/mybatis/ExamSongMapper.xml

@@ -112,4 +112,11 @@
 	<select id="getWithSubject" resultMap="ExamSong">
 		SELECT * FROM exam_song WHERE FIND_IN_SET(#{subjectId}, subject_list_)
 	</select>
+
+    <select id="getWithLevelAndType" resultMap="ExamSong">
+		SELECT * FROM exam_song
+		WHERE tenant_id_=#{tenantId}
+		AND level_list_=#{level}
+		AND type_=#{songType, typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler}
+    </select>
 </mapper>