.split()
使用 / 作为分割符时需要进行转义: .split("//")
消息队列传输字段类型
两边是通过消息队列传输,对象中的属性只要名称一致就可以,类型不一定一致
Bigdecimal
stripTrailingZeros() 是去掉末尾的0
toPlainString() 是转字符串的
decimal(16,5)
@Digits(integer = 11, fraction = 5, message = "整数不能超过11位,小数不能超过5位")
分页失效
mybatis框架中的分页:PageHelper插件,默认配置分页合理化参数(reasonable)为false
- 分页合理化参数(reasonable)
- false ——> 查不到数据返回为空
- true ——> 查不到数据返回有数据的一页
PageHelper.startPage(req.getStartPage(), req.getPageSize(), true, Boolean.FALSE, null);
PageInfo pageInfo = new PageInfo<>(this.selectList(buildListParam(req)));
包冲突问题:重复bean
问题:服务发版失败
原因:公共服务的包:对应用做限流,其中声明了一个bean:RequestOriginParser,由于我们的应用原本就接了限流,所以我们有自己声明的RequestOriginParser,这样应用在启动时就不知道用谁的了。
使用 @Primary 可以指定用哪个bean
Integer比较
Integer比较不要直接用>=,超过127后,会比较地址,不再是比较数值
Feign接口调用接不到参数
Result<PageInfo<ProtocolItemResp>> listResult = = purchaseExtraServiceClient.vmiSpareProtocolQuery(req);
报错信息
feign接口调用报错服务器处理错误
java.lang.RuntimeException: feign.codec.DecodeException: Error while extracting response for type [com.fehorizon.framework.core.model.Result<com.github.pagehelper.PageInfo<com.fehorizon.purchase.dto.resp.vmi.ProtocolItemResp>>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2024-01-01 00:00:00": not a valid representation (error: Failed to parse Date value '2024-01-01 00:00:00': Cannot parse date "2024-01-01 00:00:00": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2024-01-01 00:00:00": not a valid representation (error: Failed to parse Date value '2024-01-01 00:00:00': Cannot parse date "2024-01-01 00:00:00": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null))
原因:ProtocolItemResp类中有日期DATE格式的数据,但是并未用@JsonFormat注解格式化日期,在数据传输中,缺少了时区信息,导致接收报错
解决:日期加@JsonFormat注解
导出条数可能造成Full GC
导出限制条数的原因:
1、数据不应该以这种形式输出,量大的导出应该走流程导出,不应该用功能,这个属于信息安全的范畴,不过目前的界定没有那么严格
2、性能消耗太大,是我们限制加限制的主要目的
限制条数之后导致导出失败可能造成Full GC
虽然这里限制了5000,但是问题就在于用户没导出来,内存还是消耗了
protocolItemRespList.addAll(protocolItemRespPageInfo.getList())
public void exportVmiProtocol(String supplierCode, String itemNo, String itemName, String originalCode,String accountSetCode, HttpServletResponse response) {
StopWatch stopWatch = new StopWatch();
stopWatch.start("导出补货申请新增商品明细...");
// 初始化数据
SearchProtocolItemReqVo reqVo = new SearchProtocolItemReqVo();
reqVo.setSupplierCode(supplierCode);
reqVo.setItemNo(itemNo);
reqVo.setItemName(itemName);
reqVo.setOriginalCode(originalCode);
reqVo.setAccountSetCode(accountSetCode);
reqVo.setPageSize(200);
List<ProtocolItemResp> protocolItemRespList = new ArrayList<>();
PageInfo<ProtocolItemResp> protocolItemRespPageInfo = purchaseExtraService.vmiSpareProtocolQuery(reqVo);
long total = protocolItemRespPageInfo.getTotal();
Integer maxCountConfig = ApolloConfigUtil.getIntConfig("export.vmi.protocol.max-count", 50);
// 最大导出数量
if (total > 0) {
Assert.isTrue(total < maxCountConfig, I18nStaticEnum1.static_text_11523.getCode());
// 第一页数据
protocolItemRespList.addAll(protocolItemRespPageInfo.getList());
// 判断是否是最后一页
if(protocolItemRespPageInfo.getPageNum() < protocolItemRespPageInfo.getPages()) {
// 不是最后一页,继续查询
List<CompletableFuture<PageInfo<ProtocolItemResp>>> futureList = new ArrayList<>();
int currentPage = protocolItemRespPageInfo.getPageNum();
do {
reqVo.setPageNum(currentPage + 1);
futureList.add(CompletableFuture.supplyAsync(() -> purchaseExtraService.vmiSpareProtocolQuery(reqVo), executor));
currentPage++;
} while (currentPage < protocolItemRespPageInfo.getPages());
CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])).join();
List<PageInfo<ProtocolItemResp>> pageInfoList = futureList.stream().map(CompletableFuture::join).collect(Collectors.toList());
pageInfoList.forEach(pageInfo -> protocolItemRespList.addAll(pageInfo.getList()));
}
}
// 构建Excel
ExcelWriter writer = cn.hutool.poi.excel.ExcelUtil.getBigWriter();
writer.writeHeadRow(Lists.newArrayList(WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12137),
WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12138),
WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12340),
WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12341),
WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12342),
WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12356),
WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12357),
WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12343)));
writer.getHeadCellStyle().setAlignment(HorizontalAlignment.CENTER);
writer.getHeadCellStyle().setVerticalAlignment(VerticalAlignment.CENTER);
CellStyle cellStyle = writer.getStyleSet().getCellStyle();
cellStyle.setAlignment(HorizontalAlignment.LEFT);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
writer.getStyleSet().getCellStyleForDate().setDataFormat((short) 0xe);
List<Map<String, Object>> result = new LinkedList<>();
// 数据填充
protocolItemRespList.forEach(protocolItemResp -> {
Map<String, Object> o = new LinkedHashMap<>();
o.put(WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12137), protocolItemResp.getItemNo());
o.put(WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12138), protocolItemResp.getItemName());
o.put(WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12340), protocolItemResp.getOriginalCode());
o.put(WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12341), protocolItemResp.getUnitName());
o.put(WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12342), protocolItemResp.getSpecModel());
o.put(WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12356), protocolItemResp.getAgreementName());
o.put(WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12357), protocolItemResp.getAgreementNo());
o.put(WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12343), protocolItemResp.getAgreementDetailUuid());
result.add(o);
});
writer.write(result, false);
SXSSFSheet sheet = (SXSSFSheet) writer.getSheet();
sheet.trackAllColumnsForAutoSizing();
writer.autoSizeColumn(0);
writer.autoSizeColumn(1);
writer.autoSizeColumn(2);
writer.autoSizeColumn(3);
writer.autoSizeColumn(4);
writer.autoSizeColumn(5);
writer.autoSizeColumn(6);
writer.autoSizeColumn(7);
try {
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + new String((WmsI18nUtil.getI18nMsg(I18nStaticEnum2.static_text_12344)).getBytes()));
writer.flush(response.getOutputStream());
} catch (IOException e) {
log.error("导出补货申请新增商品明细数据异常:{}", e.getMessage(), e);
} finally {
writer.close();
}
stopWatch.stop();
log.info("导出补货申请新增商品明细时长:{}", stopWatch.prettyPrint());
}