Browse Source

1.资金各单加上中间表逻辑

heqinwei 7 years ago
parent
commit
1f2e19c0e5

+ 1 - 1
applications/document/document-server/src/main/resources/application.yml

@@ -47,7 +47,7 @@ eureka:
   client:
     registryFetchIntervalSeconds: 5
     serviceUrl:
-      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@192.168.0.181:8510/eureka/
+      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@localhost:8500/eureka/
 management:
   endpoints:
     web:

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

@@ -134,6 +134,12 @@
       <if test="bk_remark != null" >
         bk_remark,
       </if>
+      <if test="bk_spending != null" >
+        bk_spending,
+      </if>
+      <if test="bk_income != null" >
+        bk_income,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides="," >
       <if test="bk_bankcode != null" >
@@ -199,6 +205,12 @@
       <if test="bk_remark != null" >
         #{bk_remark,jdbcType=LONGVARCHAR},
       </if>
+      <if test="bk_spending != null" >
+        #{bk_spending,jdbcType=DOUBLE},
+      </if>
+      <if test="bk_income != null" >
+        #{bk_income,jdbcType=DOUBLE},
+      </if>
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.usoftchina.saas.document.entities.Bankinformation" >
@@ -267,6 +279,12 @@
       <if test="bk_remark != null" >
         bk_remark = #{bk_remark,jdbcType=LONGVARCHAR},
       </if>
+      <if test="bk_income != null" >
+        bk_income = #{bk_income,jdbcType=DOUBLE},
+      </if>
+      <if test="bk_spending != null" >
+        bk_spending = #{bk_spending,jdbcType=DOUBLE},
+      </if>
     </set>
     where bk_id = #{id,jdbcType=INTEGER}
   </update>

+ 45 - 13
applications/money/money-server/src/main/java/com/usoftchina/saas/money/service/impl/FundtransferServiceImpl.java

@@ -42,6 +42,8 @@ public class FundtransferServiceImpl extends CommonBaseServiceImpl<FundtransferM
     private PaybalanceMapper paybalanceMapper;
     @Autowired
     private MessageLogService messageLogService;
+    @Autowired
+    private BankinformationMapper bankinformationMapper;
 
     @Override
     public DocBaseDTO insert(Fundtran fundtran) {
@@ -96,7 +98,6 @@ public class FundtransferServiceImpl extends CommonBaseServiceImpl<FundtransferM
         this.changBankUntil(fundtran);
         DocBaseDTO docBaseDTO = this.insert(fundtran);
         Long id = docBaseDTO.getId();
-        String ft_code = docBaseDTO.getCode();
 
         //取从表金额更新中间表、资金账号表
         List<Fundtransferdetail> fundtransferdetailList = fundtran.getItems();
@@ -115,15 +116,28 @@ public class FundtransferServiceImpl extends CommonBaseServiceImpl<FundtransferM
             //资金账号表
             int bk_id = fundtransferdetail.getFtd_bankid();
             int bk_inid = fundtransferdetail.getFtd_inbankid();
-            Double bk_amount = paybalanceMapper.selectThisamount(bk_id) == null ? new Double(0) : paybalanceMapper.selectThisamount(bk_id);
-            Double bk_inamount = paybalanceMapper.selectThisamount(bk_inid) == null ? new Double(0) : paybalanceMapper.selectThisamount(bk_inid);
 
-            Double thisamount = bk_amount - fundtransferdetail.getFtd_nowbalance();
-            if (thisamount < 0){
-                throw new BizException(500, BizExceptionCode.BANK_AMOUNT_NOTENOUGH.getMessage());
-            }
-            paybalanceMapper.updateBankAmount(thisamount, bk_id);
-            paybalanceMapper.updateBankAmount(bk_inamount + fundtransferdetail.getFtd_nowbalance(), bk_inid);
+            Double bk_amount = fundtransferdetail.getFtd_nowbalance();
+            //付款方
+            Bankinformation bankinformation = bankinformationMapper.selectByPrimaryKey(bk_id);
+            Double beginamount = bankinformation.getBk_beginamount();
+            Double spending = bankinformation.getBk_spending() == null ? new Double(0) : bankinformation.getBk_spending();
+            Double incomme = bankinformation.getBk_income() == null ? new Double(0) : bankinformation.getBk_income();
+            bankinformation.setBk_thisamount(beginamount + incomme - spending - bk_amount);
+            bankinformation.setBk_income(incomme);
+            bankinformation.setBk_spending(spending + bk_amount);
+
+            //收款方
+            Bankinformation inbankinformation = bankinformationMapper.selectByPrimaryKey(bk_inid);
+            Double inbeginamount = inbankinformation.getBk_beginamount();
+            Double inspending = inbankinformation.getBk_spending() == null ? new Double(0) : inbankinformation.getBk_spending();
+            Double inincomme = inbankinformation.getBk_income() == null ? new Double(0) : inbankinformation.getBk_income();
+            inbankinformation.setBk_thisamount(inbeginamount + inincomme - inspending + bk_amount);
+            inbankinformation.setBk_income(inincomme + bk_amount);
+            inbankinformation.setBk_spending(inspending);
+
+            bankinformationMapper.updateByPrimaryKeySelective(bankinformation);
+            bankinformationMapper.updateByPrimaryKeySelective(inbankinformation);
         }
         DocBaseDTO baseDTO = getBaseDTOById(id);
         //日志记录
@@ -159,10 +173,28 @@ public class FundtransferServiceImpl extends CommonBaseServiceImpl<FundtransferM
             //资金账号表
             int bk_id = fundtransferdetail.getFtd_bankid();
             int bk_inid = fundtransferdetail.getFtd_inbankid();
-            Double bk_amount = paybalanceMapper.selectThisamount(bk_id) == null ? new Double(0) : paybalanceMapper.selectThisamount(bk_id);
-            Double bk_inamount = paybalanceMapper.selectThisamount(bk_inid) == null ? new Double(0) : paybalanceMapper.selectThisamount(bk_inid);
-            paybalanceMapper.updateBankAmount(bk_amount + fundtransferdetail.getFtd_nowbalance(), bk_id);
-            paybalanceMapper.updateBankAmount(bk_inamount - fundtransferdetail.getFtd_nowbalance(), bk_inid);
+
+            Double bk_amount = fundtransferdetail.getFtd_nowbalance();
+            //付款方
+            Bankinformation bankinformation = bankinformationMapper.selectByPrimaryKey(bk_id);
+            Double beginamount = bankinformation.getBk_beginamount();
+            Double spending = bankinformation.getBk_spending() == null ? new Double(0) : bankinformation.getBk_spending();
+            Double incomme = bankinformation.getBk_income() == null ? new Double(0) : bankinformation.getBk_income();
+            bankinformation.setBk_thisamount(beginamount + incomme - spending + bk_amount);
+            bankinformation.setBk_income(incomme);
+            bankinformation.setBk_spending(spending - bk_amount);
+
+            //收款方
+            Bankinformation inbankinformation = bankinformationMapper.selectByPrimaryKey(bk_inid);
+            Double inbeginamount = inbankinformation.getBk_beginamount();
+            Double inspending = inbankinformation.getBk_spending() == null ? new Double(0) : inbankinformation.getBk_spending();
+            Double inincomme = inbankinformation.getBk_income() == null ? new Double(0) : inbankinformation.getBk_income();
+            inbankinformation.setBk_thisamount(inbeginamount + inincomme - inspending - bk_amount);
+            inbankinformation.setBk_income(inincomme - bk_amount);
+            inbankinformation.setBk_spending(inspending);
+
+            bankinformationMapper.updateByPrimaryKeySelective(bankinformation);
+            bankinformationMapper.updateByPrimaryKeySelective(inbankinformation);
         }
 
         DocBaseDTO baseDTO = getBaseDTOById(Long.valueOf(id));

+ 20 - 2
applications/money/money-server/src/main/resources/mapper/BankinformationMapper.xml

@@ -68,7 +68,7 @@
       #{bk_text3,jdbcType=VARCHAR}, #{bk_text4,jdbcType=VARCHAR}, #{bk_text5,jdbcType=VARCHAR},
       #{bk_remark,jdbcType=LONGVARCHAR})
   </insert>
-  <insert id="insertSelective" parameterType="com.usoftchina.saas.money.po.Bankinformation" >
+  <insert id="insertSelective" parameterType="com.usoftchina.saas.document.entities.Bankinformation" >
     insert into bankinformation
     <trim prefix="(" suffix=")" suffixOverrides="," >
       <if test="bk_bankcode != null" >
@@ -134,6 +134,12 @@
       <if test="bk_remark != null" >
         bk_remark,
       </if>
+      <if test="bk_spending != null" >
+        bk_spending,
+      </if>
+      <if test="bk_income != null" >
+        bk_income,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides="," >
       <if test="bk_bankcode != null" >
@@ -199,9 +205,15 @@
       <if test="bk_remark != null" >
         #{bk_remark,jdbcType=LONGVARCHAR},
       </if>
+      <if test="bk_spending != null" >
+        #{bk_spending,jdbcType=DOUBLE},
+      </if>
+      <if test="bk_income != null" >
+        #{bk_income,jdbcType=DOUBLE},
+      </if>
     </trim>
   </insert>
-  <update id="updateByPrimaryKeySelective" parameterType="com.usoftchina.saas.money.po.Bankinformation" >
+  <update id="updateByPrimaryKeySelective" parameterType="com.usoftchina.saas.document.entities.Bankinformation" >
     update bankinformation
     <set >
       <if test="bk_bankcode != null" >
@@ -267,6 +279,12 @@
       <if test="bk_remark != null" >
         bk_remark = #{bk_remark,jdbcType=LONGVARCHAR},
       </if>
+      <if test="bk_income != null" >
+        bk_income = #{bk_income,jdbcType=DOUBLE},
+      </if>
+      <if test="bk_spending != null" >
+        bk_spending = #{bk_spending,jdbcType=DOUBLE},
+      </if>
     </set>
     where bk_id = #{id,jdbcType=INTEGER}
   </update>

+ 1 - 1
applications/money/money-server/src/main/resources/mapper/PaybalanceMapper.xml

@@ -604,7 +604,7 @@
   </update>
 
 <select id="selectThisamount" parameterType="java.lang.Integer" resultType="java.lang.Double">
-  select bk_thisamount from bankinformation where bk_id = #{id,jdbcType=INTEGER}
+  select bk_beginamount from bankinformation where bk_id = #{id,jdbcType=INTEGER}
 </select>
 
 <!-- 供应商-->