Browse Source

新增每次通过后计算累计

anderx 3 years ago
parent
commit
16c0b437bb

+ 8 - 9
src/main/java/com/goafanti/ambSystem/service/Impl/AmbInvestServiceImpl.java

@@ -52,16 +52,19 @@ public class AmbInvestServiceImpl extends BaseMybatisDao<AmbInvestMapper> implem
         ambInvest.setStatus(in.getStatus());
         ambInvest.setOperator(TokenManager.getAdminId());
         ambInvest.setComment(in.getComment());
-        Integer x=ambInvestMapper.selectCountAmountById(other.getId());
-        if (x!=null){
-            ambInvest.setCountAmount(ambInvest.getAmount().add(new BigDecimal(x)));
-        }
+        sumCountAmount(other.getId(), ambInvest);
         ambInvestMapper.insertSelective(ambInvest);
         addAmbInvestLog(in, ambInvest);
         if (in.getStatus()==1)addNoticAndEmail(1,myAmb,other);
         return 1;
     }
 
+    private void sumCountAmount(Long id, AmbInvest ambInvest) {
+        Integer x=ambInvestMapper.selectCountAmountById(id);
+        if (x==null)x=0;
+        ambInvest.setCountAmount(ambInvest.getAmount().add(new BigDecimal(x)));
+    }
+
     private void addNoticAndEmail(Integer i,AmbSystem myAmb,AmbSystem other) {
         StringBuffer str=new StringBuffer();
         Integer notceType=0;
@@ -152,12 +155,8 @@ public class AmbInvestServiceImpl extends BaseMybatisDao<AmbInvestMapper> implem
             newOther.setTotalAmount(other.getTotalAmount().add(ambInvest.getAmount()));
             ambSystemMapper.updateByPrimaryKeySelective(newMy);
             ambSystemMapper.updateByPrimaryKeySelective(newOther);
-            Integer x=ambInvestMapper.selectCountAmountById(newOther.getId());
-            if (x!=null){
-                newAmbInvest.setCountAmount(ambInvest.getAmount().add(new BigDecimal(x)));
-            }
+            sumCountAmount(newOther.getId(), newAmbInvest);
         }
-
         ambInvestMapper.updateByPrimaryKeySelective(newAmbInvest);
         addAmbInvestLog(in, ambInvest);
         addNoticAndEmail(in.getStatus(),myAmb,other);

+ 1 - 1
src/main/java/com/goafanti/common/mapper/AmbInvestMapper.xml

@@ -159,6 +159,6 @@
   <select id="selectCountAmountById" resultType="java.lang.Integer">
     select sum(amount)amount
     from amb_invest
-    where accept_amb_id = #{id}
+    where status=2 and  accept_amb_id = #{id}
   </select>
 </mapper>