Commit 0b1d65535be79475e3a908b9e6017dae8ffbe247

Authored by guzijian
1 parent f87060a0

feat: 新增通告

ruoyi-admin/src/main/java/com/ruoyi/controller/ReportController.java
1 1 package com.ruoyi.controller;
2 2  
3 3 import com.ruoyi.common.core.domain.AjaxResult;
  4 +import com.ruoyi.common.global.Result;
4 5 import com.ruoyi.common.utils.poi.ExcelUtil;
5 6 import com.ruoyi.pojo.request.ReportViewRequestVo;
6 7 import com.ruoyi.pojo.request.ReportErrorRequestVo;
... ... @@ -8,6 +9,7 @@ import com.ruoyi.pojo.response.ExportReportViewResponseVo;
8 9 import com.ruoyi.pojo.response.ReportErrorResponseVo;
9 10 import com.ruoyi.pojo.response.ReportViewResponseVo;
10 11 import com.ruoyi.service.ReportService;
  12 +import com.ruoyi.system.domain.SysNotice;
11 13 import io.swagger.annotations.Api;
12 14 import io.swagger.annotations.ApiOperation;
13 15 import io.swagger.annotations.ApiParam;
... ... @@ -65,6 +67,19 @@ public class ReportController {
65 67 util.exportEasyExcel(response, list, "签到报表");
66 68 }
67 69  
  70 + @ApiOperation("告警通知")
  71 + @GetMapping("/alarm/notice")
  72 + public Result<?> getAlarmNotice(){
  73 + return Result.OK(reportService.getAlarmNotice());
  74 + }
  75 +
  76 +
  77 + @ApiOperation("确认通知")
  78 + @PostMapping("/sureNotice")
  79 + public Result<?> sureNotice(@Validated @RequestBody SysNotice notice){
  80 + return Result.OK(reportService.sureNotice(notice));
  81 + }
  82 +
68 83 @ApiOperation("异常报表导出")
69 84 @PostMapping("/error/export")
70 85 public void exportErrorReport(@ApiParam ReportErrorRequestVo requestVo, HttpServletResponse response) {
... ...
ruoyi-admin/src/main/java/com/ruoyi/service/ReportService.java
1 1 package com.ruoyi.service;
2 2  
  3 +import com.ruoyi.common.utils.SecurityUtils;
3 4 import com.ruoyi.driver.mapper.DriverMapper;
4 5 import com.ruoyi.driver.mapper.DriverSchedulingMapper;
5 6 import com.ruoyi.eexception.mapper.EquipmentExceptionMapper;
... ... @@ -8,6 +9,8 @@ import com.ruoyi.domain.DriverScheduling;
8 9 import com.ruoyi.pojo.request.ReportViewRequestVo;
9 10 import com.ruoyi.pojo.request.ReportErrorRequestVo;
10 11 import com.ruoyi.pojo.response.*;
  12 +import com.ruoyi.system.domain.SysNotice;
  13 +import com.ruoyi.system.service.ISysNoticeService;
11 14 import org.springframework.beans.BeanUtils;
12 15 import org.springframework.beans.factory.annotation.Autowired;
13 16 import org.springframework.stereotype.Service;
... ... @@ -36,6 +39,9 @@ public class ReportService {
36 39 private SignInMapper signInMapper;
37 40  
38 41 @Autowired
  42 + private ISysNoticeService noticeService;
  43 +
  44 + @Autowired
39 45 private EquipmentExceptionMapper exceptionMapper;
40 46  
41 47 @Autowired
... ... @@ -188,4 +194,16 @@ public class ReportService {
188 194 List<SignInResponseVo> vos = signInMapper.selectSignInList(vo);
189 195 return vos;
190 196 }
  197 +
  198 + public SysNotice getAlarmNotice() {
  199 + String username = SecurityUtils.getUsername();
  200 + return noticeService.getAlarmNotice(username);
  201 + }
  202 +
  203 + public Object sureNotice(SysNotice notice) {
  204 + String username = SecurityUtils.getUsername();
  205 + notice.setRemark(notice.getRemark() + "," + username);
  206 + noticeService.updateNotice(notice);
  207 + return null;
  208 + }
191 209 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/service/ThreadJobService.java
... ... @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
7 7 import com.ruoyi.common.cache.NowSchedulingCache;
8 8 import com.ruoyi.common.config.RuoYiConfig;
9 9 import com.ruoyi.common.exception.file.FileUploadException;
  10 +import com.ruoyi.common.utils.DateUtils;
10 11 import com.ruoyi.common.utils.StringUtils;
11 12 import com.ruoyi.common.utils.file.FileUploadUtils;
12 13 import com.ruoyi.domain.RuleAttendanceMain;
... ... @@ -25,6 +26,8 @@ import com.ruoyi.job.DriverJob;
25 26 import com.ruoyi.domain.DriverScheduling;
26 27 import com.ruoyi.pojo.GlobalIndex;
27 28 import com.ruoyi.pojo.response.ResponseSchedulingDto;
  29 +import com.ruoyi.system.domain.SysNotice;
  30 +import com.ruoyi.system.service.ISysNoticeService;
28 31 import com.ruoyi.utils.ConstDateUtil;
29 32 import lombok.extern.slf4j.Slf4j;
30 33 import org.springframework.beans.BeanUtils;
... ... @@ -42,6 +45,7 @@ import sun.misc.BASE64Decoder;
42 45  
43 46 import javax.annotation.Resource;
44 47 import java.io.*;
  48 +import java.math.BigDecimal;
45 49 import java.time.LocalDate;
46 50 import java.util.*;
47 51 import java.util.stream.Collectors;
... ... @@ -49,6 +53,7 @@ import java.util.stream.Collectors;
49 53 import static com.ruoyi.common.ConstDriverProperties.BC_TYPE_IN;
50 54 import static com.ruoyi.common.ConstDriverProperties.BC_TYPE_OUT;
51 55 import static com.ruoyi.common.ConstEquipmentProperties.*;
  56 +import static com.ruoyi.common.ConstSignInConstSignInProperties.SIGN_ALCOHOL_EX_NUM;
52 57 import static com.ruoyi.common.ConstSignInConstSignInProperties.SIGN_NO_EX_NUM;
53 58 import static com.ruoyi.common.RuleSchedulingProperties.WORK_FLAG;
54 59  
... ... @@ -66,6 +71,9 @@ public class ThreadJobService {
66 71 @Autowired
67 72 private IErrorJobcodeService errorJobcodeService;
68 73  
  74 + @Autowired
  75 + private ISysNoticeService noticeService;
  76 +
69 77 @Resource
70 78 private EmailService emailService;
71 79  
... ... @@ -168,9 +176,47 @@ public class ThreadJobService {
168 176 exception.setPlanTime(scheduling.getBcType().equals(BC_TYPE_IN) ? new Date(scheduling.getZdsjT()) : new Date(scheduling.getFcsjT()));
169 177 }
170 178 exceptionMapper.insertEquipmentException(exception);
  179 + // 发送通知
  180 + sendNotice(signIn, driver, dto, globalIndex);
171 181 }
172 182 }
173 183  
  184 + private void sendNotice(SignIn signIn, Driver driver, List<DriverScheduling> dto, GlobalIndex globalIndex) {
  185 + if (SIGN_ALCOHOL_EX_NUM.equals(signIn.getExType())){
  186 + SysNotice notice = new SysNotice();
  187 + notice.setCreateBy("system");
  188 + notice.setUpdateBy("system");
  189 + notice.setNoticeTitle("酒精测试异常通知");
  190 + DriverScheduling item = null;
  191 + if (CollectionUtil.isEmpty(dto)) {
  192 + item = new DriverScheduling();
  193 + handlerNoScheduling(item, signIn, driver);
  194 + }else {
  195 + item = dto.get(globalIndex.getIndex());
  196 + }
  197 + String jobCode = "工号:" + item.getJobCode() + "\n";
  198 + String name = "姓名:" + item.getName() + "\n";
  199 + String posts = "工种:" + item.getPosts() + "\n";
  200 + String fleetName = "车队:" + item.getFleetName() + "\n";
  201 + String scheduling = "排班:" + (Objects.isNull(item.getScheduleDate()) ? "无排班" : "有排班") + "\n";
  202 + String signDate = "打卡时间:" + ConstDateUtil.formatDate("yyyy-MM-dd HH:mm:ss", signIn.getCreateTime()) + "\n";
  203 + String cause = "原因:酒精测试超标,当前测试值达到" + signIn.getAlcoholIntake() + "mg/100ml。属于" + getResultString(signIn.getAlcoholIntake());
  204 + String content = jobCode + name + posts + fleetName + scheduling + signDate + cause;
  205 + notice.setNoticeContent(content);
  206 + notice.setNoticeType("1");
  207 + notice.setStatus("0");
  208 + notice.setCreateTime(DateUtils.getNowDate());
  209 + notice.setUpdateTime(DateUtils.getNowDate());
  210 + noticeService.insertNotice(notice);
  211 + }
  212 + }
  213 + private String getResultString(BigDecimal alcoholIntake) {
  214 + if (alcoholIntake.compareTo(new BigDecimal(20)) >= 0 && alcoholIntake.compareTo(new BigDecimal(80)) < 0)
  215 + return "饮酒后驾驶机动车";
  216 + else
  217 + return "醉酒后驾驶机动车";
  218 + }
  219 +
174 220 @Async
175 221 public void asyncUploadDriverWithUpdateImageUrl(List<Driver> drivers, String token) {
176 222 // 插入数据
... ...
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNotice.java
... ... @@ -20,6 +20,9 @@ public class SysNotice extends BaseEntity
20 20 private Long noticeId;
21 21  
22 22 /** 公告标题 */
  23 + @Xss(message = "公告标题不能包含脚本字符")
  24 + @NotBlank(message = "公告标题不能为空")
  25 + @Size(min = 0, max = 50, message = "公告标题不能超过50个字符")
23 26 private String noticeTitle;
24 27  
25 28 /** 公告类型(1通知 2公告) */
... ... @@ -46,9 +49,7 @@ public class SysNotice extends BaseEntity
46 49 this.noticeTitle = noticeTitle;
47 50 }
48 51  
49   - @Xss(message = "公告标题不能包含脚本字符")
50   - @NotBlank(message = "公告标题不能为空")
51   - @Size(min = 0, max = 50, message = "公告标题不能超过50个字符")
  52 +
52 53 public String getNoticeTitle()
53 54 {
54 55 return noticeTitle;
... ...
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysNoticeMapper.java
... ... @@ -57,4 +57,11 @@ public interface SysNoticeMapper
57 57 * @return 结果
58 58 */
59 59 public int deleteNoticeByIds(Long[] noticeIds);
  60 +
  61 + /**
  62 + * 获取当前用户未读通告
  63 + * @param username
  64 + * @return
  65 + */
  66 + List<SysNotice> getAlarmNotice(String username);
60 67 }
... ...
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java
... ... @@ -57,4 +57,11 @@ public interface ISysNoticeService
57 57 * @return 结果
58 58 */
59 59 public int deleteNoticeByIds(Long[] noticeIds);
  60 +
  61 + /**
  62 + * 获取当前用户为已读的通告
  63 + * @param username
  64 + * @return
  65 + */
  66 + SysNotice getAlarmNotice(String username);
60 67 }
... ...
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java
1 1 package com.ruoyi.system.service.impl;
2 2  
3 3 import java.util.List;
  4 +
  5 +import com.ruoyi.common.utils.StringUtils;
4 6 import org.springframework.beans.factory.annotation.Autowired;
5 7 import org.springframework.stereotype.Service;
6 8 import com.ruoyi.system.domain.SysNotice;
... ... @@ -89,4 +91,18 @@ public class SysNoticeServiceImpl implements ISysNoticeService
89 91 {
90 92 return noticeMapper.deleteNoticeByIds(noticeIds);
91 93 }
  94 +
  95 + @Override
  96 + public SysNotice getAlarmNotice(String username) {
  97 + List<SysNotice> noticeList = noticeMapper.getAlarmNotice(username);
  98 + if (noticeList.size() > 0){
  99 + for (int i = noticeList.size(); i >= 0; i--) {
  100 + SysNotice notice = noticeList.get(0);
  101 + if (StringUtils.isEmpty(notice.getRemark()) || !notice.getRemark().contains(username)){
  102 + return notice;
  103 + }
  104 + }
  105 + }
  106 + return null;
  107 + }
92 108 }
... ...
ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml
... ... @@ -41,7 +41,13 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
41 41 </if>
42 42 </where>
43 43 </select>
44   -
  44 + <select id="getAlarmNotice" resultType="com.ruoyi.system.domain.SysNotice">
  45 + select * from sys_notice
  46 + order by create_time desc
  47 + limit 10
  48 +
  49 + </select>
  50 +
45 51 <insert id="insertNotice" parameterType="SysNotice">
46 52 insert into sys_notice (
47 53 <if test="noticeTitle != null and noticeTitle != '' ">notice_title, </if>
... ... @@ -70,7 +76,9 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
70 76 <if test="noticeContent != null">notice_content = #{noticeContent}, </if>
71 77 <if test="status != null and status != ''">status = #{status}, </if>
72 78 <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
73   - update_time = sysdate()
  79 + <if test="remark != null and remark != ''">remark = #{remark},</if>
  80 +
  81 + update_time = sysdate()
74 82 </set>
75 83 where notice_id = #{noticeId}
76 84 </update>
... ...