Browse Source

增加限制:已使用过的账户名称不允许修改

chenw 6 years ago
parent
commit
be424c927f

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

@@ -40,4 +40,44 @@ public interface BankinformationMapper extends CommonBaseMapper<Bankinformation>
 
     int getBankNameSameById(@Param("name") String name, @Param("id") Long id, @Param("companyId") Long company);
 
+    /**
+     * 查询收款单中使用此资金账户的次数
+     * @param oldBankName
+     * @param companyId
+     * @return
+     */
+    int selectCountFromRecbalanceDet(@Param("oldBankName") String oldBankName, @Param("companyId") Long companyId);
+
+    /**
+     * 查询付款单中使用此资金账户的次数
+     * @param oldBankName
+     * @param companyId
+     * @return
+     */
+    int selectCountFromPaybalanceDet(@Param("oldBankName") String oldBankName, @Param("companyId") Long companyId);
+
+    /**
+     * 查询其他收入单中使用此资金账户的次数
+     * @param oldBankName
+     * @param companyId
+     * @return
+     */
+    int selectCountFromOthreceipts(@Param("oldBankName") String oldBankName, @Param("companyId") Long companyId);
+
+    /**
+     * 查询其他支出单中使用此资金账户的次数
+     * @param oldBankName
+     * @param companyId
+     * @return
+     */
+    int selectCountFromOthspendings(@Param("oldBankName") String oldBankName, @Param("companyId") Long companyId);
+
+    /**
+     * 查询资金转存中使用此资金账户的次数
+     * @param oldBankName
+     * @param companyId
+     * @return
+     */
+    int selectCountFromFundtransferDetail(@Param("oldBankName") String oldBankName, @Param("companyId") Long companyId);
+
 }

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

@@ -53,7 +53,8 @@ public class BankinformationServiceImpl extends CommonBaseServiceImpl<Bankinform
     @Transactional
     @Override
     public boolean save(Bankinformation bankinformation){
-        bankinformation.setCompanyId(BaseContextHolder.getCompanyId());
+        Long companyId = BaseContextHolder.getCompanyId();
+        bankinformation.setCompanyId(companyId);
         bankinformation.setBk_income(new Double(0));
         bankinformation.setBk_spending(new Double(0));
         bankinformation.setCreateTime(new Date());
@@ -95,6 +96,12 @@ public class BankinformationServiceImpl extends CommonBaseServiceImpl<Bankinform
             bankinformation.setUpdaterId(BaseContextHolder.getUserId());
             bankinformation.setUpdaterName(BaseContextHolder.getUserName());
             bankinformation.setUpdateTime(new Date());
+            //判断是否已修改账户名称
+            String oldBankName = bankinformationMapper.selectByPrimaryKey(bid).getBk_bankname();
+            if (!bankinformation.getBk_bankname().equals(oldBankName)) {
+                enableUpdateBankName(oldBankName, companyId);
+            }
+
             //判断是否能修改期初金额
             Double beginamount = bankinformationMapper.selectamount(bankinformation.getId());
             Double fbeginamount = bankinformation.getBk_beginamount();
@@ -139,6 +146,40 @@ public class BankinformationServiceImpl extends CommonBaseServiceImpl<Bankinform
         return true;
     }
 
+    /**
+     * 判断是否可以更新资金账户名称
+     * @param oldBankName
+     * @param companyId
+     */
+    private void enableUpdateBankName(String oldBankName, Long companyId){
+        int count = 0;
+        //收款单  recbalanceDet
+        count = bankinformationMapper.selectCountFromRecbalanceDet(oldBankName, companyId);
+        if (count > 0) {
+            throw new BizException(BizExceptionCode.BIZ_RELUPDATE_CODEANDNAME);
+        }
+        //付款单  paybalanceDet
+        count = bankinformationMapper.selectCountFromPaybalanceDet(oldBankName, companyId);
+        if (count > 0) {
+            throw new BizException(BizExceptionCode.BIZ_RELUPDATE_CODEANDNAME);
+        }
+        //其他收入单  othreceipts
+        count = bankinformationMapper.selectCountFromOthreceipts(oldBankName, companyId);
+        if (count > 0) {
+            throw new BizException(BizExceptionCode.BIZ_RELUPDATE_CODEANDNAME);
+        }
+        //其他支出单  othspendings
+        count = bankinformationMapper.selectCountFromOthspendings(oldBankName, companyId);
+        if (count > 0) {
+            throw new BizException(BizExceptionCode.BIZ_RELUPDATE_CODEANDNAME);
+        }
+        //资金转存  fundtransferdetail
+        count = bankinformationMapper.selectCountFromFundtransferDetail(oldBankName, companyId);
+        if (count > 0) {
+            throw new BizException(BizExceptionCode.BIZ_RELUPDATE_CODEANDNAME);
+        }
+    }
+
     @Transactional
     @Override
     public boolean removeByPrimaryKey(int id){

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

@@ -375,4 +375,24 @@
   <select id="getBankNameSameById" resultType="int">
     select count(*) from bankinformation where bk_bankname = #{name} and bk_id != #{id} and companyId =#{companyId}
   </select>
+
+  <select id="selectCountFromRecbalanceDet" resultType="int">
+    select count(*) from RecbalanceDet where rd_bankname = #{oldBankName} and companyid = #{companyId}
+  </select>
+
+  <select id="selectCountFromPaybalanceDet" resultType="int">
+    select count(*) from PaybalanceDet where pd_bankname = #{oldBankName} and companyid = #{companyId}
+  </select>
+
+  <select id="selectCountFromOthreceipts" resultType="int">
+    select count(*) from othreceipts where or_bankname = #{oldBankName} and companyid = #{companyId}
+  </select>
+
+  <select id="selectCountFromOthspendings" resultType="int">
+    select count(*) from Othspendings where os_bankname = #{oldBankName} and companyid = #{companyId}
+  </select>
+
+  <select id="selectCountFromFundtransferDetail" resultType="int">
+    select count(*) from FundtransferDetail where ftd_bankname = #{oldBankName} and companyid = #{companyId}
+  </select>
 </mapper>