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