Forráskód Böngészése

采购功能修改

yzc 1 éve
szülő
commit
82c72ac965

+ 0 - 8
hx-purchase/src/main/java/com/fjhx/purchase/controller/subscribe/SubscribeDetailController.java

@@ -48,14 +48,6 @@ public class SubscribeDetailController {
         return subscribeDetailService.subscribeStatistics(dto);
     }
 
-//    /**
-//     * 待采购 维多利亚
-//     */
-//    @PostMapping("/pageByWdly")
-//    public Page<SubscribeDetailVo> pageByWdly(@RequestBody SubscribeDetailSelectDto dto) {
-//        return subscribeDetailService.getPageByWdly(dto);
-//    }
-
     /**
      * 申购单明细
      */

+ 14 - 0
hx-purchase/src/main/java/com/fjhx/purchase/entity/subscribe/vo/SubscribeDetailVo.java

@@ -107,4 +107,18 @@ public class SubscribeDetailVo extends SubscribeDetail {
      */
     private String corporationName;
 
+    /**
+     * 产品长
+     */
+    private BigDecimal productLength;
+    /**
+     * 产品宽
+     */
+    private BigDecimal productWidth;
+    /**
+     * 产品高
+     */
+    private BigDecimal productHeight;
+
+
 }

+ 0 - 5
hx-purchase/src/main/java/com/fjhx/purchase/service/subscribe/SubscribeDetailService.java

@@ -26,11 +26,6 @@ public interface SubscribeDetailService extends BaseService<SubscribeDetail> {
      */
     Page<SubscribeDetailVo> getPage(SubscribeDetailSelectDto dto);
 
-//    /**
-//     * 待采购分页 维多利亚
-//     */
-//    Page<SubscribeDetailVo> getPageByWdly(SubscribeDetailSelectDto dto);
-
     /**
      * 申购单明细
      */

+ 222 - 203
hx-purchase/src/main/java/com/fjhx/purchase/service/subscribe/impl/SubscribeDetailServiceImpl.java

@@ -50,209 +50,228 @@ import java.util.stream.Collectors;
 @Service
 public class SubscribeDetailServiceImpl extends ServiceImpl<SubscribeDetailMapper, SubscribeDetail> implements SubscribeDetailService {
 
-    @Autowired
-    private ProductInfoService productInfoService;
-
-    @Autowired
-    private WarehouseService warehouseService;
-
-    @Autowired
-    private PurchaseDetailService purchaseDetailService;
-
-    @Autowired
-    private DictTenantDataService dictTenantDataService;
-
-    @Autowired
-    private CorporationService corporationService;
-
-    /**
-     * 分页
-     *
-     * @param dto
-     * @return
-     */
-    @Override
-    public Page<SubscribeDetailVo> getPage(SubscribeDetailSelectDto dto) {
-        IWrapper<SubscribeDetail> wrapper = getWrapper();
-        // 申购单号
-        wrapper.like("t2", Subscribe::getCode, dto.getCode());
-        // 申购时间
-        wrapper.between("t2", Subscribe::getCreateTime, dto.getBeginTime(), dto.getEndTime());
-        // 申购状态
-        wrapper.ge("t2", Subscribe::getSubcribeStatus, dto.getSubscribeStatus());
-        // 关键字
-        wrapper.like("t2", Subscribe::getCode, dto.getKeyword());
-        // 状态
-        if (ObjectUtil.isNotEmpty(dto.getStatus())) {
-            wrapper.in("t2", SubscribeDetail::getStatus, Arrays.asList(dto.getStatus().split(",")));
-        }
-
-        // 如果类型存在带入类型查询
-        List<ProductInfoVo> productList = productInfoService.getListByProductType(
-                dto.getProductType(), dto.getDefinition(), dto.getProductName(), dto.getProductCode());
-        if (ObjectUtil.isEmpty(productList)) {
-            return new Page<>();
-        }
-        List<Long> productIds = productList.stream().map(ProductInfoVo::getId).collect(Collectors.toList());
-        wrapper.in("t2", SubscribeDetail::getProductId, productIds);
-
-        // 待采购过滤掉指定状态 例如不要 99 作废
-        if (StrUtil.isNotBlank(dto.getNeStatus())) {
-            wrapper.notIn("t2", SubscribeDetail::getStatus, dto.getNeStatus().split(","));
-        }
-        wrapper.orderByDesc("t2", SubscribeDetail::getCreateTime);
-
-        Page<SubscribeDetailVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
-        List<SubscribeDetailVo> list = page.getRecords();
-
-        if (list.size() == 0) {
-            return page;
-        }
-
-        // 赋值产品信息
-        for (SubscribeDetailVo s : list) {
-            Map<Long, ProductInfoVo> productMap = productList.stream().collect(Collectors.toMap(ProductInfoVo::getId, Function.identity()));
-            ProductInfoVo productInfo = productMap.get(s.getProductId());
-            s.setProductCode(productInfo.getCustomCode());
-            s.setProductName(productInfo.getName());
-            s.setProductType(productInfo.getType());
-            s.setProductCategory(productInfo.getClassifyName());
-            s.setProductUnit(productInfo.getUnit());
-            s.setProductDefinition(productInfo.getDefinition());
-            s.setProductCustomCode(productInfo.getCustomCode());
-            s.setProductSpec(productInfo.getSpec());
-        }
-
-        // 赋值采购数量
-        List<Long> subscribeDetailIds = list.stream().map(SubscribeDetail::getId).collect(Collectors.toList());
-        List<PurchaseDetailVo> purchaseDetailsList = purchaseDetailService.getPurchaseCountListBySubscribeDetailIds(subscribeDetailIds);
+	@Autowired
+	private ProductInfoService productInfoService;
+
+	@Autowired
+	private WarehouseService warehouseService;
+
+	@Autowired
+	private PurchaseDetailService purchaseDetailService;
+
+	@Autowired
+	private DictTenantDataService dictTenantDataService;
+
+	@Autowired
+	private CorporationService corporationService;
+
+	/**
+	 * 分页
+	 *
+	 * @param dto
+	 * @return
+	 */
+	@Override
+	public Page<SubscribeDetailVo> getPage(SubscribeDetailSelectDto dto) {
+		IWrapper<SubscribeDetail> wrapper = getWrapper();
+		// 申购单号
+		wrapper.like("t2.subscribeCode", dto.getCode());
+		// 申购时间
+		wrapper.between("t2", Subscribe::getCreateTime, dto.getBeginTime(), dto.getEndTime());
+		// 申购状态
+		wrapper.ge("t2", Subscribe::getSubcribeStatus, dto.getSubscribeStatus());
+		// 关键字
+		wrapper.like("t2.subscribeCode", dto.getKeyword());
+		// 状态
+		if (ObjectUtil.isNotEmpty(dto.getStatus())) {
+			wrapper.in("t2", SubscribeDetail::getStatus, Arrays.asList(dto.getStatus().split(",")));
+		}
+
+		// 如果类型存在带入类型查询
+		List<ProductInfoVo> productList = productInfoService.getListByProductType(
+				dto.getProductType(), dto.getDefinition(), dto.getProductName(), dto.getProductCode());
+		if (ObjectUtil.isEmpty(productList)) {
+			return new Page<>();
+		}
+		List<Long> productIds = productList.stream().map(ProductInfoVo::getId).collect(Collectors.toList());
+		wrapper.in("t2", SubscribeDetail::getProductId, productIds);
+
+		// 待采购过滤掉指定状态 例如不要 99 作废
+		if (StrUtil.isNotBlank(dto.getNeStatus())) {
+			wrapper.notIn("t2", SubscribeDetail::getStatus, dto.getNeStatus().split(","));
+		}
+		wrapper.orderByDesc("t2", SubscribeDetail::getCreateTime);
+
+		Page<SubscribeDetailVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+		List<SubscribeDetailVo> list = page.getRecords();
+
+		if (list.size() == 0) {
+			return page;
+		}
+
+		// 赋值产品信息
+		for (SubscribeDetailVo s : list) {
+			Map<Long, ProductInfoVo> productMap = productList.stream().collect(Collectors.toMap(ProductInfoVo::getId, Function.identity()));
+			ProductInfoVo productInfo = productMap.get(s.getProductId());
+			s.setProductCode(productInfo.getCustomCode());
+			s.setProductName(productInfo.getName());
+			s.setProductType(productInfo.getType());
+			s.setProductCategory(productInfo.getClassifyName());
+			s.setProductUnit(productInfo.getUnit());
+			s.setProductDefinition(productInfo.getDefinition());
+			s.setProductCustomCode(productInfo.getCustomCode());
+			s.setProductSpec(productInfo.getSpec());
+		}
+
+		// 赋值采购数量
+		List<Long> subscribeDetailIds = list.stream().map(SubscribeDetail::getId).collect(Collectors.toList());
+		List<PurchaseDetailVo> purchaseDetailsList = purchaseDetailService.getPurchaseCountListBySubscribeDetailIds(subscribeDetailIds);
 //        List<PurchaseDetail> purchaseDetailsList = purchaseDetailService.list(q -> q.in(PurchaseDetail::getSubscribeDetailId, subscribeDetailIds));
-        Map<Long, List<PurchaseDetail>> purchaseDetailsMap = purchaseDetailsList.stream().collect(Collectors.groupingBy(PurchaseDetail::getSubscribeDetailId));
-        for (SubscribeDetailVo subscribeDetailVo : list) {
-            List<PurchaseDetail> purchaseDetails = purchaseDetailsMap.get(subscribeDetailVo.getId());
-            if (ObjectUtil.isEmpty(purchaseDetails)) {
-                subscribeDetailVo.setPurchaseCount(BigDecimal.ZERO);
-                continue;
-            }
-            BigDecimal count = purchaseDetails.stream().map(PurchaseDetail::getCount).reduce(BigDecimal.ZERO, BigDecimal::add);
-            subscribeDetailVo.setPurchaseCount(count);
-        }
-
-        corporationService.attributeAssign(list, SubscribeDetailVo::getCorporationId, (item, corporation) -> {
-            item.setCorporationName(corporation.getName());
-        });
-
-        return page;
-    }
-
-    /**
-     * 根据IDS获取明细
-     *
-     * @param ids
-     * @return
-     */
-    @Override
-    public List<SubscribeDetailVo> detail(List<Long> ids) {
-        if (CollectionUtils.isEmpty(ids)) {
-            throw new ServiceException("参数异常");
-        }
-        List<SubscribeDetailVo> list = baseMapper.getDetail(ids);
-        if (CollectionUtils.isNotEmpty(list)) {
-            //根据申购businessId取出所有产品
-            List<Long> productIds = list.stream().map(SubscribeDetail::getProductId).collect(Collectors.toList());
-            List<ProductInfoVo> productInfoVos = productInfoService.getListByProductIds(productIds);
-            Map<Long, List<ProductInfoVo>> productMap = productInfoVos.stream().collect(Collectors.groupingBy(ProductInfoVo::getId));
-            for (SubscribeDetailVo s : list) {
-                if (MapUtils.isNotEmpty(productMap)) {
-                    ProductInfoVo p = productMap.get(s.getProductId()).get(0);
-                    s.setProductCategory(p.getClassifyName());
-                    s.setProductCode(p.getCode());
-                    s.setProductUnit(p.getUnit());
-                    s.setProductType(p.getType());
-                    s.setProductName(p.getName());
-                    s.setProductSpec(p.getSpec());
-                    s.setProductCustomCode(p.getCustomCode());
-                    s.setProductDefinition(p.getDefinition());
-                }
-            }
-        }
-        return list;
-    }
-
-    @Override
-    public void add(SubscribeDetailDto subscribeDetailDto) {
-        this.save(subscribeDetailDto);
-    }
-
-    @Override
-    public void edit(SubscribeDetailDto subscribeDetailDto) {
-        this.updateById(subscribeDetailDto);
-    }
-
-    @Override
-    public void delete(Long id) {
-        this.removeById(id);
-    }
-
-    /**
-     * 申购统计(申购单分页)
-     */
-    @Override
-    public Map<String, Object> subscribeStatistics(SubscribeDetailSelectDto dto) {
-        //存放申购统计数据
-        Map<String, Object> map = new HashMap<>();
-
-        //存放申购统计详情数据
-        List<Map<String, Object>> list = new ArrayList<>();
-
-        QueryWrapper<Object> query = Wrappers.query();
-        query.groupBy("pi.type");
-        //查询申购统计(产品类型分组)
-        List<SubscribeDetailVo> subscribeDetailVos = baseMapper.subscribeStatistics(query);
-        Map<String, List<SubscribeDetailVo>> subscribeDetailVoMap = subscribeDetailVos.stream()
-                .collect(Collectors.groupingBy(SubscribeDetailVo::getType));
-
-        //计算申购笔合计数据
-        Integer amount = subscribeDetailVos.stream().map(SubscribeDetailVo::getCounts).reduce(Integer::sum).orElse(0);
-        map.put("amount", amount);
-        //计算申购货品种类合计数据
-        Integer typeAmount = subscribeDetailVos.stream().map(SubscribeDetailVo::getTypeCount).reduce(Integer::sum).orElse(0);
-        map.put("typeAmount", typeAmount);
-        //切换数据源
-        DynamicDataSourceContextHolder.push(SourceConstant.BASE);
-        //获取产品类型字典数据
-        List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
-        DynamicDataSourceContextHolder.poll();
-
-        if (ObjectUtil.isEmpty(dictTenantDataVoList)) {
-            throw new ServiceException("数据有误:产品没有配置产品类型字典,请先添加产品类型字典");
-        }
-
-        //赋值笔数、货品种类数据
-        for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
-            //设置初始值
-            Map<String, Object> typeMap = new HashMap<>();
-            typeMap.put("type", dictTenantDataVo.getDictValue());
-            typeMap.put("count", 0);
-            typeMap.put("typeCount", 0);
-
-            //赋值
-            List<SubscribeDetailVo> subscribeDetailVoList = subscribeDetailVoMap.get(dictTenantDataVo.getDictKey());
-            if (ObjectUtil.isNotEmpty(subscribeDetailVoList)) {
-                typeMap.put("count", subscribeDetailVoList.get(0).getCounts());
-                typeMap.put("typeCount", subscribeDetailVoList.get(0).getTypeCount());
-            }
-            list.add(typeMap);
-        }
-        map.put("productTypeList", list);
-        return map;
-    }
-
-    //根据字典编码获取字典的数据
-    private List<DictTenantDataVo> getDict(String code) {
-        DictTenantDataSelectDto dto = new DictTenantDataSelectDto();
-        dto.setDictCode(code);
-        return dictTenantDataService.getList(dto);
-    }
+		Map<Long, List<PurchaseDetail>> purchaseDetailsMap = purchaseDetailsList.stream().collect(Collectors.groupingBy(PurchaseDetail::getSubscribeDetailId));
+		for (SubscribeDetailVo subscribeDetailVo : list) {
+			List<PurchaseDetail> purchaseDetails = purchaseDetailsMap.get(subscribeDetailVo.getId());
+			if (ObjectUtil.isEmpty(purchaseDetails)) {
+				subscribeDetailVo.setPurchaseCount(BigDecimal.ZERO);
+				continue;
+			}
+			BigDecimal count = purchaseDetails.stream().map(PurchaseDetail::getCount).reduce(BigDecimal.ZERO, BigDecimal::add);
+			subscribeDetailVo.setPurchaseCount(count);
+		}
+
+		corporationService.attributeAssign(list, SubscribeDetailVo::getCorporationId, (item, corporation) -> {
+			item.setCorporationName(corporation.getName());
+		});
+
+		return page;
+	}
+
+	/**
+	 * 根据IDS获取明细
+	 *
+	 * @param ids
+	 * @return
+	 */
+	@Override
+	public List<SubscribeDetailVo> detail(List<Long> ids) {
+		if (CollectionUtils.isEmpty(ids)) {
+			throw new ServiceException("参数异常");
+		}
+		List<SubscribeDetailVo> list = baseMapper.getDetail(ids);
+		if (CollectionUtils.isNotEmpty(list)) {
+			//根据申购businessId取出所有产品
+			List<Long> productIds = list.stream().map(SubscribeDetail::getProductId).collect(Collectors.toList());
+			List<ProductInfoVo> productInfoVos = productInfoService.getListByProductIds(productIds);
+			Map<Long, List<ProductInfoVo>> productMap = productInfoVos.stream().collect(Collectors.groupingBy(ProductInfoVo::getId));
+			for (SubscribeDetailVo s : list) {
+				if (MapUtils.isNotEmpty(productMap)) {
+					ProductInfoVo p = productMap.get(s.getProductId()).get(0);
+					s.setProductCategory(p.getClassifyName());
+					s.setProductCode(p.getCode());
+					s.setProductUnit(p.getUnit());
+					s.setProductType(p.getType());
+					s.setProductName(p.getName());
+					s.setProductSpec(p.getSpec());
+					s.setProductCustomCode(p.getCustomCode());
+					s.setProductDefinition(p.getDefinition());
+					s.setProductLength(p.getLength());
+					s.setProductWidth(p.getWidth());
+					s.setProductHeight(p.getHeight());
+				}
+			}
+		}
+
+		// 赋值采购数量
+		List<Long> subscribeDetailIds = list.stream().map(SubscribeDetail::getId).collect(Collectors.toList());
+		List<PurchaseDetailVo> purchaseDetailsList = purchaseDetailService.getPurchaseCountListBySubscribeDetailIds(subscribeDetailIds);
+		Map<Long, List<PurchaseDetail>> purchaseDetailsMap = purchaseDetailsList.stream().collect(Collectors.groupingBy(PurchaseDetail::getSubscribeDetailId));
+		for (SubscribeDetailVo subscribeDetailVo : list) {
+			List<PurchaseDetail> purchaseDetails = purchaseDetailsMap.get(subscribeDetailVo.getId());
+			if (ObjectUtil.isEmpty(purchaseDetails)) {
+				subscribeDetailVo.setPurchaseCount(BigDecimal.ZERO);
+				continue;
+			}
+			BigDecimal count = purchaseDetails.stream().map(PurchaseDetail::getCount).reduce(BigDecimal.ZERO, BigDecimal::add);
+			subscribeDetailVo.setPurchaseCount(count);
+		}
+
+
+		return list;
+	}
+
+	@Override
+	public void add(SubscribeDetailDto subscribeDetailDto) {
+		this.save(subscribeDetailDto);
+	}
+
+	@Override
+	public void edit(SubscribeDetailDto subscribeDetailDto) {
+		this.updateById(subscribeDetailDto);
+	}
+
+	@Override
+	public void delete(Long id) {
+		this.removeById(id);
+	}
+
+	/**
+	 * 申购统计(申购单分页)
+	 */
+	@Override
+	public Map<String, Object> subscribeStatistics(SubscribeDetailSelectDto dto) {
+		//存放申购统计数据
+		Map<String, Object> map = new HashMap<>();
+
+		//存放申购统计详情数据
+		List<Map<String, Object>> list = new ArrayList<>();
+
+		QueryWrapper<Object> query = Wrappers.query();
+		query.groupBy("pi.type");
+		//查询申购统计(产品类型分组)
+		List<SubscribeDetailVo> subscribeDetailVos = baseMapper.subscribeStatistics(query);
+		Map<String, List<SubscribeDetailVo>> subscribeDetailVoMap = subscribeDetailVos.stream()
+				.collect(Collectors.groupingBy(SubscribeDetailVo::getType));
+
+		//计算申购笔合计数据
+		Integer amount = subscribeDetailVos.stream().map(SubscribeDetailVo::getCounts).reduce(Integer::sum).orElse(0);
+		map.put("amount", amount);
+		//计算申购货品种类合计数据
+		Integer typeAmount = subscribeDetailVos.stream().map(SubscribeDetailVo::getTypeCount).reduce(Integer::sum).orElse(0);
+		map.put("typeAmount", typeAmount);
+		//切换数据源
+		DynamicDataSourceContextHolder.push(SourceConstant.BASE);
+		//获取产品类型字典数据
+		List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
+		DynamicDataSourceContextHolder.poll();
+
+		if (ObjectUtil.isEmpty(dictTenantDataVoList)) {
+			throw new ServiceException("数据有误:产品没有配置产品类型字典,请先添加产品类型字典");
+		}
+
+		//赋值笔数、货品种类数据
+		for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
+			//设置初始值
+			Map<String, Object> typeMap = new HashMap<>();
+			typeMap.put("type", dictTenantDataVo.getDictValue());
+			typeMap.put("count", 0);
+			typeMap.put("typeCount", 0);
+
+			//赋值
+			List<SubscribeDetailVo> subscribeDetailVoList = subscribeDetailVoMap.get(dictTenantDataVo.getDictKey());
+			if (ObjectUtil.isNotEmpty(subscribeDetailVoList)) {
+				typeMap.put("count", subscribeDetailVoList.get(0).getCounts());
+				typeMap.put("typeCount", subscribeDetailVoList.get(0).getTypeCount());
+			}
+			list.add(typeMap);
+		}
+		map.put("productTypeList", list);
+		return map;
+	}
+
+	//根据字典编码获取字典的数据
+	private List<DictTenantDataVo> getDict(String code) {
+		DictTenantDataSelectDto dto = new DictTenantDataSelectDto();
+		dto.setDictCode(code);
+		return dictTenantDataService.getList(dto);
+	}
 
 }

+ 3 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/dto/EhsdPurchaseDto.java

@@ -2,6 +2,7 @@ package com.fjhx.sale.entity.purchase.dto;
 
 import com.fjhx.area.service.SetCustomizeAreaId;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
+import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -48,4 +49,6 @@ public class EhsdPurchaseDto extends EhsdPurchase implements SetCustomizeAreaId
      * 产品id列表
      */
     private List<Long> productIds;
+
+    private List<EhsdPurchaseProduct> purchaseProductList;
 }

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

@@ -263,11 +263,6 @@ public class EhsdPurchase extends BasePo {
     @TableField(exist = false)
     private List<EhsdPurchaseArrival> purchaseArrivalList;
 
-    /**
-     * 采购商品列表
-     */
-    @TableField(exist = false)
-    private List<EhsdPurchaseProduct> purchaseProductList;
 
     /**
      * 采购商品列表

+ 13 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseProductVo.java

@@ -66,4 +66,17 @@ public class EhsdPurchaseProductVo extends EhsdPurchaseProduct {
      * 采购单号
      */
     private String purchaseCode;
+
+    /**
+     * 产品长
+     */
+    private BigDecimal productLength;
+    /**
+     * 产品宽
+     */
+    private BigDecimal productWidth;
+    /**
+     * 产品高
+     */
+    private BigDecimal productHeight;
 }

+ 60 - 71
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseVo.java

@@ -19,75 +19,64 @@ import java.util.List;
 @Setter
 public class EhsdPurchaseVo extends EhsdPurchase {
 
-    /**
-     * 采购明细
-     */
-    private List<EhsdPurchaseProductVo> ehsdPurchaseProductList;
-
-    /**
-     * 装箱明细
-     */
-    private List<PackDetailProductVo> packDetailProductList;
-
-    /**
-     * 买方名称
-     */
-    private String buyCorporationName;
-    /**
-     * 卖方名称
-     */
-    private String sellCorporationName;
-
-    /**
-     * 卖方国家表名称
-     */
-    private String sellCountryName;
-
-    /**
-     * 卖方省份名称
-     */
-    private String sellProvinceName;
-
-    /**
-     * 卖方城市名称
-     */
-    private String sellCityName;
-
-
-    /**
-     * 开户银行
-     */
-    private String openingBank;
-    /**
-     * 账户名
-     */
-    private String openingName;
-    /**
-     * 联系人
-     */
-    private String contactPerson;
-    /**
-     * 账户
-     */
-    private String accountOpening;
-
-    /**
-     * 流程Id
-     */
-    private Long flowId;
-
-    /**
-     * 发票总金额
-     */
-    private BigDecimal sumInvoiceMoney;
-
-    /**
-     * 付款总金额
-     */
-    private BigDecimal sumPayMoney;
-
-    /**
-     * 历史毛利信息
-     */
-    List<ContractBudgetVo.GrossProfitInfo> grossProfitInfoList;
+	/**
+	 * 历史毛利信息
+	 */
+	List<ContractBudgetVo.GrossProfitInfo> grossProfitInfoList;
+	/**
+	 * 采购商品列表
+	 */
+	private List<EhsdPurchaseProductVo> purchaseProductList;
+	/**
+	 * 装箱明细
+	 */
+	private List<PackDetailProductVo> packDetailProductList;
+	/**
+	 * 买方名称
+	 */
+	private String buyCorporationName;
+	/**
+	 * 卖方名称
+	 */
+	private String sellCorporationName;
+	/**
+	 * 卖方国家表名称
+	 */
+	private String sellCountryName;
+	/**
+	 * 卖方省份名称
+	 */
+	private String sellProvinceName;
+	/**
+	 * 卖方城市名称
+	 */
+	private String sellCityName;
+	/**
+	 * 开户银行
+	 */
+	private String openingBank;
+	/**
+	 * 账户名
+	 */
+	private String openingName;
+	/**
+	 * 联系人
+	 */
+	private String contactPerson;
+	/**
+	 * 账户
+	 */
+	private String accountOpening;
+	/**
+	 * 流程Id
+	 */
+	private Long flowId;
+	/**
+	 * 发票总金额
+	 */
+	private BigDecimal sumInvoiceMoney;
+	/**
+	 * 付款总金额
+	 */
+	private BigDecimal sumPayMoney;
 }

+ 270 - 318
hx-sale/src/main/java/com/fjhx/sale/flow/EhsdPurchaseFlow.java

@@ -1,6 +1,7 @@
 package com.fjhx.sale.flow;
 
 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;
@@ -24,7 +25,6 @@ import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
 import com.fjhx.sale.entity.contract.po.Contract;
 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.entity.sample.po.Sample;
@@ -46,7 +46,6 @@ 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.math.BigDecimal;
 import java.util.ArrayList;
@@ -64,320 +63,273 @@ import java.util.stream.Collectors;
 @Component
 public class EhsdPurchaseFlow extends FlowDelegate {
 
-    @Autowired
-    private EhsdPurchaseService purchaseService;
-
-    @Autowired
-    private EhsdPurchaseProductService purchaseProductService;
-
-    @Autowired
-    private EhsdPurchaseProjectService purchaseProjectService;
-    @Autowired
-    private SampleProductService sampleProductService;
-
-    @Autowired
-    private CodingRuleService codingRuleService;
-    @Autowired
-    private SubscribeDetailService subscribeDetailService;
-    @Autowired
-    private ContractService contractService;
-    @Autowired
-    private SampleService sampleService;
-    @Autowired
-    private ProductInfoService productInfoService;
-    @Autowired
-    private StockWaitService stockWaitService;
-    @Autowired
-    private StockWaitDetailsService stockWaitDetailsService;
-
-    @Override
-    public String getFlowKey() {
-        return "purchase_flow";
-    }
-
-    /**
-     * 发起流程
-     *
-     * @param flowId     流程ID
-     * @param submitData 采购数据
-     * @return
-     */
-    @Override
-    public Long start(Long flowId, JSONObject submitData) {
-        EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
-        purchase.setId(null);
-        purchase.setFlowId(flowId);
-
-        //手动创建 编号规则
-        if (0 == purchase.getDataResource()) {
-            purchase.setCode(codingRuleService.createCode(CodingRuleEnum.EHSD_PURCHASE.getKey(), null));
-        }
-        //合同 编号规则
-        if (1 == purchase.getDataResource()) {
-            Contract contract = contractService.getById(purchase.getDataResourceId());
-            Assert.notEmpty(contract, "查询不到合同信息,无法生成编号");
-            long count = purchaseService.count(q -> q.eq(EhsdPurchase::getDataResourceId, contract.getId()));
-            purchase.setCode(contract.getCode() + "-" + (count + 1));
-        }
-        //样品单 编号规则
-        if (2 == purchase.getDataResource()) {
-            Sample sample = sampleService.getById(purchase.getDataResourceId());
-            Assert.notEmpty(sample, "查询不到样品单信息,无法生成编号");
-            long count = purchaseService.count(q -> q.eq(EhsdPurchase::getDataResourceId, sample.getId()));
-            purchase.setCode(sample.getCode() + "-" + (count + 1));
-        }
-
-        //公共代码
-        purchase = connStart(purchase);
-
-        return purchase.getId();
-    }
-
-
-    /**
-     * 公共代码块--发起
-     */
-    public EhsdPurchaseDto connStart(EhsdPurchaseDto purchase) {
-        //赋值城市省份信息
-        CustomizeAreaUtil.setAreaId(purchase);
-        purchase.setSellCityId(purchase.getCityId());
-        purchase.setSellCountryId(purchase.getCountryId());
-        purchase.setSellProvinceId(purchase.getProvinceId());
-
-
-        purchase.setStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
-        String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
-        purchase.setUserName(nickName);
-        purchaseService.saveOrUpdate(purchase);
-        List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
-        List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
-        List<EhsdPurchaseArrival> purchaseArrivalList = purchase.getPurchaseArrivalList();
-
-        //防止空指针
-        purchaseArrivalList = (purchaseArrivalList == null ? new ArrayList<>() : purchaseArrivalList);
-        purchaseProjectList = (purchaseProjectList == null ? new ArrayList<>() : purchaseProjectList);
-        purchaseProductList = (purchaseProductList == null ? new ArrayList<>() : purchaseProductList);
-
-        //产品(采购明细)
-        for (EhsdPurchaseProduct s : purchaseProductList) {
-            s.setId(ObjectUtils.isNotEmpty(s.getId()) ? s.getId() : IdWorker.getId());
-            s.setPurchaseId(purchase.getId());
-//            List<EhsdPurchaseProductMountings> purchaseProductMountingsList = s.getPurchaseProductMountingsList();
-//            if (CollectionUtils.isNotEmpty(purchaseProductMountingsList)) {//产品配件
-//                purchaseProductMountingsList.forEach(obj -> obj.setPurchaseProductId(id));
-//            }
-//            //修改或删除数据
-//            purchaseProductMountingsService.editLinked(purchaseProductMountingsList,
-//                    EhsdPurchaseProductMountings::getPurchaseProductId, id);
-
-            if ("0".equals(purchase.getDataResource())) {
-                //计算采购数量是否大于申购数量
-                List<EhsdPurchaseProduct> purchaseDetailList1 = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getSubscribeDetailId,
-                        s.getSubscribeDetailId()));
-                //求和
-                BigDecimal purchaseCount = purchaseDetailList1.stream()
-                        .map(EhsdPurchaseProduct::getQuantity)
-                        .reduce(BigDecimal.ZERO, BigDecimal::add);
-                //计算历史采购数量+本次采购数量之和
-                BigDecimal count = purchaseCount.add(s.getQuantity());
-                //判断采购数量是否大于申购数量
-                SubscribeDetail subscribeDetail = subscribeDetailService.getById(s.getSubscribeDetailId());
-                if (count.compareTo(subscribeDetail.getCount()) > 0) {
-                    throw new ServiceException("采购数量不能大于申购数量");
-                }
-            }
-        }
-        //修改或删除数据
-        purchaseProductService.editLinked(purchaseProductList, EhsdPurchaseProduct::getPurchaseId, purchase.getId());
-
-        //收费项目
-        for (EhsdPurchaseProject s : purchaseProjectList) {
-            s.setPurchaseId(purchase.getId());
-        }
-        purchaseProjectService.editLinked(purchaseProjectList, EhsdPurchaseProject::getPurchaseId, purchase.getId());
-
-//        //到货
-//        for (EhsdPurchaseArrival s : purchaseArrivalList) {
-//            s.setPurchaseId(purchase.getId());
-//        }
-//        purchaseArrivalService.editLinked(purchaseArrivalList, EhsdPurchaseArrival::getPurchaseId, purchase.getId());
-
-        return purchase;
-    }
-
-    /**
-     * 结束流程
-     *
-     * @param flowId     流程ID
-     * @param businessId 业务ID
-     * @param submitData 数据
-     */
-    @Override
-    public void end(Long flowId, Long businessId, JSONObject submitData) {
-        //通过业务ID查询采购数据
-        EhsdPurchase purchase = purchaseService.getById(businessId);
-        if (ObjectUtils.isEmpty(purchase)) {
-            throw new ServiceException("采购单不存在,或已被删除");
-        }
-        //查询采购产品
-        List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(Wrappers.<EhsdPurchaseProduct>query().lambda().eq(EhsdPurchaseProduct::getPurchaseId, businessId));
-//        List<ContractProduct> upContractProduct = new ArrayList<>();
-        List<SampleProduct> upSampleProduct = new ArrayList<>();
-        for (EhsdPurchaseProduct p : purchaseProductList) {
-//            if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
-//                    p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
-//                ContractProduct contractProduct = contractProductService.getById(p.getDataResourceId());
-//                BigDecimal expendQuantity = contractProduct.getExpendQuantity().subtract(p.getQuantity());
-//                if (expendQuantity.compareTo(BigDecimal.ZERO) < 0) {//小于0不让继续执行
-//                    throw new ServiceException("采购数量不得大于合同剩余采购数量,请驳回审批修改");
-//                }
-//                contractProduct.setExpendQuantity(expendQuantity);
-//                upContractProduct.add(contractProduct);
-//            }
-            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(upContractProduct)) {//扣减销售合同数量
-//            contractProductService.updateBatchById(upContractProduct);
-//        }
-        if (CollectionUtils.isNotEmpty(upSampleProduct)) {//扣减样品单数量
-            sampleProductService.updateBatchById(upSampleProduct);
-        }
-        //修改采购状态为审批通过
-        purchase.setStatus(PurchaseStatusEnum.PASS.getKey());
-        purchase.setApprovedDate(new Date());
-        purchaseService.updateById(purchase);
-
-        if ("0".equals(purchase.getDataResource())) {
-            //修改申购明细状态
-            List<EhsdPurchaseProduct> purchaseDetailList = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getProductId, businessId));
-            List<Long> subscribeDetailIds = purchaseDetailList.stream().map(EhsdPurchaseProduct::getSubscribeDetailId).collect(Collectors.toList());
-            List<SubscribeDetail> subscribeDetails = subscribeDetailService.listByIds(subscribeDetailIds);
-            for (SubscribeDetail subscribeDetail : subscribeDetails) {
-                //获取申购明细下的所有采购记录 计算已采购数
-                List<EhsdPurchaseProduct> purchaseDetails = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getSubscribeDetailId,
-                        subscribeDetail.getId()).eq(EhsdPurchaseProduct::getProductId, subscribeDetail.getProductId()));
-                BigDecimal count = purchaseDetails.stream()
-                        .map(EhsdPurchaseProduct::getQuantity)
-                        .reduce(BigDecimal.ZERO, BigDecimal::add);
-                if (count.compareTo(subscribeDetail.getCount()) >= 0) {
-                    //修改为已采购
-                    subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
-                } else {
-                    //修改为部分采购
-                    subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
-                }
-            }
-            subscribeDetailService.updateBatchById(subscribeDetails);
-        }
-
-
-        List<InOutBo> inOutBoList = new ArrayList<>();
-        for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
-            //如果数据来源是申购 操作可用库存(可用库存 = 当前可用库存 + 采购明细数量)
-            if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0)) {
-                InOutBo inOutBo = new InOutBo();
-                inOutBo.setProductId(purchaseProduct.getProductId());
-                inOutBo.setQuantity(purchaseProduct.getQuantity());
-                inOutBoList.add(inOutBo);
-            }
-        }
-        productInfoService.editAvailableQuantity(inOutBoList, InOutType.IN, businessId, ProductAvailableRecordType.PURCHASE_PASS);
-
-
-        //采购审批通过 生成待入库数据
-        StockWait stockWait = new StockWait();
-        stockWait.setType(1);
-        stockWait.setBusinessType(StockWaitType.PURCHASE_ARRIVAL_IN.getDetailType());
-        stockWait.setBusinessId(purchase.getId());
-        stockWait.setBusinessCode(purchase.getCode());
-        stockWait.setStatus(0);
-        stockWait.setPurchaseId(purchase.getId());
-        stockWaitService.save(stockWait);
-        List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
-        for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
-            StockWaitDetails stockWaitDetails = new StockWaitDetails();
-            stockWaitDetails.setStockWaitId(stockWait.getId());
-            stockWaitDetails.setBusinessDetailsId(purchaseProduct.getId());
-            stockWaitDetails.setPurchaseDetailId(purchaseProduct.getId());
-
-            stockWaitDetails.setProductId(purchaseProduct.getProductId());
-            stockWaitDetails.setQuantity(purchaseProduct.getQuantity());
-            stockWaitDetails.setStatus(0);
-
-            stockWaitDetailsList.add(stockWaitDetails);
-        }
-        stockWaitDetailsService.saveBatch(stockWaitDetailsList);
-    }
-
-    /**
-     * 重新发起
-     *
-     * @param flowId
-     * @param businessId
-     * @param flowStatus
-     * @param submitData
-     */
-    @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);
-        connStart(purchase);
-    }
-
-    /**
-     * 驳回
-     *
-     * @param flowId
-     * @param businessId
-     * @param flowStatus
-     */
-    @Override
-    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
-        purchaseService.update(q -> q
-                .eq(EhsdPurchase::getId, businessId)
-                .set(EhsdPurchase::getStatus, FlowStatusEnum1.REJECT.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);
-        purchaseService.update(q -> q
-                .eq(EhsdPurchase::getId, businessId)
-                .set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
-                .set(BasePo::getUpdateTime, new Date())
-                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-        );
-
-        //修改可用库存
-        List<InOutBo> inOutBoList = new ArrayList<>();
-        List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, businessId));
-        for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
-            //如果数据来源是申购 操作可用库存(可用库存 = 当前可用库存 + 采购明细数量)
-            if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0)) {
-                InOutBo inOutBo = new InOutBo();
-                inOutBo.setProductId(purchaseProduct.getProductId());
-                inOutBo.setQuantity(purchaseProduct.getQuantity());
-                inOutBoList.add(inOutBo);
-            }
-        }
-        productInfoService.editAvailableQuantity(inOutBoList, InOutType.OUT, businessId, ProductAvailableRecordType.PURCHASE_CANCEL);
-    }
+	@Autowired
+	private EhsdPurchaseService purchaseService;
+
+	@Autowired
+	private EhsdPurchaseProductService purchaseProductService;
+
+	@Autowired
+	private EhsdPurchaseProjectService purchaseProjectService;
+	@Autowired
+	private SampleProductService sampleProductService;
+
+	@Autowired
+	private CodingRuleService codingRuleService;
+	@Autowired
+	private SubscribeDetailService subscribeDetailService;
+	@Autowired
+	private ContractService contractService;
+	@Autowired
+	private SampleService sampleService;
+	@Autowired
+	private ProductInfoService productInfoService;
+	@Autowired
+	private StockWaitService stockWaitService;
+	@Autowired
+	private StockWaitDetailsService stockWaitDetailsService;
+
+	@Override
+	public String getFlowKey() {
+		return "purchase_flow";
+	}
+
+	/**
+	 * 发起流程
+	 *
+	 * @param flowId     流程ID
+	 * @param submitData 采购数据
+	 * @return
+	 */
+	@Override
+	public Long start(Long flowId, JSONObject submitData) {
+		EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
+		purchase.setId(null);//清空id防止前端误传
+		purchase.setFlowId(flowId);//赋值流程id
+		purchase.setProcessInstanceId(getFlowKey());//赋值流程key
+
+		Integer dataResource = purchase.getDataResource();
+		if (ObjectUtils.isEmpty(dataResource)) {
+			throw new ServiceException("数据来源类型不能为空!");
+		}
+
+		//采购单编号生成
+		if (0 == dataResource) {
+			//手动创建 编号规则
+			purchase.setCode(codingRuleService.createCode(CodingRuleEnum.EHSD_PURCHASE.getKey(), null));
+		} else if (1 == dataResource) {
+			//合同 编号规则
+			Contract contract = contractService.getById(purchase.getDataResourceId());
+			Assert.notEmpty(contract, "查询不到合同信息,无法生成编号");
+			long count = purchaseService.count(q -> q.eq(EhsdPurchase::getDataResourceId, contract.getId()));
+			purchase.setCode(contract.getCode() + "-" + (count + 1));
+		} else if (2 == dataResource) {
+			//样品单 编号规则
+			Sample sample = sampleService.getById(purchase.getDataResourceId());
+			Assert.notEmpty(sample, "查询不到样品单信息,无法生成编号");
+			long count = purchaseService.count(q -> q.eq(EhsdPurchase::getDataResourceId, sample.getId()));
+			purchase.setCode(sample.getCode() + "-" + (count + 1));
+		} else {
+			throw new ServiceException("未知数据来源类型");
+		}
+
+		//公共代码
+		purchase = connStart(purchase);
+
+		return purchase.getId();
+	}
+
+
+	/**
+	 * 公共代码块--发起
+	 */
+	public EhsdPurchaseDto connStart(EhsdPurchaseDto purchase) {
+		//赋值城市省份信息
+		CustomizeAreaUtil.setAreaId(purchase);
+		purchase.setSellCityId(purchase.getCityId());
+		purchase.setSellCountryId(purchase.getCountryId());
+		purchase.setSellProvinceId(purchase.getProvinceId());
+
+
+		purchase.setStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
+		String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
+		purchase.setUserName(nickName);
+		purchaseService.saveOrUpdate(purchase);
+
+		List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
+		List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
+
+		//防止空指针
+		purchaseProjectList = (purchaseProjectList == null ? new ArrayList<>() : purchaseProjectList);
+		purchaseProductList = (purchaseProductList == null ? new ArrayList<>() : purchaseProductList);
+
+		//产品(采购明细)
+		for (EhsdPurchaseProduct s : purchaseProductList) {
+			s.setId(ObjectUtils.isNotEmpty(s.getId()) ? s.getId() : IdWorker.getId());
+			s.setPurchaseId(purchase.getId());
+		}
+		//修改或删除数据
+		purchaseProductService.editLinked(purchaseProductList, EhsdPurchaseProduct::getPurchaseId, purchase.getId());
+
+		//收费项目
+		for (EhsdPurchaseProject s : purchaseProjectList) {
+			s.setPurchaseId(purchase.getId());
+		}
+		purchaseProjectService.editLinked(purchaseProjectList, EhsdPurchaseProject::getPurchaseId, purchase.getId());
+
+		return purchase;
+	}
+
+	/**
+	 * 结束流程
+	 *
+	 * @param flowId     流程ID
+	 * @param businessId 业务ID
+	 * @param submitData 数据
+	 */
+	@Override
+	public void end(Long flowId, Long businessId, JSONObject submitData) {
+		//通过业务ID查询采购数据
+		EhsdPurchase purchase = purchaseService.getById(businessId);
+		if (ObjectUtils.isEmpty(purchase)) {
+			throw new ServiceException("采购单不存在,或已被删除");
+		}
+		//查询采购产品
+		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());
+		purchaseService.updateById(purchase);
+
+		if ("0".equals(purchase.getDataResource())) {
+			//修改申购明细状态
+			List<EhsdPurchaseProduct> purchaseDetailList = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getProductId, businessId));
+			List<Long> subscribeDetailIds = purchaseDetailList.stream().map(EhsdPurchaseProduct::getSubscribeDetailId).collect(Collectors.toList());
+			List<SubscribeDetail> subscribeDetails = subscribeDetailService.listByIds(subscribeDetailIds);
+			for (SubscribeDetail subscribeDetail : subscribeDetails) {
+				//获取申购明细下的所有采购记录 计算已采购数
+				List<EhsdPurchaseProduct> purchaseDetails = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getSubscribeDetailId,
+						subscribeDetail.getId()).eq(EhsdPurchaseProduct::getProductId, subscribeDetail.getProductId()));
+				BigDecimal count = purchaseDetails.stream()
+						.map(EhsdPurchaseProduct::getQuantity)
+						.reduce(BigDecimal.ZERO, BigDecimal::add);
+				if (count.compareTo(subscribeDetail.getCount()) >= 0) {
+					//修改为已采购
+					subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
+				} else {
+					//修改为部分采购
+					subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
+				}
+			}
+			subscribeDetailService.updateBatchById(subscribeDetails);
+		}
+
+
+		List<InOutBo> inOutBoList = new ArrayList<>();
+		for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
+			//如果数据来源是申购 操作可用库存(可用库存 = 当前可用库存 + 采购明细数量)
+			if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0)) {
+				InOutBo inOutBo = new InOutBo();
+				inOutBo.setProductId(purchaseProduct.getProductId());
+				inOutBo.setQuantity(purchaseProduct.getQuantity());
+				inOutBoList.add(inOutBo);
+			}
+		}
+		productInfoService.editAvailableQuantity(inOutBoList, InOutType.IN, businessId, ProductAvailableRecordType.PURCHASE_PASS);
+
+
+		//采购审批通过 生成待入库数据
+		StockWait stockWait = new StockWait();
+		stockWait.setType(1);
+		stockWait.setBusinessType(StockWaitType.PURCHASE_ARRIVAL_IN.getDetailType());
+		stockWait.setBusinessId(purchase.getId());
+		stockWait.setBusinessCode(purchase.getCode());
+		stockWait.setStatus(0);
+		stockWait.setPurchaseId(purchase.getId());
+		stockWaitService.save(stockWait);
+		List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
+		for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
+			StockWaitDetails stockWaitDetails = new StockWaitDetails();
+			stockWaitDetails.setStockWaitId(stockWait.getId());
+			stockWaitDetails.setBusinessDetailsId(purchaseProduct.getId());
+			stockWaitDetails.setPurchaseDetailId(purchaseProduct.getId());
+
+			stockWaitDetails.setProductId(purchaseProduct.getProductId());
+			stockWaitDetails.setQuantity(purchaseProduct.getQuantity());
+			stockWaitDetails.setStatus(0);
+
+			stockWaitDetailsList.add(stockWaitDetails);
+		}
+		stockWaitDetailsService.saveBatch(stockWaitDetailsList);
+	}
+
+	/**
+	 * 重新发起
+	 */
+	@Override
+	@LogicIgnore
+	@DSTransactional
+	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);
+		connStart(purchase);
+	}
+
+	/**
+	 * 驳回
+	 */
+	@Override
+	public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+		purchaseService.update(q -> q
+				.eq(EhsdPurchase::getId, businessId)
+				.set(EhsdPurchase::getStatus, FlowStatusEnum1.REJECT.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);
+		purchaseService.update(q -> q
+				.eq(EhsdPurchase::getId, businessId)
+				.set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
+				.set(BasePo::getUpdateTime, new Date())
+				.set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+		);
+
+		//修改可用库存
+		List<InOutBo> inOutBoList = new ArrayList<>();
+		List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, businessId));
+		for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
+			//如果数据来源是申购 操作可用库存(可用库存 = 当前可用库存 + 采购明细数量)
+			if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0)) {
+				InOutBo inOutBo = new InOutBo();
+				inOutBo.setProductId(purchaseProduct.getProductId());
+				inOutBo.setQuantity(purchaseProduct.getQuantity());
+				inOutBoList.add(inOutBo);
+			}
+		}
+		productInfoService.editAvailableQuantity(inOutBoList, InOutType.OUT, businessId, ProductAvailableRecordType.PURCHASE_CANCEL);
+	}
 }

+ 16 - 11
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseServiceImpl.java

@@ -3,7 +3,6 @@ package com.fjhx.sale.service.purchase.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson2.JSONObject;
-import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -45,7 +44,10 @@ import com.fjhx.sale.entity.pack.po.PackDetailProduct;
 import com.fjhx.sale.entity.pack.vo.PackDetailProductVo;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseDto;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseSelectDto;
-import com.fjhx.sale.entity.purchase.po.*;
+import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
+import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
+import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProductMountings;
+import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProject;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseDocumentaryVo;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseVo;
@@ -280,10 +282,13 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         //赋值产品信息
         productInfoService.attributeAssign(ehsdPurchaseProductVos, EhsdPurchaseProductVo::getProductId, (item, product) -> {
             item.setDefinition(product.getDefinition());
-            item.setProductCode(product.getCode());
+            item.setProductCode(product.getCustomCode());
             item.setProductSpec(product.getSpec());
+            item.setProductLength(product.getLength());
+            item.setProductWidth(product.getWidth());
+            item.setProductHeight(product.getHeight());
         });
-        result.setEhsdPurchaseProductList(ehsdPurchaseProductVos);
+        result.setPurchaseProductList(ehsdPurchaseProductVos);
         //赋值出货明细
         List<Long> cpIds = ehsdPurchaseProductVos.stream().map(EhsdPurchaseProductVo::getDataResourceId).collect(Collectors.toList());
         List<PackDetailProduct> packDetailProductList = packDetailProductService.list(q ->
@@ -301,13 +306,13 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         //赋值其他收费项目
         List<EhsdPurchaseProject> ehsdPurchaseProjects = ehsdPurchaseProjectService.list(q -> q.eq(EhsdPurchaseProject::getPurchaseId, id));
         result.setPurchaseProjectList(ehsdPurchaseProjects);
-        //赋值到货信息
-        List<EhsdPurchaseArrival> ehsdPurchaseArrivalList = ehsdPurchaseArrivalService.list(q -> q.eq(EhsdPurchaseArrival::getPurchaseId, id));
-        productInfoService.attributeAssign(ehsdPurchaseArrivalList, EhsdPurchaseArrival::getProductId, (item, product) -> {
-            item.setProductName(product.getName());
-            item.setProductCode(product.getCode());
-        });
-        result.setPurchaseArrivalList(ehsdPurchaseArrivalList);
+//        //赋值到货信息
+//        List<EhsdPurchaseArrival> ehsdPurchaseArrivalList = ehsdPurchaseArrivalService.list(q -> q.eq(EhsdPurchaseArrival::getPurchaseId, id));
+//        productInfoService.attributeAssign(ehsdPurchaseArrivalList, EhsdPurchaseArrival::getProductId, (item, product) -> {
+//            item.setProductName(product.getName());
+//            item.setProductCode(product.getCode());
+//        });
+//        result.setPurchaseArrivalList(ehsdPurchaseArrivalList);
 
         //赋值历史毛利图信息
         IWrapper<Contract> wrapper = IWrapper.<Contract>getWrapper().eq("t1.contractId", result.getDataResourceId());