Yansen 2 年 前
コミット
2a8bc8aa66

+ 33
- 28
src/main/java/com/yunzhi/inte/controller/NoticeMessageController.java ファイルの表示

@@ -59,43 +59,48 @@ public class NoticeMessageController extends BaseController {
59 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 79
      * @return 实例对象
80 80
      */
81 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 90
         noticeMessageService.updateById(noticeMessage);
86 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 ファイルの表示

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

+ 28
- 0
src/main/java/com/yunzhi/inte/controller/StoreController.java ファイルの表示

@@ -7,6 +7,8 @@ import com.yunzhi.inte.common.*;
7 7
 
8 8
 import java.util.List;
9 9
 
10
+import com.yunzhi.inte.entity.StoreType;
11
+import com.yunzhi.inte.service.StoreTypeService;
10 12
 import io.swagger.annotations.Api;
11 13
 import io.swagger.annotations.ApiOperation;
12 14
 import io.swagger.annotations.ApiParam;
@@ -30,6 +32,9 @@ public class StoreController extends BaseController {
30 32
     @Autowired
31 33
     private StoreService storeService;
32 34
 
35
+    @Autowired
36
+    private StoreTypeService storeTypeService;
37
+
33 38
     /**
34 39
      * 通过ID查询单条数据
35 40
      *
@@ -98,6 +103,17 @@ public class StoreController extends BaseController {
98 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 117
         store.setStatus(Constants.STATUS_NORMAL);
102 118
         storeService.save(store);
103 119
         return ResponseBean.success(store);
@@ -118,6 +134,18 @@ public class StoreController extends BaseController {
118 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 149
         store.setId(id);
122 150
         storeService.updateById(store);
123 151
         return ResponseBean.success(store);

+ 14
- 0
src/main/java/com/yunzhi/inte/controller/StoreLogController.java ファイルの表示

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

+ 42
- 22
src/main/java/com/yunzhi/inte/entity/NoticeMessage.java ファイルの表示

@@ -5,41 +5,61 @@ import io.swagger.annotations.ApiModelProperty;
5 5
 import com.baomidou.mybatisplus.annotation.IdType;
6 6
 import com.baomidou.mybatisplus.annotation.TableName;
7 7
 import com.baomidou.mybatisplus.annotation.TableId;
8
+
8 9
 import java.io.Serializable;
10
+import java.time.LocalDateTime;
9 11
 import java.util.Date;
12
+
10 13
 import lombok.Data;
11 14
 import lombok.EqualsAndHashCode;
12 15
 import lombok.experimental.Accessors;
13 16
 
14
- /**
17
+/**
15 18
  * 消息表;
19
+ *
16 20
  * @author : http://www.chiner.pro
17 21
  * @date : 2022-10-13
18 22
  */
19 23
 @Data
20 24
 @EqualsAndHashCode(callSuper = false)
21 25
 @Accessors(chain = true)
22
-@ApiModel(value = "消息表",description = "")
26
+@ApiModel(value = "消息表", description = "")
23 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 ファイルの表示

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

+ 3
- 0
src/main/java/com/yunzhi/inte/entity/StoreType.java ファイルの表示

@@ -32,6 +32,9 @@ public class StoreType implements Serializable,Cloneable{
32 32
     /** 是否食材;1是0否 */
33 33
     @ApiModelProperty(name = "是否食材",notes = "1是0否")
34 34
     private Integer isFood ;
35
+    /** 是否食材;1是0否 */
36
+    @ApiModelProperty(name = "是否设备",notes = "1是0否")
37
+    private Integer isDevice ;
35 38
     /** 状态 */
36 39
     @ApiModelProperty(name = "状态",notes = "")
37 40
     private Integer status ;

+ 5
- 3
src/main/java/com/yunzhi/inte/service/NoticeMessageService.java ファイルの表示

@@ -2,12 +2,14 @@ package com.yunzhi.inte.service;
2 2
 
3 3
 import com.baomidou.mybatisplus.extension.service.IService;
4 4
 import com.yunzhi.inte.entity.NoticeMessage;
5
+import com.yunzhi.inte.entity.Store;
5 6
 
6
- /**
7
+/**
7 8
  * 消息表;(notice_message)表服务接口
8 9
  * @author : http://njyunzhi.com
9 10
  * @date : 2022-10-13
10 11
  */
11 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 ファイルの表示

@@ -1,16 +1,39 @@
1 1
 package com.yunzhi.inte.service.impl;
2 2
 
3
+import com.yunzhi.inte.common.Constants;
4
+import com.yunzhi.inte.entity.Store;
3 5
 import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.scheduling.annotation.Async;
4 7
 import org.springframework.stereotype.Service;
5 8
 import com.yunzhi.inte.entity.NoticeMessage;
6 9
 import com.yunzhi.inte.mapper.NoticeMessageMapper;
7 10
 import com.yunzhi.inte.service.NoticeMessageService;
8
- /**
11
+
12
+import java.time.LocalDateTime;
13
+
14
+/**
9 15
  * 消息表;(notice_message)表服务实现类
16
+ *
10 17
  * @author : http://www.chiner.pro
11 18
  * @date : 2022-10-13
12 19
  */
13 20
 @Service
14 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 ファイルの表示

@@ -20,6 +20,7 @@ import java.util.List;
20 20
 
21 21
 /**
22 22
  * 用户表;(users)表服务实现类
23
+ *
23 24
  * @author : http://www.chiner.pro
24 25
  * @date : 2022-10-12
25 26
  */
@@ -30,108 +31,108 @@ public class UsersServiceImpl extends BaseServiceImpl<UsersMapper, Users> implem
30 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
+}