重复验证

This commit is contained in:
2023-12-28 15:33:05 +08:00
parent a84df8d493
commit cb7dc557b0
12 changed files with 200 additions and 27 deletions

View File

@@ -1,5 +1,6 @@
package com.cnbm.packing.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
@@ -10,8 +11,11 @@ import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.cnbm.packing.dto.IdVo;
import com.cnbm.packing.dto.ScenesDTO;
import com.cnbm.packing.entity.Scenes;
import com.cnbm.packing.excel.ScenesExcel;
import com.cnbm.packing.mapper.ScenesMapper;
import com.cnbm.packing.service.ScenesServiceBiz;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -39,6 +43,8 @@ import java.util.Map;
public class ScenesController {
@Autowired
private ScenesServiceBiz scenesService;
@Autowired
private ScenesMapper scenesMapper;
@GetMapping("page")
@ApiOperation("分页")
@@ -69,26 +75,53 @@ public class ScenesController {
@ApiOperation("保存")
@LogOperation("保存")
// @PreAuthorize("@ex.hasAuthority('basic:scenes:save')")
public Result<Long> save(@RequestBody ScenesDTO dto){
public Result<IdVo> save(@RequestBody ScenesDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
scenesService.save(dto);
return new Result<Long>().ok(dto.getId());
//验证编码是否重名
QueryWrapper<Scenes> wrapper1 = new QueryWrapper<>();
wrapper1.eq(Scenes.CODE, dto.getCode());
if(scenesMapper.selectCount(wrapper1)!= 0){
return new Result().error(1,"编码重复");
}
//验证名称是否重名
QueryWrapper<Scenes> wrapper2 = new QueryWrapper<>();
wrapper2.eq(Scenes.SCENES_NAME, dto.getScenesName());
System.out.println(scenesMapper.selectCount(wrapper2));
if(scenesMapper.selectCount(wrapper2)!= 0){
return new Result().error(1,"名称重复");
}
else {
return new Result<IdVo>().ok(scenesService.add(dto));
}
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
// @PreAuthorize("@ex.hasAuthority('basic:scenes:update')")
public Result<Long> update(@RequestBody ScenesDTO dto){
public Result<IdVo> update(@RequestBody ScenesDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
scenesService.update(dto);
return new Result<Long>().ok(dto.getId());
//验证编码是否重名
ScenesDTO entity = scenesService.get(dto.getId());
QueryWrapper<Scenes> wrapper1 = new QueryWrapper<>();
wrapper1.eq(Scenes.CODE, dto.getCode());
if(entity.getCode()!=dto.getCode() && scenesMapper.selectCount(wrapper1)!= 0){
return new Result().error(1,"编码重复");
}
//验证名称是否重名
QueryWrapper<Scenes> wrapper2 = new QueryWrapper<>();
wrapper2.eq(Scenes.SCENES_NAME, dto.getScenesName());
System.out.println(scenesMapper.selectCount(wrapper2));
if(entity.getScenesName()!=dto.getScenesName() && scenesMapper.selectCount(wrapper2)!= 0){
return new Result().error(1,"名称重复");
}
else {
return new Result<IdVo>().ok(scenesService.edit(dto));
}
}
@DeleteMapping