|
@@ -12,19 +12,17 @@ import com.gree.mall.manager.bean.material.manage.WebsitPurchaseApplyVO;
|
|
|
import com.gree.mall.manager.bean.material.vender.WebsitPurchaseCheckVO;
|
|
|
import com.gree.mall.manager.bean.material.vender.WebsitVenderGoodsRelaVO;
|
|
|
import com.gree.mall.manager.commonmapper.MaterialMapper;
|
|
|
+import com.gree.mall.manager.enums.IsEnum;
|
|
|
import com.gree.mall.manager.enums.IsYesNoEnum;
|
|
|
import com.gree.mall.manager.enums.material.MaterialFlagEnum;
|
|
|
import com.gree.mall.manager.enums.material.StateEnum;
|
|
|
import com.gree.mall.manager.enums.material.WebsitGoodsTypeEnum;
|
|
|
import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
import com.gree.mall.manager.logic.common.CommonLogic;
|
|
|
+import com.gree.mall.manager.logic.material.stock.WebitPurchaseStockLogic;
|
|
|
import com.gree.mall.manager.logic.material.vender.VenderGoodsLogic;
|
|
|
-import com.gree.mall.manager.plus.entity.WebsitPurchase;
|
|
|
-import com.gree.mall.manager.plus.entity.WebsitPurchaseItem;
|
|
|
-import com.gree.mall.manager.plus.entity.WebsitVender;
|
|
|
-import com.gree.mall.manager.plus.service.WebsitPurchaseItemService;
|
|
|
-import com.gree.mall.manager.plus.service.WebsitPurchaseService;
|
|
|
-import com.gree.mall.manager.plus.service.WebsitVenderService;
|
|
|
+import com.gree.mall.manager.plus.entity.*;
|
|
|
+import com.gree.mall.manager.plus.service.*;
|
|
|
import com.gree.mall.manager.zfire.bean.QueryParamBean;
|
|
|
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
|
|
|
import com.gree.mall.manager.zfire.util.FieldUtils;
|
|
@@ -51,6 +49,10 @@ public class WebsitMPurchaseLogic {
|
|
|
private final WebsitPurchaseItemService websitPurchaseItemService;
|
|
|
private final VenderGoodsLogic venderGoodsLogic;
|
|
|
private final WebsitVenderService websitVenderService;
|
|
|
+ private final StorageService storageService;
|
|
|
+ private final WebitPurchaseStockLogic webitPurchaseStockLogic;
|
|
|
+ private final WebsitGoodsService websitGoodsService;
|
|
|
+ private final WebsitGoodsPriceService websitGoodsPriceService;
|
|
|
|
|
|
public IPage<WebsitPurchaseApplyVO> page(ZfireParamBean zfireParamBean) {
|
|
|
AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
@@ -220,18 +222,33 @@ public class WebsitMPurchaseLogic {
|
|
|
&& itemBean.getApplyCost().compareTo(relaGoods.getCostRangeMax()) > 0) {
|
|
|
throw new RemoteServiceException(preStr + "不能高于辅材资料最大进价范围值");
|
|
|
}
|
|
|
+ // 申请进价*申请数量=申请进价金额
|
|
|
+ itemBean.setApplyCostValue(itemBean.getApplyCost().multiply(itemBean.getApplyQty()).setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
+ itemBean.setCheckQty(itemBean.getApplyCost());
|
|
|
+ itemBean.setGoodsCode(relaGoods.getGoodsCode());
|
|
|
+ itemBean.setGoodsSpecification(relaGoods.getGoodsSpecification());
|
|
|
+ itemBean.setGoodsStockUnit(relaGoods.getGoodsStockUnit());
|
|
|
+ itemBean.setParentCategoryId(relaGoods.getParentCategoryId());
|
|
|
+ itemBean.setParentCategoryName(relaGoods.getParentCategoryName());
|
|
|
+ itemBean.setGoodsCategoryId(relaGoods.getGoodsCategoryId());
|
|
|
+ itemBean.setGoodsCategoryName(relaGoods.getCategoryName());
|
|
|
+ bean.setTotalAmount(bean.getTotalAmount().add(itemBean.getApplyCostValue()));
|
|
|
+ } else if (bean.getFlag().equals(MaterialFlagEnum.SUBMIT.getKey())) {
|
|
|
+ // 检查进价范围值
|
|
|
+ if (Objects.nonNull(relaGoods.getCostRangeMini())
|
|
|
+ && itemBean.getCost().compareTo(relaGoods.getCostRangeMini()) < 0) {
|
|
|
+ throw new RemoteServiceException(preStr + "不能低于辅材资料最小进价范围值");
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(relaGoods.getCostRangeMax())
|
|
|
+ && itemBean.getCost().compareTo(relaGoods.getCostRangeMax()) > 0) {
|
|
|
+ throw new RemoteServiceException(preStr + "不能高于辅材资料最大进价范围值");
|
|
|
+ }
|
|
|
+ itemBean.setInStockCost(itemBean.getCost());
|
|
|
+ itemBean.setInStockQty(itemBean.getRecQty().add(itemBean.getRecGiftQty()));
|
|
|
+ itemBean.setCostValue(itemBean.getRecQty().multiply(itemBean.getCost()).setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
+ bean.setTotalAmount(bean.getTotalAmount().add(itemBean.getCostValue()));
|
|
|
}
|
|
|
- // 申请进价*申请数量=申请进价金额
|
|
|
- itemBean.setApplyCostValue(itemBean.getApplyCost().multiply(itemBean.getApplyQty()).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
- itemBean.setCheckQty(itemBean.getApplyCost());
|
|
|
- itemBean.setGoodsCode(relaGoods.getGoodsCode());
|
|
|
- itemBean.setGoodsSpecification(relaGoods.getGoodsSpecification());
|
|
|
- itemBean.setGoodsStockUnit(relaGoods.getGoodsStockUnit());
|
|
|
- itemBean.setParentCategoryId(relaGoods.getParentCategoryId());
|
|
|
- itemBean.setParentCategoryName(relaGoods.getParentCategoryName());
|
|
|
- itemBean.setGoodsCategoryId(relaGoods.getGoodsCategoryId());
|
|
|
- itemBean.setGoodsCategoryName(relaGoods.getCategoryName());
|
|
|
- bean.setTotalAmount(bean.getTotalAmount().add(itemBean.getApplyCostValue()));
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -363,4 +380,189 @@ public class WebsitMPurchaseLogic {
|
|
|
.set(WebsitPurchase::getCheckTime, DateUtil.date())
|
|
|
.update();
|
|
|
}
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void orderUpdate(WebsitMPurchaseBean bean) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ WebsitPurchase purchase = websitPurchaseService.getById(bean.getPurchaseId());
|
|
|
+
|
|
|
+ if (Objects.isNull(purchase)) {
|
|
|
+ throw new RemoteServiceException("单据不存在或状态已发生变化");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(bean.getImageUrl())) {
|
|
|
+ throw new RemoteServiceException("请添加附件图片");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.isNull(bean.getPurchaseTime())) {
|
|
|
+ throw new RemoteServiceException("请选择采购日期");
|
|
|
+ }
|
|
|
+
|
|
|
+ final Storage storage = storageService.lambdaQuery()
|
|
|
+ .eq(Storage::getCompanyWechatId, adminUser.getAdminCompanyWechat().getCompanyWechatId())
|
|
|
+ .eq(Storage::getWebsitId, purchase.getWebsitId())
|
|
|
+ .eq(Storage::getIsDefault, IsEnum.Y.getValue())
|
|
|
+ .one();
|
|
|
+
|
|
|
+ List<WebsitPurchaseItem> purchaseItems = websitPurchaseItemService.lambdaQuery()
|
|
|
+ .eq(WebsitPurchaseItem::getPurchaseId, purchase.getPurchaseId())
|
|
|
+ .list();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(bean.getStorageId())) {
|
|
|
+ bean.setStorageId(storage.getStorageId());
|
|
|
+ bean.setStorageName(storage.getStorageName());
|
|
|
+ }
|
|
|
+
|
|
|
+ bean.setFlag(purchase.getFlag());
|
|
|
+ this.convertOrderParams(bean, purchase, purchaseItems);
|
|
|
+
|
|
|
+ purchase.updateById();
|
|
|
+ websitPurchaseItemService.saveOrUpdateBatch(purchaseItems);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void orderRevoke(String purchaseId) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ websitPurchaseService.lambdaUpdate()
|
|
|
+ .eq(WebsitPurchase::getPurchaseId, purchaseId)
|
|
|
+ .eq(WebsitPurchase::getFlag, MaterialFlagEnum.SUBMIT.getKey())
|
|
|
+ .eq(WebsitPurchase::getIsRecheck, IsYesNoEnum.YES.getKey())
|
|
|
+ .set(WebsitPurchase::getUpdateBy, adminUser.getNickName())
|
|
|
+ .set(WebsitPurchase::getUpdateTime, DateUtil.date())
|
|
|
+ .set(WebsitPurchase::getFlag, MaterialFlagEnum.CANCEL.getKey())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convertOrderParams(WebsitMPurchaseBean bean, WebsitPurchase purchase, List<WebsitPurchaseItem> purchaseItems) {
|
|
|
+ // 获取供应商商品记录
|
|
|
+ List<WebsitVenderGoodsRelaVO> relaList = this.queryVenderGoods(bean);
|
|
|
+ final Map<String, WebsitVenderGoodsRelaVO> relaMap = relaList.stream()
|
|
|
+ .collect(Collectors.toMap(WebsitVenderGoodsRelaVO::getGoodsId, Function.identity()));
|
|
|
+
|
|
|
+ // 校验供应商商品
|
|
|
+ this.validVendorGoods(bean, relaMap);
|
|
|
+
|
|
|
+ final Map<String, WebsitMPurchaseItemBean> itemBeanMap = bean.getItems().stream()
|
|
|
+ .collect(Collectors.toMap(WebsitMPurchaseItemBean::getGoodsId, Function.identity()));
|
|
|
+
|
|
|
+ for (WebsitPurchaseItem item : purchaseItems) {
|
|
|
+ final WebsitMPurchaseItemBean itemBean = itemBeanMap.get(item.getGoodsId());
|
|
|
+ if (Objects.nonNull(itemBean)) {
|
|
|
+ item.setRecQty(itemBean.getRecQty())
|
|
|
+ .setRecGiftQty(itemBean.getRecGiftQty())
|
|
|
+ .setCost(itemBean.getCost())
|
|
|
+ .setCostValue(itemBean.getCostValue())
|
|
|
+ .setInStockCost(itemBean.getInStockCost())
|
|
|
+ .setInStockQty(itemBean.getInStockQty());
|
|
|
+ }
|
|
|
+ purchase.setTotalAmount(purchase.getTotalAmount().add(item.getCostValue()));
|
|
|
+ }
|
|
|
+
|
|
|
+ purchase.setImageUrl(bean.getImageUrl())
|
|
|
+ .setPurchaseTime(bean.getPurchaseTime())
|
|
|
+ .setConfirmRemark(bean.getConfirmRemark());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void orderConfirm(String purchaseId) throws Exception {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ WebsitPurchase purchase = websitPurchaseService.getById(purchaseId);
|
|
|
+ if (Objects.isNull(purchase)
|
|
|
+ || !StrUtil.equals(purchase.getFlag(), MaterialFlagEnum.SUBMIT.getKey())
|
|
|
+ || StrUtil.equals(purchase.getIsRecheck(), IsYesNoEnum.YES.getKey())) {
|
|
|
+ throw new RemoteServiceException("单据不存在或状态已发生变化");
|
|
|
+ }
|
|
|
+
|
|
|
+ final List<WebsitPurchaseItem> purchaseItems = websitPurchaseItemService.lambdaQuery()
|
|
|
+ .eq(WebsitPurchaseItem::getPurchaseId, purchase.getPurchaseId())
|
|
|
+ .list();
|
|
|
+
|
|
|
+ this.checkPurchaseItemsCount(purchase, purchaseItems);
|
|
|
+
|
|
|
+ purchase.setFlag(MaterialFlagEnum.OK.getKey())
|
|
|
+ .setConfirmBy(adminUser.getNickName())
|
|
|
+ .setConfirmTime(DateUtil.date())
|
|
|
+ .updateById();
|
|
|
+
|
|
|
+ // 库存处理
|
|
|
+ webitPurchaseStockLogic.newInStock(purchase, purchaseItems, "采购入库");
|
|
|
+
|
|
|
+ // 没有入库过的辅材增加售价为0记录
|
|
|
+ if (purchase.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey())) {
|
|
|
+ List<WebsitGoods> goodsList = websitGoodsService.lambdaQuery()
|
|
|
+ .eq(WebsitGoods::getCompanyWechatId, purchase.getCompanyWechatId())
|
|
|
+ .in(WebsitGoods::getGoodsId, purchaseItems.stream()
|
|
|
+ .map(WebsitPurchaseItem::getGoodsId)
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .list();
|
|
|
+
|
|
|
+ List<WebsitGoodsPrice> priceList = websitGoodsPriceService.lambdaQuery()
|
|
|
+ .eq(WebsitGoodsPrice::getCompanyWechatId, purchase.getCompanyWechatId())
|
|
|
+ .eq(WebsitGoodsPrice::getWebsitId, purchase.getWebsitId())
|
|
|
+ .in(WebsitGoodsPrice::getGoodsId, purchaseItems.stream()
|
|
|
+ .map(WebsitPurchaseItem::getGoodsId)
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .list();
|
|
|
+ // 数量不相等
|
|
|
+ if (priceList.size() != purchaseItems.size()) {
|
|
|
+ List<WebsitGoodsPrice> createPriceList = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<String, WebsitGoodsPrice> goodsPriceMap = priceList.stream()
|
|
|
+ .collect(Collectors.toMap(WebsitGoodsPrice::getGoodsId, Function.identity(), (key1,key2) -> key2));
|
|
|
+
|
|
|
+ Map<String, BigDecimal> goodsMap = goodsList.stream()
|
|
|
+ .collect(Collectors.toMap(WebsitGoods::getGoodsId, WebsitGoods::getMarketPrice, (key1,key2) -> key2));
|
|
|
+
|
|
|
+ for (WebsitPurchaseItem item : purchaseItems) {
|
|
|
+ if (!goodsPriceMap.containsKey(item.getGoodsId())) {
|
|
|
+ WebsitGoodsPrice price = new WebsitGoodsPrice();
|
|
|
+ BigDecimal salesPrice = goodsMap.getOrDefault(item.getGoodsId(), BigDecimal.ZERO);
|
|
|
+ price.setCompanyWechatId(item.getCompanyWechatId());
|
|
|
+ price.setWebsitId(item.getWebsitId());
|
|
|
+ price.setWebsitName(item.getWebsitName());
|
|
|
+ price.setGoodsType(item.getGoodsType());
|
|
|
+ price.setGoodsId(item.getGoodsId());
|
|
|
+ price.setPrice(salesPrice);
|
|
|
+ price.setSheetId("");
|
|
|
+ price.setRemark(purchase.getRemark());
|
|
|
+
|
|
|
+ createPriceList.add(price);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(createPriceList)) {
|
|
|
+ websitGoodsPriceService.saveBatch(createPriceList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkPurchaseItemsCount(WebsitPurchase purchase, List<WebsitPurchaseItem> purchaseItems) {
|
|
|
+ BigDecimal zero = new BigDecimal("0");
|
|
|
+ List<WebsitPurchaseItem> zeroItems = purchaseItems.stream()
|
|
|
+ .filter(item -> item.getInStockQty().compareTo(zero) == 0)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<WebsitPurchaseItem> purchaseItemList = purchaseItems.stream()
|
|
|
+ .filter(item -> item.getRecQty().compareTo(item.getApplyQty()) > 0)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (zeroItems.size() == purchaseItems.size()) {
|
|
|
+ throw new RemoteServiceException("辅材验收数量为0,审核失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(purchaseItemList)) {
|
|
|
+ throw new RemoteServiceException(purchaseItemList.get(0).getGoodsName() + " 辅材验收数量不能大于订货数量,审核失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal rateQty = new BigDecimal("5");
|
|
|
+ for (WebsitPurchaseItem item : purchaseItems) {
|
|
|
+ BigDecimal resultRateQty = Optional.ofNullable(item.getRecGiftQty()).orElse(BigDecimal.ZERO)
|
|
|
+ .divide(item.getApplyQty(), 4, BigDecimal.ROUND_HALF_UP)
|
|
|
+ .multiply(new BigDecimal("100"));
|
|
|
+ if (resultRateQty.compareTo(rateQty) > 0) {
|
|
|
+ throw new RemoteServiceException(item.getGoodsName() + "的赠品数量不能超过订货数量的5%,审核失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|