|
|
@@ -0,0 +1,115 @@
|
|
|
+package com.gree.mall.manager.logic.goods;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.gree.mall.manager.bean.admin.AdminUserCom;
|
|
|
+import com.gree.mall.manager.bean.goods.GoodsApplyPurchaseBean;
|
|
|
+import com.gree.mall.manager.bean.goods.GoodsApplyPurchaseVO;
|
|
|
+import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
|
+import com.gree.mall.manager.enums.ExamineStatusEnum;
|
|
|
+import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
+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.service.GoodsApplyPurchaseItemService;
|
|
|
+import com.gree.mall.manager.plus.service.GoodsApplyPurchaseService;
|
|
|
+import com.gree.mall.manager.plus.service.WebsitVenderService;
|
|
|
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
|
|
|
+import com.gree.mall.manager.zfire.util.FieldUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class GoodsApplyPurchaseLogic {
|
|
|
+
|
|
|
+ private final CommonLogic commonLogic;
|
|
|
+ private final CommonMapper commonMapper;
|
|
|
+ private final GoodsApplyPurchaseService goodsApplyPurchaseService;
|
|
|
+ private final GoodsApplyPurchaseItemService goodsApplyPurchaseItemService;
|
|
|
+ private final WebsitVenderService websitVenderService;
|
|
|
+
|
|
|
+
|
|
|
+ public IPage<GoodsApplyPurchaseVO> page(ZfireParamBean zfireParamBean) {
|
|
|
+ final AdminUserCom adminUser = commonLogic.commonAddQueryFilterParam(zfireParamBean);
|
|
|
+ FieldUtils.supplyParam(zfireParamBean, GoodsApplyPurchaseVO.class, adminUser);
|
|
|
+ IPage<GoodsApplyPurchaseVO> page = commonMapper.goodsApplyPurchaseList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ public GoodsApplyPurchaseBean detail(String id) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ String companyId = null;
|
|
|
+ if (Objects.nonNull(adminUser.getAdminCompanyWechat())) {
|
|
|
+ companyId = adminUser.getAdminCompanyWechat().getCompanyWechatId();
|
|
|
+ }
|
|
|
+ GoodsApplyPurchaseBean bean = new GoodsApplyPurchaseBean();
|
|
|
+ GoodsApplyPurchase applyPurchase = goodsApplyPurchaseService.lambdaQuery()
|
|
|
+ .eq(StringUtils.isNotBlank(companyId), GoodsApplyPurchase::getCompanyWechatId, companyId)
|
|
|
+ .eq(GoodsApplyPurchase::getId, id)
|
|
|
+ .one();
|
|
|
+
|
|
|
+ if (Objects.nonNull(applyPurchase)) {
|
|
|
+ List<GoodsApplyPurchaseItem> items = goodsApplyPurchaseItemService.lambdaQuery()
|
|
|
+ .eq(GoodsApplyPurchaseItem::getGoodsApplyPurchaseId, applyPurchase.getId())
|
|
|
+ .list();
|
|
|
+ List<GoodsApplyPurchaseItem> itemBeans = BeanUtil.copyToList(items, GoodsApplyPurchaseItem.class);
|
|
|
+
|
|
|
+ bean.setItems(itemBeans);
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(applyPurchase, bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void save(GoodsApplyPurchaseBean bean) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ final GoodsApplyPurchase old = goodsApplyPurchaseService.getById(bean.getId());
|
|
|
+
|
|
|
+ if (Objects.nonNull(old)) {
|
|
|
+ goodsApplyPurchaseItemService.lambdaUpdate()
|
|
|
+ .eq(GoodsApplyPurchaseItem::getGoodsApplyPurchaseId, old.getId())
|
|
|
+ .remove();
|
|
|
+ } else {
|
|
|
+ bean.setId(IdWorker.getIdStr())
|
|
|
+ .setStatus(ExamineStatusEnum.SAVE.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ bean.setVenderId("0").setVenderName("格力");
|
|
|
+
|
|
|
+ // 检查商品信息唯一
|
|
|
+ checkItemUnique(bean);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ goodsApplyPurchaseService.saveOrUpdate(bean);
|
|
|
+ goodsApplyPurchaseItemService.saveBatch(bean.getItems());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkItemUnique(GoodsApplyPurchaseBean bean) {
|
|
|
+ Map<String, List<GoodsApplyPurchaseItem>> materialGroup = bean.getItems().stream()
|
|
|
+ .collect(Collectors.groupingBy(GoodsApplyPurchaseItem::getGoodsMaterialId));
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<GoodsApplyPurchaseItem>> entry : materialGroup.entrySet()) {
|
|
|
+ if (entry.getValue().size() > 1) {
|
|
|
+ throw new RemoteServiceException("发现重复的商品, 请检查!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|