业务-----添加Service常用逻辑

时间:2023-12-20 19:10:38

1.参数不能为空

 /**
     * 添加人员时判断是否字段全部传值
     * @param request
     * @return
     */
    private Boolean checkClientByCols(ClientRequest request){
        if(!StringUtils.isEmpty(request.getNum()) && !StringUtils.isEmpty(request.getName())
                && request.getCtype() != null && request.getSex() != null
                && request.getCountryId() != null && request.getOrgId() != null){
            Client client = findClientByNum(request.getNum());
            if(client == null){
                return Boolean.TRUE;
            }else{
                return Boolean.FALSE;
            }
        }else{
            throw new ApplicationException(StatusCode.BAD_REQUEST.getCode(),"添加人员时,人员编号/名称/人员类型/性别/所属国籍/部门不可为空");
        }
    }

2.证件号不能重复

public Client findClientByNum(String num){
        return super.selectOne(new EntityWrapper<Client>().eq("num",num).eq(Config.ABLE_CONFIG.ABLE_COLUMN,Config.ABLE_CONFIG.ABLE));
    }

3.添加 ----添加时证件号不能重复

 public Client save(ClientRequest request) {if (request != null){
            if(checkClientByCols(request)) {
                Client client = BeanCopier.copy(request, Client.class);
                super.insert(client)
            }else{
                throw new ApplicationException(StatusCode.CONFLICT.getCode(),"人员编号不可重复");
            }
        }else {
            throw new ApplicationException(StatusCode.BAD_REQUEST.getCode(), StatusCode.BAD_REQUEST.getMessage());
        }
    }/**方法能分开就分开,不要都写在一个方法里,if else 嵌套不要太多*/