瀏覽代碼

fix 排序不能相同

zoujiajian 3 年之前
父節點
當前提交
7f0af7cab4

+ 1 - 0
netflix-dao/src/main/java/com/cyksj/model/manage/entity/Admin.java

@@ -37,6 +37,7 @@ public class Admin extends BaseEntity implements Serializable {
     /**
      * 手机号码
      */
+    @NotBlank(message = "手机号不能为空")
     private String phone;
 
     /**

+ 40 - 1
netflix-service/src/main/java/com/cyksj/service/sys/impl/SysHelpServiceImpl.java

@@ -34,6 +34,9 @@ public class SysHelpServiceImpl implements SysHelpService {
 		if (StrUtil.isEmpty(helpQuestionClassification.getName())) {
 			throw BusinessRuntimeException.getInstance("分类名称不能为空");
 		}
+		if (helpQuestionClassification.getSort() == null) {
+			throw BusinessRuntimeException.getInstance("排序不能为空");
+		}
 		if (helpQuestionClassification.getGoodsId() != null) {
 			GoodsDon goodsDon = goodsDonMapper.selectById(helpQuestionClassification.getGoodsId());
 			if (goodsDon == null || !goodsDon.getDeleted()) {
@@ -54,6 +57,13 @@ public class SysHelpServiceImpl implements SysHelpService {
 		if (helpQuestionClassification.getGoodsId() == null && StrUtil.isEmpty(helpQuestionClassification.getLogo())) {
 			throw BusinessRuntimeException.getInstance("未关联平台,请上传对应问题分类logo");
 		}
+		HelpQuestionClassification classification = classificationMapper.selectOne(Wrappers.lambdaQuery(HelpQuestionClassification.class)
+				.eq(HelpQuestionClassification::getDeleted, true)
+				.eq(HelpQuestionClassification::getSort, helpQuestionClassification.getSort())
+				.last("limit 1"));
+		if (classification != null) {
+			throw BusinessRuntimeException.getInstance("排序相同");
+		}
 		classificationMapper.insert(helpQuestionClassification);
 	}
 
@@ -66,18 +76,36 @@ public class SysHelpServiceImpl implements SysHelpService {
 		if (exits == null || !exits.getDeleted()) {
 			throw BusinessRuntimeException.getInstance("分类已被删除");
 		}
+		if (helpQuestionClassification.getSort() != null) {
+			HelpQuestionClassification classification = classificationMapper.selectOne(Wrappers.lambdaQuery(HelpQuestionClassification.class)
+					.eq(HelpQuestionClassification::getDeleted, true)
+					.eq(HelpQuestionClassification::getSort, helpQuestionClassification.getSort())
+					.ne(HelpQuestionClassification::getId, helpQuestionClassification.getId())
+					.last("limit 1"));
+			if (classification != null) {
+				throw BusinessRuntimeException.getInstance("排序相同");
+			}
+		}
 		classificationMapper.updateById(helpQuestionClassification);
 	}
 
 	@Override
 	public void saveHelpQuestion(HelpQuestion helpQuestion) {
-		if (ObjectUtil.hasEmpty(helpQuestion.getClassificationId(), helpQuestion.getName(), helpQuestion.getContent())) {
+		if (ObjectUtil.hasEmpty(helpQuestion.getClassificationId(), helpQuestion.getName(), helpQuestion.getContent(), helpQuestion.getSort())) {
 			throw BusinessRuntimeException.getInstance("请补充必填项");
 		}
 		HelpQuestionClassification classification = classificationMapper.selectById(helpQuestion.getClassificationId());
 		if (classification == null || !classification.getDeleted()) {
 			throw BusinessRuntimeException.getInstance("分类不存在");
 		}
+		HelpQuestion helpQuestion1 = helpQuestionMapper.selectOne(Wrappers.lambdaQuery(HelpQuestion.class)
+				.eq(HelpQuestion::getDeleted, true)
+				.eq(HelpQuestion::getClassificationId, helpQuestion.getClassificationId())
+				.eq(HelpQuestion::getSort, helpQuestion.getSort())
+				.last("limit 1"));
+		if (helpQuestion1 != null) {
+			throw BusinessRuntimeException.getInstance("排序相同");
+		}
 		helpQuestionMapper.insert(helpQuestion);
 	}
 
@@ -93,6 +121,17 @@ public class SysHelpServiceImpl implements SysHelpService {
 		if (helpQuestion.getClassificationId() != null && !exits.getClassificationId().equals(helpQuestion.getClassificationId())) {
 			throw BusinessRuntimeException.getInstance("问题所属分类无法修改");
 		}
+		if (helpQuestion.getSort() != null) {
+			HelpQuestion helpQuestion1 = helpQuestionMapper.selectOne(Wrappers.lambdaQuery(HelpQuestion.class)
+					.eq(HelpQuestion::getDeleted, true)
+					.eq(HelpQuestion::getClassificationId, helpQuestion.getClassificationId())
+					.eq(HelpQuestion::getSort, helpQuestion.getSort())
+					.ne(HelpQuestion::getId, helpQuestion.getId())
+					.last("limit 1"));
+			if (helpQuestion1 != null) {
+				throw BusinessRuntimeException.getInstance("排序相同");
+			}
+		}
 		helpQuestionMapper.updateById(helpQuestion);
 	}
 }

+ 15 - 2
netflix-web/src/main/java/com/cyksj/web/controller/manage/AdminController.java

@@ -84,21 +84,34 @@ public class AdminController {
 
     @PostMapping("/post")
     public Result<String> saveAdmin(@RequestBody @Validated Admin admin) throws Exception {
-        if(StringUtils.isNotBlank(admin.getPassWord())){
+        if (StringUtils.isNotBlank(admin.getPassWord())) {
             admin.setPassWord(Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.SHA256).setStringData(admin.getPassWord()).toBase64String());
         }
-        if(admin.getId() == null){
+        if (admin.getId() == null) {
             Admin ad = adminService.getOne(new LambdaQueryWrapper<Admin>().eq(Admin::getUserName, admin.getUserName()));
             if (ad != null) {
                 throw BusinessRuntimeException.getInstance("该账号已存在.");
             }
         }
+        boolean mobile = Validator.isMobile(admin.getPhone());
+        if (!mobile) {
+            throw BusinessRuntimeException.getInstance("请输入正确的手机号");
+        }
 
         adminService.saveOrUpdate(admin);
 
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
 
+    /**
+     * 删除管理员
+     */
+    @DeleteMapping("/delete/{id}")
+    public Result<String> deleteAdminById(@PathVariable Long id) {
+        adminService.removeById(id);
+        return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
+    }
+
     /**
      * 编辑管理员
      */

+ 1 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/sys/HelpController.java

@@ -59,7 +59,7 @@ public class HelpController {
 	@PutMapping("/question/classification")
 	public Result<String> editHelpQuestionClassification(@RequestBody HelpQuestionClassification helpQuestionClassification) {
 		sysHelpService.editQuestionClassification(helpQuestionClassification);
-		return GatewayResponse.SUCCESS.newBuilder().toResult("新增问题分类成功");
+		return GatewayResponse.SUCCESS.newBuilder().toResult("编辑问题分类成功");
 	}
 
 	/**