|
@@ -2,6 +2,7 @@ package com.gree.mall.manager.logic.goods;
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -14,8 +15,11 @@ import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
import com.gree.mall.manager.logic.common.CommonLogic;
|
|
import com.gree.mall.manager.logic.common.CommonLogic;
|
|
|
import com.gree.mall.manager.plus.entity.GoodsApplyPurchase;
|
|
import com.gree.mall.manager.plus.entity.GoodsApplyPurchase;
|
|
|
import com.gree.mall.manager.plus.entity.GoodsApplyPurchaseItem;
|
|
import com.gree.mall.manager.plus.entity.GoodsApplyPurchaseItem;
|
|
|
|
|
+import com.gree.mall.manager.plus.entity.GoodsPurchase;
|
|
|
|
|
+import com.gree.mall.manager.plus.entity.GoodsPurchaseItem;
|
|
|
import com.gree.mall.manager.plus.service.GoodsApplyPurchaseItemService;
|
|
import com.gree.mall.manager.plus.service.GoodsApplyPurchaseItemService;
|
|
|
import com.gree.mall.manager.plus.service.GoodsApplyPurchaseService;
|
|
import com.gree.mall.manager.plus.service.GoodsApplyPurchaseService;
|
|
|
|
|
+import com.gree.mall.manager.plus.service.GoodsPurchaseItemService;
|
|
|
import com.gree.mall.manager.plus.service.WebsitVenderService;
|
|
import com.gree.mall.manager.plus.service.WebsitVenderService;
|
|
|
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
|
|
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
|
|
|
import com.gree.mall.manager.zfire.util.FieldUtils;
|
|
import com.gree.mall.manager.zfire.util.FieldUtils;
|
|
@@ -26,6 +30,8 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
@@ -41,6 +47,7 @@ public class GoodsApplyPurchaseLogic {
|
|
|
private final GoodsApplyPurchaseService goodsApplyPurchaseService;
|
|
private final GoodsApplyPurchaseService goodsApplyPurchaseService;
|
|
|
private final GoodsApplyPurchaseItemService goodsApplyPurchaseItemService;
|
|
private final GoodsApplyPurchaseItemService goodsApplyPurchaseItemService;
|
|
|
private final WebsitVenderService websitVenderService;
|
|
private final WebsitVenderService websitVenderService;
|
|
|
|
|
+ private final GoodsPurchaseItemService goodsPurchaseItemService;
|
|
|
|
|
|
|
|
|
|
|
|
|
public IPage<GoodsApplyPurchaseVO> page(ZfireParamBean zfireParamBean) {
|
|
public IPage<GoodsApplyPurchaseVO> page(ZfireParamBean zfireParamBean) {
|
|
@@ -83,12 +90,24 @@ public class GoodsApplyPurchaseLogic {
|
|
|
final GoodsApplyPurchase old = goodsApplyPurchaseService.getById(bean.getId());
|
|
final GoodsApplyPurchase old = goodsApplyPurchaseService.getById(bean.getId());
|
|
|
|
|
|
|
|
if (Objects.nonNull(old)) {
|
|
if (Objects.nonNull(old)) {
|
|
|
|
|
+ if (old.getStatus().equals(ExamineStatusEnum.SUBMIT.getKey())) {
|
|
|
|
|
+ throw new RemoteServiceException("单据已提交不能再编辑");
|
|
|
|
|
+ }
|
|
|
goodsApplyPurchaseItemService.lambdaUpdate()
|
|
goodsApplyPurchaseItemService.lambdaUpdate()
|
|
|
.eq(GoodsApplyPurchaseItem::getGoodsApplyPurchaseId, old.getId())
|
|
.eq(GoodsApplyPurchaseItem::getGoodsApplyPurchaseId, old.getId())
|
|
|
.remove();
|
|
.remove();
|
|
|
} else {
|
|
} else {
|
|
|
- bean.setId(IdWorker.getIdStr())
|
|
|
|
|
- .setStatus(ExamineStatusEnum.SAVE.getKey());
|
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(bean.getStatus())
|
|
|
|
|
+ && !(ExamineStatusEnum.SAVE.getKey() + ExamineStatusEnum.SUBMIT.getKey()).contains(bean.getStatus())) {
|
|
|
|
|
+ throw new RemoteServiceException("单据状态异常");
|
|
|
|
|
+ }
|
|
|
|
|
+ bean.setId(IdWorker.getIdStr());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 提交时注入
|
|
|
|
|
+ if (bean.getStatus().equals(ExamineStatusEnum.SUBMIT.getKey())) {
|
|
|
|
|
+ bean.setSubmitBy(adminUser.getNickName())
|
|
|
|
|
+ .setSubmitTime(DateUtil.date());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bean.setVenderId("0").setVenderName("格力");
|
|
bean.setVenderId("0").setVenderName("格力");
|
|
@@ -96,7 +115,11 @@ public class GoodsApplyPurchaseLogic {
|
|
|
// 检查商品信息唯一
|
|
// 检查商品信息唯一
|
|
|
checkItemUnique(bean);
|
|
checkItemUnique(bean);
|
|
|
|
|
|
|
|
|
|
+ Integer totalQty = bean.getItems().stream().mapToInt(GoodsApplyPurchaseItem::getQty).sum();
|
|
|
|
|
+ double totalAmount = bean.getItems().stream().mapToDouble(v -> v.getAmount().doubleValue()).sum();
|
|
|
|
|
|
|
|
|
|
+ bean.setTotalQty(totalQty)
|
|
|
|
|
+ .setTotalAmount(BigDecimal.valueOf(totalAmount));
|
|
|
|
|
|
|
|
goodsApplyPurchaseService.saveOrUpdate(bean);
|
|
goodsApplyPurchaseService.saveOrUpdate(bean);
|
|
|
goodsApplyPurchaseItemService.saveBatch(bean.getItems());
|
|
goodsApplyPurchaseItemService.saveBatch(bean.getItems());
|
|
@@ -112,4 +135,74 @@ public class GoodsApplyPurchaseLogic {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public void examine(GoodsApplyPurchaseBean bean) {
|
|
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
|
|
+ if (Objects.nonNull(adminUser.getAdminCompanyWechat())) {
|
|
|
|
|
+ throw new RemoteServiceException("权限受限");
|
|
|
|
|
+ }
|
|
|
|
|
+ GoodsApplyPurchase goodsApplyPurchase = goodsApplyPurchaseService.getById(bean.getId());
|
|
|
|
|
+ goodsApplyPurchase.setExamineBy(adminUser.getNickName())
|
|
|
|
|
+ .setExamineTime(DateUtil.date())
|
|
|
|
|
+ .setExamineRemark(bean.getExamineRemark());
|
|
|
|
|
+
|
|
|
|
|
+ // 审核通过
|
|
|
|
|
+ if (bean.getStatus().equals(ExamineStatusEnum.OK.getKey())) {
|
|
|
|
|
+ GoodsPurchase goodsPurchase = new GoodsPurchase();
|
|
|
|
|
+ goodsPurchase.setId(IdWorker.getIdStr());
|
|
|
|
|
+ goodsPurchase.setCompanyWechatId(goodsApplyPurchase.getCompanyWechatId());
|
|
|
|
|
+ goodsPurchase.setCompanyWechatName(goodsApplyPurchase.getCompanyWechatName());
|
|
|
|
|
+ goodsPurchase.setVenderId(goodsApplyPurchase.getVenderId());
|
|
|
|
|
+ goodsPurchase.setVenderName(goodsApplyPurchase.getVenderName());
|
|
|
|
|
+ goodsPurchase.setTotalQty(goodsApplyPurchase.getTotalQty());
|
|
|
|
|
+ goodsPurchase.setTotalAmount(goodsApplyPurchase.getTotalAmount());
|
|
|
|
|
+ goodsPurchase.setStatus(ExamineStatusEnum.SAVE.getKey());
|
|
|
|
|
+ goodsPurchase.setCreateBy(goodsApplyPurchase.getExamineBy());
|
|
|
|
|
+ goodsPurchase.setCreateTime(goodsApplyPurchase.getExamineTime());
|
|
|
|
|
+ goodsPurchase.setUpdateBy(goodsApplyPurchase.getExamineBy());
|
|
|
|
|
+ goodsPurchase.setUpdateTime(goodsApplyPurchase.getExamineTime());
|
|
|
|
|
+ goodsPurchase.setJoinCode("NUM");
|
|
|
|
|
+ goodsPurchase.setStorageId(goodsApplyPurchase.getStorageId());
|
|
|
|
|
+ goodsPurchase.setStorageName(goodsApplyPurchase.getStorageName());
|
|
|
|
|
+ goodsPurchase.setGoodsApplyPurchaseId(goodsApplyPurchase.getId());
|
|
|
|
|
+
|
|
|
|
|
+ final List<GoodsApplyPurchaseItem> applyPurchaseItems = goodsApplyPurchaseItemService.lambdaQuery()
|
|
|
|
|
+ .eq(GoodsApplyPurchaseItem::getGoodsApplyPurchaseId, goodsApplyPurchase.getId())
|
|
|
|
|
+ .list();
|
|
|
|
|
+
|
|
|
|
|
+ List<GoodsPurchaseItem> itemList = new ArrayList<>();
|
|
|
|
|
+ for (GoodsApplyPurchaseItem applyPurchaseItem : applyPurchaseItems) {
|
|
|
|
|
+ GoodsPurchaseItem item = new GoodsPurchaseItem();
|
|
|
|
|
+ item.setGoodsPurchaseId(goodsPurchase.getId());
|
|
|
|
|
+ item.setBrandId("0");
|
|
|
|
|
+ item.setBrandName("格力");
|
|
|
|
|
+ item.setMainId(applyPurchaseItem.getMainId());
|
|
|
|
|
+ item.setMainName(applyPurchaseItem.getMainName());
|
|
|
|
|
+ item.setSmallId(applyPurchaseItem.getSmallId());
|
|
|
|
|
+ item.setSmallName(applyPurchaseItem.getSmallName());
|
|
|
|
|
+ item.setGoodsMaterialId(applyPurchaseItem.getGoodsMaterialId());
|
|
|
|
|
+ item.setGoodsMaterialName(applyPurchaseItem.getGoodsMaterialName());
|
|
|
|
|
+ item.setSeriesName(applyPurchaseItem.getSeriesName());
|
|
|
|
|
+ item.setSpecsName(applyPurchaseItem.getSpecsName());
|
|
|
|
|
+ item.setUnit(applyPurchaseItem.getUnit());
|
|
|
|
|
+ item.setQty(applyPurchaseItem.getQty());
|
|
|
|
|
+ item.setInsideQty(applyPurchaseItem.getInsideQty());
|
|
|
|
|
+ item.setOutQty(applyPurchaseItem.getOutQty());
|
|
|
|
|
+ item.setPartsQty(applyPurchaseItem.getPartsQty());
|
|
|
|
|
+ item.setPrice(applyPurchaseItem.getPrice());
|
|
|
|
|
+ item.setAmount(applyPurchaseItem.getAmount());
|
|
|
|
|
+ item.setStockQty(0);
|
|
|
|
|
+ item.setInsideCodeQty(0);
|
|
|
|
|
+ item.setOutCodeQty(0);
|
|
|
|
|
+ item.setPartsCodeQty(0);
|
|
|
|
|
+ item.setOrigQty(applyPurchaseItem.getQty());
|
|
|
|
|
+
|
|
|
|
|
+ itemList.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ goodsPurchase.insert();
|
|
|
|
|
+ goodsPurchaseItemService.saveBatch(itemList);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|