Browse Source

题卡复制相关bug

caozixuan 2 năm trước cách đây
mục cha
commit
4da4f78e2f

+ 8 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamCardService.java

@@ -45,5 +45,12 @@ public interface ExamCardService extends IService<ExamCard> {
 
     Boolean deleteGeneric(Long id);
 
-    Long copyCard(Long id);
+    /**
+     * 题卡复制
+     *
+     * @param id       被复制的题卡id
+     * @param courseId 复制后的题卡所绑定的课程id
+     * @return 复制后的题卡id
+     */
+    Long copyCard(Long id, Long courseId);
 }

+ 23 - 9
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamCardServiceImpl.java

@@ -22,6 +22,7 @@ import com.qmth.teachcloud.common.bean.params.ArraysParams;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
+import com.qmth.teachcloud.common.entity.BasicCourse;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.CardCreateMethodEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
@@ -100,7 +101,7 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
                     .eq(ExamCard::getCourseCode, examCardParams.getCourseCode())
                     .eq(ExamCard::getTitle, examCardParams.getTitle());
             List<ExamCard> examCardList = this.list(queryWrapper);
-            if(!examCardList.isEmpty()){
+            if (!examCardList.isEmpty()) {
                 throw ExceptionResultEnum.ERROR.exception("题卡名称已存在");
             }
 
@@ -144,13 +145,13 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
                     .eq(ExamCard::getTitle, examCardParams.getTitle())
                     .ne(ExamCard::getId, examCardParams.getId());
             List<ExamCard> examCardList = this.list(queryWrapper);
-            if(!examCardList.isEmpty()){
+            if (!examCardList.isEmpty()) {
                 throw ExceptionResultEnum.ERROR.exception("题卡名称已存在");
             }
 
             examCard = this.getById(examCardParams.getId());
             examCard.setTitle(examCardParams.getTitle());
-            if (!examCardParams.getCourseCode().equals(examCard.getCourseCode())) {
+            if (CardTypeEnum.CUSTOM.equals(examCard.getType()) && !examCardParams.getCourseCode().equals(examCard.getCourseCode())) {
                 throw ExceptionResultEnum.ERROR.exception("课程不能更改");
             }
             if (!examCardParams.getMakeMethod().name().equals(examCard.getMakeMethod().name())) {
@@ -457,7 +458,14 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
 
     @Transactional
     @Override
-    public Long copyCard(Long id) {
+    public Long copyCard(Long id, Long courseId) {
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+        BasicCourse basicCourse = basicCourseService.getById(courseId);
+        if (Objects.isNull(basicCourse)) {
+            throw ExceptionResultEnum.ERROR.exception("未找复制后题卡要绑定的课程");
+        }
+        String courseCode = basicCourse.getCode();
+
         ExamCard examCard = this.getById(id);
         if (examCard == null) {
             throw ExceptionResultEnum.ERROR.exception("题卡不存在");
@@ -465,11 +473,17 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
         // 复制题卡
         ExamCard copyExamCard = new ExamCard();
         BeanUtils.copyProperties(examCard, copyExamCard);
-        Long copyExamCardId = SystemConstant.getDbUuid();
-        copyExamCard.setId(copyExamCardId);
-        String title = checkTitle(examCard);
+        String title = checkTitle(examCard, courseCode);
         copyExamCard.setTitle(title);
+        copyExamCard.setCourseCode(basicCourse.getCode());
+        copyExamCard.setCourseName(basicCourse.getName());
+        copyExamCard.setMakeMethod(MakeMethodEnum.SELF);
+        copyExamCard.setCreateMethod(null);
+        copyExamCard.setType(CardTypeEnum.CUSTOM);
+        copyExamCard.setCardRuleId(null);
+        copyExamCard.insertInfo(requestUser.getId());
         this.save(copyExamCard);
+        Long copyExamCardId = copyExamCard.getId();
 
         ExamCardDetail examCardDetail = examCardDetailService.getByCardId(id);
         if (examCardDetail == null) {
@@ -490,10 +504,10 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
      *
      * @param examCard 题卡对象
      */
-    private String checkTitle(ExamCard examCard) {
+    private String checkTitle(ExamCard examCard, String courseCode) {
         QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
         queryWrapper.lambda().eq(ExamCard::getSchoolId, examCard.getSchoolId())
-                .eq(ExamCard::getCourseCode, examCard.getCourseCode());
+                .eq(ExamCard::getCourseCode, courseCode);
         String title;
         int i = 1;
         ExamCard newExamCard;

+ 3 - 2
distributed-print/src/main/java/com/qmth/distributed/print/api/ExamCardController.java

@@ -203,8 +203,9 @@ public class ExamCardController {
      */
     @ApiOperation(value = "复制题卡")
     @RequestMapping(value = "/copy", method = RequestMethod.POST)
-    public Result copyCard(Long id) {
-        Long copyCardId = examCardService.copyCard(id);
+    public Result copyCard(@RequestParam(value = "id") String id,
+                           @RequestParam(value = "courseId") String courseId) {
+        Long copyCardId = examCardService.copyCard(SystemConstant.convertIdToLong(id),SystemConstant.convertIdToLong(courseId));
         return ResultUtil.ok(String.valueOf(copyCardId), "");
     }
 }