Przeglądaj źródła

新增商品库存预警查询

FengChaoYu 1 dzień temu
rodzic
commit
a6009c417f

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

@@ -0,0 +1,67 @@
+package com.gree.mall.manager.bean.goods;
+
+import com.gree.mall.manager.annotation.ZfireField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@ApiModel
+@ZfireField(tbName = "a")
+public class GoodsStockWarningVO {
+
+    @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(hide = true)
+    @ApiModelProperty(value = "商品物料id")
+    private String goodsMaterialId;
+
+    @ApiModelProperty(value = "商品规格名称")
+    private String name;
+
+    @ZfireField(tbName = "c", colName = "goods_name")
+    @ApiModelProperty(value = "物料名称")
+    private String goodsMaterialName;
+
+    @ApiModelProperty(value = "物料规格型号")
+    private String specValue;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "仓库id")
+    private String storageId;
+
+    @ApiModelProperty(value = "仓库名称")
+    private String storageName;
+
+    @ApiModelProperty(value = "预设数量")
+    private Integer warningQty;
+
+    @ApiModelProperty(value = "报警时数量")
+    private Integer stockQty;
+
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+}

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

@@ -604,4 +604,13 @@ public interface CommonMapper {
      * @return
      */
     IPage<GoodsPriceChangeVO> goodsPriceChangePage(Page page, @Param("ex") ZfireParamBean zfireParamBean);
+
+    /**
+     * 物料库存预警记录
+     * @param page
+     * @param zfireParamBean
+     * @param storageIds
+     * @return
+     */
+    IPage<GoodsStockWarningVO> goodsStockWarningList(Page page, @Param("ex") ZfireParamBean zfireParamBean, @Param("storageIds") List<String> storageIds);
 }

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

@@ -0,0 +1,57 @@
+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.GoodsStockWarningVO;
+import com.gree.mall.manager.bean.listvo.goods.GoodsMaterialStockAccVO;
+import com.gree.mall.manager.helper.ResponseHelper;
+import com.gree.mall.manager.logic.goods.GoodsMaterialStockAccLogic;
+import com.gree.mall.manager.logic.goods.GoodsStockWarningLogic;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import com.gree.mall.manager.zfire.util.FieldUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+@Slf4j
+@RestController
+@Api(value = "商品规格库存预警API", tags ={"商品规格库存预警API"} )
+@RequestMapping(value = "/goods/spec/warning", produces = "application/json; charset=utf-8")
+@RequiredArgsConstructor
+public class GoodsStockWarningController {
+
+    private final GoodsStockWarningLogic goodsStockWarningLogic;
+
+    @ZfireList
+    @PostMapping("/list")
+    @ApiOperation(value = "列表")
+    public ResponseHelper<IPage<GoodsStockWarningVO>> page(
+            @RequestBody ZfireParamBean zfireParamBean
+    ) throws Exception {
+        IPage<GoodsStockWarningVO> page = goodsStockWarningLogic.list(zfireParamBean);
+        return ResponseHelper.success(page, new TypeReference<GoodsStockWarningVO>() {});
+    }
+
+    @PostMapping("/list/export")
+    @ApiOperation("导出")
+    public void listExport(
+            @RequestBody ZfireParamBean zfireParamBean,
+            HttpServletRequest request,
+            HttpServletResponse response
+    ) throws Exception {
+        //2.查询要导出的内容
+        IPage<GoodsStockWarningVO> baseVOIPage = goodsStockWarningLogic.list(zfireParamBean);
+        //3.导出
+        FieldUtils.exportData(baseVOIPage.getRecords(), zfireParamBean.getExportFields(), request, response);
+    }
+}

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

@@ -0,0 +1,31 @@
+package com.gree.mall.manager.logic.goods;
+
+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.GoodsStockWarningVO;
+import com.gree.mall.manager.commonmapper.CommonMapper;
+import com.gree.mall.manager.logic.common.CommonLogic;
+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.stereotype.Service;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class GoodsStockWarningLogic {
+
+    private final CommonMapper commonMapper;
+    private final CommonLogic commonLogic;
+
+
+    public IPage<GoodsStockWarningVO> list(ZfireParamBean zfireParamBean){
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        FieldUtils.supplyParam(zfireParamBean, GoodsStockWarningVO.class, adminUser);
+        IPage<GoodsStockWarningVO> list = commonMapper.goodsStockWarningList(new Page(zfireParamBean.getPageNum(),
+                zfireParamBean.getPageSize()), zfireParamBean, adminUser.getStorageIds());
+        return list;
+    }
+}

+ 97 - 0
mall-server-api/src/main/java/com/gree/mall/manager/schedule/GoodsStockWarningSchedule.java

@@ -0,0 +1,97 @@
+package com.gree.mall.manager.schedule;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.gree.mall.manager.plus.entity.GoodsMaterialStorage;
+import com.gree.mall.manager.plus.entity.GoodsSpec;
+import com.gree.mall.manager.plus.entity.GoodsStorageWarningRecord;
+import com.gree.mall.manager.plus.service.GoodsMaterialStorageService;
+import com.gree.mall.manager.plus.service.GoodsSpecService;
+import com.gree.mall.manager.plus.service.GoodsStorageWarningRecordService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+@ConditionalOnProperty(name = "schedule.enable", havingValue = "true", matchIfMissing = true)
+@Component
+@Slf4j
+public class GoodsStockWarningSchedule {
+
+    @Resource
+    GoodsSpecService goodsSpecService;
+    @Resource
+    GoodsMaterialStorageService goodsMaterialStorageService;
+    @Resource
+    GoodsStorageWarningRecordService goodsStorageWarningRecordService;
+
+    /**
+     * 库存预警生成
+     */
+    @Transactional
+    @Scheduled(fixedDelay = 300  * 1000)
+    public void task(){
+        // 找出预警数大于0的商品规格
+        final List<GoodsSpec> goodsSpecList = goodsSpecService.lambdaQuery()
+                .gt(GoodsSpec::getStockWarningNum, 0)
+                .list();
+
+        if (CollectionUtil.isEmpty(goodsSpecList)) {
+            return;
+        }
+
+        for (GoodsSpec goodsSpec : goodsSpecList) {
+            // 根据物料id找物料仓库少于等于预警数的数据
+            final List<GoodsMaterialStorage> storageList = goodsMaterialStorageService.lambdaQuery()
+                    .eq(GoodsMaterialStorage::getGoodsMaterialId, goodsSpec.getGoodsCode())
+                    .le(GoodsMaterialStorage::getStockQty, goodsSpec.getStockWarningNum())
+                    .list();
+
+            if (CollectionUtil.isNotEmpty(storageList)) {
+                // 查找到物料仓库少于等于预警数的数据
+                List<GoodsStorageWarningRecord> recordList = new ArrayList<>();
+
+                for (GoodsMaterialStorage storage : storageList) {
+                    // 检查是否存在预警记录
+                    GoodsStorageWarningRecord warningRecord = goodsStorageWarningRecordService.lambdaQuery()
+                            .eq(GoodsStorageWarningRecord::getGoodsMaterialId, storage.getGoodsMaterialId())
+                            .one();
+
+                    if (Objects.isNull(warningRecord)) {
+                        // 记录为空插入新记录
+                        GoodsStorageWarningRecord record = new GoodsStorageWarningRecord();
+                        record.setCompanyWechatId(goodsSpec.getCompanyWechatId())
+                                .setCompanyName(goodsSpec.getCompanyName())
+                                .setGoodsId(goodsSpec.getGoodsId())
+                                .setGoodsSpecId(goodsSpec.getGoodsSpecId())
+                                .setGoodsMaterialId(goodsSpec.getGoodsCode())
+                                .setName(goodsSpec.getName())
+                                .setSpecValue(goodsSpec.getSpecValue())
+                                .setStorageId(storage.getStorageId())
+                                .setStorageName(storage.getStorageName())
+                                .setWarningQty(goodsSpec.getStockWarningNum())
+                                .setStockQty(storage.getStockQty());
+
+                        recordList.add(record);
+                    } else {
+                        warningRecord.setWarningQty(goodsSpec.getStockWarningNum())
+                                .setStockQty(storage.getStockQty());
+                        recordList.add(warningRecord);
+                    }
+                }
+
+                goodsStorageWarningRecordService.saveOrUpdateBatch(recordList);
+            } else {
+                // 未找到物料仓库少于等于预警数的数据, 执行删除对应物料id记录
+                goodsStorageWarningRecordService.lambdaUpdate()
+                        .eq(GoodsStorageWarningRecord::getGoodsMaterialId, goodsSpec.getGoodsCode())
+                        .remove();
+            }
+        }
+    }
+}

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

@@ -1144,5 +1144,25 @@
         </if>
         ${ex.orderBy}
     </select>
+    <select id="goodsStockWarningList" resultType="com.gree.mall.manager.bean.goods.GoodsStockWarningVO">
+        SELECT
+        ${ex.selected}
+        FROM goods_storage_warning_record a LEFT JOIN goods b ON a.goods_id = b.goods_id
+        LEFT JOIN goods_material c ON a.goods_material_id = c.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>
 
 </mapper>