Browse Source

1.资金账户新增code重复

heqinwei 7 years ago
parent
commit
900443007e

+ 2 - 0
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/po/BillCodeSeq.java

@@ -14,6 +14,8 @@ public enum  BillCodeSeq {
 
     VENDOR("供应商资料", "Vendor"),
 
+    BANKINFORMATION("资金账户资料", "Bankinformation"),
+
     WAREHOUSE("仓库资料", "Warehouse"),
 
     PURCHASE("采购订单", "Purchase"),

+ 4 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/BankinformationMapper.java

@@ -31,4 +31,8 @@ public interface BankinformationMapper extends CommonBaseMapper<Bankinformation>
 
     Double selectamount(Long id);
 
+    int validateCodeWhenInsert(@Param("code") String code, @Param("companyId") Long companyId);
+
+    int validateCodeWhenUpdate(@Param("code") String code, @Param("id") Long id, @Param("companyId") Long company);
+
 }

+ 26 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/BankinformationServiceImpl.java

@@ -3,11 +3,13 @@ package com.usoftchina.saas.document.service.impl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
+import com.usoftchina.saas.commons.api.MaxnumberService;
 import com.usoftchina.saas.commons.api.MessageLogService;
 import com.usoftchina.saas.commons.dto.ComboDTO;
 import com.usoftchina.saas.commons.dto.DocBaseDTO;
 import com.usoftchina.saas.commons.dto.ListReqDTO;
 import com.usoftchina.saas.commons.exception.BizExceptionCode;
+import com.usoftchina.saas.commons.po.BillCodeSeq;
 import com.usoftchina.saas.context.BaseContextHolder;
 import com.usoftchina.saas.document.entities.Bankinformation;
 import com.usoftchina.saas.document.entities.Banksubledger;
@@ -17,6 +19,7 @@ import com.usoftchina.saas.document.service.BankinformationService;
 import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.page.PageRequest;
 import com.usoftchina.saas.utils.DateUtils;
+import com.usoftchina.saas.utils.RegexpUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -41,6 +44,8 @@ public class BankinformationServiceImpl extends CommonBaseServiceImpl<Bankinform
     private BanksubledgerMapper banksubledgerMapper;
     @Autowired
     private MessageLogService messageLogService;
+    @Autowired
+    private MaxnumberService maxnumberService;
 
     @Transactional
     @Override
@@ -53,6 +58,9 @@ public class BankinformationServiceImpl extends CommonBaseServiceImpl<Bankinform
         bankinformation.setCreatorName(BaseContextHolder.getUserName());
         int bid = Math.toIntExact(bankinformation.getId());
 
+        String bk_code = RegexpUtils.replaceSpecCharacter(bankinformation.getBk_bankcode());
+        String code = pushMaxnubmer(bk_code, bankinformation.getId());
+
         String bktion = bankinformationMapper.selectBankcode(bankinformation.getBk_bankcode() ,BaseContextHolder.getCompanyId());
         //先判断ID,再判断编号
         if (bankinformation.getId() == 0)
@@ -61,6 +69,7 @@ public class BankinformationServiceImpl extends CommonBaseServiceImpl<Bankinform
                 throw new BizException(500, BizExceptionCode.ACCOUNT_EXISTS.getMessage());
             }
             bankinformation.setBk_thisamount(bankinformation.getBk_beginamount());
+            bankinformation.setBk_bankcode(code);
             bankinformationMapper.insertSelective(bankinformation);
             Banksubledger banksubledger = this.changBanksubledger(bankinformation);
             banksubledgerMapper.insertSelective(banksubledger);
@@ -220,4 +229,21 @@ public class BankinformationServiceImpl extends CommonBaseServiceImpl<Bankinform
         }
         return null;
     }
+
+    /**
+     * @Description: 检验获取并更新单号
+     * @Param: [code, id]
+     * @return: java.lang.String
+     * @Author: chenwei
+     * @Date: 2018/10/26
+     */
+    private String pushMaxnubmer(String code, Long id) {
+        if (null == code) {
+            throw new BizException(BizExceptionCode.NULL_CODE);
+        }
+        Long companyId = BaseContextHolder.getCompanyId();
+        Integer count = "0".equals(String.valueOf(id)) ? getMapper().validateCodeWhenInsert(code, companyId) :
+                getMapper().validateCodeWhenUpdate(code, id, companyId);
+        return maxnumberService.pushMaxnubmer(count, code, BillCodeSeq.BANKINFORMATION.getCaller()).getData();
+    }
 }

+ 8 - 0
applications/document/document-server/src/main/resources/mapper/BankinformationMapper.xml

@@ -347,4 +347,12 @@
     <parameter property="v_companyid" jdbcType="INTEGER" mode="IN" />
     <parameter property="v_res" jdbcType="VARCHAR" mode="OUT" />
   </parameterMap>
+
+
+  <select id="validateCodeWhenInsert" resultType="int">
+        select count(*) from bankinformation where bk_bankcode = #{code} and companyId =#{companyId}
+    </select>
+  <select id="validateCodeWhenUpdate" resultType="int" >
+        select count(*) from bankinformation where bk_bankcode = #{code} and bk_id != #{id} and companyId =#{companyId}
+    </select>
 </mapper>