判断账户名称不重复

判断新增账户名称不能重复

 

java代码:

/**
     * 新增
      * 
     * @param setContactsBankEntity 用作展示的vo
      * @param result
     * @param redirectAttributes
     * @param model
     * @return
     */
    @RequestMapping(value = "add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Integer bankAdd(SetContactsBankEntity setContactsBankEntity, BindingResult result,
            RedirectAttributes redirectAttributes, Model model) {
        // 提示信息
        SettlementResultInfo settlementResultInfo = new SettlementResultInfo();
        // 返回
        Integer num = 0;
        // 入参不能为null
        if (setContactsBankEntity != null) {
            
            SetContactsBankRequest req = new SetContactsBankRequest();
            SetContactsBankResponse rsp = new SetContactsBankResponse();
            
            SetContactsBankListResponse rsp1 = new SetContactsBankListResponse();

            if (setContactsBankEntity.getIsSet() == null) {
                setContactsBankEntity.setIsSet(false);
            }
            if (setContactsBankEntity.getBeginMoney() == null) {
                setContactsBankEntity.setBeginMoney(BigDecimal.ZERO);
            }
            if (setContactsBankEntity.getEndMoney() == null) {
                setContactsBankEntity.setEndMoney(BigDecimal.ZERO);
            }
            if (setContactsBankEntity.getDisabled() == null) {
                setContactsBankEntity.setDisabled(false);
            }
            req.setEntity(setContactsBankEntity);
            // 查出所有银行账户
            rsp1 = setContactsBankInterface.getBankAccount();
            List list = rsp1.getObjectList();
            Boolean flag = false;
            //取出集合中银行名称,判断是否重复
            for (int i = 0; i < list.size(); i++) {
                String bankName = list.get(i).getBankName();
                if(setContactsBankEntity.getBankName().equals(bankName)){
                    flag = true;
                    num = 2;
                    break;
                }
            }
            if(!flag){
                rsp = setContactsBankInterface.save(req);
                num = rsp.getId();
            }
                
            
            if (!StringUtils.equals(rsp.getResultCode(), ReturnResult.SUCCESS.getResultCode())) {
                settlementResultInfo.setResCode(-1);
                settlementResultInfo.setResMessage("错误代码:" + rsp.getResultCode() + "," + rsp.getResultMessage());
            }
            if (StringUtils.equals(rsp.getResultCode(), ReturnResult.SUCCESS.getResultCode())) {
                settlementResultInfo.setResCode(1);
            }

        } else {
            addErrorMessage(model, "参数异常!");
        }

        return num;
    }

 

js代码:

//新增
	function saveConfirm() {
		validValue = $("#popupForm").valid();
		if (validValue) {
			$.ajax({
				url : '${ctx}/xxx/add',
				type : "POST",
				data : $('#popupForm').serialize(),
				dataType : 'json',
				success : function(data) {
					if(data == 2){
						alert("银行账户不能重复!");
					}else{
						if (data != null && data > 0) {
							alert("新增银行账户成功!", function() {
								window.location.reload();
							});

						} else {
							alert("系统出错,请稍后重试!");
						}
					}
					
				},
				error : function(data) {
					alert("error:" + data);
					alert("系统出错,请稍后重试--------------------------------!");
				},

			});
		}

 


 
 

 

你可能感兴趣的:(判断名称不重复)