1、cad拆单支持造型数据压缩存入mysql;2、未排单数据、计算用板量、优化生产接口支持mysql造型数据替换es造型数据;

This commit is contained in:
gaoqr
2026-05-12 09:50:18 +08:00
parent ba914beb16
commit 9f9941e71e
19 changed files with 291 additions and 98 deletions
@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
@@ -75,7 +76,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(text, clazz);
} catch (IOException e) {
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -89,7 +90,7 @@ public class JsonUtils {
JsonNode pathNode = treeNode.path(path);
return objectMapper.readValue(pathNode.toString(), clazz);
} catch (IOException e) {
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -101,7 +102,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(text, objectMapper.getTypeFactory().constructType(type));
} catch (IOException e) {
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -129,7 +130,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(bytes, clazz);
} catch (IOException e) {
log.error(JSON_PARSE_ERROR_NOTIFICATION, bytes, e);
// log.error(JSON_PARSE_ERROR_NOTIFICATION, bytes, e);
throw new RuntimeException(e);
}
}
@@ -138,7 +139,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(text, typeReference);
} catch (IOException e) {
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -150,7 +151,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
} catch (IOException e) {
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -164,7 +165,7 @@ public class JsonUtils {
JsonNode pathNode = treeNode.path(path);
return objectMapper.readValue(pathNode.toString(), objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
} catch (IOException e) {
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -173,7 +174,7 @@ public class JsonUtils {
try {
return objectMapper.readTree(text);
} catch (IOException e) {
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -182,7 +183,7 @@ public class JsonUtils {
try {
return objectMapper.readTree(text);
} catch (IOException e) {
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
// log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -269,5 +270,80 @@ public class JsonUtils {
}
}
/**
* 压缩
*
* @param str
* @return
*/
public static byte[] zip(String str) {
Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION);
deflater.setInput(str.getBytes(StandardCharsets.UTF_8));
deflater.finish();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
while (!deflater.finished()) {
int len = deflater.deflate(buffer);
outputStream.write(buffer, 0, len);
}
deflater.end();
return outputStream.toByteArray();
}
/**
* 解压缩
*
* @param data
* @return
*/
public static String unzip(byte[] data) {
Inflater inflater = new Inflater();
inflater.setInput(data);
byte[] buffer = new byte[1024];
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
while (!inflater.finished()) {
int len = inflater.inflate(buffer);
// 防止异常数据导致死循环
if (len == 0) {
if (inflater.needsInput()) {
break;
}
if (inflater.needsDictionary()) {
throw new RuntimeException("Inflater needs dictionary");
}
}
outputStream.write(buffer, 0, len);
}
return outputStream.toString(StandardCharsets.UTF_8);
} catch (DataFormatException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
inflater.end();
}
}
}
@@ -0,0 +1,74 @@
package com.cf.imes.framework.mybatis.core.type;
import com.cf.imes.framework.common.util.json.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* mb自定义压缩字符串到byte[]类型转换器
*
* @author Gqr
* @since 2026/5/11 14:22
*/
public class CompressByteTypeHandler extends BaseTypeHandler<String> {
@Override
public void setNonNullParameter(
PreparedStatement ps,
int i,
String parameter,
JdbcType jdbcType
) throws SQLException {
if (StringUtils.isBlank(parameter)) {
ps.setBytes(i, null);
return;
}
byte[] compressed = JsonUtils.zip(parameter);
ps.setBytes(i, compressed);
}
@Override
public String getNullableResult(ResultSet rs, String columnName)
throws SQLException {
byte[] bytes = rs.getBytes(columnName);
return unzip(bytes);
}
@Override
public String getNullableResult(ResultSet rs, int columnIndex)
throws SQLException {
byte[] bytes = rs.getBytes(columnIndex);
return unzip(bytes);
}
@Override
public String getNullableResult(CallableStatement cs, int columnIndex)
throws SQLException {
byte[] bytes = cs.getBytes(columnIndex);
return unzip(bytes);
}
private String unzip(byte[] bytes) {
if (bytes == null || bytes.length == 0) {
return null;
}
return JsonUtils.unzip(bytes);
}
}