From e56ed69c91e6b3a4568363a809524026a52be329 Mon Sep 17 00:00:00 2001 From: wxc <191104855@qq.com> Date: Tue, 5 Mar 2024 15:07:25 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=AD=A6=E5=8A=A1=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E7=BC=96=E8=BE=91BUG=E4=BF=AE=E5=A4=8D=202.=20=E4=BB=8B?= =?UTF-8?q?=E7=BB=8D=E5=A4=96=E7=BD=91=E6=8E=A8=E9=80=81=E7=9A=84=E4=BF=A1?= =?UTF-8?q?=E4=BB=B6=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/biutag/config/Minio.java | 16 +++- .../com/biutag/entity/system/PoliceUser.java | 42 ++++----- .../com/biutag/exception/AuthException.java | 7 ++ .../lan/controller/ApiV1Controller.java | 68 ++++++++++++++ .../biutag/lan/controller/MailController.java | 3 + .../com/biutag/lan/crontab/MailSourceJob.java | 82 ----------------- .../biutag/lan/domain/bo/MailApiV1Req.java | 92 +++++++++++++++++++ .../service/impl/PoliceUserServiceImpl.java | 9 +- .../resources/mapper/PoliceUserMapper.xml | 2 +- mailbox-outer/pom.xml | 4 + .../java/com/biutag/outer/domain/Mail.java | 2 + .../java/com/biutag/outer/domain/MailEtl.java | 27 ++++++ .../java/com/biutag/outer/job/MailJob.java | 82 +++++++++++++++++ .../biutag/outer/mapper/MailEtlMapper.java | 9 ++ .../com/biutag/outer/mapper/MailMapper.java | 5 + .../src/main/resources/application-dev.yml | 7 +- .../test/java/com/biutag/outer/ApiTest.java | 19 ++++ 17 files changed, 367 insertions(+), 109 deletions(-) create mode 100644 mailbox-lan/src/main/java/com/biutag/lan/controller/ApiV1Controller.java delete mode 100644 mailbox-lan/src/main/java/com/biutag/lan/crontab/MailSourceJob.java create mode 100644 mailbox-lan/src/main/java/com/biutag/lan/domain/bo/MailApiV1Req.java create mode 100644 mailbox-outer/src/main/java/com/biutag/outer/domain/MailEtl.java create mode 100644 mailbox-outer/src/main/java/com/biutag/outer/job/MailJob.java create mode 100644 mailbox-outer/src/main/java/com/biutag/outer/mapper/MailEtlMapper.java create mode 100644 mailbox-outer/src/test/java/com/biutag/outer/ApiTest.java diff --git a/mailbox-common/src/main/java/com/biutag/config/Minio.java b/mailbox-common/src/main/java/com/biutag/config/Minio.java index cfd620a..caeb850 100644 --- a/mailbox-common/src/main/java/com/biutag/config/Minio.java +++ b/mailbox-common/src/main/java/com/biutag/config/Minio.java @@ -9,12 +9,14 @@ import io.minio.*; import io.minio.errors.*; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URLDecoder; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.util.Base64; import java.util.Date; import java.util.Optional; @@ -46,8 +48,12 @@ public class Minio { } public String upload(InputStream is, String originName) { + return upload(is, originName, false); + } + + public String upload(InputStream is, String originName, boolean fullPath) { try { - String filepath = DateUtil.format(new Date(), "YYMMdd") + "/" + IdUtil.nanoId(8) + + String filepath = fullPath ? originName : DateUtil.format(new Date(), "YYMMdd") + "/" + IdUtil.nanoId(8) + (StrUtil.isNotBlank(originName) && originName.contains(".") ? originName.substring(originName.lastIndexOf(".")) : ""); PutObjectArgs putObjectArgs = PutObjectArgs.builder() .object(filepath) @@ -85,4 +91,12 @@ public class Minio { } } + public String getBase64(String filepath) { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + get(filepath, os); + byte[] data = os.toByteArray(); + // 使用Base64编码器对字节数组进行编码 + return Base64.getEncoder().encodeToString(data); + } + } diff --git a/mailbox-common/src/main/java/com/biutag/entity/system/PoliceUser.java b/mailbox-common/src/main/java/com/biutag/entity/system/PoliceUser.java index b259030..79ecfbb 100644 --- a/mailbox-common/src/main/java/com/biutag/entity/system/PoliceUser.java +++ b/mailbox-common/src/main/java/com/biutag/entity/system/PoliceUser.java @@ -14,11 +14,11 @@ public class PoliceUser implements Serializable { private static final long serialVersionUID = 1L; - @TableId(value="id", type=IdType.AUTO) + @TableId(value = "id", type = IdType.AUTO) @ApiModelProperty("ID") private Integer id; - @ApiModelProperty("用户账号") + @ApiModelProperty("用户账号") private String nickname; @ApiModelProperty("用户昵称") @@ -26,11 +26,11 @@ public class PoliceUser implements Serializable { @ApiModelProperty("警号") private String empNo; @ApiModelProperty("身份证") - private String idCode; + private String idCode; @ApiModelProperty("职位名称") - private String displayName; + private String displayName; @ApiModelProperty("姓名") - private String name; + private String name; @ApiModelProperty("用户密码") private String password; @@ -46,7 +46,7 @@ public class PoliceUser implements Serializable { @ApiModelProperty("部门主键") private String deptIds; - @ApiModelProperty("部门名称") + @ApiModelProperty("部门名称") private String deptName; @ApiModelProperty("岗位主键") @@ -56,41 +56,40 @@ public class PoliceUser implements Serializable { private Integer sort; @ApiModelProperty("岗位主键") - private String districtId; + private String districtId; @ApiModelProperty("工作") - private String job; + private String job; @ApiModelProperty("工作类型") - private String jobType; + private String jobType; @ApiModelProperty("未知") private String managerId; @ApiModelProperty("电话") - private String phone; + private String phone; @ApiModelProperty("传真号") private String faxNo; @ApiModelProperty("职位名称") - private String postTitle; + private String postTitle; @ApiModelProperty("工作地址") - private String workAddress; + private String workAddress; @ApiModelProperty("账号") - private String account; + private String account; @ApiModelProperty("手机号") - private String mobile; + private String mobile; @ApiModelProperty("电子邮件") - private String email; + private String email; @ApiModelProperty("性别") - private String gender; + private String gender; @ApiModelProperty("出生年月") - private String birthday; + private String birthday; @ApiModelProperty("状态") - private String status; + private String status; @ApiModelProperty("入职实际") - private String hiredAt; + private String hiredAt; @ApiModelProperty("类型 0 原始数据 1 协警 2 文员 3 临时工") - private String type; - + private String type; @ApiModelProperty("多端登录: [0=否, 1=是]") @@ -103,7 +102,6 @@ public class PoliceUser implements Serializable { private Integer isDelete; - @ApiModelProperty("最后登录IP") private String lastLoginIp; diff --git a/mailbox-common/src/main/java/com/biutag/exception/AuthException.java b/mailbox-common/src/main/java/com/biutag/exception/AuthException.java index 9db4265..b1c3aa9 100644 --- a/mailbox-common/src/main/java/com/biutag/exception/AuthException.java +++ b/mailbox-common/src/main/java/com/biutag/exception/AuthException.java @@ -6,4 +6,11 @@ package com.biutag.exception; */ public class AuthException extends RuntimeException { + public AuthException() { + } + + public AuthException(String message) { + super(message); + } + } diff --git a/mailbox-lan/src/main/java/com/biutag/lan/controller/ApiV1Controller.java b/mailbox-lan/src/main/java/com/biutag/lan/controller/ApiV1Controller.java new file mode 100644 index 0000000..5f85fbd --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/controller/ApiV1Controller.java @@ -0,0 +1,68 @@ +package com.biutag.lan.controller; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.crypto.digest.MD5; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.biutag.config.Minio; +import com.biutag.core.AjaxResult; +import com.biutag.exception.AuthException; +import com.biutag.exception.BusinessException; +import com.biutag.lan.domain.MailSource; +import com.biutag.lan.domain.bo.MailApiV1Req; +import com.biutag.lan.service.MailSourceService; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; +import org.simpleframework.xml.core.Validate; +import org.springframework.web.bind.annotation.*; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +@RequiredArgsConstructor +@Validate +@RequestMapping("/v1/") +@RestController +public class ApiV1Controller { + + private final MailSourceService mailSourceService; + + private final Minio minio; + + private final String key = "mailbox"; + + @PostMapping("mail") + public AjaxResult addMail(@RequestBody @Valid MailApiV1Req mail, HttpServletRequest request) { + validAuth(request); + if (mailSourceService.exists(new LambdaQueryWrapper().eq(MailSource::getId, mail.getId()))) { + return AjaxResult.success(); + } + if (StrUtil.isNotBlank(mail.getAttachments())) { + List attachments = JSON.parseArray(mail.getAttachments()).toList(JSONObject.class); + for (JSONObject attachment : attachments) { + //minio.upload(IOUtil.base64ToStream(attachment.getString("base64")), attachment.getString("filepath"), true); + attachment.remove("base64"); + } + mail.setAttachments(JSON.toJSONString(attachments)); + } + mailSourceService.saveBatch(Collections.singletonList(mail.toMailOuter())); + return AjaxResult.success(); + } + + private void validAuth(HttpServletRequest request) { + String authorization = request.getHeader("Authorization"); + String timestamp = request.getHeader("timestamp"); + if (StrUtil.isBlank(authorization) || StrUtil.isBlank(timestamp)) { + throw new AuthException(); + } + if (!authorization.equals(MD5.create().digestHex(key + timestamp))) { + throw new AuthException(); + } + } + +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/controller/MailController.java b/mailbox-lan/src/main/java/com/biutag/lan/controller/MailController.java index 8c41ef6..42a9e47 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/controller/MailController.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/controller/MailController.java @@ -62,4 +62,7 @@ public class MailController { return AjaxResult.success(mailService.invalidCompletion(completion)); } + + + } diff --git a/mailbox-lan/src/main/java/com/biutag/lan/crontab/MailSourceJob.java b/mailbox-lan/src/main/java/com/biutag/lan/crontab/MailSourceJob.java deleted file mode 100644 index babe67c..0000000 --- a/mailbox-lan/src/main/java/com/biutag/lan/crontab/MailSourceJob.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.biutag.lan.crontab; - -import cn.hutool.core.date.DatePattern; -import cn.hutool.http.HttpResponse; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONObject; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.biutag.constants.AppConstants; -import com.biutag.lan.domain.MailSourceEtl; -import com.biutag.lan.domain.bo.MailOuter; -import com.biutag.lan.service.MailSourceEtlService; -import com.biutag.lan.service.MailSourceService; -import lombok.RequiredArgsConstructor; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -@RequiredArgsConstructor -@Component -public class MailSourceJob { - - private final MailSourceEtlService mailSourceEtlService; - - private final MailSourceService mailSourceService; - -// @Scheduled(fixedRate = 60000) - @Transactional(rollbackFor = Exception.class) - public void extractMailSource() { - System.out.println("extractMailSource------------"); - MailSourceEtl latestEtl = mailSourceEtlService.getLatestSuccess(); - LocalDateTime beginTime = Optional.ofNullable(latestEtl).map(MailSourceEtl::getEtlTime).orElse(LocalDateTime.of(1970, 1, 1, 0, 0, 0)); - LocalDateTime now = LocalDateTime.now(); - int current = 1; - int size = 10; - Page mailOuterPage = pageMailOuterByCreateTime(current, size, - beginTime.format(DatePattern.NORM_DATETIME_FORMAT.getDateTimeFormatter()), - now.format(DatePattern.NORM_DATETIME_FORMAT.getDateTimeFormatter()), - new ArrayList<>()); - // 保存记录 - if (mailOuterPage.getTotal() > 0) { - mailSourceService.saveBatch(mailOuterPage.getRecords()); - mailSourceEtlService.save(new MailSourceEtl().setEtlTime(now).setSuccess(AppConstants.YES).setTotal(mailOuterPage.getTotal())); - } - } - - public Page pageMailOuterByCreateTime(int current, int size, String beginTime, String endTime, List records) { - String url = String.format("https://mailbox.biutag.com/api/api/mail?current=%s&size=%s&beginTime=%s&endTime=%s", current, size, beginTime, endTime); - HttpResponse httpResponse = HttpUtil.createGet(url) - .auth("chuangke") - .execute(); - if (!httpResponse.isOk()) { - - } - JSONObject data = JSON.parseObject(httpResponse.body()); - Long total = data.getLong("total"); - records.addAll(data.getList("records", MailOuter.class)); - if (total <= records.size()) { - return new Page().setTotal(total).setRecords(records); - } - return pageMailOuterByCreateTime(++current, size, beginTime, endTime, records, total); - } - - public Page pageMailOuterByCreateTime(int current, int size, String beginTime, String endTime, List records, long total) { - String url = String.format("https://mailbox.biutag.com/api/api/mail?current=%s&size=%s&beginTime=%s&endTime=%s", current, size, beginTime, endTime); - HttpResponse httpResponse = HttpUtil.createGet(url) - .auth("chuangke") - .execute(); - JSONObject data = JSON.parseObject(httpResponse.body()); - records.addAll(data.getList("records", MailOuter.class)); - if (total <= records.size()) { - return new Page().setTotal(total).setRecords(records); - } - return pageMailOuterByCreateTime(++current, size, beginTime, endTime, records); - } - -} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/domain/bo/MailApiV1Req.java b/mailbox-lan/src/main/java/com/biutag/lan/domain/bo/MailApiV1Req.java new file mode 100644 index 0000000..0459115 --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/domain/bo/MailApiV1Req.java @@ -0,0 +1,92 @@ +package com.biutag.lan.domain.bo; + +import com.biutag.lan.domain.MailSource; +import com.biutag.validator.annotation.IdCard; +import com.biutag.validator.annotation.Phone; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.validator.constraints.Length; +import org.springframework.beans.BeanUtils; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +@Setter +@Getter +public class MailApiV1Req { + + /** + * + */ + @NotBlank + private String id; + + /** + * 联系人姓名 + */ + @NotBlank(message = "请输入联系人姓名") + private String contactName; + + /** + * 联系人性别 M / F + */ + private String contactSex; + + /** + * 联系人身份证号 + */ + @IdCard + private String contactIdCard; + + /** + * 联系人手机号 + */ + @Phone + private String contactPhone; + + /** + * 案件编号 + */ + private String caseNumber; + + /** + * 内容 + */ + @Length(min= 10, max = 300, message = "信件内容不符合规范(不少于10字,不多于300字)") + @NotBlank(message = "请输入信件内容") + private String content; + + /** + * 附件 + */ + private String attachments; + + /** + * 创建时间 + */ + @NotNull + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + /** + * 涉及单位ID + */ + private Integer involvedDeptId; + + /** + * 涉及单位名称 + */ + private String involvedDeptName; + + + private String source = MailSource.Source.MAILBOX.getValue(); + + public MailOuter toMailOuter() { + MailOuter mailOuter = new MailOuter(); + BeanUtils.copyProperties(this, mailOuter); + return mailOuter; + } + +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/impl/PoliceUserServiceImpl.java b/mailbox-lan/src/main/java/com/biutag/lan/service/impl/PoliceUserServiceImpl.java index 7ba58b8..3b76474 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/service/impl/PoliceUserServiceImpl.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/impl/PoliceUserServiceImpl.java @@ -16,6 +16,7 @@ import com.biutag.lan.mapper.PoliceUserMapper; import com.biutag.lan.service.IDeptService; import com.biutag.lan.service.IPermService; import com.biutag.lan.service.IPoliceUserService; +import com.biutag.lan.service.IPostService; import com.biutag.lan.validate.commons.PageValidate; import com.biutag.lan.validate.system.PoliceUserCreateValidate; import com.biutag.lan.validate.system.PoliceUserSearchValidate; @@ -62,6 +63,9 @@ public class PoliceUserServiceImpl implements IPoliceUserService { @Resource IDeptService deptService; + @Resource + IPostService iPostService; + /** * 管理员列表 * @@ -95,7 +99,6 @@ public class PoliceUserServiceImpl implements IPoliceUserService { return PageResult.iPageHandle(pages); } - /** * 管理员列表 * @@ -282,6 +285,8 @@ public class PoliceUserServiceImpl implements IPoliceUserService { this.batchSaveDepartByEmpNo(createValidate.getEmpNo(), Collections.singletonList(createValidate.getDeptIds())); model.setPostIds(createValidate.getPostIds().toString()); + PostVo post = iPostService.detail(createValidate.getPostIds()); + model.setPostTitle(post.getName()); this.batchSavePositionByEmpNo(createValidate.getEmpNo(), Collections.singletonList(createValidate.getPostIds())); model.setEmpNo(createValidate.getEmpNo()); model.setName(createValidate.getName()); @@ -344,6 +349,8 @@ public class PoliceUserServiceImpl implements IPoliceUserService { if(StringUtils.isNotNull(updateValidate.getPostIds())) { model.setPostIds(updateValidate.getPostIds().toString()); + PostVo post = iPostService.detail(updateValidate.getPostIds()); + model.setPostTitle(post.getName()); if(!policeUser.getPostIds().equals(model.getPostIds())){ this.batchSavePositionByEmpNo(updateValidate.getEmpNo(), Collections.singletonList(updateValidate.getPostIds())); } diff --git a/mailbox-lan/src/main/resources/mapper/PoliceUserMapper.xml b/mailbox-lan/src/main/resources/mapper/PoliceUserMapper.xml index 0b13f51..86ce445 100644 --- a/mailbox-lan/src/main/resources/mapper/PoliceUserMapper.xml +++ b/mailbox-lan/src/main/resources/mapper/PoliceUserMapper.xml @@ -5,7 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"