编辑判断不能重复时排除自身 规范了返回值
This commit is contained in:
+26
-15
@@ -8,6 +8,7 @@ import com.adc.da.slrs.customWorkGroup.service.IWorkGroupService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.apache.commons.codec.language.Nysiis;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -37,18 +38,21 @@ public class WorkGroupController extends BaseController<WorkGroup> {
|
||||
@ApiModelProperty("新增工作组")
|
||||
@PostMapping
|
||||
public ResponseMessage addWorkGroup(WorkGroup workGroup) {
|
||||
String meg="";
|
||||
if (isDistinct(workGroup.getWorkGroup())){
|
||||
ResponseMessage<Object> result = Result.success();
|
||||
|
||||
if (isDistinct(workGroup.getWorkGroup(),null)){
|
||||
if (iWorkGroupService.add(workGroup)){
|
||||
meg="新增成功!";
|
||||
result=Result.success("200","新增成功");
|
||||
}else {
|
||||
meg="新增失败!";
|
||||
result=Result.error("201","新增失败");
|
||||
|
||||
}
|
||||
}else {
|
||||
meg="组名已存在!";
|
||||
result=Result.error("202","组名已存在");
|
||||
|
||||
}
|
||||
|
||||
return Result.success("200",meg);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,32 +76,39 @@ public class WorkGroupController extends BaseController<WorkGroup> {
|
||||
@ApiModelProperty("修改工作组")
|
||||
@PutMapping
|
||||
public ResponseMessage updateWorkGroup(WorkGroup workGroup){
|
||||
String meg="";
|
||||
if (isDistinct(workGroup.getWorkGroup())){
|
||||
|
||||
ResponseMessage<Object> result = Result.success();
|
||||
|
||||
if (isDistinct(workGroup.getWorkGroup(),workGroup.getId())){
|
||||
if (iWorkGroupService.update(workGroup)){
|
||||
meg="修改成功!";
|
||||
result=Result.success("200", "修改成功");
|
||||
}else {
|
||||
meg="修改失败";
|
||||
result=Result.error("201", "修改失败");
|
||||
}
|
||||
|
||||
}else {
|
||||
meg="组名已存在!";
|
||||
result=Result.error("202", "组名已存在");
|
||||
}
|
||||
|
||||
return Result.success("200",meg);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断提交的工作组名称是否重复
|
||||
* @param groupName
|
||||
* @return true 没有重复 false 有重复
|
||||
* @param groupName 条件
|
||||
* @param id 排除id
|
||||
* @returntrue 没有重复 false 有重复
|
||||
*/
|
||||
private boolean isDistinct(String groupName){
|
||||
private boolean isDistinct(String groupName,String id){
|
||||
|
||||
QueryWrapper<WorkGroup> ew = new QueryWrapper<>();
|
||||
|
||||
ew.eq("work_group_name",groupName);
|
||||
|
||||
if (id!=null){
|
||||
ew.ne("id",id);
|
||||
}
|
||||
|
||||
List<WorkGroup> list = iWorkGroupService.list(ew);
|
||||
return list.isEmpty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user