|
@@ -11,16 +11,11 @@ import com.gree.mall.manager.bean.goods.GoodsApplyPurchaseBean;
|
|
|
import com.gree.mall.manager.bean.goods.GoodsApplyPurchaseVO;
|
|
import com.gree.mall.manager.bean.goods.GoodsApplyPurchaseVO;
|
|
|
import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
|
import com.gree.mall.manager.enums.ExamineStatusEnum;
|
|
import com.gree.mall.manager.enums.ExamineStatusEnum;
|
|
|
|
|
+import com.gree.mall.manager.enums.material.GoodsMaterialTypeEnum;
|
|
|
import com.gree.mall.manager.exception.RemoteServiceException;
|
|
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.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.GoodsApplyPurchaseService;
|
|
|
|
|
-import com.gree.mall.manager.plus.service.GoodsPurchaseItemService;
|
|
|
|
|
-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.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;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -48,6 +43,7 @@ public class GoodsApplyPurchaseLogic {
|
|
|
private final GoodsApplyPurchaseItemService goodsApplyPurchaseItemService;
|
|
private final GoodsApplyPurchaseItemService goodsApplyPurchaseItemService;
|
|
|
private final WebsitVenderService websitVenderService;
|
|
private final WebsitVenderService websitVenderService;
|
|
|
private final GoodsPurchaseItemService goodsPurchaseItemService;
|
|
private final GoodsPurchaseItemService goodsPurchaseItemService;
|
|
|
|
|
+ private final GoodsMaterialItemService goodsMaterialItemService;
|
|
|
|
|
|
|
|
|
|
|
|
|
public IPage<GoodsApplyPurchaseVO> page(ZfireParamBean zfireParamBean) {
|
|
public IPage<GoodsApplyPurchaseVO> page(ZfireParamBean zfireParamBean) {
|
|
@@ -73,6 +69,7 @@ public class GoodsApplyPurchaseLogic {
|
|
|
if (Objects.nonNull(applyPurchase)) {
|
|
if (Objects.nonNull(applyPurchase)) {
|
|
|
List<GoodsApplyPurchaseItem> items = goodsApplyPurchaseItemService.lambdaQuery()
|
|
List<GoodsApplyPurchaseItem> items = goodsApplyPurchaseItemService.lambdaQuery()
|
|
|
.eq(GoodsApplyPurchaseItem::getGoodsApplyPurchaseId, applyPurchase.getId())
|
|
.eq(GoodsApplyPurchaseItem::getGoodsApplyPurchaseId, applyPurchase.getId())
|
|
|
|
|
+ .orderByAsc(GoodsApplyPurchaseItem::getId)
|
|
|
.list();
|
|
.list();
|
|
|
List<GoodsApplyPurchaseItem> itemBeans = BeanUtil.copyToList(items, GoodsApplyPurchaseItem.class);
|
|
List<GoodsApplyPurchaseItem> itemBeans = BeanUtil.copyToList(items, GoodsApplyPurchaseItem.class);
|
|
|
|
|
|
|
@@ -105,15 +102,21 @@ public class GoodsApplyPurchaseLogic {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 提交时注入
|
|
// 提交时注入
|
|
|
- if (bean.getStatus().equals(ExamineStatusEnum.SUBMIT.getKey())) {
|
|
|
|
|
|
|
+ if (bean.getStatus().equals(ExamineStatusEnum.WAIT.getKey())) {
|
|
|
bean.setSubmitBy(adminUser.getNickName())
|
|
bean.setSubmitBy(adminUser.getNickName())
|
|
|
.setSubmitTime(DateUtil.date());
|
|
.setSubmitTime(DateUtil.date());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bean.setVenderId("0").setVenderName("格力");
|
|
bean.setVenderId("0").setVenderName("格力");
|
|
|
|
|
|
|
|
|
|
+ if (Objects.nonNull(adminUser.getAdminCompanyWechat())) {
|
|
|
|
|
+ bean.setCompanyWechatId(adminUser.getAdminCompanyWechat().getCompanyWechatId())
|
|
|
|
|
+ .setCompanyWechatName(adminUser.getAdminCompanyWechat().getCompanyName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 检查商品信息唯一
|
|
// 检查商品信息唯一
|
|
|
checkItemUnique(bean);
|
|
checkItemUnique(bean);
|
|
|
|
|
+ addPartsNum(bean.getItems());
|
|
|
|
|
|
|
|
Integer totalQty = bean.getItems().stream().mapToInt(GoodsApplyPurchaseItem::getQty).sum();
|
|
Integer totalQty = bean.getItems().stream().mapToInt(GoodsApplyPurchaseItem::getQty).sum();
|
|
|
double totalAmount = bean.getItems().stream().mapToDouble(v -> v.getAmount().doubleValue()).sum();
|
|
double totalAmount = bean.getItems().stream().mapToDouble(v -> v.getAmount().doubleValue()).sum();
|
|
@@ -122,7 +125,9 @@ public class GoodsApplyPurchaseLogic {
|
|
|
.setTotalAmount(BigDecimal.valueOf(totalAmount));
|
|
.setTotalAmount(BigDecimal.valueOf(totalAmount));
|
|
|
|
|
|
|
|
goodsApplyPurchaseService.saveOrUpdate(bean);
|
|
goodsApplyPurchaseService.saveOrUpdate(bean);
|
|
|
- goodsApplyPurchaseItemService.saveBatch(bean.getItems());
|
|
|
|
|
|
|
+ goodsApplyPurchaseItemService.saveBatch(bean.getItems().stream()
|
|
|
|
|
+ .peek(v -> v.setGoodsApplyPurchaseId(bean.getId()))
|
|
|
|
|
+ .collect(Collectors.toList()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void checkItemUnique(GoodsApplyPurchaseBean bean) {
|
|
private void checkItemUnique(GoodsApplyPurchaseBean bean) {
|
|
@@ -149,6 +154,7 @@ public class GoodsApplyPurchaseLogic {
|
|
|
|
|
|
|
|
// 审核通过
|
|
// 审核通过
|
|
|
if (bean.getStatus().equals(ExamineStatusEnum.OK.getKey())) {
|
|
if (bean.getStatus().equals(ExamineStatusEnum.OK.getKey())) {
|
|
|
|
|
+ goodsApplyPurchase.setStatus(ExamineStatusEnum.OK.getKey());
|
|
|
GoodsPurchase goodsPurchase = new GoodsPurchase();
|
|
GoodsPurchase goodsPurchase = new GoodsPurchase();
|
|
|
goodsPurchase.setId(IdWorker.getIdStr());
|
|
goodsPurchase.setId(IdWorker.getIdStr());
|
|
|
goodsPurchase.setCompanyWechatId(goodsApplyPurchase.getCompanyWechatId());
|
|
goodsPurchase.setCompanyWechatId(goodsApplyPurchase.getCompanyWechatId());
|
|
@@ -203,6 +209,43 @@ public class GoodsApplyPurchaseLogic {
|
|
|
|
|
|
|
|
goodsPurchase.insert();
|
|
goodsPurchase.insert();
|
|
|
goodsPurchaseItemService.saveBatch(itemList);
|
|
goodsPurchaseItemService.saveBatch(itemList);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ goodsApplyPurchase.setStatus(ExamineStatusEnum.SAVE.getKey());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ goodsApplyPurchase.updateById();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 添加采购明细的物料明细数量
|
|
|
|
|
+ public void addPartsNum(List<GoodsApplyPurchaseItem> items) {
|
|
|
|
|
+ // 查询物料明细
|
|
|
|
|
+ final List<GoodsMaterialItem> materialItemList = goodsMaterialItemService.lambdaQuery()
|
|
|
|
|
+ .in(GoodsMaterialItem::getGoodsMaterialId, items.stream().map(GoodsApplyPurchaseItem::getGoodsMaterialId).collect(Collectors.toList()))
|
|
|
|
|
+ .list();
|
|
|
|
|
+
|
|
|
|
|
+ // 分组物料明细
|
|
|
|
|
+ final Map<String, List<GoodsMaterialItem>> groupMaterialItem = materialItemList.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(GoodsMaterialItem::getGoodsMaterialId));
|
|
|
|
|
+
|
|
|
|
|
+ for (GoodsApplyPurchaseItem item : items) {
|
|
|
|
|
+ if (groupMaterialItem.containsKey(item.getGoodsMaterialId())) {
|
|
|
|
|
+ final List<GoodsMaterialItem> materialItems = groupMaterialItem.get(item.getGoodsMaterialId());
|
|
|
|
|
+
|
|
|
|
|
+ for (GoodsMaterialItem materialItem : materialItems) {
|
|
|
|
|
+ if (materialItem.getType().equals(GoodsMaterialTypeEnum.INSIDE.getKey())) {
|
|
|
|
|
+ // 内机总数量
|
|
|
|
|
+ item.setInsideQty(materialItem.getQty() * item.getQty());
|
|
|
|
|
+ } else if (materialItem.getType().equals(GoodsMaterialTypeEnum.OUT.getKey())) {
|
|
|
|
|
+ // 外机总数量
|
|
|
|
|
+ item.setOutQty(materialItem.getQty() * item.getQty());
|
|
|
|
|
+ } else if (materialItem.getType().equals(GoodsMaterialTypeEnum.PARTS.getKey())) {
|
|
|
|
|
+ // 配件总数量
|
|
|
|
|
+ item.setPartsQty(materialItem.getQty() * item.getQty());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ item.setAmount(BigDecimal.valueOf(item.getQty()).multiply(item.getPrice()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|