|
@@ -0,0 +1,121 @@
|
|
|
|
|
+package com.gree.mall.manager.logic.goods;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+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.goods.GoodsAdviceNoticeItemVO;
|
|
|
|
|
+import com.gree.mall.manager.bean.goods.GoodsAdviceNoticeVO;
|
|
|
|
|
+import com.gree.mall.manager.bean.goods.GoodsMaterialVO;
|
|
|
|
|
+import com.gree.mall.manager.bean.listvo.goods.GoodsMaterialStockAccVO;
|
|
|
|
|
+import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
|
|
|
+import com.gree.mall.manager.enums.IsYesNoEnum;
|
|
|
|
|
+import com.gree.mall.manager.enums.NoticeEnum;
|
|
|
|
|
+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.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class GoodsAdviceNoticeLogic {
|
|
|
|
|
+
|
|
|
|
|
+ private final CommonLogic commonLogic;
|
|
|
|
|
+ private final CommonMapper commonMapper;
|
|
|
|
|
+ private final GoodsAdviceNoticeService goodsAdviceNoticeService;
|
|
|
|
|
+ private final GoodsAdviceNoticeItemService goodsAdviceNoticeItemService;
|
|
|
|
|
+ private final GoodsMaterialStorageService goodsMaterialStorageService;
|
|
|
|
|
+ private final NoticeRecordService noticeRecordService;
|
|
|
|
|
+ private final UserService userService;
|
|
|
|
|
+ private final GoodsService goodsService;
|
|
|
|
|
+ private final GoodsSpecService goodsSpecService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public IPage<GoodsAdviceNoticeVO> page(ZfireParamBean zfireParamBean) {
|
|
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
|
|
+ FieldUtils.supplyParam(zfireParamBean, GoodsAdviceNoticeVO.class, adminUser);
|
|
|
|
|
+ IPage<GoodsAdviceNoticeVO> list = commonMapper.goodsAdviceNoticeList(new Page(zfireParamBean.getPageNum(),
|
|
|
|
|
+ zfireParamBean.getPageSize()), zfireParamBean, adminUser.getStorageIds());
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public IPage<GoodsAdviceNoticeItemVO> itemList(String id, Integer pageNum, Integer pageSize) {
|
|
|
|
|
+ IPage<GoodsAdviceNoticeItemVO> list = commonMapper.goodsAdviceNoticeItemList(new Page(pageNum,
|
|
|
|
|
+ pageSize), id);
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public void send(String id) {
|
|
|
|
|
+ GoodsAdviceNotice adviceNotice = goodsAdviceNoticeService.getById(id);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查是否有库存才发送通知
|
|
|
|
|
+ final GoodsMaterialStorage materialStorage = goodsMaterialStorageService.lambdaQuery()
|
|
|
|
|
+ .eq(GoodsMaterialStorage::getCompanyWechatId, adviceNotice.getCompanyWechatId())
|
|
|
|
|
+ .eq(GoodsMaterialStorage::getStorageId, adviceNotice.getStorageId())
|
|
|
|
|
+ .eq(GoodsMaterialStorage::getGoodsMaterialId, adviceNotice.getGoodsMaterialId())
|
|
|
|
|
+ .one();
|
|
|
|
|
+
|
|
|
|
|
+ if (materialStorage.getStockQty() <= 0) {
|
|
|
|
|
+ throw new RemoteServiceException("检查到库存为0, 发送失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ final Goods goods = goodsService.getById(adviceNotice.getId());
|
|
|
|
|
+ final GoodsSpec goodsSpec = goodsSpecService.getById(adviceNotice.getGoodsSpecId());
|
|
|
|
|
+
|
|
|
|
|
+ List<GoodsAdviceNoticeItem> itemList = goodsAdviceNoticeItemService.lambdaQuery()
|
|
|
|
|
+ .eq(GoodsAdviceNoticeItem::getId, id)
|
|
|
|
|
+ .list();
|
|
|
|
|
+
|
|
|
|
|
+ final List<User> userList = userService.lambdaQuery()
|
|
|
|
|
+ .in(User::getUserId, itemList.stream().map(GoodsAdviceNoticeItem::getUserId).collect(Collectors.toList()))
|
|
|
|
|
+ .list();
|
|
|
|
|
+
|
|
|
|
|
+ final Map<String, String> userMap = userList.stream().collect(Collectors.toMap(User::getUserId, User::getNickName));
|
|
|
|
|
+
|
|
|
|
|
+ List<NoticeRecord> recordList = new ArrayList<>();
|
|
|
|
|
+ for (GoodsAdviceNoticeItem item : itemList) {
|
|
|
|
|
+ final String nickName = userMap.get(item.getUserId());
|
|
|
|
|
+ if (StringUtils.isBlank(nickName)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ NoticeRecord noticeRecord = new NoticeRecord();
|
|
|
|
|
+ noticeRecord.setNoticeId(adviceNotice.getStorageId());
|
|
|
|
|
+ noticeRecord.setTitle("到货通知");
|
|
|
|
|
+ noticeRecord.setContent("“"+ materialStorage.getStorageName() + "”仓库, 的商品”" + goods.getGoodsName()
|
|
|
|
|
+ + "“规格名称“" + goodsSpec.getName() + "“已到货, 可下单购买!");
|
|
|
|
|
+ noticeRecord.setType(NoticeEnum.B.getKey());
|
|
|
|
|
+ noticeRecord.setIsNotice(IsYesNoEnum.YES.getKey());
|
|
|
|
|
+ noticeRecord.setReadFlag(IsYesNoEnum.NO.getKey());
|
|
|
|
|
+ noticeRecord.setAdminUserId(item.getUserId());
|
|
|
|
|
+ noticeRecord.setAdminNickName(nickName);
|
|
|
|
|
+ noticeRecord.setIsWorker("YES");
|
|
|
|
|
+ noticeRecord.setIssueTime(new Date());
|
|
|
|
|
+ noticeRecord.setAdminCompanyId(adviceNotice.getCompanyWechatId());
|
|
|
|
|
+ noticeRecord.setAdminCompanyName(adviceNotice.getCompanyName());
|
|
|
|
|
+ noticeRecord.setNoticeType("SYSTEM");
|
|
|
|
|
+ recordList.add(noticeRecord);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(recordList)) {
|
|
|
|
|
+ noticeRecordService.saveBatch(recordList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ adviceNotice.setIsNotice(true)
|
|
|
|
|
+ .updateById();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|