Yansen 2 lat temu
rodzic
commit
2a8bc8aa66

+ 33
- 28
src/main/java/com/yunzhi/inte/controller/NoticeMessageController.java Wyświetl plik

59
         return ResponseBean.success(result);
59
         return ResponseBean.success(result);
60
     }
60
     }
61
     
61
     
62
-    /** 
63
-     * 新增数据
64
-     *
65
-     * @param noticeMessage 实例对象
66
-     * @return 实例对象
67
-     */
68
-    @ApiOperation("新增数据")
69
-    @PostMapping("/noticeMessage")
70
-    public ResponseBean add(@ApiParam("对象实体") @RequestBody NoticeMessage noticeMessage) throws Exception {
71
-        noticeMessageService.save(noticeMessage);
72
-        return ResponseBean.success(noticeMessage);
73
-    }
62
+//    /**
63
+//     * 新增数据
64
+//     *
65
+//     * @param noticeMessage 实例对象
66
+//     * @return 实例对象
67
+//     */
68
+//    @ApiOperation("新增数据")
69
+//    @PostMapping("/noticeMessage")
70
+//    public ResponseBean add(@ApiParam("对象实体") @RequestBody NoticeMessage noticeMessage) throws Exception {
71
+//        noticeMessageService.save(noticeMessage);
72
+//        return ResponseBean.success(noticeMessage);
73
+//    }
74
     
74
     
75
     /** 
75
     /** 
76
      * 更新数据
76
      * 更新数据
77
      *
77
      *
78
-     * @param noticeMessage 实例对象
78
+     * @param id 对象ID
79
      * @return 实例对象
79
      * @return 实例对象
80
      */
80
      */
81
     @ApiOperation("更新数据")
81
     @ApiOperation("更新数据")
82
-    @PutMapping("/noticeMessage/{id}")
83
-    public ResponseBean edit(@ApiParam("对象实体") @RequestBody NoticeMessage noticeMessage,
84
-                            @ApiParam("对象ID") @PathVariable Integer id ) throws Exception {
82
+    @PutMapping("/noticeMessage/{id}/readed")
83
+    public ResponseBean edit(@ApiParam("对象ID") @PathVariable Integer id ) throws Exception {
84
+        NoticeMessage noticeMessage = noticeMessageService.getById(id);
85
+        if (null == noticeMessage) {
86
+            return ResponseBean.error("未找到消息内容");
87
+        }
88
+
89
+        noticeMessage.setIsReaded(true);
85
         noticeMessageService.updateById(noticeMessage);
90
         noticeMessageService.updateById(noticeMessage);
86
         return ResponseBean.success(noticeMessage);
91
         return ResponseBean.success(noticeMessage);
87
     }
92
     }
88
     
93
     
89
-    /** 
90
-     * 通过主键删除数据
91
-     *
92
-     * @param id 主键
93
-     * @return 是否成功
94
-     */
95
-    @ApiOperation("通过主键删除数据")
96
-    @DeleteMapping("/noticeMessage/{id}")
97
-    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
98
-        noticeMessageService.removeLogicById(id);
99
-        return ResponseBean.success("success");
100
-    }
94
+//    /**
95
+//     * 通过主键删除数据
96
+//     *
97
+//     * @param id 主键
98
+//     * @return 是否成功
99
+//     */
100
+//    @ApiOperation("通过主键删除数据")
101
+//    @DeleteMapping("/noticeMessage/{id}")
102
+//    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
103
+//        noticeMessageService.removeLogicById(id);
104
+//        return ResponseBean.success("success");
105
+//    }
101
 }
106
 }

+ 27
- 23
src/main/java/com/yunzhi/inte/controller/PostsController.java Wyświetl plik

9
 
9
 
10
 import java.time.LocalDateTime;
10
 import java.time.LocalDateTime;
11
 import java.util.List;
11
 import java.util.List;
12
+
12
 import io.swagger.annotations.Api;
13
 import io.swagger.annotations.Api;
13
 import io.swagger.annotations.ApiOperation;
14
 import io.swagger.annotations.ApiOperation;
14
 import io.swagger.annotations.ApiParam;
15
 import io.swagger.annotations.ApiParam;
17
 import com.yunzhi.inte.entity.Posts;
18
 import com.yunzhi.inte.entity.Posts;
18
 import com.yunzhi.inte.service.PostsService;
19
 import com.yunzhi.inte.service.PostsService;
19
 
20
 
20
- /**
21
+/**
21
  * 信息发布表;(posts)表控制层
22
  * 信息发布表;(posts)表控制层
23
+ *
22
  * @author : http://njyunzhi.com
24
  * @author : http://njyunzhi.com
23
  * @date : 2022-10-16
25
  * @date : 2022-10-16
24
  */
26
  */
26
 @RestController
28
 @RestController
27
 @RequestMapping("/")
29
 @RequestMapping("/")
28
 public class PostsController extends BaseController {
30
 public class PostsController extends BaseController {
29
-    
31
+
30
     @Autowired
32
     @Autowired
31
     private PostsService postsService;
33
     private PostsService postsService;
32
-    
33
-    /** 
34
-     * 通过ID查询单条数据 
34
+
35
+    /**
36
+     * 通过ID查询单条数据
35
      *
37
      *
36
      * @param id 主键
38
      * @param id 主键
37
      * @return 实例对象
39
      * @return 实例对象
41
     public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
43
     public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
42
         return ResponseBean.success(postsService.getById(id));
44
         return ResponseBean.success(postsService.getById(id));
43
     }
45
     }
44
-    
45
-    /** 
46
+
47
+    /**
46
      * 分页查询
48
      * 分页查询
47
      *
49
      *
48
-     * @param pageNum 当前页码
50
+     * @param pageNum  当前页码
49
      * @param pageSize 每页条数
51
      * @param pageSize 每页条数
50
      * @return 查询结果
52
      * @return 查询结果
51
      */
53
      */
52
     @ApiOperation("分页查询")
54
     @ApiOperation("分页查询")
53
     @GetMapping("/posts")
55
     @GetMapping("/posts")
54
-    public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
55
-                            @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
56
-        
56
+    public ResponseBean list(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
57
+                             @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws Exception {
58
+
57
         IPage<Posts> pg = new Page<>(pageNum, pageSize);
59
         IPage<Posts> pg = new Page<>(pageNum, pageSize);
58
-        // QueryWrapper<Posts> queryWrapper = new QueryWrapper<>();
59
-        // queryWrapper.orderByDesc("create_date");
60
-        IPage<Posts> result = postsService.page(pg);
61
-        
60
+        QueryWrapper<Posts> queryWrapper = new QueryWrapper<>();
61
+        queryWrapper.gt("status", Constants.STATUS_DELETE);
62
+
63
+        queryWrapper.orderByDesc("create_date");
64
+        IPage<Posts> result = postsService.page(pg, queryWrapper);
65
+
62
         return ResponseBean.success(result);
66
         return ResponseBean.success(result);
63
     }
67
     }
64
-    
65
-    /** 
68
+
69
+    /**
66
      * 新增数据
70
      * 新增数据
67
      *
71
      *
68
      * @param posts 实例对象
72
      * @param posts 实例对象
81
         postsService.save(posts);
85
         postsService.save(posts);
82
         return ResponseBean.success(posts);
86
         return ResponseBean.success(posts);
83
     }
87
     }
84
-    
85
-    /** 
88
+
89
+    /**
86
      * 更新数据
90
      * 更新数据
87
      *
91
      *
88
      * @param posts 实例对象
92
      * @param posts 实例对象
91
     @ApiOperation("更新数据")
95
     @ApiOperation("更新数据")
92
     @PutMapping("/posts/{id}")
96
     @PutMapping("/posts/{id}")
93
     public ResponseBean edit(@ApiParam("对象实体") @RequestBody Posts posts,
97
     public ResponseBean edit(@ApiParam("对象实体") @RequestBody Posts posts,
94
-                            @ApiParam("对象ID") @PathVariable Integer id ) throws Exception {
98
+                             @ApiParam("对象ID") @PathVariable Integer id) throws Exception {
95
 
99
 
96
         posts.setId(id);
100
         posts.setId(id);
97
 
101
 
98
         postsService.updateById(posts);
102
         postsService.updateById(posts);
99
         return ResponseBean.success(posts);
103
         return ResponseBean.success(posts);
100
     }
104
     }
101
-    
102
-    /** 
105
+
106
+    /**
103
      * 通过主键删除数据
107
      * 通过主键删除数据
104
      *
108
      *
105
      * @param id 主键
109
      * @param id 主键
107
      */
111
      */
108
     @ApiOperation("通过主键删除数据")
112
     @ApiOperation("通过主键删除数据")
109
     @DeleteMapping("/posts/{id}")
113
     @DeleteMapping("/posts/{id}")
110
-    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
114
+    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id) {
111
         postsService.removeLogicById(id);
115
         postsService.removeLogicById(id);
112
         return ResponseBean.success("success");
116
         return ResponseBean.success("success");
113
     }
117
     }

+ 28
- 0
src/main/java/com/yunzhi/inte/controller/StoreController.java Wyświetl plik

7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
 
9
 
10
+import com.yunzhi.inte.entity.StoreType;
11
+import com.yunzhi.inte.service.StoreTypeService;
10
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiParam;
14
 import io.swagger.annotations.ApiParam;
30
     @Autowired
32
     @Autowired
31
     private StoreService storeService;
33
     private StoreService storeService;
32
 
34
 
35
+    @Autowired
36
+    private StoreTypeService storeTypeService;
37
+
33
     /**
38
     /**
34
      * 通过ID查询单条数据
39
      * 通过ID查询单条数据
35
      *
40
      *
98
             return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
103
             return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
99
         }
104
         }
100
 
105
 
106
+        if (null == store.getTypeId()) {
107
+            return ResponseBean.error("未选择分类", ResponseBean.ERROR_ILLEGAL_PARAMS);
108
+        }
109
+
110
+        StoreType storeType = storeTypeService.getById(store.getTypeId());
111
+        if (null == storeType) {
112
+            return ResponseBean.error("分类选择不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
113
+        }
114
+
115
+        store.setIsDish(storeType.getIsFood());
116
+        store.setIsDevice(storeType.getIsDevice());
101
         store.setStatus(Constants.STATUS_NORMAL);
117
         store.setStatus(Constants.STATUS_NORMAL);
102
         storeService.save(store);
118
         storeService.save(store);
103
         return ResponseBean.success(store);
119
         return ResponseBean.success(store);
118
             return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
134
             return ResponseBean.error("当前名称重复", ResponseBean.ERROR_ILLEGAL_PARAMS);
119
         }
135
         }
120
 
136
 
137
+        if (null == store.getTypeId()) {
138
+            return ResponseBean.error("未选择分类", ResponseBean.ERROR_ILLEGAL_PARAMS);
139
+        }
140
+
141
+        StoreType storeType = storeTypeService.getById(store.getTypeId());
142
+        if (null == storeType) {
143
+            return ResponseBean.error("分类选择不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
144
+        }
145
+
146
+        store.setIsDish(storeType.getIsFood());
147
+        store.setIsDevice(storeType.getIsDevice());
148
+
121
         store.setId(id);
149
         store.setId(id);
122
         storeService.updateById(store);
150
         storeService.updateById(store);
123
         return ResponseBean.success(store);
151
         return ResponseBean.success(store);

+ 14
- 0
src/main/java/com/yunzhi/inte/controller/StoreLogController.java Wyświetl plik

13
 
13
 
14
 import com.yunzhi.inte.entity.Store;
14
 import com.yunzhi.inte.entity.Store;
15
 import com.yunzhi.inte.entity.Users;
15
 import com.yunzhi.inte.entity.Users;
16
+import com.yunzhi.inte.service.NoticeMessageService;
16
 import com.yunzhi.inte.service.StoreService;
17
 import com.yunzhi.inte.service.StoreService;
17
 import io.swagger.annotations.Api;
18
 import io.swagger.annotations.Api;
18
 import io.swagger.annotations.ApiOperation;
19
 import io.swagger.annotations.ApiOperation;
40
     @Autowired
41
     @Autowired
41
     private StoreService storeService;
42
     private StoreService storeService;
42
 
43
 
44
+    @Autowired
45
+    private NoticeMessageService noticeMessageService;
46
+
43
 //    /**
47
 //    /**
44
 //     * 通过ID查询单条数据
48
 //     * 通过ID查询单条数据
45
 //     *
49
 //     *
137
         Double amount = storeLog.getAmount();
141
         Double amount = storeLog.getAmount();
138
         Double leftAmount = preAmount;
142
         Double leftAmount = preAmount;
139
 
143
 
144
+        // 库存预警
145
+        boolean warn = false;
146
+        Double warnAmount = store.getWarnAmount() == null ? 1 : store.getWarnAmount();
147
+
140
         // 如果是盘点
148
         // 如果是盘点
141
         if ("fix".equals(storeLog.getOptType())) {
149
         if ("fix".equals(storeLog.getOptType())) {
142
             if (amount < 0) {
150
             if (amount < 0) {
144
             }
152
             }
145
 
153
 
146
             leftAmount = amount;
154
             leftAmount = amount;
155
+            warn = leftAmount <= warnAmount;
147
         } else {
156
         } else {
148
             if ("out".equals(storeLog.getOptType())) {
157
             if ("out".equals(storeLog.getOptType())) {
149
                 // 如果是出库
158
                 // 如果是出库
153
             }
162
             }
154
 
163
 
155
             leftAmount = amount + preAmount;
164
             leftAmount = amount + preAmount;
165
+            warn = leftAmount <= warnAmount;
156
 
166
 
157
             if (leftAmount < 0) {
167
             if (leftAmount < 0) {
158
                 return ResponseBean.error("库存不足", ResponseBean.ERROR_ILLEGAL_PARAMS);
168
                 return ResponseBean.error("库存不足", ResponseBean.ERROR_ILLEGAL_PARAMS);
169
         store.setAmount(leftAmount);
179
         store.setAmount(leftAmount);
170
         storeService.updateById(store);
180
         storeService.updateById(store);
171
 
181
 
182
+        if (warn) {
183
+            noticeMessageService.warnStore(store);
184
+        }
185
+
172
         return ResponseBean.success(storeLog);
186
         return ResponseBean.success(storeLog);
173
     }
187
     }
174
 //
188
 //

+ 42
- 22
src/main/java/com/yunzhi/inte/entity/NoticeMessage.java Wyświetl plik

5
 import com.baomidou.mybatisplus.annotation.IdType;
5
 import com.baomidou.mybatisplus.annotation.IdType;
6
 import com.baomidou.mybatisplus.annotation.TableName;
6
 import com.baomidou.mybatisplus.annotation.TableName;
7
 import com.baomidou.mybatisplus.annotation.TableId;
7
 import com.baomidou.mybatisplus.annotation.TableId;
8
+
8
 import java.io.Serializable;
9
 import java.io.Serializable;
10
+import java.time.LocalDateTime;
9
 import java.util.Date;
11
 import java.util.Date;
12
+
10
 import lombok.Data;
13
 import lombok.Data;
11
 import lombok.EqualsAndHashCode;
14
 import lombok.EqualsAndHashCode;
12
 import lombok.experimental.Accessors;
15
 import lombok.experimental.Accessors;
13
 
16
 
14
- /**
17
+/**
15
  * 消息表;
18
  * 消息表;
19
+ *
16
  * @author : http://www.chiner.pro
20
  * @author : http://www.chiner.pro
17
  * @date : 2022-10-13
21
  * @date : 2022-10-13
18
  */
22
  */
19
 @Data
23
 @Data
20
 @EqualsAndHashCode(callSuper = false)
24
 @EqualsAndHashCode(callSuper = false)
21
 @Accessors(chain = true)
25
 @Accessors(chain = true)
22
-@ApiModel(value = "消息表",description = "")
26
+@ApiModel(value = "消息表", description = "")
23
 @TableName("notice_message")
27
 @TableName("notice_message")
24
-public class NoticeMessage implements Serializable,Cloneable{
25
-    /** 消息ID */
26
-    @ApiModelProperty(name = "消息ID",notes = "")
27
-    @TableId(value = "id", type = IdType.INPUT)
28
-    private Integer id ;
29
-    /** 消息内容 */
30
-    @ApiModelProperty(name = "消息内容",notes = "")
31
-    private String message ;
32
-    /** 对象类型 */
33
-    @ApiModelProperty(name = "对象类型",notes = "")
34
-    private String targetType ;
35
-    /** 对象ID */
36
-    @ApiModelProperty(name = "对象ID",notes = "")
37
-    private String targetId ;
38
-    /** 状态 */
39
-    @ApiModelProperty(name = "状态",notes = "")
40
-    private Integer status ;
41
-    /** 创建时间 */
42
-    @ApiModelProperty(name = "创建时间",notes = "")
43
-    private Date createDate ;
28
+public class NoticeMessage implements Serializable, Cloneable {
29
+    /**
30
+     * 消息ID
31
+     */
32
+    @ApiModelProperty(name = "消息ID", notes = "")
33
+    @TableId(value = "id", type = IdType.AUTO)
34
+    private Integer id;
35
+    /**
36
+     * 消息内容
37
+     */
38
+    @ApiModelProperty(name = "消息内容", notes = "")
39
+    private String message;
40
+    /**
41
+     * 对象类型
42
+     */
43
+    @ApiModelProperty(name = "对象类型", notes = "")
44
+    private String targetType;
45
+    /**
46
+     * 对象ID
47
+     */
48
+    @ApiModelProperty(name = "对象ID", notes = "")
49
+    private String targetId;
50
+
51
+    @ApiModelProperty(name = "是否已读", notes = "")
52
+    private Boolean isReaded;
53
+
54
+    /**
55
+     * 状态
56
+     */
57
+    @ApiModelProperty(name = "状态", notes = "")
58
+    private Integer status;
59
+    /**
60
+     * 创建时间
61
+     */
62
+    @ApiModelProperty(name = "创建时间", notes = "")
63
+    private LocalDateTime createDate;
44
 
64
 
45
 }
65
 }

+ 10
- 1
src/main/java/com/yunzhi/inte/entity/Store.java Wyświetl plik

47
     @ExcelProperty(value = "库存量", index = 3)
47
     @ExcelProperty(value = "库存量", index = 3)
48
     @ApiModelProperty(name = "库存量",notes = "")
48
     @ApiModelProperty(name = "库存量",notes = "")
49
     private Double amount ;
49
     private Double amount ;
50
+
51
+    @ExcelIgnore
52
+    @ApiModelProperty(name = "预警库存",notes = "")
53
+    private Double warnAmount ;
54
+
50
     /** 单位 */
55
     /** 单位 */
51
     @ExcelProperty(value = "单位", index = 1)
56
     @ExcelProperty(value = "单位", index = 1)
52
     @ApiModelProperty(name = "单位",notes = "")
57
     @ApiModelProperty(name = "单位",notes = "")
53
     private String unit ;
58
     private String unit ;
54
 
59
 
55
-
56
     /** 是否食材 */
60
     /** 是否食材 */
57
     @ExcelIgnore
61
     @ExcelIgnore
58
     @ApiModelProperty(name = "是否食材",notes = "")
62
     @ApiModelProperty(name = "是否食材",notes = "")
59
     private Integer isDish;
63
     private Integer isDish;
60
 
64
 
65
+    @ExcelIgnore
66
+    @ApiModelProperty(name = "是否设备",notes = "1是0否")
67
+    private Integer isDevice ;
68
+
61
     /** 状态 */
69
     /** 状态 */
62
     @ExcelIgnore
70
     @ExcelIgnore
63
     @ApiModelProperty(name = "状态",notes = "")
71
     @ApiModelProperty(name = "状态",notes = "")
64
     private Integer status ;
72
     private Integer status ;
73
+
65
     /** 创建时间 */
74
     /** 创建时间 */
66
     @ExcelIgnore
75
     @ExcelIgnore
67
     @ApiModelProperty(name = "创建时间",notes = "")
76
     @ApiModelProperty(name = "创建时间",notes = "")

+ 3
- 0
src/main/java/com/yunzhi/inte/entity/StoreType.java Wyświetl plik

32
     /** 是否食材;1是0否 */
32
     /** 是否食材;1是0否 */
33
     @ApiModelProperty(name = "是否食材",notes = "1是0否")
33
     @ApiModelProperty(name = "是否食材",notes = "1是0否")
34
     private Integer isFood ;
34
     private Integer isFood ;
35
+    /** 是否食材;1是0否 */
36
+    @ApiModelProperty(name = "是否设备",notes = "1是0否")
37
+    private Integer isDevice ;
35
     /** 状态 */
38
     /** 状态 */
36
     @ApiModelProperty(name = "状态",notes = "")
39
     @ApiModelProperty(name = "状态",notes = "")
37
     private Integer status ;
40
     private Integer status ;

+ 5
- 3
src/main/java/com/yunzhi/inte/service/NoticeMessageService.java Wyświetl plik

2
 
2
 
3
 import com.baomidou.mybatisplus.extension.service.IService;
3
 import com.baomidou.mybatisplus.extension.service.IService;
4
 import com.yunzhi.inte.entity.NoticeMessage;
4
 import com.yunzhi.inte.entity.NoticeMessage;
5
+import com.yunzhi.inte.entity.Store;
5
 
6
 
6
- /**
7
+/**
7
  * 消息表;(notice_message)表服务接口
8
  * 消息表;(notice_message)表服务接口
8
  * @author : http://njyunzhi.com
9
  * @author : http://njyunzhi.com
9
  * @date : 2022-10-13
10
  * @date : 2022-10-13
10
  */
11
  */
11
 public interface NoticeMessageService extends IBaseService<NoticeMessage> {
12
 public interface NoticeMessageService extends IBaseService<NoticeMessage> {
12
-    
13
-}
13
+
14
+     void warnStore(Store store);
15
+ }

+ 25
- 2
src/main/java/com/yunzhi/inte/service/impl/NoticeMessageServiceImpl.java Wyświetl plik

1
 package com.yunzhi.inte.service.impl;
1
 package com.yunzhi.inte.service.impl;
2
 
2
 
3
+import com.yunzhi.inte.common.Constants;
4
+import com.yunzhi.inte.entity.Store;
3
 import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.scheduling.annotation.Async;
4
 import org.springframework.stereotype.Service;
7
 import org.springframework.stereotype.Service;
5
 import com.yunzhi.inte.entity.NoticeMessage;
8
 import com.yunzhi.inte.entity.NoticeMessage;
6
 import com.yunzhi.inte.mapper.NoticeMessageMapper;
9
 import com.yunzhi.inte.mapper.NoticeMessageMapper;
7
 import com.yunzhi.inte.service.NoticeMessageService;
10
 import com.yunzhi.inte.service.NoticeMessageService;
8
- /**
11
+
12
+import java.time.LocalDateTime;
13
+
14
+/**
9
  * 消息表;(notice_message)表服务实现类
15
  * 消息表;(notice_message)表服务实现类
16
+ *
10
  * @author : http://www.chiner.pro
17
  * @author : http://www.chiner.pro
11
  * @date : 2022-10-13
18
  * @date : 2022-10-13
12
  */
19
  */
13
 @Service
20
 @Service
14
 public class NoticeMessageServiceImpl extends BaseServiceImpl<NoticeMessageMapper, NoticeMessage> implements NoticeMessageService {
21
 public class NoticeMessageServiceImpl extends BaseServiceImpl<NoticeMessageMapper, NoticeMessage> implements NoticeMessageService {
15
-    
22
+
23
+    @Override
24
+    @Async
25
+    public void warnStore(Store store) {
26
+        try {
27
+            NoticeMessage noticeMessage = new NoticeMessage();
28
+            noticeMessage.setMessage(String.format("物资【%s】库存不足, 请及时补仓", store.getName()));
29
+            noticeMessage.setTargetId(store.getId().toString());
30
+            noticeMessage.setTargetType("store");
31
+            noticeMessage.setIsReaded(false);
32
+            noticeMessage.setStatus(Constants.STATUS_NORMAL);
33
+            noticeMessage.setCreateDate(LocalDateTime.now());
34
+            save(noticeMessage);
35
+        } catch (Exception e) {
36
+            e.printStackTrace();
37
+        }
38
+    }
16
 }
39
 }

+ 106
- 105
src/main/java/com/yunzhi/inte/service/impl/UsersServiceImpl.java Wyświetl plik

20
 
20
 
21
 /**
21
 /**
22
  * 用户表;(users)表服务实现类
22
  * 用户表;(users)表服务实现类
23
+ *
23
  * @author : http://www.chiner.pro
24
  * @author : http://www.chiner.pro
24
  * @date : 2022-10-12
25
  * @date : 2022-10-12
25
  */
26
  */
30
     UserRolesMapper userRolesMapper;
31
     UserRolesMapper userRolesMapper;
31
 
32
 
32
 
33
 
33
-      @Override
34
-      public Users login(LoginParm loginParm) throws Exception {
35
-          Users sysUser = baseMapper.getByLoginID(loginParm.getUserName());
36
-          if (null == sysUser) {
37
-              throw new Exception("用户名或者密码不正确");
38
-          }
39
-
40
-          boolean isRight = checkPassword(loginParm.getPassword(), sysUser.getPassword(), sysUser.getId().toString());
41
-          if (!isRight) {
42
-              throw new Exception("用户名或者密码不正确");
43
-          }
44
-
45
-          sysUser.setPassword(null);
46
-          return sysUser;
47
-      }
48
-
49
-     @Override
50
-     @Transactional(rollbackFor = Exception.class)
51
-     public boolean mergeData(Users users) throws Exception {
52
-         if (StringUtils.isEmpty(users.getName())) {
53
-             throw new Exception("采购计划名称不能为空");
54
-         }
55
-
56
-         LocalDateTime now = LocalDateTime.now();
57
-
58
-         // 用户表
59
-         Integer userId = users.getId();
60
-         if (null == userId) {
61
-             Users origin = getExistBy("name", users.getName(), false, true);
62
-             if (null != origin) {
63
-                 throw new Exception("名称重复");
64
-             }
65
-
66
-             if (!StringUtils.isEmpty(users.getPhone())) {
67
-                 Users origin2 = getExistBy("phone", users.getPhone(), false, true);
68
-                 if (null != origin2) {
69
-                     throw new Exception("手机号重复");
70
-                 }
71
-             }
72
-
73
-             if (null == users.getStatus()) {
74
-                 users.setStatus(Constants.STATUS_NORMAL);
75
-             }
76
-
77
-             users.setCreateDate(now);
78
-             save(users);
79
-             userId = users.getId();
80
-         } else {
81
-             Users origin = getByButNot("name", users.getName(), "id", userId, true);
82
-             if (null != origin) {
83
-                 throw new Exception("名称重复");
84
-             }
85
-
86
-             if (!StringUtils.isEmpty(users.getPhone())) {
87
-                 Users origin2 = getByButNot("phone", users.getPhone(), "id", userId, true);
88
-                 if (null != origin2) {
89
-                     throw new Exception("手机号重复");
90
-                 }
91
-             }
92
-
93
-             //
94
-             updateById(users);
95
-         }
96
-
97
-         // 如果密码不为空, 说明修改了密码
98
-         if (!StringUtils.isEmpty(users.getPassword())) {
99
-             users.setPassword(EncryptUtils.md5(users.getPassword(), users.getId().toString()));
100
-             updateById(users);
101
-         }
102
-
103
-         // 授权角色
104
-         List<Roles> rolesList = users.getRolesList();
105
-         if (null == rolesList || rolesList.size() == 0) {
106
-             userRolesMapper.deleteByMap(new HashMap<String, Object>(){{
107
-                 put("user_id", users.getId());
108
-             }});
109
-         } else {
110
-             List<Integer> idList = new ArrayList<>();
111
-             for (Roles role : rolesList) {
112
-                 UserRoles item = new UserRoles();
113
-                 item.setUserId(users.getId());
114
-                 item.setRoleId(role.getId());
115
-
116
-                 UserRoles exists = userRolesMapper.getByUserAndRole(users.getId(), role.getId());
117
-                 if (null != exists) {
118
-                     item.setId(exists.getId());
119
-                 } else {
120
-                     userRolesMapper.insert(item);
121
-                 }
122
-
123
-                 idList.add(item.getId());
124
-             }
125
-
126
-             // 去除垃圾数据
127
-             userRolesMapper.deleteNotIn(users.getId(), idList);
128
-         }
129
-
130
-         return true;
131
-     }
132
-
133
-     boolean checkPassword(String src, String targ, String salt) {
134
-         String newPass = EncryptUtils.md5(src, salt);
135
-         return targ.equals(newPass);
136
-     }
137
- }
34
+    @Override
35
+    public Users login(LoginParm loginParm) throws Exception {
36
+        Users sysUser = baseMapper.getByLoginID(loginParm.getUserName());
37
+        if (null == sysUser) {
38
+            throw new Exception("用户名或者密码不正确");
39
+        }
40
+
41
+        boolean isRight = checkPassword(loginParm.getPassword(), sysUser.getPassword(), sysUser.getId().toString());
42
+        if (!isRight) {
43
+            throw new Exception("用户名或者密码不正确");
44
+        }
45
+
46
+        sysUser.setPassword(null);
47
+        return sysUser;
48
+    }
49
+
50
+    @Override
51
+    @Transactional(rollbackFor = Exception.class)
52
+    public boolean mergeData(Users users) throws Exception {
53
+        if (StringUtils.isEmpty(users.getName())) {
54
+            throw new Exception("采购计划名称不能为空");
55
+        }
56
+
57
+        LocalDateTime now = LocalDateTime.now();
58
+
59
+        // 用户表
60
+        Integer userId = users.getId();
61
+        if (null == userId) {
62
+            Users origin = getExistBy("name", users.getName(), false, true);
63
+            if (null != origin) {
64
+                throw new Exception("名称重复");
65
+            }
66
+
67
+            if (!StringUtils.isEmpty(users.getPhone())) {
68
+                Users origin2 = getExistBy("phone", users.getPhone(), false, true);
69
+                if (null != origin2) {
70
+                    throw new Exception("手机号重复");
71
+                }
72
+            }
73
+
74
+            if (null == users.getStatus()) {
75
+                users.setStatus(Constants.STATUS_NORMAL);
76
+            }
77
+
78
+            users.setCreateDate(now);
79
+            save(users);
80
+            userId = users.getId();
81
+        } else {
82
+            Users origin = getByButNot("name", users.getName(), "id", userId, true);
83
+            if (null != origin) {
84
+                throw new Exception("名称重复");
85
+            }
86
+
87
+            if (!StringUtils.isEmpty(users.getPhone())) {
88
+                Users origin2 = getByButNot("phone", users.getPhone(), "id", userId, true);
89
+                if (null != origin2) {
90
+                    throw new Exception("手机号重复");
91
+                }
92
+            }
93
+
94
+            //
95
+            updateById(users);
96
+        }
97
+
98
+        // 如果密码不为空, 说明修改了密码
99
+        if (!StringUtils.isEmpty(users.getPassword())) {
100
+            users.setPassword(EncryptUtils.md5(users.getPassword(), users.getId().toString()));
101
+            updateById(users);
102
+        }
103
+
104
+        // 授权角色
105
+        List<Roles> rolesList = users.getRolesList();
106
+        if (null == rolesList || rolesList.size() == 0) {
107
+            userRolesMapper.deleteByMap(new HashMap<String, Object>() {{
108
+                put("user_id", users.getId());
109
+            }});
110
+        } else {
111
+            List<Integer> idList = new ArrayList<>();
112
+            for (Roles role : rolesList) {
113
+                UserRoles item = new UserRoles();
114
+                item.setUserId(users.getId());
115
+                item.setRoleId(role.getId());
116
+
117
+                UserRoles exists = userRolesMapper.getByUserAndRole(users.getId(), role.getId());
118
+                if (null != exists) {
119
+                    item.setId(exists.getId());
120
+                } else {
121
+                    userRolesMapper.insert(item);
122
+                }
123
+
124
+                idList.add(item.getId());
125
+            }
126
+
127
+            // 去除垃圾数据
128
+            userRolesMapper.deleteNotIn(users.getId(), idList);
129
+        }
130
+
131
+        return true;
132
+    }
133
+
134
+    boolean checkPassword(String src, String targ, String salt) {
135
+        String newPass = EncryptUtils.md5(src, salt);
136
+        return targ.equals(newPass);
137
+    }
138
+}