FengChaoYu 1 dia atrás
pai
commit
ca30ab99be

+ 2 - 2
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/constant/Constant.java

@@ -45,6 +45,8 @@ public class Constant {
         public final static String VERIFICATION = "zfire:overseas:verification";
         public final static String TOKEN_TAX = "zfire:overseas:token:tax";
         public final static String LOCK_EXCHANGE_CODE = "zfire:overseas:lock:exchangecode";
+
+        public final static String LOCK_COMMON =  "zfire:overseas:lock:common:";
         //订单号每日流水
         public final static String ORDER_NUM = "zfire:overseas:orderNo:";
 
@@ -57,8 +59,6 @@ public class Constant {
 
     }
 
-    //礼品卡支持的市
-    public final static List<String> GIFT_CITY = Arrays.asList("广州市","清远市","韶关市","佛山市","肇庆市","云浮市");
     //APPID
     public final static String APPID = "APPID";
     //默认的appid

+ 20 - 4
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/controller/goods/GoodsController.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.gree.mall.miniapp.annotation.ApiNotAuth;
 import com.gree.mall.miniapp.bean.goods.*;
 import com.gree.mall.miniapp.bean.user.UserWxBean;
+import com.gree.mall.miniapp.constant.Constant;
 import com.gree.mall.miniapp.enums.QrCodeEnum;
 import com.gree.mall.miniapp.exception.RemoteServiceException;
 import com.gree.mall.miniapp.helper.ResponseHelper;
@@ -21,7 +22,9 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.redis.util.RedisLockRegistry;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -30,6 +33,8 @@ import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.List;
 import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
 
 @Slf4j
 @RestController
@@ -46,6 +51,8 @@ public class GoodsController {
     WechatLogic wechatLogic;
     @Autowired
     OSSUtil ossUtil;
+    @Resource
+    RedisLockRegistry redisLockRegistry;
 
 
     @GetMapping("/category/list/all")
@@ -183,11 +190,20 @@ public class GoodsController {
     @ApiOperation("到货通知")
     public ResponseHelper<String> qrcode(
             @ApiParam(value = "商品id",required = true) @RequestParam String goodsId,
-            @ApiParam(value = "商品规格id",required = true) @RequestParam String goodsSpecId
-    ) throws IOException, RemoteServiceException {
-
+            @ApiParam(value = "商品规格id",required = true) @RequestParam String goodsSpecId,
+            @ApiParam(value = "仓库id",required = true) @RequestParam String storageId
+    ) throws Exception {
 
-        return ResponseHelper.success();
+        Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_COMMON + goodsId + goodsSpecId);
+        if(!obtain.tryLock(10, TimeUnit.SECONDS)){
+            return ResponseHelper.error("系统繁忙,请稍后再试");
+        }
+        try {
+            goodsLogic.adviceNotice(goodsId, goodsSpecId, storageId);
+            return ResponseHelper.success();
+        } finally {
+            obtain.unlock();
+        }
     }
 
 }

+ 48 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/goods/GoodsLogic.java

@@ -1,5 +1,6 @@
 package com.gree.mall.miniapp.logic.goods;
 
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.gree.mall.miniapp.logic.common.outside.WechatLogic;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.gree.mall.miniapp.logic.promotion.PromotionFullPieceLogic;
@@ -19,6 +20,7 @@ import com.gree.mall.miniapp.plus.service.*;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -62,6 +64,8 @@ public class GoodsLogic {
     GoodsMaterialStorageService goodsMaterialStorageService;
     @Resource
     GoodsDetailService goodsDetailService;
+    @Resource
+    GoodsAdviceNoticeService goodsAdviceNoticeService;
 
     /**
      * 商品列表
@@ -242,4 +246,48 @@ public class GoodsLogic {
         return goodsSpecService.getById(goodsSpecId);
     }
 
+    @Transactional
+    public void adviceNotice(String goodsId, String goodsSpecId, String storageId) {
+        final CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
+        final String companyWechatId = currentCompanyWechat.getCompanyWechatId();
+        GoodsAdviceNotice adviceNotice = goodsAdviceNoticeService.lambdaQuery()
+                .eq(GoodsAdviceNotice::getCompanyWechatId, companyWechatId)
+                .eq(GoodsAdviceNotice::getGoodsId, goodsId)
+                .eq(GoodsAdviceNotice::getGoodsSpecId, goodsSpecId)
+                .eq(GoodsAdviceNotice::getStorageId, storageId)
+                .eq(GoodsAdviceNotice::getIsNotice, false)
+                .one();
+
+        if (Objects.isNull(adviceNotice)) {
+            final GoodsSpec goodsSpec = goodsSpecService.lambdaQuery()
+                    .eq(GoodsSpec::getCompanyWechatId, companyWechatId)
+                    .eq(GoodsSpec::getGoodsId, goodsId)
+                    .eq(GoodsSpec::getGoodsSpecId, goodsSpecId)
+                    .one();
+            adviceNotice = new GoodsAdviceNotice();
+            adviceNotice.setId(IdWorker.getIdStr())
+                    .setCompanyWechatId(companyWechatId)
+                    .setCompanyName(currentCompanyWechat.getCompanyName())
+                    .setGoodsId(goodsId)
+                    .setGoodsSpecId(goodsSpecId)
+                    .setGoodsMaterialId(goodsSpec.getGoodsCode())
+                    .setStorageId(storageId)
+                    .setNum(1)
+                    .setIsNotice(false)
+                    .insert();
+        } else {
+            adviceNotice.setNum(adviceNotice.getNum() + 1)
+                    .updateById();
+        }
+
+        GoodsAdviceNoticeItem item = new GoodsAdviceNoticeItem();
+
+        try {
+            item.setGoodsAdviceNoticeId(adviceNotice.getId())
+                    .setUserId(currentCompanyWechat.getUserId())
+                    .insert();
+        } catch (Exception e) {
+            throw new RemoteServiceException("已记录");
+        }
+    }
 }

+ 31 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/goods/GoodsAdviceNoticeItemVO.java

@@ -0,0 +1,31 @@
+package com.gree.mall.manager.bean.goods;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@ApiModel
+@Data
+public class GoodsAdviceNoticeItemVO {
+
+    @ApiModelProperty(value = "id")
+    private String id;
+
+    @ApiModelProperty(value = "通知id")
+    private String goodsAdviceNoticeId;
+
+    @ApiModelProperty(value = "用户id")
+    private String userId;
+
+    @ApiModelProperty(value = "名称")
+    private String nickName;
+
+    @ApiModelProperty(value = "手机号")
+    private String mobile;
+
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+}

+ 69 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/goods/GoodsAdviceNoticeVO.java

@@ -0,0 +1,69 @@
+package com.gree.mall.manager.bean.goods;
+
+import com.gree.mall.manager.annotation.ZfireField;
+import com.gree.mall.manager.enums.IsEnum;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@ZfireField(tbName = "a")
+@ApiModel
+@Data
+public class GoodsAdviceNoticeVO {
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "id")
+    private String id;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "商户id")
+    private String companyWechatId;
+
+    @ApiModelProperty(value = "商户名称")
+    private String companyName;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "商品id")
+    private String goodsId;
+
+    @ZfireField(tbName = "b")
+    @ApiModelProperty(value = "商品名称")
+    private String goodsName;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "商品规格id")
+    private String goodsSpecId;
+
+    @ZfireField(tbName = "c")
+    @ApiModelProperty(value = "商品规格名称")
+    private String name;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "物料id")
+    private String goodsMaterialId;
+
+    @ZfireField(tbName = "d", colName = "goods_name")
+    @ApiModelProperty(value = "商品规格名称")
+    private String goodsMaterialName;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "仓库id")
+    private String storageId;
+
+    @ZfireField(tbName = "e", colName = "storage_name")
+    @ApiModelProperty(value = "仓库名称")
+    private String storageName;
+
+    @ApiModelProperty(value = "是否通知")
+    private IsEnum isNotice;
+
+    @ApiModelProperty(value = "人数")
+    private Integer num;
+
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 16 - 0
mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/CommonMapper.java

@@ -609,4 +609,20 @@ public interface CommonMapper {
      */
     IPage<GoodsStockWarningVO> goodsStockWarningList(Page page, @Param("ex") ZfireParamBean zfireParamBean, @Param("storageIds") List<String> storageIds);
 
+    /**
+     * 商品到货通知记录
+     * @param page
+     * @param zfireParamBean
+     * @param storageIds
+     * @return
+     */
+    IPage<GoodsAdviceNoticeVO> goodsAdviceNoticeList(Page page, @Param("ex") ZfireParamBean zfireParamBean, @Param("storageIds") List<String> storageIds);
+
+    /**
+     * 商品到货通知记录明细
+     * @param page
+     * @param id
+     * @return
+     */
+    IPage<GoodsAdviceNoticeItemVO> goodsAdviceNoticeItemList(Page page, @Param("id") String id);
 }

+ 59 - 0
mall-server-api/src/main/java/com/gree/mall/manager/controller/goods/GoodsAdviceNoticeController.java

@@ -0,0 +1,59 @@
+package com.gree.mall.manager.controller.goods;
+
+import cn.hutool.core.lang.TypeReference;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.gree.mall.manager.annotation.ZfireList;
+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.helper.ResponseHelper;
+import com.gree.mall.manager.logic.goods.GoodsAdviceNoticeLogic;
+import com.gree.mall.manager.logic.goods.GoodsMaterialLogic;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+@Slf4j
+@RestController
+@Api(value = "商品到货通知API", tags ={"商品到货通知API"} )
+@RequestMapping(value = "/goods/advice/notice", produces = "application/json; charset=utf-8")
+public class GoodsAdviceNoticeController {
+
+    @Resource
+    GoodsAdviceNoticeLogic goodsAdviceNoticeLogic;
+
+    @ZfireList
+    @PostMapping("/list")
+    @ApiOperation(value = "列表")
+    public ResponseHelper<IPage<GoodsAdviceNoticeVO>> page(
+            @RequestBody ZfireParamBean zfireParamBean
+    ) throws Exception {
+        IPage<GoodsAdviceNoticeVO> page = goodsAdviceNoticeLogic.page(zfireParamBean);
+        return ResponseHelper.success(page, new TypeReference<GoodsAdviceNoticeVO>() {});
+    }
+
+    @PostMapping("/item/list")
+    @ApiOperation(value = "明细列表")
+    public ResponseHelper<IPage<GoodsAdviceNoticeItemVO>> itemList(
+            @ApiParam(value = "id", required = true) @RequestParam String id,
+            @ApiParam(value = "pageNo", required = true) @RequestParam Integer pageNum,
+            @ApiParam(value = "pageSize", required = true) @RequestParam Integer pageSize
+    ) throws Exception {
+        IPage<GoodsAdviceNoticeItemVO> page = goodsAdviceNoticeLogic.itemList(id, pageNum, pageSize);
+        return ResponseHelper.success(page);
+    }
+
+    @PostMapping("/send")
+    @ApiOperation(value = "发送通知到货")
+    public ResponseHelper send(
+            @ApiParam(value = "id", required = true) @RequestParam String id
+    ) throws Exception {
+        goodsAdviceNoticeLogic.send(id);
+        return ResponseHelper.success();
+    }
+}

+ 121 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/goods/GoodsAdviceNoticeLogic.java

@@ -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();
+    }
+}

+ 32 - 0
mall-server-api/src/main/resources/mapper/CommonMapper.xml

@@ -1159,5 +1159,37 @@
         </if>
         ${ex.orderBy}
     </select>
+    <select id="goodsAdviceNoticeList" resultType="com.gree.mall.manager.bean.goods.GoodsAdviceNoticeVO">
+        SELECT
+        ${ex.selected}
+        FROM goods_advice_notice a LEFT JOIN goods b ON a.goods_id = b.goods_id
+            LEFT JOIN goods_spec c ON a.goods_spec_id = c.goods_spec_id
+            LEFT JOIN goods_material d ON a.goods_material_id = d.id
+            LEFT JOIN storage e ON a.storage_id = e.storage_id
+        ${ex.query}
+        <if test="ex.companyWechatId != null and ex.companyWechatId != ''">
+            AND a.company_wechat_id = ${ex.companyWechatId}
+        </if>
+        <if test="storageIds != null and storageIds.size > 0">
+            AND a.storage_id IN
+            <foreach item="item" index="index" collection="storageIds" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="ex.orderBy == null or ex.orderBy ==''">
+            ORDER BY a.create_time DESC
+        </if>
+        ${ex.orderBy}
+    </select>
+    <select id="goodsAdviceNoticeItemList"
+            resultType="com.gree.mall.manager.bean.goods.GoodsAdviceNoticeItemVO">
+        SELECT
+            a.*, b.*
+        FROM
+            goods_advice_notice_item a LEFT JOIN  user b ON a.user_id = b.user_id
+        WHERE
+            a.id = #{id}
+        ORDER BY a.create_time DESC
+    </select>
 
 </mapper>