Browse Source

BUG 修复

master
wxc 2 years ago
parent
commit
b6adf44d4d
  1. 7
      mailbox-common/src/main/java/com/biutag/config/Minio.java
  2. 22
      mailbox-common/src/main/java/com/biutag/exception/GlobalException.java
  3. 3
      mailbox-lan/sql/0312.sql
  4. 5
      mailbox-lan/sql/0313.sql
  5. 3
      mailbox-lan/src/main/java/com/biutag/lan/enums/MailState.java
  6. 4
      mailbox-lan/src/main/java/com/biutag/lan/flow/node/FirstSignFlow.java
  7. 1
      mailbox-lan/src/main/java/com/biutag/lan/service/MailService.java
  8. 2
      mailbox-outer/src/main/java/com/biutag/outer/config/InterceptorConfig.java
  9. 37
      mailbox-outer/src/main/java/com/biutag/outer/controller/FileController.java
  10. 5
      mailbox-outer/src/main/java/com/biutag/outer/job/Job.java
  11. 9
      mailbox-outer/src/main/resources/application.yml
  12. 21
      mailbox-outer/src/test/java/com/biutag/outer/JSONTest.java

7
mailbox-common/src/main/java/com/biutag/config/Minio.java

@ -7,6 +7,8 @@ import com.biutag.exception.MinioOperateException;
import com.biutag.util.IOUtil;
import io.minio.*;
import io.minio.errors.*;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import java.io.ByteArrayOutputStream;
@ -19,6 +21,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Date;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@ConditionalOnProperty(value = "oss.minio.enable")
public class Minio {
@ -28,10 +31,14 @@ public class Minio {
public Minio(MinioProperties properties) {
this.properties = properties;
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectionPool(new ConnectionPool(20, 5L, TimeUnit.MINUTES))
.build();
// 创建MinIO客户端
this.minioClient = MinioClient.builder()
.endpoint(properties.getEndpoint())
.credentials(properties.getAccessKey(), properties.getSecretKey())
.httpClient(okHttpClient)
.build();
BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder()
.bucket(properties.getBucketName())

22
mailbox-common/src/main/java/com/biutag/exception/GlobalException.java

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.biutag.config.GlobalConfig;
import com.biutag.core.AjaxResult;
import com.biutag.enums.ErrorEnum;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
@ -33,11 +35,11 @@ public class GlobalException {
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler(Exception.class)
@ResponseBody
public AjaxResult<Object> handleException(Exception e) {
if (GlobalConfig.debug) {
e.printStackTrace();
public AjaxResult<Object> handleException(Exception e, HttpServletResponse response) {
if ("application/javascript;charset=UTF-8".equals(response.getHeader("Content-Type"))) {
return null;
}
log.error("系统异常 {}", e.getMessage());
log.error("系统异常 {}", e.getMessage(), e);
return AjaxResult.failed(ErrorEnum.SYSTEM_ERROR.getCode(), e.getMessage());
}
@ -48,6 +50,7 @@ public class GlobalException {
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseBody
public AjaxResult<Object> handleNoHandlerFoundException(NoHandlerFoundException e) {
log.error(e.getMessage());
return AjaxResult.failed(ErrorEnum.REQUEST_404_ERROR.getCode(), e.getMessage());
}
@ -60,6 +63,7 @@ public class GlobalException {
public AjaxResult<Object> handleException(BaseException e) {
int code = e.getCode();
String msg = e.getMsg();
log.error(e.getMessage());
return AjaxResult.failed(code, msg);
}
@ -73,6 +77,7 @@ public class GlobalException {
BindingResult bindingResult = e.getBindingResult();
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode();
String msg = Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage();
log.error(e.getMessage());
return AjaxResult.failed(code, msg);
}
@ -84,8 +89,8 @@ public class GlobalException {
@ResponseBody
public AjaxResult<Object> handlePathException(MissingServletRequestParameterException e) {
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode();
String msg = Objects.requireNonNull(e.getMessage());
return AjaxResult.failed(code, msg);
log.error(e.getMessage());
return AjaxResult.failed(code, e.getMessage());
}
/**
@ -98,6 +103,7 @@ public class GlobalException {
BindingResult bindingResult = e.getBindingResult();
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode();
String msg = Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage();
log.error(e.getMessage());
return AjaxResult.failed(code, msg);
}
@ -110,6 +116,7 @@ public class GlobalException {
public AjaxResult<Object> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
Integer code = ErrorEnum.PARAMS_TYPE_ERROR.getCode();
String msg = Objects.requireNonNull(e.getMessage());
log.error(e.getMessage());
return AjaxResult.failed(code, msg.split(";")[0]);
}
@ -122,6 +129,7 @@ public class GlobalException {
public AjaxResult<Object> handleRequestMethodException(HttpRequestMethodNotSupportedException e) {
Integer code = ErrorEnum.REQUEST_METHOD_ERROR.getCode();
String msg = Objects.requireNonNull(e.getMessage());
log.error(e.getMessage());
return AjaxResult.failed(code, msg);
}
@ -147,6 +155,7 @@ public class GlobalException {
public AjaxResult<Object> handleMybatisPlusException(MybatisPlusException e) {
Integer code = ErrorEnum.ASSERT_MYBATIS_ERROR.getCode();
String msg = Objects.requireNonNull(e.getMessage());
log.error(e.getMessage(), e);
return AjaxResult.failed(code, msg);
}
@ -155,6 +164,7 @@ public class GlobalException {
@ResponseBody
public AjaxResult<Object> handleMinioOperateException(MinioOperateException e) {
Integer code = ErrorEnum.SYSTEM_ERROR.getCode();
log.error(e.getMessage(), e);
return AjaxResult.failed(code, String.format("Minio 操作异常:%s", e.getMessage()));
}

3
mailbox-lan/sql/0312.sql

@ -0,0 +1,3 @@
update police_user set dept_ids = data_dept_id where role_ids = 1;
update police_user set data_dept_id = 1 where role_ids = 1;

5
mailbox-lan/sql/0313.sql

@ -0,0 +1,5 @@
update mail set mail_state = '' where mail_category in ('无效类', '', '');
ALTER TABLE mail ALTER COLUMN contact_id_card DROP NOT NULL;
ALTER TABLE mail_source ALTER COLUMN contact_id_card DROP NOT NULL;

3
mailbox-lan/src/main/java/com/biutag/lan/enums/MailState.java

@ -8,6 +8,7 @@ import lombok.Getter;
public enum MailState {
processing("processing", "办理中"),
terminated("terminated", "已终止"),
delayed("delayed", "已延期"),
completion("completion", "已办结");
@ -15,4 +16,4 @@ public enum MailState {
private String name;
}
}

4
mailbox-lan/src/main/java/com/biutag/lan/flow/node/FirstSignFlow.java

@ -105,7 +105,7 @@ public class FirstSignFlow extends Flow {
.setMailCategory(mailFirstCategory)
.setSecondDeptId(secondDeptId)
.setThreeDeptId(threeDeptId)
.setMailState(MailState.completion.name())
.setMailState(MailState.terminated.name())
.setFlowKey(FlowNodeEnum.COMPLETION.getKey())
.setFlowName(FlowNodeEnum.COMPLETION.getFullName())
.setUpdateTime(now);
@ -125,7 +125,7 @@ public class FirstSignFlow extends Flow {
Mail mail = mailSource.toMail()
.setMailFirstCategory(mailFirstCategory)
.setMailCategory(mailFirstCategory)
.setMailState(MailState.completion.name())
.setMailState(MailState.terminated.name())
.setFlowKey(FlowNodeEnum.COMPLETION.getKey())
.setFlowName(FlowNodeEnum.COMPLETION.getFullName())
.setUpdateTime(now)

1
mailbox-lan/src/main/java/com/biutag/lan/service/MailService.java

@ -397,4 +397,5 @@ public class MailService extends ServiceImpl<MailMapper, Mail> {
mailFlowService.save(mailFlow);
return updateById(mail);
}
}

2
mailbox-outer/src/main/java/com/biutag/outer/config/InterceptorConfig.java

@ -2,7 +2,6 @@ package com.biutag.outer.config;
import cn.hutool.core.util.StrUtil;
import com.biutag.exception.AuthException;
import com.biutag.outer.domain.User;
import com.biutag.outer.util.TokenUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@ -41,7 +40,6 @@ public class InterceptorConfig implements WebMvcConfigurer {
System.out.println(authorization);
return true;
}
}
}

37
mailbox-outer/src/main/java/com/biutag/outer/controller/FileController.java

@ -1,19 +1,22 @@
package com.biutag.outer.controller;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.biutag.core.AjaxResult;
import com.biutag.config.Minio;
import com.biutag.core.AjaxResult;
import com.biutag.util.IOUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@Slf4j
@RequestMapping("file")
@ -33,15 +36,43 @@ public class FileController {
@ResponseBody
@PostMapping("upload/base64")
public AjaxResult<JSONObject> upload(@RequestBody JSONObject file) {
long l = System.currentTimeMillis();
log.info("文件上传开始----------------------------------------");
String base64 = file.getString("base64");
log.info("文件上传 base64: {}", StrUtil.isNotBlank(base64) ? base64.substring(0, Math.min(20, base64.length())) : "");
if (base64.startsWith("data:image")) {
base64 = base64.substring(base64.indexOf(",") + 1);
}
String filepath = minio.upload(base64);
log.info("文件上传耗时:{}ms", System.currentTimeMillis() - l);
return AjaxResult.success(JSONObject.of("filepath", filepath));
}
@ResponseBody
@PostMapping("upload/base64/test")
public AjaxResult<JSONObject> uploadTest(@RequestBody JSONObject file) {
long l = System.currentTimeMillis();
String base64 = file.getString("base64");
log.info("test 文件上传 base64: {}", StrUtil.isNotBlank(base64) ? base64.substring(0, Math.min(20, base64.length())) : "");
if (base64.startsWith("data:image")) {
base64 = base64.substring(base64.indexOf(",") + 1);
}
InputStream is = IOUtil.base64ToStream(base64);
try {
FileOutputStream os = new FileOutputStream("/home/jar/files/" + IdUtil.simpleUUID());
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(buffer, 0, buffer.length)) != -1) {
os.write(buffer, 0, bytesRead);
}
is.close();
os.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
log.info("文件上传耗时:{}ms", System.currentTimeMillis() - l);
return AjaxResult.success(JSONObject.of("filepath", "test"));
}
@GetMapping("stream/**")
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException {
String requestURI = request.getRequestURI();

5
mailbox-outer/src/main/java/com/biutag/outer/job/Job.java

@ -7,6 +7,7 @@ import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.biutag.config.Minio;
@ -64,10 +65,12 @@ public class Job {
mail.setAttachments(JSON.toJSONString(attachments));
}
long timestamp = new Date().getTime();
HttpResponse httpResponse = HttpUtil.createPost(mailboxUrl + "mail")
.header("timestamp", String.valueOf(timestamp))
.auth(MD5.create().digestHex(key + timestamp))
.body(JSON.toJSONString(mail))
// 图片base64 过大时,会发生OutOfMemoryError 解决办法 JSONWriter.Feature.WriteClassName, JSONWriter.Feature.LargeObject
.body(JSON.toJSONString(mail, JSONWriter.Feature.WriteClassName, JSONWriter.Feature.LargeObject))
.execute();
if (!httpResponse.isOk()) {
log.error("推送信件内容异常,body: {}", httpResponse.body());

9
mailbox-outer/src/main/resources/application.yml

@ -1,6 +1,13 @@
server:
port: 8080
tongweb:
resource:
cache-max-size: 102400
allow-caching: true
max-threads: 20
min-spare-threads: 10
max-keep-alive-requests: 500
max-http-post-size: 10MB
license:
path: classpath:license/license.dat
@ -16,7 +23,7 @@ spring:
hikari:
connection-timeout: 30000 # 等待连接分配连接的最大时长(毫秒),超出时长还没可用连接则发送SQLException,默认30秒
minimum-idle: 5 # 最小连接数
maximum-pool-size: 20 # 最大连接数
maximum-pool-size: 40 # 最大连接数
auto-commit: true # 自动提交
idle-timeout: 600000 # 连接超时的最大时长(毫秒),超时则被释放(retired),默认10分钟
pool-name: DateSourceHikariCP # 连接池名称

21
mailbox-outer/src/test/java/com/biutag/outer/JSONTest.java

@ -0,0 +1,21 @@
package com.biutag.outer;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.biutag.outer.domain.Mail;
import org.junit.jupiter.api.Test;
public class JSONTest {
@Test
public void testFastJSON() {
Mail mail = new Mail();
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < 5; i++) {
jsonArray.add(JSONObject.of("base64", ""));
}
mail.setAttachments(jsonArray.toJSONString());
System.out.println(JSON.toJSONString(jsonArray));
}
}
Loading…
Cancel
Save