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/MailReturn.java b/mailbox-lan/src/main/java/com/biutag/lan/domain/MailReturn.java index 5b56cc8..6028352 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/domain/MailReturn.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/domain/MailReturn.java @@ -15,14 +15,17 @@ public class MailReturn { @TableId(type = IdType.AUTO) private Integer id; + /** * */ private String mailId; + /** * 退回原因 */ private String reason; + /** * */ @@ -37,12 +40,15 @@ public class MailReturn { * */ private Integer handlerDeptId; + /** * */ private String handlerDeptName; + /** * */ private LocalDateTime createTime; -} + +} \ No newline at end of file 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/flow/node/CountersignFlow.java b/mailbox-lan/src/main/java/com/biutag/lan/flow/node/CountersignFlow.java index a4036d2..3437753 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/flow/node/CountersignFlow.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/flow/node/CountersignFlow.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.Assert; import java.time.LocalDateTime; +import java.util.Comparator; import java.util.List; import java.util.Optional; @@ -53,7 +54,7 @@ public class CountersignFlow extends Flow { return null; } List mailFlows = mailFlowService.list(mailId); - MailFlow mailFlow = mailFlows.stream().filter(item -> item.getFlowAfterName().equals("发起会签")).findFirst().get(); + MailFlow mailFlow = mailFlows.stream().sorted(Comparator.comparing(MailFlow::getCreateTime).reversed()).filter(item -> item.getFlowAfterName().equals("发起会签")).findFirst().get(); List flowNodes = flowNodeService.list(); String flowBeforeName = flowNodes.stream().filter(item -> item.getKey().equals(mailFlow.getFlowKey())).findFirst().map(FlowNode::getBeforeName).get(); // 会签完成 diff --git a/mailbox-lan/src/main/java/com/biutag/lan/flow/node/FirstApprovalFlow.java b/mailbox-lan/src/main/java/com/biutag/lan/flow/node/FirstApprovalFlow.java index 7f7d459..d360982 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/flow/node/FirstApprovalFlow.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/flow/node/FirstApprovalFlow.java @@ -95,7 +95,6 @@ public class FirstApprovalFlow extends Flow { public Flow mailReturn(String mailId, JSONObject data) { LocalDateTime now = LocalDateTime.now(); String returnOperate = data.getString("returnOperate"); - Assert.hasText(returnOperate, "参数错误"); String reason = data.getString("reason"); Assert.hasText(reason, "参数错误"); Mail mail = mailService.getById(mailId); @@ -115,6 +114,7 @@ public class FirstApprovalFlow extends Flow { // 更新信件 mail.setUpdateTime(now) .setFlowKey(FlowNodeEnum.SECOND_APPROVAL.getKey()) + .setCurrentOperator(String.format("%s专班", mail.getSecondDeptName())) .setReturnOperate(returnOperate); mailService.updateById(mail); return null; 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 00c82fa..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); } - /** * 管理员列表 * @@ -280,9 +283,11 @@ public class PoliceUserServiceImpl implements IPoliceUserService { model.setDeptIds(createValidate.getDeptIds().toString()); model.setDeptName(deptVo.getName()); - this.batchSaveDepartByEmpNo(createValidate.getEmpNo(), Arrays.asList(createValidate.getDeptIds())); + this.batchSaveDepartByEmpNo(createValidate.getEmpNo(), Collections.singletonList(createValidate.getDeptIds())); model.setPostIds(createValidate.getPostIds().toString()); - this.batchSavePositionByEmpNo(createValidate.getEmpNo(), Arrays.asList(createValidate.getPostIds())); + 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()); model.setAvatar(avatar); @@ -343,6 +348,9 @@ public class PoliceUserServiceImpl implements IPoliceUserService { model.setDeptName(deptVo.getName()); 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 694253d..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"