anderx лет назад: 3
Родитель
Сommit
a8729e45d6

+ 19 - 0
src/main/java/com/goafanti/ambSystem/bo/InputAmbInvest.java

@@ -1,15 +1,34 @@
 package com.goafanti.ambSystem.bo;
 
+import com.goafanti.common.constant.ErrorConstants;
+import com.goafanti.common.utils.Param;
+
+import javax.validation.constraints.NotNull;
 import java.math.BigDecimal;
 
 public class InputAmbInvest {
+    private Long id;
+    @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
+    @Param(name = "发起阿米巴编号")
     private Long myAmbId;
+    @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
+    @Param(name = "接收阿米巴编号")
     private Long otherAmbId;
+    @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
+    @Param(name = "金额")
     private BigDecimal amount;
     private String comment;
     private Integer status;
 
 
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
     public Integer getStatus() {
         return status;
     }

+ 47 - 11
src/main/java/com/goafanti/ambSystem/controller/AmbInvestApiController.java

@@ -8,6 +8,7 @@ import com.goafanti.ambSystem.service.AmbService;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
+import com.goafanti.common.enums.ActivityFields;
 import com.goafanti.common.utils.ParamUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.BindingResult;
@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.validation.Valid;
 import java.math.BigDecimal;
 
 
@@ -26,18 +28,15 @@ public class AmbInvestApiController extends CertifyApiController {
 	private AmbInvestService ambInvestService;
 
 	/**
-	 * 划拨金额
+	 * 投资金额
 	 * @return
 	 */
-	@RequestMapping(value="/transfer",method = RequestMethod.POST)
-	public Result transfer(InputAmbInvest in){
+	@RequestMapping(value="/addTransfer",method = RequestMethod.POST)
+	public Result transfer(@Validated InputAmbInvest in  , BindingResult bindingResult){
 		Result res =new Result();
-		if (in.getMyAmbId()==null){
-			res.getError().add(buildErrorMessageParams(ErrorConstants.PARAM_EMPTY_ERROR,"阿米巴编号"));
-			return res;
-		}
-		if (in.getAmount()==null){
-			res.getError().add(buildErrorMessageParams(ErrorConstants.PARAM_EMPTY_ERROR,"金额"));
+		if (bindingResult.hasErrors()) {
+			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
+					ParamUtils.getParamName(in,bindingResult.getFieldError().getField())));
 			return res;
 		}
 		if (in.getStatus()==null){
@@ -56,7 +55,7 @@ public class AmbInvestApiController extends CertifyApiController {
 
 
 	/**
-	 * 划拨列表
+	 * 投资列表
 	 * @return
 	 */
 	@RequestMapping(value="/InvestList",method = RequestMethod.GET)
@@ -67,7 +66,7 @@ public class AmbInvestApiController extends CertifyApiController {
 	}
 
 	/**
-	 * 划拨日志
+	 * 投资日志
 	 * @return
 	 */
 	@RequestMapping(value="/InvestLog",method = RequestMethod.GET)
@@ -77,4 +76,41 @@ public class AmbInvestApiController extends CertifyApiController {
 		return res;
 	}
 
+	/**
+	 * 修改投资金额
+	 * @return
+	 */
+	@RequestMapping(value="/updateTransfer",method = RequestMethod.POST)
+	public Result updateTransfer(InputAmbInvest in){
+		Result res =new Result();
+		if (in.getStatus()==null){
+			in.setStatus(0);
+		} else if (in.getStatus()>1){
+			res.getError().add(buildError("状态不可大于发起。"));
+			return res;
+		}
+		if (in.getMyAmbId()!=null&&ambInvestService.checkMyAmb(in.getMyAmbId())){
+			res.getError().add(buildError("只有当前阿米巴负责人可以发起投资划拨。"));
+			return res;
+		}
+		res.data(ambInvestService.updateInvestTransfer(in));
+		return res;
+	}
+
+	/**
+	 * 修改投资金额
+	 * @return
+	 */
+	@RequestMapping(value="/examineTransfer",method = RequestMethod.POST)
+	public Result examineTransfer(InputAmbInvest in){
+		Result res =new Result();
+		if (in.getStatus()<1){
+			res.getError().add(buildError("状态不可小于。"));
+			return res;
+		}
+
+		res.data(ambInvestService.updateExamineTransfer(in));
+		return res;
+	}
+
 }

+ 4 - 0
src/main/java/com/goafanti/ambSystem/service/AmbInvestService.java

@@ -15,4 +15,8 @@ public interface AmbInvestService {
     Pagination<?> InvestList(InputInvestList in);
 
     List<OutInvestLog> InvestLog(String id);
+
+    int updateInvestTransfer(InputAmbInvest in);
+
+    int updateExamineTransfer(InputAmbInvest in);
 }

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

@@ -51,17 +51,31 @@ public class AmbInvestServiceImpl extends BaseMybatisDao<AmbInvestMapper> implem
         ambInvest.setOperator(TokenManager.getAdminId());
         ambInvest.setComment(in.getComment());
         ambInvestMapper.insertSelective(ambInvest);
-        AmbInvestLog log=new AmbInvestLog();
-        log.setAmbInvestId(ambInvest.getId());
-        log.setComment(in.getComment());
-        log.setOperator(TokenManager.getAdminId());
-        log.setStatus(1);
-        ambInvestLogMapper.insertSelective(log);
-        String str="["+myAmb.getName()+"]管理员发起了对["+other.getName()+"]"+"的金额投资,请及时确认!";
-        asyncUtils.addNoticAndEmail(myAmb.getAccountant(), NoticeStatus.AMB_INVEST_START.getCode(),str );
+        addAmbInvestLog(in, ambInvest);
+        if (in.getStatus()==1)addNoticAndEmail(1,myAmb,other);
         return 1;
     }
 
+    private void addNoticAndEmail(Integer i,AmbSystem myAmb,AmbSystem other) {
+        StringBuffer str=new StringBuffer();
+        Integer notceType=0;
+        String aid="";
+        if (i==1){
+            aid=myAmb.getAccountant();
+            str=str.append("[").append(myAmb.getName()).append("]负责人发起了对[").append(other.getName()).append("]"+"的金额投资,请及时确认!");
+            notceType=NoticeStatus.AMB_INVEST_START.getCode();
+        }else if (i==2){
+            str=str.append("发起的对[").append(other.getName()).append("]"+"的金额投资,已通过审核!");
+            notceType=NoticeStatus.AMB_INVEST_YES.getCode();
+            aid=myAmb.getLeader();
+        }else if (i==3){
+            str=str.append("发起的对[").append(other.getName()).append("]"+"的金额投资,已拒绝,请及时修改!");
+            notceType=NoticeStatus.AMB_INVEST_NO.getCode();
+            aid=myAmb.getLeader();
+        }
+            asyncUtils.addNoticAndEmail(aid,notceType ,str.toString());
+    }
+
     @Override
     public boolean checkMyAmb(Long myAmbId) {
         AmbSystem myAmb = ambSystemMapper.selectByPrimaryKey(myAmbId);
@@ -85,4 +99,56 @@ public class AmbInvestServiceImpl extends BaseMybatisDao<AmbInvestMapper> implem
     public List<OutInvestLog> InvestLog(String id) {
         return ambInvestLogMapper.selectByAmbInvestId(id);
     }
+
+    @Override
+    public int updateInvestTransfer(InputAmbInvest in) {
+        AmbSystem myAmb = ambSystemMapper.selectByPrimaryKey(in.getMyAmbId());
+        AmbSystem other=ambSystemMapper.selectByPrimaryKey(in.getOtherAmbId());
+        AmbInvest ambInvest=new AmbInvest();
+        ambInvest.setId(in.getId());
+        if (in.getOtherAmbId()!=null)ambInvest.setAcceptAmbId(in.getOtherAmbId());
+        if (in.getAmount()!=null)ambInvest.setAmount(in.getAmount());
+        if (in.getStatus()!=null)ambInvest.setStatus(in.getStatus());
+        if (in.getComment()!=null)ambInvest.setComment(in.getComment());
+        ambInvest.setOperator(TokenManager.getAdminId());
+        ambInvestMapper.updateByPrimaryKeySelective(ambInvest);
+        addAmbInvestLog(in, ambInvest);
+        if (in.getStatus()==1)addNoticAndEmail(1,myAmb,other);
+        return 1;
+    }
+
+    @Override
+    @Transactional
+    public int updateExamineTransfer(InputAmbInvest in) {
+        AmbInvest ambInvest = ambInvestMapper.selectByPrimaryKey(in.getId());
+        AmbSystem myAmb = ambSystemMapper.selectByPrimaryKey(ambInvest.getInitiateAmbId());
+        AmbSystem other=ambSystemMapper.selectByPrimaryKey(ambInvest.getAcceptAmbId());
+        AmbInvest newAmbInvest=new AmbInvest();
+        newAmbInvest.setId(in.getId());
+        newAmbInvest.setStatus(in.getStatus());
+        if (in.getStatus()==2){
+            AmbSystem newMy=new AmbSystem();
+            newMy.setId(myAmb.getId());
+            newMy.setSurplus(myAmb.getSurplus().subtract(ambInvest.getAmount()));
+            newMy.setForeign(myAmb.getForeign().add(ambInvest.getAmount()));
+            AmbSystem newOther=new AmbSystem();
+            newOther.setId(other.getId());
+            newOther.setReceived(other.getReceived().add(ambInvest.getAmount()));
+            ambSystemMapper.updateByPrimaryKeySelective(newMy);
+            ambSystemMapper.updateByPrimaryKeySelective(newOther);
+        }
+        ambInvestMapper.updateByPrimaryKeySelective(newAmbInvest);
+        addAmbInvestLog(in, ambInvest);
+        addNoticAndEmail(in.getStatus(),myAmb,other);
+        return 1;
+    }
+
+    private void addAmbInvestLog(InputAmbInvest in, AmbInvest ambInvest) {
+        AmbInvestLog log = new AmbInvestLog();
+        log.setAmbInvestId(ambInvest.getId());
+        log.setComment(in.getComment());
+        log.setOperator(TokenManager.getAdminId());
+        log.setStatus(in.getStatus());
+        ambInvestLogMapper.insertSelective(log);
+    }
 }