|
|
@@ -0,0 +1,178 @@
|
|
|
+package com.gree.mall.manager.logic.goods;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+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.GoodsPriceChangeBean;
|
|
|
+import com.gree.mall.manager.bean.goods.GoodsPriceChangeVO;
|
|
|
+import com.gree.mall.manager.bean.listvo.UserCustomerVO;
|
|
|
+import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
|
+import com.gree.mall.manager.constant.Constant;
|
|
|
+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.Goods;
|
|
|
+import com.gree.mall.manager.plus.entity.GoodsPriceChange;
|
|
|
+import com.gree.mall.manager.plus.entity.GoodsSpec;
|
|
|
+import com.gree.mall.manager.plus.service.GoodsPriceChangeService;
|
|
|
+import com.gree.mall.manager.plus.service.GoodsService;
|
|
|
+import com.gree.mall.manager.plus.service.GoodsSpecService;
|
|
|
+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.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class GoodsPriceChangeLogic {
|
|
|
+
|
|
|
+ private final CommonLogic commonLogic;
|
|
|
+ private final CommonMapper commonMapper;
|
|
|
+ private final GoodsPriceChangeService goodsPriceChangeService;
|
|
|
+ private final GoodsService goodsService;
|
|
|
+ private final GoodsSpecService goodsSpecService;
|
|
|
+
|
|
|
+ public IPage<GoodsPriceChangeVO> list(ZfireParamBean zfireParamBean) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ zfireParamBean.setCompanyWechatId(adminUser.getCompanyWechatId());
|
|
|
+ FieldUtils.supplyParam(zfireParamBean, UserCustomerVO.class);
|
|
|
+
|
|
|
+ IPage<GoodsPriceChangeVO> page = commonMapper.goodsPriceChangePage(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ public GoodsPriceChangeBean detail(String sheetId) {
|
|
|
+ final List<GoodsPriceChange> changeList = goodsPriceChangeService.lambdaQuery()
|
|
|
+ .eq(GoodsPriceChange::getSheetId, sheetId)
|
|
|
+ .orderByAsc(GoodsPriceChange::getId)
|
|
|
+ .list();
|
|
|
+
|
|
|
+ final List<Goods> goodsList = goodsService.lambdaQuery()
|
|
|
+ .in(Goods::getGoodsId, changeList.stream().map(GoodsPriceChange::getGoodsId).collect(Collectors.toList()))
|
|
|
+ .list();
|
|
|
+
|
|
|
+ final List<GoodsSpec> goodsSpecList = goodsSpecService.lambdaQuery()
|
|
|
+ .in(GoodsSpec::getGoodsSpecId, changeList.stream().map(GoodsPriceChange::getGoodsSpecId).collect(Collectors.toList()))
|
|
|
+ .list();
|
|
|
+
|
|
|
+ final Map<String, String> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getGoodsId, Goods::getGoodsName));
|
|
|
+ final Map<String, GoodsSpec> goodsSpecMap = goodsSpecList.stream().collect(Collectors.toMap(GoodsSpec::getGoodsSpecId, Function.identity()));
|
|
|
+
|
|
|
+ GoodsPriceChangeBean bean = new GoodsPriceChangeBean();
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(changeList.get(0), bean);
|
|
|
+
|
|
|
+ List<GoodsPriceChangeBean> items = new ArrayList<>();
|
|
|
+ for (GoodsPriceChange change : changeList) {
|
|
|
+ final String goodsName = goodsMap.get(change.getGoodsId());
|
|
|
+ final GoodsSpec goodsSpec = goodsSpecMap.get(change.getGoodsSpecId());
|
|
|
+ GoodsPriceChangeBean item = new GoodsPriceChangeBean();
|
|
|
+ BeanUtils.copyProperties(change, item);
|
|
|
+ item.setGoodsName(goodsName);
|
|
|
+ item.setName(goodsSpec.getName());
|
|
|
+ item.setSpecValue(goodsSpec.getSpecValue());
|
|
|
+ items.add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ bean.setItems(items);
|
|
|
+
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public String add(GoodsPriceChangeBean bean) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ final String no = commonLogic.generateNo("", "GOODS_PRICE_CHANGE", 16);
|
|
|
+ List<GoodsPriceChangeBean> items = bean.getItems();
|
|
|
+
|
|
|
+ for (GoodsPriceChangeBean item : items) {
|
|
|
+ if (item.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw new RemoteServiceException(item.getGoodsName() + "规格: " + item.getName() + "售价必须大于0");
|
|
|
+ }
|
|
|
+ item.setId(IdWorker.getIdStr())
|
|
|
+ .setSheetId(no)
|
|
|
+ .setCompanyWechatId(adminUser.getCompanyWechatId())
|
|
|
+ .setCompanyName(adminUser.getCompanyName())
|
|
|
+ .setRemark(bean.getRemark());
|
|
|
+ }
|
|
|
+
|
|
|
+ goodsPriceChangeService.saveBatch(items.stream()
|
|
|
+ .map(v -> {
|
|
|
+ GoodsPriceChange change = new GoodsPriceChange();
|
|
|
+ BeanUtils.copyProperties(v, change);
|
|
|
+ return change;
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ return no;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void editItem(String id, BigDecimal price, String remark) {
|
|
|
+ if (Objects.nonNull(price)) {
|
|
|
+ if (price.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw new RemoteServiceException("售价必须大于0");
|
|
|
+ }
|
|
|
+ GoodsPriceChange change = new GoodsPriceChange();
|
|
|
+ change.setId(id)
|
|
|
+ .setPrice(price);
|
|
|
+ goodsPriceChangeService.updateById(change);
|
|
|
+ } else {
|
|
|
+ goodsPriceChangeService.lambdaUpdate()
|
|
|
+ .set(GoodsPriceChange::getRemark, remark)
|
|
|
+ .eq(GoodsPriceChange::getSheetId, id)
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void delItem(String id) {
|
|
|
+ goodsPriceChangeService.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void examine(String sheetId) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ List<GoodsPriceChange> changeList = goodsPriceChangeService.lambdaQuery()
|
|
|
+ .eq(GoodsPriceChange::getSheetId, sheetId)
|
|
|
+ .eq(GoodsPriceChange::getCompanyWechatId, adminUser.getCompanyWechatId())
|
|
|
+ .eq(GoodsPriceChange::getStatus, ExamineStatusEnum.SAVE.getKey())
|
|
|
+ .list();
|
|
|
+
|
|
|
+ if (CollectionUtil.isEmpty(changeList)) {
|
|
|
+ throw new RemoteServiceException("单据不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<GoodsSpec> goodsSpecList = new ArrayList<>();
|
|
|
+ for (GoodsPriceChange change : changeList) {
|
|
|
+ GoodsSpec spec = new GoodsSpec();
|
|
|
+ spec.setGoodsSpecId(change.getGoodsSpecId())
|
|
|
+ .setPrice(change.getPrice());
|
|
|
+ goodsSpecList.add(spec);
|
|
|
+
|
|
|
+ change.setStatus(ExamineStatusEnum.OK.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ goodsSpecService.saveOrUpdateBatch(goodsSpecList);
|
|
|
+
|
|
|
+ goodsPriceChangeService.saveOrUpdateBatch(changeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void del(String sheetId) {
|
|
|
+ goodsPriceChangeService.lambdaUpdate()
|
|
|
+ .eq(GoodsPriceChange::getSheetId, sheetId)
|
|
|
+ .remove();
|
|
|
+ }
|
|
|
+}
|