From 7b3bc4bcf0a44778ba18e55a4c22fda07e42d787 Mon Sep 17 00:00:00 2001 From: wangxuanran <3055088966@qq.com> Date: Mon, 3 Jul 2023 12:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=8A=A5=E9=94=99=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/ButtonTriggeringGenerateData.java | 108 ++++ .../common/getlog/enums/LogTypeEnum.java | 58 ++ .../common/getlog/util/GetLogUtil.java | 565 ++++++++++++++++++ .../ey/job/BadDebtProvisionSynJob.java | 145 +++++ .../ey/job/BankJournalToCollectSynJob.java | 251 ++++++++ .../ey/mode/BadDebtProvisionDt3.java | 313 ++++++++++ .../api/nonstandardext/ey/utils/EyLogger.java | 93 +++ .../entity/ModelFieldAsyncConfig.java | 24 + .../entity/ModelFieldAsyncConfigClass.java | 20 + .../entity/ModelFieldAsyncConfigDetail.java | 24 + .../interfaces/TriFunction.java | 12 + .../mapper/ModelFieldAsyncMapper.java | 105 ++++ .../service/ModelFieldAsyncServiceImpl.java | 247 ++++++++ .../convert/CusModelFieldAsyncConvert.java | 18 + .../util/EyCusModelFieldValueRuleMethod.java | 104 ++++ .../util/ValueRuleMethodNo.java | 19 + .../modeexpand/ey/jiahx/TransferSelect.java | 130 ++++ .../ey/jiahx/TransferSelect_fp.java | 73 +++ .../java/ebu7dev1/common/getlog/CusTest.java | 38 ++ .../java/xuanran/wang/checker/Checker.java | 118 ++++ .../wang/checker/CheckerException.java | 15 + .../java/xuanran/wang/checker/Checkers.java | 15 + .../java/xuanran/wang/checker/Condition.java | 70 +++ .../xuanran/wang/checker/ConvertUtil.java | 97 +++ .../java/xuanran/wang/checker/ECheckType.java | 17 + .../wang/checker/fun/HandleFunction.java | 26 + .../xuanran/wang/checker/fun/Predicate.java | 20 + .../xuanran/wang/checker/fun/SFunction.java | 20 + .../checker/handler/ConditionHandler.java | 114 ++++ .../abstracts/CusAbstractRequestService.java | 85 +++ .../wang/common/entity/CusRequestParams.java | 30 + .../xuanran/wang/common/test/ServiceTest.java | 22 + .../wang/common/test/TestServiceImpl.java | 28 + .../xuanran/wang/eny/ModelFieldAsyncTest.java | 94 +++ .../wang/shyl/dataasync/TestPassword.java | 22 + 35 files changed, 3140 insertions(+) create mode 100644 src/main/java/com/api/customization/ey/jiahx/web/ButtonTriggeringGenerateData.java create mode 100644 src/main/java/com/api/ebu7dev1/common/getlog/enums/LogTypeEnum.java create mode 100644 src/main/java/com/api/ebu7dev1/common/getlog/util/GetLogUtil.java create mode 100644 src/main/java/com/api/nonstandardext/ey/job/BadDebtProvisionSynJob.java create mode 100644 src/main/java/com/api/nonstandardext/ey/job/BankJournalToCollectSynJob.java create mode 100644 src/main/java/com/api/nonstandardext/ey/mode/BadDebtProvisionDt3.java create mode 100644 src/main/java/com/api/nonstandardext/ey/utils/EyLogger.java create mode 100644 src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfig.java create mode 100644 src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfigClass.java create mode 100644 src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfigDetail.java create mode 100644 src/main/java/com/api/nonstandardext/model_field_async/interfaces/TriFunction.java create mode 100644 src/main/java/com/api/nonstandardext/model_field_async/mapper/ModelFieldAsyncMapper.java create mode 100644 src/main/java/com/api/nonstandardext/model_field_async/service/ModelFieldAsyncServiceImpl.java create mode 100644 src/main/java/com/api/nonstandardext/model_field_async/service/convert/CusModelFieldAsyncConvert.java create mode 100644 src/main/java/com/api/nonstandardext/model_field_async/util/EyCusModelFieldValueRuleMethod.java create mode 100644 src/main/java/com/api/nonstandardext/model_field_async/util/ValueRuleMethodNo.java create mode 100644 src/main/java/weaver/formmode/customjavacode/modeexpand/ey/jiahx/TransferSelect.java create mode 100644 src/main/java/weaver/formmode/customjavacode/modeexpand/ey/jiahx/TransferSelect_fp.java create mode 100644 src/test/java/ebu7dev1/common/getlog/CusTest.java create mode 100644 src/test/java/xuanran/wang/checker/Checker.java create mode 100644 src/test/java/xuanran/wang/checker/CheckerException.java create mode 100644 src/test/java/xuanran/wang/checker/Checkers.java create mode 100644 src/test/java/xuanran/wang/checker/Condition.java create mode 100644 src/test/java/xuanran/wang/checker/ConvertUtil.java create mode 100644 src/test/java/xuanran/wang/checker/ECheckType.java create mode 100644 src/test/java/xuanran/wang/checker/fun/HandleFunction.java create mode 100644 src/test/java/xuanran/wang/checker/fun/Predicate.java create mode 100644 src/test/java/xuanran/wang/checker/fun/SFunction.java create mode 100644 src/test/java/xuanran/wang/checker/handler/ConditionHandler.java create mode 100644 src/test/java/xuanran/wang/common/abstracts/CusAbstractRequestService.java create mode 100644 src/test/java/xuanran/wang/common/entity/CusRequestParams.java create mode 100644 src/test/java/xuanran/wang/common/test/ServiceTest.java create mode 100644 src/test/java/xuanran/wang/common/test/TestServiceImpl.java create mode 100644 src/test/java/xuanran/wang/eny/ModelFieldAsyncTest.java create mode 100644 src/test/java/xuanran/wang/shyl/dataasync/TestPassword.java diff --git a/src/main/java/com/api/customization/ey/jiahx/web/ButtonTriggeringGenerateData.java b/src/main/java/com/api/customization/ey/jiahx/web/ButtonTriggeringGenerateData.java new file mode 100644 index 0000000..217ce38 --- /dev/null +++ b/src/main/java/com/api/customization/ey/jiahx/web/ButtonTriggeringGenerateData.java @@ -0,0 +1,108 @@ +package com.api.customization.ey.jiahx.web; + +import com.alibaba.fastjson.JSONObject; +import com.api.nonstandardext.model_field_async.service.ModelFieldAsyncServiceImpl; +import com.weaver.general.TimeUtil; +import weaver.conn.RecordSet; +import weaver.formmode.setup.ModeRightInfo; +import weaver.general.BaseBean; +import weaver.general.Util; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.ArrayList; +import java.util.List; + +/** + * @Description + * @Author 贾寒旭 + * @Date 2023/5/22 + * @Other + * @Version + */ +@Path("/pushData") +public class ButtonTriggeringGenerateData { + private static final BaseBean baseBean = new BaseBean(); + private static weaver.formmode.setup.ModeRightInfo ModeRightInfo = new ModeRightInfo();//模块信息 + private static String currentdate = TimeUtil.getCurrentDateString();//当前日期 + private static String currenttime = TimeUtil.getOnlyCurrentTimeString();//当前时间 + + private final ModelFieldAsyncServiceImpl service = new ModelFieldAsyncServiceImpl(); + + @GET + @Path("/doPushData") + @Produces({MediaType.TEXT_PLAIN}) + public JSONObject doPushData(@Context HttpServletRequest request, @Context HttpServletResponse response){ + baseBean.writeLog("点击按钮获得进行流程主表数据传递到明细表开始>>>>>>>>"); + RecordSet rs = new RecordSet(); + String sql = "select m.invoiceNo invoiceNo,d.mainid mainid,d.totalAmount totalAmount,m.yjthzje yjthzje,m.customerCode customerCode" + + ",m.customerName customerName,m.groupinvoiceno groupinvoiceno,m.finishedTime finishedTime,m.orifinishedTime orifinishedTime," + + "m.hzjtyqz hzjtyqz,m.arState arState,m.yskje yskje,m.qskje qskje,m.wskje wskje,m.kpzt kpzt,m.sckprq sckprq,m.ykpje ykpje,m.wkpje wkpje from uf_zdjmbd_dt2 d left join uf_zdjmbd m on m.id = d.mainid "; + baseBean.writeLog("查询明细表2的数据sql为=====" + sql); + rs.executeQuery(sql); + JSONObject jsonObject = new JSONObject(); + List list = new ArrayList<>(); + boolean flag = false; + while (rs.next()) { + String invoiceNo = Util.null2String(rs.getString("invoiceNo")); + if (!invoiceNo.equals("")) { + String mainid = Util.null2String(rs.getString("mainid"));//id + String zdje = Util.null2String(rs.getString("totalAmount"));//总金额 + String jyjtje = Util.null2String(rs.getString("yjthzje"));//计划计提金额 + String customerCode = Util.null2String(rs.getString("customerCode"));//客户编码 + String customerName = Util.null2String(rs.getString("customerName"));//客户名称 + String group_invoice_no = Util.null2String(rs.getString("groupinvoiceno"));//组账单ID + String finishedTime = Util.null2String(rs.getString("finishedTime"));//账单开具日期 + String orifinishedTime = Util.null2String(rs.getString("orifinishedTime"));//原账单开具日期 + String sqjtyqrq = Util.null2String(rs.getString("hzjtyqz"));//坏账计提延期至 + String skzt = Util.null2String(rs.getString("arState"));//实收状态 + String yskje = Util.null2String(rs.getString("yskje"));//收款金额 + String qskje = Util.null2String(rs.getString("qskje"));//其他收款金额 + String wskje = Util.null2String(rs.getString("wskje"));//未收款金额 + String kpzt = Util.null2String(rs.getString("kpzt"));//开票状态 + String sckprq = Util.null2String(rs.getString("sckprq"));//首次开票日期 + String ykpje = Util.null2String(rs.getString("ykpje"));//已开票金额 + String wkpje = Util.null2String(rs.getString("wkpje"));//客户编码 + String fbmxzt = "0";//客户编码 + String sjjtje = wskje;//实际计提金额 + RecordSet recordSet = new RecordSet(); + String insertSql = "insert into uf_zdjmbd_dt4 (mainid,group_invoice_no,invoiceNo,finishedTime," + + "orifinishedTime,sqjtyqrq,zdje,skzt,yskje,qskje,wskje,kpzt,sckprq,ykpje,wkpje,jyjtje,sjjtje,customerCode,customerName,fbmxzt) values (?,?,?,?,?,?," + + "?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + baseBean.writeLog("插入的明细表的sql为" + insertSql); + if (!"".equals(skzt)) { + baseBean.writeLog("我进入判断了>>>>>"); + boolean b = recordSet.executeUpdate(insertSql, mainid, group_invoice_no, invoiceNo, finishedTime, orifinishedTime, sqjtyqrq, zdje, skzt, yskje, qskje, wskje, kpzt, sckprq, ykpje, wkpje, jyjtje, sjjtje, customerCode, customerName, fbmxzt); + list.add(b); + } + + /** + * 通过配置同步字段 + * @author xuanran.wang + * @date 2023-06-27 + */ + service.asyncDataByClassName(this.getClass().getSimpleName(), mainid); + } + + } + baseBean.writeLog("list===" + list); + if(!list.isEmpty()){ + if (list.contains(false)) { + baseBean.writeLog("aaaaaaaaaaaaa"); + jsonObject.put("result", flag); + }else { + flag = true; + jsonObject.put("result", flag); + } + }else { + jsonObject.put("result", flag); + } + + return jsonObject; + } +} diff --git a/src/main/java/com/api/ebu7dev1/common/getlog/enums/LogTypeEnum.java b/src/main/java/com/api/ebu7dev1/common/getlog/enums/LogTypeEnum.java new file mode 100644 index 0000000..09c8ca9 --- /dev/null +++ b/src/main/java/com/api/ebu7dev1/common/getlog/enums/LogTypeEnum.java @@ -0,0 +1,58 @@ +package com.api.ebu7dev1.common.getlog.enums; + + + +import weaver.xiao.commons.config.enumtype.DataSourceEnum; + +import java.io.File; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + *

日志类型枚举

+ * + * @author xuanran.wang + * @date 2023/7/1 16:24 + */ +public enum LogTypeEnum { + THREAD(1, "0", "log" + File.separator + "thread","thread"), + ECOLOGY(1, "1", "log","ecology"), + RESIN(0, "2", "log","Resin"), + SECURITY(1, "3","WEB-INF" + File.separator + "securitylog","security"), + INTEGRATION(1,"4", "log" + File.separator + "integration","integration"), + SQL(1, "5", "log" + File.separator + "sql","sql"), + UTIL_CUS(1,"6", "log" + File.separator + "cus" + File.separator + "util_cus","util_cus"), + SQL_LOG(1,"7","log" + File.separator + "cus" + File.separator + "sql_log","sql_log"), + HTTP_UTIL(1,"8","log" + File.separator + "cus" + File.separator + "http_util","http_util"); + private final Integer logBelongType; + private final String value; + private final String logPath; + private final String key; + LogTypeEnum(Integer logBelongType, String value, String logPath,String key) { + this.logBelongType = logBelongType; + this.value = value; + this.logPath = logPath; + this.key = key; + } + public final static Map ENUMS = new HashMap<>(16); + + static { + for (LogTypeEnum typeEnum : EnumSet.allOf(LogTypeEnum.class)){ + ENUMS.put(typeEnum.value,typeEnum); + } + } + public String getValue() { + return value; + } + public Integer getLogBelongType() { + return logBelongType; + } + public String getLogPath() { + return logPath; + } + + public String getKey() { + return key; + } +} diff --git a/src/main/java/com/api/ebu7dev1/common/getlog/util/GetLogUtil.java b/src/main/java/com/api/ebu7dev1/common/getlog/util/GetLogUtil.java new file mode 100644 index 0000000..4a5126e --- /dev/null +++ b/src/main/java/com/api/ebu7dev1/common/getlog/util/GetLogUtil.java @@ -0,0 +1,565 @@ +package com.api.ebu7dev1.common.getlog.util; + +import java.io.*; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import aiyh.utils.excention.CustomerException; +import com.api.ebu7dev1.common.getlog.enums.LogTypeEnum; +import org.apache.commons.io.IOUtils; +import weaver.hrm.User; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/7/1 14:00 + */ +public class GetLogUtil { + + public static void checkUser(User loginUser) { + if (loginUser.getUID() != 1) { + throw new CustomerException("无权限查看!"); + } + } + + + /** + *

读取ec weaver.properties配置文件 返回集群ip

+ * + * @param weaverPropertiesPath ec weaver.properties配置文件路径 + * @return 集群ip + * @author xuanran.wang + * @dateTime 2023/7/1 14:08 + **/ + public static Set readEcologyProp(String weaverPropertiesPath) { + File file = new File(weaverPropertiesPath); + Set res = new HashSet<>(); + try { + if (!file.exists()) { + return res; + } + Properties registerProp = new Properties(); + InputStreamReader reader = new InputStreamReader(Files.newInputStream(file.toPath())); + registerProp.load(reader); + String initialHost = registerProp.getProperty("initial_hosts"); + if (initialHost != null && !"".equals(initialHost)) { + String[] initialHosts = initialHost.split(","); + for (String initial_hostStr : initialHosts) { + if (!initial_hostStr.isEmpty()) { + res.add(initial_hostStr); + } + } + } + IOUtils.closeQuietly(reader); + } catch (IOException e) { + e.printStackTrace(); + } + return res; + } + + /** + *

读取 resin 启动脚本文件 返回集群信息

+ * + * @param resinStartPath resin启动路径地址 + * @return 集群ip + * @author xuanran.wang + * @dateTime 2023/7/1 14:10 + **/ + public static Set readResinProp(String resinStartPath) { + File resinFile = new File(resinStartPath); + Set res = new HashSet<>(); + if (!resinFile.exists()) { + return res; + } + if (resinFile.isFile() && resinFile.length() > 0) { + FileInputStream fileInput = null; + BufferedReader bufferedReader = null; + try { + fileInput = new FileInputStream(resinFile); + bufferedReader = new BufferedReader(new InputStreamReader(fileInput)); + String str; + while ((str = bufferedReader.readLine()) != null) { + if (str.contains("-Dinitial_hosts") || str.contains("-J-Dinitial_hosts")) { + if (str.contains("-J-Dinitial_hosts")) { + str = str.substring(str.indexOf("-J-Dinitial_hosts") + 17); + } + if (str.contains("-Dinitial_hosts")) { + str = str.substring(str.indexOf("-Dinitial_hosts") + 15); + } + str = str.contains("=") ? str.substring(str.indexOf("=") + 1) : str; + str = str.contains("-") ? str.substring(0, str.indexOf("-")) : str; + str = str.contains(" ") ? str.substring(0, str.indexOf(" ")) : str; + String[] ips = str.split(","); + for (String ip : ips) { + try { + String tmpIp = ip.replace(".", "").replace(":", ""); + Long.parseLong(tmpIp.trim()); + res.add(ip.trim()); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + } catch (Throwable t) { + t.printStackTrace(); + } finally { + IOUtils.closeQuietly(fileInput); + IOUtils.closeQuietly(bufferedReader); + } + } + return res; + } + + /** + *

获取内网ip

+ * + * @return 内网ip + * @author xuanran.wang + * @dateTime 2023/7/1 14:17 + **/ + public static String getInnerIp() { + try { + Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces(); + while (netInterfaces.hasMoreElements()) { + NetworkInterface ni = netInterfaces.nextElement(); + Enumeration nii = ni.getInetAddresses(); + while (nii.hasMoreElements()) { + InetAddress inetAddress = nii.nextElement(); + if (!inetAddress.getHostAddress().contains(":")) { + String ip = inetAddress.getHostAddress(); + if (ip.startsWith("10.") || ip.startsWith("192.168.")) {// || + return ip; + } else { + if (ip.startsWith("172.")) { + return ip; + } + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return "127.0.0.1"; + } + + /** + *

将数据进行解析返回每种类型对应的路径

+ * + * @param ecPath ec路径 + * @param resinPath resin路径 + * @param logTypeList 前端要获取的日志类型 + * @return 转换后的数据 + * @author xuanran.wang + * @dateTime 2023/7/1 16:56 + **/ + public static List> getLogPathByLogType(String ecPath, String resinPath, List logTypeList) { + List> list = new ArrayList<>(); + for (String logType : logTypeList) { + Map map = new HashMap<>(); + LogTypeEnum typeEnum = LogTypeEnum.ENUMS.get(logType); + Integer logBelongType = typeEnum.getLogBelongType(); + String logPath = typeEnum.getLogPath(); + String basePath = ecPath; + if (logBelongType == 0) { + basePath = resinPath; + } + map.put("logType", logType); + map.put("path", basePath + File.separator + logPath); + map.put("key", typeEnum.getKey()); + list.add(map); + } + return list; + } + + /** + *

+ * + * @param logPath + * @param startDate + * @param endDate + * @return

+ * { + * "2023-07-01":{ + * "http_util":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/cus/http_util/cus.log" + * ], + * "ecology":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/ecology" + * ], + * "security":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/WEB-INF/securitylog/systemRunInfo2023-07-01.log", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/WEB-INF/securitylog/systemSecurity2023-07-01.log" + * ], + * "util_cus":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/cus/util_cus/cus.log" + * ], + * "Resin":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/stdout.log", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/stderr.log", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/watchdog-manager.log", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/jvm-default.log" + * ], + * "integration":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/integration/integration.log" + * ], + * "thread":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/thread/2023-07-01" + * ], + * "sql_log":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/cus/sql_log/cus.log" + * ], + * "sql":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/sql/sqlcount_2023-07-01.log", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/sql/sqltime_2023-07-01.log" + * ] + * }, + * "2023-07-02":{ + * "http_util":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/cus/http_util/cus.log_20230702.log" + * ], + * "ecology":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/ecology_20230702.log" + * ], + * "security":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/WEB-INF/securitylog/systemRunInfo2023-07-02.log", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/WEB-INF/securitylog/systemSecurity2023-07-02.log" + * ], + * "util_cus":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/cus/util_cus/cus.log_20230702.log" + * ], + * "Resin":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/stdout-20230702.log.gz", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/stderr-20230702.log.gz", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/watchdog-manager.log", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/jvm-default.log" + * ], + * "integration":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/integration/integration.log_20230702.log" + * ], + * "thread":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/thread/2023-07-02" + * ], + * "sql_log":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/cus/sql_log/cus.log_20230702.log" + * ], + * "sql":[ + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/sql/sqlcount_2023-07-02.log", + * "/Users/wangxuanran/company/project/ebu_ecology_dev1/log/sql/sqltime_2023-07-02.log" + * ] + * } + * } + *

+ * @author xuanran.wang + * @dateTime 2023/7/1 18:26 + **/ + public static Map>> getLogFilePath(List> logPath, String startDate, String endDate) { + Map>> res = new HashMap<>(); + List dateList = getDateList(startDate, endDate); + for (String date : dateList) { + Map> keyMap = new HashMap<>(); + for (Map map : logPath) { + boolean isToDay = isToDay(date); + String key = map.get("key"); + List pathList = parseLogFilePath(key, map.get("path"), date, isToDay); + keyMap.put(key, pathList); + } + res.put(date, keyMap); + } + return res; + } + + public static String collectLog(String ecologyPath, Map>> pathListKeyMap) throws FileNotFoundException { + FileOutputStream fos; + String outPath = ecologyPath + File.separator + "getlog" + File.separator + "log" + File.separator + (System.currentTimeMillis() / 1000); + File outFile = null; + try { + outFile = new File(outPath); + if (!outFile.exists()) { + outFile.mkdirs(); + } + } catch (Exception e) { + e.printStackTrace(); + } + String outLogPath = outFile + File.separator + getInnerIp() + "_downLog.zip"; + fos = new FileOutputStream(outLogPath); + try { + ZipOutputStream zos = new ZipOutputStream(fos); + zos.setLevel(1); + for (Map.Entry>> entry : pathListKeyMap.entrySet()) { + String date = entry.getKey(); + Map> value = entry.getValue(); + for (Map.Entry> pathKeyList : value.entrySet()) { + String key = pathKeyList.getKey(); + String basePath = date + File.separator; + List pathList = pathKeyList.getValue(); + for (String path : pathList) { + if ("sqllog".equals(key)) { + basePath += ("sqllog" + File.separator); + } + if ("monitorevent".equals(key)) { + basePath += ("event" + File.separator); + } + if ("monitorlog".equals(key)) { + basePath += ("monitorlog" + File.separator); + } + if (key.equals("cus")) { + basePath += ("cus" + File.separator); + } + if (key.equals("util_cus")) { + basePath += ("util_cus" + File.separator); + } + if (key.equals("sql_log")) { + basePath += ("sql_log" + File.separator); + } + if (key.equals("http_util")) { + basePath += ("http_util" + File.separator); + } + compressbyType(path, zos, basePath); + } + } + } + + System.out.println("日志文件地址 : " + outLogPath); + + try { + zos.close(); + } catch (Exception es) { + + } + if (fos != null) { + fos.close(); + } + } catch (Exception e) { + + } + return outLogPath; + } + + /** + * 按照原路径的类型就行压缩。文件路径直接把文件压缩 + * + * @param src + * @param zos + * @param baseDir + */ + private static void compressbyType(String src, ZipOutputStream zos, String baseDir) { + File srcFile = new File(src); + if (!srcFile.exists()) { + return; + } + //判断文件是否是文件,如果是文件调用compressFile方法,如果是路径,则调用compressDir方法; + if (srcFile.isFile()) { + //src是文件,调用此方法 + compressFile(srcFile, zos, baseDir); + } else if (srcFile.isDirectory()) { + compressDir(srcFile, zos, baseDir); + } + } + + /** + * 压缩文件,取后面的80M内容 + */ + private static void compressFile(File file, ZipOutputStream zos, String baseDir) { + if (!file.exists()) + return; + try { + RandomAccessFile fileRead = new RandomAccessFile(file, "r"); //用读模式 + long fileLength = fileRead.length();//获得文件长度 + if (file.getName().endsWith(".log") && fileLength > 1073741820) {//如果文件超过80M,则只取文件倒数80M内容 + fileRead.seek(fileLength - 1073741820); + } else { + fileRead.seek(0); + } + ZipEntry entry = new ZipEntry(baseDir + file.getName()); + zos.putNextEntry(entry); + int hasRead; + byte[] buf = new byte[1024]; + while ((hasRead = fileRead.read(buf)) != -1) { + zos.write(buf, 0, hasRead); + } + fileRead.close(); + } catch (Exception e) { + + } + } + + /** + * 压缩文件夹 + */ + private static void compressDir(File dir, ZipOutputStream zos, String baseDir) { + if (!dir.exists()) + return; + File[] files = dir.listFiles(); + for (int i = 0; i < files.length; i++) { + File file = files[i]; + compressFile(file, zos, baseDir + dir.getName() + File.separator); + } + } + + + public static List parseLogFilePath(String key, String path, String date, boolean isToDay) { + List list = new ArrayList(); + if ("thread".equals(key)) { + list.add(path + File.separator + date); + } else if ("mem".equals(key)) { + list.add(path + File.separator + "memory_" + date + ".log"); + } else if ("ecology".equals(key)) { + if (isToDay) { + list.add(path + File.separator + "ecology"); + } else { + list.add(path + File.separator + "ecology_" + getDateStr(date) + ".log"); + } + } else if ("sql".equals(key)) { + list.add(path + File.separator + "sqlcount_" + date + ".log"); + list.add(path + File.separator + "sqltime_" + date + ".log"); + } else if ("integration".equals(key)) { + if (isToDay) { + list.add(path + File.separator + "integration.log"); + } else { + list.add(path + File.separator + "integration.log_" + getDateStr(date) + ".log"); + } + } else if ("security".equals(key)) { + list.add(path + File.separator + "systemRunInfo" + date + ".log"); + list.add(path + File.separator + "systemSecurity" + date + ".log"); + } else if ("Resin".equals(key)) { + if (isToDay) { + list.add(path + File.separator + "stdout.log"); + list.add(path + File.separator + "stderr.log"); + } else { + list.add(path + File.separator + "stdout-" + getDateStr(date) + ".log.gz"); + list.add(path + File.separator + "stderr-" + getDateStr(date) + ".log.gz"); + } + list.add(path + File.separator + "watchdog-manager.log"); + list.add(path + File.separator + "jvm-default.log"); + } else if ("sqllog".equals(key)) { + list.add(path + File.separator + getSqlPathByDate(date)); + list.add(path + File.separator); + } else if ("monitorevent".equals(key)) { + list.addAll(eventLog(path, date)); + } else if ("monitorPool".equals(key)) { + list.add(path + File.separator + "pool_" + getDateStr(date) + "_ecology.log"); + list.add(path + File.separator + "pool_" + getDateStr(date) + "_ecology.zip"); + } else if ("monitorlog".equals(key)) { + if (isToDay) { + list.add(path + File.separator + "stdout.log"); + list.add(path + File.separator + "stderr-log"); + } else { + list.add(path + File.separator + "stdout-" + getDateStr(date) + ".log.gz"); + list.add(path + File.separator + "stderr-" + getDateStr(date) + ".log.gz"); + } + } else if ("monitorconcurrent".equals(key)) { + list.add(path + File.separator + "concurrent_" + getDateStr(date) + ".log"); + list.add(path + File.separator + "concurrent_" + getDateStr(date) + ".zip"); + } else if ("monitorcpu".equals(key)) { + list.add(path + File.separator + "cpu_" + getDateStr(date) + ".log"); + list.add(path + File.separator + "cpu_" + getDateStr(date) + ".zip"); + } else if ("resinconf".equals(key)) { + list.add(path); + } else if ("ecoloyweaver".equals(key)) { + dealWidthWeaverProp(path + "weaver.properties", new File(path + "weaversecurity.properties")); + list.add(path + "weaversecurity.properties"); + } else if ("cus".equals(key) || "util_cus".equals(key) || "sql_log".equals(key) || "http_util".equals(key)) { + if (isToDay) { + list.add(path + File.separator + "cus.log"); + } else { + list.add(path + File.separator + "cus.log_" + getDateStr(date) + ".log"); + } + } + return list; + } + + private static List eventLog(String path, String date) { + List list = new ArrayList(); + File file = new File(path); + if (!file.exists()) { + return list; + } + File[] filelists = new File(path).listFiles(); + date = getDateStr(date); + for (int i = 0; i < filelists.length; i++) { + File filelist = filelists[i]; + if (filelist.getName().indexOf(date) != -1) { + list.add(filelist.getAbsolutePath()); + } + } + return list; + } + + private static String getSqlPathByDate(String date) { + return date.replace("-", File.separator); + } + + private static String getDateStr(String date) { + date = date.replaceAll("-", ""); + return date; + } + + + private static boolean isToDay(String date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String toDay = sdf.format(new Date()); + return date.equals(toDay); + } + + private static List getDateList(String startDate, String endDate) { + List list = new ArrayList<>(); + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date start = sdf.parse(startDate); + Date end = sdf.parse(endDate); + Calendar tempStart = Calendar.getInstance(); + tempStart.setTime(start); + while (start.getTime() <= end.getTime()) { + list.add(sdf.format(tempStart.getTime())); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + start = tempStart.getTime(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } + + private static void dealWidthWeaverProp(String path, File outFile) {//处理weaver.prop密码问题 + File file = new File(path); + if (!file.exists()) { + return; + } + InputStreamReader reader = null; + java.io.Writer outWriter = null; + try { + if (!file.exists()) { + file.createNewFile(); + } + Properties registerProp = new Properties(); + reader = new InputStreamReader(new FileInputStream(file)); + registerProp.load(reader); + reader.close(); + outWriter = new FileWriter(outFile); + registerProp.put("ecology.password", "***********"); + registerProp.store(outWriter, ""); + outWriter.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (reader != null) { + reader.close(); + } + if (outWriter != null) { + outWriter.close(); + } + } catch (Exception e) { + } + } + } +} + diff --git a/src/main/java/com/api/nonstandardext/ey/job/BadDebtProvisionSynJob.java b/src/main/java/com/api/nonstandardext/ey/job/BadDebtProvisionSynJob.java new file mode 100644 index 0000000..a272629 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/ey/job/BadDebtProvisionSynJob.java @@ -0,0 +1,145 @@ +package com.api.nonstandardext.ey.job; + +import com.api.nonstandardext.ey.mode.BadDebtProvisionDt3; +import com.api.nonstandardext.ey.utils.EyLogger; +import com.api.nonstandardext.model_field_async.service.ModelFieldAsyncServiceImpl; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.interfaces.schedule.BaseCronJob; + +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.Date; + +/** + * + * 管报 开始执行坏账计提将主表参数携带到明细表3中定时任务 + * + * 计划任务-每周执行一次 + * + * 获取账单台账;uf_zdjmbd 中账单状态invoiceStatus 为0(Open)且 当前日期-子账单计提开始计算日期>=180天的, + * + * 在该条数据的明细表3中插入一条新的数据,如果存在手动的更新为自动 + * + * 账单台账.明细表3中的数据 来源于 账单台账主表,对应关系详见开发点4 + * @Description + * @Author 贾寒旭 + * @Date 2023/3/21 + * @Other + * @Version + */ +public class BadDebtProvisionSynJob extends BaseCronJob { + + private static final EyLogger logger = new EyLogger(); + + private final static String JobName = " BadDebtProvisionSynJob V2 , "; + + private final ModelFieldAsyncServiceImpl service = new ModelFieldAsyncServiceImpl(); + + @Override + public void execute() { + logger.writeLogInfo( this.getClass().getName(),JobName + " >>>>>>"); + + //首先查询账单台账,在其中进行查询获得到指定的数据 + //账单请求类型:只取0、1、2、3、5 + //以及账单号前三个字母,包含MCN、MHK + + RecordSet rs = new RecordSet(); + RecordSet innerRs = new RecordSet(); + RecordSet updateRs = new RecordSet(); + + try { + + String dateSql = "select * from uf_gbrqgz"; + innerRs.executeQuery(dateSql); + int gbscts = 0; + while (innerRs.next()) { + gbscts = Util.getIntValue(innerRs.getString("gbscts"), 0); + } + + String sql = "select m.id, d.bu bu,m.customerCode customerCode,m.requestType requestType,m.invoiceNo invoiceNo," + + "m.customerName customerName," + + "m.finishedTime finishedTime,m.orifinishedTime orifinishedTime,m.hzjtyqz hzjtyqz," + + "d.totalAmount totalAmount,d.skzt skzt,d.yskje yskje,d.qskje qskje,d.wskje wskje," + + "m.kpzt kpzt,m.sckprq sckprq,m.ykpje ykpje,m.wkpje wkpje,d.jtksjsrq as computeDate " + + "from uf_zdjmbd m left join uf_zdjmbd_dt1 d on d.mainid = m.id where m.invoiceStatus = 0"; + + rs.executeQuery(sql); + logger.writeLogInfo( this.getClass().getName(),JobName + " gbscts:" + gbscts + ", rs count:" + rs.getCounts() + " , sql=====" + sql); + + SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); + String format = sf.format(new Date()); + + while (rs.next()) { + String id = rs.getString("id"); + String customerName = rs.getString("customerName");//客户名称 + String computeDate = rs.getString("computeDate"); + String requestType = rs.getString("requestType"); + String invoiceNo = rs.getString("invoiceNo"); + + logger.writeLogInfo( this.getClass().getName(),JobName + "customerName:" + customerName + ", computeDate:" + computeDate + ", requestType:" + requestType + ", invoiceNo:" + invoiceNo); + + long daysBetween = 0; + + if (!"".equals(computeDate)) { + LocalDate date1 = LocalDate.parse(format); + LocalDate date2 = LocalDate.parse(computeDate); + daysBetween = Math.abs(ChronoUnit.DAYS.between(date1, date2)); + + logger.writeLogInfo( this.getClass().getName(),JobName + ", computeDate:" + computeDate + ", daysBetween:" + daysBetween + ", gbscts:" + gbscts); + + if (daysBetween >= gbscts) { + + String existSql = "select * from uf_zdjmbd_dt3 where (tszt is null or tszt=0) and mainid=" + id; + innerRs.execute(existSql); + + logger.writeLogInfo( this.getClass().getName(),JobName + " innerRs count : " + innerRs.getCounts() + ",existSql:" + existSql); + if (innerRs.getCounts() > 0){ + updateRs.execute("update uf_zdjmbd_dt3 set tszt=1 where (tszt is null or tszt=0) and mainid=" + id); + continue; + } + + String customerCode = rs.getString("customerCode");//客户编码 + String bu = rs.getString("bu");//客户编码 + + BadDebtProvisionDt3 dt3 = new BadDebtProvisionDt3(); + dt3.setMainId(id); + dt3.setCustomerCode(customerCode); + dt3.setCustomerName(customerName); + dt3.setGroup_invoice_no(rs.getString("groupinvoiceno")); //组账单ID + dt3.setInvoiceNo(rs.getString("invoiceNo")); //账单ID + dt3.setFinishedTime(rs.getString("finishedTime")); //账单开具日期 + dt3.setOrifinishedTime(rs.getString("orifinishedTime")); //原账单开具日期 + dt3.setSqjtyqrq(rs.getString("hzjtyqz")); //申请计提延期日期 取 坏账计提延期至 + dt3.setZdje(rs.getString("totalAmount")); //账单金额 + dt3.setSkzt(rs.getString("skzt")); //收款状态 + dt3.setYskje(rs.getString("yskje")); //已收款金额 + dt3.setQskje(rs.getString("qskje")); //其他收款金额 + dt3.setWskje(rs.getString("wskje")); //未收款金额 + dt3.setKpzt(rs.getString("kpzt")); //开票状态 + dt3.setSckprq(rs.getString("sckprq")); //首次开票日期 + dt3.setYkpje(rs.getString("ykpje")); //已开票金额 + dt3.setWkpje(rs.getString("wkpje")); //未开票金额 + dt3.setJyjtje(dt3.getWskje()); //建议计提金额 + dt3.setSjjtje(dt3.getWskje()); //实际计提金额 + dt3.setBu(bu); //bu + dt3.setTszt("1"); //状态 + + dt3.save(dt3, "uf_zdjmbd_dt3"); + logger.writeLogInfo( this.getClass().getName(),JobName + " dt3 : " + dt3.toString()); + + /** + * 通过配置同步字段 + * @author xuanran.wang + * @date 2023-06-27 + */ + service.asyncDataByClassName(this.getClass().getSimpleName(), id); + } + } + } + } catch (Exception e){ + logger.writeLogInfo( this.getClass().getName(),JobName + " exception : " + e.getMessage()); + } + } +} diff --git a/src/main/java/com/api/nonstandardext/ey/job/BankJournalToCollectSynJob.java b/src/main/java/com/api/nonstandardext/ey/job/BankJournalToCollectSynJob.java new file mode 100644 index 0000000..0bbceb5 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/ey/job/BankJournalToCollectSynJob.java @@ -0,0 +1,251 @@ +package com.api.nonstandardext.ey.job; + +import com.api.nonstandardext.ey.utils.EyLogger; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.interfaces.schedule.BaseCronJob; +import weaver.workflow.webservices.*; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * 法报 + * 执行频率: + * @Description + * @Author 贾寒旭 + * @Date 2023/3/20 + * @Other + * @Version从银行流水到收款单 + */ +public class BankJournalToCollectSynJob extends BaseCronJob { + + private static final EyLogger logger = new EyLogger(); + + private final static String JobName = " BankJournalToCollectSynJob V1 ,"; + + private String workflowId; + + public String getWorkflowId() { + return workflowId; + } + + public void setWorkflowId(String workflowId) { + this.workflowId = workflowId; + } + + /** + * 开始执行从银行流水到收款单定时任务 + */ + @Override + public void execute() { + + logger.writeLogInfo( this.getClass().getName(),JobName + " >>>>>> start"); + + RecordSet rs = new RecordSet(); + RecordSet innerRs = new RecordSet(); + try { + SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); + String format = sf.format(new Date()); + String sql = "select * from uf_yhjylsjmbd where szfx = '0'"; + + rs.executeQuery(sql); + while (rs.next()) { + String jylsh = rs.getString("jylsh");//交易流水号对应流程表单上的银行流水id + + String qsql = "select * from formtable_main_257 where yhlsid = ?"; + innerRs.executeQuery(qsql, jylsh); + if (innerRs.next()) { + logger.writeLogInfo( this.getClass().getName(), JobName + " exists receipt workflow can not create >>>>"); + } else { + Map map = new HashMap<>(); + String dfhm = rs.getString("dfhm");//对方账户名fkrmc + String dfzh = rs.getString("dfzh");//对方账号fkrzh + String dfyhmc = rs.getString("dfyhmc");//对方银行名称fkrkhh + String jyhm = rs.getString("jyhm");//交易户名skfmc + String jyzh = rs.getString("jyzh");//交易账号skfzh + String jyyhmc = rs.getString("jyyhmc");//交易银行名称skrkhh + String bb = rs.getString("bb");//币别bb + String szlx = rs.getString("szfx");//收支方向szlx + String jyfse = rs.getString("jyfse");//交易发生额jyje + String zy = rs.getString("zy");//摘要zy + String jyrq = rs.getString("jyrq");//交易日期jyrq + String jysj = rs.getString("jysj");//交易时间jysj + String jylsh1 = rs.getString("jylsh");//交易流水号yhlsid + String bz = rs.getString("bz");//备注bz + String ywrq = format; + map.put("fkrmc", dfhm); + map.put("fkrzh", dfzh); + map.put("fkrkhh", dfyhmc); + map.put("skfmc", jyhm); + map.put("skfzh", jyzh); + map.put("skrkhh", jyyhmc); + map.put("bb", bb); + map.put("szlx", szlx); + map.put("jyje", jyfse); + map.put("jyrq", jyrq); + map.put("jysj", jysj); + map.put("yhlsid", jylsh1); + map.put("bz", bz); + map.put("zy", zy); + map.put("ywrq", ywrq); + map.put("sfyyhls", "0"); + map.put("sfxyepemqr", "1"); + logger.writeLogInfo( this.getClass().getName(),JobName + " main data map=" + map); + //将(摘要)zy字段进行拆分 + List> zyMap = cfzy(zy); + logger.writeLogInfo( this.getClass().getName(),JobName + "zyMap=====" + zyMap); + //创建流程 + //获得主表信息 + WorkflowMainTableInfo workflowMainTableInfo = getMainInfo(map); + //获得明细表信息 + WorkflowDetailTableInfo[] detail_tableinfo = null; + if (!zyMap.isEmpty()) { + detail_tableinfo = getDetailInfo(zyMap); + } + + //创建流程工作 创建流程时为必输项 + String requestName = "收款认领流程"; + WorkflowRequestInfo workflowRequestInfo = new WorkflowRequestInfo();//工作流程请求信息 + WorkflowBaseInfo workflowBaseInfo = new WorkflowBaseInfo();//工作流信息 + workflowRequestInfo.setWorkflowMainTableInfo(workflowMainTableInfo);//添加主表字段数据 + if (detail_tableinfo != null) { + workflowRequestInfo.setWorkflowDetailTableInfos(detail_tableinfo);//添加明细数据 + } + workflowRequestInfo.setCreatorId("1");//创建者ID 创建流程时为必输项 + workflowRequestInfo.setRequestName(requestName); + workflowBaseInfo.setWorkflowId(getWorkflowId());//流程ID + workflowRequestInfo.setWorkflowBaseInfo(workflowBaseInfo);//工作流信息 + workflowRequestInfo.setIsnextflow("0");//停留在当前节点,1代表流转下一节点 + /**提交流程*/ + WorkflowService service = new WorkflowServiceImpl(); + String requestid1 = service.doCreateWorkflowRequest(workflowRequestInfo, 1); + String statusCode = Util.null2String(service.submitWorkflowRequest(workflowRequestInfo, Integer.parseInt(requestid1), 1, "save", "")); + String statusCode1 = Util.null2String(service.submitWorkflowRequest(workflowRequestInfo, Integer.parseInt(requestid1), 1, "submit", "")); + logger.writeLogInfo( this.getClass().getName(),JobName + " submit requestid1 : " + requestid1 + " statusCode: " + statusCode + " statusCode1 : " + statusCode1); + } + } + } catch (Exception e){ + logger.writeLogInfo( this.getClass().getName(), JobName + " exception: " + e.getMessage()); + } + } + + /** + * 组装明细表数据 + * @return + * @param zyMap + */ + public WorkflowDetailTableInfo[] getDetailInfo(List> zyMap) throws Exception{ + //设置明细表字段 + int index = Integer.parseInt("1"); //获取子表封装的表 + logger.writeLogInfo( this.getClass().getName(), JobName + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>create detail data>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + WorkflowDetailTableInfo[] detail_tableinfo = new WorkflowDetailTableInfo[index];//定义一个明细表对象 + WorkflowRequestTableRecord[] detil_wrtri = new WorkflowRequestTableRecord[zyMap.size()];//创建多少行明细数据 + List dwrs = null; //一行 + WorkflowRequestTableField det_wrti = null; //一个字段 + int rownum = 0; + for (Map map : zyMap) { + logger.writeLogInfo( this.getClass().getName(), JobName + "get map data" + map); + dwrs = new ArrayList<>(); + for (String key : map.keySet()) { + logger.writeLogInfo( this.getClass().getName(), JobName + "current map key" + key); + det_wrti = new WorkflowRequestTableField(); + String value = Util.null2String(map.get(key));//原字段字段值 + logger.writeLogInfo( this.getClass().getName(), JobName + "value==="+value); + det_wrti.setFieldName(key);//目标字段字段 + det_wrti.setFieldValue(value); + det_wrti.setView(true); + det_wrti.setEdit(true); + dwrs.add(det_wrti); + } + WorkflowRequestTableField[] workflowRequestTableFields = new WorkflowRequestTableField[dwrs.size()]; + for (int i = 0; i < dwrs.size(); i++) { + workflowRequestTableFields[i] = dwrs.get(i); + } + detil_wrtri[rownum] = new WorkflowRequestTableRecord(); + detil_wrtri[rownum].setWorkflowRequestTableFields(workflowRequestTableFields); + rownum++; + //将明细数据加入明细表index - 1中 从0开始 + detail_tableinfo[index - 1] = new WorkflowDetailTableInfo(); + detail_tableinfo[index - 1].setWorkflowRequestTableRecords(detil_wrtri); + logger.writeLogInfo( this.getClass().getName(), JobName + "create detail data end " + detail_tableinfo); + } + return detail_tableinfo; + } + + + /** + * 拆分摘要 + * @param zy + */ + public List> cfzy(String zy) throws Exception{ +// 账单号:ICSV*******;客户编号:***;客户名称:****;账单号:ICSV*******;客户编号:***;客户名称:****; + logger.writeLogInfo( this.getClass().getName(), JobName + " zhai yao : " + zy); + String[] strings = zy.split(" "); + List> list = new ArrayList<>(); + for (int i = 0; i < strings.length; i++) { + Map map = new HashMap<>(); + if(strings[i].toLowerCase().length()==14){ + if (strings[i].toUpperCase().contains("ICN") + ||strings[i].toUpperCase().contains("XCN") + ||strings[i].toUpperCase().contains("RCN") + ||strings[i].toUpperCase().contains("MCN") + ||strings[i].toUpperCase().contains("WCN")) { + String zdh = strings[i].toUpperCase(); + logger.writeLogInfo( this.getClass().getName(), JobName + "zdh===" + zdh); + RecordSet rs = new RecordSet(); + String sql = "select id from uf_zdjmbd where invoiceNo = ?"; + rs.executeQuery(sql, zdh); + String id = ""; + while (rs.next()) { + id = rs.getString("id"); + } + //TODO 流程明细表没有对应字段 + map.put("zdh", id); +// map.put("khbh", khbh); +// map.put("khmc", khmc); + map.put("zdhwb", zdh); + list.add(map); + } else { + return new ArrayList<>(); + } + } else { + return new ArrayList<>(); + } + logger.writeLogInfo( this.getClass().getName(), JobName + ", map size:" + map.size()); + } + logger.writeLogInfo( this.getClass().getName(), JobName + ",list size:" + list.size()); + return list; + } + + + /** + * 组装主表数据 + * @param map + * @return + */ + public WorkflowMainTableInfo getMainInfo(Map map) { + logger.writeLogInfo( this.getClass().getName(), JobName + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>create main data start>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + WorkflowMainTableInfo workflowMainTableInfo = new WorkflowMainTableInfo();//定义一个主表对象 + WorkflowRequestTableRecord[] workflowRequestTableRecord = new WorkflowRequestTableRecord[1];//创建多少行主表数据 + List main_dwrs = new ArrayList();//一行 + WorkflowRequestTableField main_det_wrti = null; + for (String s : map.keySet()) { + main_det_wrti = new WorkflowRequestTableField();//一个字段 + String value = map.get(s); + main_det_wrti.setFieldName(s); + main_det_wrti.setFieldValue(value); + main_det_wrti.setView(true); + main_det_wrti.setEdit(true); + main_dwrs.add(main_det_wrti); + } + WorkflowRequestTableField[] workflowRequestTableFields = new WorkflowRequestTableField[main_dwrs.size()]; + for (int i = 0; i < main_dwrs.size(); i++) { + workflowRequestTableFields[i] = main_dwrs.get(i); + } + workflowRequestTableRecord[0] = new WorkflowRequestTableRecord(); + workflowRequestTableRecord[0].setWorkflowRequestTableFields(workflowRequestTableFields); + workflowMainTableInfo.setRequestRecords(workflowRequestTableRecord); + logger.writeLogInfo( this.getClass().getName(), JobName + "create main data end>>>>>>>>>>>>>>>>>>>>>>>>>" + workflowMainTableInfo); + return workflowMainTableInfo; + } +} diff --git a/src/main/java/com/api/nonstandardext/ey/mode/BadDebtProvisionDt3.java b/src/main/java/com/api/nonstandardext/ey/mode/BadDebtProvisionDt3.java new file mode 100644 index 0000000..19421b3 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/ey/mode/BadDebtProvisionDt3.java @@ -0,0 +1,313 @@ +package com.api.nonstandardext.ey.mode; + +import com.api.nonstandardext.ey.utils.EyLogger; +import com.weaver.general.BaseBean; +import weaver.conn.RecordSet; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +public class BadDebtProvisionDt3 extends BaseBean { + + private static final EyLogger logger = new EyLogger(); + + private String mainId; + + private String customerCode; + + private String customerName; + + private String group_invoice_no; + + private String invoiceNo; + + private String finishedTime; + + private String orifinishedTime; + + private String sqjtyqrq; + + private String zdje; + + private String skzt; + + private String yskje; + + private String qskje; + + private String wskje; + + private String kpzt; + + private String sckprq; + + private String ykpje; + + private String wkpje; + + private String jyjtje; + + private String sjjtje; + + private String bu; + + private String tszt; + + public Integer save(BadDebtProvisionDt3 ufModel, String tableName) { + String modelName = "管报明细"; + Integer mainId = null; + try { + RecordSet rs = new RecordSet(); + String fieldSql = ""; + String valueSql = ""; + boolean result = false; + + // 获取实体类的所有属性,返回Field数组 + Field[] field = ufModel.getClass().getDeclaredFields(); + // 遍历所有属性 + for (int i = 0; i < field.length; i++) { + // 获取属性的名字,并将属性第一个字符大写 + String name = field[i].getName(); + name = name.substring(0, 1).toUpperCase() + name.substring(1); + // 得到属性类型 + String type = field[i].getGenericType().toString(); + if (type.equals("class java.lang.String")) { + Method m = ufModel.getClass().getMethod("get" + name); + // 调用getter方法获取属性值 + String value = (String) m.invoke(ufModel); + if (value != null) { + if ("".equals(value)){ + fieldSql += "," + name; + valueSql += ",null"; + } else { + fieldSql += "," + name; + valueSql += ",'" + value.trim() + "'"; + } + } + } + if (type.equals("class java.lang.Integer")) { + Method m = ufModel.getClass().getMethod("get" + name); + // 调用getter方法获取属性值 + Integer value = (Integer) m.invoke(ufModel); + if (value != null) { + fieldSql += "," + name; + valueSql += "," + value + ""; + } + } + } + if (!"".equals(fieldSql)) { + fieldSql = fieldSql.substring(1); + valueSql = valueSql.substring(1); + String insertSql = "insert into " + tableName + " (" + fieldSql + ") values (" + valueSql + ")"; + + logger.writeLogInfo( this.getClass().getName()," insertSql : " + insertSql); + + result = rs.execute(insertSql); + if (!result) { + return null; + } + writeLog(modelName + ", insertSql ->" + insertSql + ", result:" + result); + } + } catch (Exception e) { + writeLog(modelName + ", 新增报错 ->" + e.getMessage()); + e.printStackTrace(); + return null; + } + return mainId; + } + + public String getMainId() { + return mainId; + } + + public void setMainId(String mainId) { + this.mainId = mainId; + } + + public String getCustomerCode() { + return customerCode; + } + + public void setCustomerCode(String customerCode) { + this.customerCode = customerCode; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getGroup_invoice_no() { + return group_invoice_no; + } + + public void setGroup_invoice_no(String group_invoice_no) { + this.group_invoice_no = group_invoice_no; + } + + public String getInvoiceNo() { + return invoiceNo; + } + + public void setInvoiceNo(String invoiceNo) { + this.invoiceNo = invoiceNo; + } + + public String getFinishedTime() { + return finishedTime; + } + + public void setFinishedTime(String finishedTime) { + this.finishedTime = finishedTime; + } + + public String getOrifinishedTime() { + return orifinishedTime; + } + + public void setOrifinishedTime(String orifinishedTime) { + this.orifinishedTime = orifinishedTime; + } + + public String getSqjtyqrq() { + return sqjtyqrq; + } + + public void setSqjtyqrq(String sqjtyqrq) { + this.sqjtyqrq = sqjtyqrq; + } + + public String getZdje() { + return zdje; + } + + public void setZdje(String zdje) { + this.zdje = zdje; + } + + public String getSkzt() { + return skzt; + } + + public void setSkzt(String skzt) { + this.skzt = skzt; + } + + public String getYskje() { + return yskje; + } + + public void setYskje(String yskje) { + this.yskje = yskje; + } + + public String getQskje() { + return qskje; + } + + public void setQskje(String qskje) { + this.qskje = qskje; + } + + public String getWskje() { + return wskje; + } + + public void setWskje(String wskje) { + this.wskje = wskje; + } + + public String getKpzt() { + return kpzt; + } + + public void setKpzt(String kpzt) { + this.kpzt = kpzt; + } + + public String getSckprq() { + return sckprq; + } + + public void setSckprq(String sckprq) { + this.sckprq = sckprq; + } + + public String getYkpje() { + return ykpje; + } + + public void setYkpje(String ykpje) { + this.ykpje = ykpje; + } + + public String getWkpje() { + return wkpje; + } + + public void setWkpje(String wkpje) { + this.wkpje = wkpje; + } + + public String getJyjtje() { + return jyjtje; + } + + public void setJyjtje(String jyjtje) { + this.jyjtje = jyjtje; + } + + public String getSjjtje() { + return sjjtje; + } + + public void setSjjtje(String sjjtje) { + this.sjjtje = sjjtje; + } + + public String getBu() { + return bu; + } + + public void setBu(String bu) { + this.bu = bu; + } + + public String getTszt() { + return tszt; + } + + public void setTszt(String tszt) { + this.tszt = tszt; + } + + @Override + public String toString() { + return "BadDebtProvisionDt3{" + + "mainId='" + mainId + '\'' + + ", customerCode='" + customerCode + '\'' + + ", customerName='" + customerName + '\'' + + ", group_invoice_no='" + group_invoice_no + '\'' + + ", invoiceNo='" + invoiceNo + '\'' + + ", finishedTime='" + finishedTime + '\'' + + ", orifinishedTime='" + orifinishedTime + '\'' + + ", sqjtyqrq='" + sqjtyqrq + '\'' + + ", zdje='" + zdje + '\'' + + ", skzt='" + skzt + '\'' + + ", yskje='" + yskje + '\'' + + ", qskje='" + qskje + '\'' + + ", wskje='" + wskje + '\'' + + ", kpzt='" + kpzt + '\'' + + ", sckprq='" + sckprq + '\'' + + ", ykpje='" + ykpje + '\'' + + ", wkpje='" + wkpje + '\'' + + ", jyjtje='" + jyjtje + '\'' + + ", sjjtje='" + sjjtje + '\'' + + ", bu='" + bu + '\'' + + ", tszt='" + tszt + '\'' + + '}'; + } +} diff --git a/src/main/java/com/api/nonstandardext/ey/utils/EyLogger.java b/src/main/java/com/api/nonstandardext/ey/utils/EyLogger.java new file mode 100644 index 0000000..4f4f61c --- /dev/null +++ b/src/main/java/com/api/nonstandardext/ey/utils/EyLogger.java @@ -0,0 +1,93 @@ +package com.api.nonstandardext.ey.utils; + +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.GCONST; +import weaver.general.TimeUtil; +import weaver.general.Util; + +import java.io.*; + +public class EyLogger extends BaseBean{ + + boolean isDebug = false; + + public EyLogger() { + + } + + /** + * 构造方法 + */ + public EyLogger(RecordSet rs) { + String logSql = "select value from uf_systemconfig where config_key = 'DebugLogger'"; + rs.execute(logSql); + if (rs.next()){ + String valule = Util.null2String(rs.getString("value")); + if("1".equals(valule)){ + isDebug = true; + } + } + } + + /** + * 写入同步的日志文件 + */ + public void writeLogInfo(String o,String s){ + BufferedWriter out = null; + try { + String filename = "ey_" + TimeUtil.getCurrentDateString() + "_ecology.log"; + + String folder = GCONST.getRootPath() + "log" + File.separatorChar + "ey_dev_log"; + + //this.writeDebugLog("folder:[" + folder + "]"); + + File f = new File(folder); + + // 创建文件夹 + if (!f.exists()) { + f.mkdirs(); + } + + f = new File(folder + File.separatorChar + filename); + + if(!f.exists()){//文件不存在,则直接创建 + f.createNewFile(); + } + + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f, true))); + + out.write("[" + o.getClass() + "][" + TimeUtil.getCurrentTimeString() + "]:"+ s + "\r\n"); + + //关闭写入流 + if (out != null){ + out.close(); + } + + } catch (IOException e) { + if (out != null){ + try { + out.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + e.printStackTrace(); + this.writeDebugLog("创建日志文件存在异常:[" + e.getMessage() + "/" + e.toString() + "]"); + } finally { + if (out != null){ + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + public void writeDebugLog(Object logstr){ + if(isDebug){ + this.writeLog(logstr.toString()); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfig.java b/src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfig.java new file mode 100644 index 0000000..ba14776 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfig.java @@ -0,0 +1,24 @@ +package com.api.nonstandardext.model_field_async.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + *

配置主表对象

+ * + * @author xuanran.wang + * @date 2023/6/26 14:33 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ModelFieldAsyncConfig { + private String modelTable; + private String onlyMark; + private String cusWhereSql; + private String tableName; + private List configDetailList; +} diff --git a/src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfigClass.java b/src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfigClass.java new file mode 100644 index 0000000..0314446 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfigClass.java @@ -0,0 +1,20 @@ +package com.api.nonstandardext.model_field_async.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + *

建模字段同步执行类配置

+ * + * @author xuanran.wang + * @date 2023/6/27 10:18 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ModelFieldAsyncConfigClass { + private String onlyMark; + private String className; + private String detailIndex; +} diff --git a/src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfigDetail.java b/src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfigDetail.java new file mode 100644 index 0000000..be7d294 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/model_field_async/entity/ModelFieldAsyncConfigDetail.java @@ -0,0 +1,24 @@ +package com.api.nonstandardext.model_field_async.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + *

配置明细对象

+ * + * @author xuanran.wang + * @date 2023/6/26 14:34 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ModelFieldAsyncConfigDetail { + private String detailIndex; + private String targetField; + private String valueField; + private int getValueType; + private String valueContext; + private String targetFieldName; + private String valueFieldName; +} diff --git a/src/main/java/com/api/nonstandardext/model_field_async/interfaces/TriFunction.java b/src/main/java/com/api/nonstandardext/model_field_async/interfaces/TriFunction.java new file mode 100644 index 0000000..882fcc2 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/model_field_async/interfaces/TriFunction.java @@ -0,0 +1,12 @@ +package com.api.nonstandardext.model_field_async.interfaces; + +/** + *

三个参数的函数接口

+ * + * @author xuanran.wang + * @date 2023/6/28 10:06 + */ +@FunctionalInterface +public interface TriFunction { + R apply(T t, U u, V v); +} \ No newline at end of file diff --git a/src/main/java/com/api/nonstandardext/model_field_async/mapper/ModelFieldAsyncMapper.java b/src/main/java/com/api/nonstandardext/model_field_async/mapper/ModelFieldAsyncMapper.java new file mode 100644 index 0000000..ab03066 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/model_field_async/mapper/ModelFieldAsyncMapper.java @@ -0,0 +1,105 @@ +package com.api.nonstandardext.model_field_async.mapper; + +import aiyh.utils.annotation.recordset.*; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfig; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfigClass; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfigDetail; + +import java.util.List; +import java.util.Map; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/6/26 14:39 + */ +@SqlMapper +public interface ModelFieldAsyncMapper { + + @Select("select * from uf_model_filed_async_class_config where class_name = #{className}") + ModelFieldAsyncConfigClass selectModelFieldAsyncConfigClass(@ParamMapper("className") String className); + + @Select("SELECT a.*,b.tablename as table_name, c.id as model_id " + + "FROM uf_model_field_async a " + + "left join workflow_mode_table_view b " + + "on a.model_table = b.id " + + "left join modeinfo c " + + "on a.model_table = c.formid " + + "where only_mark = #{onlyMark}") + @CollectionMappings({ + @CollectionMapping(property = "configDetailList", + column = "id", + id = @Id(value = Integer.class, methodId = 1)) + }) + ModelFieldAsyncConfig selectConfigByOnlyMark(@ParamMapper("onlyMark") String onlyMark); + + /** + *

查询配置表明细表信息

+ * @author xuanran.wang + * @dateTime 2023/3/1 16:39 + * @param mainId 主表数据id + * @return 配置集合 + **/ + @Select("select a.*,b.fieldname target_field_name, c.fieldname value_field_name " + + "from uf_model_field_async_dt1 a " + + "left join workflow_field_table_view b " + + "on a.target_field = b.id " + + "left join workflow_field_table_view c " + + "on a.value_field = c.id " + + "where mainid = #{mainId} " + + "and ( enable is null or enable = 0 )") + @CollectionMethod(1) + List selectConfigDetail(@ParamMapper("mainId") int mainId); + + /** + *

查询数据总条数

+ * @author xuanran.wang + * @dateTime 2023/6/26 15:15 + * @param modelTableName 表名 + * @param where 自定义数据条件 + * @return 数据总条数 + **/ + @Select("select count(*) from $t{modelTableName} $t{where}") + Integer selectModelTableCount(@ParamMapper("modelTableName") String modelTableName, + @ParamMapper("where") String where); + /** + *

分页查询建模数据

+ * @author xuanran.wang + * @dateTime 2023/6/26 15:15 + * @param modelTableName 表名 + * @param offset 首页 + * @param pageSize 分页大小 + * @return 建模数据 + **/ + @Select("SELECT * " + + "FROM $t{modelTableName} " + + "$t{where} " + + "LIMIT $t{offset}, $t{pageSize}") + @CaseConversion(value = false) + List> selectModelContent(@ParamMapper("modelTableName") String modelTableName, + @ParamMapper("where") String where, + @ParamMapper("offset") Integer offset, + @ParamMapper("pageSize") Integer pageSize); + + @Select("SELECT * " + + "FROM $t{modelTableName} " + + "$t{where}") + @CaseConversion(value = false) + List> selectModelContent(@ParamMapper("modelTableName")String modelTableName, @ParamMapper("where")String where); + + @Select("SELECT * " + + "FROM $t{modelTableName} " + + "$t{cusWhere}") + @CaseConversion(value = false) + Map selectMainModelContent(@ParamMapper("modelTableName")String modelTableName, + @ParamMapper("id") String id, + @ParamMapper("cusWhere")String where); + + + @Select(custom = true) + String selectCustomerSql(@SqlString String sql, + @ParamMapper("detail") Map detailMap, + @ParamMapper("main") Map mainMap); + +} diff --git a/src/main/java/com/api/nonstandardext/model_field_async/service/ModelFieldAsyncServiceImpl.java b/src/main/java/com/api/nonstandardext/model_field_async/service/ModelFieldAsyncServiceImpl.java new file mode 100644 index 0000000..6e133cd --- /dev/null +++ b/src/main/java/com/api/nonstandardext/model_field_async/service/ModelFieldAsyncServiceImpl.java @@ -0,0 +1,247 @@ +package com.api.nonstandardext.model_field_async.service; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.recordset.MapperBuilderSql; +import com.alibaba.fastjson.JSONObject; +import lombok.Setter; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.xuanran.wang.common.mapper.CommonMapper; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfig; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfigClass; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfigDetail; +import com.api.nonstandardext.model_field_async.mapper.ModelFieldAsyncMapper; +import com.api.nonstandardext.model_field_async.util.EyCusModelFieldValueRuleMethod; + +import java.util.*; +import java.util.stream.Collectors; + +/** + *

同步建模字段值

+ * + * @author xuanran.wang + * @date 2023/6/26 14:31 + */ +@Setter +public class ModelFieldAsyncServiceImpl { + + private final ModelFieldAsyncMapper asyncMapper = Util.getMapper(ModelFieldAsyncMapper.class); + + private final CommonMapper commonMapper = Util.getMapper(CommonMapper.class); + + private Integer pageSize = 1000; + + private final Logger logger = Util.getLogger(); + + /** + *

根据类名查询配置

+ * + * @param className 类名 + * @return 配置对象 + * @author xuanran.wang + * @dateTime 2023/6/7 11:28 + **/ + public ModelFieldAsyncConfigClass getConfigClass(String className) { + ModelFieldAsyncConfigClass config = asyncMapper.selectModelFieldAsyncConfigClass(className); + if(Objects.isNull(config)){ + throw new CustomerException("该className [ " + className + " ] 在uf_model_filed_async_class_config配置表中未找到对应的配置!"); + } + return config; + } + + /** + *

根据模块id查询配置

+ * + * @param onlyMark 唯一标识 + * @return 配置对象 + * @author xuanran.wang + * @dateTime 2023/6/7 11:28 + **/ + public ModelFieldAsyncConfig getConfig(String onlyMark) { + ModelFieldAsyncConfig config = asyncMapper.selectConfigByOnlyMark(onlyMark); + if(Objects.isNull(config) || CollectionUtils.isEmpty(config.getConfigDetailList())){ + throw new CustomerException("该唯一标识在 [ " + onlyMark+ " +uf_model_field_async配置表中未找到对应的配置!或存在该配置但是明细数据为空!"); + } + return config; + } + + + /** + *

通过类名同步数据

+ * @author xuanran.wang + * @dateTime 2023/6/27 11:45 + * @param className 类名 + * @param dataIds 数据ids + **/ + public void asyncDataByClassName(String className, String dataIds){ + if(StringUtils.isBlank(dataIds)){ + logger.error("dataIds can not be empty!"); + return; + } + try { + ModelFieldAsyncConfigClass configClass = getConfigClass(className); + String onlyMark = configClass.getOnlyMark(); + ModelFieldAsyncConfig asyncConfig = getConfig(onlyMark); + for (String dataId : dataIds.split(",")) { + asyncModelField(configClass.getDetailIndex(), dataId, asyncConfig); + } + }catch (Exception e){ + logger.error("============== asyncDataByClassName error : " + e.getMessage() + " =============="); + logger.error(Util.getErrString(e)); + } + } + + /** + *

进行建模字段数据同步

+ * @author xuanran.wang + * @dateTime 2023/6/26 17:18 + * @param detailIndexList 需要同步的明细下标 -1 代表主表 -1,1,2 : 代表主表, 明细1, 明细2 + * @param config 同步配置集合 + **/ + public void asyncAllModelField(String detailIndexList, ModelFieldAsyncConfig config){ + asyncModelField(detailIndexList, "", config); + } + + /** + *

进行建模字段数据同步

+ * @author xuanran.wang + * @dateTime 2023/6/26 17:18 + * @param detailIndexList 需要同步的明细下标 -1 代表主表 -1,1,2 : 代表主表, 明细1, 明细2 + * @param dataId 数据id + * @param config 同步配置集合 + **/ + public void asyncModelField(String detailIndexList, String dataId, ModelFieldAsyncConfig config){ + List configDetailList = config.getConfigDetailList(); + Map> groups = configDetailList.stream() + .collect(Collectors.groupingBy(ModelFieldAsyncConfigDetail::getDetailIndex)); + String preSuffix = " id "; + boolean limit = StringUtils.isBlank(dataId); + for (String index : detailIndexList.split(",")) { + if(StringUtils.isBlank(index)){ + continue; + } + // 该明细/主表的配置集合 + List configDetails = groups.get(index); + if(CollectionUtils.isEmpty(configDetailList)){ + logger.error("index = " + index + " not found config! current configs : " + JSONObject.toJSONString(groups)); + continue; + } + String tableName = config.getTableName(); + String mainTableName = config.getTableName(); + // 如果是-1则代表同步主表数据 + if(!"-1".equals(index)){ + tableName += "_dt" + index; + preSuffix = " mainid "; + } + String cusWhereSql = buildWhereSql(Util.null2DefaultStr(config.getCusWhereSql(),""), dataId, preSuffix); + String cusMainWhereSql = buildWhereSql(Util.null2DefaultStr(config.getCusWhereSql(),""), dataId, "id"); + // 获取主表数据 + Map mainMap = asyncMapper.selectMainModelContent(mainTableName, dataId, cusMainWhereSql); + asyncAllData(tableName, cusWhereSql, configDetails, limit, mainMap); + } + } + + /** + *

同步所有的数据

+ * @author xuanran.wang + * @dateTime 2023/6/27 11:44 + * @param tableName 表名 + * @param cusWhereSql 自定义where sql + * @param configDetails 配置表集合 + * @param limit 是否需要分页同步 + * @param mainMap 主表数据 + **/ + public void asyncAllData(String tableName, + String cusWhereSql, + List configDetails, + boolean limit, + Map mainMap){ + // 数据总条数 + int count = limit ? asyncMapper.selectModelTableCount(tableName, cusWhereSql) : 1; + // 总页数 + int pageCount = (int) Math.ceil((double) count / pageSize); + int pageNumber = 1; + while (pageNumber <= pageCount){ + int offset = (pageNumber - 1) * pageSize; + // 分页查数据 + List> dataList = asyncMapper.selectModelContent(tableName, cusWhereSql, offset, pageSize); + if(CollectionUtils.isEmpty(dataList)){ + pageNumber++; + continue; + } + convertDataList(tableName, dataList, configDetails, mainMap); + pageNumber++; + } + } + + /** + *

构建where语句

+ * @author xuanran.wang + * @dateTime 2023/6/27 11:44 + * @param modelWhereSql 配置表中的where sql + * @param dataId 数据id + * @param preSuffix 前缀 mainId or id + * @return 构建的where语句 + **/ + public String buildWhereSql(String modelWhereSql, String dataId, String preSuffix){ + StringBuilder sb = new StringBuilder(); + if(StringUtils.isNotBlank(modelWhereSql)){ + modelWhereSql = Util.sbc2dbcCase(modelWhereSql); + sb.append(modelWhereSql); + } + if(StringUtils.isNotBlank(dataId)){ + if(sb.length() > 0){ + sb.append(" and "); + } + sb.append(preSuffix).append(" = ").append(dataId); + } + sb.insert(0, " where "); + return sb.toString(); + } + + /** + *

将建模集合数据进行自定义转换

+ * @author xuanran.wang + * @dateTime 2023/6/26 17:20 + * @param tableName 表名 + * @param dataList 建模数据集合 + * @param configDetails 配置集合 + * @param mainMap 主表数据 + **/ + public void convertDataList(String tableName, List> dataList, + List configDetails, Map mainMap){ + List> res = new ArrayList<>(); + for (Map data : dataList) { + res.add(convertData(data, configDetails, mainMap)); + } + // 需要进行更新的字段集合 + Map fields = configDetails.stream().collect(Collectors.toMap(ModelFieldAsyncConfigDetail::getTargetFieldName, item -> "")); + String updateSql = MapperBuilderSql.builderUpdateSql(tableName, fields,"item"); + updateSql += " where id = #{item.id}"; + if (!commonMapper.updateModelInfoList(updateSql, res)) { + throw new CustomerException("出错了... 更新 " + tableName + " 失败!"); + } + } + + /** + *

将单条数据进行转换

+ * @author xuanran.wang + * @dateTime 2023/6/26 17:20 + * @param data 明细单条数据 + * @param configDetails 配置对象 + * @param mainMap 主表数据 + * @return 转换后的map + **/ + public Map convertData(Map data, List configDetails, Map mainMap){ + Map res = new HashMap<>(); + for (ModelFieldAsyncConfigDetail detail : configDetails) { + Object convert = EyCusModelFieldValueRuleMethod.VALUE_RULE_FUNCTION.get(detail.getGetValueType()).apply(detail, data, mainMap); + res.put(detail.getTargetFieldName(), convert); + } + res.put("id", data.get("id")); + return res; + } + +} diff --git a/src/main/java/com/api/nonstandardext/model_field_async/service/convert/CusModelFieldAsyncConvert.java b/src/main/java/com/api/nonstandardext/model_field_async/service/convert/CusModelFieldAsyncConvert.java new file mode 100644 index 0000000..a121786 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/model_field_async/service/convert/CusModelFieldAsyncConvert.java @@ -0,0 +1,18 @@ +package com.api.nonstandardext.model_field_async.service.convert; + +import aiyh.utils.Util; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfigDetail; +import org.apache.log4j.Logger; + +import java.util.Map; + +/** + *

自定义转换接口

+ * + * @author xuanran.wang + * @date 2023/4/11 16:49 + */ +public interface CusModelFieldAsyncConvert { + Logger log = Util.getLogger(); + Object cusConvert(ModelFieldAsyncConfigDetail configDetail, Map detailMap, Map mainMap, Map pathParam); +} diff --git a/src/main/java/com/api/nonstandardext/model_field_async/util/EyCusModelFieldValueRuleMethod.java b/src/main/java/com/api/nonstandardext/model_field_async/util/EyCusModelFieldValueRuleMethod.java new file mode 100644 index 0000000..857fba8 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/model_field_async/util/EyCusModelFieldValueRuleMethod.java @@ -0,0 +1,104 @@ +package com.api.nonstandardext.model_field_async.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfigDetail; +import com.api.nonstandardext.model_field_async.interfaces.TriFunction; +import com.api.nonstandardext.model_field_async.mapper.ModelFieldAsyncMapper; +import com.google.common.base.Strings; +import org.apache.log4j.Logger; +import weaver.xuanran.wang.eny.data_async.service.convert.CusAsyncConvert; +import com.api.nonstandardext.model_field_async.service.convert.CusModelFieldAsyncConvert; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +/** + *

值处理方法

+ * + *

create: 2023-02-02 15:15

+ * + * @author youHong.ai + */ + +public class EyCusModelFieldValueRuleMethod { + + + public static final Map, Map, Object>> VALUE_RULE_FUNCTION = new HashMap<>(); + + private final ModelFieldAsyncMapper mapper = Util.getMapper(ModelFieldAsyncMapper.class); + + private final Logger log = Util.getLogger(); + + static { + Class valueRuleMethodClass = EyCusModelFieldValueRuleMethod.class; + Method[] methods = valueRuleMethodClass.getMethods(); + for (Method method : methods) { + if (method.isAnnotationPresent(ValueRuleMethodNo.class)) { + ValueRuleMethodNo annotation = method.getAnnotation(ValueRuleMethodNo.class); + int value = annotation.value(); + VALUE_RULE_FUNCTION.put(value, (detail, detailmap, mainMap) -> { + try { + EyCusModelFieldValueRuleMethod eyCusModelFieldValueRuleMethod = new EyCusModelFieldValueRuleMethod(); + return method.invoke(eyCusModelFieldValueRuleMethod, detail, detailmap, mainMap); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }); + } + } + } + + @ValueRuleMethodNo(value = 0, desc = "明细表数据不转换") + public Object getFixValue(ModelFieldAsyncConfigDetail configDetail,Map detailMap, Map mainMap) { + return Util.null2DefaultStr(detailMap.get(configDetail.getValueFieldName()),""); + } + + + @ValueRuleMethodNo(value = 1, desc = "默认值") + public Object getCusText(ModelFieldAsyncConfigDetail configDetail, Map detailMap, Map mainMap) { + return Util.null2DefaultStr(configDetail.getValueContext(),""); + } + + + @ValueRuleMethodNo(value = 2, desc = "自定义sql") + public Object getCustomerSqlValue(ModelFieldAsyncConfigDetail configDetail, Map detailMap, Map mainMap) { + String cusText = configDetail.getValueContext(); + cusText = Util.sbc2dbcCase(cusText); + if (Strings.isNullOrEmpty(cusText)) { + return null; + } + if (!cusText.startsWith("select")) { + return null; + } + return Util.null2DefaultStr(mapper.selectCustomerSql(cusText, detailMap, mainMap),""); + } + + @ValueRuleMethodNo(value = 3, desc = "自定义接口") + public Object getCusConvertInterface(ModelFieldAsyncConfigDetail configDetail, Map detailMap, Map mainMap) { + String cusText = configDetail.getValueContext(); + if(Strings.isNullOrEmpty(cusText)){ + return null; + } + try { + Class clazz = Class.forName(cusText); + if(!CusAsyncConvert.class.isAssignableFrom(clazz)){ + throw new CustomerException(cusText + " not implements getLogFilePath.api.nonstandardext.model_field_async.service.convert"); + } + CusModelFieldAsyncConvert o = (CusModelFieldAsyncConvert) clazz.newInstance(); + Map pathParam = Util.parseCusInterfacePathParam(cusText); + return o.cusConvert(configDetail, detailMap, mainMap, pathParam); + }catch (Exception e){ + log.error("getCusConvertInterface error! " + e.getMessage()); + return null; + } + } + + @ValueRuleMethodNo(value = 4, desc = "转主表数据") + public Object getMainTableFieldValue(ModelFieldAsyncConfigDetail configDetail, Map detailMap, Map mainMap) { + return Util.null2DefaultStr(mainMap.get(configDetail.getValueFieldName()),""); + } + +} diff --git a/src/main/java/com/api/nonstandardext/model_field_async/util/ValueRuleMethodNo.java b/src/main/java/com/api/nonstandardext/model_field_async/util/ValueRuleMethodNo.java new file mode 100644 index 0000000..b3e3eb1 --- /dev/null +++ b/src/main/java/com/api/nonstandardext/model_field_async/util/ValueRuleMethodNo.java @@ -0,0 +1,19 @@ +package com.api.nonstandardext.model_field_async.util; + +import java.lang.annotation.*; + +/** + *

值处理方法编号注解

+ * + *

create: 2023-02-02 15:18

+ * + * @author youHong.ai + */ + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface ValueRuleMethodNo { + int value(); + String desc(); +} diff --git a/src/main/java/weaver/formmode/customjavacode/modeexpand/ey/jiahx/TransferSelect.java b/src/main/java/weaver/formmode/customjavacode/modeexpand/ey/jiahx/TransferSelect.java new file mode 100644 index 0000000..fd3b62e --- /dev/null +++ b/src/main/java/weaver/formmode/customjavacode/modeexpand/ey/jiahx/TransferSelect.java @@ -0,0 +1,130 @@ +package weaver.formmode.customjavacode.modeexpand.ey.jiahx; + +import com.api.nonstandardext.model_field_async.service.ModelFieldAsyncServiceImpl; +import weaver.conn.RecordSet; +import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Description + * @Author 贾寒旭 + * @Date 2023/4/6 + * @Other + * @Version + */ +public class TransferSelect extends AbstractModeExpandJavaCodeNew { + + private final ModelFieldAsyncServiceImpl service = new ModelFieldAsyncServiceImpl(); + + @Override + public Map doModeExpand(Map param) { + BaseBean baseBean = new BaseBean(); + +// src/weaver/formmode/customjavacode/modeexpand/getKmmb.java + baseBean.writeLog("保存自定义接口开始TransferSelect>>>>>"); + Map result = new HashMap(); + try { + User user = (User) param.get("user"); + int billid = -1;//数据id + int modeid = -1;//模块id + RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo"); + if (requestInfo != null) { + billid = Util.getIntValue(requestInfo.getRequestid()); + modeid = Util.getIntValue(requestInfo.getWorkflowid()); + RecordSet upRs = new RecordSet(); + if (billid > 0 && modeid > 0) { + //------请在下面编写业务逻辑代码------ +// billingType,requestType,billingIssueType,clientType,multipleBilling,serviceType,LeType + String sql = "select * from uf_zdjmbd where id = ?"; + RecordSet rs = new RecordSet(); + rs.executeQuery(sql, billid); + while (rs.next()) { + String billingTypewb = Util.null2String(rs.getString("billingTypewb")); + String requestTypewb = Util.null2String(rs.getString("requestTypewb")); + String billingIssueTypewb = Util.null2String(rs.getString("billingIssueTypewb")); + String clientTypewb = Util.null2String(rs.getString("clientTypewb")); + String multipleBillingwb = Util.null2String(rs.getString("multipleBillingwb")); + String serviceTypewb = Util.null2String(rs.getString("serviceTypewb")); + String LeTypewb = Util.null2String(rs.getString("LeTypewb")); + //2023年6月7日新增engCodewb转换engCode --cds + String engCodewb = Util.null2String(rs.getString("engCodewb")); + + if (!engCodewb.equals("")) { + String Upsql = "update uf_zdjmbd uf ,uf_xmjbxxjmbd xm set uf.engCode = xm.engagement_code " + + "where uf.engCodewb = xm.engagement_code1 and uf.engCodewb=? and uf.id = ?"; + upRs.executeUpdate(Upsql, engCodewb, billid); + } + if (!billingTypewb.equals("")) { + String Upsql = "update uf_zdjmbd uf ,uf_vmschange_dt1 uv set uf.billingType = uv.zdid" + + " where uf.billingTypewb = uv.zdnr and uf.billingType is null and uf.id = ?"; + upRs.executeUpdate(Upsql, billid); + } + if (!requestTypewb.equals("")) { + String Upsql = "update uf_zdjmbd uf ,uf_vmschange_dt1 uv set uf.requestType = uv.zdid " + + " where uf.requestTypewb = uv.zdnr and uf.requestType is null and uf.id = ?"; + upRs.executeUpdate(Upsql, billid); + } + if (!billingIssueTypewb.equals("")) { + String Upsql = "update uf_zdjmbd uf ,uf_vmschange_dt1 uv set uf.billingIssueType = uv.zdid " + + " where uf.billingIssueTypewb = uv.zdnr and uf.billingIssueType is null and uf.id = ?"; + upRs.executeUpdate(Upsql, billid); + } + if (!clientTypewb.equals("")) { + String Upsql = "update uf_zdjmbd uf ,uf_vmschange_dt1 uv set uf.clientType = uv.zdid " + + " where uf.clientTypewb = uv.zdnr and uf.clientType is null and uf.id = ?"; + upRs.executeUpdate(Upsql, billid); + } + if (!multipleBillingwb.equals("")) { + String Upsql = "update uf_zdjmbd uf ,uf_vmschange_dt1 uv set uf.multipleBilling = uv.zdid " + + " where uf.multipleBillingwb = uv.zdnr and uf.multipleBilling is null and uf.id = ?"; + upRs.executeUpdate(Upsql, billid); + } + if (!serviceTypewb.equals("")) { + String Upsql = "update uf_zdjmbd uf ,uf_vmschange_dt1 uv set uf.serviceType = uv.zdid " + + " where uf.serviceTypewb = uv.zdnr and uf.serviceType is null and uf.id = ?"; + upRs.executeUpdate(Upsql, billid); + } + if (!LeTypewb.equals("")) { + String Upsql = "update uf_zdjmbd uf ,uf_vmschange_dt1 uv set uf.LeType = uv.zdid " + + " where uf.LeTypewb = uv.zdnr and uf.LeType is null and uf.id = ?"; + upRs.executeUpdate(Upsql, billid); + } + } + + rs.executeQuery("select dt1.engCodewb,dt1.id from uf_zdjmbd_dt1 dt1 left join uf_zdjmbd m on dt1.mainid=m.id where m.id = ?", billid); + + //更新uf_zdjmbd_dt1,engCode + String Upsql = "update uf_zdjmbd_dt1 uf ,uf_xmjbxxjmbd xm set uf.engCode = xm.engagement_code " + + "where uf.engCodewb = xm.engagement_code1 and uf.engCodewb=? and uf.id = ?"; + while (rs.next()) { + String engCodewb = Util.null2String(rs.getString("engCodewb")); + String id = Util.null2String(rs.getString("id")); + if (!"".equals(engCodewb)) { + boolean b = upRs.executeUpdate(Upsql, engCodewb, id); + baseBean.writeLog("TransferSelect转换明细engCode-----Flag:" + b); + } + } + /** + * 通过配置同步字段 + * @author xuanran.wang + * @date 2023-06-27 + */ + service.asyncDataByClassName(this.getClass().getSimpleName(), String.valueOf(billid)); + + + } + } + } catch (Exception e) { + baseBean.writeLog("TransferSelect catch exception:" + e); + result.put("errmsg", "自定义出错信息"); + result.put("flag", "false"); + } + return result; + } +} diff --git a/src/main/java/weaver/formmode/customjavacode/modeexpand/ey/jiahx/TransferSelect_fp.java b/src/main/java/weaver/formmode/customjavacode/modeexpand/ey/jiahx/TransferSelect_fp.java new file mode 100644 index 0000000..860dc8b --- /dev/null +++ b/src/main/java/weaver/formmode/customjavacode/modeexpand/ey/jiahx/TransferSelect_fp.java @@ -0,0 +1,73 @@ +package weaver.formmode.customjavacode.modeexpand.ey.jiahx; + +import com.api.nonstandardext.model_field_async.service.ModelFieldAsyncServiceImpl; +import weaver.conn.RecordSet; +import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Description + * @Author 贾寒旭 + * @Date 2023/4/6 + * @Other + * @Version + */ +//更新 uf_fptbjmbd_dt1 ,engCode +public class TransferSelect_fp extends AbstractModeExpandJavaCodeNew { + + private final ModelFieldAsyncServiceImpl service = new ModelFieldAsyncServiceImpl(); + + @Override + public Map doModeExpand(Map param) { + BaseBean baseBean = new BaseBean(); + +// src/weaver/formmode/customjavacode/modeexpand/getKmmb.java + baseBean.writeLog("保存自定义接口开始TransferSelect_fp>>>>>"); + Map result = new HashMap(); + try { + User user = (User) param.get("user"); + int billid = -1;//数据id + int modeid = -1;//模块id + RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo"); + if (requestInfo != null) { + billid = Util.getIntValue(requestInfo.getRequestid()); + modeid = Util.getIntValue(requestInfo.getWorkflowid()); + RecordSet upRs = new RecordSet(); + if (billid > 0 && modeid > 0) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select dt1.engCodewb,dt1.id from uf_fptbjmbd_dt1 dt1 left join uf_fptbjmbd m on dt1.mainid=m.id where m.id = ?", billid); + + //更新uf_fptbjmbd_dt1,engCode + String Upsql = "update uf_fptbjmbd_dt1 uf ,uf_fptbjmbd xm set uf.engCode = xm.engagement_code " + + "where uf.engCodewb = xm.engagement_code1 and uf.engCodewb=? and uf.id = ?"; + while (rs.next()) { + String engCodewb = Util.null2String(rs.getString("engCodewb")); + String id = Util.null2String(rs.getString("id")); + if (!"".equals(engCodewb)) { + boolean b = upRs.executeUpdate(Upsql, engCodewb, id); + baseBean.writeLog("TransferSelect_fp转换明细engCode-----Flag:" + b); + } + } + /** + * 通过配置同步字段 + * @author xuanran.wang + * @date 2023-06-27 + */ + service.asyncDataByClassName(this.getClass().getSimpleName(), String.valueOf(billid)); + + } + } + } catch (Exception e) { + baseBean.writeLog("TransferSelect_fp catch exception:" + e); + result.put("errmsg", "自定义出错信息"); + result.put("flag", "false"); + } + return result; + } +} diff --git a/src/test/java/ebu7dev1/common/getlog/CusTest.java b/src/test/java/ebu7dev1/common/getlog/CusTest.java new file mode 100644 index 0000000..ade6442 --- /dev/null +++ b/src/test/java/ebu7dev1/common/getlog/CusTest.java @@ -0,0 +1,38 @@ +package ebu7dev1.common.getlog; + +import basetest.BaseTest; +import com.alibaba.fastjson.JSONObject; +import com.api.ebu7dev1.common.getlog.service.GetLogService; +import com.api.ebu7dev1.common.getlog.util.GetLogUtil; +import org.junit.Test; + +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/7/1 17:33 + */ +public class CusTest extends BaseTest { + + private final GetLogService service = new GetLogService(); + + @Test + public void testA() throws FileNotFoundException { + List list = new ArrayList<>(); + for (int i = 0; i <= 8; i++) { + list.add(i + ""); + } + String base = "/Users/wangxuanran/company/project/ebu_ecology_dev1"; + List> path = GetLogUtil.getLogPathByLogType(base, base, list); + + Map>> map = GetLogUtil.getLogFilePath(path, "2023-07-01", "2023-07-02"); + + System.out.println(JSONObject.toJSONString(map)); +// GetLogUtil.com(base, map); + } +} diff --git a/src/test/java/xuanran/wang/checker/Checker.java b/src/test/java/xuanran/wang/checker/Checker.java new file mode 100644 index 0000000..093a7f2 --- /dev/null +++ b/src/test/java/xuanran/wang/checker/Checker.java @@ -0,0 +1,118 @@ +package xuanran.wang.checker; + +import xuanran.wang.checker.fun.HandleFunction; +import xuanran.wang.checker.fun.Predicate; +import xuanran.wang.checker.fun.SFunction; +import xuanran.wang.checker.handler.ConditionHandler; + +import java.util.*; + +/** + * 参数校验工具 + * + * @author alan + * @date 2023/06/12 + */ +public class Checker { + + private final List> conditions = new ArrayList<>(); + + private static final Map FUNCTION_HASH_MAP = new HashMap<>(); + + static { + FUNCTION_HASH_MAP.put(ECheckType.NE, ConditionHandler::handleNe); + FUNCTION_HASH_MAP.put(ECheckType.NOTNULL, ConditionHandler::handleNotNull); + FUNCTION_HASH_MAP.put(ECheckType.NOTNULL_NE, ConditionHandler::handleNotNullNe); + FUNCTION_HASH_MAP.put(ECheckType.IN, ConditionHandler::handleIn); + FUNCTION_HASH_MAP.put(ECheckType.CUSTOM, ConditionHandler::handleCustom); + } + + /** + * 判断该值不能为传入值 + */ + public Checker ne(SFunction column, Object val, String desc) { + conditions.add(new Condition<>(getFieldMeta(column), ECheckType.NE, val, desc)); + return this; + } + + /** + * 判断值不能为空 + */ + public Checker notNull(SFunction column, String desc) { + conditions.add(new Condition(getFieldMeta(column), ECheckType.NOTNULL, null, desc)); + return this; + } + + /** + * 不能为空且不能为传入值 + */ + public Checker notNe(SFunction column, Object val, String desc) { + conditions.add(new Condition<>(getFieldMeta(column), ECheckType.NOTNULL_NE, val, desc)); + return this; + } + + /** + * 不能为空且不能为传入值 + */ + public Checker in(SFunction column, Collection val, String desc) { + conditions.add(new Condition<>(getFieldMeta(column), ECheckType.IN, val, desc)); + return this; + } + + /** + * 判断该值不能为传入值 + */ + public Checker ne(SFunction column, Object val) { + return ne(column, val, null); + } + + /** + * 判断值不能为空 + */ + public Checker notNull(SFunction column) { + return notNull(column, null); + } + + /** + * 不能为空且不能为传入值 + */ + public Checker notNe(SFunction column, Object val) { + return notNe(column, val, null); + } + + /** + * 不能为空且不能为传入值 + */ + public Checker in(SFunction column, Collection val) { + return in(column, val, null); + } + + /** + * 自定义规则 条件成立则抛出 业务异常 + */ + public Checker custom(Predicate resultPredicate, String desc) { + Condition condition = new Condition<>("", ECheckType.CUSTOM, null, desc); + condition.setResultPredicate(resultPredicate); + conditions.add(condition); + return this; + } + + /** + * 执行校验逻辑 + */ + public void check(T obj) { + + if (Objects.isNull(obj)) { + throw new CheckerException("参数为空"); + } + for (Condition condition : conditions) { + FUNCTION_HASH_MAP.get(condition.getType()).apply(obj, condition); + } + + } + + private String getFieldMeta(SFunction column) { + return ConvertUtil.convertToFieldName(column); + } + +} diff --git a/src/test/java/xuanran/wang/checker/CheckerException.java b/src/test/java/xuanran/wang/checker/CheckerException.java new file mode 100644 index 0000000..d01345d --- /dev/null +++ b/src/test/java/xuanran/wang/checker/CheckerException.java @@ -0,0 +1,15 @@ +package xuanran.wang.checker; + +/*** + * 参数校验异常 + * + * @author loser + * @date 2023/06/12 + */ +public class CheckerException extends RuntimeException { + + public CheckerException(String message) { + super(message); + } + +} diff --git a/src/test/java/xuanran/wang/checker/Checkers.java b/src/test/java/xuanran/wang/checker/Checkers.java new file mode 100644 index 0000000..307cba1 --- /dev/null +++ b/src/test/java/xuanran/wang/checker/Checkers.java @@ -0,0 +1,15 @@ +package xuanran.wang.checker; + +/** + * 参数校验工具 + * + * @author alan + * @date 2023/06/12 + */ +public class Checkers { + + public static Checker lambdaCheck() { + return new Checker<>(); + } + +} diff --git a/src/test/java/xuanran/wang/checker/Condition.java b/src/test/java/xuanran/wang/checker/Condition.java new file mode 100644 index 0000000..0ee9435 --- /dev/null +++ b/src/test/java/xuanran/wang/checker/Condition.java @@ -0,0 +1,70 @@ +package xuanran.wang.checker; + + +import xuanran.wang.checker.fun.Predicate; + +/*** + * 条件 + * + * @author loser + * @date 2023/06/12 + */ +public class Condition { + + private String field; + + private ECheckType type; + + private Object val; + + private String desc; + + private Predicate resultPredicate; + + public Condition(String field, ECheckType type, Object val, String desc) { + this.field = field; + this.type = type; + this.val = val; + this.desc = desc; + } + + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } + + public ECheckType getType() { + return type; + } + + public void setType(ECheckType type) { + this.type = type; + } + + public Object getVal() { + return val; + } + + public void setVal(Object val) { + this.val = val; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public Predicate getResultPredicate() { + return resultPredicate; + } + + public void setResultPredicate(Predicate resultPredicate) { + this.resultPredicate = resultPredicate; + } +} diff --git a/src/test/java/xuanran/wang/checker/ConvertUtil.java b/src/test/java/xuanran/wang/checker/ConvertUtil.java new file mode 100644 index 0000000..56be49d --- /dev/null +++ b/src/test/java/xuanran/wang/checker/ConvertUtil.java @@ -0,0 +1,97 @@ +package xuanran.wang.checker; + + + +import xuanran.wang.checker.fun.SFunction; + +import java.io.Serializable; +import java.lang.invoke.SerializedLambda; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + + +/** + * 转换工具 + * + * @author loser + * @date 2023/06/12 + */ +public class ConvertUtil { + + private ConvertUtil() { + } + + public static final String GET = "get"; + + public static final String IS = "is"; + + /** + * 缓存方法应用对应的属性名称 + */ + private static final Map, String> CLASS_FIELD_META_MAP = new ConcurrentHashMap<>(); + + /** + * 转换方法引用为属性名 + */ + public static String convertToFieldName(SFunction fn) { + + SerializedLambda lambda = getSerializedLambda(fn); + String cacheData = CLASS_FIELD_META_MAP.get(fn.getClass()); + if (Objects.nonNull(cacheData)) { + return cacheData; + } + String methodName = lambda.getImplMethodName(); + if (methodName.startsWith(GET)) { + methodName = methodName.substring(3); + } else if (methodName.startsWith(IS)) { + methodName = methodName.substring(2); + } else { + throw new IllegalArgumentException("无效的getter方法:" + methodName); + } + try { + String fieldMeta = firstToLowerCase(methodName); + CLASS_FIELD_META_MAP.put(fn.getClass(), fieldMeta); + return fieldMeta; + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + /** + * 获取一个实现了序列化的lambda函数 + * + * @param fn 目标函数 + * @return 实现了序列化的lambda函数 + */ + public static SerializedLambda getSerializedLambda(Serializable fn) { + + SerializedLambda lambda; + try { + // 提取SerializedLambda并缓存 + Method method = fn.getClass().getDeclaredMethod("writeReplace"); + method.setAccessible(Boolean.TRUE); + lambda = (SerializedLambda) method.invoke(fn); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + return lambda; + + } + + /** + * 首字母转换小写 + * + * @param str 需要转换的字符串 + * @return 转换好的字符串 + */ + public static String firstToLowerCase(final String str) { + if (null == str || str.length() == 0) { + return ""; + } + return str.substring(0, 1).toLowerCase() + str.substring(1); + } +} \ No newline at end of file diff --git a/src/test/java/xuanran/wang/checker/ECheckType.java b/src/test/java/xuanran/wang/checker/ECheckType.java new file mode 100644 index 0000000..6c0ae02 --- /dev/null +++ b/src/test/java/xuanran/wang/checker/ECheckType.java @@ -0,0 +1,17 @@ +package xuanran.wang.checker; + +/** + * 比较类型 + * + * @author loser + * @date 2023/06/12 + */ +public enum ECheckType { + + NE, + NOTNULL, + NOTNULL_NE, + IN, + CUSTOM + +} diff --git a/src/test/java/xuanran/wang/checker/fun/HandleFunction.java b/src/test/java/xuanran/wang/checker/fun/HandleFunction.java new file mode 100644 index 0000000..9ef2975 --- /dev/null +++ b/src/test/java/xuanran/wang/checker/fun/HandleFunction.java @@ -0,0 +1,26 @@ +package xuanran.wang.checker.fun; + + +import xuanran.wang.checker.Condition; + +import java.io.Serializable; + +/*** + * 功能处理器 + * + * @author loser + * @date 2023/06/12 + */ +@FunctionalInterface +public interface HandleFunction extends Serializable { + + /** + * 处理时间 + * + * @param target 目标对象 + * @param condition 条件 + * @return 是否通过 + */ + boolean apply(Object target, Condition condition); + +} diff --git a/src/test/java/xuanran/wang/checker/fun/Predicate.java b/src/test/java/xuanran/wang/checker/fun/Predicate.java new file mode 100644 index 0000000..5db2d0e --- /dev/null +++ b/src/test/java/xuanran/wang/checker/fun/Predicate.java @@ -0,0 +1,20 @@ +package xuanran.wang.checker.fun; + +/*** + * 断言 + * + * @author loser + * @date 2023/06/12 + */ +@FunctionalInterface +public interface Predicate { + + /** + * 断言操作 + * + * @param target 判断对象 + * @return 是否成 + */ + boolean apply(T target); + +} diff --git a/src/test/java/xuanran/wang/checker/fun/SFunction.java b/src/test/java/xuanran/wang/checker/fun/SFunction.java new file mode 100644 index 0000000..f166cff --- /dev/null +++ b/src/test/java/xuanran/wang/checker/fun/SFunction.java @@ -0,0 +1,20 @@ +package xuanran.wang.checker.fun; + +import java.io.Serializable; + +/** + * 支持序列化的 Function + * 为了获取字段名字 + * + * @author loser + * @date 2023/06/12 + */ +@FunctionalInterface +public interface SFunction extends Serializable { + + /** + * 执行方法 + */ + R apply(T t); + +} diff --git a/src/test/java/xuanran/wang/checker/handler/ConditionHandler.java b/src/test/java/xuanran/wang/checker/handler/ConditionHandler.java new file mode 100644 index 0000000..42f13a5 --- /dev/null +++ b/src/test/java/xuanran/wang/checker/handler/ConditionHandler.java @@ -0,0 +1,114 @@ +package xuanran.wang.checker.handler; + +import org.apache.commons.lang3.StringUtils; +import xuanran.wang.checker.CheckerException; +import xuanran.wang.checker.Condition; + +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.Objects; + +/*** + * 条件处理器 + * + * @author loser + * @date 2023/06/12 + */ +@SuppressWarnings("all") +public class ConditionHandler { + + public static boolean handleCustom(Object obj, Condition condition) { + if (condition.getResultPredicate().apply(obj)) { + throw new CheckerException(condition.getDesc()); + } + return true; + } + + public static boolean handleNe(Object obj, Condition condition) { + try { + Class targetClass = obj.getClass(); + Field field = targetClass.getDeclaredField(condition.getField()); + field.setAccessible(true); + Object result = field.get(obj); + if (Objects.equals(result, condition.getVal())) { + throwBizError(condition); + } + } catch (CheckerException e) { + throw e; + } catch (Exception e) { + throwFieldError(condition); + } + return true; + } + + private static void throwFieldError(Condition condition) { + throwMsg(String.format("字段(%s)不存在", condition.getField())); + } + + private static void throwBizError(Condition condition) { + String msg = StringUtils.isEmpty(condition.getDesc()) ? String.format("字段(%s)值错误", condition.getField()) : condition.getDesc(); + throwMsg(msg); + } + + public static boolean handleNotNull(Object obj, Condition condition) { + try { + Class targetClass = obj.getClass(); + Field field = targetClass.getDeclaredField(condition.getField()); + field.setAccessible(true); + Object result = field.get(obj); + if (Objects.isNull(result)) { + throwBizError(condition); + } + } catch (CheckerException e) { + throw e; + } catch (Exception e) { + throwFieldError(condition); + } + return true; + } + + public static boolean handleNotNullNe(Object obj, Condition condition) { + try { + Class targetClass = obj.getClass(); + Field field = targetClass.getDeclaredField(condition.getField()); + field.setAccessible(true); + Object result = field.get(obj); + if (Objects.isNull(result) || result.equals(condition.getVal())) { + throwBizError(condition); + } + } catch (CheckerException e) { + throw e; + } catch (Exception e) { + throwFieldError(condition); + } + return true; + } + + public static boolean handleIn(Object obj, Condition condition) { + + try { + Class targetClass = obj.getClass(); + Field field = targetClass.getDeclaredField(condition.getField()); + field.setAccessible(true); + Object result = field.get(obj); + Object val = condition.getVal(); + if (val instanceof Collection) { + Collection temp = (Collection) val; + if (Objects.isNull(result) || !temp.contains(result)) { + throwBizError(condition); + } + } + } catch (CheckerException e) { + throw e; + } catch (Exception e) { + throwFieldError(condition); + } + return true; + + } + + public static void throwMsg(String msg) { + throw new CheckerException(msg); + } + +} diff --git a/src/test/java/xuanran/wang/common/abstracts/CusAbstractRequestService.java b/src/test/java/xuanran/wang/common/abstracts/CusAbstractRequestService.java new file mode 100644 index 0000000..0fb6956 --- /dev/null +++ b/src/test/java/xuanran/wang/common/abstracts/CusAbstractRequestService.java @@ -0,0 +1,85 @@ +package xuanran.wang.common.abstracts; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSON; +import org.apache.commons.collections.CollectionUtils; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xiao.commons.config.entity.ResponseMapping; +import weaver.xiao.commons.config.service.DealWithMapping; +import weaver.xiao.commons.utils.SqlUtil; +import weaver.xuanran.wang.common.util.CommonUtil; +import xuanran.wang.common.entity.CusRequestParams; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + + +/** + *

+ * + * @author xuanran.wang + * @date 2023/6/26 10:39 + */ +public abstract class CusAbstractRequestService{ + private final DealWithMapping dealWithMapping = new DealWithMapping(); + private CusRequestParams cusRequestParams = null; + private final Logger log = Util.getLogger(); // 获取日志对象 + private final SqlUtil sqlUtil = new SqlUtil(); + protected CusRequestParams getRequestParams(String onlyMark, String billTable, String requestId){ + RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); // 将配置参数通过唯一标识查询处理成树形结构 + if(Objects.isNull(requestMappingConfig)){ + throw new CustomerException("唯一标识为 : " + onlyMark + " ,在参数配置表中没有找到对应的配置!"); + } + String selectMainSql = CommonUtil.getSelectSql(requestMappingConfig, billTable); + RecordSet recordSet = new RecordSet(); + if (recordSet.executeQuery(selectMainSql, requestId) && recordSet.next()) { + String url = requestMappingConfig.getRequestUrl(); + dealWithMapping.setMainTable(billTable); + Map param = dealWithMapping.getRequestParam(recordSet, requestMappingConfig); + this.cusRequestParams = CusRequestParams.builder() + .url(url) + .mainRs(recordSet) + .requestId(requestId) + .requestMappingConfig(requestMappingConfig) + .billTable(billTable) + .requestParam(param) + .build(); + return this.cusRequestParams; + }else { + log.error("该流程暂未查到数据! requestId : " + requestId); + return null; + } + } + + public abstract T apiSend(CusRequestParams cusRequestParams); + + protected void writeBackResponse(Map result){ + if(Objects.isNull(this.cusRequestParams)){ + log.error("cusRequestParams不能为空!"); + } + if(Objects.isNull(result)){ + log.error("响应信息对象不能为空!"); + } + RequestMappingConfig requestMappingConfig = this.cusRequestParams.getRequestMappingConfig(); + List responseMappingList = requestMappingConfig.getResponseMappingList(); + if(CollectionUtils.isEmpty(responseMappingList)){ + return; + } + String billTable = this.cusRequestParams.getBillTable(); + String requestId = this.cusRequestParams.getRequestId(); + Map> writeBackMessage = dealWithMapping.dealResponse(responseMappingList, result); + log.info("回写信息 writeBackMessage ==>"+ JSON.toJSONString(writeBackMessage)); + Map updateMsg = writeBackMessage.get(billTable); + Map whereParam = new HashMap<>(); + whereParam.put("requestid",requestId); + boolean success = sqlUtil.updateMode(billTable, updateMsg, whereParam); + if(!success){ + log.error("数据回写表单失败!"); + } + } +} diff --git a/src/test/java/xuanran/wang/common/entity/CusRequestParams.java b/src/test/java/xuanran/wang/common/entity/CusRequestParams.java new file mode 100644 index 0000000..d669762 --- /dev/null +++ b/src/test/java/xuanran/wang/common/entity/CusRequestParams.java @@ -0,0 +1,30 @@ +package xuanran.wang.common.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import weaver.conn.RecordSet; +import weaver.xiao.commons.config.entity.RequestMappingConfig; + +import java.util.Map; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/6/26 10:42 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CusRequestParams { + private String url; + private RecordSet mainRs; + private Map requestParam; + private String requestId; + private String billTable; + private RequestMappingConfig requestMappingConfig; + private Object cusSuccess; +} diff --git a/src/test/java/xuanran/wang/common/test/ServiceTest.java b/src/test/java/xuanran/wang/common/test/ServiceTest.java new file mode 100644 index 0000000..d15673f --- /dev/null +++ b/src/test/java/xuanran/wang/common/test/ServiceTest.java @@ -0,0 +1,22 @@ +package xuanran.wang.common.test; + +import basetest.BaseTest; +import org.junit.Test; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/6/26 11:05 + */ +public class ServiceTest extends BaseTest { + private final TestServiceImpl service = new TestServiceImpl(); + private final TestServiceImpl service1 = new TestServiceImpl(); + private final TestServiceImpl service2 = new TestServiceImpl(); + @Test + public void testA(){ + service.getA(); + service1.getA(); + service2.getA(); + } +} diff --git a/src/test/java/xuanran/wang/common/test/TestServiceImpl.java b/src/test/java/xuanran/wang/common/test/TestServiceImpl.java new file mode 100644 index 0000000..cc3fee9 --- /dev/null +++ b/src/test/java/xuanran/wang/common/test/TestServiceImpl.java @@ -0,0 +1,28 @@ +package xuanran.wang.common.test; + +import xuanran.wang.common.abstracts.CusAbstractRequestService; +import xuanran.wang.common.entity.CusRequestParams; + +import java.util.HashMap; +import java.util.Map; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/6/26 10:57 + */ +public class TestServiceImpl extends CusAbstractRequestService> { + public void getA(){ + CusRequestParams requestParams = this.getRequestParams("pushSealTask", "formtable_main_22", "182398"); + Map map = apiSend(requestParams); + this.writeBackResponse(map); + } + + @Override + public Map apiSend(CusRequestParams cusRequestParams) { + Map res = new HashMap<>(); + res.put("result","123"); + return res; + } +} diff --git a/src/test/java/xuanran/wang/eny/ModelFieldAsyncTest.java b/src/test/java/xuanran/wang/eny/ModelFieldAsyncTest.java new file mode 100644 index 0000000..cf1698c --- /dev/null +++ b/src/test/java/xuanran/wang/eny/ModelFieldAsyncTest.java @@ -0,0 +1,94 @@ +package xuanran.wang.eny; + +import aiyh.utils.ScriptUtil; +import aiyh.utils.Util; +import aiyh.utils.tool.cn.hutool.core.swing.ScreenUtil; +import aiyh.utils.tool.org.apache.commons.jexl3.JexlContext; +import aiyh.utils.tool.org.apache.commons.jexl3.JexlEngine; +import aiyh.utils.tool.org.apache.commons.jexl3.MapContext; +import basetest.BaseTest; +import com.alibaba.fastjson.JSONObject; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfigClass; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import com.api.nonstandardext.model_field_async.entity.ModelFieldAsyncConfig; +import com.api.nonstandardext.model_field_async.mapper.ModelFieldAsyncMapper; +import com.api.nonstandardext.model_field_async.service.ModelFieldAsyncServiceImpl; +import xuanran.wang.checker.Checkers; +import xuanran.wang.checker.fun.Predicate; +import xuanran.wang.checker.fun.SFunction; + +import java.util.*; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/6/26 14:49 + */ +public class ModelFieldAsyncTest extends BaseTest { + + private final ModelFieldAsyncServiceImpl service = new ModelFieldAsyncServiceImpl(); + private final ModelFieldAsyncMapper asyncMapper = Util.getMapper(ModelFieldAsyncMapper.class); + + @Test + public void testA(){ + ModelFieldAsyncConfig test1 = service.getConfig("test1"); + System.out.println(JSONObject.toJSONString(test1)); +// service.asyncModelField("1,2", test1); + ModelFieldAsyncConfigClass configClass = service.getConfigClass("TransferSelect"); + System.out.println(JSONObject.toJSONString(configClass)); + service.asyncDataByClassName("TransferSelect", "1"); + } + + @Test + public void testB(){ + String json = "{\n" + + "\t\t\"result\":\"86cebabe-cc3d-4ab6-8512-08db76eadf52\",\n" + + "\t\t\"success\":true,\n" + + "\t\t\"unAuthorizedRequest\":false,\n" + + "\t\t\"__abp\":true\n" + + "\t}"; + Map map = JSONObject.parseObject(json, Map.class); + Map parsemap = (Map) parse("", map); + System.out.println("parse : " + JSONObject.toJSONString(parsemap)); + } + + @Test + public void testC(){ + String script = "for (int i = 0; i < 10; i++) { ans.append(b); }"; + Map params = new HashMap<>(); + params.put("a", 2); + params.put("b", "*"); + params.put("ans", new StringBuilder()); + Object o = ScriptUtil.invokeScript(script, params); + System.out.println("o : " + o); + } + + @Test + public void testD(){ + Map params = new HashMap<>(); + params.put("a", "2"); + params.put("b", "*"); + params.put("ans", new StringBuilder()); + List list = new ArrayList<>(); + list.add("2"); + Checkers.>lambdaCheck() + .custom(map->list.contains(map.get("a")), "值11111").check(params); + } + + public T parse(String dataKey, Map response){ + String[] split = Util.null2DefaultStr(dataKey,"").split("\\."); + int len = split.length; + if(len == 0 || StringUtils.isBlank(dataKey)){ + return (T)response; + } + for (int i = 0; i < len - 1; i++) { + response = (Map) response.get(split[i]); + } + return (T) response.get(split[len - 1]); + } + + + +} diff --git a/src/test/java/xuanran/wang/shyl/dataasync/TestPassword.java b/src/test/java/xuanran/wang/shyl/dataasync/TestPassword.java new file mode 100644 index 0000000..3882ba3 --- /dev/null +++ b/src/test/java/xuanran/wang/shyl/dataasync/TestPassword.java @@ -0,0 +1,22 @@ +package xuanran.wang.shyl.dataasync; + +import basetest.BaseTest; +import org.junit.Test; +import weaver.rsa.security.RSA; + +import java.util.List; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/7/3 11:49 + */ +public class TestPassword extends BaseTest { + @Test + public void testA(){ + RSA var15 = new RSA(); + String decrypt = var15.decrypt("cY5Y2bIDOnQCGfmmAHTH6g48qhAw+b3DbAPndeT1KxkK0z5K5kyBA5cbE8mfJYdjhK6WQ2W5/YfIHAWDNQxP1UCGzFSjmBbUkx5oJFlhm0G+s/AwsxqsiFU2uFVqKpyfJP/Xdm0ux6bNfUSu8KoqfrB6h6HonGPmXQc2fATQ66urHC7mnpvC6XGOQ/0K7z0grcLv59PuKU5AkZpn2LZ/qMeaGWkAaBOB2Ko9xc8lBnvppyN23cozde2CVyoD8s59otp543oSN6MFHpkLVk2C1Uew8arZhEP+04VJdGhABtLX1H5X+N/hG20dlH5HxWlvYkc6H9qaKv89XvcXdg072Q==``RSA``"); + System.out.println(decrypt); + } +}