Browse Source

1.资金账号更新问题

heqinwei 7 years ago
parent
commit
1fcfdb5f78

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

@@ -24,5 +24,6 @@ public interface BankinformationMapper extends CommonBaseMapper<Bankinformation>
 
     List<ComboDTO> getCombo(@Param("companyId") Long companyId);
     String selectBankcode(String bk_bankcode);
+    Long selectBankId(String bk_bankcode);
 
 }

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

@@ -43,12 +43,28 @@ public class BankinformationServiceImpl extends CommonBaseServiceImpl<Bankinform
         bankinformation.setBk_income(new Double(0));
         bankinformation.setBk_spending(new Double(0));
 
-        //判断编号
         String bktion = bankinformationMapper.selectBankcode(bankinformation.getBk_bankcode());
-        if (bktion != null){
-            throw new BizException(500, BizExceptionCode.ACCOUNT_EXISTS.getMessage());
+        //先判断ID,再判断编号
+        if (bankinformation.getId() == 0)
+        {
+            if (bktion != null){
+                throw new BizException(500, BizExceptionCode.ACCOUNT_EXISTS.getMessage());
+            }
+            bankinformationMapper.insertSelective(bankinformation);
+        }else {
+            if (bktion != null){
+                Long id = bankinformationMapper.selectBankId(bankinformation.getBk_bankcode());
+                if (id.equals(bankinformation.getId())){
+                    bankinformationMapper.updateByPrimaryKeySelective(bankinformation);
+                }else {
+                    throw new BizException(500, BizExceptionCode.ACCOUNT_EXISTS.getMessage());
+                }
+            }else {
+                bankinformationMapper.updateByPrimaryKeySelective(bankinformation);
+            }
         }
 
+
         //中间表
         Banksubledger banksubledger = new Banksubledger();
         Date date = bankinformation.getBk_date();
@@ -75,10 +91,8 @@ public class BankinformationServiceImpl extends CommonBaseServiceImpl<Bankinform
         banksubledger.setBl_orderamount(bankinformation.getBk_beginamount());
 
         if(bankinformation.getId() == 0){
-            bankinformationMapper.insertSelective(bankinformation);
             banksubledgerMapper.insertSelective(banksubledger);
         }else{
-            bankinformationMapper.updateByPrimaryKeySelective(bankinformation);
             banksubledgerMapper.updateByPrimaryKeySelective(banksubledger);
         }
         return true;

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

@@ -339,4 +339,8 @@
   <select id="selectBankcode" parameterType="java.lang.String" resultType="java.lang.String">
         select bk_bankcode from bankinformation where bk_bankcode = #{bk_bankcode,jdbcType=VARCHAR}
     </select>
+
+  <select id="selectBankId" parameterType="java.lang.String" resultType="java.lang.Long">
+        select bk_id from bankinformation where bk_bankcode = #{bk_bankcode,jdbcType=VARCHAR}
+    </select>
 </mapper>