Przeglądaj źródła

设置库存预警通知

zoujiajian 2 lat temu
rodzic
commit
48877594ba

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GroupsRelationAlertMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.GroupsRelationAlert;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: GroupsRelationAlertMapper
+ * 创建者: JavaZou
+ * 创建时间:2023/10/26 15:14
+ */
+public interface GroupsRelationAlertMapper extends BaseMapper<GroupsRelationAlert> {
+}

+ 47 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/GroupsRelationAlert.java

@@ -0,0 +1,47 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: GroupsRelationAlert
+ * 创建者: JavaZou
+ * 创建时间:2023/10/26 15:13
+ */
+@Getter
+@Setter
+public class GroupsRelationAlert extends BaseEntity{
+
+	/**
+	 * 针对库存
+	 */
+	@NotNull
+	private Long skuId;
+
+	/**
+	 * 预警数量
+	 */
+	@NotNull(message = "预警数量不为空")
+	@Min(value = 1, message = "请输入正确的库存预警数量")
+	private Integer num;
+
+	/**
+	 * 手机号
+	 */
+	@NotNull(message = "手机号不为空")
+	private String phoneStr;
+
+	/**
+	 * 预警开发
+	 */
+	private Boolean isOpen;
+
+	/**
+	 * 是否重置 根据新增对应规格账号 重置该预警记录
+	 */
+	private Boolean isRest;
+}

+ 21 - 0
netflix-service/src/main/java/com/cyksj/service/mange/group/CmsGroupServiceImpl.java

@@ -69,6 +69,9 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
     private final GroupsMapper groupsMapper;
 
     private final AccountCommonService accountCommonService;
+
+    private final GroupsRelationAlertMapper alertMapper;
+
     private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
 
 
@@ -102,6 +105,15 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
             }
             relationMapper.insert(relation);
         }
+        Integer alertCount = alertMapper.selectCount(Wrappers.lambdaQuery(GroupsRelationAlert.class)
+                .eq(GroupsRelationAlert::getSkuId, sku.getId())
+                .last("limit 1"));
+        if (alertCount > 0) {
+            alertMapper.update(null, Wrappers.lambdaUpdate(GroupsRelationAlert.class)
+                    .set(GroupsRelationAlert::getIsRest, true)
+                    .eq(GroupsRelationAlert::getSkuId, sku.getId())
+                    .eq(GroupsRelationAlert::getIsRest, false));
+        }
         return groups;
     }
 
@@ -248,6 +260,15 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
         }
        updateById(groupsTrips);
 
+        Integer alertCount = alertMapper.selectCount(Wrappers.lambdaQuery(GroupsRelationAlert.class)
+                .eq(GroupsRelationAlert::getSkuId, sku.getId())
+                .last("limit 1"));
+        if (alertCount > 0) {
+            alertMapper.update(null, Wrappers.lambdaUpdate(GroupsRelationAlert.class)
+                    .set(GroupsRelationAlert::getIsRest, true)
+                    .eq(GroupsRelationAlert::getSkuId, sku.getId())
+                    .eq(GroupsRelationAlert::getIsRest, false));
+        }
     }
 
     @Override

+ 50 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/group/CmsGroupController.java

@@ -4,21 +4,26 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateTime;
+import cn.hutool.core.lang.Validator;
 import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONObject;
 import com.alibaba.excel.support.ExcelTypeEnum;
+import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.annotation.Log;
 import com.cyksj.common.annotation.NoSubmit;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.GoogleGenerator;
+import com.cyksj.common.util.Jsons;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.BusinessType;
 import com.cyksj.enums.GatewayResponse;
+import com.cyksj.mapper.GroupsRelationAlertMapper;
 import com.cyksj.mapper.GroupsRelationMapper;
 import com.cyksj.mapper.UserMapper;
 import com.cyksj.model.entity.Account;
+import com.cyksj.model.entity.GroupsRelationAlert;
 import com.cyksj.model.entity.GroupsTrips;
 import com.cyksj.model.entity.GroupsTripsAccountReplaceRecord;
 import com.cyksj.model.excel.ExcelGroupRelationData;
@@ -39,6 +44,7 @@ import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.dao.DuplicateKeyException;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -69,6 +75,8 @@ public class CmsGroupController {
 
     private final AccountCommonService accountCommonService;
 
+    private final GroupsRelationAlertMapper alertMapper;
+
     private final UserMapper userMapper;
 
     @GetMapping("/get")
@@ -340,4 +348,46 @@ public class CmsGroupController {
         Integer available = groupService.getAvailableRelation(goodsId, skuId);
         return GatewayResponse.SUCCESS.newBuilder().toResult(available);
     }
+
+    /**
+     * 设置库存预警通知
+     */
+    @PutMapping("/set/relation/alert")
+    public Result<String> setGroupsRelationAlert(@RequestBody @Validated GroupsRelationAlert groupsRelationAlert) throws Exception {
+        if (groupsRelationAlert.getId() == null) {
+            try {
+                alertMapper.insert(groupsRelationAlert);
+            } catch (DuplicateKeyException e) {
+            }
+            return GatewayResponse.SUCCESS.newBuilder().toResult();
+        }
+        Long id = groupsRelationAlert.getId();
+        Assert.notNull(id, "预警id不存在");
+        GroupsRelationAlert dbAlert = alertMapper.selectById(id);
+        Assert.notNull(dbAlert, "预警不存在");
+        String phoneStr = groupsRelationAlert.getPhoneStr();
+        List<String> phoneList = Jsons.parseList(phoneStr, String.class);
+        phoneList.forEach(phone -> {
+            if (!Validator.isMobile(phone)) {
+                throw BusinessRuntimeException.getInstance("请输入正确的手机格式");
+            }
+        });
+        Integer dbNum = dbAlert.getNum();
+        Integer num = groupsRelationAlert.getNum();
+        if (dbNum != num) {
+            groupsRelationAlert.setIsRest(true);
+        }
+        alertMapper.updateById(groupsRelationAlert);
+        return GatewayResponse.SUCCESS.newBuilder().toResult();
+    }
+
+    /**
+     * 库存预警通知
+     */
+    @GetMapping("/get/relation/alert")
+    public Result<GroupsRelationAlert> getGroupsRelationAlert(@RequestParam(required = true) Long skuId) {
+        GroupsRelationAlert groupsRelationAlert = alertMapper.selectOne(Wrappers.lambdaQuery(GroupsRelationAlert.class)
+                .eq(GroupsRelationAlert::getSkuId, skuId).last("limit 1"));
+        return GatewayResponse.SUCCESS.newBuilder().toResult(groupsRelationAlert);
+    }
 }