Skip to content

Commit

Permalink
refactor: 岗位名称校验唯一性时,只判断同一级别下的岗位是否重名
Browse files Browse the repository at this point in the history
  • Loading branch information
zuihou committed Jul 4, 2023
1 parent 2b34f2c commit 38a660a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ public interface StationService extends SuperCacheService<Station>, LoadService
/**
* 检测名称是否存在
*
* @param id id
* @param name name
* @param id id
* @param orgId 机构ID
* @param name 岗位名称
* @return boolean
* @author zuihou
* @date 2021/5/23 9:37 下午
* @create [2021/5/23 9:37 下午 ] [tangyh] [初始创建]
*/
boolean check(Long id, String name);
boolean check(Long id, Long orgId, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ protected CacheKeyBuilder cacheKeyBuilder() {
}

@Override
public boolean check(Long id, String name) {
public boolean check(Long id, Long orgId, String name) {
LbqWrapper<Station> wrap = Wraps.<Station>lbQ()
.eq(Station::getName, name).ne(Station::getId, id);
.eq(Station::getName, name).eq(Station::getOrgId, orgId).ne(Station::getId, id);
return count(wrap) > 0;
}

@Override
@Transactional(rollbackFor = Exception.class)
public boolean save(Station model) {
ArgumentAssert.isFalse(check(null, model.getName()), StrUtil.format("岗位[{}]已经存在", model.getName()));
ArgumentAssert.isFalse(check(null, model.getOrgId(), model.getName()), StrUtil.format("岗位[{}]已经存在", model.getName()));
return super.save(model);
}

@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateById(Station model) {
ArgumentAssert.isFalse(check(model.getId(), model.getName()), StrUtil.format("岗位[{}]已经存在", model.getName()));
ArgumentAssert.isFalse(check(model.getId(), model.getOrgId(), model.getName()), StrUtil.format("岗位[{}]已经存在", model.getName()));
return super.updateById(model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,22 @@
@RequiredArgsConstructor
public class StationController extends SuperCacheController<StationService, Long, Station, StationPageQuery, StationSaveDTO, StationUpdateDTO> {
private final UserHelperService userHelperService;

@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ID", dataType = DATA_TYPE_LONG, paramType = PARAM_TYPE_QUERY),
@ApiImplicitParam(name = "orgId", value = "orgId", dataType = DATA_TYPE_LONG, paramType = PARAM_TYPE_QUERY),
@ApiImplicitParam(name = "name", value = "名称", dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
})
@ApiOperation(value = "检测名称是否可用", notes = "检测名称是否可用")
@GetMapping("/check")
public R<Boolean> check(@RequestParam(required = false) Long id, @RequestParam String name) {
return success(baseService.check(id, name));
public R<Boolean> check(@RequestParam(required = false) Long id, @RequestParam Long orgId, @RequestParam String name) {
return success(baseService.check(id, orgId, name));
}

@Override
public R<Station> handlerSave(StationSaveDTO model) {
SysUser sysUser = userHelperService.getUserByIdCache(ContextUtil.getUserId());
if (sysUser!= null) {
if (sysUser != null) {
model.setCreatedOrgId(sysUser.getOrgId());
}
return super.handlerSave(model);
Expand Down

0 comments on commit 38a660a

Please sign in to comment.