From c69aeb13bfd620ceb98f9131c38ea5c703811f51 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Mon, 24 Apr 2023 13:52:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9dealWithMapping=E7=9A=84?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82?= =?UTF-8?q?=E5=B8=B8bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- .../java/aiyh/utils/fileUtil/pdf/PdfUtil.java | 4 + .../utils/recordset/FloatTypeHandler.java | 27 +-- .../biz/requestForm/RequestRemindBiz.java | 21 +- .../ai/taibao/email/BlackListRegister.java | 32 ++- .../mapper/InitBlackEmailListMapper.java | 4 +- .../config/service/DealWithMapping.java | 24 +- .../youhong/ai/yashilandai/GroupByTime.java | 224 ++++++++++++++++++ .../java/youhong/ai/yashilandai/MyTest.java | 24 ++ 9 files changed, 306 insertions(+), 58 deletions(-) create mode 100644 src/test/java/youhong/ai/yashilandai/GroupByTime.java create mode 100644 src/test/java/youhong/ai/yashilandai/MyTest.java diff --git a/.gitignore b/.gitignore index bfc3e78..7b4e676 100644 --- a/.gitignore +++ b/.gitignore @@ -47,5 +47,5 @@ src/test/resources/font src/main/resources/WEB-INF/vm/outFile target/ *.back -src/main/aiyh_old_src/ -src/main/jitu_src/ \ No newline at end of file +src/main/youhong_ai_old_src/ +src/main/youhong_ai_jitu_src/ \ No newline at end of file diff --git a/src/main/java/aiyh/utils/fileUtil/pdf/PdfUtil.java b/src/main/java/aiyh/utils/fileUtil/pdf/PdfUtil.java index c0c3bab..b6d62af 100644 --- a/src/main/java/aiyh/utils/fileUtil/pdf/PdfUtil.java +++ b/src/main/java/aiyh/utils/fileUtil/pdf/PdfUtil.java @@ -2,6 +2,7 @@ package aiyh.utils.fileUtil.pdf; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; +import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Image; import com.itextpdf.text.pdf.PdfContentByte; @@ -107,6 +108,9 @@ public class PdfUtil { } InputStream inputStream = ImageFileManager.getInputStreamById(pdfImageFileId); List keywordPoints = findKeywordPoints(inputStream, keyword); + if (CollectionUtil.isEmpty(keywordPoints)) { + throw new CustomerException("关键字定位异常,未发现关键字!"); + } PdfReader pdfReader = null; Image image = null; try { diff --git a/src/main/java/aiyh/utils/recordset/FloatTypeHandler.java b/src/main/java/aiyh/utils/recordset/FloatTypeHandler.java index 0e7e65d..ec47a9a 100644 --- a/src/main/java/aiyh/utils/recordset/FloatTypeHandler.java +++ b/src/main/java/aiyh/utils/recordset/FloatTypeHandler.java @@ -27,11 +27,7 @@ public class FloatTypeHandler implements TypeHandler { } return 0.0F; } - float v = Float.parseFloat(string); - if (!string.equals(String.valueOf(v))) { - return Double.parseDouble(string); - } - return v; + return Float.parseFloat(string); } @Override @@ -45,11 +41,8 @@ public class FloatTypeHandler implements TypeHandler { } return 0.0F; } - float v = Float.parseFloat(string); - if (!string.equals(String.valueOf(v))) { - return Double.parseDouble(string); - } - return v; + + return Float.parseFloat(string); } @Override @@ -63,11 +56,8 @@ public class FloatTypeHandler implements TypeHandler { } return 0.0F; } - float v = Float.parseFloat(string); - if (!string.equals(String.valueOf(v))) { - return Double.parseDouble(string); - } - return v; + + return Float.parseFloat(string); } @Override @@ -81,11 +71,8 @@ public class FloatTypeHandler implements TypeHandler { } return 0.0F; } - float v = Float.parseFloat(string); - if (!string.equals(String.valueOf(v))) { - return Double.parseDouble(string); - } - return v; + + return Float.parseFloat(string); } } diff --git a/src/main/java/com/engine/workflow/biz/requestForm/RequestRemindBiz.java b/src/main/java/com/engine/workflow/biz/requestForm/RequestRemindBiz.java index 8d1790f..ed3b7d9 100644 --- a/src/main/java/com/engine/workflow/biz/requestForm/RequestRemindBiz.java +++ b/src/main/java/com/engine/workflow/biz/requestForm/RequestRemindBiz.java @@ -1746,9 +1746,14 @@ public class RequestRemindBiz { } } /* ******************* youhong.ai 添加发送邮箱的黑名单拓展start ******************* */ - Set expansionList = BlackListRegister.getExpansionList(mailAddress); - if (Objects.nonNull(expansionList)) { - mailAddress = expansionList; + + try { + Set expansionList = BlackListRegister.getExpansionList(mailAddress); + if (Objects.nonNull(expansionList)) { + mailAddress = expansionList; + } + } catch (Exception e) { + aiyh.utils.Util.getLogger().error("过滤黑名单日志失败:" + aiyh.utils.Util.getErrString(e)); } /* ******************* youhong.ai 添加发送邮箱的黑名单拓展 end ******************* */ if (mailAddress.isEmpty()) return; @@ -1781,9 +1786,13 @@ public class RequestRemindBiz { } } /* ******************* youhong.ai 添加发送邮箱的黑名单拓展start ******************* */ - Set expansionList = BlackListRegister.getExpansionApproveList(mailAddress); - if (Objects.nonNull(expansionList)) { - mailAddress = expansionList; + try { + Set expansionList = BlackListRegister.getExpansionApproveList(mailAddress); + if (Objects.nonNull(expansionList)) { + mailAddress = expansionList; + } + } catch (Exception e) { + aiyh.utils.Util.getLogger().error("过滤黑名单日志失败:" + aiyh.utils.Util.getErrString(e)); } /* ******************* youhong.ai 添加发送邮箱的黑名单拓展 end ******************* */ EmailApprovalRunnable.threadModeReminder(String.join(",", mailAddress), title, content, String.valueOf(requestId), allAttchment); diff --git a/src/main/java/com/engine/youhong/ai/taibao/email/BlackListRegister.java b/src/main/java/com/engine/youhong/ai/taibao/email/BlackListRegister.java index 314f70d..1d41a40 100644 --- a/src/main/java/com/engine/youhong/ai/taibao/email/BlackListRegister.java +++ b/src/main/java/com/engine/youhong/ai/taibao/email/BlackListRegister.java @@ -2,8 +2,8 @@ package com.engine.youhong.ai.taibao.email; import aiyh.utils.Util; import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil; -import aiyh.utils.tool.cn.hutool.core.util.StrUtil; import com.engine.youhong.ai.taibao.email.mapper.InitBlackEmailListMapper; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Objects; @@ -28,33 +28,31 @@ public class BlackListRegister { return null; } List hrmList = mapper.selectWorkflowBlackEmailList(); - if (CollectionUtil.isEmpty(hrmList)) { - return null; - } - String ids = Util.join(hrmList, ","); - List blackEmailList = mapper.selectEmailListByHrmIds(ids); - if (CollectionUtil.isEmpty(blackEmailList)) { - return set; - } - return set.stream() - .filter(item -> !blackEmailList.contains(item)) - .collect(Collectors.toSet()); + return getBlackListEamil(set, hrmList); } public static Set getExpansionApproveList(Set set) { if (Objects.isNull(set)) { return null; } - String ids = mapper.selectWorkflowApproveBlackEmailList(); - if (StrUtil.isBlank(ids)) { + List hrmList = mapper.selectWorkflowApproveBlackEmailList(); + return getBlackListEamil(set, hrmList); + } + + @Nullable + private static Set getBlackListEamil(Set set, List hrmList) { + if (CollectionUtil.isEmpty(hrmList)) { return null; } + String ids = Util.join(hrmList, ","); List blackEmailList = mapper.selectEmailListByHrmIds(ids); if (CollectionUtil.isEmpty(blackEmailList)) { return null; } - return set.stream() - .filter(item -> !blackEmailList.contains(item)) - .collect(Collectors.toSet()); + Set collect = set.stream() + .filter(item -> !blackEmailList.contains(item)) + .collect(Collectors.toSet()); + Util.getLogger().info("拦截后邮箱:" + collect); + return collect; } } diff --git a/src/main/java/com/engine/youhong/ai/taibao/email/mapper/InitBlackEmailListMapper.java b/src/main/java/com/engine/youhong/ai/taibao/email/mapper/InitBlackEmailListMapper.java index cb23cce..889f79e 100644 --- a/src/main/java/com/engine/youhong/ai/taibao/email/mapper/InitBlackEmailListMapper.java +++ b/src/main/java/com/engine/youhong/ai/taibao/email/mapper/InitBlackEmailListMapper.java @@ -29,8 +29,8 @@ public interface InitBlackEmailListMapper { * * @return email黑名单 */ - @Select("select email from uf_black_email_conf where type = 1") - String selectWorkflowApproveBlackEmailList(); + @Select("select black_hrm from uf_black_email_conf where type = 0") + List selectWorkflowApproveBlackEmailList(); /** diff --git a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java index 01a10f9..6f165eb 100644 --- a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java +++ b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java @@ -123,7 +123,7 @@ public class DealWithMapping extends ToolUtil { continue; } if ("DOUBLE".equalsIgnoreCase(type)) { - map.put(key,Util.getDoubleValue(rs.getString(i))); + map.put(key, Util.getDoubleValue(rs.getString(i))); continue; } if ("DECIMAL".equalsIgnoreCase(type) || "NUMERIC".equalsIgnoreCase(type)) { @@ -465,8 +465,7 @@ public class DealWithMapping extends ToolUtil { } tempList.add(map); } - } - else { + } else { tempList.add(o); } } @@ -559,8 +558,7 @@ public class DealWithMapping extends ToolUtil { } tempList.add(map); } - } - else{ + } else { tempList.add(o); } } @@ -627,14 +625,18 @@ public class DealWithMapping extends ToolUtil { String fieldName = fieldMassage.getFieldName(); String fieldNameLowe = fieldName.toLowerCase(); if ("1".equals(childSource)) { - workFlowVal = Util.null2String(detailMap.get(fieldNameLowe)); - if ("".equals(workFlowVal)) { - workFlowVal = Util.null2String(detailMap.get(fieldName)); + if (Objects.nonNull(detailMap)) { + workFlowVal = Util.null2String(detailMap.get(fieldNameLowe)); + if ("".equals(workFlowVal)) { + workFlowVal = Util.null2String(detailMap.get(fieldName)); + } } } else if ("0".equals(childSource)) { - workFlowVal = Util.null2String(mainMap.get(fieldNameLowe)); - if ("".equals(workFlowVal)) { - workFlowVal = Util.null2String(mainMap.get(fieldName)); + if (Objects.nonNull(mainMap)) { + workFlowVal = Util.null2String(mainMap.get(fieldNameLowe)); + if ("".equals(workFlowVal)) { + workFlowVal = Util.null2String(mainMap.get(fieldName)); + } } } } diff --git a/src/test/java/youhong/ai/yashilandai/GroupByTime.java b/src/test/java/youhong/ai/yashilandai/GroupByTime.java new file mode 100644 index 0000000..7c02caf --- /dev/null +++ b/src/test/java/youhong/ai/yashilandai/GroupByTime.java @@ -0,0 +1,224 @@ +package youhong.ai.yashilandai; + +import com.alibaba.fastjson.JSON; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +public class GroupByTime { + public static void main(String[] args) { + // 假设我们有一个包含Map对象的List + List> list = new ArrayList<>(); + + // 向List中添加一些Map对象,每个Map对象都有一个createTime键,值为yyyy-MM-dd HH:mm:ss格式的时间字符串 + Map map1 = new HashMap<>(); + map1.put("createTime", "2022-04-24 12:34:56"); + map1.put("type", "test_1"); + list.add(map1); + + Map map2 = new HashMap<>(); + map2.put("createTime", "2022-04-23 11:22:33"); + map2.put("type", "test_1"); + list.add(map2); + + Map map3 = new HashMap<>(); + map3.put("createTime", "2022-04-22 10:11:12"); + map3.put("type", "test_1"); + list.add(map3); + + Map map4 = new HashMap<>(); + map4.put("createTime", "2022-04-21 09:08:07"); + map4.put("type", "test_1"); + list.add(map4); + + Map map5 = new HashMap<>(); + map5.put("createTime", "2022-04-20 08:07:06"); + map5.put("type", "test_2"); + list.add(map5); + + Map map6 = new HashMap<>(); + map6.put("createTime", "2022-04-19 07:06:05"); + map6.put("type", "test_2"); + list.add(map6); + + Map map7 = new HashMap<>(); + map7.put("createTime", "2022-04-18 06:05:04"); + map7.put("type", "test_2"); + list.add(map7); + + Map map8 = new HashMap<>(); + map8.put("createTime", "2022-04-17 05:04:03"); + map8.put("type", "test_3"); + list.add(map8); + + Map map9 = new HashMap<>(); + map9.put("createTime", "2022-04-16 05:04:03"); + map9.put("type", "test_4"); + list.add(map9); + + Map map10 = new HashMap<>(); + map10.put("createTime", "2022-04-15 05:04:03"); + map10.put("type", "test_1"); + list.add(map10); + + Map map11 = new HashMap<>(); + map11.put("createTime", "2022-04-14 05:04:03"); + map11.put("type", "test_2"); + list.add(map11); + + Map map12 = new HashMap<>(); + map12.put("createTime", "2022-04-09 05:04:03"); + map12.put("type", "test_1"); + list.add(map12); + + Map map13 = new HashMap<>(); + map13.put("createTime", "2022-04-13 05:04:03"); + map13.put("type", "test_1"); + list.add(map13); + + Map map14 = new HashMap<>(); + map14.put("createTime", "2022-04-12 05:04:03"); + map14.put("type", "test_5"); + list.add(map14); + + Map map15 = new HashMap<>(); + map15.put("createTime", "2022-04-11 05:04:03"); + map15.put("type", "test_1"); + list.add(map15); + + Map map16 = new HashMap<>(); + map16.put("createTime", "2022-04-10 05:04:03"); + map16.put("type", "test_5"); + list.add(map16); + + // 调用groupByTime方法进行分组 + + Object result = groupByCreateTime(list); + System.out.println(JSON.toJSONString(result)); + Object result2 = groupData(list); + System.out.println(JSON.toJSONString(result2)); + } + + public static Map>> groupData(List> dataList) { + // 根据type进行分组 + // Map>> typeMap = new HashMap<>(); + // for (Map data : dataList) { + // String type = data.get("type").toString(); + // if (!typeMap.containsKey(type)) { + // typeMap.put(type, new ArrayList<>()); + // } + // typeMap.get(type).add(data); + // } + Map>> typeMap = dataList.stream() + .collect(Collectors.groupingBy(item -> String.valueOf(item.get("type")))); + // 对每个type的数据进行日期分组 + Map>> result = new HashMap<>(); + int groupIndex = 1; + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (String type : typeMap.keySet()) { + List> typeDataList = typeMap.get(type); + typeDataList.sort((o1, o2) -> { + try { + Date date1 = dateFormat.parse(o1.get("createTime").toString()); + Date date2 = dateFormat.parse(o2.get("createTime").toString()); + return date1.compareTo(date2); + } catch (ParseException e) { + e.printStackTrace(); + return 0; + } + }); + Map baseData = typeDataList.get(0); + Date baseDate = null; + try { + baseDate = dateFormat.parse(baseData.get("createTime").toString()); + } catch (ParseException e) { + e.printStackTrace(); + } + + List> groupList = new ArrayList<>(); + groupList.add(baseData); + + for (int i = 1; i < typeDataList.size(); i++) { + Map data = typeDataList.get(i); + Date date = null; + try { + date = dateFormat.parse(data.get("createTime").toString()); + } catch (ParseException e) { + e.printStackTrace(); + } + + if (date == null || baseDate == null) { + continue; + } + if (Math.abs(date.getTime() - baseDate.getTime()) <= 7 * 24 * 60 * 60 * 1000) { + groupList.add(data); + } else { + baseDate = date; + result.put(groupIndex++, groupList); + groupList = new ArrayList<>(); + groupList.add(data); + } + } + + if (groupList.size() > 0) { + result.put(groupIndex++, groupList); + } + } + + return result; + } + + public static Map>> groupByCreateTime(List> dataList) { + // 按照时间进行升序排序 + dataList.sort((a, b) -> { + try { + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(a.get("createTime").toString()) + .compareTo(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(b.get("createTime").toString())); + } catch (ParseException e) { + e.printStackTrace(); + } + return 0; + }); + + Map>> result = new HashMap<>(); + + if (dataList.size() > 0) { + int groupIndex = 1; // 分组序号 + List> group = new ArrayList<>(); // 当前分组 + group.add(dataList.get(0)); // 将第一个元素添加到当前分组 + + // 从第二个元素开始遍历 + for (int i = 1; i < dataList.size(); i++) { + Map item = dataList.get(i); // 当前元素 + Map base = group.get(0); // 基准元素 + + // 时间差 + long diff = 0; + try { + diff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(item.get("createTime").toString()).getTime() + - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(base.get("createTime").toString()).getTime(); + } catch (ParseException e) { + throw new RuntimeException(e); + } + + // 时间差在7天以内 + if (diff <= 7 * 24 * 60 * 60 * 1000) { + // 将当前元素加入当前分组 + group.add(item); + } else { // 时间差超过7天 + result.put(groupIndex++, group); // 将当前分组添加到结果列表 + group = new ArrayList<>(); // 新建一组 + group.add(item); // 将当前元素加入新分组 + } + } + // 处理最后一组 + if (!group.isEmpty()) { + result.put(groupIndex, group); + } + } + return result; + } +} \ No newline at end of file diff --git a/src/test/java/youhong/ai/yashilandai/MyTest.java b/src/test/java/youhong/ai/yashilandai/MyTest.java new file mode 100644 index 0000000..fe496d9 --- /dev/null +++ b/src/test/java/youhong/ai/yashilandai/MyTest.java @@ -0,0 +1,24 @@ +package youhong.ai.yashilandai; + +import basetest.BaseTest; +import com.alibaba.fastjson.JSON; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + *

雅诗兰黛测试

+ * + *

create: 2023/4/23 14:00

+ * + * @author youHong.ai + */ +public class MyTest extends BaseTest { + +} + +