Browse Source

发起投资金额判定设置

anderx 3 years ago
parent
commit
0bc4665c96

+ 20 - 3
src/main/java/com/goafanti/ambSystem/service/Impl/AmbInvestServiceImpl.java

@@ -50,6 +50,7 @@ public class AmbInvestServiceImpl extends BaseMybatisDao<AmbInvestMapper> implem
             myAmb= ambSystemMapper.selectByPrimaryKey(1l);
         }else {
             myAmb=ambSystemMapper.selectByPrimaryKey(in.getMyAmbId());
+            chekAmount(in, myAmb);
         }
         AmbSystem other=ambSystemMapper.selectByPrimaryKey(in.getOtherAmbId());
         AmbInvest ambInvest=new AmbInvest();
@@ -66,6 +67,20 @@ public class AmbInvestServiceImpl extends BaseMybatisDao<AmbInvestMapper> implem
         return 1;
     }
 
+    private void chekAmount(InputAmbInvest in, AmbSystem myAmb) {
+        if (myAmb.getLvl()!=1){
+            List<OutInvestList> outInvestLists = ambInvestMapper.selectAmbInvestDtailsList(in.getMyAmbId(), 0);
+            BigDecimal count = new BigDecimal(0);
+            for (OutInvestList outInvestList : outInvestLists) {
+                count=count.add(outInvestList.getAmount());
+            }
+            count=count.add(in.getAmount());
+            if (count.compareTo(myAmb.getSurplus())>0){
+                throw new BusinessException("对外投资金额加上本次投资金额不可大于收到的投资金额!(注意已发起的投资金额)");
+            }
+        }
+    }
+
     private void sumCountAmount(Long id, AmbInvest ambInvest) {
         Integer x=ambInvestMapper.selectCountAmountById(id);
         if (x==null)x=0;
@@ -130,6 +145,7 @@ public class AmbInvestServiceImpl extends BaseMybatisDao<AmbInvestMapper> implem
     @Override
     public int updateInvestTransfer(InputAmbInvest in) {
         AmbSystem myAmb = ambSystemMapper.selectByPrimaryKey(in.getMyAmbId());
+        chekAmount(in, myAmb);
         AmbSystem other=ambSystemMapper.selectByPrimaryKey(in.getOtherAmbId());
         AmbInvest ambInvest=new AmbInvest();
         ambInvest.setId(in.getId());
@@ -158,14 +174,15 @@ public class AmbInvestServiceImpl extends BaseMybatisDao<AmbInvestMapper> implem
         newAmbInvest.setStatus(in.getStatus());
         newAmbInvest.setAmount(ambInvest.getAmount());
         if (in.getStatus()==2){
-            if (!(myAmb.getId()==1L)){
                 AmbSystem newMy=new AmbSystem();
                 newMy.setId(myAmb.getId());
+            if (!(myAmb.getId()==1L)){
+                newMy.setForeign(myAmb.getForeign().add(ambInvest.getAmount()));
+            }else {
                 newMy.setTotalAmount(myAmb.getTotalAmount().subtract(ambInvest.getAmount()));
                 newMy.setSurplus(myAmb.getSurplus().subtract(ambInvest.getAmount()));
-                newMy.setForeign(myAmb.getForeign().add(ambInvest.getAmount()));
-                ambSystemMapper.updateByPrimaryKeySelective(newMy);
             }
+            ambSystemMapper.updateByPrimaryKeySelective(newMy);
             AmbSystem newOther=new AmbSystem();
             newOther.setId(other.getId());
             newOther.setReceived(other.getReceived().add(ambInvest.getAmount()));

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

@@ -194,13 +194,11 @@
            b.name initiateName,c.name acceptName,d.name operator
     from amb_invest  a left join amb_system b on a.initiate_amb_id =b.id
     left join amb_system c on a.accept_amb_id =c.id left join admin d on a.operator =d.id
-    where  a.status =2
+    where  1=1
     <if test="type==0">
-      and a.initiate_amb_id= #{id}
-    </if>
-    <if test="type==1">
-      and a.accept_amb_id = #{id}
+      and a.status in (0,1,3)
     </if>
+      and a.initiate_amb_id= #{id}
     order by  a.create_time desc
   </select>
 </mapper>