码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-07 14:25:28      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:bsp   cli   throw   不能   str   ice   super   copy   tco   

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 嵌套不要太多
*/

 

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

标签:bsp   cli   throw   不能   str   ice   super   copy   tco   

原文地址:http://www.cnblogs.com/inspred/p/7634353.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!