Browse Source

fix: 更新开发环境数据库配置

fit: 新增值班导入
master
wxc 1 year ago
parent
commit
a5df61798c
  1. 2
      mailbox-common/src/main/java/com/biutag/entity/system/Duty.java
  2. 10
      mailbox-common/src/main/java/com/biutag/enums/DeptTypeEnum.java
  3. 3
      mailbox-common/src/main/java/com/biutag/util/TimeUtils.java
  4. 68
      mailbox-lan/src/main/java/com/biutag/lan/controller/system/DutyController.java
  5. 27
      mailbox-lan/src/main/java/com/biutag/lan/domain/bo/DutyImport.java
  6. 2
      mailbox-lan/src/main/java/com/biutag/lan/service/IDutyService.java
  7. 7
      mailbox-lan/src/main/java/com/biutag/lan/service/impl/DutyServiceImpl.java
  8. 6
      mailbox-lan/src/main/resources/application-dev.yml
  9. BIN
      mailbox-lan/src/main/resources/templates/值班表模板.xlsx
  10. 19
      mailbox-outer/src/main/java/com/biutag/outer/job/Job.java
  11. 6
      mailbox-outer/src/main/resources/application-dev.yml

2
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;

10
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;
}
}

3
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));
}

68
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<PageResult<DutyListedVo>> list(@Validated PageValidate pageValidate,
@ -71,9 +96,48 @@ public class DutyController {
@Log(title = "值班导入")
@PostMapping("/import")
@Operation(summary = "值班导入")
public AjaxResult<Void> dataImport(@RequestPart("file") MultipartFile file) {
public AjaxResult<Void> dataImport(@RequestPart("file") MultipartFile file) throws IOException {
List<DutyImport> list = new ArrayList<>();
ExcelReader excelReader = EasyExcel.read(file.getInputStream(), DutyImport.class, new ReadListener<DutyImport>() {
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<Duty> 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<PoliceUser>().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()));
}
}

27
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;
}

2
mailbox-lan/src/main/java/com/biutag/lan/service/IDutyService.java

@ -63,4 +63,6 @@ public interface IDutyService {
List<Duty> getSameDayDuty(String depatType);
boolean saveBatch(List<Duty> list);
}

7
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<Duty> list) {
list.forEach(item -> {
dutyMapper.insert(item);
});
return true;
}
}

6
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:
# 地址

BIN
mailbox-lan/src/main/resources/templates/值班表模板.xlsx

Binary file not shown.

19
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<String, Boolean> cache = Caffeine.newBuilder()
.expireAfterWrite(8, TimeUnit.HOURS) // 设置写入后过期时间
.maximumSize(1000)
.build();
// 30s
@Scheduled(fixedRate = 10000)
@Scheduled(fixedRate = 30000)
public void pushMailData() {
List<Mail> 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);
}
}
}
}

6
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:

Loading…
Cancel
Save