|
@@ -0,0 +1,325 @@
|
|
|
|
|
+package com.gree.mall.manager.logic.supply.sales.price;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.gree.mall.manager.bean.admin.AdminUserCom;
|
|
|
|
|
+import com.gree.mall.manager.bean.supply.sales.price.ProductPriceUpdateBean;
|
|
|
|
|
+import com.gree.mall.manager.bean.supply.sales.price.ProductPriceUpdateVO;
|
|
|
|
|
+import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
|
|
|
+import com.gree.mall.manager.enums.ExamineStatusEnum;
|
|
|
|
|
+import com.gree.mall.manager.enums.material.StateEnum;
|
|
|
|
|
+import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
|
|
+import com.gree.mall.manager.logic.common.CommonLogic;
|
|
|
|
|
+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.util.FieldUtils;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.http.client.utils.DateUtils;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class ProductPriceUpdateLogic {
|
|
|
|
|
+
|
|
|
|
|
+ private final CommonLogic commonLogic;
|
|
|
|
|
+ private final CommonMapper commonMapper;
|
|
|
|
|
+ private final ProductPriceUpdateService productPriceUpdateService;
|
|
|
|
|
+ private final ProductPriceUpdateItemService productPriceUpdateItemService;
|
|
|
|
|
+ private final ProductPriceService productPriceService;
|
|
|
|
|
+ private final SalesTypeService salesTypeService;
|
|
|
|
|
+ private final WalletService walletService;
|
|
|
|
|
+ private final RebateTypeService rebateTypeService;
|
|
|
|
|
+ private final GoodsMaterialService goodsMaterialService;
|
|
|
|
|
+
|
|
|
|
|
+ public IPage<ProductPriceUpdateVO> list(ZfireParamBean zfireParamBean) {
|
|
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
|
|
+ FieldUtils.platformParam(zfireParamBean, ProductPriceUpdateVO.class, adminUser);
|
|
|
|
|
+
|
|
|
|
|
+ return commonMapper.productPriceUpdateList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public ProductPriceUpdateBean detail(String id) {
|
|
|
|
|
+ ProductPriceUpdateBean bean = new ProductPriceUpdateBean();
|
|
|
|
|
+ final ProductPriceUpdate priceUpdate = productPriceUpdateService.getById(id);
|
|
|
|
|
+ BeanUtils.copyProperties(priceUpdate, bean);
|
|
|
|
|
+
|
|
|
|
|
+ final List<ProductPriceUpdateItem> updateItems = productPriceUpdateItemService.lambdaQuery()
|
|
|
|
|
+ .eq(ProductPriceUpdateItem::getProductPriceUpdateId, id)
|
|
|
|
|
+ .list();
|
|
|
|
|
+ bean.setItems(updateItems);
|
|
|
|
|
+ return bean;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public void save(ProductPriceUpdateBean bean) {
|
|
|
|
|
+ List<ProductPriceUpdateItem> updateItemList = bean.getItems();
|
|
|
|
|
+ if (CollectionUtil.isEmpty(updateItemList)) {
|
|
|
|
|
+ throw new RemoteServiceException("明细不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(bean.getId())) {
|
|
|
|
|
+ final String generateNo = commonLogic.generateNo("PU", "PRODUCT_PRICE_UPDATE", 13);
|
|
|
|
|
+ bean.setId(generateNo);
|
|
|
|
|
+ bean.setExamineStatus(ExamineStatusEnum.SAVE.getKey());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ final ProductPriceUpdate old = productPriceUpdateService.getById(bean.getId());
|
|
|
|
|
+ if (!old.getExamineStatus().equals(ExamineStatusEnum.SAVE.getKey())) {
|
|
|
|
|
+ throw new RemoteServiceException("单据状态已发生变化,请刷新");
|
|
|
|
|
+ }
|
|
|
|
|
+ productPriceUpdateItemService.lambdaUpdate()
|
|
|
|
|
+ .eq(ProductPriceUpdateItem::getProductPriceUpdateId, bean.getId())
|
|
|
|
|
+ .remove();
|
|
|
|
|
+ }
|
|
|
|
|
+ bean.setCompanyWechatId("0");
|
|
|
|
|
+
|
|
|
|
|
+ bean.insertOrUpdate();
|
|
|
|
|
+
|
|
|
|
|
+ for (ProductPriceUpdateItem updateItem : updateItemList) {
|
|
|
|
|
+ if (StringUtils.isBlank(updateItem.getWalletId())) {
|
|
|
|
|
+ throw new RemoteServiceException(updateItem.getSalesTypeName() + updateItem.getFactoryNo() + updateItem.getGoodsMaterialName() + "不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ productPriceUpdateItemService.saveBatch(updateItemList.stream().peek(v -> v.setProductPriceUpdateId(bean.getId())).collect(Collectors.toList()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public void batchExamine(List<String> ids) {
|
|
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
|
|
+ final List<ProductPriceUpdate> updateList = productPriceUpdateService.lambdaQuery()
|
|
|
|
|
+ .select(ProductPriceUpdate::getId, ProductPriceUpdate::getRemark)
|
|
|
|
|
+ .eq(ProductPriceUpdate::getExamineStatus, ExamineStatusEnum.WAIT.getKey())
|
|
|
|
|
+ .in(ProductPriceUpdate::getId, ids)
|
|
|
|
|
+ .list();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ List<String> filterIds = updateList.stream()
|
|
|
|
|
+ .map(ProductPriceUpdate::getId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtil.isEmpty(filterIds)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ final Map<String, String> updateMap = updateList.stream().collect(Collectors.toMap(ProductPriceUpdate::getId, v -> StringUtils.isNotBlank(v.getRemark()) ? v.getRemark() : ""));
|
|
|
|
|
+
|
|
|
|
|
+ productPriceUpdateService.lambdaUpdate()
|
|
|
|
|
+ .set(ProductPriceUpdate::getExamineBy, adminUser.getNickName())
|
|
|
|
|
+ .set(ProductPriceUpdate::getExamineTime, DateUtil.date())
|
|
|
|
|
+ .set(ProductPriceUpdate::getExamineStatus, ExamineStatusEnum.OK.getKey())
|
|
|
|
|
+ .in(ProductPriceUpdate::getId, filterIds)
|
|
|
|
|
+ .update();
|
|
|
|
|
+
|
|
|
|
|
+ final List<ProductPriceUpdateItem> updateItems = productPriceUpdateItemService.lambdaQuery()
|
|
|
|
|
+ .in(ProductPriceUpdateItem::getProductPriceUpdateId, filterIds)
|
|
|
|
|
+ .list();
|
|
|
|
|
+
|
|
|
|
|
+ List<ProductPrice> priceList = new ArrayList<>();
|
|
|
|
|
+ for (ProductPriceUpdateItem updateItem : updateItems) {
|
|
|
|
|
+ ProductPrice productPrice = new ProductPrice();
|
|
|
|
|
+ BeanUtils.copyProperties(updateItem, productPrice);
|
|
|
|
|
+ final String remark = updateMap.get(updateItem.getProductPriceUpdateId());
|
|
|
|
|
+ productPrice.setCompanyWechatId("0")
|
|
|
|
|
+ .setRemark(remark);
|
|
|
|
|
+ priceList.add(productPrice);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ productPriceService.saveBatch(priceList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public void batchDel(List<String> ids) {
|
|
|
|
|
+ final List<String> filterIds = productPriceUpdateService.lambdaQuery()
|
|
|
|
|
+ .select(ProductPriceUpdate::getId)
|
|
|
|
|
+ .in(ProductPriceUpdate::getExamineStatus, ExamineStatusEnum.SAVE.getKey(), ExamineStatusEnum.FAIL.getKey())
|
|
|
|
|
+ .in(ProductPriceUpdate::getId, ids)
|
|
|
|
|
+ .list()
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .map(ProductPriceUpdate::getId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(filterIds)) {
|
|
|
|
|
+ productPriceUpdateService.removeByIds(filterIds);
|
|
|
|
|
+ productPriceUpdateItemService.lambdaUpdate()
|
|
|
|
|
+ .in(ProductPriceUpdateItem::getProductPriceUpdateId, filterIds)
|
|
|
|
|
+ .remove();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public int importData(List<Object> objects, String remark) {
|
|
|
|
|
+ //所有销售类型code
|
|
|
|
|
+ List<SalesType> saleTypes = salesTypeService.lambdaQuery()
|
|
|
|
|
+ .eq(SalesType::getStatus, true)
|
|
|
|
|
+ .list();
|
|
|
|
|
+ Map<String, SalesType> saleTypeMap = saleTypes.stream().collect(Collectors.toMap(SalesType::getCode, v -> v));
|
|
|
|
|
+ //所有物料
|
|
|
|
|
+ List<GoodsMaterial> kingDeeMaterials = goodsMaterialService.lambdaQuery()
|
|
|
|
|
+ .eq(GoodsMaterial::getState, StateEnum.ON.getKey())
|
|
|
|
|
+ .eq(GoodsMaterial::getCompanyWechatId, "0")
|
|
|
|
|
+ .list();
|
|
|
|
|
+ Map<String, GoodsMaterial> materialMap = kingDeeMaterials.stream().collect(Collectors.toMap(GoodsMaterial::getFactoryNo, v -> v));
|
|
|
|
|
+ //查询所有现金钱包
|
|
|
|
|
+ List<Wallet> wallets = walletService.list();
|
|
|
|
|
+ Map<String, Wallet> walletMap = wallets.stream().collect(Collectors.toMap(Wallet::getCode, v -> v));
|
|
|
|
|
+ //查询所有返利钱包
|
|
|
|
|
+ List<RebateType> walletRebates = rebateTypeService.list();;
|
|
|
|
|
+ Map<String, RebateType> walletRebateMap = walletRebates.stream().collect(Collectors.toMap(RebateType::getCode, v -> v));
|
|
|
|
|
+
|
|
|
|
|
+ List<ProductPriceUpdateItem> resultList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ int index = 2;
|
|
|
|
|
+ for(Object o : objects){
|
|
|
|
|
+ List<Object> row = (List<Object>)o;
|
|
|
|
|
+ String materialNumber = (String)row.get(0);
|
|
|
|
|
+ if(StringUtils.isEmpty(materialNumber)){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String saleTypeCode = (String)row.get(1);
|
|
|
|
|
+ BigDecimal price;
|
|
|
|
|
+ try {
|
|
|
|
|
+ price = new BigDecimal(row.get(2).toString());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 单价转换出错, 请检查");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String walletNames = (String)row.get(3);
|
|
|
|
|
+ String rebateWalletNames = (String)row.get(4);
|
|
|
|
|
+ String[] walletName = walletNames.trim().replaceAll(",",",").split(",");
|
|
|
|
|
+ String startDate = (String)row.get(5);
|
|
|
|
|
+ String endDate = (String)row.get(6);
|
|
|
|
|
+ if(StringUtils.isEmpty(startDate)){
|
|
|
|
|
+ startDate = DateUtils.formatDate(new Date());
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StringUtils.isEmpty(endDate)){
|
|
|
|
|
+ endDate = "2100-01-01 23:59:59";
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StringUtils.isEmpty(materialNumber) || StringUtils.isEmpty(saleTypeCode)
|
|
|
|
|
+ || StringUtils.isEmpty(walletNames)){
|
|
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 检测到物料编码/销售类型编码/现金钱包编码有为空的情况");
|
|
|
|
|
+ }
|
|
|
|
|
+ SalesType saleType = saleTypeMap.get(saleTypeCode);
|
|
|
|
|
+ if(saleType == null){
|
|
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 销售类型编码:" + saleTypeCode + "不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ GoodsMaterial goodsMaterial = materialMap.get(materialNumber);
|
|
|
|
|
+ if(goodsMaterial == null){
|
|
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 物料编码:" + materialNumber + "不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ProductPriceUpdateItem item = new ProductPriceUpdateItem();
|
|
|
|
|
+ item.setSalesTypeId(saleType.getId());
|
|
|
|
|
+ item.setSalesTypeCode(saleTypeCode);
|
|
|
|
|
+ item.setSalesTypeName(saleType.getName());
|
|
|
|
|
+ item.setPrice(price);
|
|
|
|
|
+ item.setStartDate(DateUtil.parseDate(startDate));
|
|
|
|
|
+ item.setEndDate(DateUtil.parseDate(endDate));
|
|
|
|
|
+ item.setMainId(goodsMaterial.getMainId());
|
|
|
|
|
+ item.setMainName(goodsMaterial.getMainName());
|
|
|
|
|
+ item.setSmallId(goodsMaterial.getSmallId());
|
|
|
|
|
+ item.setSmallName(goodsMaterial.getSmallName());
|
|
|
|
|
+ item.setFactoryNo(goodsMaterial.getFactoryNo());
|
|
|
|
|
+ item.setGoodsMaterialId(goodsMaterial.getId());
|
|
|
|
|
+ item.setGoodsMaterialName(goodsMaterial.getGoodsName());
|
|
|
|
|
+ item.setSeriesName(goodsMaterial.getSeriesName());
|
|
|
|
|
+ item.setSpecsName(goodsMaterial.getSpecsName());
|
|
|
|
|
+ item.setUnit(goodsMaterial.getUnit());
|
|
|
|
|
+
|
|
|
|
|
+ List<String> walletIdList = new ArrayList<>();
|
|
|
|
|
+ List<String> walletCodedList = new ArrayList<>();
|
|
|
|
|
+ List<String> walletNameList = new ArrayList<>();
|
|
|
|
|
+ for(String name : walletName){
|
|
|
|
|
+ Wallet wallet = walletMap.get(name);
|
|
|
|
|
+ if(wallet == null){
|
|
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 钱包编码: "+name+", 不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ walletIdList.add(wallet.getId());
|
|
|
|
|
+ walletCodedList.add(wallet.getCode());
|
|
|
|
|
+ walletNameList.add(wallet.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<String> rebateTypeIdList = new ArrayList<>();
|
|
|
|
|
+ List<String> rebateTypeCodeList = new ArrayList<>();
|
|
|
|
|
+ List<String> rebateTypeNameList = new ArrayList<>();
|
|
|
|
|
+ if(StringUtils.isNotEmpty(rebateWalletNames)) {
|
|
|
|
|
+ String[] rebateWalletName = rebateWalletNames.trim().replaceAll(",",",").split(",");
|
|
|
|
|
+ for (String name : rebateWalletName) {
|
|
|
|
|
+ RebateType walletRebate = walletRebateMap.get(name);
|
|
|
|
|
+ if (walletRebate == null) {
|
|
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 返利钱包编码: " + name + ", 不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+// Integer count = commonLogic.getRebateSaleTypeCount(saleType.getId(), walletRebate.getWalletRebateId());
|
|
|
|
|
+// if (count == 0) {
|
|
|
|
|
+// throw new RemoteServiceException("返利钱包+【"+walletRebate.getName() + "】与销售类型【" + saleType.getSaleName() + "】对应关系不存在");
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ rebateTypeIdList.add(walletRebate.getId());
|
|
|
|
|
+ rebateTypeCodeList.add(walletRebate.getCode());
|
|
|
|
|
+ rebateTypeNameList.add(walletRebate.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ item.setRebateTypeName(CollectionUtil.isNotEmpty(Arrays.asList(rebateWalletName)) ? StrUtil.join(",", Arrays.asList(rebateWalletName)) : null);
|
|
|
|
|
+ }
|
|
|
|
|
+ item.setWalletId(StrUtil.join(",", walletIdList));
|
|
|
|
|
+ item.setWalletCode(StrUtil.join(",", walletCodedList));
|
|
|
|
|
+ item.setWalletName(StrUtil.join(",", walletNameList));
|
|
|
|
|
+ item.setRebateTypeId(CollectionUtil.isNotEmpty(rebateTypeIdList) ? StrUtil.join(",", rebateTypeIdList) : null);
|
|
|
|
|
+ item.setRebateTypeCode(CollectionUtil.isNotEmpty(rebateTypeCodeList) ? StrUtil.join(",", rebateTypeCodeList) : null);
|
|
|
|
|
+ item.setRebateTypeName(CollectionUtil.isNotEmpty(rebateTypeNameList) ? StrUtil.join(",", rebateTypeNameList) : null);
|
|
|
|
|
+ resultList.add(item);
|
|
|
|
|
+
|
|
|
|
|
+ index++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(resultList)) {
|
|
|
|
|
+ ProductPriceUpdate productUpdPriceBillBean = new ProductPriceUpdate();
|
|
|
|
|
+ final String generateNo = commonLogic.generateNo("PU", "PRODUCT_PRICE_UPDATE", 13);
|
|
|
|
|
+ productUpdPriceBillBean.setId(generateNo)
|
|
|
|
|
+ .setExamineStatus(ExamineStatusEnum.WAIT.getKey())
|
|
|
|
|
+ .setRemark(remark)
|
|
|
|
|
+ .insert();
|
|
|
|
|
+
|
|
|
|
|
+ productPriceUpdateItemService.saveBatch(resultList.stream()
|
|
|
|
|
+ .peek(v -> v.setProductPriceUpdateId(generateNo))
|
|
|
|
|
+ .collect(Collectors.toList()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return resultList.size();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public void batchFail(List<String> ids) {
|
|
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
|
|
+ final List<ProductPriceUpdate> updateList = productPriceUpdateService.lambdaQuery()
|
|
|
|
|
+ .select(ProductPriceUpdate::getId)
|
|
|
|
|
+ .eq(ProductPriceUpdate::getExamineStatus, ExamineStatusEnum.WAIT.getKey())
|
|
|
|
|
+ .in(ProductPriceUpdate::getId, ids)
|
|
|
|
|
+ .list();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ List<String> filterIds = updateList.stream()
|
|
|
|
|
+ .map(ProductPriceUpdate::getId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtil.isEmpty(filterIds)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ productPriceUpdateService.lambdaUpdate()
|
|
|
|
|
+ .set(ProductPriceUpdate::getExamineBy, adminUser.getNickName())
|
|
|
|
|
+ .set(ProductPriceUpdate::getExamineTime, DateUtil.date())
|
|
|
|
|
+ .set(ProductPriceUpdate::getExamineStatus, ExamineStatusEnum.SAVE.getKey())
|
|
|
|
|
+ .in(ProductPriceUpdate::getId, filterIds)
|
|
|
|
|
+ .update();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|