Browse Source

虚拟合同逻辑完善,项目和合同人员适配

ljy121 1 year ago
parent
commit
8e5380c328

+ 5 - 5
zjugis-business/src/main/java/com/zjugis/business/bean/request/ContractRequest.java

@@ -13,7 +13,7 @@ import java.time.LocalDate;
  * @date 2023/11/17 14:19
  */
 @Data
-public class ContractRequest {
+public class  ContractRequest {
 
     /**
      * 合同ID
@@ -53,14 +53,14 @@ public class ContractRequest {
     private String assigneeName;
 
     /**
-     * 客户联系人
+     * 销售经理
      */
-    private String customerContact;
+    private String areaManager;
 
     /**
-     * 客户联系人ID
+     * 销售经理ID
      */
-    private String customerContactId;
+    private String areaManagerId;
 
     /**
      * 合同开始日期

+ 19 - 0
zjugis-business/src/main/java/com/zjugis/business/flow/contract/event/ContractEvent.java

@@ -1,9 +1,12 @@
 package com.zjugis.business.flow.contract.event;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zjugis.business.bean.entity.Contract;
+import com.zjugis.business.bean.entity.ContractAreaManager;
 import com.zjugis.business.bean.entity.Project;
 import com.zjugis.business.constants.FlowStatusConstants;
 import com.zjugis.business.flow.contract.service.FlowContractService;
+import com.zjugis.business.mapper.ContractAreaManagerMapper;
 import com.zjugis.business.mapper.ProjectMapper;
 import com.zjugis.business.service.ContractService;
 import com.zjugis.business.service.ProjectService;
@@ -43,6 +46,10 @@ public class ContractEvent extends BaseController {
     @Resource
     private FlowContractService flowContractService;
 
+
+    @Autowired
+    private ContractAreaManagerMapper contractAreaManagerMapper;
+
     @Autowired
     private ProjectService projectService;
 
@@ -96,11 +103,19 @@ public class ContractEvent extends BaseController {
                 entity.setVirtualAmount(entity.getContractAmount());
                 entity.setFlowStatus(FlowStatusConstants.FLOW_FINISHED);
                 entity.setFlowFinishtime(LocalDateTime.now());
+                QueryWrapper<ContractAreaManager> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("CONTRACT_ID",entity.getId());
+                List<ContractAreaManager> contractAreaManagers = contractAreaManagerMapper.selectList(queryWrapper);
                 String projectId = entity.getProjectId();
                 Project project = projectMapper.selectById(projectId);
                 project.setOutputValue(entity.getContractAmount());
+                if(!contractAreaManagers.isEmpty()){
+                    project.setXsryId(contractAreaManagers.get(0).getAreaManagerId());
+                    project.setXsry(contractAreaManagers.get(0).getAreaManagerName());
+                }
                 projectMapper.updateById(project);
                 flowContractService.updateById(entity);
+                updateVirtualContract(entity,project.getId());
                 return ok("true");
             } else {
                 throw new BusinessException("执行事件出错,请联系管理员!");
@@ -111,6 +126,10 @@ public class ContractEvent extends BaseController {
         }
     }
 
+    private void updateVirtualContract(Contract contract,String projectId) {
+        contractService.updateVirtualContract(contract,projectId);
+    }
+
     /**
      * 作废事件
      *

+ 1 - 21
zjugis-business/src/main/java/com/zjugis/business/flow/contract/service/FlowContractService.java

@@ -154,30 +154,10 @@ public class FlowContractService {
     }
 
     public int updateById(Contract contract) {
-        updateAreaManager(contract);
+        contractService.updateAreaManager(contract);
         return contractMapper.updateById(contract);
     }
 
-    private void updateAreaManager(Contract contract){
-        String areaManagerId = contract.getAreaManagerId();
-        String areaManagerName = contract.getAreaManager();
-        QueryWrapper<ContractAreaManager> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("CONTRACT_ID",contract.getId());
-        contractAreaManagerMapper.delete(queryWrapper);
-        List<ContractAreaManager> insertList = new ArrayList<>();
-        if(StringUtils.isNotBlank(areaManagerId)){
-            String[] ids = areaManagerId.split(",");
-            String[] names = areaManagerName.split(",");
-            for (int i = 0; i < ids.length; i++) {
-                ContractAreaManager contractAreaManager = new ContractAreaManager();
-                contractAreaManager.setContractId(contract.getId());
-                contractAreaManager.setAreaManagerId(ids[i]);
-                contractAreaManager.setAreaManagerName(names[i]);
-                insertList.add(contractAreaManager);
-            }
-        }
-        contractAreaManagerMapper.insertBatch(insertList);
-    }
 
     public Map<String, Object> getOutsourcingFormParams(String flowInstanceId) {
         String userId = SecurityFrameworkUtils.getLoginUserId();

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

@@ -26,4 +26,6 @@ public interface ContractMapper extends BaseMapperX<Contract> {
     AmountDto selectReceivableAmount(String contractId);
 
     List<Contract> selectVirtualList(String contractId);
+
+    void updateVirtualContractByProjectId(@Param("contract")Contract contract,@Param("ids") List<String> projectIds);
 }

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

@@ -37,5 +37,7 @@ public interface ProjectMapper extends BaseMapperX<Project> {
     SumResponse costSum(@Param("params") ProjectDto projectDto);
 
     BigDecimal selectChildrenOutputValue(String pid);
+
+    List<String> selectChildrenIds(String projectId);
 }
 

+ 4 - 0
zjugis-business/src/main/java/com/zjugis/business/service/ContractService.java

@@ -50,4 +50,8 @@ public interface ContractService{
     String outsourcing(String contractId);
 
     AmountDto selectReceivableAmount(String contractId);
+
+    void updateAreaManager(Contract contract);
+
+    void updateVirtualContract(Contract contract, String projectId);
 }

+ 65 - 0
zjugis-business/src/main/java/com/zjugis/business/service/impl/ContractServiceImpl.java

@@ -6,13 +6,18 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zjugis.business.bean.dto.AmountDto;
 import com.zjugis.business.bean.dto.ContractDto;
 import com.zjugis.business.bean.entity.Contract;
+import com.zjugis.business.bean.entity.ContractAreaManager;
+import com.zjugis.business.bean.entity.Project;
 import com.zjugis.business.bean.request.ContractRequest;
 import com.zjugis.business.bean.response.ContractChildResponse;
 import com.zjugis.business.bean.response.ContractResponse;
 import com.zjugis.business.constants.ContractConstants;
 import com.zjugis.business.constants.FlowStatusConstants;
+import com.zjugis.business.mapper.ContractAreaManagerMapper;
 import com.zjugis.business.mapper.ContractMapper;
+import com.zjugis.business.mapper.ProjectMapper;
 import com.zjugis.business.service.ContractService;
+import com.zjugis.business.service.ProjectService;
 import com.zjugis.framework.common.exception.ServiceException;
 import com.zjugis.framework.common.pojo.CommonResult;
 import com.zjugis.framework.security.core.util.SecurityFrameworkUtils;
@@ -51,6 +56,15 @@ public class ContractServiceImpl implements ContractService{
     @Autowired
     private WorkflowClient workflowClient;
 
+    @Autowired
+    private ContractAreaManagerMapper contractAreaManagerMapper;
+
+    @Autowired
+    private ProjectService projectService;
+
+    @Autowired
+    private ProjectMapper projectMapper;
+
     @Override
     public String insert(Contract contract) {
         contractMapper.insert(contract);
@@ -68,9 +82,54 @@ public class ContractServiceImpl implements ContractService{
     public int updateById(ContractRequest record) {
         Contract contract = new Contract();
         BeanUtils.copyProperties(record,contract);
+        updateProjectXsry(record);
         return contractMapper.updateById(contract);
     }
 
+    private void updateProjectXsry(ContractRequest record) {
+        Contract dbContract = contractMapper.selectById(record.getId());
+        Project project = projectMapper.selectById(dbContract.getProjectId());
+        project.setXsryId(record.getAreaManagerId());
+        project.setXsry(record.getAreaManager());
+        projectMapper.updateById(project);
+        updateAreaManager(dbContract);
+    }
+
+    public void updateAreaManager(Contract contract){
+        String areaManagerId = contract.getAreaManagerId();
+        String areaManagerName = contract.getAreaManager();
+        QueryWrapper<ContractAreaManager> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("CONTRACT_ID",contract.getId());
+        contractAreaManagerMapper.delete(queryWrapper);
+        List<ContractAreaManager> insertList = new ArrayList<>();
+        if(StringUtils.isNotBlank(areaManagerId)){
+            String[] ids = areaManagerId.split(",");
+            String[] names = areaManagerName.split(",");
+            for (int i = 0; i < ids.length; i++) {
+                ContractAreaManager contractAreaManager = new ContractAreaManager();
+                contractAreaManager.setContractId(contract.getId());
+                contractAreaManager.setAreaManagerId(ids[i]);
+                contractAreaManager.setAreaManagerName(names[i]);
+                insertList.add(contractAreaManager);
+            }
+        }
+        contractAreaManagerMapper.insertBatch(insertList);
+    }
+
+    /**
+     * @param contract
+     * @param projectId
+     */
+    @Override
+    public void updateVirtualContract(Contract contract, String projectId) {
+        List<String> ids = projectMapper.selectChildrenIds(projectId);
+        if(!ids.isEmpty()){
+            contractMapper.updateVirtualContractByProjectId(contract,ids);
+        }
+
+    }
+
+
     @Override
     public Page<Contract> page(Page<Contract> page, ContractDto contractDto) {
         return  contractMapper.page(page, contractDto);
@@ -249,6 +308,12 @@ public class ContractServiceImpl implements ContractService{
             contract.setContractType(ContractConstants.TYPE_MAIN_CONTRACT);
             contract.setFlowStatus(FlowStatusConstants.FLOW_NOT_START);
             insert(contract);
+            ContractAreaManager contractAreaManager = new ContractAreaManager();
+            contractAreaManager.setContractId(contract.getId());
+            Project project = projectService.selectById(projectId);
+            contractAreaManager.setAreaManagerId(project.getXsryId());
+            contractAreaManager.setAreaManagerName(project.getXsry());
+            contractAreaManagerMapper.insert(contractAreaManager);
             return returnUrl;
         }
     }

+ 33 - 20
zjugis-business/src/main/java/com/zjugis/business/service/impl/ProjectServiceImpl.java

@@ -118,10 +118,12 @@ public class ProjectServiceImpl implements ProjectService {
         }
         ProjectResponse parent = projects.get(0);
         Contract contract = contractService.selectMainByProject(parent.getId());
-        parent.setContractAmount(contract.getContractAmount());
-        AmountDto amountDto =  contractService.selectReceivableAmount(contract.getId());
-        parent.setReceivableAmount(amountDto.getInvoiceAmount().subtract(amountDto.getReturnAmount()));
-        parent.setContractBalance(contract.getContractAmount().subtract(parent.getReceivableAmount()).subtract(amountDto.getReturnAmount()));
+        if(contract != null) {
+            parent.setContractAmount(contract.getContractAmount());
+            AmountDto amountDto = contractService.selectReceivableAmount(contract.getId());
+            parent.setReceivableAmount(amountDto.getInvoiceAmount().subtract(amountDto.getReturnAmount()));
+            parent.setContractBalance(contract.getContractAmount().subtract(parent.getReceivableAmount()).subtract(amountDto.getReturnAmount()));
+        }
         projects.remove(0);
         parent.setChildren(projects);
         return parent;
@@ -137,6 +139,13 @@ public class ProjectServiceImpl implements ProjectService {
             if(StringUtils.isNotBlank(dbProject.getPid())){
                 updateVirtualContract(dbProject);
             }
+            if(dbProject.getXsryId() != null && !(dbProject.getXsryId().equals(request.getXsryId()))) {
+                Contract dbContract = contractService.selectMainByProject(dbProject.getId());
+                dbContract.setAreaManagerId(dbProject.getXsryId());
+                dbContract.setAreaManager(dbProject.getXsry());
+                contractMapper.updateById(dbContract);
+                contractService.updateAreaManager(dbContract);
+            }
         }
         return res;
     }
@@ -166,22 +175,26 @@ public class ProjectServiceImpl implements ProjectService {
         Contract contract = new Contract();
         String pid = child.getPid();
         Contract mainContract = contractService.selectMainByProject(pid);
-        contract.setParentId(mainContract.getId());
-        contract.setContractType(ContractConstants.TYPE_VIRTUAL);
-        contract.setProjectId(child.getId());
-        contract.setVirtualAmount(child.getOutputValue());
-        contract.setContractAmount(mainContract.getContractAmount());
-        contract.setContractNumber(mainContract.getContractNumber());
-        contract.setName(mainContract.getName());
-        contract.setSignWay(mainContract.getSignWay());
-        contract.setIsSign(mainContract.getIsSign());
-        contract.setMainType(mainContract.getMainType());
-        contract.setSecondType(mainContract.getSecondType());
-        contract.setAmountStatus(mainContract.getAmountStatus());
-        contract.setAssigneeName(mainContract.getAssigneeName());
-        contract.setContractOn(mainContract.getContractOn());
-        contract.setContractOff(mainContract.getContractOff());
-
+        if(mainContract != null) {
+            contract.setParentId(mainContract.getId());
+            contract.setContractType(ContractConstants.TYPE_VIRTUAL);
+            contract.setProjectId(child.getId());
+            contract.setVirtualAmount(child.getOutputValue());
+            contract.setContractAmount(mainContract.getContractAmount());
+            contract.setContractNumber(mainContract.getContractNumber());
+            contract.setName(mainContract.getName());
+            contract.setSignWay(mainContract.getSignWay());
+            contract.setIsSign(mainContract.getIsSign());
+            contract.setMainType(mainContract.getMainType());
+            contract.setSecondType(mainContract.getSecondType());
+            contract.setContractOn(mainContract.getContractOn());
+            contract.setContractOff(mainContract.getContractOff());
+        } else {
+            contract.setContractType(ContractConstants.TYPE_VIRTUAL);
+            contract.setProjectId(child.getId());
+            contract.setVirtualAmount(BigDecimal.ZERO);
+            contract.setContractAmount(BigDecimal.ZERO);
+        }
         contractService.insert(contract);
         BigDecimal childrenOutput = projectMapper.selectChildrenOutputValue(pid);
         if(mainContract != null){

+ 19 - 0
zjugis-business/src/main/resources/mapper/oracle/ContractMapper.xml

@@ -103,4 +103,23 @@
         UNION
         SELECT * FROM CONTRACT where ISVALID = 1 AND PARENT_ID = #{contractId,jdbcType=VARCHAR} and CONTRACT_TYPE = 4
     </select>
+
+    <update id="updateVirtualContractByProjectId">
+        UPDATE CONTRACT SET
+        PARENT_ID = #{contract.id,jdbcType=VARCHAR},
+        CONTRACT_AMOUNT = #{contract.contractAmount},
+        CONTRACT_NUMBER = #{contract.contractNumber},
+        NAME = #{contract.name,jdbcType=VARCHAR},
+        SIGN_WAY = #{contract.signWay,jdbcType=INTEGER},
+        IS_SIGN = #{contract.isSign,jdbcType=INTEGER},
+        MAIN_TYPE = #{contract.mainType,jdbcType=INTEGER},
+        SECOND_TYPE = #{contract.secondType,jdbcType=INTEGER},
+        CONTRACT_ON = #{contract.contractOn,jdbcType=DATE},
+        CONTRACT_OFF = #{contract.contractOff,jdbcType=DATE}
+        WHERE PROJECT_ID IN
+        <foreach item="id" index="index" collection="ids" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        AND CONTRACT_TYPE = 4 AND ISVALID = 1
+    </update>
 </mapper>

+ 4 - 0
zjugis-business/src/main/resources/mapper/oracle/ProjectMapper.xml

@@ -102,4 +102,8 @@
     <select id="selectChildrenOutputValue" resultType="java.math.BigDecimal">
         select nvl(sum(nvl(t.payment_cost,0)), 0) from PROJECT where PID = #{pid,jdbcType=VARCHAR} and ISVALID = 1
     </select>
+
+    <select id="selectChildrenIds" resultType="java.lang.String">
+        SELECT ID FROM PROJECT WHERE PID = #{projectId,jdbcType=VARCHAR} AND ISVALID = 1
+    </select>
 </mapper>

+ 4 - 2
zjugis-business/src/main/resources/static/flow/js/formCommon.js

@@ -10,7 +10,7 @@ function allowChildClick(even, treeNode, clickFlag) {
     }
 }
 
-function selecttree(selector,data,callback,beforeClick){
+function selecttree(selector,data,callback,beforeClick,onCloseBtn,loadSuccess){
     var wid = $(selector).width();
     z.ui.selecttree(selector).init({
         panelwidth: wid,
@@ -37,9 +37,11 @@ function selecttree(selector,data,callback,beforeClick){
             enable: false
         },
         treedata: data,
+        onCloseBtnClick: onCloseBtn,
         callback: {
             beforeClick: beforeClick,
-            onClick: callback
+            onClick: callback,
+            onLoadSuccess: loadSuccess
         }
     });
 }

+ 18 - 12
zjugis-business/src/main/resources/templates/FlowContract/js/apply.js

@@ -191,7 +191,8 @@
             data: {},
             success: function (res) {
                 if(res && res.length > 0){
-                    selectMutiTree("[name='areaManager']",res,onClear,clickAreaManager,setAreaManager,allowUserClick,{ "Y": "s", "N": "s" })
+                    // selecttree("[name='areaManager']",res,onClear,clickAreaManager,setAreaManager,allowUserClick,{ "Y": "s", "N": "s" })
+                    selecttree("[name='areaManager']",res,clickAreaManager,allowUserClick,onClear,setAreaManager)
                 }
             },
             error: function () {
@@ -211,18 +212,23 @@
         }
     }
 
+    // function clickAreaManager(even, treeId, treeNode) {
+    //         var ids = [];
+    //         var names = [];
+    //         var nodes =  z.ui.selecttree("[name='areaManager']").tree.getCheckedNodes();
+    //         for(var i in nodes){
+    //             ids.push(nodes[i].id);
+    //             names.push(nodes[i].name);
+    //         }
+    //         if(ids.length > 0){
+    //             $("[name='contract$areaManagerId']").val(ids.join(","));
+    //             $("[name='contract$areaManager']").val(names.join(","));
+    //         }
+    // }
+
     function clickAreaManager(even, treeId, treeNode) {
-            var ids = [];
-            var names = [];
-            var nodes =  z.ui.selecttree("[name='areaManager']").tree.getCheckedNodes();
-            for(var i in nodes){
-                ids.push(nodes[i].id);
-                names.push(nodes[i].name);
-            }
-            if(ids.length > 0){
-                $("[name='contract$areaManagerId']").val(ids.join(","));
-                $("[name='contract$areaManager']").val(names.join(","));
-            }
+        $("[name='contract$areaManagerId']").val(treeNode.id);
+        $("[name='contract$areaManager']").val(treeNode.name);
     }
 
     function clickClient(even, treeId, treeNode) {