Browse Source

no message

ly 1 year ago
parent
commit
d266e216ac

+ 5 - 0
src/main/java/cn/ezhizao/project/business/order/domain/BizArchiveInputDetail.java

@@ -120,4 +120,9 @@ public class BizArchiveInputDetail extends BaseEntity
     @TableField(exist = false)
     private BigDecimal arrived;
 
+    @TableField(exist = false)
+    private BigDecimal payment;
+    @TableField(exist = false)
+    private BigDecimal reallyAmount;
+
 }

+ 78 - 11
src/main/java/cn/ezhizao/project/business/payment/controller/BizPaymentController.java

@@ -11,6 +11,9 @@ import cn.ezhizao.framework.web.page.TableDataInfo;
 import cn.ezhizao.project.business.account.domain.BizAccount;
 import cn.ezhizao.project.business.account.service.IBizAccountService;
 import cn.ezhizao.project.business.collection.domain.BizCollection;
+import cn.ezhizao.project.business.collection.domain.BizCollectionDetail;
+import cn.ezhizao.project.business.collection.service.IBizCollectionDetailService;
+import cn.ezhizao.project.business.collection.service.IBizCollectionService;
 import cn.ezhizao.project.business.order.domain.BizArchiveInputDetail;
 import cn.ezhizao.project.business.payment.domain.BizPayment;
 import cn.ezhizao.project.business.company.domain.BizCompany;
@@ -30,6 +33,7 @@ import cn.ezhizao.project.system.domain.SysUser;
 import cn.ezhizao.project.system.service.ISysFileStorageService;
 import cn.ezhizao.project.system.service.ISysUserService;
 import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -39,7 +43,9 @@ import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
+import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 @RestController
@@ -68,6 +74,10 @@ public class BizPaymentController extends BaseController {
     IBizPaymentSubjectService paymentSubjectService;
     @Resource
     IBizAccountService accountService;
+    @Resource
+    IBizCollectionService collectionService;
+    @Resource
+    IBizCollectionDetailService collectionDetailService;
 
     @PreAuthorize("@ss.hasPermi('business:payment:query')")
     @GetMapping(value = "/{id}")
@@ -166,8 +176,7 @@ public class BizPaymentController extends BaseController {
 
     @PreAuthorize("@ss.hasAnyPermi('business:payment:query')")
     @GetMapping("/listCompany")
-    public TableDataInfo listCompany(BizCompany bizCompany) throws NoSuchFieldException, IllegalAccessException
-    {
+    public TableDataInfo listCompany(BizCompany bizCompany) throws NoSuchFieldException, IllegalAccessException {
         setTenantId(bizCompany);
         startPage();
         List<BizCompany> list = companyService.getList(bizCompany);
@@ -175,16 +184,15 @@ public class BizPaymentController extends BaseController {
     }
 
 
-
     @ApiOperation("获取合同")
     @GetMapping("/listContract")
     @PreAuthorize("@ss.hasPermi('business:payment:query')")
     @ResponseBody
-    public TableDataInfo listContract(BizArchiveInput condition) throws NoSuchFieldException, IllegalAccessException
-    {
+    public TableDataInfo listContract(BizArchiveInput condition) throws NoSuchFieldException, IllegalAccessException {
         setTenantId(condition);
         startPage();
         List<BizArchiveInput> list = archiveInputService.getList(condition);
+
         return getDataTable(list);
     }
 
@@ -196,6 +204,30 @@ public class BizPaymentController extends BaseController {
         setTenantId(condition);
         startPage();
         List<BizArchiveInputDetail> list = contractDetailService.getList(condition);
+
+        Long contractId = condition.getContractId();
+        List<BizCollection> collectionList = collectionService.list(new LambdaQueryWrapper<BizCollection>().eq(BizCollection::getContractId, contractId).eq(BizCollection::getStatus, 1).eq(BizCollection::getArriveStatus, 1));
+        List<Long> idCollectionList = collectionList.stream().map(m -> m.getId()).collect(Collectors.toList());
+        if (idCollectionList.size() > 0) {
+            List<BizCollectionDetail> detailList = collectionDetailService.list(new LambdaQueryWrapper<BizCollectionDetail>().in(BizCollectionDetail::getCollectionId, idCollectionList));
+            Map<Long, BigDecimal> collect = detailList.stream().collect(Collectors.groupingBy(BizCollectionDetail::getTaskTypeId, Collectors.reducing(BigDecimal.ZERO, BizCollectionDetail::getArriveAmount, BigDecimal::add)));
+            for (BizArchiveInputDetail detail : list) {
+                BigDecimal bigDecimal = collect.get(detail.getTaskTypeId());
+                detail.setReallyAmount(bigDecimal);
+            }
+        }
+        List<BizPayment> paymentList = paymentService.list(new LambdaQueryWrapper<BizPayment>().eq(BizPayment::getContractId, contractId).eq(BizPayment::getPaymentStatus, 1).eq(BizPayment::getVerifyStatus, 3));
+        List<Long> idList = paymentList.stream().map(m -> m.getId()).collect(Collectors.toList());
+        if (idList.size() > 0) {
+            List<BizPaymentDetail> bizPaymentDetailList = paymentDetailService.list(new LambdaQueryWrapper<BizPaymentDetail>().in(BizPaymentDetail::getPaymentId, idList));
+            Map<Long, BigDecimal> taskTypeToTotalAmount = bizPaymentDetailList.stream()
+                    .collect(Collectors.groupingBy(BizPaymentDetail::getTaskTypeId,
+                            Collectors.reducing(BigDecimal.ZERO, BizPaymentDetail::getPaymentAmount, BigDecimal::add)));
+            for (BizArchiveInputDetail detail : list) {
+                BigDecimal bigDecimal = taskTypeToTotalAmount.get(detail.getTaskTypeId());
+                detail.setPayment(bigDecimal);
+            }
+        }
         return getDataTable(list);
     }
 
@@ -206,7 +238,7 @@ public class BizPaymentController extends BaseController {
     public AjaxResult remove(@PathVariable List<Long> ids) {
         //查询所有需要删除的数据
         List<BizPayment> list = paymentService.getByIds(ids);
-        for (BizPayment l:list){
+        for (BizPayment l : list) {
             //判读是否已经审核
             if (l.getVerifyStatus() == 1) {
                 //已经审核无法删除
@@ -214,7 +246,7 @@ public class BizPaymentController extends BaseController {
             }
         }
         //全未审核则删除
-        return toAjax(paymentService.removeBatchByIds(ids)&&paymentService.removePaymentDetail(ids));
+        return toAjax(paymentService.removeBatchByIds(ids) && paymentService.removePaymentDetail(ids));
     }
 
 
@@ -233,7 +265,7 @@ public class BizPaymentController extends BaseController {
                 payment.setContractAmount(archiveInput.getTrueAmount());
                 BizPayment payemntConditions = new BizPayment();
                 payemntConditions.setContractId(archiveInput.getId());
-                payemntConditions.setPaymentStatus((byte)1);
+                payemntConditions.setPaymentStatus((byte) 1);
                 List<BizPayment> payed = paymentService.getListByBean(payemntConditions);
 //                payment.setNonpayment(archiveInput.getAmount().subtract(BigDecimal.valueOf(collections.stream().mapToDouble(v -> v.getAmount().doubleValue()).sum())).compareTo(BigDecimal.ZERO) > 0);
                 payment.setPayedAmount(BigDecimal.valueOf(payed.stream().mapToDouble(v -> v.getAmount().doubleValue()).sum()));
@@ -251,10 +283,45 @@ public class BizPaymentController extends BaseController {
             detailCondition.setPaymentId(payment.getId());
             List<BizPaymentDetail> details = paymentDetailService.getListByBean(detailCondition);
             payment.setDetails(details);
+            totalAmountPaid(payment, details);
+            totalAmountReceived(payment, details);
         }
         return payment;
     }
 
+    private void totalAmountReceived(BizPayment payment, List<BizPaymentDetail> details) {
+        //-------已收款总金额
+        Long contractId = payment.getContractId();
+        List<BizCollection> collectionList = collectionService.list(new LambdaQueryWrapper<BizCollection>().eq(BizCollection::getContractId, contractId).eq(BizCollection::getStatus, 1).eq(BizCollection::getArriveStatus, 1));
+        List<Long> idCollectionList = collectionList.stream().map(m -> m.getId()).collect(Collectors.toList());
+        if (idCollectionList.size() > 0) {
+            List<BizCollectionDetail> detailList = collectionDetailService.list(new LambdaQueryWrapper<BizCollectionDetail>().in(BizCollectionDetail::getCollectionId, idCollectionList));
+            Map<Long, BigDecimal> collect = detailList.stream().collect(Collectors.groupingBy(BizCollectionDetail::getTaskTypeId, Collectors.reducing(BigDecimal.ZERO, BizCollectionDetail::getArriveAmount, BigDecimal::add)));
+            for (BizPaymentDetail detail : details) {
+                BigDecimal bigDecimal = collect.get(detail.getTaskTypeId());
+                detail.setReallyAmount(bigDecimal);
+            }
+        }
+        //-------已收款总金额
+    }
+
+    private void totalAmountPaid(BizPayment payment, List<BizPaymentDetail> details) {
+        //-------已支付总金额
+        List<BizPayment> list = paymentService.list(new LambdaQueryWrapper<BizPayment>().eq(BizPayment::getContractId, payment.getContractId()).eq(BizPayment::getPaymentStatus, 1).eq(BizPayment::getVerifyStatus, 3));
+        List<Long> idList = list.stream().map(m -> m.getId()).collect(Collectors.toList());
+        if (idList.size() > 0) {
+            List<BizPaymentDetail> bizPaymentDetailList = paymentDetailService.list(new LambdaQueryWrapper<BizPaymentDetail>().in(BizPaymentDetail::getPaymentId, idList));
+            Map<Long, BigDecimal> taskTypeToTotalAmount = bizPaymentDetailList.stream()
+                    .collect(Collectors.groupingBy(BizPaymentDetail::getTaskTypeId,
+                            Collectors.reducing(BigDecimal.ZERO, BizPaymentDetail::getPaymentAmount, BigDecimal::add)));
+            for (BizPaymentDetail detail : details) {
+                BigDecimal bigDecimal = taskTypeToTotalAmount.get(detail.getTaskTypeId());
+                detail.setPayment(bigDecimal);
+            }
+        }
+        //-------
+    }
+
     @ApiOperation("审核")
     @PostMapping("/verified")
     @Log(title = "支付审核", businessType = BusinessType.UPDATE)
@@ -280,8 +347,8 @@ public class BizPaymentController extends BaseController {
         startPage();
         startOrderBy();
         List<BizPayment> list = paymentService.getListByBean(payment);
-        list.forEach(l->{
-            switch(l.getVerifyStatus()){
+        list.forEach(l -> {
+            switch (l.getVerifyStatus()) {
                 case 0:
                     l.setVerifyStatusStr("未审核");
                     break;
@@ -299,7 +366,7 @@ public class BizPaymentController extends BaseController {
                     break;
             }
 
-            switch(l.getPaymentStatus()){
+            switch (l.getPaymentStatus()) {
                 case 0:
                     l.setPaymentStatusStr("未支付");
                     break;

+ 2 - 0
src/main/java/cn/ezhizao/project/business/payment/domain/BizPaymentDetail.java

@@ -66,6 +66,8 @@ public class BizPaymentDetail extends BaseEntity {
     @TableField(exist = false)
     private BigDecimal payment;
     @TableField(exist = false)
+    private BigDecimal reallyAmount;
+    @TableField(exist = false)
     private BigDecimal arrived;
 
     @ApiModelProperty("账套外键")

+ 3 - 3
src/main/resources/mybatis/business/BizPaymentDetailMapper.xml

@@ -31,9 +31,9 @@
         SELECT t1.*, t2.name as task_type_name,
         (select sum(cd.arrive_amount) from biz_collection_detail cd left join biz_collection c on c.id =
         cd.collection_id where cd.deleted = 0 and c.status = 1 and cd.contract_detail_id = t1.contract_detail_id)
-        arrived,
-        (select sum(payment_amount) from biz_payment_detail pd where pd.deleted = 0
-        and pd.contract_detail_id = t1.contract_detail_id) payment
+        arrived
+--         (select sum(payment_amount) from biz_payment_detail pd where pd.deleted = 0
+--         and pd.contract_detail_id = t1.contract_detail_id) payment
         FROM biz_payment_detail t1
         left join biz_task_type t2 on t2.id = t1.task_type_id
         WHERE t1.deleted = 0