diff --git a/mailbox-common/src/main/java/com/biutag/entity/system/Duty.java b/mailbox-common/src/main/java/com/biutag/entity/system/Duty.java index 98c836f..94f8590 100644 --- a/mailbox-common/src/main/java/com/biutag/entity/system/Duty.java +++ b/mailbox-common/src/main/java/com/biutag/entity/system/Duty.java @@ -33,7 +33,7 @@ public class Duty implements Serializable { private String deptType; @Schema(name = "机构类型名称") - private String typeName; + private String typeName; @Schema(name = "民警姓名") private String policeName; diff --git a/mailbox-common/src/main/java/com/biutag/enums/DeptTypeEnum.java b/mailbox-common/src/main/java/com/biutag/enums/DeptTypeEnum.java index 6ba9575..a5d18f5 100644 --- a/mailbox-common/src/main/java/com/biutag/enums/DeptTypeEnum.java +++ b/mailbox-common/src/main/java/com/biutag/enums/DeptTypeEnum.java @@ -30,4 +30,14 @@ public enum DeptTypeEnum { private String name; + public static DeptTypeEnum get(String type) { + for (DeptTypeEnum value : values()) { + if (value.getType().equals(type)) { + return value; + } + + } + return null; + } + } diff --git a/mailbox-common/src/main/java/com/biutag/util/TimeUtils.java b/mailbox-common/src/main/java/com/biutag/util/TimeUtils.java index 7c10d0a..7b2544b 100644 --- a/mailbox-common/src/main/java/com/biutag/util/TimeUtils.java +++ b/mailbox-common/src/main/java/com/biutag/util/TimeUtils.java @@ -18,6 +18,9 @@ public class TimeUtils { * @return String */ public static String timestampToDate(Long time) { + if (Objects.isNull(time)) { + return ""; + } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time * 1000)); } diff --git a/mailbox-lan/src/main/java/com/biutag/lan/controller/system/DutyController.java b/mailbox-lan/src/main/java/com/biutag/lan/controller/system/DutyController.java index a2abc78..283987a 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/controller/system/DutyController.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/controller/system/DutyController.java @@ -1,9 +1,21 @@ package com.biutag.lan.controller.system; +import cn.hutool.core.date.DateUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelReader; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.read.listener.ReadListener; +import com.alibaba.excel.read.metadata.ReadSheet; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.biutag.aop.NotPower; import com.biutag.core.AjaxResult; import com.biutag.core.PageResult; +import com.biutag.entity.system.Dept; +import com.biutag.entity.system.Duty; +import com.biutag.entity.system.PoliceUser; +import com.biutag.enums.DeptTypeEnum; import com.biutag.lan.aop.Log; +import com.biutag.lan.domain.bo.DutyImport; import com.biutag.lan.domain.validate.commons.IdValidate; import com.biutag.lan.domain.validate.commons.PageValidate; import com.biutag.lan.domain.validate.system.DutyCreateValidate; @@ -11,7 +23,9 @@ import com.biutag.lan.domain.validate.system.DutySearchValidate; import com.biutag.lan.domain.validate.system.DutyUpdateValidate; import com.biutag.lan.domain.vo.system.DutyDetailVo; import com.biutag.lan.domain.vo.system.DutyListedVo; +import com.biutag.lan.mapper.PoliceUserMapper; import com.biutag.lan.service.IDutyService; +import com.biutag.mapper.system.DeptMapper; import com.biutag.validator.annotation.IDMust; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -20,6 +34,11 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + @RestController @RequestMapping("api/duty") @Tag(name = "值班管理") @@ -28,6 +47,12 @@ public class DutyController { @Resource IDutyService iDutyService; + @Resource + DeptMapper deptMapper; + + @Resource + PoliceUserMapper policeUserMapper; + @GetMapping("/list") @Operation(summary = "值班列表") public AjaxResult> list(@Validated PageValidate pageValidate, @@ -71,9 +96,48 @@ public class DutyController { @Log(title = "值班导入") @PostMapping("/import") @Operation(summary = "值班导入") - public AjaxResult dataImport(@RequestPart("file") MultipartFile file) { + public AjaxResult dataImport(@RequestPart("file") MultipartFile file) throws IOException { + List list = new ArrayList<>(); + ExcelReader excelReader = EasyExcel.read(file.getInputStream(), DutyImport.class, new ReadListener() { - return AjaxResult.success(); + @Override + public void invoke(DutyImport data, AnalysisContext analysisContext) { + list.add(data); + } + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + } + }).build(); + + ReadSheet sheet = EasyExcel.readSheet(0).build(); + excelReader.read(sheet); + excelReader.close(); + List dutyList = list.stream().map(item -> { + Duty duty = new Duty(); + String date = DateUtil.format(DateUtil.parse(item.getDate(), "yyyy/MM/dd"), "yyyy-MM-dd"); + duty.setStartTime(date); + duty.setEndTime(date); + duty.setPoliceName(item.getPoliceName()); + duty.setEmpNo(item.getEmpNo()); + duty.setMobile(item.getMobile()); + PoliceUser policeUser = policeUserMapper.selectOne(new LambdaQueryWrapper().eq(PoliceUser::getEmpNo, item.getEmpNo())); + if (Objects.isNull(policeUser)) { + throw new RuntimeException(String.format("警号[%s]无该警员信息", item.getEmpNo())); + } + Dept dept = deptMapper.selectById(policeUser.getDataDeptId()); + if (Objects.isNull(dept)) { + throw new RuntimeException("未找到单位信息"); + } + duty.setRoleId(policeUser.getRoleIds()); + duty.setDepartId(String.valueOf(policeUser.getDataDeptId())); + duty.setDepartName(dept.getName()); + duty.setDeptType(dept.getCategory()); + duty.setTypeName(DeptTypeEnum.get(dept.getCategory()).getName()); + duty.setCreateTime(System.currentTimeMillis() / 1000); + return duty; + }).toList(); + iDutyService.saveBatch(dutyList); + return AjaxResult.success(String.format("已导入%s条数据", dutyList.size())); } } diff --git a/mailbox-lan/src/main/java/com/biutag/lan/domain/bo/DutyImport.java b/mailbox-lan/src/main/java/com/biutag/lan/domain/bo/DutyImport.java new file mode 100644 index 0000000..6ae316d --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/domain/bo/DutyImport.java @@ -0,0 +1,27 @@ +package com.biutag.lan.domain.bo; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Getter; +import lombok.Setter; + +/** + * @author wxc + * @date 2024/10/28 + */ +@Setter +@Getter +public class DutyImport { + + @ExcelProperty("日 期") + private String date; + + @ExcelProperty("值 班 人 员") + private String policeName; + + @ExcelProperty("警号") + private String empNo; + + @ExcelProperty("电话号码") + private String mobile; + +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/IDutyService.java b/mailbox-lan/src/main/java/com/biutag/lan/service/IDutyService.java index dc31a8b..9de427d 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/service/IDutyService.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/IDutyService.java @@ -63,4 +63,6 @@ public interface IDutyService { List getSameDayDuty(String depatType); + + boolean saveBatch(List list); } diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/impl/DutyServiceImpl.java b/mailbox-lan/src/main/java/com/biutag/lan/service/impl/DutyServiceImpl.java index 72a0fc0..0089a02 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/service/impl/DutyServiceImpl.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/impl/DutyServiceImpl.java @@ -276,4 +276,11 @@ public class DutyServiceImpl implements IDutyService { return dutyList; } + @Override + public boolean saveBatch(List list) { + list.forEach(item -> { + dutyMapper.insert(item); + }); + return true; + } } diff --git a/mailbox-lan/src/main/resources/application-dev.yml b/mailbox-lan/src/main/resources/application-dev.yml index 15fe70e..48475b5 100644 --- a/mailbox-lan/src/main/resources/application-dev.yml +++ b/mailbox-lan/src/main/resources/application-dev.yml @@ -1,8 +1,8 @@ spring: datasource: - url: jdbc:postgresql://172.31.217.20:30924/mailbox?currentSchema=mailbox - username: pg - password: ip12341234 + url: jdbc:postgresql://58.51.152.18:10642/mailbox?currentSchema=mailbox + username: alphay + password: alphay@123 data: redis: # 地址 diff --git a/mailbox-lan/src/main/resources/templates/值班表模板.xlsx b/mailbox-lan/src/main/resources/templates/值班表模板.xlsx new file mode 100644 index 0000000..cf1ccb4 Binary files /dev/null and b/mailbox-lan/src/main/resources/templates/值班表模板.xlsx differ diff --git a/mailbox-outer/src/main/java/com/biutag/outer/job/Job.java b/mailbox-outer/src/main/java/com/biutag/outer/job/Job.java index b962990..3589aad 100644 --- a/mailbox-outer/src/main/java/com/biutag/outer/job/Job.java +++ b/mailbox-outer/src/main/java/com/biutag/outer/job/Job.java @@ -17,7 +17,10 @@ import com.biutag.outer.domain.*; import com.biutag.outer.mapper.*; import com.biutag.outer.service.SmsSendService; import com.biutag.outer.util.Random; +import com.biutag.outer.util.Sms; import com.biutag.outer.util.SmsUtil; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -29,6 +32,7 @@ import java.time.LocalDateTime; import java.util.Date; import java.util.List; import java.util.Objects; +import java.util.concurrent.TimeUnit; @Slf4j @RequiredArgsConstructor @@ -55,8 +59,13 @@ public class Job { private final String key = "mailbox"; + private static final Cache cache = Caffeine.newBuilder() + .expireAfterWrite(8, TimeUnit.HOURS) // 设置写入后过期时间 + .maximumSize(1000) + .build(); + // 30s - @Scheduled(fixedRate = 10000) + @Scheduled(fixedRate = 30000) public void pushMailData() { List mails = mailMapper.listByMailEtl(); for (Mail mail : mails) { @@ -91,6 +100,14 @@ public class Job { log.error("推送信件[{}]异常: {}", mail.getId(), e.getMessage(), e); MailEtl mailEtl = new MailEtl().setMailId(mail.getId()).setSuccess(false).setCreateTime(LocalDateTime.now()).setErrMsg(e.getMessage()); mailEtlMapper.insert(mailEtl); + String key = "errNotification"; + if (Objects.isNull(cache.getIfPresent(key)) || !cache.getIfPresent(key)) { + String message = String.format("局长信箱信件推送异常:%s", e.getMessage()); + SmsUtil.sendSms("15608487213", message); + SmsUtil.sendSms("18867391894", message); + SmsUtil.sendSms("13787166867", message); + cache.put(key, true); + } } } } diff --git a/mailbox-outer/src/main/resources/application-dev.yml b/mailbox-outer/src/main/resources/application-dev.yml index e0e775f..fd7c4cb 100644 --- a/mailbox-outer/src/main/resources/application-dev.yml +++ b/mailbox-outer/src/main/resources/application-dev.yml @@ -1,8 +1,8 @@ spring: datasource: - url: jdbc:postgresql://172.31.217.20:32378/mailbox?currentSchema=mailbox-outer - username: vbadmin - password: Ip12341234 + url: jdbc:postgresql://58.51.152.18:10642/mailbox?currentSchema=mailbox-outer + username: alphay + password: alphay@123 oss: minio: