|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.FieldsDto;
|
|
|
import com.qmth.distributed.print.business.entity.BasicExamRule;
|
|
|
import com.qmth.distributed.print.business.entity.ExamPrintPlan;
|
|
|
import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
|
|
@@ -20,9 +21,13 @@ import com.qmth.teachcloud.common.service.BasicRoleDataPermissionService;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -52,9 +57,9 @@ public class BasicExamRuleServiceImpl extends ServiceImpl<BasicExamRuleMapper, B
|
|
|
queryWrapper.lambda().eq(BasicExamRule::getSchoolId, schoolId);
|
|
|
|
|
|
BasicExamRule basicExamRule = this.getOne(queryWrapper);
|
|
|
- if(basicExamRule == null){
|
|
|
+ if (basicExamRule == null) {
|
|
|
List<EnumResult> enumResultList = RequiredFieldsEnum.listTypes();
|
|
|
- List<JSONObject> requiredObjects = enumResultList.stream().map(m->{
|
|
|
+ List<JSONObject> requiredObjects = enumResultList.stream().map(m -> {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("code", m.getCode());
|
|
|
jsonObject.put("name", m.getDesc());
|
|
@@ -87,6 +92,41 @@ public class BasicExamRuleServiceImpl extends ServiceImpl<BasicExamRuleMapper, B
|
|
|
examRule.setSchoolId(schoolId);
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
|
|
+ List<FieldsDto> extendFieldList = JSONObject.parseArray(examRule.getExtendFields(), FieldsDto.class);
|
|
|
+ if (!CollectionUtils.isEmpty(extendFieldList)) {
|
|
|
+ // 校验扩展字段变量名是否重复
|
|
|
+ Map<String, List<FieldsDto>> byCodeCollect = extendFieldList.stream().collect(Collectors.groupingBy(FieldsDto::getCode));
|
|
|
+ for (Map.Entry<String, List<FieldsDto>> entry : byCodeCollect.entrySet()) {
|
|
|
+ if (entry.getValue().size() > 1) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("扩展字段中字段变量名[" + entry.getKey() + "]有" + entry.getValue().size() + "个重复");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 校验扩展字段名称是否重复
|
|
|
+ Map<String, List<FieldsDto>> byNameCollect = extendFieldList.stream().collect(Collectors.groupingBy(FieldsDto::getName));
|
|
|
+ for (Map.Entry<String, List<FieldsDto>> entry : byNameCollect.entrySet()) {
|
|
|
+ if (entry.getValue().size() > 1) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("扩展字段中字段名称[" + entry.getKey() + "]有" + entry.getValue().size() + "个重复");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验扩展字段变量名是否与必选字段重复
|
|
|
+ List<FieldsDto> requiredFieldList = JSONObject.parseArray(examRule.getRequiredFields(), FieldsDto.class);
|
|
|
+ for (FieldsDto fieldsDto : extendFieldList) {
|
|
|
+ long count = requiredFieldList.stream().filter(t -> t.getCode().equals(fieldsDto.getCode())).count();
|
|
|
+ if (count > 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("扩展字段中字段变量名[" + fieldsDto.getCode() + "]在必选字段中已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验扩展字段名称是否与必选字段重复
|
|
|
+ for (FieldsDto fieldsDto : extendFieldList) {
|
|
|
+ long count = requiredFieldList.stream().filter(t -> t.getName().equals(fieldsDto.getName())).count();
|
|
|
+ if (count > 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("扩展字段中字段名称[" + fieldsDto.getName() + "]在必选字段中已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 新增
|
|
|
if (examRule.getId() == null) {
|
|
|
examRule.insertInfo(sysUser.getId());
|
|
@@ -99,39 +139,24 @@ public class BasicExamRuleServiceImpl extends ServiceImpl<BasicExamRuleMapper, B
|
|
|
QueryWrapper<ExamPrintPlan> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.lambda().eq(ExamPrintPlan::getSchoolId, schoolId).ne(ExamPrintPlan::getStatus, PrintPlanStatusEnum.END);
|
|
|
List<ExamPrintPlan> examPrintPlanList = examPrintPlanService.list(queryWrapper);
|
|
|
- if (examPrintPlanList != null && !examPrintPlanList.isEmpty()) {
|
|
|
- // -- 可直接抛出异常下面的判断均可不用执行
|
|
|
+ if (!CollectionUtils.isEmpty(examPrintPlanList)) {
|
|
|
BasicExamRule basicExamRule = this.getById(examRule.getId());
|
|
|
// 匹配扩展字段是否有变动
|
|
|
String oldExtends = basicExamRule.getExtendFields();
|
|
|
String newExtends = examRule.getExtendFields();
|
|
|
- List<Map> oldMapList = JSONObject.parseArray(oldExtends, Map.class);
|
|
|
- List<Map> newMapList = JSONObject.parseArray(newExtends, Map.class);
|
|
|
- if (oldMapList.size() != newMapList.size()) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("有未结束的印刷计划,不能修改扩展字段");
|
|
|
- }
|
|
|
- for (Map map : oldMapList) {
|
|
|
- String code = String.valueOf(map.get("code"));
|
|
|
- String name = String.valueOf(map.get("name"));
|
|
|
- String enable = String.valueOf(map.get("enable"));
|
|
|
+ List<FieldsDto> oldFieldList = JSONObject.parseArray(oldExtends, FieldsDto.class);
|
|
|
+ List<FieldsDto> newFieldList = JSONObject.parseArray(newExtends, FieldsDto.class);
|
|
|
+ oldFieldList.sort(Comparator.comparing(FieldsDto::getCode));
|
|
|
+ newFieldList.sort(Comparator.comparing(FieldsDto::getCode));
|
|
|
|
|
|
- boolean flag = true;
|
|
|
- for (Map map1 : newMapList) {
|
|
|
- String code1 = String.valueOf(map1.get("code"));
|
|
|
- String name1 = String.valueOf(map1.get("name"));
|
|
|
- String enable1 = String.valueOf(map1.get("enable"));
|
|
|
- if (code.equals(code1) && name.equals(name1) && enable.equals(enable1)) {
|
|
|
- flag = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (flag) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("有未结束的印刷计划,不能修改扩展字段");
|
|
|
- }
|
|
|
+ // md5加密
|
|
|
+ String md5OldExtends = DigestUtils.md5DigestAsHex(JSONObject.toJSONBytes(oldFieldList));
|
|
|
+ String newOldExtends = DigestUtils.md5DigestAsHex(JSONObject.toJSONBytes(newFieldList));
|
|
|
+ if (!md5OldExtends.equals(newOldExtends)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("有未结束的印刷计划,不能修改扩展字段");
|
|
|
}
|
|
|
}
|
|
|
examRule.updateInfo(sysUser.getId());
|
|
|
- examRule.setOrgId(sysUser.getOrgId());
|
|
|
this.updateById(examRule);
|
|
|
}
|
|
|
return examRule.getId();
|