فهرست منبع

新增题卡规则删除

wangliang 2 سال پیش
والد
کامیت
54b89ca277

+ 33 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicCardRuleServiceImpl.java

@@ -1,15 +1,20 @@
 package com.qmth.distributed.print.business.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.distributed.print.business.bean.dto.CardRuleDto;
 import com.qmth.distributed.print.business.entity.BasicCardRule;
+import com.qmth.distributed.print.business.entity.ExamCard;
+import com.qmth.distributed.print.business.entity.ExamTask;
 import com.qmth.distributed.print.business.mapper.BasicCardRuleMapper;
 import com.qmth.distributed.print.business.service.BasicCardRuleService;
+import com.qmth.distributed.print.business.service.BasicPrintConfigService;
+import com.qmth.distributed.print.business.service.ExamCardService;
+import com.qmth.distributed.print.business.service.ExamTaskService;
 import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.entity.BasicPrintConfig;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.service.TeachcloudCommonService;
@@ -36,6 +41,15 @@ public class BasicCardRuleServiceImpl extends ServiceImpl<BasicCardRuleMapper, B
     @Resource
     TeachcloudCommonService teachcloudCommonService;
 
+    @Resource
+    BasicPrintConfigService basicPrintConfigService;
+
+    @Resource
+    ExamCardService examCardService;
+
+    @Resource
+    ExamTaskService examTaskService;
+
     @Override
     public IPage<CardRuleDto> list(Boolean enable, String name, Long createStartTime, Long createEndTime, Integer pageNumber, Integer pageSize) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
@@ -51,9 +65,24 @@ public class BasicCardRuleServiceImpl extends ServiceImpl<BasicCardRuleMapper, B
 
     @Override
     public boolean enable(BasicCardRule cardRule) {
-        UpdateWrapper<BasicCardRule> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.lambda().set(BasicCardRule::getEnable, cardRule.getEnable()).eq(BasicCardRule::getId, cardRule.getId());
-        return this.update(updateWrapper);
+        QueryWrapper<BasicPrintConfig> basicPrintConfigQueryWrapper = new QueryWrapper<>();
+        basicPrintConfigQueryWrapper.lambda().eq(BasicPrintConfig::getCardRuleId, cardRule.getId());
+        int basicPrintConfigCount = basicPrintConfigService.count(basicPrintConfigQueryWrapper);
+
+        QueryWrapper<ExamCard> examCardQueryWrapper = new QueryWrapper<>();
+        examCardQueryWrapper.lambda().eq(ExamCard::getCardRuleId, cardRule.getId());
+        int examCardCount = examCardService.count(examCardQueryWrapper);
+
+        QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
+        examTaskQueryWrapper.lambda().eq(ExamTask::getCardRuleId, cardRule.getId());
+        int examTaskCount = examTaskService.count(examTaskQueryWrapper);
+
+        if (basicPrintConfigCount == 0 && examCardCount == 0 && examTaskCount == 0) {
+            this.removeById(cardRule.getId());
+        } else {
+            throw ExceptionResultEnum.ERROR.exception("题卡规则已绑定数据,不能删除");
+        }
+        return true;
     }
 
     @Transactional

+ 2 - 2
distributed-print-business/src/main/resources/db/2、init-table-data.sql

@@ -81,7 +81,7 @@ INSERT INTO `sys_privilege` VALUES (100, '考务规则-新增/修改', '/api/adm
 INSERT INTO `sys_privilege` VALUES (101, '题卡规则-查询', '/api/admin/basic/card_rule/list', 'URL', 9, 1, 'AUTH', NULL, 1, 1, 1);
 INSERT INTO `sys_privilege` VALUES (102, '题卡规则-查询单个', '/api/admin/basic/card_rule/get_one', 'URL', 9, 2, 'AUTH', NULL, 1, 1, 1);
 INSERT INTO `sys_privilege` VALUES (103, '题卡规则-新增/修改', '/api/admin/basic/card_rule/save', 'URL', 9, 3, 'AUTH', NULL, 1, 1, 1);
-INSERT INTO `sys_privilege` VALUES (104, '题卡规则-启用/禁用', '/api/admin/basic/card_rule/enable', 'URL', 9, 4, 'AUTH', NULL, 1, 1, 1);
+INSERT INTO `sys_privilege` VALUES (104, '题卡规则-删除', '/api/admin/basic/card_rule/delete', 'URL', 9, 4, 'AUTH', NULL, 1, 1, 1);
 INSERT INTO `sys_privilege` VALUES (105, '通用模板-查询', '/api/admin/basic/template/list', 'URL', 10, 1, 'AUTH', NULL, 1, 1, 1);
 INSERT INTO `sys_privilege` VALUES (106, '通用模板-新增/修改', '/api/admin/basic/template/save', 'URL', 10, 2, 'AUTH', NULL, 1, 1, 1);
 INSERT INTO `sys_privilege` VALUES (107, '通用模板-启用/禁用', '/api/admin/basic/template/enable', 'URL', 10, 3, 'AUTH', NULL, 1, 1, 1);
@@ -296,7 +296,7 @@ INSERT INTO `sys_privilege` VALUES (340, '任务管理-查询条件', 'Condition
 INSERT INTO `sys_privilege` VALUES (341, '任务管理-列表', 'List', 'LIST', 113, 1, 'AUTH', '114', 1, 0, 1);
 INSERT INTO `sys_privilege` VALUES (342, '题卡规则-预览', 'Preview', 'LINK', 9, 1, 'AUTH', '102', 1, 0, 1);
 INSERT INTO `sys_privilege` VALUES (343, '题卡规则-编辑', 'Edit', 'LINK', 9, 2, 'AUTH', '103', 1, 0, 1);
-INSERT INTO `sys_privilege` VALUES (345, '题卡规则-启用&禁用', 'Enable', 'LINK', 9, 3, 'AUTH', '104', 1, 0, 1);
+INSERT INTO `sys_privilege` VALUES (345, '题卡规则-删除', 'Delete', 'LINK', 9, 3, 'AUTH', '104', 1, 0, 1);
 INSERT INTO `sys_privilege` VALUES (346, '题卡审核-未审核查询', 'NotReviewSelect', 'BUTTON', 172, 1, 'AUTH', '173', 1, 0, 1);
 INSERT INTO `sys_privilege` VALUES (347, '题卡审核-未审核批量下载试卷文件', 'NotReviewBatchDownload', 'BUTTON', 172, 2, 'AUTH', '185', 1, 0, 1);
 INSERT INTO `sys_privilege` VALUES (348, '题卡审核-未审核查询条件', 'NotReviewCondition', 'CONDITION', 172, 1, 'AUTH', '173', 1, 0, 1);

+ 3 - 5
distributed-print/src/main/java/com/qmth/distributed/print/api/BasicCardRuleController.java

@@ -2,8 +2,6 @@ package com.qmth.distributed.print.api;
 
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.qmth.boot.api.annotation.Aac;
-import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.distributed.print.business.bean.dto.CardRuleDto;
 import com.qmth.distributed.print.business.entity.BasicCardRule;
@@ -105,13 +103,13 @@ public class BasicCardRuleController {
     }
 
     /**
-     * 启用/禁用
+     * 删除
      *
      * @param cardRule
      * @return
      */
-    @ApiOperation(value = "启用/禁用")
-    @RequestMapping(value = "/enable", method = RequestMethod.POST)
+    @ApiOperation(value = "删除")
+    @RequestMapping(value = "/delete", method = RequestMethod.POST)
     public Result enable(@RequestBody BasicCardRule cardRule) {
         boolean isSuccess = basicCardRuleService.enable(cardRule);
         return ResultUtil.ok(isSuccess);