Browse Source

回款登记子项目问题修改

yewc 9 months ago
parent
commit
f1c390f161

+ 4 - 3
zjugis-business/src/main/java/com/zjugis/business/flow/contractinvoice/service/FlowContractInvoiceService.java

@@ -132,18 +132,19 @@ public class FlowContractInvoiceService {
                         }
                     }
                     map.put("project", project);
-                    ProjectAmount projectAmount = projectAmountService.selectById(contract.getProjectId());
+                    //获取所有主、子合同相加的数据
+                    ProjectAmount projectAmount = projectAmountService.getProjectByParentId(contract.getProjectId());
                     if (projectAmount != null) {
                         map.put("amount", projectAmount);
                     }
                 }
                 if (contract.getMainType() != null) {
                     CommonResult<DictDataRespDTO> result = dictDataApi.getDictData(DictConstants.TYPE_CONTRACT_MAIN_TYPE, String.valueOf(contract.getMainType()));
-                    map.put("mainType", result.getCheckedData().getLabel());
+                    //map.put("mainType", result.getCheckedData().getLabel());
                 }
                 if (contract.getSecondType() != null) {
                     CommonResult<DictDataRespDTO> result = dictDataApi.getDictData(DictConstants.TYPE_CONTRACT_SECOND_TYPE, String.valueOf(contract.getSecondType()));
-                    map.put("secondType", result.getCheckedData().getLabel());
+                   // map.put("secondType", result.getCheckedData().getLabel());
                 }
             }
         }

+ 2 - 0
zjugis-business/src/main/java/com/zjugis/business/mapper/ContractInvoiceRelationMapper.java

@@ -23,5 +23,7 @@ public interface ContractInvoiceRelationMapper extends BaseMapperX<ContractInvoi
     void updateAmount(@Param("params") ContractInvoiceRelation item);
 
     List<ContractInvoiceRelation> selectAmountByProjectIds(@Param("ids")List<String> projectIds);
+
+    ContractInvoiceRelation geSumDataByContractId(String contractId);
 }
 

+ 2 - 0
zjugis-business/src/main/java/com/zjugis/business/mapper/ProjectAmountMapper.java

@@ -29,4 +29,6 @@ public interface ProjectAmountMapper extends BaseMapperX<ProjectAmount> {
     default List<ProjectAmount> selectByIds(Set<String> ids){
         return selectList(new LambdaQueryWrapperX<ProjectAmount>().in(ProjectAmount::getProjectId,ids));
     }
+
+    ProjectAmount getProjectByParentId(String projectId);
 }

+ 2 - 0
zjugis-business/src/main/java/com/zjugis/business/service/ContractInvoiceRelationService.java

@@ -27,5 +27,7 @@ public interface ContractInvoiceRelationService {
     List<ContractInvoiceRelation> selectAmountByProjectIds(List<String> projectIds);
 
     void updateById(ContractInvoiceRelation relation);
+
+    ContractInvoiceRelation geSumDataByContractId(String contractId);
 }
 

+ 2 - 0
zjugis-business/src/main/java/com/zjugis/business/service/ProjectAmountService.java

@@ -37,4 +37,6 @@ public interface ProjectAmountService {
     ContractInfoResp selectCostSum(ProjectDto projectAmountDto);
 
     List<ProjectAmount> selectByIds(Set<String> ids);
+
+    ProjectAmount getProjectByParentId(String projectId);
 }

+ 2 - 0
zjugis-business/src/main/java/com/zjugis/business/service/ProjectService.java

@@ -111,5 +111,7 @@ public interface ProjectService {
     List<FileResponse> getProjectFile(String projectId);
 
     void materialUploadToFlow(String flowInstanceId,String projectId) throws Exception;
+
+    void updateProjectAmount(String projectId,String contractId);
 }
 

+ 5 - 0
zjugis-business/src/main/java/com/zjugis/business/service/impl/ContractInvoiceRelationServiceImpl.java

@@ -88,4 +88,9 @@ public class ContractInvoiceRelationServiceImpl implements ContractInvoiceRelati
     public void updateById(ContractInvoiceRelation relation) {
         contractInvoiceRelationMapper.updateById(relation);
     }
+
+    @Override
+    public ContractInvoiceRelation geSumDataByContractId(String contractId) {
+        return contractInvoiceRelationMapper.geSumDataByContractId(contractId);
+    }
 }

+ 2 - 1
zjugis-business/src/main/java/com/zjugis/business/service/impl/ContractMessageServiceImpl.java

@@ -153,7 +153,8 @@ public class ContractMessageServiceImpl implements ContractMessageService {
         ContractMessage message = null;
         if(StringUtils.isNotBlank(contractReturnMoney.getId())) {
             QueryWrapper<ContractMessage> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("BUSINESS_ID", contractReturnMoney.getId()).eq("MESSAGE_TYPE", 2);
+            queryWrapper.eq("BUSINESS_ID", contractReturnMoney.getId()).eq("MESSAGE_TYPE", 2)
+                    .eq("contract_id", contractReturnMoney.getContractId());
             message = contractMessageMapper.selectOne(queryWrapper);
         }
         if(message == null) {

+ 20 - 4
zjugis-business/src/main/java/com/zjugis/business/service/impl/ContractReturnMoneyServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.nacos.common.utils.StringUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zjugis.business.bean.entity.Contract;
+import com.zjugis.business.bean.entity.ContractInvoiceRelation;
 import com.zjugis.business.bean.entity.ContractReturnMoney;
 import com.zjugis.business.bean.response.ContractReturnMoneyResponse;
 import com.zjugis.business.mapper.ContractReturnMoneyMapper;
@@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.List;
 
 /**
@@ -76,14 +78,28 @@ public class ContractReturnMoneyServiceImpl implements ContractReturnMoneyServic
         if(contractReturnMoney.getRelationList() != null && !contractReturnMoney.getRelationList().isEmpty()){
             contractInvoiceRelationService.updateAmount(contractReturnMoney.getRelationList());
         }
-        Contract contract = contractService.selectByPrimaryKey(contractReturnMoney.getContractId());
-        if(StringUtils.isNotBlank(contract.getProjectId())) {
-            projectService.calcProject(contract.getProjectId());
+        for(ContractInvoiceRelation list: contractReturnMoney.getRelationList()){
+            Contract contract = contractService.selectByPrimaryKey(list.getContractId());
+            if(StringUtils.isNotBlank(contract.getProjectId())) {
+                projectService.calcProject(contract.getProjectId());
+                projectService.updateProjectAmount(contract.getProjectId(),list.getContractId());
+            }
         }
+
         contractInvoiceService.updateAmountStatus(contractReturnMoney.getContractInvoiceId());
         contractService.updateAmountStatus(contractReturnMoney.getContractId());
         if(!"冲红".equals(contractReturnMoney.getBz())){
-            contractMessageService.addByReturnMoney(contractReturnMoney);
+            BigDecimal sum=BigDecimal.ZERO;
+            for(ContractInvoiceRelation list: contractReturnMoney.getRelationList()){
+                sum=sum.add(list.getInvoiceAmount());
+            }
+            BigDecimal returnAmount=contractReturnMoney.getReturnAmount();
+            for(ContractInvoiceRelation list: contractReturnMoney.getRelationList()){
+                //获取主项目和子项目
+                contractReturnMoney.setReturnAmount(returnAmount.divide(sum,10, RoundingMode.HALF_UP).multiply(list.getInvoiceAmount()));
+                contractReturnMoney.setContractId(list.getContractId());
+                contractMessageService.addByReturnMoney(contractReturnMoney);
+            }
         }
         return contractReturnMoney.getId();
     }

+ 5 - 0
zjugis-business/src/main/java/com/zjugis/business/service/impl/ProjectAmountServiceImpl.java

@@ -128,4 +128,9 @@ public class ProjectAmountServiceImpl implements ProjectAmountService {
     public List<ProjectAmount> selectByIds(Set<String> ids) {
         return projectAmountMapper.selectByIds(ids);
     }
+
+    @Override
+    public ProjectAmount getProjectByParentId(String projectId) {
+        return projectAmountMapper.getProjectByParentId(projectId);
+    }
 }

+ 19 - 0
zjugis-business/src/main/java/com/zjugis/business/service/impl/ProjectServiceImpl.java

@@ -679,5 +679,24 @@ public class ProjectServiceImpl implements ProjectService {
             workflowClient.addList(item).getCheckedData();
         }
     }
+
+    /**
+     *  开票累加;
+     *  回款累加;
+     *  应收=开票-回款
+     *  余额=虚拟合同额-应收-回款;
+     * @param projectId
+     */
+    @Override
+    public void updateProjectAmount(String projectId,String contractId) {
+        ProjectAmount entity = projectAmountService.selectById(projectId);
+        ContractInvoiceRelation re=contractInvoiceRelationService.geSumDataByContractId(contractId);
+        entity.setProjectId(projectId);
+        entity.setReturnAmount(re.getReturnAmount());
+        entity.setInvoiceAmount(re.getInvoiceAmount());
+        entity.setReceivableAmount(re.getInvoiceAmount().subtract(re.getReturnAmount()));
+        entity.setContractBalance(entity.getContractAmount().subtract(entity.getReceivableAmount()).subtract(entity.getReturnAmount()));
+        projectAmountService.update(entity);
+    }
 }
 

+ 7 - 0
zjugis-business/src/main/resources/mapper/oracle/ContractInvoiceRelationMapper.xml

@@ -38,4 +38,11 @@
         </foreach>
         GROUP BY t.CONTRACT_ID
     </select>
+    <select id="geSumDataByContractId" resultType="com.zjugis.business.bean.entity.ContractInvoiceRelation">
+       select SUM(T.INVOICE_AMOUNT) AS invoiceAmount,
+              SUM(T.RETURN_AMOUNT) AS returnAmount
+       from CONTRACT_INVOICE_RELATION T
+        LEFT JOIN CONTRACT_INVOICE T1 ON T.CONTRACT_INVOICE_ID=T1.ID
+        where t.CONTRACT_ID=#{contractId} and t1.FLOW_STATUS in (101,102) and T1.ISVALID=1
+    </select>
 </mapper>

+ 10 - 0
zjugis-business/src/main/resources/mapper/oracle/ProjectAmountMapper.xml

@@ -56,4 +56,14 @@
             </if>
         </where>
     </select>
+    <select id="getProjectByParentId" resultType="com.zjugis.business.bean.entity.ProjectAmount">
+        select COALESCE(SUM(COALESCE(t.CONTRACT_BALANCE,0)),0) AS contractBalance,
+        COALESCE(SUM(COALESCE(t.RETURN_AMOUNT,0)),0) AS returnAmount,
+        COALESCE(SUM(COALESCE(t.INVOICE_AMOUNT,0)),0) AS invoiceAmount,
+        COALESCE(SUM(COALESCE(t.RECEIVABLE_AMOUNT,0)),0) AS receivableAmount
+        FROM PROJECT_AMOUNT t
+        where
+            PROJECT_ID=#{projectId} or MAIN_PROJECT_ID=#{projectId}
+
+    </select>
 </mapper>