Browse Source

问题处理

yzc 1 year ago
parent
commit
69bc654577

+ 11 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/report/dto/ReportLossesDetailsSelectDto.java

@@ -14,4 +14,15 @@ import lombok.Setter;
 @Setter
 public class ReportLossesDetailsSelectDto extends BaseSelectDto {
 
+    /**
+     * 类型 0补单1丢失
+     */
+    private Integer type;
+
+    /**
+     * 过期数量
+     */
+    private Integer pastDay;
+
+
 }

+ 7 - 0
hx-mes/src/main/java/com/fjhx/mes/service/report/impl/ReportLossesDetailsServiceImpl.java

@@ -47,6 +47,13 @@ public class ReportLossesDetailsServiceImpl extends ServiceImpl<ReportLossesDeta
     public Page<ReportLossesDetailsVo> getPage(ReportLossesDetailsSelectDto dto) {
         IWrapper<ReportLossesDetails> wrapper = getWrapper();
 
+        //类型过滤
+        wrapper.eq("rld", ReportLossesDetailsVo::getType, dto.getType());
+
+        //近n天过滤
+        wrapper.ge("DATEDIFF(NOW(),rld.repo_time)", 0);
+        wrapper.le("DATEDIFF(NOW(),rld.repo_time)", dto.getPastDay());
+
         wrapper.groupBy("rld.id");
 
         wrapper.orderByDesc("rld", ReportLossesDetails::getId);

+ 0 - 7
hx-purchase/src/main/java/com/fjhx/purchase/service/purchase/impl/PurchaseServiceImpl.java

@@ -33,13 +33,11 @@ import com.fjhx.purchase.service.arrival.ArrivalDetailService;
 import com.fjhx.purchase.service.invoice.InvoiceDetailsService;
 import com.fjhx.purchase.service.pay.PayDetailService;
 import com.fjhx.purchase.service.purchase.PurchaseDetailService;
-import com.fjhx.purchase.service.purchase.PurchasePayRecordDetailService;
 import com.fjhx.purchase.service.purchase.PurchaseService;
 import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
 import com.fjhx.purchase.service.subscribe.SubscribeService;
 import com.fjhx.supply.entity.supplier.po.SupplierInfo;
 import com.fjhx.supply.service.supplier.SupplierInfoService;
-import com.fjhx.wms.service.warehouse.WarehouseService;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.core.domain.BaseSelectDto;
 import com.ruoyi.common.exception.ServiceException;
@@ -86,8 +84,6 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
     @Autowired
     private ArrivalDetailService arrivalDetailService;
 
-    @Autowired
-    private WarehouseService warehouseService;
 
     @Autowired
     private SubscribeDetailService subscribeDetailService;
@@ -98,9 +94,6 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
     @Autowired
     private CodingRuleService codingRuleService;
 
-    @Autowired
-    private PurchasePayRecordDetailService purchasePayRecordDetailService;
-
     /**
      * 列表
      *

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/controller/purchase/EhsdPurchaseController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.purchase.entity.pay.vo.PayVo;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseDto;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseSelectDto;
+import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseVo;
 import com.fjhx.sale.service.purchase.EhsdPurchaseService;
 import com.ruoyi.common.core.domain.BaseSelectDto;
@@ -96,4 +97,12 @@ public class EhsdPurchaseController {
         return ehsdPurchaseService.getProductPriceInfo(dto);
     }
 
+    /**
+     * 根据供应商查询无发票的采购合同
+     */
+    @GetMapping("/getNoInvoiceListBySupplyId")
+    public List<EhsdPurchase> getNoInvoiceListBySupplyId(@RequestParam("supplyId") String supplyId) {
+        return ehsdPurchaseService.getNoInvoiceListBySupplyId(supplyId);
+    }
+
 }

+ 6 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/po/EhsdPurchase.java

@@ -287,4 +287,10 @@ public class EhsdPurchase extends BasePo {
      */
     private Long companyId;
 
+    @TableField(exist = false)
+    private BigDecimal sumInvoiceMoney;
+
+    @TableField(exist = false)
+    private BigDecimal sumPayMoney;
+
 }

+ 0 - 6
hx-sale/src/main/java/com/fjhx/sale/flow/ContractFlow.java

@@ -144,12 +144,6 @@ public class ContractFlow extends FlowDelegate {
             ObsFileUtil.editFile(cp.getFileList(), cp.getId());
             //保存生产源文件
             ObsFileUtil.copyFileAndSave(cp.getProdFileList(), cp.getId(), 1);
-//            String prodFilePath = cp.getProdFilePath();
-//            if (ObjectUtil.isNotEmpty(prodFilePath) && prodFilePath.startsWith("/temp")) {
-//                String targetFolderPath = String.format("/contractProduct/%s", cp.getId());
-//                com.alibaba.fastjson2.JSONObject prodFile = ftpFileService.moveFolder(prodFilePath, targetFolderPath);
-//                cp.setProdFilePath(prodFile.getString("path"));
-//            }
 
             //赋值产品BOM信息
             List<ContractProductBom> contractProductBomList = cp.getContractProductBomList();

+ 24 - 181
hx-sale/src/main/java/com/fjhx/sale/flow/ContractUpdateFlow.java

@@ -1,27 +1,23 @@
 package com.fjhx.sale.flow;
 
-import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.toolkit.*;
-import com.fjhx.area.utils.CustomizeAreaUtil;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fjhx.common.enums.FlowStatusEnum1;
 import com.fjhx.common.utils.Assert;
+import com.fjhx.common.utils.Utils;
 import com.fjhx.file.utils.ObsFileUtil;
 import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.flow.enums.FlowStatusEnum;
-import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.sale.entity.contract.dto.ContractDto;
-import com.fjhx.sale.entity.contract.dto.ContractProductDto;
 import com.fjhx.sale.entity.contract.po.Contract;
 import com.fjhx.sale.entity.contract.po.ContractProduct;
 import com.fjhx.sale.entity.contract.po.ContractProject;
 import com.fjhx.sale.service.contract.ContractProductService;
 import com.fjhx.sale.service.contract.ContractProjectService;
 import com.fjhx.sale.service.contract.ContractService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
 import com.ruoyi.common.core.domain.BasePo;
-import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -29,9 +25,6 @@ import org.springframework.stereotype.Component;
 
 import java.util.Date;
 import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -52,14 +45,6 @@ public class ContractUpdateFlow extends FlowDelegate {
     @Autowired
     private ContractProjectService contractProjectService;
 
-//    @Autowired
-//    private ContractShipmentService contractShipmentService;
-
-    @Autowired
-    private EhsdPurchaseProductService purchaseProductService;
-    @Autowired
-    private ProductInfoService productInfoService;
-
     @Override
     public String getFlowKey() {
         return "contract_update_flow";
@@ -67,114 +52,46 @@ public class ContractUpdateFlow extends FlowDelegate {
 
     /**
      * 发起流程
-     *
-     * @param flowId     流程ID
-     * @param submitData 采购付款数据
-     * @return
      */
     @Override
     public Long start(Long flowId, JSONObject submitData) {
-
         ContractDto contract = submitData.toJavaObject(ContractDto.class);
-
+        //清理ID字段防止误传
+        contract.setId(null);
         //赋值流程id
         contract.setFlowId(flowId);
 
-        //判断合同是否在变更中,防止用户缓存导致重复变更
-        Contract byId = contractService.getById(contract.getOldContractId());
-        Assert.notEmpty(byId, "查询不到合同信息");
-        if (byId.getStatus().equals(FlowStatusEnum1.UPDATE_LOADING.getKey())) {
-            throw new ServiceException("合同正在变更中,禁止重复变更!");
-        }
-
-        // 原合同id不能为空
+        //原合同id不能为空
         Long oldContractId = contract.getOldContractId();
-        if (oldContractId == null) {
-            throw new ServiceException("原合同id不能为空");
-        }
+        Assert.notEmpty(oldContractId, "原合同id不能为空");
         //查询原合同
         Contract oldContract = contractService.getById(contract.getOldContractId());
-        if (ObjectUtil.isEmpty(oldContract)) {
-            throw new ServiceException("查询不到原合同信息");
-        }
-        //更新原样品单状态为变更中
-        oldContract.setStatus(FlowStatusEnum1.UPDATE_LOADING.getKey());
-        contractService.updateById(oldContract);
-        //查询旧合同的订单产品
-        List<ContractProduct> oldContractProductList = contractProductService.list(q -> q.eq(ContractProduct::getContractId, oldContractId));
-        if (CollectionUtils.isEmpty(oldContractProductList)) {
-            throw new ServiceException("原合同没有产品");
-        }
-        Map<Long, List<ContractProduct>> oldContractProductMap = oldContractProductList.stream().collect(Collectors.groupingBy(ContractProduct::getId));
-        List<ContractProductDto> newContractProductList = contract.getContractProductList();
-        if (CollectionUtils.isEmpty(newContractProductList)) {
-            throw new ServiceException("变更合同产品不能为空");
-        }
-        /**
-         * 赋值新的变更合同号
-         */
-        String code = oldContract.getCode();
-        Matcher matcher = Pattern.compile(".*\\((.*?)\\)$").matcher(code);
-        int index = 2;
-        if (matcher.find()) {
-            index = (Integer.parseInt(matcher.group(1)) + 1);
-            code = code.substring(0, code.lastIndexOf("("));
+        Assert.notEmpty(oldContract, "查询不到原合同信息");
+        //判断合同是否在变更中,防止用户缓存导致重复变更
+        if (oldContract.getStatus().equals(FlowStatusEnum1.UPDATE_LOADING.getKey())) {
+            throw new ServiceException("原合同正在变更中,禁止重复变更!");
         }
-        contract.setCode(code + "(" + index + ")");
+
+        //将原合同改为变更中
+        contractService.update(q -> q.eq(Contract::getId, oldContractId).set(Contract::getStatus, FlowStatusEnum1.UPDATE_LOADING.getKey()));
+
+        //赋值变更后的单号新单号
+        contract.setCode(Utils.getNewCode(oldContract.getCode()));
         contract.setIsShow(1);//隐藏当前数据
-        /**
-         * 计算新合同的剩余数量
-         */
-        for (ContractProduct newCp : newContractProductList) {
-            newCp.setExpendQuantity(newCp.getQuantity());
-            if (ObjectUtil.isNotEmpty(newCp.getId())) {//如果新合同产品ID不为空
-                //取出旧合同
-                ContractProduct oldContractProduct = oldContractProductMap.getOrDefault(newCp.getId(), null).get(0);
-//                //取出旧合同包装方式
-//                JSONObject oldJson = JSONObject.parseObject(oldContractProduct.getEhsdJson());
-//                String oldPackMethod = ObjectUtil.isEmpty(oldJson) ? null : oldJson.getString("packMethod");
-//                //取出新合同包装方式
-//                JSONObject newJson = JSONObject.parseObject(newCp.getEhsdJson());
-//                String newPackMethod = ObjectUtil.isEmpty(newJson) ? null : newJson.getString("packMethod");
-                /**
-                 * 商品英文名、尺寸、包装方式、数量 没有变更---取原本的剩余数量
-                 */
-                if (oldContractProduct.getQuantity().compareTo(newCp.getQuantity()) == 0
-                        && StringUtils.equals(oldContractProduct.getProductName(), newCp.getProductName())
-                        && StringUtils.equals(oldContractProduct.getProductModel(), newCp.getProductModel())
-//                        && StringUtils.equals(oldPackMethod, newPackMethod)
-                ) {
-                    //取出旧的剩余数量
-                    newCp.setExpendQuantity(oldContractProduct.getExpendQuantity());
-                }
-            }
-        }
-        long contractId = update(contract);
-//        if(contract.getStartType()==1){//直接审批通过
-//            this.end(flowId,contractId,submitData);
-//        }
-        return contractId;
+
+        //调用合同发起通用代码
+        return contractFlow.start(contract);
     }
 
     /**
      * 结束流程
-     *
-     * @param flowId     流程ID
-     * @param businessId 业务ID
-     * @param submitData 数据
      */
     @Override
     public void end(Long flowId, Long businessId, JSONObject submitData) {
         // 通过业务ID查询合同数据
         Contract newContract = contractService.getById(businessId);
-        if (ObjectUtils.isEmpty(newContract)) {
-            throw new ServiceException("合同不存在");
-        }
-        long oldContractId = newContract.getOldContractId();//取出旧的合同ID
+        Long oldContractId = newContract.getOldContractId();
         Contract oldContract = contractService.getById(oldContractId);
-        if (oldContract == null) {
-            throw new ServiceException("原合同不存在");
-        }
 
         //替换新数据ID为临时ID
         long temNewId = IdWorker.getId();
@@ -190,16 +107,14 @@ public class ContractUpdateFlow extends FlowDelegate {
         contractService.updateContract(temOldUpContract);
 
 
-        //查询新数据产品、收费、出货
+        //查询新数据产品、收费
         List<Long> newContractProductIds = contractProductService.list(Wrappers.<ContractProduct>query().lambda().select(ContractProduct::getId).eq(ContractProduct::getContractId, businessId)).stream().map(ContractProduct::getId).collect(Collectors.toList());
         List<Long> newContractProjectIds = contractProjectService.list(Wrappers.<ContractProject>query().lambda().select(ContractProject::getId).eq(ContractProject::getContractId, businessId)).stream().map(ContractProject::getId).collect(Collectors.toList());
-//        List<Long> newContractShipmentIds = contractShipmentService.list(Wrappers.<ContractShipment>query().lambda().select(ContractShipment::getId).eq(ContractShipment::getContractId, businessId)).stream().map(ContractShipment::getId).collect(Collectors.toList());
 
 
-        //查询旧数据产品、收费、出货
+        //查询旧数据产品、收费
         List<Long> oldContractProductIds = contractProductService.list(Wrappers.<ContractProduct>query().lambda().select(ContractProduct::getId).eq(ContractProduct::getContractId, oldContractId)).stream().map(ContractProduct::getId).collect(Collectors.toList());
         List<Long> oldContractProjectIds = contractProjectService.list(Wrappers.<ContractProject>query().lambda().select(ContractProject::getId).eq(ContractProject::getContractId, oldContractId)).stream().map(ContractProject::getId).collect(Collectors.toList());
-//        List<Long> oldContractShipmentIds = contractShipmentService.list(Wrappers.<ContractShipment>query().lambda().select(ContractShipment::getId).eq(ContractShipment::getContractId, oldContractId)).stream().map(ContractShipment::getId).collect(Collectors.toList());
 
 
         /**
@@ -220,10 +135,6 @@ public class ContractUpdateFlow extends FlowDelegate {
         if (CollectionUtils.isNotEmpty(newContractProjectIds)) {
             contractProjectService.update(Wrappers.<ContractProject>update().lambda().set(ContractProject::getContractId, oldContractId).in(ContractProject::getId, newContractProjectIds));
         }
-//        //修改合同出货相关数据
-//        if (CollectionUtils.isNotEmpty(newContractShipmentIds)) {
-//            contractShipmentService.update(Wrappers.<ContractShipment>update().lambda().set(ContractShipment::getContractId, oldContractId).in(ContractShipment::getId, newContractShipmentIds));
-//        }
 
         /**
          * 处理旧的合同---
@@ -243,73 +154,9 @@ public class ContractUpdateFlow extends FlowDelegate {
             //修改合同收费相关数据
             contractProjectService.update(Wrappers.<ContractProject>update().lambda().set(ContractProject::getContractId, businessId).in(ContractProject::getId, oldContractProjectIds));
         }
-//        //修改合同出货相关数据
-//        if (CollectionUtils.isNotEmpty(oldContractShipmentIds)) {
-//            //修改合同出货相关数据
-//            contractShipmentService.update(Wrappers.<ContractShipment>update().lambda().set(ContractShipment::getContractId, businessId).in(ContractShipment::getId, oldContractShipmentIds));
-//        }
         ObsFileUtil.exchangeBusinessId(oldContractId, businessId);
     }
 
-    /**
-     * 变更
-     *
-     * @param contract
-     * @return
-     */
-    public Long update(ContractDto contract) {
-        // 赋值城市省份信息
-        CustomizeAreaUtil.setAreaId(contract);
-        SysUser loginUser = SecurityUtils.getLoginUser().getUser();
-        contract.setUserName(loginUser.getNickName());
-        contract.setBuyCityId(contract.getCityId());
-        contract.setBuyCountryId(contract.getCountryId());
-        contract.setBuyProvinceId(contract.getProvinceId());
-        contract.setStatus(FlowStatusEnum1.UNDER_REVIEW.getKey());
-//        contract.setRate(ExchangeRateUtil.getCnyToCodeRate(contract.getCurrency()));
-        contractService.save(contract);
-
-        // 保存合同产品
-        List<ContractProductDto> contractProductDtoList = contract.getContractProductList();
-        List<ContractProduct> contractProductList = BeanUtil.copyToList(contractProductDtoList, ContractProduct.class);
-        if (CollectionUtils.isNotEmpty(contractProductList)) {
-            for (ContractProduct c : contractProductList) {
-                c.setId(IdWorker.getId());
-                c.setContractId(contract.getId());
-//                ObsFileUtil.saveFile(c.getFileList(), c.getId());
-            }
-            contractProductService.saveBatch(contractProductList);
-        }
-
-        // 保存收费项目
-        List<ContractProject> contractProjectList = contract.getContractProjectList();
-        if (CollectionUtils.isNotEmpty(contractProjectList)) {
-            for (ContractProject c : contractProjectList) {
-                c.setId(IdWorker.getId());
-                c.setContractId(contract.getId());
-            }
-            contractProjectService.saveBatch(contractProjectList);
-        }
-
-//        // 保存自定义出货
-//        List<ContractShipment> contractShipmentList = contract.getContractShipmentList();
-//        if (CollectionUtils.isNotEmpty(contractShipmentList)) {
-//            for (ContractShipment c : contractShipmentList) {
-//                c.setId(IdWorker.getId());
-//                c.setContractId(contract.getId());
-//            }
-//            contractShipmentService.saveBatch(contractShipmentList);
-//        }
-
-        // 交接单附件列表
-        ObsFileUtil.copyFileAndSave(contract.getFileList(), contract.getId(), 1);
-
-        // 包装指示附件列表
-        ObsFileUtil.copyFileAndSave(contract.getPackageFileList(), contract.getId(), 2);
-
-        return contract.getId();
-    }
-
 
     /**
      * 重新发起
@@ -321,10 +168,6 @@ public class ContractUpdateFlow extends FlowDelegate {
 
     /**
      * 驳回
-     *
-     * @param flowId
-     * @param businessId
-     * @param flowStatus
      */
     @Override
     public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {

+ 0 - 16
hx-sale/src/main/java/com/fjhx/sale/flow/EhsdPurchaseFlow.java

@@ -3,7 +3,6 @@ package com.fjhx.sale.flow;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -26,7 +25,6 @@ import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProject;
 import com.fjhx.sale.entity.sample.po.Sample;
-import com.fjhx.sale.entity.sample.po.SampleProduct;
 import com.fjhx.sale.service.contract.ContractService;
 import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
 import com.fjhx.sale.service.purchase.EhsdPurchaseProjectService;
@@ -45,7 +43,6 @@ import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -207,19 +204,6 @@ public class EhsdPurchaseFlow extends FlowDelegate {
         }
         //查询采购产品
         List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(Wrappers.<EhsdPurchaseProduct>query().lambda().eq(EhsdPurchaseProduct::getPurchaseId, businessId));
-        List<SampleProduct> upSampleProduct = new ArrayList<>();
-        for (EhsdPurchaseProduct p : purchaseProductList) {
-            if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
-                    p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_2.getKey()) {//如果采购的是样品单
-                SampleProduct sampleProduct = sampleProductService.getById(p.getDataResourceId());
-                BigDecimal expendQuantity = sampleProduct.getExpendQuantity().subtract(p.getQuantity());
-                sampleProduct.setExpendQuantity(expendQuantity);
-                upSampleProduct.add(sampleProduct);
-            }
-        }
-        if (CollectionUtils.isNotEmpty(upSampleProduct)) {//扣减样品单数量
-            sampleProductService.updateBatchById(upSampleProduct);
-        }
         //修改采购状态为审批通过
         purchase.setStatus(PurchaseStatusEnum.PASS.getKey());
         purchase.setApprovedDate(new Date());

+ 77 - 147
hx-sale/src/main/java/com/fjhx/sale/flow/EhsdPurchaseUpdateFlow.java

@@ -7,6 +7,7 @@ import com.fjhx.common.entity.InOutBo;
 import com.fjhx.common.enums.FlowStatusEnum1;
 import com.fjhx.common.enums.InOutType;
 import com.fjhx.common.utils.Assert;
+import com.fjhx.common.utils.Utils;
 import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.flow.enums.FlowStatusEnum;
 import com.fjhx.item.enums.ProductAvailableRecordType;
@@ -14,35 +15,26 @@ import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.purchase.entity.purchase.enums.PurchaseDataResourceEnum;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseDto;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchaseArrival;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProject;
-import com.fjhx.sale.service.contract.ContractProductService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseArrivalService;
 import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
 import com.fjhx.sale.service.purchase.EhsdPurchaseProjectService;
 import com.fjhx.sale.service.purchase.EhsdPurchaseService;
-import com.fjhx.sale.service.sample.SampleProductService;
-import com.ruoyi.common.annotation.LogicIgnore;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 /**
- * EHSD采购变更流程
+ * 采购变更流程
  */
 @Component
-//@DS(SourceConstant.SALE)
 public class EhsdPurchaseUpdateFlow extends FlowDelegate {
     @Autowired
     private EhsdPurchaseService ehsdPurchaseService;
@@ -53,12 +45,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
     @Autowired
     private EhsdPurchaseProjectService ehsdPurchaseProjectService;
     @Autowired
-    private EhsdPurchaseArrivalService ehsdPurchaseArrivalService;
-    @Autowired
-    private ContractProductService contractProductService;
-    @Autowired
-    private SampleProductService sampleProductService;
-    @Autowired
     private ProductInfoService productInfoService;
 
     @Override
@@ -72,53 +58,35 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
     @Override
     public Long start(Long flowId, JSONObject submitData) {
         EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
-        Assert.notEmpty(purchase.getId(), "采购合同id不能为空");
 
-        //判断合同是否在变更中,防止用户缓存导致重复变更
-        EhsdPurchase byId = ehsdPurchaseService.getById(purchase.getId());
-        Assert.notEmpty(byId, "查询不到采购信息");
-        if (byId.getStatus().equals(FlowStatusEnum1.UPDATE_LOADING.getKey())) {
-            throw new ServiceException("合同正在变更中,禁止重复变更!");
-        }
-
-        //赋值原合同id
-        purchase.setOldPurchaseId(purchase.getId());
+        //清理Id防止前端误传
+        purchase.setId(null);
 
         //赋值流程id
         purchase.setFlowId(flowId);
 
-        //变更 用原来合同号加后缀
-        EhsdPurchase oldPurchase = ehsdPurchaseService.getById(purchase.getOldPurchaseId());
-        Assert.notEmpty(oldPurchase, "查询不到原合同信息");
-        //原合同修改为变更中
-        oldPurchase.setStatus(FlowStatusEnum1.UPDATE_LOADING.getKey());
-        ehsdPurchaseService.updateById(oldPurchase);
+        Long oldPurchaseId = purchase.getOldPurchaseId();
+        Assert.notEmpty(oldPurchaseId, "原采购订单id不能为空");
 
-        String code = oldPurchase.getCode();
-        Matcher matcher = Pattern.compile(".*\\((.*?)\\)$").matcher(code);
-        int index = 2;
-        if (matcher.find()) {
-            index = (Integer.parseInt(matcher.group(1)) + 1);
-            code = code.substring(0, code.lastIndexOf("("));
+        //判断合同是否在变更中,防止用户缓存导致重复变更
+        EhsdPurchase oldPurchase = ehsdPurchaseService.getById(oldPurchaseId);
+        Assert.notEmpty(oldPurchase, "查询不到原采购订单信息");
+        if (oldPurchase.getStatus().equals(FlowStatusEnum1.UPDATE_LOADING.getKey())) {
+            throw new ServiceException("原采购订单正在变更中,禁止重复变更!");
         }
-        purchase.setCode(code + "(" + index + ")");
+
+        //原采购订单修改为变更中
+        ehsdPurchaseService.update(q -> q.eq(EhsdPurchase::getId, oldPurchaseId).set(EhsdPurchase::getStatus, FlowStatusEnum1.UPDATE_LOADING.getKey()));
+
+        //赋值新单号
+        purchase.setCode(Utils.getNewCode(oldPurchase.getCode()));
 
         //获取明细信息
         List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
         List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
-        List<EhsdPurchaseArrival> purchaseArrivalList = purchase.getPurchaseArrivalList();
-
-        //清空采购合同的id
-        purchase.setId(null);
-        //清空采购明细的id 以及 配件id 方便后面重新发起
-        for (EhsdPurchaseProduct ehsdPurchaseProduct : purchaseProductList) {
-            ehsdPurchaseProduct.setId(null);
-            ehsdPurchaseProduct.getPurchaseProductMountingsList().forEach(item -> item.setId(null));
-        }
-        //清空其他费用的id方便后面重新发起
+        //清空物料,收费项目id 防止前端误传
+        purchaseProductList.forEach(item -> item.setId(null));
         purchaseProjectList.forEach(item -> item.setId(null));
-        //清空到货要求的id方便后面重新发起
-        purchaseArrivalList.forEach(item -> item.setId(null));
 
         //调用采购发起公共代码块
         purchase = ehsdPurchaseFlow.connStart(purchase);
@@ -127,67 +95,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
     }
 
     /**
-     * 重新发起
-     */
-    @Override
-    @LogicIgnore
-    @Transactional(rollbackFor = Exception.class)
-    public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
-        //删除采购合同
-        EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
-        if (ObjectUtils.isEmpty(purchase)) {
-            throw new ServiceException("采购数据不能为空");
-        }
-        purchase.setFlowId(flowId);
-        ehsdPurchaseFlow.connStart(purchase);
-    }
-
-    /**
-     * 驳回
-     */
-    @Override
-    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
-        ehsdPurchaseService.update(q -> q
-                .eq(EhsdPurchase::getId, businessId)
-                .set(EhsdPurchase::getStatus, FlowStatusEnum1.REJECT.getKey())
-                .set(EhsdPurchase::getUpdateTime, new Date())
-                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-        );
-
-        //恢复原合同
-        EhsdPurchase ehsdPurchase = ehsdPurchaseService.getById(businessId);
-        ehsdPurchaseService.update(q -> q
-                .eq(BasePo::getId, ehsdPurchase.getOldPurchaseId())
-                .set(EhsdPurchase::getStatus, FlowStatusEnum1.PASS.getKey())
-                .set(BasePo::getUpdateTime, new Date())
-                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-        );
-    }
-
-    /**
-     * 作废
-     */
-    @Override
-    public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
-        super.cancellation(flowId, businessId, flowStatus);
-        ehsdPurchaseService.update(q -> q
-                .eq(EhsdPurchase::getId, businessId)
-                .set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
-                .set(EhsdPurchase::getUpdateTime, new Date())
-                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-        );
-
-        //恢复原合同
-        EhsdPurchase ehsdPurchase = ehsdPurchaseService.getById(businessId);
-        ehsdPurchaseService.update(q -> q
-                .eq(BasePo::getId, ehsdPurchase.getOldPurchaseId())
-                .set(EhsdPurchase::getStatus, FlowStatusEnum1.PASS.getKey())
-                .set(BasePo::getUpdateTime, new Date())
-                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-        );
-    }
-
-    /**
      * 结束流程
      */
     @Override
@@ -201,25 +108,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
         oldEhsdPurchase.setStatus(FlowStatusEnum1.UPDATE.getKey());
         ehsdPurchaseService.updateById(oldEhsdPurchase);
 
-//        //回滚旧合同的已采购数量
-//        List<EhsdPurchaseProduct> oldPurchaseProductList = ehsdPurchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, purchase.getOldPurchaseId()));
-//        for (EhsdPurchaseProduct ehsdPurchaseProduct : oldPurchaseProductList) {
-//            if (ObjectUtils.isNotEmpty(ehsdPurchaseProduct.getDataResourceId()) && ehsdPurchaseProduct.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
-//                ContractProduct contractProduct = contractProductService.getById(ehsdPurchaseProduct.getDataResourceId());
-//                //回滚变更前待采购数量
-//                contractProduct.setExpendQuantity(contractProduct.getExpendQuantity().add(ehsdPurchaseProduct.getQuantity()));
-//                contractProductService.updateById(contractProduct);
-//            }
-//            if (ObjectUtils.isNotEmpty(ehsdPurchaseProduct.getDataResourceId()) && ehsdPurchaseProduct.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_2.getKey()) {//如果采购的是样品单
-//                SampleProduct sampleProduct = sampleProductService.getById(ehsdPurchaseProduct.getDataResourceId());
-//                //回滚变更前待采购数量
-//                sampleProduct.setExpendQuantity(sampleProduct.getExpendQuantity().add(ehsdPurchaseProduct.getQuantity()));
-//                sampleProductService.updateById(sampleProduct);
-//            }
-//        }
-
-        //---------------------------------------
-
         //修改可用库存
         //回滚旧合同数据
         List<InOutBo> oldInOutBoList = new ArrayList<>();
@@ -251,9 +139,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
         productInfoService.editAvailableQuantity(inOutBoList, InOutType.IN, businessId, ProductAvailableRecordType.PURCHASE_UPDATE, purchase.getCompanyId());
 
 
-        //-----------------------------
-
-
         //调用采购发起流程的结束方法
         ehsdPurchaseFlow.end(flowId, businessId, submitData);
 
@@ -264,7 +149,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
         ehsdPurchaseService.updatePurchaseId(businessId, tempId, SecurityUtils.getUserId(), null);
         ehsdPurchaseProductService.update(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, businessId).set(EhsdPurchaseProduct::getPurchaseId, tempId));
         ehsdPurchaseProjectService.update(q -> q.eq(EhsdPurchaseProject::getPurchaseId, businessId).set(EhsdPurchaseProject::getPurchaseId, tempId));
-//        ehsdPurchaseArrivalService.update(q -> q.eq(EhsdPurchaseArrival::getPurchaseId, businessId).set(EhsdPurchaseArrival::getPurchaseId, tempId));
 
 
         //将旧合同的id改为新合同id
@@ -281,12 +165,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
                 .set(BasePo::getUpdateTime, new Date())
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
         );
-//        ehsdPurchaseArrivalService.update(q -> q
-//                .eq(EhsdPurchaseArrival::getPurchaseId, oldPurchaseId)
-//                .set(EhsdPurchaseArrival::getPurchaseId, businessId)
-//                .set(BasePo::getUpdateTime, new Date())
-//                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-//        );
         //将新合同id改为旧合同id
         ehsdPurchaseService.updatePurchaseId(tempId, oldPurchaseId, SecurityUtils.getUserId(), businessId);
         ehsdPurchaseProductService.update(q -> q
@@ -301,12 +179,64 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
                 .set(BasePo::getUpdateTime, new Date())
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
         );
-//        ehsdPurchaseArrivalService.update(q -> q
-//                .eq(EhsdPurchaseArrival::getPurchaseId, tempId)
-//                .set(EhsdPurchaseArrival::getPurchaseId, oldPurchaseId)
-//                .set(BasePo::getUpdateTime, new Date())
-//                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-//        );
+    }
+
+    /**
+     * 重新发起
+     */
+    @Override
+    public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
+        EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
+        if (ObjectUtils.isEmpty(purchase)) {
+            throw new ServiceException("采购数据不能为空");
+        }
+        purchase.setFlowId(flowId);
+        ehsdPurchaseFlow.connStart(purchase);
+    }
+
+    /**
+     * 驳回
+     */
+    @Override
+    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+        ehsdPurchaseService.update(q -> q
+                .eq(EhsdPurchase::getId, businessId)
+                .set(EhsdPurchase::getStatus, FlowStatusEnum1.REJECT.getKey())
+                .set(EhsdPurchase::getUpdateTime, new Date())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+        );
+
+        //恢复原合同
+        EhsdPurchase ehsdPurchase = ehsdPurchaseService.getById(businessId);
+        ehsdPurchaseService.update(q -> q
+                .eq(BasePo::getId, ehsdPurchase.getOldPurchaseId())
+                .set(EhsdPurchase::getStatus, FlowStatusEnum1.PASS.getKey())
+                .set(BasePo::getUpdateTime, new Date())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+        );
+    }
+
+    /**
+     * 作废
+     */
+    @Override
+    public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+        super.cancellation(flowId, businessId, flowStatus);
+        ehsdPurchaseService.update(q -> q
+                .eq(EhsdPurchase::getId, businessId)
+                .set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
+                .set(EhsdPurchase::getUpdateTime, new Date())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+        );
+
+        //恢复原合同
+        EhsdPurchase ehsdPurchase = ehsdPurchaseService.getById(businessId);
+        ehsdPurchaseService.update(q -> q
+                .eq(BasePo::getId, ehsdPurchase.getOldPurchaseId())
+                .set(EhsdPurchase::getStatus, FlowStatusEnum1.PASS.getKey())
+                .set(BasePo::getUpdateTime, new Date())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+        );
     }
 
 }

+ 2 - 0
hx-sale/src/main/java/com/fjhx/sale/service/purchase/EhsdPurchaseService.java

@@ -70,4 +70,6 @@ public interface EhsdPurchaseService extends BaseService<EhsdPurchase> {
      * 获取产品采购指导价
      */
     Map<Long, Map<String, Object>> getProductPriceInfo(EhsdPurchaseDto dto);
+
+    List<EhsdPurchase> getNoInvoiceListBySupplyId(String supplyId);
 }

+ 31 - 0
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseServiceImpl.java

@@ -650,4 +650,35 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         return reData;
     }
 
+
+    /**
+     * 根据供应商查询无发票的采购合同
+     */
+    @Override
+    public List<EhsdPurchase> getNoInvoiceListBySupplyId(String supplyId) {
+        if (StringUtils.isEmpty(supplyId)) {
+            throw new ServiceException("供应商ID不能为空");
+        }
+        List<EhsdPurchase> list = this.list(Wrappers.<EhsdPurchase>query().lambda().eq(EhsdPurchase::getSellCorporationId, supplyId).eq(EhsdPurchase::getStatus, PurchaseStatusEnum.PASS.getKey()).ne(EhsdPurchase::getInvoiceType, "0"));
+        List<Long> ids = list.stream().distinct().map(EhsdPurchase::getId).collect(Collectors.toList());
+        List<InvoiceDetailsVo> invoiceDetailsList = invoiceDetailsService.getSumMoneyByPurchaseIds(ids);
+        Map<Long, BigDecimal> invoiceMap = invoiceDetailsList.stream().collect(Collectors.toMap(InvoiceDetailsVo::getPurchaseId, InvoiceDetailsVo::getSumMoney));
+        List<PayDetailVo> payDetailVoList = payDetailService.getSumMoneyByPurchaseIds(ids);
+        Map<Long, BigDecimal> payMap = payDetailVoList.stream().collect(Collectors.toMap(PayDetailVo::getPurchaseId, PayDetailVo::getSumMoney));
+        for (EhsdPurchase p : list) {
+            if (MapUtils.isNotEmpty(invoiceMap)) {
+                p.setSumInvoiceMoney(invoiceMap.getOrDefault(p.getId(), BigDecimal.ZERO));
+            } else {
+                p.setSumInvoiceMoney(BigDecimal.ZERO);
+            }
+            if (MapUtils.isNotEmpty(payMap)) {
+                p.setSumPayMoney(payMap.getOrDefault(p.getId(), BigDecimal.ZERO));
+            } else {
+                p.setSumPayMoney(BigDecimal.ZERO);
+            }
+        }
+
+        return list;
+    }
+
 }

+ 10 - 0
hx-wms/src/main/java/com/fjhx/wms/service/stock/impl/StockJournalServiceImpl.java

@@ -34,6 +34,7 @@ import com.fjhx.wms.service.stock.StockJournalService;
 import com.fjhx.wms.service.stock.StockWaitDetailsService;
 import com.fjhx.wms.service.stock.StockWaitService;
 import com.fjhx.wms.service.warehouse.WarehouseService;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.system.utils.UserUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,6 +42,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 
 /**
@@ -107,6 +109,14 @@ public class StockJournalServiceImpl extends ServiceImpl<StockJournalMapper, Sto
             }
         }
 
+        //权限过滤:出入库流水-子公司看自己,总公司看全部
+        Long companyId = SecurityUtils.getCompanyId();
+        if (!Objects.equals(companyId, 100L)) {
+            wrapper.eq("sj.company_id", companyId);
+        } else {
+            wrapper.eq("sj.company_id", dto.getCompanyId());
+        }
+
         wrapper.orderByDesc("sj", StockJournal::getCreateTime);
         Page<StockJournalVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         List<StockJournalVo> records = page.getRecords();