张涛 1 年之前
父節點
當前提交
b59f2fbeb9

+ 7
- 1
application/src/main/java/com/lyg/application/controller/TaMessageController.java 查看文件

44
     public SaResult queryById(@ApiParam("对象ID") @PathVariable String id) throws Exception {
44
     public SaResult queryById(@ApiParam("对象ID") @PathVariable String id) throws Exception {
45
         TaMessage taMessage = taMessageService.getById(id);
45
         TaMessage taMessage = taMessageService.getById(id);
46
 
46
 
47
+
48
+        System.out.println("checkAuth()" + checkAuth());
47
         Boolean b = checkAuth() == null || checkAuth() == taMessage.getCreateUser();
49
         Boolean b = checkAuth() == null || checkAuth() == taMessage.getCreateUser();
48
 
50
 
49
         if (b) {
51
         if (b) {
50
-            SaResult.data(taMessageService.getById(id));
52
+            return SaResult.data(taMessageService.getById(id));
51
         }
53
         }
52
         return SaResult.error("无权限");
54
         return SaResult.error("无权限");
53
     }
55
     }
65
     @GetMapping("/taMessage")
67
     @GetMapping("/taMessage")
66
     public SaResult list(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
68
     public SaResult list(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
67
                          @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
69
                          @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
70
+                         @ApiParam("来源表") @RequestParam(value = "sourceName", required = false) String sourceName,
71
+                         @ApiParam("内容") @RequestParam(value = "contentSent", required = false) String contentSent,
68
                          @ApiParam("正序排列") @RequestParam(value = "sortAsc", required = false) String sortAsc,
72
                          @ApiParam("正序排列") @RequestParam(value = "sortAsc", required = false) String sortAsc,
69
                          @ApiParam("倒序排列") @RequestParam(value = "sortDesc", defaultValue = "create_date") String sortDesc) throws Exception {
73
                          @ApiParam("倒序排列") @RequestParam(value = "sortDesc", defaultValue = "create_date") String sortDesc) throws Exception {
70
 
74
 
71
         IPage<TaMessage> pg = new Page<>(pageNum, pageSize);
75
         IPage<TaMessage> pg = new Page<>(pageNum, pageSize);
72
         QueryWrapper<TaMessage> queryWrapper = new QueryWrapper<>();
76
         QueryWrapper<TaMessage> queryWrapper = new QueryWrapper<>();
73
         queryWrapper.eq(StringUtil.isNotEmpty(checkAuth()), "CREATE_USER", checkAuth());
77
         queryWrapper.eq(StringUtil.isNotEmpty(checkAuth()), "CREATE_USER", checkAuth());
78
+        queryWrapper.eq(StringUtil.isNotEmpty(sourceName), "SOURCE_NAME", sourceName);
79
+        queryWrapper.like(StringUtil.isNotEmpty(contentSent), "content_sent", contentSent);
74
         queryWrapper.orderByAsc(StringUtil.isNotEmpty(sortAsc), StringUtil.humpToLine(sortAsc));
80
         queryWrapper.orderByAsc(StringUtil.isNotEmpty(sortAsc), StringUtil.humpToLine(sortAsc));
75
         queryWrapper.orderByDesc(StringUtil.isNotEmpty(sortDesc), StringUtil.humpToLine(sortDesc));
81
         queryWrapper.orderByDesc(StringUtil.isNotEmpty(sortDesc), StringUtil.humpToLine(sortDesc));
76
         IPage<TaMessage> result = taMessageService.page(pg, queryWrapper);
82
         IPage<TaMessage> result = taMessageService.page(pg, queryWrapper);

+ 1
- 1
application/src/main/java/com/lyg/application/controller/TaSendingController.java 查看文件

46
 
46
 
47
         Boolean b = checkAuth() == null || checkAuth() == taSending.getCreateUser();
47
         Boolean b = checkAuth() == null || checkAuth() == taSending.getCreateUser();
48
         if (b) {
48
         if (b) {
49
-            SaResult.data(taSendingService.getById(id));
49
+            return SaResult.data(taSendingService.getById(id));
50
         }
50
         }
51
         return SaResult.error("无权限");
51
         return SaResult.error("无权限");
52
 
52
 

+ 0
- 1
application/src/main/java/com/lyg/application/job/TotationJobTime.java 查看文件

24
     @AccessLimit()
24
     @AccessLimit()
25
     @Scheduled(cron = "0 0 8 * * *")
25
     @Scheduled(cron = "0 0 8 * * *")
26
     public void promptWarning() throws Exception {
26
     public void promptWarning() throws Exception {
27
-
28
         taRotationService.selectGetWaring();
27
         taRotationService.selectGetWaring();
29
 
28
 
30
     }
29
     }

+ 4
- 0
application/src/main/java/com/lyg/application/mapper/TaMessageMapper.java 查看文件

3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
 import com.lyg.application.entity.TaMessage;
4
 import com.lyg.application.entity.TaMessage;
5
 import org.apache.ibatis.annotations.Mapper;
5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.Map;
6
 
9
 
7
 /**
10
 /**
8
  * 消息表;(ta_massage)表数据库访问层
11
  * 消息表;(ta_massage)表数据库访问层
13
 @Mapper
16
 @Mapper
14
 public interface TaMessageMapper extends BaseMapper<TaMessage> {
17
 public interface TaMessageMapper extends BaseMapper<TaMessage> {
15
 
18
 
19
+    void updateBySourceId(@Param("id") String leaveId, @Param("params") Map<String, String> params);
16
 }
20
 }

+ 44
- 50
application/src/main/java/com/lyg/application/service/impl/TaMandatoryLeaveServiceImpl.java 查看文件

1
 package com.lyg.application.service.impl;
1
 package com.lyg.application.service.impl;
2
 
2
 
3
 import com.lyg.application.entity.TaMandatoryLeave;
3
 import com.lyg.application.entity.TaMandatoryLeave;
4
-import com.lyg.application.entity.TaMessage;
5
-import com.lyg.application.entity.TaSending;
6
 import com.lyg.application.mapper.TaMandatoryLeaveMapper;
4
 import com.lyg.application.mapper.TaMandatoryLeaveMapper;
7
 import com.lyg.application.mapper.TaMessageMapper;
5
 import com.lyg.application.mapper.TaMessageMapper;
8
 import com.lyg.application.mapper.TaSendingMapper;
6
 import com.lyg.application.mapper.TaSendingMapper;
9
 import com.lyg.application.service.TaMandatoryLeaveService;
7
 import com.lyg.application.service.TaMandatoryLeaveService;
10
 import com.lyg.application.service.TaMessageService;
8
 import com.lyg.application.service.TaMessageService;
11
-import com.lyg.common.util.StringUtil;
12
-import com.lyg.system.entity.SysUser;
9
+import com.lyg.application.util.MessageHandle;
13
 import com.lyg.system.mapper.SysPositionMapper;
10
 import com.lyg.system.mapper.SysPositionMapper;
14
 import com.lyg.system.mapper.SysUserMapper;
11
 import com.lyg.system.mapper.SysUserMapper;
15
 import com.lyg.system.service.SysOrgService;
12
 import com.lyg.system.service.SysOrgService;
22
 import java.time.LocalDate;
19
 import java.time.LocalDate;
23
 import java.util.ArrayList;
20
 import java.util.ArrayList;
24
 import java.util.List;
21
 import java.util.List;
22
+import java.util.function.Function;
25
 
23
 
26
 /**
24
 /**
27
  * 强制休假表;(ta_mandatory_leave)表服务实现类
25
  * 强制休假表;(ta_mandatory_leave)表服务实现类
32
 @Service
30
 @Service
33
 public class TaMandatoryLeaveServiceImpl extends BaseServiceImpl<TaMandatoryLeaveMapper, TaMandatoryLeave> implements TaMandatoryLeaveService {
31
 public class TaMandatoryLeaveServiceImpl extends BaseServiceImpl<TaMandatoryLeaveMapper, TaMandatoryLeave> implements TaMandatoryLeaveService {
34
     private final List<String> errorMessages = new ArrayList<>();
32
     private final List<String> errorMessages = new ArrayList<>();
33
+
34
+    private static final String MESSAGE_SOURCE_NAME = "taMandatoryLeave";
35
+    private static final String PROMPT_TYPE = "prompt";
36
+
35
     @Value("${yz.holidayTmp}")
37
     @Value("${yz.holidayTmp}")
36
     String holidayTmp;
38
     String holidayTmp;
39
+
37
     @Autowired
40
     @Autowired
38
     private SysOrgService sysOrgService;
41
     private SysOrgService sysOrgService;
39
     @Autowired
42
     @Autowired
49
     @Autowired
52
     @Autowired
50
     private SysUserMapper sysUserMapper;
53
     private SysUserMapper sysUserMapper;
51
 
54
 
55
+    @Autowired
56
+    private MessageHandle messageHandle;
57
+
52
     @Override
58
     @Override
53
     public TaMandatoryLeave handleEntity(TaMandatoryLeave entity, Integer index) throws Exception {
59
     public TaMandatoryLeave handleEntity(TaMandatoryLeave entity, Integer index) throws Exception {
54
 //校验验证
60
 //校验验证
114
     public void selectGetPrompt() {
120
     public void selectGetPrompt() {
115
         LocalDate localDate = LocalDate.now();
121
         LocalDate localDate = LocalDate.now();
116
 
122
 
117
-        List<TaMandatoryLeave> promptList = baseMapper.prompt(localDate);
118
-        Integer numI = 3;
119
-        Integer nameI = 8;
120
-
121
-        if (promptList.size() != 0) {
122
-            for (TaMandatoryLeave item : promptList) {
123
-                TaMessage taMessage = new TaMessage();
124
-                String uuid = StringUtil.UUID();
125
-                taMessage.setMessageId(uuid);
126
-                taMessage.setSourceId(item.getLeaveId());
127
-                StringBuilder sb = new StringBuilder(holidayTmp);
128
-                sb.insert(numI, item.getEmployeeNum());
129
-                Integer i = item.getEmployeeNum().length() + nameI;
130
-                sb.insert(i, item.getEmployeeName());
131
-                taMessage.setContentSent(sb.toString());
132
-                taMessage.setSourceName("taMandatoryLeave");
133
-                taMessage.setWaringType("prompt");
134
-
135
-
136
-                Long count = taMessageService.countBy("source_id", item.getLeaveId(), true);
137
-                if (count == 0) {
138
-                    taMessageMapper.insert(taMessage);
139
-                    insertIntoTaSending(item.getCreateUser(), uuid);
140
-                }
141
-
142
-            }
143
-        }
123
+//        messageHandle.handleMandatoryLeaves(localDate, holidayTmp, PROMPT_TYPE);
124
+        // 提示消息处理
125
+        messageHandle.handleMandatoryLeaves(localDate, holidayTmp, PROMPT_TYPE,MESSAGE_SOURCE_NAME, baseMapper::prompt);
126
+//        List<TaMandatoryLeave> promptList = baseMapper.prompt(localDate);
127
+//
128
+//        if (promptList.size() != 0) {
129
+//            for (TaMandatoryLeave item : promptList) {
130
+//                Map<String,String> params = new HashMap<>();
131
+//                TaMessage taMessage = new TaMessage();
132
+//                String uuid = StringUtil.UUID();
133
+//                taMessage.setMessageId(uuid);
134
+//                taMessage.setSourceId(item.getLeaveId());
135
+//                StringBuilder sb = new StringBuilder(holidayTmp);
136
+//                sb.insert(Constants.numI, item.getEmployeeNum());
137
+//                Integer i = item.getEmployeeNum().length() + Constants.nameI;
138
+//                sb.insert(i, item.getEmployeeName());
139
+//                taMessage.setContentSent(sb.toString());
140
+//                taMessage.setSourceName("taMandatoryLeave");
141
+//                taMessage.setWaringType("prompt");
142
+//                params.put("taMandatoryLeave","taMandatoryLeave");
143
+//                params.put("prompt","prompt");
144
+//                params.put("stringBuilder",sb.toString());
145
+//
146
+//
147
+//                Long count = taMessageService.countBy("source_id", item.getLeaveId(), true);
148
+//                if (count == 0) {
149
+//                    taMessageMapper.insert(taMessage);
150
+//                    insertIntoTaSending(item.getCreateUser(), uuid);
151
+//                }else{
152
+//                    taMessageMapper.updateBySourceId(item.getLeaveId(),params);
153
+//                }
154
+//
155
+//            }
156
+//        }
144
 
157
 
145
 
158
 
146
     }
159
     }
147
 
160
 
148
-    public void insertIntoTaSending(String createUser, String uuid) {
149
 
161
 
150
-        //                item.getCreateUser()  就是新增这个数据的人
151
-        //现在需要去重 创建人和管理员  是一个人只能往  Tasending插入一条数据否则是两条数据
152
-        SysUser sysUserAdmin = sysUserMapper.getAdmin(createUser);
153
-//                如果为空 就不是管理员创建的;
154
-        List<String> userIdList = new ArrayList<>();
155
-
156
-        if (sysUserAdmin == null) {
157
-            userIdList.add(createUser);
158
-        }
159
-        userIdList = sysUserMapper.allAdmin();
160
-        for (String it : userIdList) {
161
-            TaSending taSending = new TaSending();
162
-            taSending.setMessageId(uuid);
163
-            taSending.setRecipientId(it);
164
-            taSendingMapper.insert(taSending);
165
-        }
166
-
167
-    }
168
 }
162
 }

+ 65
- 78
application/src/main/java/com/lyg/application/service/impl/TaRotationServiceImpl.java 查看文件

1
 package com.lyg.application.service.impl;
1
 package com.lyg.application.service.impl;
2
 
2
 
3
-import com.lyg.application.entity.TaMessage;
4
 import com.lyg.application.entity.TaRotation;
3
 import com.lyg.application.entity.TaRotation;
5
-import com.lyg.application.entity.TaSending;
6
 import com.lyg.application.mapper.TaMessageMapper;
4
 import com.lyg.application.mapper.TaMessageMapper;
7
 import com.lyg.application.mapper.TaRotationMapper;
5
 import com.lyg.application.mapper.TaRotationMapper;
8
 import com.lyg.application.mapper.TaSendingMapper;
6
 import com.lyg.application.mapper.TaSendingMapper;
9
 import com.lyg.application.service.TaMessageService;
7
 import com.lyg.application.service.TaMessageService;
10
 import com.lyg.application.service.TaRotationService;
8
 import com.lyg.application.service.TaRotationService;
9
+import com.lyg.application.util.MessageHandle;
11
 import com.lyg.application.util.Rule;
10
 import com.lyg.application.util.Rule;
12
-import com.lyg.common.util.StringUtil;
13
-import com.lyg.system.entity.SysUser;
14
 import com.lyg.system.mapper.SysPositionMapper;
11
 import com.lyg.system.mapper.SysPositionMapper;
15
 import com.lyg.system.mapper.SysUserMapper;
12
 import com.lyg.system.mapper.SysUserMapper;
16
 import com.lyg.system.service.SysOrgService;
13
 import com.lyg.system.service.SysOrgService;
35
 
32
 
36
 public class TaRotationServiceImpl extends BaseServiceImpl<TaRotationMapper, TaRotation> implements TaRotationService {
33
 public class TaRotationServiceImpl extends BaseServiceImpl<TaRotationMapper, TaRotation> implements TaRotationService {
37
 
34
 
35
+    private static final String WARNING_TYPE = "waring";
36
+    private static final String PROMPT_TYPE = "prompt";
37
+    private static final String MESSAGE_SOURCE_NAME = "taRotation";
38
     private final List<Object> errorMessages = new ArrayList<>();
38
     private final List<Object> errorMessages = new ArrayList<>();
39
     @Autowired
39
     @Autowired
40
     Rule rule;
40
     Rule rule;
59
     @Autowired
59
     @Autowired
60
     private SysUserMapper sysUserMapper;
60
     private SysUserMapper sysUserMapper;
61
 
61
 
62
+    @Autowired
63
+    private MessageHandle messageHandle;
64
+
65
+
62
     public TaRotation handleEntity(TaRotation entity, Integer index) throws Exception {
66
     public TaRotation handleEntity(TaRotation entity, Integer index) throws Exception {
63
 //校验验证
67
 //校验验证
64
         System.out.println("******************************entity**************************************");
68
         System.out.println("******************************entity**************************************");
140
 
144
 
141
     @Override
145
     @Override
142
     public void selectGetWaring() {
146
     public void selectGetWaring() {
147
+//
148
+////预警 消息
149
+//        List<TaRotation> earlyWaringList = baseMapper.waring(localDate);
150
+//
151
+//        if (!earlyWaringList.isEmpty()) {
152
+//            for (TaRotation item : earlyWaringList) {
153
+//                TaMessage taMessage = new TaMessage();
154
+//                String uuid = StringUtil.UUID();
155
+//                taMessage.setMessageId(uuid);
156
+//                taMessage.setSourceId(item.getRotationId());
157
+//                StringBuilder sb = new StringBuilder(warningTmp);
158
+//                sb.insert(Constants.numI, item.getEmployeeNum());
159
+//                Integer i = item.getEmployeeNum().length() + Constants.nameI;
160
+//                sb.insert(i, item.getEmployeeName());
161
+//                taMessage.setContentSent(sb.toString());
162
+//                taMessage.setSourceName("taRotation");
163
+//                taMessage.setWaringType("waring");
164
+//
165
+//                Long count = taMessageService.countBy("source_id", item.getRotationId(), true);
166
+//                if (count == 0) {
167
+//                    taMessageMapper.insert(taMessage);
168
+//                    insertIntoTaSending(item.getCreateUser(), uuid);
169
+//                }
170
+//
171
+//            }
172
+//        }
173
+////提示消息
174
+//        List<TaRotation> earlyPromptList = baseMapper.prompt(localDate);
175
+//
176
+//        if (earlyPromptList.size() != 0) {
177
+//            for (TaRotation item : earlyPromptList) {
178
+//                TaMessage taMessage = new TaMessage();
179
+//                String uuid = StringUtil.UUID();
180
+//                taMessage.setMessageId(uuid);
181
+//                taMessage.setSourceId(item.getRotationId());
182
+//                StringBuilder sb = new StringBuilder(promptTmp);
183
+//                sb.insert(Constants.numI, item.getEmployeeNum());
184
+//                Integer i = item.getEmployeeNum().length() + Constants.nameI;
185
+//                sb.insert(i, item.getEmployeeName());
186
+//                taMessage.setContentSent(sb.toString());
187
+//                taMessage.setSourceName("taRotation");
188
+//                taMessage.setWaringType("prompt");
189
+//
190
+//                Long count = taMessageService.countBy("source_id", item.getRotationId(), true);
191
+//                if (count == 0) {
192
+//                    taMessageMapper.insert(taMessage);
193
+//                    insertIntoTaSending(item.getCreateUser(), uuid);
194
+//                }
195
+//
196
+//            }
197
+//        }
198
+
199
+//        return;
143
         LocalDate localDate = LocalDate.now();
200
         LocalDate localDate = LocalDate.now();
144
-        Integer numI = 3;
145
-        Integer nameI = 8;
146
-//预警 消息
147
-        List<TaRotation> earlyWaringList = baseMapper.waring(localDate);
148
-
149
-        if (earlyWaringList.size() != 0) {
150
-            for (TaRotation item : earlyWaringList) {
151
-                TaMessage taMessage = new TaMessage();
152
-                String uuid = StringUtil.UUID();
153
-                taMessage.setMessageId(uuid);
154
-                taMessage.setSourceId(item.getRotationId());
155
-                StringBuilder sb = new StringBuilder(warningTmp);
156
-                sb.insert(numI, item.getEmployeeNum());
157
-                Integer i = item.getEmployeeNum().length() + nameI;
158
-                sb.insert(i, item.getEmployeeName());
159
-                taMessage.setContentSent(sb.toString());
160
-                taMessage.setSourceName("taRotation");
161
-                taMessage.setWaringType("waring");
162
-
163
-                Long count = taMessageService.countBy("source_id", item.getRotationId(), true);
164
-                if (count == 0) {
165
-                    taMessageMapper.insert(taMessage);
166
-                    insertIntoTaSending(item.getCreateUser(), uuid);
167
-                }
168
-
169
-            }
170
-        }
171
-//提示消息
172
-        List<TaRotation> earlyPromptList = baseMapper.prompt(localDate);
173
-
174
-        if (earlyPromptList.size() != 0) {
175
-            for (TaRotation item : earlyPromptList) {
176
-                TaMessage taMessage = new TaMessage();
177
-                String uuid = StringUtil.UUID();
178
-                taMessage.setMessageId(uuid);
179
-                taMessage.setSourceId(item.getRotationId());
180
-                StringBuilder sb = new StringBuilder(promptTmp);
181
-                sb.insert(numI, item.getEmployeeNum());
182
-                Integer i = item.getEmployeeNum().length() + nameI;
183
-                sb.insert(i, item.getEmployeeName());
184
-                taMessage.setContentSent(sb.toString());
185
-                taMessage.setSourceName("taRotation");
186
-                taMessage.setWaringType("prompt");
187
-
188
-                Long count = taMessageService.countBy("source_id", item.getRotationId(), true);
189
-                if (count == 0) {
190
-                    taMessageMapper.insert(taMessage);
191
-                    insertIntoTaSending(item.getCreateUser(), uuid);
192
-                }
193
-
194
-            }
195
-        }
196
 
201
 
202
+        // 预警消息处理
203
+        messageHandle.handleMessages(localDate, warningTmp,WARNING_TYPE,MESSAGE_SOURCE_NAME ,baseMapper::waring);
197
 
204
 
198
-        return;
205
+        // 提示消息处理
206
+        messageHandle.handleMessages(localDate,promptTmp, PROMPT_TYPE, MESSAGE_SOURCE_NAME ,baseMapper::prompt);
199
     }
207
     }
200
 
208
 
201
-    public void insertIntoTaSending(String createUser, String uuid) {
202
-
203
-        //                item.getCreateUser()  就是新增这个数据的人
204
-        //现在需要去重 创建人和管理员  是一个人只能往  Tasending插入一条数据否则是两条数据
205
-        SysUser sysUserAdmin = sysUserMapper.getAdmin(createUser);
206
-//                如果为空 就不是管理员创建的;
207
-        List<String> userIdList = new ArrayList<>();
208
-
209
-        if (sysUserAdmin == null) {
210
-            userIdList.add(createUser);
211
-        }
212
-        userIdList = sysUserMapper.allAdmin();
213
-
214
-        for (String it : userIdList) {
215
-            TaSending taSending = new TaSending();
216
-            taSending.setMessageId(uuid);
217
-            taSending.setRecipientId(it);
218
-            taSendingMapper.insert(taSending);
219
-        }
220
-
221
-    }
222
 
209
 
223
     public List<Object> getErrorMessages() {
210
     public List<Object> getErrorMessages() {
224
         return errorMessages;
211
         return errorMessages;

+ 164
- 0
application/src/main/java/com/lyg/application/util/MessageHandle.java 查看文件

1
+package com.lyg.application.util;
2
+
3
+import com.lyg.application.entity.TaMandatoryLeave;
4
+import com.lyg.application.entity.TaMessage;
5
+import com.lyg.application.entity.TaRotation;
6
+import com.lyg.application.entity.TaSending;
7
+import com.lyg.application.mapper.TaMandatoryLeaveMapper;
8
+import com.lyg.application.mapper.TaMessageMapper;
9
+import com.lyg.application.mapper.TaSendingMapper;
10
+import com.lyg.application.service.TaMessageService;
11
+import com.lyg.common.Constants;
12
+import com.lyg.common.util.StringUtil;
13
+import com.lyg.system.entity.SysUser;
14
+import com.lyg.system.mapper.SysUserMapper;
15
+import org.springframework.beans.factory.annotation.Autowired;
16
+import org.springframework.stereotype.Component;
17
+
18
+import java.time.LocalDate;
19
+import java.util.ArrayList;
20
+import java.util.HashMap;
21
+import java.util.List;
22
+import java.util.Map;
23
+import java.util.function.Function;
24
+
25
+@Component
26
+public class MessageHandle {
27
+
28
+    private static final String MESSAGE_SOURCE_NAME = "taRotation";
29
+
30
+
31
+    @Autowired
32
+    private TaMessageService taMessageService;
33
+    @Autowired
34
+    private TaMessageMapper taMessageMapper;
35
+    @Autowired
36
+    private SysUserMapper sysUserMapper;
37
+    @Autowired
38
+    private TaSendingMapper taSendingMapper;
39
+
40
+    @Autowired
41
+    private TaMandatoryLeaveMapper taMandatoryLeaveMapper;
42
+
43
+    /**
44
+     * 处理消息的通用逻辑
45
+     *
46
+     * @param localDate        日期
47
+     * @param messageType      消息类型
48
+     * @param dataFetchingFunc 数据获取的函数
49
+     */
50
+    public void handleMessages(LocalDate localDate, String tmp, String messageType, String sourceName, Function<LocalDate, List<TaRotation>> dataFetchingFunc) {
51
+        List<TaRotation> messageList = dataFetchingFunc.apply(localDate);
52
+
53
+        if (!messageList.isEmpty()) {
54
+            // 在循环外初始化StringBuilder
55
+
56
+            for (TaRotation item : messageList) {
57
+                processItem(item, tmp, messageType, sourceName);
58
+            }
59
+        }
60
+    }
61
+
62
+
63
+    /**
64
+     * 处理每个项目的消息逻辑
65
+     *
66
+     * @param item        数据项
67
+     * @param messageType 消息类型
68
+     */
69
+    private void processItem(TaRotation item, String tmp, String messageType, String sourceName) {
70
+        StringBuilder stringBuilder = new StringBuilder();
71
+        TaMessage taMessage = new TaMessage();
72
+        Map<String, String> params = new HashMap<>();
73
+
74
+
75
+        String uuid = StringUtil.UUID();
76
+        taMessage.setMessageId(uuid);
77
+        taMessage.setSourceId(item.getRotationId());
78
+
79
+        // 使用描述性强的常量代替硬编码值
80
+        stringBuilder.append(tmp); // 假设warningTmp或promptTmp已经定义且包含插入点
81
+        stringBuilder.insert(Constants.numI, item.getEmployeeNum());
82
+        int insertPos = Constants.numI + item.getEmployeeNum().length() + Constants.nameI;
83
+        stringBuilder.insert(insertPos, item.getEmployeeName());
84
+        taMessage.setContentSent(stringBuilder.toString());
85
+        taMessage.setSourceName(sourceName);
86
+        taMessage.setWaringType(messageType);
87
+        params.put("sourceName", sourceName);
88
+        params.put("waringType", messageType);
89
+        params.put("contentSent", stringBuilder.toString());
90
+        Long count = taMessageService.countBy("source_id", item.getRotationId(), true);
91
+        if (count == 0) {
92
+            taMessageMapper.insert(taMessage);
93
+            insertIntoTaSending(item.getCreateUser(), uuid);
94
+        } else {
95
+            taMessageMapper.updateBySourceId(item.getRotationId(), params);
96
+        }
97
+    }
98
+
99
+
100
+    public void handleMandatoryLeaves(LocalDate localDate, String tmp, String messageType, String sourceName, Function<LocalDate, List<TaMandatoryLeave>> dataFetchingFunc) {
101
+        List<TaMandatoryLeave> messageList = dataFetchingFunc.apply(localDate);
102
+
103
+        if (!messageList.isEmpty()) {
104
+
105
+            for (TaMandatoryLeave item : messageList) {
106
+                processItemLeaves(item, tmp, messageType, sourceName);
107
+            }
108
+        }
109
+    }
110
+
111
+    private void processItemLeaves(TaMandatoryLeave item, String tmp, String messageType, String sourceName) {
112
+        StringBuilder stringBuilder = new StringBuilder();
113
+        TaMessage taMessage = new TaMessage();
114
+        Map<String, String> params = new HashMap<>();
115
+
116
+        String uuid = StringUtil.UUID();
117
+        taMessage.setMessageId(uuid);
118
+        taMessage.setSourceId(item.getLeaveId());
119
+
120
+        // 使用描述性强的常量代替硬编码值
121
+        stringBuilder.append(tmp); // 假设warningTmp或promptTmp已经定义且包含插入点
122
+        stringBuilder.insert(Constants.numI, item.getEmployeeNum());
123
+        int insertPos = Constants.numI + item.getEmployeeNum().length() + Constants.nameI;
124
+        stringBuilder.insert(insertPos, item.getEmployeeName());
125
+        taMessage.setContentSent(stringBuilder.toString());
126
+        taMessage.setSourceName(sourceName);
127
+        taMessage.setWaringType(messageType);
128
+        params.put("sourceName", "taMandatoryLeave");
129
+        params.put("waringType", "prompt");
130
+        params.put("contentSent", stringBuilder.toString());
131
+        Long count = taMessageService.countBy("source_id", item.getLeaveId(), true);
132
+        if (count == 0) {
133
+            taMessageMapper.insert(taMessage);
134
+            insertIntoTaSending(item.getCreateUser(), uuid);
135
+        } else {
136
+            taMessageMapper.updateBySourceId(item.getLeaveId(), params);
137
+        }
138
+    }
139
+
140
+
141
+    public void insertIntoTaSending(String createUser, String uuid) {
142
+
143
+        //                item.getCreateUser()  就是新增这个数据的人
144
+        //现在需要去重 创建人和管理员  是一个人只能往  Tasending插入一条数据否则是两条数据
145
+        SysUser sysUserAdmin = sysUserMapper.getAdmin(createUser);
146
+//                如果为空 就不是管理员创建的;
147
+        List<String> userIdList = new ArrayList<>();
148
+
149
+        if (sysUserAdmin == null) {
150
+            userIdList.add(createUser);
151
+        }
152
+        userIdList = sysUserMapper.allAdmin();
153
+
154
+        for (String it : userIdList) {
155
+            TaSending taSending = new TaSending();
156
+            taSending.setMessageId(uuid);
157
+            taSending.setRecipientId(it);
158
+            taSendingMapper.insert(taSending);
159
+        }
160
+
161
+    }
162
+
163
+
164
+}

+ 63
- 22
application/src/main/java/com/lyg/application/util/RuleDetail.java 查看文件

5
 import com.lyg.application.entity.TaRotation;
5
 import com.lyg.application.entity.TaRotation;
6
 
6
 
7
 import java.util.ArrayList;
7
 import java.util.ArrayList;
8
+import java.util.Collection;
8
 import java.util.List;
9
 import java.util.List;
9
 
10
 
10
 public class RuleDetail {
11
 public class RuleDetail {
15
         List<ErrorDto> result = new ArrayList<>();
16
         List<ErrorDto> result = new ArrayList<>();
16
 
17
 
17
         //普通规则
18
         //普通规则
18
-        if (taIncompatibleList.size() == 0) {
19
-            errorDto.setRegularRules("普通规则:根据不相容设置这两个岗位是相容的");
20
-        } else {
21
-            for (TaIncompatible item : taIncompatibleList) {
22
-                errorDto.setPrimaryPost(item.getPrimaryPost());
23
-                errorDto.setTargetPost(item.getTargetPost());
24
-
25
-            }
19
+        // 处理 taIncompatibleList
20
+        if (taIncompatibleList.size() != 0) {
21
+            result.addAll(processTaIncompatibleList(taIncompatibleList));
26
         }
22
         }
27
 
23
 
28
 
24
 
29
-        if (repelList.size() == 0) {
30
-            errorDto.setMonthRules("三个月规则: 这是两个岗位是相容的");
31
-        } else {
32
-            for (TaRotation item : repelList) {
33
-                errorDto.setCounterImpPositions(item.getCounterImpPositions());
34
-                errorDto.setCounterImpPost(item.getCounterImpPostRotation());
35
-                errorDto.setSpecificOrgName(item.getSpecificOrgName());
36
-                errorDto.setSpecificOrgNum(item.getSpecificOrgNum());
37
-                errorDto.setSpecificNameOrgRotation(item.getSpecificNameOrgRotation());
38
-                errorDto.setOrgNumJobRotation(item.getOrgNumJobRotation());
39
-                errorDto.setEmployeeNum(item.getEmployeeNum());
40
-                errorDto.setEmployeeName(item.getEmployeeName());
41
-            }
25
+        // 处理 repelList
26
+        if (repelList.size() != 0) {
27
+            result.addAll(processTaRotationList(repelList));
42
         }
28
         }
43
-        result.add(errorDto);
44
         return result;
29
         return result;
30
+
31
+
32
+    }
33
+
34
+    private Collection<? extends ErrorDto> processTaRotationList(List<TaRotation> repelList) {
35
+        List<ErrorDto> resultList = new ArrayList<>();
36
+        ErrorDto errorDto = new ErrorDto();
37
+
38
+        // 当列表为空,直接添加一个具有默认信息的 ErrorDto
39
+        if (repelList.isEmpty()) {
40
+            errorDto.setMonthRules("根据不相容设置这两个岗位是相容的");
41
+            resultList.add(errorDto);
42
+            return resultList;
43
+        }
44
+
45
+        // 对每个 item 进行处理,创建新的 ErrorDto 实例
46
+        for (TaRotation item : repelList) {
47
+            ErrorDto dto = new ErrorDto();
48
+            // 设置属性
49
+            dto.setCounterImpPositions(item.getCounterImpPositions());
50
+            dto.setCounterImpPost(item.getCounterImpPostRotation());
51
+            dto.setSpecificOrgName(item.getSpecificOrgName());
52
+            dto.setSpecificOrgNum(item.getSpecificOrgNum());
53
+            dto.setSpecificNameOrgRotation(item.getSpecificNameOrgRotation());
54
+            dto.setOrgNumJobRotation(item.getOrgNumJobRotation());
55
+            dto.setEmployeeNum(item.getEmployeeNum());
56
+            dto.setEmployeeName(item.getEmployeeName());
57
+            resultList.add(dto);
58
+        }
59
+
60
+        return resultList;
61
+
62
+    }
63
+
64
+    private Collection<? extends ErrorDto> processTaIncompatibleList(List<TaIncompatible> taIncompatibleList) {
65
+
66
+        List<ErrorDto> resultList = new ArrayList<>();
67
+        ErrorDto errorDto = new ErrorDto();
68
+
69
+        // 当列表为空,直接添加一个具有默认信息的 ErrorDto
70
+        if (taIncompatibleList.isEmpty()) {
71
+            errorDto.setRegularRules("根据不相容设置这两个岗位是相容的");
72
+            resultList.add(errorDto);
73
+            return resultList;
74
+        }
75
+
76
+        // 对每个 item 进行处理,创建新的 ErrorDto 实例
77
+        for (TaIncompatible item : taIncompatibleList) {
78
+            ErrorDto dto = new ErrorDto();
79
+            dto.setPrimaryPost(item.getPrimaryPost());
80
+            dto.setTargetPost(item.getTargetPost());
81
+            resultList.add(dto);
82
+        }
83
+
84
+        return resultList;
85
+
45
     }
86
     }
46
 
87
 
47
 }
88
 }

+ 17
- 1
application/src/main/resources/mapper/TaMessageMapper.xml 查看文件

2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
 
3
 
4
 <mapper namespace="com.lyg.application.mapper.TaMessageMapper">
4
 <mapper namespace="com.lyg.application.mapper.TaMessageMapper">
5
-    
5
+
6
+    <update id="updateBySourceId">
7
+        update TA_MESSAGE m
8
+        <set>
9
+            <if test="params.contentSent != null and params.contentSent != ''">
10
+                m.CONTENT_SENT = #{params.contentSent},
11
+            </if>
12
+            <if test="params.sourceName != null and params.sourceName != ''">
13
+                m.SOURCE_NAME = #{params.sourceName},
14
+            </if>
15
+            <if test="params.waringType != null and params.waringType != ''">
16
+                m.WARING_TYPE = #{params.waringType}
17
+            </if>
18
+        </set>
19
+        WHERE m.source_id = #{id}
20
+        AND m.deleted = 0
21
+    </update>
6
 </mapper>
22
 </mapper>

+ 5
- 0
common/src/main/java/com/lyg/common/Constants.java 查看文件

19
     //三个月规则
19
     //三个月规则
20
     public final static String MONTH_RULE = "monthRules";
20
     public final static String MONTH_RULE = "monthRules";
21
 
21
 
22
+
23
+    //TaMessage
24
+    public final static Integer numI = 3;
25
+    public final static Integer nameI = 8;
26
+
22
 }
27
 }