From d78176c580b16385181dccbaf27ecc6a16e2d6ae Mon Sep 17 00:00:00 2001 From: wangxuanran <3055088966@qq.com> Date: Thu, 4 May 2023 14:34:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=A4=87=E4=BB=BD=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OtherSystemToOAController.java | 66 ++ .../sso/mapper/OtherSystemToOAMapper.java | 44 + .../sso/service/OtherSystemToOAService.java | 49 ++ .../impl/OtherSystemToOAServiceImpl.java | 97 +++ .../BatchCreateWorkFlowController.java | 2 +- .../shyl/controller/GetStudentsClass.java | 2 +- .../service/BatchCreateWorkflowService.java | 4 +- .../controller/EmailOutSendController.java | 45 + .../email/entity/EmailOutConfigDetail.java | 17 + .../email/entity/EmailOutConfigMain.java | 21 + .../email/mapper/EmailOutSendMapper.java | 42 + .../email/service/EmailOutSendService.java | 17 + .../service/impl/EmailOutSendServiceImpl.java | 120 +++ .../wang/common/mapper/CommonMapper.java | 9 + .../xuanran/wang/common/util/CommonUtil.java | 52 ++ .../xuanran/wang/common/util/CusData2OA.java | 99 +++ .../xuanran/wang/cssc/cms/WorkflowToCms.java | 153 ++++ .../wang/cssc/cms/entity/CusSuccess.java | 27 + .../cms/service/WorkflowToCmsService.java | 14 + .../impl/WorkFlowToCmsServiceImpl.java | 73 ++ .../cssc/cms/util/RequestMasterPlate.java | 80 ++ .../sap/action/WorkflowToSap.java | 53 ++ .../entity/eneity/DetailRequestConfig.java | 41 + .../sap/entity/eneity/MainRequestConfig.java | 47 ++ .../sap/service/WorkflowToSapService.java | 16 + .../impl/WorkflowToSapServiceImpl.java | 49 ++ .../sap/util/ReadConfigUtil.java | 565 +++++++++++++ .../service/WorkFlowToVmsAndMQService.java | 39 +- .../sh_bigdata/common/entity/CusSuccess.java | 3 +- .../common/service/CusDataDecipher.java | 15 + .../common/util/RequestMasterPlate.java | 10 +- .../common/util/SendTodoTaskUtil.java | 19 +- .../sh_bigdata/common/util/ShBigDataUtil.java | 69 +- .../sh_bigdata/common/util/TokenUtil.java | 40 +- .../OrganizationHrmSyncFromOtherSys.java | 37 + .../annotations/CusOrgHrmAsyncConvert.java | 16 + .../entity/OrgHrmAsyncCache.java | 43 + .../entity/OrgHrmAsyncConfigDetail.java | 30 + .../entity/OrgHrmAsyncConfigMain.java | 39 + .../entity/OtherSysDepartment.java | 23 +- .../job/OrganizationHrmSyncJob.java | 146 ++++ .../mapper/OrgHrmAsyncMapper.java | 86 +- .../service/OrgHrmAsyncApiService.java | 15 +- .../service/OrgHrmAsyncService.java | 17 +- .../impl/OrgHrmAsyncApiServiceImpl.java | 45 +- .../impl/OrgHrmAsyncEntityServiceImpl.java | 265 ++++++ .../service/impl/OrgHrmAsyncServiceImpl.java | 775 +++++++++++++++--- .../org_hrm_async/util/OrgHrmAsyncUtil.java | 102 +++ .../org_hrm_async/util/ValueRuleMethod.java | 178 ++++ .../org_hrm_async/util/ValueRuleMethodNo.java | 19 + .../task_async/entity/CusDoneTask.java | 2 +- .../task_async/entity/CusTodoTask.java | 2 +- .../service/impl/SendTodoTaskServiceImpl.java | 3 +- .../shyl/dataasync/entity/StudentClass.java | 2 + .../shyl/dataasync/job/CusDataAsyncJob.java | 36 +- .../service/CusDataAsyncService.java | 38 + .../wang/shyl_mq/mapper/ConsumerMapper.java | 4 +- .../shyl_mq/service/impl/OrgServiceImpl.java | 2 +- .../wang/shyl_mq/util/RocketConsumerUtil.java | 1 + .../prop/prop2map/ShBigdataConf.properties | 54 +- .../xuanran/wang/big_data/BigDataTest.java | 400 +++++++++ src/test/java/xuanran/wang/cssc/FileTest.java | 204 +++++ .../wang/eighty_five_degreec/SAPTest.java | 52 ++ .../java/xuanran/wang/immc/Kafka/MQTest.java | 8 + .../wang/traffic_bank/EmailOutSendTest.java | 45 + 65 files changed, 4477 insertions(+), 211 deletions(-) create mode 100644 src/main/java/com/api/xuanran/wang/sh_bigdata/sso/controller/OtherSystemToOAController.java create mode 100644 src/main/java/com/api/xuanran/wang/sh_bigdata/sso/mapper/OtherSystemToOAMapper.java create mode 100644 src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/OtherSystemToOAService.java create mode 100644 src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/impl/OtherSystemToOAServiceImpl.java create mode 100644 src/main/java/com/api/xuanran/wang/traffic_bank/email/controller/EmailOutSendController.java create mode 100644 src/main/java/com/api/xuanran/wang/traffic_bank/email/entity/EmailOutConfigDetail.java create mode 100644 src/main/java/com/api/xuanran/wang/traffic_bank/email/entity/EmailOutConfigMain.java create mode 100644 src/main/java/com/api/xuanran/wang/traffic_bank/email/mapper/EmailOutSendMapper.java create mode 100644 src/main/java/com/api/xuanran/wang/traffic_bank/email/service/EmailOutSendService.java create mode 100644 src/main/java/com/api/xuanran/wang/traffic_bank/email/service/impl/EmailOutSendServiceImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/common/util/CusData2OA.java create mode 100644 src/main/java/weaver/xuanran/wang/cssc/cms/WorkflowToCms.java create mode 100644 src/main/java/weaver/xuanran/wang/cssc/cms/entity/CusSuccess.java create mode 100644 src/main/java/weaver/xuanran/wang/cssc/cms/service/WorkflowToCmsService.java create mode 100644 src/main/java/weaver/xuanran/wang/cssc/cms/service/impl/WorkFlowToCmsServiceImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/cssc/cms/util/RequestMasterPlate.java create mode 100644 src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/action/WorkflowToSap.java create mode 100644 src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/DetailRequestConfig.java create mode 100644 src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/MainRequestConfig.java create mode 100644 src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/WorkflowToSapService.java create mode 100644 src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/impl/WorkflowToSapServiceImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/util/ReadConfigUtil.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/common/service/CusDataDecipher.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/annotations/CusOrgHrmAsyncConvert.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncCache.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncConfigDetail.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncConfigMain.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/job/OrganizationHrmSyncJob.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncEntityServiceImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/OrgHrmAsyncUtil.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/ValueRuleMethod.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/ValueRuleMethodNo.java create mode 100644 src/test/java/xuanran/wang/big_data/BigDataTest.java create mode 100644 src/test/java/xuanran/wang/cssc/FileTest.java create mode 100644 src/test/java/xuanran/wang/eighty_five_degreec/SAPTest.java create mode 100644 src/test/java/xuanran/wang/traffic_bank/EmailOutSendTest.java diff --git a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/controller/OtherSystemToOAController.java b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/controller/OtherSystemToOAController.java new file mode 100644 index 0000000..076bda2 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/controller/OtherSystemToOAController.java @@ -0,0 +1,66 @@ +package com.api.xuanran.wang.sh_bigdata.sso.controller; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import com.api.xuanran.wang.sh_bigdata.sso.service.OtherSystemToOAService; +import com.api.xuanran.wang.sh_bigdata.sso.service.impl.OtherSystemToOAServiceImpl; +import com.sun.jersey.api.view.Viewable; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.integration.util.SessionUtil; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; +import java.util.Map; + +/** + *

第三方系统登录oa

+ * + * @author xuanran.wang + * @date 2023/4/17 14:22 + */ +@Path("/wxr/sh_big_data/sso") +public class OtherSystemToOAController { + + private final Logger log = Util.getLogger(); + private final OtherSystemToOAService service = new OtherSystemToOAServiceImpl(); + @Path("/login/{appId}") + @GET + public Viewable login(@PathParam("appId") String appId, + @Context HttpServletRequest request, + @Context HttpServletResponse response) { + try { + log.info("appId : " + appId); + String code = Util.null2DefaultStr(request.getParameter("code"),""); + log.info("sso login code : " + code); + if(StringUtils.isBlank(code)){ + throw new CustomerException("code is null!"); + } + // 获取重定向地址和secret + Map redirectUrlAndCorpsecret = service.getRedirectUrlAndCorpsecret(appId); + String redirectUrl = Util.null2DefaultStr(redirectUrlAndCorpsecret.get("REDIRECTURL"),""); + log.info("successSendRedirectUrl : " + redirectUrl); + if(StringUtils.isBlank(redirectUrl)){ + throw new CustomerException("redirectUrl is null! " + JSONObject.toJSONString(redirectUrlAndCorpsecret)); + } + int userId = service.getUserFromOtherSys(code, redirectUrlAndCorpsecret); + SessionUtil.createSession(userId + "", request, response); + response.sendRedirect(redirectUrl); + }catch (Exception e){ + log.error("sso error : " + e.getMessage()); + log.error(Util.getErrString(e)); + try { + response.sendRedirect(Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("loginErrorSendRedirectUrl"),"/login/login.jsp")); + }catch (Exception ec){ + log.error("sendRedirect error " + ec.getMessage()); + } + } + return null; + } +} diff --git a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/mapper/OtherSystemToOAMapper.java b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/mapper/OtherSystemToOAMapper.java new file mode 100644 index 0000000..f3c4884 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/mapper/OtherSystemToOAMapper.java @@ -0,0 +1,44 @@ +package com.api.xuanran.wang.sh_bigdata.sso.mapper; + +import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; + +import java.util.Map; + +/** + *

第三方系统登录oa mapper

+ * + * @author xuanran.wang + * @date 2023/4/18 09:54 + */ +@SqlMapper +public interface OtherSystemToOAMapper { + /** + *

根据outKey查oa ID

+ * @author xuanran.wang + * @dateTime 2023/4/20 11:46 + * @param outKey 外键id + * @return oa ID + **/ + @Select("select id from hrmresource where outkey = #{outKey}") + int selectUserIdByOutKey(@ParamMapper("outKey") String outKey); + /** + *

根据appId 查跳转的地址

+ * @author xuanran.wang + * @dateTime 2023/4/20 11:47 + * @param appId appId + * @return 跳转的地址 + **/ + @Select("select zydz from uf_AppPortal where zcsjbs = #{appId}") + String selectRedirectUrlByAppId(@ParamMapper("appId") String appId); + /** + *

根据appId 查跳转的地址

+ * @author xuanran.wang + * @dateTime 2023/4/20 11:47 + * @param appId appId + * @return 跳转的地址 + **/ + @Select("select zydz redirectUrl, secret from uf_AppPortal where zcsjbs = #{appId}") + Map selectRedirectUrlAndSecretByAppId(@ParamMapper("appId") String appId); +} diff --git a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/OtherSystemToOAService.java b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/OtherSystemToOAService.java new file mode 100644 index 0000000..7f736c4 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/OtherSystemToOAService.java @@ -0,0 +1,49 @@ +package com.api.xuanran.wang.sh_bigdata.sso.service; + +import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; + +import java.util.Map; + +/** + *

第三方系统登录oa

+ * + * @author xuanran.wang + * @date 2023/4/17 14:27 + */ +public interface OtherSystemToOAService { + /** + *

发请求根据code获取第三方系统用户id

+ * @author xuanran.wang + * @dateTime 2023/4/18 13:29 + * @param url 请求地址 + * @param params 参数 + * @param headers 请求头 + * @param cusSuccess 自定义接口成功/失败标识 + * @return 接口响应字段 + **/ + int getUserIdByCode(String url, Map params, Map headers, CusSuccess cusSuccess, Map redirectUrlSecret); + /** + *

根据第三方系统人员code匹配oa人员id

+ * @author xuanran.wang + * @dateTime 2023/4/18 13:30 + * @param code 第三方系统人员code + * @return oa人员id + **/ + int getUserFromOtherSys(String code, Map redirectUrlSecret); + /** + *

根据appId获取oa地址

+ * @author xuanran.wang + * @dateTime 2023/4/20 11:14 + * @param appId 建模appId + * @return 跳转应用地址 + **/ + String getLoginSuccessSendRedirectUrl(String appId); + /** + *

根据appId获取跳转地址和corpsecret

+ * @author xuanran.wang + * @dateTime 2023/4/20 11:14 + * @param appId 建模appId + * @return 跳转应用地址 + **/ + Map getRedirectUrlAndCorpsecret(String appId); +} diff --git a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/impl/OtherSystemToOAServiceImpl.java b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/impl/OtherSystemToOAServiceImpl.java new file mode 100644 index 0000000..3e1581a --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/impl/OtherSystemToOAServiceImpl.java @@ -0,0 +1,97 @@ +package com.api.xuanran.wang.sh_bigdata.sso.service.impl; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import com.api.xuanran.wang.sh_bigdata.sso.mapper.OtherSystemToOAMapper; +import com.api.xuanran.wang.sh_bigdata.sso.service.OtherSystemToOAService; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; +import weaver.xuanran.wang.sh_bigdata.common.util.RequestMasterPlate; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; + +import java.util.HashMap; +import java.util.Map; + +/** + *

第三方系统登录oa

+ * + * @author xuanran.wang + * @date 2023/4/17 14:35 + */ +public class OtherSystemToOAServiceImpl implements OtherSystemToOAService { + + private final RequestMasterPlate requestMasterPlate = new RequestMasterPlate(); + private final CusSuccess cusSuccess = CusSuccess.builder() + .successField("code") + .successValue(0) + .errorMsg("msg") + .dataKey("data.id") + .build(); + private final OtherSystemToOAMapper otherSystemToOAMapper = Util.getMapper(OtherSystemToOAMapper.class); + private final Logger log = Util.getLogger(); + @Override + public int getUserIdByCode(String url, Map params, Map headers, CusSuccess cusSuccess, Map redirectUrlSecret) { + String secret = Util.null2DefaultStr(redirectUrlSecret.get("SECRET"), ""); + log.info("secret : " + secret); + if(StringUtils.isBlank(secret)){ + throw new CustomerException("secret is null! " + JSONObject.toJSONString(redirectUrlSecret)); + } + return requestMasterPlate.apiGet(ShBigDataUtil.addToken2Url(url, secret), params ,new HashMap<>(), cusSuccess); + } + + @Override + public int getUserFromOtherSys(String code, Map redirectUrlSecret) { + HashMap params = new HashMap<>(); + params.put("code", code); + // 获取第三方系统id + String getUserInfoByCodeUrl = ShBigDataUtil.getPropertiesValByKey("getUserInfoByCodeUrl"); + int codeId; + try { + codeId = getUserIdByCode(getUserInfoByCodeUrl, params, new HashMap<>(), cusSuccess, redirectUrlSecret); + }catch (Exception e){ + String getUserIdDebug = ShBigDataUtil.getPropertiesValByKey("getUserIdDebug"); + // 开启调试模式 + if("1".equals(getUserIdDebug)){ + codeId = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("getUserIdDebugOutKey"), 109); + log.info("debug codeId : " + codeId); + }else { + throw new CustomerException(e.getMessage()); + } + } + if(codeId < 0){ + throw new CustomerException(Util.logStr("code : {}, not found in {} .", code, getUserInfoByCodeUrl)); + } + int id = otherSystemToOAMapper.selectUserIdByOutKey(codeId + ""); + if(id < 0){ + throw new CustomerException(Util.logStr("code : {} not found in OA!", id)); + } + return id; + } + + @Override + public String getLoginSuccessSendRedirectUrl(String appId) { + String defaultUrl = Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("loginSuccessSendRedirectUrl"), "/wui/index.html#/main"); + String url = otherSystemToOAMapper.selectRedirectUrlByAppId(appId); + if(StringUtils.isBlank(appId) || StringUtils.isBlank(url)){ + return defaultUrl; + } + return url; + } + + @Override + public Map getRedirectUrlAndCorpsecret(String appId) { + Map res = otherSystemToOAMapper.selectRedirectUrlAndSecretByAppId(appId); + if(MapUtils.isEmpty(res)){ + throw new CustomerException(Util.logStr("该appId在建模配置中不存在配置!")); + } + long count = res.values().stream().filter(StringUtils::isBlank).count(); + if(count > 0){ + throw new CustomerException(Util.logStr("该appId查询重定向地址或secret数据为空!: {}", JSONObject.toJSONString(res))); + } + return res; + } + +} diff --git a/src/main/java/com/api/xuanran/wang/shyl/controller/BatchCreateWorkFlowController.java b/src/main/java/com/api/xuanran/wang/shyl/controller/BatchCreateWorkFlowController.java index 94abd03..01dc790 100644 --- a/src/main/java/com/api/xuanran/wang/shyl/controller/BatchCreateWorkFlowController.java +++ b/src/main/java/com/api/xuanran/wang/shyl/controller/BatchCreateWorkFlowController.java @@ -71,7 +71,7 @@ public class BatchCreateWorkFlowController { return ApiResult.success(service.batchCreateWorkflow(user, workflows)); }catch (Exception e){ log.error(Util.logStr("batchCreate error : {}", e.getMessage())); - return ApiResult.error(500,"批量创建流程接口发生异常! 异常信息 :[ " + e.getMessage() + " ]"); + return ApiResult.error(500, e.getMessage()); } } diff --git a/src/main/java/com/api/xuanran/wang/shyl/controller/GetStudentsClass.java b/src/main/java/com/api/xuanran/wang/shyl/controller/GetStudentsClass.java index 10b720f..3e58125 100644 --- a/src/main/java/com/api/xuanran/wang/shyl/controller/GetStudentsClass.java +++ b/src/main/java/com/api/xuanran/wang/shyl/controller/GetStudentsClass.java @@ -16,7 +16,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; /** - *

+ *

<学员接口/h1> * * @author xuanran.wang * @date 2023/3/1 10:56 diff --git a/src/main/java/com/api/xuanran/wang/shyl/service/BatchCreateWorkflowService.java b/src/main/java/com/api/xuanran/wang/shyl/service/BatchCreateWorkflowService.java index 7621447..998cd6e 100644 --- a/src/main/java/com/api/xuanran/wang/shyl/service/BatchCreateWorkflowService.java +++ b/src/main/java/com/api/xuanran/wang/shyl/service/BatchCreateWorkflowService.java @@ -37,9 +37,7 @@ public class BatchCreateWorkflowService { private final Logger log = Util.getLogger(); private static final String CUSTOM_ID = "customId"; - // private final MeetingMapper meetingTransMapper = Util.getTransMapper(MeetingMapper.class); - private final MeetingService meetingService = new MeetingService(); /** *

取消会议 支持多个

@@ -97,7 +95,7 @@ public class BatchCreateWorkflowService { } } if(errors.size() > 0){ - throw new CustomerException("创建流程失败!错误参数流程 : \n" + JSONObject.toJSONString(errors)); + throw new CustomerException(JSONObject.toJSONString(errors)); } return res; }catch (Exception e){ diff --git a/src/main/java/com/api/xuanran/wang/traffic_bank/email/controller/EmailOutSendController.java b/src/main/java/com/api/xuanran/wang/traffic_bank/email/controller/EmailOutSendController.java new file mode 100644 index 0000000..f0e59ac --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/traffic_bank/email/controller/EmailOutSendController.java @@ -0,0 +1,45 @@ +package com.api.xuanran.wang.traffic_bank.email.controller; + +import aiyh.utils.ApiResult; +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import com.api.xuanran.wang.traffic_bank.email.service.EmailOutSendService; +import com.api.xuanran.wang.traffic_bank.email.service.impl.EmailOutSendServiceImpl; +import io.swagger.v3.oas.annotations.parameters.RequestBody; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +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.Map; + +/** + *

交银理财邮件外发

+ * + * @author xuanran.wang + * @date 2023/4/18 14:11 + */ +@Path("/wxr/traffic_bank/email") +public class EmailOutSendController { + + private final EmailOutSendService service = new EmailOutSendServiceImpl(); + + @Path("/send") + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public String sendEmail(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map param) { + try { + service.sendEmail(param); + return ApiResult.success(null); + }catch (Exception e){ + Util.getLogger().error("EmailOutSendController error " + e.getMessage()); + Util.getLogger().error(Util.getErrString(e)); + return ApiResult.error("发送邮件异常 : " + e.getMessage()); + } + } +} diff --git a/src/main/java/com/api/xuanran/wang/traffic_bank/email/entity/EmailOutConfigDetail.java b/src/main/java/com/api/xuanran/wang/traffic_bank/email/entity/EmailOutConfigDetail.java new file mode 100644 index 0000000..f636e5c --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/traffic_bank/email/entity/EmailOutConfigDetail.java @@ -0,0 +1,17 @@ +package com.api.xuanran.wang.traffic_bank.email.entity; + +import lombok.Data; + +/** + *

邮件外发配置表明细

+ * + * @author xuanran.wang + * @date 2023/4/18 14:23 + */ +@Data +public class EmailOutConfigDetail { + private String interfaceField; + private String fieldName; + private String cusStyleClass; + private int mergeCell; +} diff --git a/src/main/java/com/api/xuanran/wang/traffic_bank/email/entity/EmailOutConfigMain.java b/src/main/java/com/api/xuanran/wang/traffic_bank/email/entity/EmailOutConfigMain.java new file mode 100644 index 0000000..7004a09 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/traffic_bank/email/entity/EmailOutConfigMain.java @@ -0,0 +1,21 @@ +package com.api.xuanran.wang.traffic_bank.email.entity; + +import lombok.Data; + +import java.util.List; + +/** + *

邮件外发配置表主表

+ * + * @author xuanran.wang + * @date 2023/4/18 14:17 + */ +@Data +public class EmailOutConfigMain { + private int transType; + private String templatePath; + private String emailAddressCusSql; + private int enable; + private String titleField; + private List configDetailList; +} diff --git a/src/main/java/com/api/xuanran/wang/traffic_bank/email/mapper/EmailOutSendMapper.java b/src/main/java/com/api/xuanran/wang/traffic_bank/email/mapper/EmailOutSendMapper.java new file mode 100644 index 0000000..f295e6d --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/traffic_bank/email/mapper/EmailOutSendMapper.java @@ -0,0 +1,42 @@ +package com.api.xuanran.wang.traffic_bank.email.mapper; + +import aiyh.utils.annotation.recordset.*; +import com.api.xuanran.wang.traffic_bank.email.entity.EmailOutConfigDetail; +import com.api.xuanran.wang.traffic_bank.email.entity.EmailOutConfigMain; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigDetail; + +import java.util.List; +import java.util.Map; + +/** + *

邮件外发mapper

+ * + * @author xuanran.wang + * @date 2023/4/18 14:26 + */ +@SqlMapper +public interface EmailOutSendMapper { + + @Select("select * from uf_email_out_config where trans_type = #{transType}") + @CollectionMappings({ + @CollectionMapping(property = "configDetailList", + column = "id", + id = @Id(value = Integer.class, methodId = 1)) + }) + EmailOutConfigMain selectConfigByTypeId(@ParamMapper("transType") int transType); + + /** + *

查询配置表明细表信息

+ * @author xuanran.wang + * @dateTime 2023/3/1 16:39 + * @param mainId 主表数据id + * @return 配置集合 + **/ + @Select("select * from uf_email_out_config_dt1 where mainid = #{mainId}") + @CollectionMethod(1) + List selectConfigDetail(@ParamMapper("mainId") int mainId); + + @Select(custom = true) + String selectCustomerSql(@SqlString String sql, Map map); + +} diff --git a/src/main/java/com/api/xuanran/wang/traffic_bank/email/service/EmailOutSendService.java b/src/main/java/com/api/xuanran/wang/traffic_bank/email/service/EmailOutSendService.java new file mode 100644 index 0000000..376a617 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/traffic_bank/email/service/EmailOutSendService.java @@ -0,0 +1,17 @@ +package com.api.xuanran.wang.traffic_bank.email.service; + +import com.api.xuanran.wang.traffic_bank.email.entity.EmailOutConfigMain; + +import java.util.List; +import java.util.Map; + +/** + *

邮件外发

+ * + * @author xuanran.wang + * @date 2023/4/18 14:15 + */ +public interface EmailOutSendService { + EmailOutConfigMain selectConfigByTransType(int type); + void sendEmail(Map params); +} diff --git a/src/main/java/com/api/xuanran/wang/traffic_bank/email/service/impl/EmailOutSendServiceImpl.java b/src/main/java/com/api/xuanran/wang/traffic_bank/email/service/impl/EmailOutSendServiceImpl.java new file mode 100644 index 0000000..0ebcd22 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/traffic_bank/email/service/impl/EmailOutSendServiceImpl.java @@ -0,0 +1,120 @@ +package com.api.xuanran.wang.traffic_bank.email.service.impl; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import com.api.xuanran.wang.traffic_bank.email.entity.EmailOutConfigDetail; +import com.api.xuanran.wang.traffic_bank.email.entity.EmailOutConfigMain; +import com.api.xuanran.wang.traffic_bank.email.mapper.EmailOutSendMapper; +import com.api.xuanran.wang.traffic_bank.email.service.EmailOutSendService; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; +import weaver.email.EmailWorkRunnable; + +import java.util.*; + +/** + *

邮件外发业务方法

+ * + * @author xuanran.wang + * @date 2023/4/18 14:33 + */ +public class EmailOutSendServiceImpl implements EmailOutSendService { + private final EmailOutSendMapper emailOutSendMapper = Util.getMapper(EmailOutSendMapper.class); + private final Logger log = Util.getLogger(); + @Override + public EmailOutConfigMain selectConfigByTransType(int type) { + EmailOutConfigMain configMain = emailOutSendMapper.selectConfigByTypeId(type); + Assert.notNull(configMain, Util.logStr("type= {}, not found config in uf_email_out_config!", type)); + List configDetailList = configMain.getConfigDetailList(); + Assert.notEmpty(configDetailList, Util.logStr("type= {}, not found config in uf_email_out_config_dt1!", type)); + return configMain; + } + + @Override + public void sendEmail(Map param) { + int type = Util.getIntValue(Util.null2DefaultStr(param.get("type"), ""), -1); + EmailOutConfigMain outConfigMain = selectConfigByTransType(type); + List> data = (List>) param.get("data"); + Map map = convertConfigToMail(outConfigMain, data); + List addressList = (List) map.get("address"); + String title = Util.null2DefaultStr(map.get("title"),""); + String email = Util.null2DefaultStr(map.get("email"), ""); + log.info("sendEmailInfo => \n " + JSONObject.toJSONString(map)); + if(CollectionUtils.isEmpty(addressList)){ + log.error("address is empty!"); + return; + } + for (String address : addressList) { + EmailWorkRunnable workRunnable = new EmailWorkRunnable(address, title, email); + if(!workRunnable.emailCommonRemind()){ + throw new CustomerException(Util.logStr("发送邮件失败! 邮件地址: {}, 标题: {}, 内容: {}",address, title, email)); + } + } + } + + + /** + *

根据配置将参数进行转换

+ * @author xuanran.wang + * @dateTime 2023/4/19 11:05 + * @param outConfigMain 配置表对象 + * @param params 邮件参数 + * @return 转换后的邮件参数map + **/ + public Map convertConfigToMail(EmailOutConfigMain outConfigMain, List> params){ + List detailConfig = outConfigMain.getConfigDetailList(); + String title = ""; + String titleField = Util.null2DefaultStr(outConfigMain.getTitleField(),""); + String emailAddressCusSql = outConfigMain.getEmailAddressCusSql(); + String sql = Util.sbc2dbcCase(emailAddressCusSql); + List emailList = new ArrayList<>(); + StringBuilder sb = new StringBuilder(); + int size = 0; + // 表头 + for (EmailOutConfigDetail detail : detailConfig) { + sb.append("").append(detail.getFieldName()).append(""); + size++; + } + sb.append(""); + for (Map param : params) { + sb.append(""); + for (EmailOutConfigDetail detail : detailConfig) { + int mergeCell = detail.getMergeCell(); + if(mergeCell > 0){ + sb.append(""); + sb.append(Util.null2DefaultStr(param.get(detail.getInterfaceField()),"")); + }else { + sb.append("").append(Util.null2DefaultStr(param.get(detail.getInterfaceField()),"")); + } + sb.append(""); + } + sb.append(""); + String email = emailOutSendMapper.selectCustomerSql(sql, param); + if(StringUtils.isNotBlank(email)){ + emailList.add(email); + } + if(StringUtils.isNotBlank(titleField)){ + title = Util.null2DefaultStr(param.get(titleField),""); + } + } + String html = outConfigMain.getTemplatePath(); + html = html + .replace("\n"," ") + .replace("\t"," ") + .replace("{tableInfo}", sb.toString()) + .replace("{?data.size}", size + "") + .replace("{?title}", title); + Map email = new HashMap<>(); + email.put("title", title); + email.put("email", html); + email.put("address", emailList); + return email; + } + +} diff --git a/src/main/java/weaver/xuanran/wang/common/mapper/CommonMapper.java b/src/main/java/weaver/xuanran/wang/common/mapper/CommonMapper.java index ec35493..1a13798 100644 --- a/src/main/java/weaver/xuanran/wang/common/mapper/CommonMapper.java +++ b/src/main/java/weaver/xuanran/wang/common/mapper/CommonMapper.java @@ -112,4 +112,13 @@ public interface CommonMapper { @Update("update meeting set meetingstatus = 4 where requestid in (${requestIds})") boolean cancelMeeting(@ParamMapper("requestIds") List requestIds); + + @Select(custom = true) + String selectCustomerSql(@SqlString String sql, Map map); + + @Update(custom = true) + boolean updateModelInfo(@SqlString String sql, Map params); + + @BatchUpdate(custom = true) + boolean updateModelInfoList(@SqlString String sql, @BatchSqlArgs List> params); } diff --git a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java index 818b3f0..6d2b236 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java @@ -10,6 +10,9 @@ import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import weaver.conn.RecordSet; import weaver.formmode.data.ModeDataApproval; +import weaver.formmode.data.ModeDataIdUpdate; +import weaver.formmode.setup.ModeRightInfo; +import weaver.general.TimeUtil; import weaver.hrm.User; import weaver.xiao.commons.config.entity.RequestMappingConfig; import weaver.xiao.commons.config.service.DealWithMapping; @@ -60,6 +63,9 @@ public class CommonUtil { **/ private static final CommonMapper commonMapper = Util.getMapper(CommonMapper.class); + private static final ModeDataIdUpdate modeDataIdUpdate = ModeDataIdUpdate.getInstance(); + private static final ModeRightInfo moderightinfo = new ModeRightInfo(); + public CommonUtil(){ } @@ -655,6 +661,52 @@ public class CommonUtil { return commonMapper.queryMeetingIdByRequestId(requestId); } + /** + *

删除建模数据

+ * @author xuanran.wang + * @dateTime 2022/11/23 21:02 + * @param modelId 模块id + * @param ids 数据集合 + * @return 删除是否成功 + **/ + public static boolean deleteModelDataByIds(String modelId, List ids){ + String tableName = commonMapper.getModelNameByModelId(modelId); + return commonMapper.deleteModelDataByIds(tableName, ids); + } + /** + *

获取建模数据id

+ * @author xuanran.wang + * @dateTime 2022/12/15 10:56 + * @param modelTableName 表名 + * @param modelId 模块id + * @return 新的建模数据id + **/ + private static Integer getNewIdByModelInfo(String modelTableName, int modelId){ + String currentDateTime = TimeUtil.getCurrentTimeString(); + //日期 + String currentDate = currentDateTime.substring(0, 10); + //时间 + String currentTime = currentDateTime.substring(11); + return modeDataIdUpdate.getModeDataNewId(modelTableName, modelId, 1, 0, currentDate, currentTime); + } + + /** + *

校验模块id 并获取表名

+ * @author xuanran.wang + * @dateTime 2023/2/9 11:18 + * @param modelId 模块id + * @return 表名 + **/ + public static String checkModelId(int modelId){ + if(modelId < 0){ + throw new RuntimeException("建模模块id不能小于0!"); + } + String tableName = commonMapper.getModelNameByModelId(String.valueOf(modelId)); + if(StringUtils.isBlank(tableName)){ + throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!"); + } + return tableName; + } } diff --git a/src/main/java/weaver/xuanran/wang/common/util/CusData2OA.java b/src/main/java/weaver/xuanran/wang/common/util/CusData2OA.java new file mode 100644 index 0000000..7e7e465 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/common/util/CusData2OA.java @@ -0,0 +1,99 @@ +package weaver.xuanran.wang.common.util; + +import aiyh.utils.Util; +import aiyh.utils.annotation.recordset.BatchUpdate; +import aiyh.utils.excention.CustomerException; +import org.apache.axis2.databinding.types.xsd._float; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.formmode.data.ModeDataIdUpdate; +import weaver.formmode.setup.ModeRightInfo; +import weaver.xuanran.wang.common.mapper.CommonMapper; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + *

自定义数据写入oa

+ * + * @author xuanran.wang + * @date 2023/4/19 16:24 + */ +public class CusData2OA { + private static final CommonMapper commonMapper = Util.getMapper(CommonMapper.class); + private static final Logger log = Util.getLogger(); + private static final String TABLE_NAME_PLACEHOLDER = "#\\{tableName}"; + + public static String writeToModel(String modelId, String uniqueSql, Map params){ + return baseExecute(modelId, uniqueSql, Collections.singletonList(params)).get(0); + } + + public static String writeToModel(String modelId, Map params){ + return baseExecute(modelId, "", Collections.singletonList(params)).get(0); + } + + public static List batchWriteToModel(String modelId, List> params){ + return baseExecute(modelId, "", params); + } + + public static List batchWriteToModel(String modelId, String uniqueSql, List> params){ + return baseExecute(modelId, uniqueSql, params); + } + + @BatchUpdate + public static List baseExecute(String modelId, String uniqueSql, List> params){ + int modelIdInt = Util.getIntValue(modelId, -1); + String tableName = CommonUtil.checkModelId(modelIdInt); + if(modelIdInt < 0 || StringUtils.isBlank(tableName)){ + throw new CustomerException("modelId can not < 0 or modelTableName can not empty!"); + } + uniqueSql = Util.sbc2dbcCase(uniqueSql); + uniqueSql = uniqueSql.replaceAll(TABLE_NAME_PLACEHOLDER, tableName); + String modelDataId = ""; + List delList = new ArrayList<>(); + List modelDataList = new ArrayList<>(); + String updateSql = ""; + + for (Map param : params) { + if(StringUtils.isNotBlank(uniqueSql)){ + modelDataId = commonMapper.selectCustomerSql(uniqueSql, param); + } + if(StringUtils.isBlank(modelDataId)){ + modelDataId = Util.null2DefaultStr(Util.getModeDataId(tableName, modelIdInt, 1),""); + delList.add(modelDataId); + Util.rebuildModeDataShare(1, tableName, Util.getIntValue(modelDataId, -1)); + } + if(StringUtils.isBlank(updateSql)){ + updateSql = buildUpdateSql(tableName, param); + } + param.put("id",modelDataId); + modelDataList.add(modelDataId); + } + try { + if (!commonMapper.updateModelInfoList(updateSql, params)) { + throw new CustomerException("update model data sql execute error!"); + } + }catch (Exception e){ + CommonUtil.deleteDataByIds(delList, tableName); + throw new CustomerException(e); + } + return modelDataList; + } + + public static String buildUpdateSql(String tableName, Map params) { + StringBuilder sqlSb = new StringBuilder("update ") + .append(tableName) + .append(" set "); + for (Map.Entry entry : params.entrySet()) { + sqlSb.append(entry.getKey()) + .append(" = #{item.") + .append(entry.getKey()) + .append("},"); + } + sqlSb.deleteCharAt(sqlSb.length() - 1); + sqlSb.append(" where id = #{item.id}"); + return sqlSb.toString(); + } +} diff --git a/src/main/java/weaver/xuanran/wang/cssc/cms/WorkflowToCms.java b/src/main/java/weaver/xuanran/wang/cssc/cms/WorkflowToCms.java new file mode 100644 index 0000000..d9f5b35 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/cssc/cms/WorkflowToCms.java @@ -0,0 +1,153 @@ +package weaver.xuanran.wang.cssc.cms; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.ActionDesc; +import aiyh.utils.annotation.ActionOptionalParam; +import aiyh.utils.annotation.PrintParamMark; +import aiyh.utils.annotation.RequiredMark; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.xuanran.wang.cssc.cms.entity.CusSuccess; +import weaver.xuanran.wang.cssc.cms.service.WorkflowToCmsService; +import weaver.xuanran.wang.cssc.cms.service.impl.WorkFlowToCmsServiceImpl; + +/** + *

中国船舶研究所流程数据推送到科研综合管理系统

+ * + * @author xuanran.wang + * @date 2023/4/26 10:52 + */ +@ActionDesc(value = "中国船舶研究所流程数据推送到科研综合管理系统", author = "xuanran.wang") +public class WorkflowToCms extends SafeCusBaseAction { + private final WorkflowToCmsService workflowToCmsService = new WorkFlowToCmsServiceImpl(); + @PrintParamMark + @RequiredMark("建模配置文件唯一标识") + private String onlyMark; + + @PrintParamMark + private String tokenOnlyMark; + @PrintParamMark + private String tokenSuccessField; + @PrintParamMark + private String tokenSuccessVal; + @PrintParamMark + private String tokenMsg; + @PrintParamMark + private String tokenDataKey; + + + @PrintParamMark + @ActionOptionalParam(value = "code", desc = "接口成功标识字段") + private String successField; + @PrintParamMark + @ActionOptionalParam(value = "successVal", desc = "接口成功标识默认200") + private String successVal; + @PrintParamMark + @ActionOptionalParam(value = "message", desc = "报错返回信息字段") + private String msg; + @PrintParamMark + private String dataKey; + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + log.info("-------------- " + requestId + " begin --------------"); + CusSuccess cmsResponseVoField = CusSuccess + .builder() + .successField(Util.null2DefaultStr(successField, "success")) + .successValue(Util.null2DefaultStr(successVal, "true")) + .errorMsg(Util.null2DefaultStr(msg, "error")) + .dataKey(Util.null2DefaultStr(dataKey, "result.accessToken")) + .build(); + log.info(""); + + CusSuccess tokenSuccess = CusSuccess + .builder() + .successField(Util.null2DefaultStr(tokenSuccessField, "success")) + .successValue(Util.null2DefaultStr(tokenSuccessVal, "true")) + .errorMsg(Util.null2DefaultStr(tokenMsg, "error")) + .dataKey(Util.null2DefaultStr(tokenDataKey,"")) + .build(); + workflowToCmsService.workflowToCms(onlyMark,tokenOnlyMark, billTable, requestId,cmsResponseVoField, tokenSuccess); + } + + public String getOnlyMark() { + return onlyMark; + } + + public void setOnlyMark(String onlyMark) { + this.onlyMark = onlyMark; + } + + public String getSuccessField() { + return successField; + } + + public void setSuccessField(String successField) { + this.successField = successField; + } + + public String getSuccessVal() { + return successVal; + } + + public void setSuccessVal(String successVal) { + this.successVal = successVal; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public String getTokenOnlyMark() { + return tokenOnlyMark; + } + + public void setTokenOnlyMark(String tokenOnlyMark) { + this.tokenOnlyMark = tokenOnlyMark; + } + + public String getTokenSuccessField() { + return tokenSuccessField; + } + + public void setTokenSuccessField(String tokenSuccessField) { + this.tokenSuccessField = tokenSuccessField; + } + + public String getTokenSuccessVal() { + return tokenSuccessVal; + } + + public void setTokenSuccessVal(String tokenSuccessVal) { + this.tokenSuccessVal = tokenSuccessVal; + } + + public String getTokenMsg() { + return tokenMsg; + } + + public void setTokenMsg(String tokenMsg) { + this.tokenMsg = tokenMsg; + } + + public String getTokenDataKey() { + return tokenDataKey; + } + + public void setTokenDataKey(String tokenDataKey) { + this.tokenDataKey = tokenDataKey; + } + + public String getDataKey() { + return dataKey; + } + + public void setDataKey(String dataKey) { + this.dataKey = dataKey; + } +} diff --git a/src/main/java/weaver/xuanran/wang/cssc/cms/entity/CusSuccess.java b/src/main/java/weaver/xuanran/wang/cssc/cms/entity/CusSuccess.java new file mode 100644 index 0000000..ef44af1 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/cssc/cms/entity/CusSuccess.java @@ -0,0 +1,27 @@ +package weaver.xuanran.wang.cssc.cms.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import weaver.xuanran.wang.sh_bigdata.common.service.CusDataDecipher; + + +/** + *

自定义请求条件

+ * + * @author xuanran.wang + * @date 2023/4/6 19:34 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CusSuccess { + private String successField; + private Object successValue; + private String errorMsg; + private String dataKey; + private Object response; + private CusDataDecipher cusDataDecipher; +} diff --git a/src/main/java/weaver/xuanran/wang/cssc/cms/service/WorkflowToCmsService.java b/src/main/java/weaver/xuanran/wang/cssc/cms/service/WorkflowToCmsService.java new file mode 100644 index 0000000..b30454f --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/cssc/cms/service/WorkflowToCmsService.java @@ -0,0 +1,14 @@ +package weaver.xuanran.wang.cssc.cms.service; + +import weaver.xuanran.wang.cssc.cms.entity.CusSuccess; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/4/26 10:53 + */ +public interface WorkflowToCmsService { + String getToken(String onlyMark, String billTable, String requestId, CusSuccess cusSuccess); + void workflowToCms(String onlyMark,String tokenMark,String billTable, String requestId, CusSuccess cusSuccess, CusSuccess tokenSuccess); +} diff --git a/src/main/java/weaver/xuanran/wang/cssc/cms/service/impl/WorkFlowToCmsServiceImpl.java b/src/main/java/weaver/xuanran/wang/cssc/cms/service/impl/WorkFlowToCmsServiceImpl.java new file mode 100644 index 0000000..f3f65e7 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/cssc/cms/service/impl/WorkFlowToCmsServiceImpl.java @@ -0,0 +1,73 @@ +package weaver.xuanran.wang.cssc.cms.service.impl; + +import aiyh.utils.Util; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xiao.commons.config.service.DealWithMapping; +import weaver.xuanran.wang.common.util.CommonUtil; +import weaver.xuanran.wang.cssc.cms.entity.CusSuccess; +import weaver.xuanran.wang.cssc.cms.service.WorkflowToCmsService; +import weaver.xuanran.wang.cssc.cms.util.RequestMasterPlate; + +import java.util.HashMap; +import java.util.Map; + +/** + *

vms业务方法

+ * + * @Author xuanran.wang + * @Date 2022/12/1 10:58 + */ +public class WorkFlowToCmsServiceImpl implements WorkflowToCmsService { + private final DealWithMapping dealWithMapping = new DealWithMapping(); + private final Logger log = Util.getLogger(); // 获取日志对象 + private final RequestMasterPlate requestMasterPlate = new RequestMasterPlate(); + @Override + public String getToken(String onlyMark,String billTable, + String requestId, CusSuccess cusSuccess) { + RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); // 将配置参数通过唯一标识查询处理成树形结构 + RecordSet recordSet = initRs(requestMappingConfig, billTable, requestId); + String url = requestMappingConfig.getRequestUrl(); + dealWithMapping.setMainTable(billTable); + Map param = dealWithMapping.getRequestParam(recordSet, requestMappingConfig); + return requestMasterPlate.apiPost(url, param, new HashMap<>(), cusSuccess); + } + + /** + *

推送数据

+ * + * @param onlyMark 唯一编码 + * @param billTable 表名 + * @param requestId 请求id + * @author xuanran.wang + * @dateTime 2022/12/5 17:05 + **/ + @Override + public void workflowToCms(String onlyMark,String tokenMark, String billTable, + String requestId, CusSuccess cusSuccess, CusSuccess tokenSuccess) { + Map headers = new HashMap<>(); + if(StringUtils.isNotBlank(tokenMark)) { + String token = getToken(tokenMark, billTable, requestId, tokenSuccess); + headers.put("Authorization", "Bearer " + token); + } + RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); // 将配置参数通过唯一标识查询处理成树形结构 + RecordSet recordSet = initRs(requestMappingConfig, billTable, requestId); + String url = requestMappingConfig.getRequestUrl(); + dealWithMapping.setMainTable(billTable); + Map param = dealWithMapping.getRequestParam(recordSet, requestMappingConfig); + requestMasterPlate.apiPost(url, param, headers, cusSuccess); + } + + public RecordSet initRs( RequestMappingConfig requestMappingConfig, String billTable, String requestId){ + String selectMainSql = CommonUtil.getSelectSql(requestMappingConfig, billTable); + log.info(Util.logStr("查询主表数据sql : {}, requestId : {}", selectMainSql, requestId)); + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(selectMainSql, requestId); + recordSet.next(); + return recordSet; + } +} + + diff --git a/src/main/java/weaver/xuanran/wang/cssc/cms/util/RequestMasterPlate.java b/src/main/java/weaver/xuanran/wang/cssc/cms/util/RequestMasterPlate.java new file mode 100644 index 0000000..d2ed309 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/cssc/cms/util/RequestMasterPlate.java @@ -0,0 +1,80 @@ +package weaver.xuanran.wang.cssc.cms.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import com.alibaba.fastjson.JSON; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.xuanran.wang.cssc.cms.entity.CusSuccess; + +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.util.Map; + +/** + *

请求模版方法

+ * + * @author xuanran.wang + * @date 2023/4/4 11:51 + */ +public class RequestMasterPlate { + private final Logger log = Util.getLogger(); + private final HttpUtils httpUtils = new HttpUtils(); + private static final int HTTP_SUCCESS_CODE = 200; + + public T apiGet(String url, Map params, Map headers, CusSuccess cusSuccess){ + ResponeVo responeVo; + try { + responeVo = httpUtils.apiGet(url, params, headers); + } catch (IOException e) { + throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + return parseResponse(url, responeVo, params, cusSuccess); + } + + public T apiPost(String url, Object o, Map headers, CusSuccess cusSuccess){ + ResponeVo responeVo; + try { + headers.put("Content-Type", MediaType.APPLICATION_JSON); + responeVo = httpUtils.apiPostObject(url, o, headers); + } catch (IOException e) { + throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + return parseResponse(url, responeVo, o, cusSuccess); + } + + public T parseResponse(String url, ResponeVo responseVo, Object o, CusSuccess cusSuccess){ + if (responseVo.getCode() != HTTP_SUCCESS_CODE) { // 相应状态码 + log.error(Util.logStr("can not fetch [{}],this request params is [{}]," + // 构建日志字符串 + "this request heard is [{}],but response status code is [{}]," + + "this response is [{}]", url, JSON.toJSON(o), JSON.toJSONString(httpUtils.getGlobalCache().header), responseVo.getCode(), // 相应状态码 + responseVo.getEntityString())); // 相应内容 + throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + Map response; + if(cusSuccess.getCusDataDecipher() != null){ + response = cusSuccess.getCusDataDecipher().decoder(responseVo); + }else { + response = responseVo.getResponseMap(); // 根据相应结果转化为map集合 + } + cusSuccess.setResponse(response); + String responseValue = Util.null2DefaultStr(response.get(cusSuccess.getSuccessField()), ""); + if (!cusSuccess.getSuccessValue().equals(responseValue)) { + throw new CustomerException(Util.logStr("接口地址:[{}], 接口响应码不为: [{}], 接口响应信息: {}", url, cusSuccess.getSuccessValue(), Util.null2DefaultStr(response.get(cusSuccess.getErrorMsg()), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + String[] split = Util.null2DefaultStr(cusSuccess.getDataKey(),"").split("\\."); + int len = split.length; + if(len == 0 || StringUtils.isBlank(cusSuccess.getDataKey())){ + 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/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/action/WorkflowToSap.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/action/WorkflowToSap.java new file mode 100644 index 0000000..46cc313 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/action/WorkflowToSap.java @@ -0,0 +1,53 @@ +package weaver.xuanran.wang.eighty_five_degreec.sap.action; + +import aiyh.utils.ThreadPoolConfig; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.ActionDesc; +import aiyh.utils.annotation.PrintParamMark; +import aiyh.utils.annotation.RequiredMark; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig; +import weaver.xuanran.wang.eighty_five_degreec.sap.service.WorkflowToSapService; +import weaver.xuanran.wang.eighty_five_degreec.sap.service.impl.WorkflowToSapServiceImpl; + +import java.util.concurrent.ExecutorService; + +/** + *

将流程数据推送到sap中

+ * + * @author xuanran.wang + * @date 2023/4/14 16:30 + */ +@ActionDesc(value = "流程数据推送到SAP",author = "xuanran.wang") +public class WorkflowToSap extends SafeCusBaseAction { + + private final WorkflowToSapService service = new WorkflowToSapServiceImpl(); + private final ExecutorService pool = ThreadPoolConfig.createThreadPoolInstance(); + @PrintParamMark + @RequiredMark("配置表唯一标识") + private String uniqueCode; + @PrintParamMark + @RequiredMark("日志表模块id") + private String modelId; + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + try { + MainRequestConfig config = service.getRequestConfig(uniqueCode, billTable); + String xml = service.convertXml(config, requestId, billTable); + String response = service.sendToSap(); + pool.execute(()->{ + try { + service.logToOA(modelId, config.getRequestUrl(), requestId, xml, response); + }catch (Exception e){ + log.error("日志数据写入建模失败! " + e.getMessage()); + } + }); + }catch (Exception e){ + log.error("流程数据推送SAP error : " + e.getMessage()); + } + + } + +} diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/DetailRequestConfig.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/DetailRequestConfig.java new file mode 100644 index 0000000..5509ef1 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/DetailRequestConfig.java @@ -0,0 +1,41 @@ +package weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity; + + +import aiyh.utils.annotation.recordset.SqlDbFieldAnn; +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; +import lombok.Data; + +/** + * @Author xuanran.wang + * @Date 2022/6/18 16:47 + */ +@Data +public class DetailRequestConfig { + @SqlDbFieldAnn("paramName") + @SqlOracleDbFieldAnn("PARAMNAME") + private String paramName; + @SqlDbFieldAnn("paramType") + @SqlOracleDbFieldAnn("PARAMTYPE") + private String paramType; + @SqlDbFieldAnn("getValueType") + @SqlOracleDbFieldAnn("GETVALUETYPE") + private String getValueType; + @SqlDbFieldAnn("valueContext") + @SqlOracleDbFieldAnn("VALUECONTEXT") + private String valueContext; + @SqlDbFieldAnn("tableName") + @SqlOracleDbFieldAnn("TABLENAME") + private String tableName; + @SqlDbFieldAnn("workFlowField") + @SqlOracleDbFieldAnn("WORKFLOWFIELD") + private String workFlowField; + @SqlDbFieldAnn("fieldName") + @SqlOracleDbFieldAnn("FIELDNAME") + private String fieldName; + @SqlDbFieldAnn("detailId") + @SqlOracleDbFieldAnn("DETAILID") + private String detailId; + @SqlDbFieldAnn("parentName") + @SqlOracleDbFieldAnn("PARENTNAME") + private String parentName; +} diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/MainRequestConfig.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/MainRequestConfig.java new file mode 100644 index 0000000..28f5c50 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/MainRequestConfig.java @@ -0,0 +1,47 @@ +package weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity; + + +import aiyh.utils.annotation.recordset.SqlDbFieldAnn; +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; +import lombok.Data; + +import java.util.List; + +/** + * @Author xuanran.wang + * @Date 2022/6/18 15:43 + */ +@Data +public class MainRequestConfig { + @SqlDbFieldAnn("id") + @SqlOracleDbFieldAnn("ID") + private String id; + @SqlDbFieldAnn("uniqueCode") + @SqlOracleDbFieldAnn("UNIQUECODE") + private String uniqueCode; + @SqlDbFieldAnn("workflow") + @SqlOracleDbFieldAnn("WORKFLOW") + private String workflow; + @SqlDbFieldAnn("requestUrl") + @SqlOracleDbFieldAnn("REQUESTURL") + private String requestUrl; + @SqlDbFieldAnn("dataSource") + @SqlOracleDbFieldAnn("DATASOURCE") + private String dataSource; + @SqlDbFieldAnn("detailIndex") + @SqlOracleDbFieldAnn("DETAILINDEX") + private String detailIndex; + @SqlDbFieldAnn("cusSql") + @SqlOracleDbFieldAnn("CUSSQL") + private String cusSql; + @SqlDbFieldAnn("configFilePath") + @SqlOracleDbFieldAnn("CONFIGFILEPATH") + private String configFilePath; + @SqlDbFieldAnn("enable") + @SqlOracleDbFieldAnn("ENABLE") + private String enable; + @SqlDbFieldAnn("methodParameterClassName") + @SqlOracleDbFieldAnn("METHODPARAMETERCLASSNAME") + private String methodParameterClassName; + private List detailRequestConfigList; +} diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/WorkflowToSapService.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/WorkflowToSapService.java new file mode 100644 index 0000000..0498b63 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/WorkflowToSapService.java @@ -0,0 +1,16 @@ +package weaver.xuanran.wang.eighty_five_degreec.sap.service; + +import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig; + +/** + *

流程数据推送sap

+ * + * @author xuanran.wang + * @date 2023/4/19 15:15 + */ +public interface WorkflowToSapService { + MainRequestConfig getRequestConfig(String uniqueCode, String tableName); + String convertXml(MainRequestConfig config, String requestId, String tableName); + String sendToSap(); + void logToOA(String modelId, String url, String requestId, String requestXml, String response); +} diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/impl/WorkflowToSapServiceImpl.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/impl/WorkflowToSapServiceImpl.java new file mode 100644 index 0000000..b0aa755 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/impl/WorkflowToSapServiceImpl.java @@ -0,0 +1,49 @@ +package weaver.xuanran.wang.eighty_five_degreec.sap.service.impl; + +import aiyh.utils.Util; +import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig; +import weaver.xuanran.wang.eighty_five_degreec.sap.service.WorkflowToSapService; +import weaver.xuanran.wang.eighty_five_degreec.sap.util.ReadConfigUtil; + +import java.util.Collections; +import java.util.HashMap; + + +/** + *

将流程数据推送至sap

+ * + * @author xuanran.wang + * @date 2023/4/19 15:17 + */ +public class WorkflowToSapServiceImpl implements WorkflowToSapService { + private final ReadConfigUtil configUtil = new ReadConfigUtil(); + + @Override + public MainRequestConfig getRequestConfig(String uniqueCode, String tableName) { + return configUtil.getConfigByUniqueCode(uniqueCode, tableName); + } + + @Override + public String convertXml(MainRequestConfig config, String requestId, String tableName) { + return configUtil.getXml(config, requestId, tableName); + } + + @Override + public String sendToSap() { + // TODO sap接口调用方式暂时搞不了 + return ""; + } + + @Override + public void logToOA(String modelId, String url, String requestId, + String requestXml, String response) { + HashMap params = new HashMap<>(); + params.put("requestUrlAndFunName", url); + params.put("reqId", requestId); + params.put("requestXml", requestXml); + params.put("responseCode",""); + params.put("erpResponse", response); + CusInfoToOAUtil.getDataId(Util.getIntValue(modelId, -1), params, "select id from #{tableName} where reqId = ?", Collections.singletonList(requestId)); + } +} diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/util/ReadConfigUtil.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/util/ReadConfigUtil.java new file mode 100644 index 0000000..d805dd1 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/util/ReadConfigUtil.java @@ -0,0 +1,565 @@ +package weaver.xuanran.wang.eighty_five_degreec.sap.util; + +import com.google.common.base.Strings; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.general.GCONST; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.DetailRequestConfig; +import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig; +import weaver.zwl.common.ToolUtil; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; +import java.security.SecureRandom; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * @Author xuanran.wang + * @Date 2022/11/14 11:33 + * 读取配置文件 + */ +public class ReadConfigUtil extends ToolUtil { + private static final int enable = 0; + private final Logger log = aiyh.utils.Util.getLogger(); + + /** + *

读取配置文件

+ * @param uniqueCode 唯一编码 + * @param mainTableName 主表名称 + * @return 配置对象 + */ + public MainRequestConfig getConfigByUniqueCode(String uniqueCode, String mainTableName){ + MainRequestConfig res = new MainRequestConfig(); + RecordSet queryRs = new RecordSet(); + String sql = "select * from uf_memsic_createXml where uniqueCode = ? and enable = ?"; + if (queryRs.executeQuery(sql, uniqueCode,enable)) { + if (queryRs.next()) { + res = getInstance(queryRs, MainRequestConfig.class); + } + } + if (res == null || StringUtils.isBlank(res.getId()) || (-1 == Util.getIntValue(res.getId(), -1))) { + throw new RuntimeException("配置不存在"); + } + int mainId = Util.getIntValue(res.getId()); + // 配置明细表 + sql = "select paramName,paramType,parentName,getValueType,workflowField,valueContext,fv.tableName," + + " fv.id fieldId,fv.fieldname,fv.indexdesc " + + " from uf_memsic_createXml_dt1 config " + + " left join workflow_field_table_view fv on config.workflowField = fv.id " + + " where mainid = ? and enable = ?"; + if (queryRs.executeQuery(sql, mainId,enable)) { + ArrayList detailConfigs = new ArrayList<>(); + while (queryRs.next()) { + DetailRequestConfig detailConfig = getInstance(queryRs, DetailRequestConfig.class); + String tableName = detailConfig.getTableName(); + // 主表默认0 + String detailId = "0"; + // 明细id替换 + if(!mainTableName.equals(detailConfig.getTableName())){ + detailId = tableName.replaceAll(mainTableName + "_dt", ""); + } + detailConfig.setDetailId(detailId); + detailConfigs.add(detailConfig); + } + res.setDetailRequestConfigList(detailConfigs); + } + return res; + } + + /** + *

获取对象

+ * @author xuanran.wang + * @dateTime 2022/11/15 22:20 + * @param queryRs 查询结果集 + * @param clazz 返回类class + * @return 返回类对象 + **/ + public static T getInstance(RecordSet queryRs, Class clazz) { + T res = null; + try { + res = clazz.newInstance(); + Field[] fields = clazz.getDeclaredFields(); + for (Field field : fields) { + // 判断字段类型 + if (field.getType().isAssignableFrom(List.class) || field.getType().isAssignableFrom(Map.class)) { + continue; + } + field.setAccessible(true); + String fieldName = field.getName(); + if ("oracle".equals(queryRs.getDBType())) { + fieldName = fieldName.toUpperCase(); + } + String value = Util.null2String(queryRs.getString(fieldName)); + field.set(res, value); + } + } catch (Exception e) { + throw new RuntimeException("实体类生成异常"); + } + return res; + } + + /** + *

获取参数值

+ * @param detailRequestConfig 配置文件 + * @param mainRs 主表recordSet + * @param detailRs 明细recordSet + * @return 参数值 + */ + public Object getParamValue(DetailRequestConfig detailRequestConfig, + RecordSet mainRs, RecordSet detailRs, int count){ + Object value = ""; + try { + // 参数类型 + String paramType = detailRequestConfig.getParamType(); + // 取值方式 + String getValueType = detailRequestConfig.getGetValueType(); + // 明细id + String detailId = detailRequestConfig.getDetailId(); + // 自定义文本 + String valueContext = detailRequestConfig.getValueContext(); + // 接口参数名称 + String paramName = detailRequestConfig.getParamName(); + // 父级参数名称 + String parentName = detailRequestConfig.getParentName(); + switch (getValueType){ + // 流程字段 + case "0":{ + String fieldName = detailRequestConfig.getFieldName(); + if("0".equals(detailId)){ + value = Util.null2String(mainRs.getString(fieldName)); + }else{ + value = Util.null2String(detailRs.getString(fieldName)); + } + break; + } + // 固定值 + case "1":{ + value = Util.null2String(detailRequestConfig.getValueContext()); + break; + } + // 当前时间 + case "3":{ + // 当前时间 + value = TimeUtil.getCurrentTimeString(); + break; + } + // 自定义sql + case "4":{ + String fieldName = detailRequestConfig.getFieldName(); + String tempValue; + if("0".equals(detailId)){ + tempValue = Util.null2String(mainRs.getString(fieldName)); + }else{ + tempValue = Util.null2String(detailRs.getString(fieldName)); + } + String requestId = Util.null2String(mainRs.getString("requestid")); + value = getValueByChangeRule(detailRequestConfig.getValueContext(), tempValue, requestId); + break; + } + // 请求id + case "5" : { + value = Util.null2String(mainRs.getString("requestid")); + }break; + // 主数据id + case "6": { + if ("mainRecord".equals(parentName)) { + value = Util.null2String(mainRs.getString("id")); + } else { + value = Util.null2String(detailRs.getString("id")); + } + }break; + // 随机数 + case "7": { + int bit = Util.getIntValue(valueContext, 10); + value = this.getGUID(bit); + }break; + case "9":{ + value = count; + }break; + default:break; + } + // 参数类型 + switch (paramType){ + // String + case "0":{ + value = Util.null2String(value); + value = String.valueOf(value).replaceAll(" ", " ") + .replaceAll("
", " ") + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll("\"", """) + .replaceAll("'", "'"); + break; + } + // Int + case "1":{ + value = Util.getIntValue(String.valueOf(value),0); + break; + } + // Double + case "2":{ + value = Util.getDoubleValue(String.valueOf(value),0); + break; + } + //日期类型 + case "3" : { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, "yyyy-MM-dd"); + } catch (Exception e) { + throw new RuntimeException("时间处理异常:参数>>" + paramName); + } + }break; + // 时间日期类型 + case "4": { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, "yyyy-MM-dd HH:mm:ss"); + } catch (Exception e) { + throw new RuntimeException("时间处理异常:参数>>" + paramName + " 异常信息:" + e); + } + } + break; + // 自定义时间格式化类型 + case "7": { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, valueContext); + } catch (Exception e) { + throw new RuntimeException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage()); + } + } + break; + // 时间戳类型 + case "8": { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = date.getTime(); + } catch (Exception e) { + throw new RuntimeException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage()); + } + }break; + default:break; + } + }catch (Exception e){ + throw new RuntimeException("执行setCommonParamValue发生异常 : " + e.getMessage()); + } + return value; + } + + /** + *

日期解析

+ * @param dateStr 日期字符串 + * @return 日期对象 + */ + public static Date parseDate(String dateStr) { + ThreadLocal SIMPLE_DATE_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd")); + if (dateStr == null || dateStr.length() == 0) { + return null; + } + String regex = "\\/|\\.|年|月|日"; + Date date = null; + try { + date = SIMPLE_DATE_FORMAT.get().parse(dateStr.replaceAll(regex, "-")); + return date; + } catch (ParseException e) { + throw new RuntimeException("无法将" + dateStr + "转换为日期对象!", e); + } + } + + /** + *

自定义时间格式化

+ * @param date 日期 + * @param tempStr 格式化字符串 + * @return 格式化字符串 + */ + private static String diyDateFortMat(Date date,String tempStr){ + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(tempStr); + return simpleDateFormat.format(date); + } + + /** + *

根据配置对象生成xml

+ * @param config 配置对象 + * @param requestId 请求id + * @param tableName 表名 + * @return xml + */ + public String getXml(MainRequestConfig config, String requestId,String tableName){ + try { + String configFilePath = config.getConfigFilePath(); + if(StringUtils.isBlank(configFilePath)){ + throw new RuntimeException("建模主表配置文件不能为空!"); + } + String requestUrl = config.getRequestUrl(); + if(StringUtils.isBlank(requestUrl)){ + throw new RuntimeException("获取配置文件明细表为空!"); + } + List requestConfigList = config.getDetailRequestConfigList(); + if(CollectionUtils.isEmpty(requestConfigList)){ + throw new RuntimeException("获取配置文件明细表为空!"); + } + String sql = "select * from " + tableName + " where requestid = ?"; + if(StringUtils.isNotBlank(config.getCusSql())){ + sql += config.getCusSql(); + } + String dataSource = config.getDataSource(); + RecordSet mainRs = new RecordSet(); + RecordSet detailRs = new RecordSet(); + mainRs.executeQuery(sql, requestId); + log.info("执行主表查询SQL[ " + sql + " ], 参数 [ " + requestId + " ]"); + if (mainRs.next()) { + String mainId = mainRs.getString("id"); + String mainXml = ""; + String detailXml = ""; + // 主表 + if ("0".equals(dataSource)) { + mainXml = getMainXml(requestConfigList, mainRs, detailRs); + } else if("1".equals(dataSource)) { + // 仅明细 + detailXml = getDetailXml(requestConfigList, mainRs, detailRs, config.getDetailIndex(), tableName, mainId); + }else { + // 主表-明细 + mainXml = getMainXml(requestConfigList, mainRs, detailRs); + detailXml = getDetailXml(requestConfigList, mainRs, detailRs, config.getDetailIndex(), tableName, mainId); + } + StringBuilder xml = new StringBuilder(); + try { + String filePath = parseConfigPath(configFilePath); + log.info("模板配置文件路径 [ " + filePath + " ]"); + FileInputStream in = new FileInputStream(filePath); + InputStreamReader inReader = new InputStreamReader(in, StandardCharsets.UTF_8); + BufferedReader bufReader = new BufferedReader(inReader); + String line; + while ((line = bufReader.readLine()) != null) { + if(line.contains("{mainRecord}")){ + line = mainXml; + xml.append(line); + }else if(line.contains("{detailRecord}")){ + line = detailXml; + xml.append(line); + }else { + if(StringUtils.isNotBlank(line)){ + String pattern = "(?<=\\{).+(?=})"; + Pattern compile = Pattern.compile(pattern); + Matcher matcher = compile.matcher(line); + while (matcher.find()){ + String field = matcher.group(); + if(StringUtils.isNotBlank(field)){ + if(field.startsWith("main.")){ + String mainField = field.replace("main.", ""); + line = line.replaceAll("#\\{.+}",Util.null2String(mainRs.getString(mainField))); + }else if(field.startsWith("sql.")){ + String selectSql = field.replace("sql.", ""); + Matcher matcherSql = compile.matcher(selectSql); + while (matcherSql.find()){ + String sqlField = matcherSql.group(); + String value = Util.null2String(mainRs.getString(sqlField)); + String replaceAllSql = selectSql.replaceAll("#\\{.+}", "\\?"); + line = line.replaceAll("#\\{.+}",Util.null2String(getValueByChangeRule(replaceAllSql,value, requestId))); + } + } + } + } + } + xml.append(line).append("\n"); + } + } + bufReader.close(); + inReader.close(); + in.close(); + } catch (Exception e) { + throw new RuntimeException("读取配置文件失败!文件路径=> " + configFilePath + " error => " + e.getMessage()); + } + return xml.toString(); + } + }catch (Exception e){ + throw new RuntimeException("生成xml发生异常, " + e.getMessage()); + } + return ""; + } + + /** + *

获取主xml

+ * @param requestConfigList 配置明细集合 + * @param mainRs 主表recordSet + * @param detailRs 明细recordSet + * @return 主表xml + */ + public String getMainXml(List requestConfigList, + RecordSet mainRs, + RecordSet detailRs){ + List collect = requestConfigList.stream() + .filter(item -> "mainRecord".equals(item.getParentName())) + .collect(Collectors.toList()); + StringBuilder mainSb = new StringBuilder(); + appendXml(mainSb, collect, mainRs, detailRs,1); + return mainSb.toString(); + } + + /** + *

获取明细xml

+ * @param requestConfigList 配置集合 + * @param mainRs 主表recordSet + * @param detailRs 明细表recordSet + * @param detailIndex 明细下标 + * @param tableName 表名 + * @param mainId 主数据id + * @return 明细xml + */ + public String getDetailXml(List requestConfigList, + RecordSet mainRs, RecordSet detailRs, String detailIndex, + String tableName, String mainId){ + // 明细 + String[] detailIdArr = detailIndex.split(","); + StringBuilder detailSb = new StringBuilder(); + for (String detailId : detailIdArr) { + List detailCollect = requestConfigList.stream() + .filter(item -> "detailRecord".equals(item.getParentName()) + ).collect(Collectors.toList()); + String detailSql = "select * from " + tableName + "_dt" + detailId + " where mainid = ?"; + if (detailRs.executeQuery(detailSql, mainId)) { + int count = 1; + while (detailRs.next()) { + appendXml(detailSb, detailCollect, mainRs, detailRs, count++); + } + } + } + return detailSb.toString(); + } + + /** + *

xml拼接

+ * @param xml xml对象 + * @param configList 配置对象集合 + * @param mainRs 主表recordSet + * @param detailRs 明细recordSet + * @param count 序号 + */ + public void appendXml(StringBuilder xml, List configList, + RecordSet mainRs, RecordSet detailRs, int count){ + for (DetailRequestConfig requestConfig : configList) { + String paramName = requestConfig.getParamName(); + xml.append("<") + .append(paramName) + .append(">") + .append(getParamValue(requestConfig, mainRs, detailRs,count)) + .append("<") + .append(paramName) + .append(">") + .append("\n"); + } + } + + /** + *

解析请求xml模板位置

+ * wxr.memsic.test.xml = /wxr/memsic/test.xml + * @param configFilePath 模板文件路径 + * @return 解析后的文件路径 + */ + public String parseConfigPath(String configFilePath){ + StringBuilder filePath = new StringBuilder(GCONST.getSysFilePath()); + int beginIndex = configFilePath.indexOf("."); + int endIndex = configFilePath.lastIndexOf("."); + if(beginIndex == endIndex){ + filePath.append(configFilePath); + }else { + String[] pathArr = configFilePath.split("\\."); + for (int i = 0; i < pathArr.length - 2; i++) { + if(i != 0){ + filePath.append(File.separator); + } + filePath.append(pathArr[i]); + } + filePath.append(File.separator) + .append(pathArr[pathArr.length - 2]) + .append(".") + .append(pathArr[pathArr.length - 1]); + } + return filePath.toString(); + } + + private String getGUID(int bit) { + StringBuilder uid = new StringBuilder(); + // 产生16位的强随机数 + Random rd = new SecureRandom(); + for (int i = 0; i < bit; i++) { + // 产生0-2的3位随机数 + int type = rd.nextInt(3); + switch (type) { + case 0: + // 0-9的随机数 + uid.append(rd.nextInt(10)); + break; + case 1: + // ASCII在65-90之间为大写,获取大写随机 + uid.append((char) (rd.nextInt(25) + 65)); + break; + case 2: + // ASCII在97-122之间为小写,获取小写随机 + uid.append((char) (rd.nextInt(25) + 97)); + break; + default: + break; + } + } + return uid.toString(); + } + + + /** + *

解析响应数据

+ * @param responseMap 响应map + * @param responseField 需要从map中获取指定字段的标识 Response.Execution + * @return 响应数据 + */ + public String parseMap(Map responseMap, String responseField){ + String[] strArr = responseField.split("\\."); + int i = 0; + while (i < strArr.length - 1){ + Object o = responseMap.get(strArr[i]); + if(o instanceof Map){ + responseMap = (Map) o; + }else if(o instanceof List){ + List> list = (List>) o; + if(CollectionUtils.isEmpty(list)){ + return ""; + } + responseMap = list.get(0); + } + i++; + } + return Util.null2String(responseMap.get(strArr[strArr.length - 1])); + } + +} diff --git a/src/main/java/weaver/xuanran/wang/immc/service/WorkFlowToVmsAndMQService.java b/src/main/java/weaver/xuanran/wang/immc/service/WorkFlowToVmsAndMQService.java index 84d08ef..6de58fa 100644 --- a/src/main/java/weaver/xuanran/wang/immc/service/WorkFlowToVmsAndMQService.java +++ b/src/main/java/weaver/xuanran/wang/immc/service/WorkFlowToVmsAndMQService.java @@ -13,14 +13,18 @@ import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.RecordMetadata; import org.apache.log4j.Logger; import weaver.conn.RecordSet; +import weaver.general.GCONST; import weaver.xiao.commons.config.entity.RequestMappingConfig; import weaver.xiao.commons.config.service.DealWithMapping; import weaver.xuanran.wang.common.util.CommonUtil; import weaver.xuanran.wang.immc.entity.VmsResponseVoField; import javax.ws.rs.core.MediaType; -import java.io.IOException; +import java.io.*; +import java.nio.file.Files; +import java.util.HashMap; import java.util.Map; +import java.util.Properties; /** *

vms业务方法

@@ -115,32 +119,41 @@ public class WorkFlowToVmsAndMQService { **/ public void sendToMQ(String kafkaConfig, Map message){ KafkaProducer producer = null; + InputStream inputStream = null; try { - Map configMap = Util.getProperties2Map(kafkaConfig); - if(MapUtils.isEmpty(configMap)){ + String path = GCONST.getPropertyPath() + "prop2map" + File.separator + kafkaConfig + ".properties"; + File configFile = new File(path); + if(!configFile.exists()){ throw new CustomerException("please check /web-inf/prop2map has " + kafkaConfig + ".properties"); } - log.info("kafkaConfig : " + JSONObject.toJSONString(configMap)); - String topic = Util.null2DefaultStr(configMap.get("topic"),""); + Properties prop = new Properties(); + inputStream= new BufferedInputStream(Files.newInputStream(configFile.toPath())); + prop.load(inputStream); + log.info("prop => " + JSONObject.toJSONString(prop)); + log.info("msg => " + JSONObject.toJSONString(message)); + String topic = Util.null2DefaultStr(prop.getProperty("topic"),""); if(StringUtils.isBlank(topic)){ throw new CustomerException("kafka properties topic can not null!"); } - producer = new KafkaProducer<>(configMap); + producer = new KafkaProducer<>(prop); // 发送消息到指定主题 ProducerRecord record = new ProducerRecord<>(topic, JSONObject.toJSONString(message)); - try { - RecordMetadata recordMetadata = producer.send(record).get(); - log.info(Util.logStr("send mq recordMetadata: {}", JSONObject.toJSONString(recordMetadata))); - }catch (Exception e){ - throw new CustomerException(Util.logStr("producer send error: {}!", e.getMessage())); - } + producer.send(record).get(); }catch (Exception e){ - throw new CustomerException(Util.logStr("send to kafka error!: {}", e.getMessage())); + log.error(Util.getErrString(e)); + throw new CustomerException(Util.logStr("send to kafka error!: [{}]", e.getMessage())); }finally { // 关闭Kafka生产者实例 if(producer != null){ producer.close(); } + if(inputStream != null){ + try { + inputStream.close(); + }catch (Exception e){ + log.error("inputStream close error! " + e.getMessage()); + } + } } } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java index 75622c5..1750741 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java @@ -4,8 +4,8 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import weaver.xuanran.wang.sh_bigdata.common.service.CusDataDecipher; -import java.util.function.Consumer; /** *

自定义请求条件

@@ -23,4 +23,5 @@ public class CusSuccess { private String errorMsg; private String dataKey; private Object response; + private CusDataDecipher cusDataDecipher; } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/service/CusDataDecipher.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/service/CusDataDecipher.java new file mode 100644 index 0000000..7e56528 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/service/CusDataDecipher.java @@ -0,0 +1,15 @@ +package weaver.xuanran.wang.sh_bigdata.common.service; + +import aiyh.utils.httpUtil.ResponeVo; + +import java.util.Map; + +/** + *

自定义解密类

+ * + * @author xuanran.wang + * @date 2023/4/10 13:20 + */ +public interface CusDataDecipher { + Map decoder(ResponeVo responeVo); +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java index b638132..beb3b3c 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java @@ -5,7 +5,6 @@ import aiyh.utils.excention.CustomerException; import aiyh.utils.httpUtil.ResponeVo; import aiyh.utils.httpUtil.util.HttpUtils; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; @@ -52,11 +51,16 @@ public class RequestMasterPlate{ responseVo.getEntityString())); // 相应内容 throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 } - Map response = responseVo.getResponseMap(); // 根据相应结果转化为map集合 + Map response; + if(cusSuccess.getCusDataDecipher() != null){ + response = cusSuccess.getCusDataDecipher().decoder(responseVo); + }else { + response = responseVo.getResponseMap(); // 根据相应结果转化为map集合 + } cusSuccess.setResponse(response); int responseValue = Util.getIntValue(Util.null2DefaultStr(response.get(cusSuccess.getSuccessField()), ""),-1); if (cusSuccess.getSuccessValue() != responseValue) { - throw new CustomerException(Util.logStr("接口响应码不为: [{}], 接口响应信息: {}", cusSuccess.getSuccessValue(), Util.null2DefaultStr(response.get(cusSuccess.getErrorMsg()), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + throw new CustomerException(Util.logStr("接口地址:[{}], 接口响应码不为: [{}], 接口响应信息: {}", url, cusSuccess.getSuccessValue(), Util.null2DefaultStr(response.get(cusSuccess.getErrorMsg()), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 } String[] split = Util.null2DefaultStr(cusSuccess.getDataKey(),"").split("\\."); int len = split.length; diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/SendTodoTaskUtil.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/SendTodoTaskUtil.java index 6810040..1a796ff 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/SendTodoTaskUtil.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/SendTodoTaskUtil.java @@ -26,7 +26,7 @@ import java.util.stream.Collectors; public class SendTodoTaskUtil { private final SendTodoTaskMapper mapper = Util.getMapper(SendTodoTaskMapper.class); private final CommonMapper commonMapper = Util.getMapper(CommonMapper.class); - private String appId; + private String agentId; private String oaAddress; private Logger log = Util.getLogger(); @@ -71,11 +71,11 @@ public class SendTodoTaskUtil { int requestId = obj.getRequestid(); int userId = obj.getUser().getUID(); todoTask.setTaskNum(taskId); - todoTask.setAppId(appId); + todoTask.setAgentid(agentId); todoTask.setTaskName(obj.getRequestnamenew()); todoTask.setTaskDesc(obj.getRequestnamenew()); - todoTask.setLinkUrl(oaAddress + "/spa/workflow/static4form/index.html?#/main/workflow/req?requestid="+requestId); - todoTask.setMobileLinkUrl(oaAddress + "/spa/workflow/static4mobileform/index.html?#/req?requestid="+requestId); + todoTask.setLinkUrl(Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("taskPcUrl"), oaAddress) + "/spa/workflow/static4form/index.html?#/main/workflow/req?requestid="+requestId); + todoTask.setMobileLinkUrl(Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("taskMobileUrl"), oaAddress) + "/spa/workflow/static4mobileform/index.html?#/req?requestid="+requestId); todoTask.setSender(getConvertHrm(0, obj, obj.getCreator().getUID() + "")); todoTask.setReceiver(getConvertHrm(1, obj,userId + "")); res.add(todoTask); @@ -99,7 +99,7 @@ public class SendTodoTaskUtil { CusDoneTask doneTask = new CusDoneTask(); doneTask.setTaskNum(num); doneTask.setStatus(1); - doneTask.setAppId(appId); + doneTask.setAgentid(agentId); res.add(doneTask); } } @@ -156,11 +156,10 @@ public class SendTodoTaskUtil { * @return OA地址 **/ public String getOAAddress(){ - String address = mapper.queryOAAddress(); - if(StringUtils.isBlank(address)){ - throw new CustomerException("OAAddress can not null!"); - } - return address; + // if(StringUtils.isBlank(address)){ +// throw new CustomerException("OAAddress can not null!"); +// } + return Util.null2DefaultStr(mapper.queryOAAddress(),""); } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java index 5688afc..bcf46c6 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java @@ -2,11 +2,9 @@ package weaver.xuanran.wang.sh_bigdata.common.util; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; -import com.alibaba.fastjson.JSONObject; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; -import weaver.xuanran.wang.sh_bigdata.common.entity.CusToken; +import weaver.general.TimeUtil; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations.CusDbEntityMapping; import java.lang.reflect.Field; @@ -28,6 +26,15 @@ public class ShBigDataUtil { static { WHILTE_LIST.add("hrmSenderConvertRuleSql"); WHILTE_LIST.add("hrmReceiveConvertRuleSql"); + WHILTE_LIST.add("maxLevel"); + WHILTE_LIST.add("orgNoFetchChild"); + WHILTE_LIST.add("orgUpdateTime"); + WHILTE_LIST.add("hrmUpdateTime"); + WHILTE_LIST.add("orgHrmAsyncLogModelId"); + WHILTE_LIST.add("loginSuccessSendRedirectUrl"); + WHILTE_LIST.add("loginErrorSendRedirectUrl"); + WHILTE_LIST.add("getUserIdDebug"); + WHILTE_LIST.add("getUserIdDebugOutKey"); } /** @@ -37,7 +44,18 @@ public class ShBigDataUtil { * @return token **/ public static String getToken(){ - return TokenUtil.getToken(); + return TokenUtil.getToken(ShBigDataUtil.getPropertiesValByKey("corpSecret")); + } + + /** + *

获取token

+ * @author xuanran.wang + * @dateTime 2023/4/6 19:59 + * @param secret 密钥 + * @return token + **/ + public static String getToken(String secret){ + return TokenUtil.getToken(secret); } /** @@ -51,6 +69,18 @@ public class ShBigDataUtil { return url + "?access_token=" + getToken(); } + /** + *

给post请求的url添加token

+ * @author xuanran.wang + * @dateTime 2023/4/6 20:11 + * @param url 路径 + * @param secret 密钥 + * @return 添加完token的路径url + **/ + public static String addToken2Url(String url, String secret){ + return url + "?access_token=" + getToken(secret); + } + /** *

获取配置文件

* @author xuanran.wang @@ -90,6 +120,19 @@ public class ShBigDataUtil { * @return 参数 **/ public static LinkedHashMap parseCusDbEntityMapping(int type, Object o) throws IllegalAccessException { + return parseCusDbEntityMapping(type, 0, false); + } + + /** + *

解析注解并将实体类转换成map

+ * @author xuanran.wang + * @dateTime 2023/4/6 12:27 + * @param type 表类型 0: 分部, 1: 部门 + * @param o 对象 + * @param addSysParam 是否添加系统默认参数 + * @return 参数 + **/ + public static LinkedHashMap parseCusDbEntityMapping(int type, Object o, boolean addSysParam) throws IllegalAccessException { Class clazz = o.getClass(); LinkedHashMap params = new LinkedHashMap<>(); Field[] fields = clazz.getDeclaredFields(); @@ -103,18 +146,28 @@ public class ShBigDataUtil { if(cusDbEntityMapping != null){ String[] dbFields = cusDbEntityMapping.dbFiled(); String dbField; - if(dbFields.length == 0 || type == -1){ - dbField = field.getName(); + if(dbFields.length <= 1 || type == -1){ + dbField = dbFields[0]; }else { - int index = Math.min(dbFields.length, type); - dbField = dbFields[index - 1]; + dbField = dbFields[type]; + } + if(StringUtils.isBlank(dbField)){ + continue; } field.setAccessible(true); params.put(dbField, field.get(o)); } } + if(addSysParam){ + String dateTime = TimeUtil.getCurrentTimeString(); + params.put("creater",1); + params.put("created", dateTime); + params.put("modifier", 1); + params.put("modified", dateTime); + } return params; } + } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java index 706bf4c..f9ae238 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java @@ -10,6 +10,7 @@ import weaver.xuanran.wang.sh_bigdata.common.entity.CusToken; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** *

token 工具类

@@ -19,39 +20,43 @@ import java.util.Map; */ public class TokenUtil { private static final Logger log = Util.getLogger(); - private static volatile CusToken cusToken = null; +// private static volatile CusToken cusToken = null; private static final CusSuccess tokenCusSuccess = CusSuccess.builder() .successField("errcode") .successValue(0) - .errorMsg("msg") + .errorMsg("errmsg") .dataKey("") .build(); private static final RequestMasterPlate requestMasterPlate = new RequestMasterPlate(); + private static final Map TOKEN_MAP = new ConcurrentHashMap<>(); /** *

获取token

* @author xuanran.wang * @dateTime 2023/4/6 19:59 * @return token + * @param secret 密钥 **/ - public static String getToken() { - if(cusToken == null){ + public static String getToken(String secret) { + CusToken token = TOKEN_MAP.get(secret); + if(token == null){ synchronized (TokenUtil.class){ - if(cusToken == null){ - return getTokenByHTTP(); + token = TOKEN_MAP.get(secret); + if(token == null){ + return getTokenByHTTP(secret); } } } - long expiryTime = cusToken.getExpiryTime(); + long expiryTime = token.getExpiryTime(); if(new Date().getTime() >= expiryTime){ synchronized (TokenUtil.class){ - expiryTime = cusToken.getExpiryTime(); + expiryTime = token.getExpiryTime(); if(new Date().getTime() >= expiryTime){ - return getTokenByHTTP(); + return getTokenByHTTP(secret); } } } - return cusToken.getAccess_token(); + return token.getAccess_token(); } /** @@ -60,19 +65,20 @@ public class TokenUtil { * @dateTime 2023/4/7 23:49 * @return token **/ - private static String getTokenByHTTP(){ + private static String getTokenByHTTP(String secret){ + log.info("getTokenByHTTP secret : " + secret); HashMap params = new HashMap<>(); // 接口调用地址 String tokenUrl = ShBigDataUtil.getPropertiesValByKey("tokenUrl"); // 密钥 - String corpSecret = ShBigDataUtil.getPropertiesValByKey("corpSecret"); - params.put("corpsecret", corpSecret); + params.put("corpsecret", secret); Map tokenMap = requestMasterPlate.apiGet(tokenUrl, params, new HashMap<>(), tokenCusSuccess); - cusToken = JSONObject.parseObject(JSONObject.toJSONString(tokenMap), CusToken.class); + CusToken token = JSONObject.parseObject(JSONObject.toJSONString(tokenMap), CusToken.class); long expiryBeforeTime = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("expiryBeforeTime"), 5); // 默认少5分钟过期 - cusToken.setExpiryTime(new Date().getTime() + (cusToken.getExpires_in() * 1000) - (60 * expiryBeforeTime * 1000)); - log.info("http token => " + JSONObject.toJSONString(cusToken)); - return cusToken.getAccess_token(); + token.setExpiryTime(new Date().getTime() + (token.getExpires_in() * 1000) - (60 * expiryBeforeTime * 1000)); + TOKEN_MAP.put(secret, token); + log.info("token maps : " + JSONObject.toJSONString(TOKEN_MAP)); + return token.getAccess_token(); } } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/OrganizationHrmSyncFromOtherSys.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/OrganizationHrmSyncFromOtherSys.java index 7e2b8d2..c4e5c18 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/OrganizationHrmSyncFromOtherSys.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/OrganizationHrmSyncFromOtherSys.java @@ -1,9 +1,16 @@ package weaver.xuanran.wang.sh_bigdata.org_hrm_async; +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import org.apache.log4j.Logger; import weaver.hrm.resource.HrmSynDAO; import weaver.interfaces.hrm.*; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncService; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl.OrgHrmAsyncServiceImpl; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -15,17 +22,29 @@ import java.util.Map; public class OrganizationHrmSyncFromOtherSys implements HrmSynService { private HashMap synResult; + private final OrgHrmAsyncService asyncService = new OrgHrmAsyncServiceImpl(); + + private final Logger log = Util.getLogger(); + public OrganizationHrmSyncFromOtherSys(){ this.removeSynResult(); } @Override public String SynTimingToOASubCompany() { + List> subCompany = asyncService.asyncOrgDep(0); + List> list = buildItemList(subCompany); + this.synResult.put("1", list); + log.info("subCompany : \n" + JSONObject.toJSONString(list)); return null; } @Override public String SynTimingToOADepartment() { + List> subCompany = asyncService.asyncOrgDep(1); + List> list = buildItemList(subCompany); + this.synResult.put("2", list); + log.info("department : \n" + JSONObject.toJSONString(list)); return null; } @@ -36,6 +55,10 @@ public class OrganizationHrmSyncFromOtherSys implements HrmSynService { @Override public String SynTimingToOAHrmResource() { + List> hrmList = asyncService.asyncHrm(); + List> list = buildItemList(hrmList); + this.synResult.put("4", list); + log.info("hrmresource : \n" + JSONObject.toJSONString(list)); return null; } @@ -93,6 +116,18 @@ public class OrganizationHrmSyncFromOtherSys implements HrmSynService { this.synResult = new HashMap<>(); } + private List> buildItemList(List> list){ + List> synResultlist = new ArrayList<>(); + for (Map map : list) { + String id = Util.null2DefaultStr(map.get("id"), ""); + String name = Util.null2DefaultStr(map.get("name"), ""); + String code = Util.null2DefaultStr(map.get("code"), ""); + String msg = Util.null2DefaultStr(map.get("msg"), ""); + synResultlist.add(buildItemMap(id, id, name, code, msg)); + } + return synResultlist; + } + private Map buildItemMap(String pkCode, String pk, String memo, String success, String error) { //保存结果 Map res = new HashMap<>(); @@ -103,4 +138,6 @@ public class OrganizationHrmSyncFromOtherSys implements HrmSynService { res.put(HrmSynDAO.ErrorMessage, error); return res; } + + } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/annotations/CusOrgHrmAsyncConvert.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/annotations/CusOrgHrmAsyncConvert.java new file mode 100644 index 0000000..53e47ea --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/annotations/CusOrgHrmAsyncConvert.java @@ -0,0 +1,16 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations; + +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncCache; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigDetail; + +import java.util.Map; + +/** + *

自定义转换接口

+ * + * @author xuanran.wang + * @date 2023/4/11 16:49 + */ +public interface CusOrgHrmAsyncConvert { + Object cusConvert(OrgHrmAsyncConfigDetail detail, OrgHrmAsyncCache cache, Map pathParam); +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncCache.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncCache.java new file mode 100644 index 0000000..56902e1 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncCache.java @@ -0,0 +1,43 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.HashMap; +import java.util.Map; + +/** + *

人员同步接口缓存对象

+ * + * @author xuanran.wang + * @date 2023/4/11 17:19 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class OrgHrmAsyncCache { + /** + *

分部缓存

+ **/ + private Map subCompanyCache; + /** + *

部门缓存

+ **/ + private Map departmentCache; + /** + *

接口数据

+ **/ + private Map interfaceVal; + /** + *

人员缓存

+ **/ + private Map hrmCache; + /** + *

岗位缓存

+ **/ + private Map jobTitleCache; + private int arrIndex; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncConfigDetail.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncConfigDetail.java new file mode 100644 index 0000000..2a9b914 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncConfigDetail.java @@ -0,0 +1,30 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity; + +import aiyh.utils.annotation.recordset.SqlDbFieldAnn; +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; +import lombok.Data; + +/** + *

组织架构同步配置表-明细

+ * + * @author xuanran.wang + * @date 2023/4/11 15:08 + */ +@Data +public class OrgHrmAsyncConfigDetail { + @SqlDbFieldAnn("interfaceField") + @SqlOracleDbFieldAnn("INTERFACEFIELD") + private String interfaceField; + @SqlDbFieldAnn("oaField") + @SqlOracleDbFieldAnn("OAFIELD") + private String oaField; + @SqlDbFieldAnn("fieldType") + @SqlOracleDbFieldAnn("FIELDTYPE") + private int fieldType; + @SqlDbFieldAnn("convertType") + @SqlOracleDbFieldAnn("CONVERTTYPE") + private int convertType; + @SqlDbFieldAnn("cusText") + @SqlOracleDbFieldAnn("CUSTEXT") + private String cusText; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncConfigMain.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncConfigMain.java new file mode 100644 index 0000000..3cb71be --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OrgHrmAsyncConfigMain.java @@ -0,0 +1,39 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity; + +import aiyh.utils.annotation.recordset.SqlDbFieldAnn; +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; +import lombok.Data; + +import java.util.List; + +/** + *

组织架构同步配置表

+ * + * @author xuanran.wang + * @date 2023/4/11 15:05 + */ +@Data +public class OrgHrmAsyncConfigMain { + @SqlDbFieldAnn("asyncType") + @SqlOracleDbFieldAnn("ASYNCTYPE") + private int asyncType; + @SqlDbFieldAnn("updateTableName") + @SqlOracleDbFieldAnn("UPDATETABLENAME") + private String updateTableName; + @SqlDbFieldAnn("cusWhere") + @SqlOracleDbFieldAnn("CUSWHERE") + private String cusWhere; + @SqlDbFieldAnn("primaryKey") + @SqlOracleDbFieldAnn("PRIMARYKEY") + private String primaryKey; + @SqlDbFieldAnn("foreignKey") + @SqlOracleDbFieldAnn("FOREIGNKEY") + private String foreignKey; + @SqlDbFieldAnn("cusDepartment") + @SqlOracleDbFieldAnn("CUSDEPARTMENT") + private String cusDepartment; + @SqlDbFieldAnn("cudSubCompany") + @SqlOracleDbFieldAnn("CUDSUBCOMPANY") + private String cudSubCompany; + private List orgHrmAsyncConfigDetailList; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OtherSysDepartment.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OtherSysDepartment.java index aacf42a..a427ef4 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OtherSysDepartment.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OtherSysDepartment.java @@ -1,7 +1,9 @@ package weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity; import aiyh.utils.annotation.recordset.SqlDbFieldAnn; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations.CusDbEntityMapping; import java.util.List; @@ -14,6 +16,8 @@ import java.util.List; * @date 2023/4/4 11:03 */ @Data +@AllArgsConstructor +@NoArgsConstructor public class OtherSysDepartment { /** *

创建的部门id

@@ -37,17 +41,26 @@ public class OtherSysDepartment { **/ @CusDbEntityMapping(dbFiled = {"showorder"}) private int order; - /** - *

所属分部id

- **/ - @CusDbEntityMapping(dbFiled = {"supsubcomid","supsubcomid1"}) - private int subCompanyId; /** *

* 是否有子部门,0:否,1:是 *

**/ private int hasChild; + /** + *

层级

+ **/ + @CusDbEntityMapping(dbFiled = {"tlevel"}) + private int level; + /** + *

删除 0:有效

+ **/ + private int isDeleted; + /** + *

所属分部

+ **/ + @CusDbEntityMapping(dbFiled = {"","subcompanyid1"}) + private int division; private List childList; } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/job/OrganizationHrmSyncJob.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/job/OrganizationHrmSyncJob.java new file mode 100644 index 0000000..c3b96d8 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/job/OrganizationHrmSyncJob.java @@ -0,0 +1,146 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.job; + +import aiyh.utils.ThreadPoolConfig; +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.interfaces.schedule.BaseCronJob; +import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncService; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl.OrgHrmAsyncServiceImpl; + +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.function.Function; + +/** + *

组织架构-人员同步 计划任务

+ * + * @author xuanran.wang + * @date 2023/4/14 11:51 + */ +public class OrganizationHrmSyncJob extends BaseCronJob { + private final OrgHrmAsyncService asyncService = new OrgHrmAsyncServiceImpl(); + private final Logger log = Util.getLogger(); + private String orgHrmAsyncLogModelId; + private final ExecutorService executorService = ThreadPoolConfig.createThreadPoolInstance(); + private String asyncType; + private static final String ALL_ASYNC = ""; + private static final String ORG_COMPANY_ASYNC = "1"; + private static final String HRMRESOURCE_ASYNC = "2"; + private final Map> maps = new HashMap<>(); + + { + try { + orgHrmAsyncLogModelId = ShBigDataUtil.getPropertiesValByKey("orgHrmAsyncLogModelId"); + }catch (Exception e){ + log.error("orgHrmAsyncLogModelId init error!"); + } + maps.put(ORG_COMPANY_ASYNC, (o)->{ + orgAsync(); + return ""; + }); + maps.put(ALL_ASYNC, (o)->{ + orgAsync(); + hrmAsync(); + return ""; + }); + maps.put(HRMRESOURCE_ASYNC, (o)->{ + hrmAsync(); + return ""; + }); + } + + @Override + public void execute() { + if(StringUtils.isNotBlank(orgHrmAsyncLogModelId)){ + try { + asyncType = Util.null2DefaultStr(asyncType, ""); + log.info("asyncType : [ " + asyncType + " ]"); + Function function = maps.get(asyncType); + if(function != null){ + function.apply(""); + } + }catch (Exception e){ + log.error("OrganizationHrmSyncJob execute error! " + e.getMessage()); + log.info(Util.getErrString(e)); + } + } + } + /** + *

组织架构同步

+ * @author xuanran.wang + * @dateTime 2023/4/14 16:12 + **/ + private void orgAsync(){ + List> subCompanyList = asyncService.asyncOrgDep(0); + poolExecute(subCompanyList, 0); + List> departmentList = asyncService.asyncOrgDep(1); + poolExecute(departmentList, 1); + } + + /** + *

人员同步

+ * @author xuanran.wang + * @dateTime 2023/4/14 16:12 + **/ + private void hrmAsync(){ + List> hrmList = asyncService.asyncHrm(); + poolExecute(hrmList, 2); + } + + /** + *

线程池提交任务

+ * @author xuanran.wang + * @dateTime 2023/4/14 14:11 + * @param list 数据 + **/ + private void poolExecute(List> list, int type){ + executorService.execute(()->{ + try { + log.info("subCompanyList : \n" + JSONObject.toJSONString(list)); + List> convert = convert(list, type); + CusInfoToOAUtil.executeBatch(Util.getIntValue(this.orgHrmAsyncLogModelId, -1), convert); + }catch (Exception e){ + log.info("写入日志建模异常! " + e.getMessage()); + } + }); + } + + /** + *

将同步数据转换成日志记录map对象

+ * @author xuanran.wang + * @dateTime 2023/4/14 14:12 + * @param dataList 数据集合 + * @param type 同步类型 + * @return 转换后的集合 + **/ + private List> convert(List> dataList, int type){ + List> res = new ArrayList<>(); + for (Map map : dataList) { + LinkedHashMap linkedHashMap = new LinkedHashMap<>(); + linkedHashMap.put("asyncType", type); + // 0 是失败 1是插入 2 是更新 + int success = Util.getIntValue(Util.null2DefaultStr(map.get("code"), ""), 0); + // 建模表 数据同步状态 成功是0 1是失败 + linkedHashMap.put("status", success == 0 ? 1 : 0); + // 建模表 更新/插入 更新是0 插入是1 + linkedHashMap.put("updateOrInsert", success == 2 ? 0 : 1); + linkedHashMap.put("msg", Util.null2DefaultStr(map.get("msg"), "")); + linkedHashMap.put("outPk", Util.null2DefaultStr(map.get("id"), "")); + linkedHashMap.put("dataName", Util.null2DefaultStr(map.get("name"), "")); + res.add(linkedHashMap); + } + return res; + } + + public String getAsyncType() { + return asyncType; + } + + public void setAsyncType(String asyncType) { + this.asyncType = asyncType; + } +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/mapper/OrgHrmAsyncMapper.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/mapper/OrgHrmAsyncMapper.java index 769ae6f..bd8943a 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/mapper/OrgHrmAsyncMapper.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/mapper/OrgHrmAsyncMapper.java @@ -1,11 +1,10 @@ package weaver.xuanran.wang.sh_bigdata.org_hrm_async.mapper; -import aiyh.utils.annotation.recordset.Select; -import aiyh.utils.annotation.recordset.SqlMapper; -import aiyh.utils.annotation.recordset.SqlString; -import aiyh.utils.annotation.recordset.Update; -import io.swagger.models.auth.In; +import aiyh.utils.annotation.recordset.*; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigDetail; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigMain; +import java.util.List; import java.util.Map; /** @@ -17,9 +16,80 @@ import java.util.Map; @SqlMapper public interface OrgHrmAsyncMapper { - @Select("select outkey, id from HrmSubCompany where outkey != '' and outkey is not null") - Map selectSubCompany(); + /** + *

查询配置表主表信息

+ * @author xuanran.wang + * @dateTime 2023/3/1 16:39 + * @return 主表配置对象 + **/ + @Select("select * from uf_org_hrm_async where asyncType = #{asyncType}") + @CollectionMappings({ + @CollectionMapping(property = "orgHrmAsyncConfigDetailList", + column = "id", + id = @Id(value = Integer.class, methodId = 1)) + }) + List selectSubCompanyAsyncConfig(@ParamMapper("asyncType") int asyncType); + + /** + *

查询配置表明细表信息

+ * @author xuanran.wang + * @dateTime 2023/3/1 16:39 + * @param mainId 主表数据id + * @return 配置集合 + **/ + @Select("select * from uf_org_hrm_async_dt1 where mainid = #{mainId}") + @CollectionMethod(1) + List selectSubCompanyAsyncConfigDetail(@ParamMapper("mainId") int mainId); + + @Select("select outkey, id from HrmSubCompany where outkey <> '' and outkey is not null") + List> selectSubCompanyAll(); + + @Select("select outkey, id from hrmdepartment where outkey <> '' and outkey is not null") + List> selectDepartmentAll(); + + @Select("select outkey, id, tlevel from HrmSubCompany where outkey <> '' and outkey is not null and canceled <> 1") + List> selectSubCompanyActive(); + + @Select("select outkey, id from hrmdepartment where outkey <> '' and outkey is not null and canceled <> 1") + List> selectDepartmentActive(); + + @Select("select jobtitlename,id from hrmjobtitles") + List> selectJobTitle(); + + @Select("select id from hrmjobtitles where jobtitlename = #{jobTitleName}") + String selectJobTitleByName(@ParamMapper("jobTitleName") String jobTitleName); + + @Insert("insert into hrmjobtitles(jobtitlemark, jobtitlename, creater, created) values(#{position}, #{position}, 1, #{jobCreateTime})") + boolean insertJobTitle(Map params); @Update(custom = true) - boolean updateSubInfo(@SqlString String sql, Map params); + boolean updateOrgInfo(@SqlString String sql, Map params); + + @Select("select interfaceDataId from uf_depart_or_sub where depOrSub = 0") + List selectCusSubCompany(); + + @Select("select interfaceDataId from uf_depart_or_sub where depOrSub = 1") + List selectCusDepart(); + + @Select(custom = true) + String selectCustomerSql(@SqlString String sql, Map map); + @Select(custom = true) + List selectCustomerSqlArr(@SqlString String sql, Map map); + @Update("update HrmSubCompany set canceled = 1 where outkey in (${outKeys})") + boolean updateHrmSubCompanyCanceled(List outKeys); + + @Update("update hrmdepartment set canceled = 1 where outkey in (${outKeys})") + boolean updateHrmDepartmentCanceled(List outKeys); + + @Select("select min(outkey) from hrmsubcompany where outkey <> '' and outkey is not null") + String selectTopLevelOutKey(); + + @Select("select outkey, id from hrmresource ") + List> selectHrmIdAndOutKey(); + + @Insert(custom = true) + boolean insertHrmInfo(@SqlString String sql, Map params); + + @Select("select 1 from hrmresource where departmentid = (select id from hrmdepartment where outkey = #{outKey})") + int selectDepartHasUser(@ParamMapper("outKey") String outKey); } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncApiService.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncApiService.java index 8d23e7c..2474287 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncApiService.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncApiService.java @@ -1,8 +1,10 @@ package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service; +import com.icbc.api.internal.apache.http.impl.cookie.S; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; import java.util.List; +import java.util.Map; /** *

上海大数据中心人员/组织架构同步 接口调用

@@ -14,12 +16,13 @@ public interface OrgHrmAsyncApiService { /** - *

获取用户信息

+ *

获取用户信息 通过传入顶级组织id 并且递归获取所有用户

* @author xuanran.wang * @dateTime 2023/4/4 11:13 + * @param topLevelId 三方系统顶级组织id * @return 响应对象 **/ - List getUserInfo(); + List> getUserInfo(int topLevelId); /** *

获取部门信息

@@ -29,4 +32,12 @@ public interface OrgHrmAsyncApiService { **/ List getDepartmentInfo(); + /** + *

获取部门信息

+ * @author xuanran.wang + * @dateTime 2023/4/4 11:13 + * @return 响应对象 + **/ + List> getDepartmentInfoMap(); + } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncService.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncService.java index c7d1cf7..2a184a3 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncService.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncService.java @@ -1,6 +1,5 @@ package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service; -import io.swagger.models.auth.In; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; import java.util.List; @@ -14,13 +13,6 @@ import java.util.Map; */ public interface OrgHrmAsyncService { - /** - *

获取分部表中 outKey 与 id对应到map集合

- * @author xuanran.wang - * @dateTime 2023/4/6 13:44 - * @return 分部表中 outKey 与 id对应到map集合 - **/ - Map initSubCompany(); /** *

部门数据同步

* @author xuanran.wang @@ -28,4 +20,13 @@ public interface OrgHrmAsyncService { **/ List asyncDepartment(); + /** + *

部门数据同步

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:44 + **/ + List> asyncOrgDep(int type); + + List> asyncHrm(); + } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncApiServiceImpl.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncApiServiceImpl.java index d4ba595..0f2ea17 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncApiServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncApiServiceImpl.java @@ -1,6 +1,8 @@ package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl; +import aiyh.utils.Util; import com.alibaba.fastjson.JSONObject; +import com.engine.common.service.impl.ThemeServiceImpl; import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncApiService; @@ -22,23 +24,30 @@ import java.util.Map; */ public class OrgHrmAsyncApiServiceImpl implements OrgHrmAsyncApiService { private final RequestMasterPlate requestMasterPlate = new RequestMasterPlate(); - @Override - public List getUserInfo() { - return null; - } @Override - public List getDepartmentInfo() { - String departmentInfoUrl = ShBigDataUtil.getPropertiesValByKey("departmentInfoUrl"); + public List> getUserInfo(int topLevelId) { + String departmentInfoUrl = ShBigDataUtil.getPropertiesValByKey("userInfoUrl"); HashMap params = new HashMap<>(); params.put("access_token", ShBigDataUtil.getToken()); + params.put("department_id", topLevelId); + params.put("no_fetch_child", 1); + // 如果hrmUpdateTime则获取增量数据 + if(1 == Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("hrmUpdateTime"),0)){ + params.put("updateTime", System.currentTimeMillis()); + } CusSuccess cusSuccess = CusSuccess.builder() .successField("code") .successValue(0) .errorMsg("msg") - .dataKey("data.department") + .dataKey("data.userList") .build(); - List> list = requestMasterPlate.apiGet(departmentInfoUrl, params, new HashMap<>(), cusSuccess); + return requestMasterPlate.apiGet(departmentInfoUrl, params, new HashMap<>(), cusSuccess); + } + + @Override + public List getDepartmentInfo() { + List> list = getDepartmentInfoMap(); List res = new ArrayList<>(); for (Object o : list) { res.add(JSONObject.parseObject(JSONObject.toJSONString(o), OtherSysDepartment.class)); @@ -46,4 +55,24 @@ public class OrgHrmAsyncApiServiceImpl implements OrgHrmAsyncApiService { return res; } + @Override + public List> getDepartmentInfoMap() { + String departmentInfoUrl = ShBigDataUtil.getPropertiesValByKey("departmentInfoUrl"); + HashMap params = new HashMap<>(); + params.put("access_token", ShBigDataUtil.getToken()); + params.put("no_fetch_child", Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("orgNoFetchChild"),0)); + // orgUpdateTime = 1 进行增量数据同步 + if(1 == Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("orgUpdateTime"),0)){ + params.put("updateTime", System.currentTimeMillis()); + } + CusSuccess cusSuccess = CusSuccess.builder() + .successField("code") + .successValue(0) + .errorMsg("msg") + .dataKey("data.department") + .build(); + return requestMasterPlate.apiGet(departmentInfoUrl, params, new HashMap<>(), cusSuccess); + } + + } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncEntityServiceImpl.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncEntityServiceImpl.java new file mode 100644 index 0000000..e0f7cf7 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncEntityServiceImpl.java @@ -0,0 +1,265 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections.CollectionUtils; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.matrix.MatrixUtil; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.mapper.OrgHrmAsyncMapper; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncApiService; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncService; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.util.OrgHrmAsyncUtil; + +import java.util.*; +import java.util.stream.Collectors; + +/** + *

组织架构同步

+ * + * @author xuanran.wang + * @date 2023/4/6 10:10 + */ +public class OrgHrmAsyncEntityServiceImpl implements OrgHrmAsyncService { + private final Logger log = Util.getLogger(); + private final OrgHrmAsyncApiService orgHrmAsyncApiService = new OrgHrmAsyncApiServiceImpl(); + private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class); + private final SubCompanyComInfo sci = new SubCompanyComInfo(); + /** + *

配置表中部门白名单

+ **/ + private final List departmentWhiteList; + /** + *

配置表中分部白名单

+ **/ + private final List subCompanyWhiteList; + /** + *

分部缓存

+ **/ + private Map subCompanyCache = new HashMap<>(); + /** + *

部门缓存

+ **/ + private Map departmentCache = new HashMap<>(); + /** + *

分部最大层级

+ **/ + int maxLevel; + /** + *

接口中 上级分部字段

+ **/ + private String interfaceSupSubCompany; + + { + departmentWhiteList = orgHrmAsyncMapper.selectCusDepart(); + subCompanyWhiteList = orgHrmAsyncMapper.selectCusSubCompany(); + + List> subCompany = orgHrmAsyncMapper.selectSubCompanyAll(); + subCompanyCache = OrgHrmAsyncUtil.parseListMap2Map(subCompany); + + List> department = orgHrmAsyncMapper.selectDepartmentAll(); + departmentCache = OrgHrmAsyncUtil.parseListMap2Map(department); + maxLevel = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("maxLevel"), 3); + + } + + + @Override + public List asyncDepartment() { + List departmentInfo = orgHrmAsyncApiService.getDepartmentInfo(); + // 将部门信息转换成树 + List convetList = Util.listToTree(departmentInfo, + OtherSysDepartment::getId, OtherSysDepartment::getParentid, + OtherSysDepartment::getChildList, OtherSysDepartment::setChildList, + parentid -> parentid == -1); + // 进行部门分部解析 + List hrmSubCompany = new ArrayList<>(); + List hrmDepartment = new ArrayList<>(); + // 解析是部门还是分部 + parseSubCompanyAndDepartment(convetList, 0, maxLevel, hrmSubCompany, hrmDepartment); + // 进行顺序排序 + hrmSubCompany = hrmSubCompany.stream().sorted(Comparator.comparingInt(OtherSysDepartment::getId)).collect(Collectors.toList()); + hrmDepartment = hrmDepartment.stream().sorted(Comparator.comparingInt(OtherSysDepartment::getId)).collect(Collectors.toList()); + System.out.println("hrmSubCompany => " + JSONObject.toJSONString(hrmSubCompany)); + System.out.println("hrmDepartment => " + JSONObject.toJSONString(hrmDepartment)); + // 同步 + addHrmSubCompany(hrmSubCompany); + addHrmDepartment(hrmDepartment); + + return departmentInfo; + } + + + /** + *

同步数据到分部

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:37 + * @param departmentList 部门数据集合 + **/ + public void addHrmSubCompany(List departmentList){ + char separator = weaver.general.Util.getSeparator(); + RecordSet rsSch = new RecordSet(); + for (OtherSysDepartment department : departmentList) { + int subId = Util.getIntValue(Util.null2DefaultStr(subCompanyCache.get(department.getId()),""),-1); + if(subId < 0){ + String para = department.getName() + separator + department.getName() + separator + "1" + separator + + department.getId()+ separator + "" + separator +department.getOrder(); + rsSch.executeProc("HrmSubCompany_Insert", para); + if (rsSch.next()) { + subId = rsSch.getInt(1); + } + subCompanyCache.put(department.getId() + "", subId); + } + department.setParentid(Util.getIntValue(Util.null2DefaultStr(subCompanyCache.get(department.getParentid()),""),0)); + updateTable("HrmSubCompany", subId, 0, department); + } + //清除全部分部缓存 + sci.removeCompanyCache(); + } + + /** + *

同步数据到分部

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:37 + * @param departmentList 部门数据集合 + **/ + public void addHrmDepartment(List departmentList){ + char separator = weaver.general.Util.getSeparator(); + RecordSet rsSch = new RecordSet(); + for (OtherSysDepartment department : departmentList) { + int id = Util.getIntValue(Util.null2DefaultStr(departmentCache.get(department.getId()), ""),-1); + if(id < 0){ + String para = department.getName() + separator + department.getName() + separator + + "" + separator + "" + separator + department.getParentid() + separator + department.getOrder() + separator + ""; + rsSch.executeProc("HrmDepartment_Insert", para); + if (rsSch.next()) { + id = rsSch.getInt(1); + } + departmentCache.put(department.getId() + "", id); + } + System.out.println("departmentCache => " + JSONObject.toJSONString(departmentCache)); + System.out.println("subCompanyCache => " + JSONObject.toJSONString(subCompanyCache)); + System.out.println("department => " + JSONObject.toJSONString(department)); + int parentid = department.getParentid(); + department.setParentid(Util.getIntValue(Util.null2DefaultStr(departmentCache.get(parentid),""),0)); + // 如果一个分部从 分部变成了部门 那么他下面所有的都是部门 在设置所属分部的时候要将 分部的所属分部替换 + int division = Util.getIntValue(Util.null2DefaultStr(subCompanyCache.get(parentid), ""), -1); + department.setDivision(division); + updateTable("HrmDepartment", id, 1, department); + } + //清除全部分部缓存 + sci.removeCompanyCache(); + } + + + /** + *

解析部门or分部

+ * @author xuanran.wang + * @dateTime 2023/4/10 12:13 + * @param list 树形集合 + * @param n 层级 + * @param hrmSubCompany 分部 + * @param hrmDepartment 部门 + **/ + public void parseSubCompanyAndDepartment(List list, int n, int maxLevel,List hrmSubCompany, List hrmDepartment){ + n++; + for (OtherSysDepartment department : list) { + department.setLevel(n); + List childList = department.getChildList(); + String departmentId = department.getId() + ""; + if(CollectionUtils.isNotEmpty(childList)){ + List collect = department.getChildList().stream().map(item -> Util.null2DefaultStr(item.getId(), "")).collect(Collectors.toList()); + if(departmentWhiteList.contains(departmentId)){ + departmentWhiteList.addAll(collect); + }else if(subCompanyWhiteList.contains(departmentId)){ + subCompanyWhiteList.addAll(collect); + } + parseSubCompanyAndDepartment(childList, n, maxLevel, hrmSubCompany, hrmDepartment); + department.setChildList(new ArrayList<>()); + } + if(n > maxLevel || departmentWhiteList.contains(departmentId)){ + hrmDepartment.add(department); + }else{ + hrmSubCompany.add(department); + } + } + } + + /** + *

更新表数据

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:35 + * @param tableName 表名 + * @param id 数据id + * @param type 类型 + * @param o 对象 + **/ + public void updateTable(String tableName, int id, int type, Object o){ + StringBuilder sb = new StringBuilder("update "); + sb.append(tableName).append(" set "); + Map params; + try { + params = ShBigDataUtil.parseCusDbEntityMapping(type, o, true); + }catch (Exception e){ + throw new CustomerException("parseCusDbEntityMapping error!" + e.getMessage()); + } + for (Map.Entry entry : params.entrySet()) { + sb.append(entry.getKey()) + .append(" = #{") + .append(entry.getKey()) + .append("},"); + } + sb.deleteCharAt(sb.length() - 1); + sb.append(" where id = ").append(id); + boolean success = orgHrmAsyncMapper.updateOrgInfo(sb.toString(), params); + if(!success){ + log.error(Util.logStr("update {} sql error!", tableName)); + } + //同步分部数据到矩阵 + MatrixUtil.updateSubcompayData(String.valueOf(id)); + } + + @Override + public List> asyncOrgDep(int type) { + return new ArrayList<>(); + } + + @Override + public List> asyncHrm() { + return null; + } + + + /** + *

解析部门or分部

+ * @author xuanran.wang + * @dateTime 2023/4/10 12:13 + * @param list 树形集合 + * @param n 层级 + * @param hrmSubCompany 分部 + * @param hrmDepartment 部门 + **/ +// public void parseSubCompanyAndDepartment(List list, int n, int maxLevel,List hrmSubCompany, List hrmDepartment){ +// n++; +// for (OtherSysDepartment department : list) { +// department.setLevel(n); +// List childList = department.getChildList(); +// if(CollectionUtils.isNotEmpty(childList)){ +// parseSubCompanyAndDepartment(childList, n, maxLevel, hrmSubCompany, hrmDepartment); +// department.setChildList(null); +// } +// String departmentId = department.getId() + ""; +// if(n > maxLevel || departmentWhiteList.contains(departmentId)){ +// hrmDepartment.add(department); +// }else if(n < maxLevel || subCompanyWhiteList.contains(departmentId)){ +// hrmSubCompany.add(department); +// } +// } +// } + + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncServiceImpl.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncServiceImpl.java index b3500d8..a44e23b 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncServiceImpl.java @@ -1,21 +1,33 @@ package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl; +import aiyh.utils.ThreadPoolConfig; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.service.impl.ThemeServiceImpl; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.hrm.company.DepartmentComInfo; import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.resource.ResourceComInfo; import weaver.matrix.MatrixUtil; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncCache; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigMain; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.mapper.OrgHrmAsyncMapper; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncApiService; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncService; import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.util.OrgHrmAsyncUtil; -import java.util.Comparator; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.function.Function; import java.util.stream.Collectors; +import ln.LN; /** *

组织架构同步

@@ -24,65 +36,346 @@ import java.util.stream.Collectors; * @date 2023/4/6 10:10 */ public class OrgHrmAsyncServiceImpl implements OrgHrmAsyncService { + private final Logger log = Util.getLogger(); private final OrgHrmAsyncApiService orgHrmAsyncApiService = new OrgHrmAsyncApiServiceImpl(); - private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class); - private final SubCompanyComInfo sci = new SubCompanyComInfo(); + private final DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + private ResourceComInfo comInfo = null; + /** + *

配置表中部门白名单

+ **/ + private final List departmentWhiteList; + /** + *

配置表中分部白名单

+ **/ + private final List subCompanyWhiteList; + /** + *

分部缓存

+ **/ + private final Map subCompanyCache; + /** + *

部门缓存

+ **/ + private final Map departmentCache; + /** + *

岗位缓存

+ **/ + private final Map jobTitleCache; + /** + *

人员缓存

+ **/ + private final Map hrmCache; + /** + *

分部最大层级

+ **/ + int maxLevel; + /** + *

分部同步配置表对象

+ **/ + private final List subCompanyConfig; + /** + *

部门同步配置表对象

+ **/ + private final List departmentConfig; + /** + *

人员同步配置表对象

+ **/ + private final List hrmReSourceConfig; + /** + *

分部同步记录

+ **/ + private final List> asyncHrmSubCompany = new ArrayList<>(); + /** + *

部门同步记录

+ **/ + private final List> asyncHrmDepartment = new ArrayList<>(); + private final Map typeTableName = new HashMap<>(); + private final HashMap> getNextIdTypeMap = new HashMap<>(); + private final Map subCompanyLevelCache; - @Override - public Map initSubCompany() { - return orgHrmAsyncMapper.selectSubCompany(); + // 创建按order值进行排序的比较器 + Comparator> orderByOrder = (o1, o2) -> { + int order1 = (int) o1.get("order"); + int order2 = (int) o2.get("order"); + if (order1 != order2) { + return Integer.compare(order2, order1); + } else { + int id1 = (int) o1.get("id"); + int id2 = (int) o2.get("id"); + return Integer.compare(id1, id2); + } + }; + + // 创建按id值进行排序的比较器 + Comparator> orderById = (o1, o2) -> { + int id1 = (int) o1.get("id"); + int id2 = (int) o2.get("id"); + return Integer.compare(id1, id2); + }; + + private RecordSet procRs = new RecordSet(); + + ExecutorService threadPoolInstance = ThreadPoolConfig.createThreadPoolInstance(); + + private final ThemeServiceImpl themeService = new ThemeServiceImpl(); + + { + // ========================= 白名单初始化 ========================= +// departmentWhiteList = orgHrmAsyncMapper.selectCusDepart(); + departmentWhiteList = new ArrayList<>(); +// subCompanyWhiteList = orgHrmAsyncMapper.selectCusSubCompany(); + subCompanyWhiteList = new ArrayList<>(); + // ================================================================ + + // ========================= 部门&分部&岗位&用户 缓存初始化 ========================= + List> subCompany = orgHrmAsyncMapper.selectSubCompanyActive(); + subCompanyCache = OrgHrmAsyncUtil.parseListMap2Map(subCompany); + subCompanyLevelCache = OrgHrmAsyncUtil.parseListMap2Map("outkey","tlevel", subCompany); + List> department = orgHrmAsyncMapper.selectDepartmentActive(); + departmentCache = OrgHrmAsyncUtil.parseListMap2Map(department); + List> jobTitle = orgHrmAsyncMapper.selectJobTitle(); + jobTitleCache = OrgHrmAsyncUtil.parseListMap2Map("jobtitlename","id", jobTitle); + List> hrm = orgHrmAsyncMapper.selectHrmIdAndOutKey(); + hrmCache = OrgHrmAsyncUtil.parseListMap2Map(hrm); + // ======================================================================= + + maxLevel = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("maxLevel"), 3); + + // ======================部门-分部-人员 同步配置表初始化 ===================== + subCompanyConfig = orgHrmAsyncMapper.selectSubCompanyAsyncConfig(0); + if(subCompanyConfig == null || CollectionUtils.isEmpty(subCompanyConfig.get(0).getOrgHrmAsyncConfigDetailList())){ + throw new CustomerException("subCompanyConfig can not be null!"); + } + departmentConfig = orgHrmAsyncMapper.selectSubCompanyAsyncConfig(1); + if(departmentConfig == null || CollectionUtils.isEmpty(departmentConfig.get(0).getOrgHrmAsyncConfigDetailList())){ + throw new CustomerException("departmentConfig can not be null!"); + } + hrmReSourceConfig = orgHrmAsyncMapper.selectSubCompanyAsyncConfig(2); + // ======================================================================= + typeTableName.put(0, "hrmsubcompany"); + typeTableName.put(1, "hrmdepartment"); + typeTableName.put(2, "hrmresource"); + + + getNextIdTypeMap.put(0, (o)-> getNextHrmSubCompanyId()); + getNextIdTypeMap.put(1, (o)-> getNextHrmDepartmentId()); + getNextIdTypeMap.put(2, (o)-> getNextHrmId()); + + try { + comInfo = new ResourceComInfo(); + }catch (Exception e){ + log.error("init ResourceComInfo error : " + e.getMessage()); + } } + private final OrgHrmAsyncCache orgHrmAsyncCache = OrgHrmAsyncCache.builder() + .departmentCache(departmentCache) + .subCompanyCache(subCompanyCache) + .hrmCache(hrmCache) + .jobTitleCache(jobTitleCache) + .arrIndex(0) + .build(); + + @Override public List asyncDepartment() { - List departmentInfo = orgHrmAsyncApiService.getDepartmentInfo(); - //TODO 分部(条件待确认) - List subList = departmentInfo - .stream() - .filter(item -> -1 == item.getParentid()) - .sorted(Comparator.comparing(OtherSysDepartment::getId)) - .collect(Collectors.toList()); - addHrmSubCompany(subList); - - // 过滤出父节点并根据id进行升序排序 - List rootDepList = departmentInfo - .stream() - .filter(item -> 0 == item.getHasChild() && -1 != item.getParentid()) - .sorted(Comparator.comparing(OtherSysDepartment::getId)) - .collect(Collectors.toList()); - return null; } - /** - *

同步数据到分部

- * @author xuanran.wang - * @dateTime 2023/4/6 13:37 - * @param departmentList 部门数据集合 - **/ - public void addHrmSubCompany(List departmentList){ - //新增的分部id - int subId; - char separator = weaver.general.Util.getSeparator(); - RecordSet rsSch = new RecordSet(); - // 分部数据 - Map subCompany = initSubCompany(); - for (OtherSysDepartment department : departmentList) { - subId = Util.getIntValue(Util.null2DefaultStr(subCompany.get(department.getId()),""),-1); - if(subId < 0){ - String para = department.getName() + separator + department.getName() + separator + "1" + separator - + department.getId()+ separator + "" + separator +department.getOrder(); - rsSch.executeProc("HrmSubCompany_Insert", para); - if (rsSch.next()) { - subId = rsSch.getInt(1); + @Override + public synchronized List> asyncOrgDep(int type) { + if(CollectionUtils.isEmpty(asyncHrmSubCompany) || CollectionUtils.isEmpty(asyncHrmDepartment)){ + initWhiteList(); + List> departmentInfoMap = orgHrmAsyncApiService.getDepartmentInfoMap(); + // 解析成树形 + List> tree = convertListToTree(departmentInfoMap); + if(CollectionUtils.isEmpty(tree)){ + subDepIncrementDataAsync(departmentInfoMap, asyncHrmSubCompany, asyncHrmDepartment); + }else { + asyncOrDepByTree(tree,0, maxLevel, asyncHrmSubCompany, asyncHrmDepartment); + } + asyncOrgExtraData(); + } + threadPoolInstance.execute(()->{ + departmentComInfo.removeCache(); + sci.removeCompanyCache(); + }); + return type == 0 ? asyncHrmSubCompany : asyncHrmDepartment; + } + + @Override + public List> asyncHrm() { + if(CollectionUtils.isEmpty(hrmReSourceConfig) ){ + throw new CustomerException("hrmReSourceConfig can not be null!"); + } + int topLevelOutKey = Util.getIntValue(orgHrmAsyncMapper.selectTopLevelOutKey(), -1); + if(topLevelOutKey < 0){ + return new ArrayList<>(); + } + List> userInfo = orgHrmAsyncApiService.getUserInfo(topLevelOutKey); + try { + List oaCacheOutKeys = new ArrayList<>(hrmCache.keySet()); + LN ln = new LN(); + int licenseNum = ln.CkHrmnum(); + log.info("当前可用license : " + licenseNum); + log.info("当前接口数据条数 : " + userInfo.size()); + log.info("当前oa缓存outKey条数 : " + oaCacheOutKeys.size()); + if(CollectionUtils.isEmpty(oaCacheOutKeys)){ + if(licenseNum < userInfo.size()){ + log.error("当前接口条数大于可用license!本次同步跳过!"); + return new ArrayList<>(); + } + }else { + List> notContains = userInfo.stream().filter(item -> !oaCacheOutKeys.contains(Util.null2DefaultStr(item.get("id"), ""))).collect(Collectors.toList()); + log.info("接口中存在oa中不存在数据条数 : " + notContains.size()); + if(oaCacheOutKeys.size() + notContains.size() > licenseNum){ + log.error("当前接口条数+oa人员数量大于可用license!本次同步跳过!"); + return new ArrayList<>(); } } - updateTable("HrmSubCompany", subId, 0, department); + }catch (Exception e){ + log.error("校验可用license数量失败! " + e.getMessage()); } - //清除全部分部缓存 - sci.removeCompanyCache(); + addHrmResourceMap(userInfo); + List hrmExtraConfig = hrmReSourceConfig.stream() + .filter(item -> StringUtils.isNotBlank(item.getUpdateTableName()) + && !"hrmresource".equalsIgnoreCase(item.getUpdateTableName())) + .collect(Collectors.toList()); + threadPoolInstance.execute(()-> asyncExtraData(userInfo, hrmExtraConfig)); + return userInfo; + } + + /** + *

同步非树形的数据

+ * @author xuanran.wang + * @dateTime 2023/4/14 15:14 + * @param list 接口数据 + * @param hrmSubCompany 分部数据 + * @param hrmDepartment 部门数据 + **/ + public void subDepIncrementDataAsync(List> list, List> hrmSubCompany, List> hrmDepartment){ + for (Map data : list) { + int parentid = Util.getIntValue(Util.null2DefaultStr(data.get("parentid"), ""), -1); + int parentLevel = Util.getIntValue(Util.null2DefaultStr(subCompanyLevelCache.get(parentid + ""),""), -1); + data.put("msg","success!"); + String departmentId = Util.null2DefaultStr(data.get("id"),""); + // 如果分部中不存在并且父节点的层级等于最大的层级 + boolean isDep = parentLevel < 0 || parentLevel == maxLevel; + if(departmentWhiteList.contains(departmentId)){ + isDep = true; + } + if(subCompanyWhiteList.contains(departmentId)){ + isDep = false; + } + if(isDep){ + try { + addHrmDepartmentMap(Collections.singletonList(data)); + hrmDepartment.add(data); + orgHrmAsyncMapper.updateHrmSubCompanyCanceled(Collections.singletonList(departmentId)); + }catch (Exception e){ + log.error(Util.logStr("async depart error!: {}, json: \n{}",e.getMessage(),JSONObject.toJSONString(data))); + data.put("code",0); + data.put("msg","async department error! " + e.getMessage()); + } + }else { + try { + addHrmSubCompanyMap(Collections.singletonList(data)); + hrmSubCompany.add(data); + orgHrmAsyncMapper.updateHrmDepartmentCanceled(Collections.singletonList(departmentId)); + }catch (Exception e){ + log.error(Util.logStr("async depart error!: {}, json: \n{}",e.getMessage(),JSONObject.toJSONString(data))); + data.put("code",0); + data.put("msg","async department error! " + e.getMessage()); + } + } + } + } + + /** + *

处理分部与部门别的表同步数据

+ * @author xuanran.wang + * @dateTime 2023/4/14 15:17 + **/ + public void asyncOrgExtraData(){ + List subCompanyAsyncOtherConfig = subCompanyConfig.stream() + .filter(item -> StringUtils.isNotBlank(item.getUpdateTableName()) && !"hrmsubcompany".equalsIgnoreCase(item.getUpdateTableName())) + .collect(Collectors.toList()); + List departOtherAsyncConfig = subCompanyConfig.stream() + .filter(item -> StringUtils.isNotBlank(item.getUpdateTableName()) && !"hrmdepartment".equalsIgnoreCase(item.getUpdateTableName())) + .collect(Collectors.toList()); + threadPoolInstance.execute(()->{ + // 同步部门其他表数据 + asyncExtraData(asyncHrmSubCompany, subCompanyAsyncOtherConfig); + // 同步分部其他表数据 + asyncExtraData(asyncHrmDepartment, departOtherAsyncConfig); + }); + } + + + /** + *

执行自定义表数据同步

+ * @author xuanran.wang + * @dateTime 2023/4/13 13:20 + * @param data 数据 + * @param configs 同步配置 + **/ + public void asyncExtraData(List> data, List configs){ + for (OrgHrmAsyncConfigMain config : configs) { + for (Map map : data) { + String updateTableName = config.getUpdateTableName(); + String primaryKey = config.getPrimaryKey(); + String cusWhere = config.getCusWhere(); + if(StringUtils.isNotBlank(cusWhere)){ + cusWhere = Util.sbc2dbcCase(cusWhere); + } + orgHrmAsyncCache.setInterfaceVal(map); + String id = orgHrmAsyncMapper.selectCustomerSql(cusWhere, map); + Map param = OrgHrmAsyncUtil.convertInterfaceValToOA(orgHrmAsyncCache, config, false); + if(StringUtils.isNotBlank(id)){ + executeSql(updateTableName, Util.getIntValue(id, -1), param, 0, primaryKey); + }else { + executeSql(updateTableName, Util.getIntValue(id, -1), param, 1); + } + } + } + } + + /** + *

初始化配置表中部门与分部的白名单

+ * @author xuanran.wang + * @dateTime 2023/4/14 15:16 + **/ + public void initWhiteList(){ + // 解析白名单数据 + subCompanyConfig.forEach(item->{ + String cudSubCompany = item.getCudSubCompany(); + if(StringUtils.isNotBlank(cudSubCompany)){ + subCompanyWhiteList.addAll(Arrays.asList(cudSubCompany.split(","))); + } + }); + departmentConfig.forEach(item->{ + String cusDepartment = item.getCusDepartment(); + if(StringUtils.isNotBlank(cusDepartment)){ + departmentWhiteList.addAll(Arrays.asList(cusDepartment.split(","))); + } + }); + log.info("departmentWhiteList : \n" + JSONObject.toJSONString(departmentWhiteList)); + log.info("subCompanyWhiteList : \n" + JSONObject.toJSONString(subCompanyWhiteList)); + } + + + + /** + *

同步数据到分部

+ * + * @param departmentList 部门数据集合 + * @author xuanran.wang + * @dateTime 2023/4/6 13:37 + **/ + public void addHrmSubCompanyMap(List> departmentList) { + List collect = subCompanyConfig.stream().filter(item -> StringUtils.isBlank(item.getUpdateTableName())).collect(Collectors.toList()); + baseAddOrgDepByMap(departmentList, 0, subCompanyCache, collect.get(0)); } /** @@ -91,73 +384,361 @@ public class OrgHrmAsyncServiceImpl implements OrgHrmAsyncService { * @dateTime 2023/4/6 13:37 * @param departmentList 部门数据集合 **/ - public void addHrmDepartment(List departmentList){ - //新增的分部id - int id = 0; - char separator = weaver.general.Util.getSeparator(); - RecordSet rsSch = new RecordSet(); - for (OtherSysDepartment department : departmentList) { - String para = department.getName() + separator + department.getName() + separator + "1" + separator - + department.getParentid() + separator + "" + separator +department.getOrder(); - rsSch.executeProc("HrmSubCompany_Insert", para); - if (rsSch.next()) { - id = rsSch.getInt(1); - updateTable("HrmSubCompany", id, 0, department); - } - } - //清除全部分部缓存 - sci.removeCompanyCache(); + public void addHrmDepartmentMap(List> departmentList){ + List collect = departmentConfig.stream().filter(item -> StringUtils.isBlank(item.getUpdateTableName())).collect(Collectors.toList()); + baseAddOrgDepByMap(departmentList, 1, departmentCache, collect.get(0)); } /** - *

更新分部数据

+ *

同步数据到人员信息

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:37 + * @param hrmList 部门数据集合 + **/ + public void addHrmResourceMap(List> hrmList){ + List hrmAsyncConf = hrmReSourceConfig.stream() + .filter(item -> StringUtils.isBlank(item.getUpdateTableName()) || !"hrmresource".equalsIgnoreCase(item.getUpdateTableName())) + .collect(Collectors.toList()); + baseAddOrgDepByMap(hrmList, 2, hrmCache, hrmAsyncConf.get(0)); + } + + /** + *

同步数据

+ * @author xuanran.wang + * @dateTime 2023/4/12 10:36 + * @param dataList 集合 + * @param type 类型 0 分部 1 部门 + **/ + public void baseAddOrgDepByMap(List> dataList, + int type, Map cache, + OrgHrmAsyncConfigMain config){ + for (Map data : dataList) { + int interfaceId = Util.getIntValue(Util.null2DefaultStr(data.get("id"), ""), -1); + int oaId = Util.getIntValue(Util.null2DefaultStr(cache.get(interfaceId + ""),""), -1); + boolean insert = false; + // 如果不存在则需要新增 + if(oaId < 0){ + oaId = getNextIdTypeMap.get(type).apply(null); + if(oaId < 0){ + log.error("create " + typeTableName.get(type) + " id fail!"); + continue; + } + cache.put(interfaceId + "", oaId); + insert = true; + } + orgHrmAsyncCache.setInterfaceVal(data); + Map map = OrgHrmAsyncUtil.convertInterfaceValToOA(orgHrmAsyncCache, config, true); + if(insert){ + map.put("creater",1); + map.put("created", TimeUtil.getCurrentTimeString()); + } + if(type == 2 && insert){ + map.put("id", oaId); + executeSql(typeTableName.get(type), oaId, map, 1); + try { + int subcompanyid1 = Util.getIntValue(Util.null2DefaultStr(map.get("subcompanyid1"), ""), -1); + if(subcompanyid1 > 0){ + themeService.createSubCompanyMenu(oaId, subcompanyid1); + } + }catch (Exception e){ + log.error("为新员工创建默认的菜单权限 error " + e.getMessage()); + } + try { + comInfo.addResourceInfoCache(oaId + ""); + }catch (Exception e){ + log.error("添加人员缓存 error " + e.getMessage()); + } + }else { + if(type == 2){ + try { + comInfo.updateResourceInfoCache(oaId + ""); + }catch (Exception e){ + log.error("更新人员缓存 error " + e.getMessage()); + } + } + executeSql(typeTableName.get(type), oaId, map, 0); + } + if(insert){ + data.put("code", 1); + }else { + data.put("code", 2); + } + if(type == 0){ + //同步分部数据到矩阵 + MatrixUtil.updateSubcompayData(String.valueOf(oaId)); + } + } + } + + /** + *

获取下一个分部id

+ * @author xuanran.wang + * @dateTime 2023/4/12 13:25 + * @return 分部id + **/ + public int getNextHrmSubCompanyId(){ + char separator = weaver.general.Util.getSeparator(); + String uuid = UUID.randomUUID().toString(); + String para = uuid + separator + uuid + separator + "1" + separator + + 1 + separator + "" + separator + 1; + return executeProc("HrmSubCompany_Insert", para); + } + + /** + *

获取下一个部门id

+ * @author xuanran.wang + * @dateTime 2023/4/12 13:24 + * @return 部门id + **/ + public int getNextHrmDepartmentId(){ + char separator = weaver.general.Util.getSeparator(); + String uuid = UUID.randomUUID().toString(); + String para = uuid + separator +uuid + separator + + "" + separator + "" + separator + 1+ separator + 1 + separator + ""; + return executeProc("HrmDepartment_Insert", para); + } + + /** + *

获取下一个人员id

+ * @author xuanran.wang + * @dateTime 2023/4/12 13:24 + * @return 人员id + **/ + public int getNextHrmId(){ + procRs.executeProc("HrmResourceMaxId_Get", ""); + if (procRs.next()) { + return procRs.getInt(1); + } + return -1; + } + + /** + *

执行存储过程

+ * @author xuanran.wang + * @dateTime 2023/4/12 16:12 + * @param name 执行存储过程名称 + * @param para 参数 + * @return 下一个id + **/ + public int executeProc(String name, String para){ + if(procRs == null){ + procRs = new RecordSet(); + } + procRs.executeProc(name, para); + if (procRs.next()) { + return procRs.getInt(1); + } + return -1; + } + + /** + *

更新表数据

+ * + * @param tableName 表名 + * @param id 数据id + * @param params 参数 + * @param type 操作类型 0: 更新 1: 新增 * @author xuanran.wang * @dateTime 2023/4/6 13:35 - * @param tableName 表名 - * @param id 数据id - * @param type 类型 - * @param o 对象 **/ - public void updateTable(String tableName, int id, int type, Object o){ - StringBuilder sb = new StringBuilder("update "); - sb.append(tableName).append(" set "); - Map params; - try { - params = ShBigDataUtil.parseCusDbEntityMapping(type, o); - }catch (Exception e){ - throw new CustomerException("parseCusDbEntityMapping error!"); + public boolean executeSql(String tableName, int id, Map params, int type) { + return executeSql(tableName, id, params, type, "id"); + } + + /** + *

更新表数据

+ * + * @param tableName 表名 + * @param id 数据id + * @param params 参数 + * @param type 操作类型 0: 更新 1: 新增 + * @param primaryKey where主键 + * @author xuanran.wang + * @dateTime 2023/4/6 13:35 + **/ + public boolean executeSql(String tableName, int id, Map params, int type, String primaryKey) { + String operationType = "update "; + if(type == 1){ + operationType = "insert "; } + StringBuilder sqlSb = new StringBuilder(operationType) + .append(tableName) + .append(" set "); for (Map.Entry entry : params.entrySet()) { - sb.append(entry.getKey()) + sqlSb.append(entry.getKey()) .append(" = #{") .append(entry.getKey()) .append("},"); } - sb.deleteCharAt(sb.length() - 1); - sb.append(" where id = ").append(id); - boolean success = orgHrmAsyncMapper.updateSubInfo(sb.toString(), params); - if(!success){ - throw new CustomerException(Util.logStr("update {} sql error!", tableName)); + sqlSb.deleteCharAt(sqlSb.length() - 1); + if(type == 0){ + sqlSb.append(" where ") + .append(primaryKey) + .append(" = ") + .append(id); } - //同步分部数据到矩阵 - MatrixUtil.updateSubcompayData(String.valueOf(id)); + boolean success; + if(type == 1){ + success = orgHrmAsyncMapper.insertHrmInfo(sqlSb.toString(), params); + }else { + success = orgHrmAsyncMapper.updateOrgInfo(sqlSb.toString(), params); + } + if (!success) { + throw new CustomerException(operationType + tableName + " fail!"); + } + return true; } - public void setChildList(List departmentList){ - if(departmentList.size() == 0){ - return; - } - for (OtherSysDepartment department : departmentList) { - List childList = departmentList - .stream() - .filter(item -> department.getId() == item.getParentid()) - .collect(Collectors.toList()); - department.setChildList(childList); - if(CollectionUtils.isNotEmpty(childList)){ - setChildList(childList); + + /** + *

解析部门or分部

+ * + * @param list 树形集合 + * @param n 层级 + * @author xuanran.wang + * @dateTime 2023/4/10 12:13 + **/ + public void asyncOrDepByTree(List> list, int n, int maxLevel, List> hrmSubCompany, List> hrmDepartment) { + n++; + for (Map department : list) { + department.put("level", n); + List> childList = (List>) department.get("childList"); + String departmentId = Util.null2DefaultStr(department.get("id"), ""); + boolean dep = n > maxLevel; + if(departmentWhiteList.contains(departmentId)){ + dep = true; + } + if(subCompanyWhiteList.contains(departmentId)){ + dep = false; + } + department.put("msg","success!"); + if(dep){ + try { + addHrmDepartmentMap(Collections.singletonList(department)); + orgHrmAsyncMapper.updateHrmSubCompanyCanceled(Collections.singletonList(departmentId)); + }catch (Exception e){ + log.error(Util.logStr("async depart error!: {}, json: \n{}",e.getMessage(),JSONObject.toJSONString(department))); + department.put("code",0); + department.put("msg","async department error! " + e.getMessage()); + } + hrmDepartment.add(department); + }else { + try { + if(subCompanyWhiteList.contains(departmentId) && orgHrmAsyncMapper.selectDepartHasUser(departmentId) > 0){ + String error = "该部门下存在人员,无法同步成分部.本次同步不做更新请手动同步! json:\n" + JSONObject.toJSONString(department); + throw new CustomerException(error); + } + addHrmSubCompanyMap(Collections.singletonList(department)); + orgHrmAsyncMapper.updateHrmDepartmentCanceled(Collections.singletonList(departmentId)); + }catch (Exception e){ + log.error(Util.logStr("async subCompany error!: {}, json: \n{}",e.getMessage(),JSONObject.toJSONString(department))); + department.put("code",0); + department.put("msg","async subCompany error! " + e.getMessage()); + } + hrmSubCompany.add(department); + } + if (CollectionUtils.isNotEmpty(childList)) { + childList.sort(orderByOrder.thenComparing(orderById)); + List childIds = childList + .stream() + .map(item -> Util.null2DefaultStr(item.get("id"), "")) + .collect(Collectors.toList()); + if (departmentWhiteList.contains(departmentId)) { + departmentWhiteList.addAll(childIds); +// childIds.add(departmentId); +// if (!orgHrmAsyncMapper.updateHrmSubCompanyCanceled(childIds)) { +// log.error("updateHrmSubCompanyCanceled error!"); +// } + } +// else if (subCompanyWhiteList.contains(departmentId)) { +// orgHrmAsyncMapper.updateHrmDepartmentCanceled(Collections.singletonList(departmentId)); +// } + asyncOrDepByTree(childList, n, maxLevel, hrmSubCompany, hrmDepartment); + department.put("childList", new ArrayList<>()); } } } + /** + *

解析部门or分部(方法弃用)

+ * + * @param list 树形集合 + * @param n 层级 + * @param hrmSubCompany 分部 + * @param hrmDepartment 部门 + * @author xuanran.wang + * @dateTime 2023/4/10 12:13 + **/ + @Deprecated + public void parseSubCompanyAndDepartmentMap(List> list, int n, int maxLevel, List> hrmSubCompany, List> hrmDepartment) { + n++; + for (Map department : list) { + department.put("level", n); + List> childList = (List>) department.get("childList"); + String departmentId = Util.null2DefaultStr(department.get("id"), ""); + if (CollectionUtils.isNotEmpty(childList)) { + List collect = childList.stream() + .map(item -> Util.null2DefaultStr(item.get("id"), "")) + .collect(Collectors.toList()); + // 分部变成了部门则把子节点都变成部门 并将 当前数据和子数据以前是分部的全部封存 + if (departmentWhiteList.contains(departmentId)) { + departmentWhiteList.addAll(collect); + collect.add(departmentId); + if (!orgHrmAsyncMapper.updateHrmSubCompanyCanceled(collect)) { + log.error("updateHrmSubCompanyCanceled error!"); + } + } + // 如果部门变成了分部那么 把当前部门变成分部 然后把部门表中相应的数据进行封存 + else if (subCompanyWhiteList.contains(departmentId)) { +// subCompanyWhiteList.addAll(collect); + orgHrmAsyncMapper.updateHrmDepartmentCanceled(Collections.singletonList(departmentId)); + } + parseSubCompanyAndDepartmentMap(childList, n, maxLevel, hrmSubCompany, hrmDepartment); + department.put("childList", new ArrayList<>()); + } + if (n > maxLevel || departmentWhiteList.contains(departmentId)) { + hrmDepartment.add(department); + } else { + hrmSubCompany.add(department); + } + } + } + + /** + *

通过parentId将集合转成树

+ * + * @param list 接口返回集合 + * @return 树形结构 + * @author xuanran.wang + * @dateTime 2023/4/11 13:26 + **/ + public List> convertListToTree(List> list) { + Map> map = new HashMap<>(); + for (Map item : list) { + map.put((Integer) item.get("id"), item); + } + // 构建树形结构 + List> tree = new ArrayList<>(); + for (Map item : list) { + int parentId = (Integer) item.get("parentid"); + if (parentId == -1) { + // 添加根节点 + tree.add(item); + } else { + // 添加子节点 + Map parent = map.get(parentId); + if (parent != null) { + List> childList = (List>) parent.get("childList"); + if (childList == null) { + childList = new ArrayList<>(); + parent.put("childList", childList); + } + childList.add(item); + } + } + } + return tree; + } + } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/OrgHrmAsyncUtil.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/OrgHrmAsyncUtil.java new file mode 100644 index 0000000..95c2b50 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/OrgHrmAsyncUtil.java @@ -0,0 +1,102 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.util; + +import aiyh.utils.Util; +import io.swagger.models.auth.In; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import weaver.general.TimeUtil; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncCache; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigDetail; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigMain; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + *

组织架构-人员同步

+ * + * @author xuanran.wang + * @date 2023/4/11 15:48 + */ +public class OrgHrmAsyncUtil { + + /** + *

将接口数据按照建模配置转成map

+ * @author xuanran.wang + * @dateTime 2023/4/11 18:21 + * @param orgHrmAsyncCache 缓存对象 + * @param hrmAsyncConfig 建模配置对象 + * @return 参数map + **/ + public static Map convertInterfaceValToOA(OrgHrmAsyncCache orgHrmAsyncCache, OrgHrmAsyncConfigMain hrmAsyncConfig){ + return convertInterfaceValToOA(orgHrmAsyncCache, hrmAsyncConfig, false); + } + + /** + *

将接口数据按照建模配置转成map

+ * @author xuanran.wang + * @dateTime 2023/4/11 18:21 + * @param orgHrmAsyncCache 缓存对象 + * @param hrmAsyncConfig 建模配置对象 + * @return 参数map + **/ + public static Map convertInterfaceValToOA(OrgHrmAsyncCache orgHrmAsyncCache, OrgHrmAsyncConfigMain hrmAsyncConfig, boolean addSystemParam){ + List configDetailList = hrmAsyncConfig.getOrgHrmAsyncConfigDetailList(); + LinkedHashMap res = new LinkedHashMap<>(); + for (OrgHrmAsyncConfigDetail detail : configDetailList) { + String oaField = detail.getOaField(); + Object value = ValueRuleMethod.VALUE_RULE_FUNCTION.get(detail.getConvertType()).apply(detail, orgHrmAsyncCache); + int fieldType = detail.getFieldType(); + if(0 == fieldType){ + value = Util.null2DefaultStr(value, ""); + }else { + value = Util.getIntValue(Util.null2DefaultStr(value, ""),0); + } + res.put(oaField, value); + } + if(addSystemParam){ + addSysParam(res); + } + return res; + } + + /** + *

将集合数据放到缓存中

+ * @author xuanran.wang + * @dateTime 2023/4/10 18:33 + * @param listMap 集合数据 + **/ + public static HashMap parseListMap2Map( List> listMap){ + return parseListMap2Map("outkey","id", listMap); + } + + /** + *

将集合数据放到缓存中

+ * @author xuanran.wang + * @dateTime 2023/4/10 18:33 + * @param listMap 集合数据 + **/ + public static HashMap parseListMap2Map(String key, String value, List> listMap){ + if(CollectionUtils.isEmpty(listMap)){ + return new HashMap<>(); + } + HashMap res = new HashMap<>(); + listMap.forEach(map -> { + String outKey = Util.null2DefaultStr(map.get(key),""); + if(StringUtils.isNotBlank(outKey)){ + int id = Util.getIntValue(Util.null2DefaultStr(map.get(value),""),-1); + res.put(outKey, id); + } + }); + return res; + } + + public static void addSysParam(Map res){ + String dateTime = TimeUtil.getCurrentTimeString(); + res.put("modifier", 1); + res.put("modified", dateTime); + } + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/ValueRuleMethod.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/ValueRuleMethod.java new file mode 100644 index 0000000..ed69837 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/ValueRuleMethod.java @@ -0,0 +1,178 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import com.google.common.base.Strings; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.general.TimeUtil; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations.CusOrgHrmAsyncConvert; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncCache; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigDetail; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.mapper.OrgHrmAsyncMapper; +import weaver.youhong.ai.haripijiu.action.sapdocking.config.mapper.SapConfigMapper; +import weaver.youhong.ai.haripijiu.action.sapdocking.config.pojo.SapConfigDetail; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; +import java.util.function.BiFunction; + +/** + *

值处理方法

+ * + *

create: 2023-02-02 15:15

+ * + * @author youHong.ai + */ + +public class ValueRuleMethod { + + + public static final Map> VALUE_RULE_FUNCTION = new HashMap<>(); + + private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class); + + private final Logger log = Util.getLogger(); + + static { + Class valueRuleMethodClass = ValueRuleMethod.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, (OrgHrmAsyncConfigDetail, orgHrmAsyncCache) -> { + try { + ValueRuleMethod valueRuleMethod = new ValueRuleMethod(); + return method.invoke(valueRuleMethod, OrgHrmAsyncConfigDetail, orgHrmAsyncCache); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }); + } + } + } + + @ValueRuleMethodNo(value = 0, desc = "不转换") + public Object getFixValue(OrgHrmAsyncConfigDetail configDetail,OrgHrmAsyncCache cache) { + return cache.getInterfaceVal().get(configDetail.getInterfaceField()); + } + + + @ValueRuleMethodNo(value = 1, desc = "默认值") + public Object getCusText(OrgHrmAsyncConfigDetail configDetail, OrgHrmAsyncCache cache) { + return configDetail.getCusText(); + } + + + @ValueRuleMethodNo(value = 2, desc = "自定义sql") + public Object getCustomerSqlValue(OrgHrmAsyncConfigDetail configDetail, OrgHrmAsyncCache cache) { + Map interfaceVal = cache.getInterfaceVal(); + String cusText = configDetail.getCusText(); + cusText = Util.sbc2dbcCase(cusText); + if (Strings.isNullOrEmpty(cusText)) { + return null; + } + if (!cusText.startsWith("select")) { + return null; + } + // 接口字段值判断 + String interfaceField = configDetail.getInterfaceField(); + String interfaceFieldVal = Util.null2DefaultStr(interfaceVal.get(interfaceField),""); + if(StringUtils.isBlank(interfaceFieldVal)){ + return ""; + } + Object val = interfaceVal.get(configDetail.getInterfaceField()); + // 如果接口参数是集合则转成'1,2'形式 放到参数中 + if(val instanceof List && ((List) val).size() > 0){ + ArrayList temp = new ArrayList<>(); + for (int i = 0; i < ((List) val).size(); i++) { + interfaceVal.put(interfaceField + "_" + i, ((List) val).get(i)); + temp.add("'" + ((List) val).get(i) + "'"); + } + interfaceVal.put(interfaceField,StringUtils.join(temp,",")); + } + String oaField = configDetail.getOaField(); + // 先从缓存中找数据 + int cacheVal = convertFromCache(interfaceVal, cache, oaField, interfaceFieldVal); + if(cacheVal > 0){ + return cacheVal; + } + if(StringUtils.isNotBlank(interfaceFieldVal)){ + cusText = cusText.replace("?", interfaceFieldVal); + } + List strings = orgHrmAsyncMapper.selectCustomerSqlArr(cusText, interfaceVal); + if(CollectionUtils.isNotEmpty(strings)){ + return StringUtils.join(strings,","); + } + return ""; + } + + @ValueRuleMethodNo(value = 3, desc = "自定义接口") + public Object getCusConvertInterface(OrgHrmAsyncConfigDetail configDetail, OrgHrmAsyncCache cache) { + String cusText = configDetail.getCusText(); + if(Strings.isNullOrEmpty(cusText)){ + return null; + } + try { + Class clazz = Class.forName(cusText); + if(!CusOrgHrmAsyncConvert.class.isAssignableFrom(clazz)){ + throw new CustomerException(cusText + " not implements weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations.CusOrgHrmAsyncConvert"); + } + CusOrgHrmAsyncConvert o = (CusOrgHrmAsyncConvert) clazz.newInstance(); + Map pathParam = Util.parseCusInterfacePathParam(cusText); + return o.cusConvert(configDetail, cache, pathParam); + }catch (Exception e){ + log.error("getCusConvertInterface error! " + e.getMessage()); + return null; + } + } + + /** + *

从缓存中找数据

+ * @author xuanran.wang + * @dateTime 2023/4/13 13:44 + * @param interfaceVal 接口参数map + * @param cache 缓存对象 + * @param oaField oa字段名 + * @param interfaceFieldVal 接口参数值 + * @return 数据id + **/ + public int convertFromCache(Map interfaceVal, OrgHrmAsyncCache cache, String oaField, String interfaceFieldVal){ + Map subCompanyCache = cache.getSubCompanyCache(); + Map departmentCache = cache.getDepartmentCache(); + Integer value = Util.getIntValue(Util.null2DefaultStr(interfaceVal.get("parentid"), ""),-1); + // 特殊处理 先从缓存中拿如果缓存中没有在执行sql + if("subcompanyid1".equalsIgnoreCase(oaField) || "supsubcomid".equalsIgnoreCase(oaField)){ + value = subCompanyCache.get(value + ""); + } else if("supdepId".equalsIgnoreCase(oaField)){ + value = departmentCache.get(value + ""); + } + if("jobtitle".equalsIgnoreCase(oaField)){ + Map jobTitleCache = cache.getJobTitleCache(); + value = Util.getIntValue(Util.null2DefaultStr(jobTitleCache.get(interfaceFieldVal), ""), -1); + if(value < 0){ + interfaceVal.put("jobCreateTime", TimeUtil.getCurrentTimeString()); + boolean success = orgHrmAsyncMapper.insertJobTitle(interfaceVal); + if(!success){ + log.error("insertJobTitle fail!"); + } + int id = Util.getIntValue(orgHrmAsyncMapper.selectJobTitleByName(interfaceFieldVal), -1); + if(id > 0){ + jobTitleCache.put(interfaceFieldVal, id); + } + } + } + + if(!Objects.isNull(value) && value > 0){ + return value; + } + + return -1; + } + + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/ValueRuleMethodNo.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/ValueRuleMethodNo.java new file mode 100644 index 0000000..80179bb --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/util/ValueRuleMethodNo.java @@ -0,0 +1,19 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_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/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTask.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTask.java index a69e3e9..311a790 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTask.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTask.java @@ -19,5 +19,5 @@ public class CusDoneTask { @SqlFieldMapping private String taskNum; private int status; - private String appId; + private String agentid; } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTask.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTask.java index fe8a8a8..1337e35 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTask.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTask.java @@ -18,7 +18,7 @@ import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField; public class CusTodoTask { @SqlFieldMapping protected String taskNum; - protected String appId; + protected String agentid; @SqlFieldMapping protected String taskName; protected String taskDesc; diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/impl/SendTodoTaskServiceImpl.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/impl/SendTodoTaskServiceImpl.java index 748848b..581cd14 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/impl/SendTodoTaskServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/impl/SendTodoTaskServiceImpl.java @@ -33,7 +33,6 @@ import java.util.*; @Data public class SendTodoTaskServiceImpl implements SendTodoTaskService { private final Logger log = Util.getLogger(); - private String appId; private final SendTodoTaskUtil sendTodoTaskUtil = new SendTodoTaskUtil(); private String addTodoTaskUrl; private String updateTodoTaskUrl; @@ -45,7 +44,7 @@ public class SendTodoTaskServiceImpl implements SendTodoTaskService { { - sendTodoTaskUtil.setAppId(ShBigDataUtil.getPropertiesValByKey("appId")); + sendTodoTaskUtil.setAgentId(ShBigDataUtil.getPropertiesValByKey("agentId")); modelId = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("modelId"),-1); addTodoTaskUrl = ShBigDataUtil.getPropertiesValByKey("addTodoTaskUrl"); updateTodoTaskUrl = ShBigDataUtil.getPropertiesValByKey("updateTodoTaskUrl"); diff --git a/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/StudentClass.java b/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/StudentClass.java index 914d78b..7f4fef0 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/StudentClass.java +++ b/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/StudentClass.java @@ -33,4 +33,6 @@ public class StudentClass { **/ @SqlFieldMapping() private int belongYear; + @SqlFieldMapping() + private String teacherId; } diff --git a/src/main/java/weaver/xuanran/wang/shyl/dataasync/job/CusDataAsyncJob.java b/src/main/java/weaver/xuanran/wang/shyl/dataasync/job/CusDataAsyncJob.java index 4778f42..52fd9b0 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/dataasync/job/CusDataAsyncJob.java +++ b/src/main/java/weaver/xuanran/wang/shyl/dataasync/job/CusDataAsyncJob.java @@ -2,13 +2,12 @@ package weaver.xuanran.wang.shyl.dataasync.job; import aiyh.utils.Util; import lombok.Data; +import lombok.EqualsAndHashCode; import org.apache.log4j.Logger; import weaver.interfaces.schedule.BaseCronJob; import weaver.xuanran.wang.common.annocation.ParamNotNull; import weaver.xuanran.wang.common.annocation.ParamPrint; import weaver.xuanran.wang.common.util.CommonUtil; -import weaver.xuanran.wang.shyl.dataasync.entity.Student; -import weaver.xuanran.wang.shyl.dataasync.entity.StudentClass; import weaver.xuanran.wang.shyl.dataasync.service.CusDataAsyncService; import java.util.HashMap; @@ -19,7 +18,6 @@ import java.util.HashMap; * @author xuanran.wang * @date 2023/2/9 10:02 */ -@Data public class CusDataAsyncJob extends BaseCronJob { /** @@ -63,18 +61,42 @@ public class CusDataAsyncJob extends BaseCronJob { private final CusDataAsyncService dataAsyncService = new CusDataAsyncService(); -// private final Logger logger = Util.getLogger(); + private final Logger logger = Util.getLogger(); @Override public void execute() { try { CommonUtil.checkParamNotNull(this); // 数据同步 - dataAsyncService.asyncData(baseAddr + queryClassUrl, classModelId, StudentClass.class, updateClassSql,"data"); + dataAsyncService.asyncData(baseAddr + queryClassUrl, classModelId, updateClassSql,"data"); }catch (Exception e){ -// logger.error(Util.logStr("CusDataAsyncJob execute error! the error is :{}, " + -// "error stack trace msg is: \n{}", e.getMessage(), Util.getErrString(e))); + logger.error(Util.logStr("CusDataAsyncJob execute error! the error is :{}, " + + "error stack trace msg is: \n{}", e.getMessage(), Util.getErrString(e))); } } + + public String getBaseAddr() { + return baseAddr; + } + + public void setBaseAddr(String baseAddr) { + this.baseAddr = baseAddr; + } + + public String getQueryClassUrl() { + return queryClassUrl; + } + + public void setQueryClassUrl(String queryClassUrl) { + this.queryClassUrl = queryClassUrl; + } + + public String getClassModelId() { + return classModelId; + } + + public void setClassModelId(String classModelId) { + this.classModelId = classModelId; + } } diff --git a/src/main/java/weaver/xuanran/wang/shyl/dataasync/service/CusDataAsyncService.java b/src/main/java/weaver/xuanran/wang/shyl/dataasync/service/CusDataAsyncService.java index 91be9a6..8533560 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/dataasync/service/CusDataAsyncService.java +++ b/src/main/java/weaver/xuanran/wang/shyl/dataasync/service/CusDataAsyncService.java @@ -11,7 +11,9 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; +import weaver.conn.RecordSet; import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import weaver.xuanran.wang.shyl.dataasync.entity.StudentClass; import javax.ws.rs.core.MediaType; import java.io.IOException; @@ -59,13 +61,49 @@ public class CusDataAsyncService { return; } ArrayList dataList = new ArrayList<>(); + ArrayList ids = new ArrayList<>(); for (Object o : array) { Object temp = JSONObject.parseObject(o.toString(), clazz); dataList.add(temp); + } CusInfoToOAUtil.executeBatchByEntity(Util.getIntValue(modelId, -1), dataList, updateSql); } + /** + *

数据同步

+ * @author xuanran.wang + * @dateTime 2023/2/9 10:10 + * @param url 请求地址 + * @param modelId 建模模块id + * @param updateSql 建模更新数据sql + **/ + public void asyncData(String url, String modelId, String updateSql, String key){ + Object data = getResponseDataByGet(url, new HashMap<>(), new HashMap<>(), key); + JSONArray array = JSONObject.parseArray(JSONObject.toJSONString(data)); + log.info("data : " + array); + if(CollectionUtils.isEmpty(array)){ + log.error("array is empty!"); + return; + } + ArrayList dataList = new ArrayList<>(); + ArrayList ids = new ArrayList<>(); + for (Object o : array) { + StudentClass temp = JSONObject.parseObject(o.toString(), StudentClass.class); + dataList.add(temp); + ids.add("'" + temp.getId() + "'"); + } + CusInfoToOAUtil.executeBatchByEntity(Util.getIntValue(modelId, -1), dataList, updateSql); + RecordSet updateRs = new RecordSet(); + if(CollectionUtils.isNotEmpty(ids)){ + String updateDelStatus = "update " + CusInfoToOAUtil.checkModelId(Util.getIntValue(modelId, -1)) + " set delStatus = 1 where " + + weaver.general.Util.getSubINClause(StringUtils.join(ids,","),"classId","not in"); + if (!updateRs.executeUpdate(updateDelStatus)) { + throw new CustomerException("更新删除状态失败!"); + } + } + } + /** *

获取token

* @author xuanran.wang diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/mapper/ConsumerMapper.java b/src/main/java/weaver/xuanran/wang/shyl_mq/mapper/ConsumerMapper.java index e1ec671..af8f3f8 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/mapper/ConsumerMapper.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/mapper/ConsumerMapper.java @@ -50,7 +50,7 @@ public interface ConsumerMapper { * @param outKey 外部系统id * @return map key : id, val : 分部id **/ - @Select("select id departmentId, subcompanyid1 subCompanyId from hrmdepartment where outkey = #{outKey} and canceled != 1") + @Select("select id departmentId, subcompanyid1 subCompanyId from hrmdepartment where outkey = #{outKey} and ifnull(canceled,0) <> 1") Map getDepInfoByOutKey(@ParamMapper("outKey") String outKey); /** @@ -70,7 +70,7 @@ public interface ConsumerMapper { * @param outKey 外部系统id * @return id **/ - @Select("select id from hrmdepartment where outkey = #{outKey} and canceled != 1") + @Select("select id from hrmdepartment where outkey = #{outKey} and ifnull(canceled,0) <> 1") String getDepIdByOutKey(@ParamMapper("outKey") String outKey); /** diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/OrgServiceImpl.java b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/OrgServiceImpl.java index ddbf9e1..8b8f306 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/OrgServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/OrgServiceImpl.java @@ -42,7 +42,7 @@ public class OrgServiceImpl extends CusInfoActionService { **/ @Override public ConsumeConcurrentlyStatus cusCreateAction(MQMessage message) { - int depId = 0; + int depId; try { String content = message.getContent(); Org org = JSONObject.parseObject(content, Org.class); diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java b/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java index c6b564d..3227443 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java @@ -122,6 +122,7 @@ public class RocketConsumerUtil { log.error(Util.logStr("MQMessageId: {}, Already consumed!",mqMessageId)); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } + log.info("mqMessage : " + JSONObject.toJSONString(mqMessage)); // 业务类型 String actionType = mqMessage.getActionType(); switch (actionType){ diff --git a/src/main/resources/WEB-INF/prop/prop2map/ShBigdataConf.properties b/src/main/resources/WEB-INF/prop/prop2map/ShBigdataConf.properties index 448dd3f..e78577d 100644 --- a/src/main/resources/WEB-INF/prop/prop2map/ShBigdataConf.properties +++ b/src/main/resources/WEB-INF/prop/prop2map/ShBigdataConf.properties @@ -1,24 +1,54 @@ -# ??????? +# 应用的凭证密钥 corpSecret=5eab6957b4944d75acfa9cfcc8feff5a agentId=10000060 corpId=wwdbb6b075752cc1b9 -# ??token??? +# 获取token的地址 tokenUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/gettoken -# ?????? +# 人员信息接口 userInfoUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/user/get -# ?????? +# 部门信息接口 departmentInfoUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/department/list -# ?????? +# 新增待办接口 addTodoTaskUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/task/create -# ?????? +# 更新待办接口 updateTodoTaskUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/task/update -# ?????????appId +# 新增待办接口的appId appId=wwdbb6b075752cc1b9 -# ????????????ID +# 统一待办推送日志记录模块ID modelId=112 -# ???????????sql ????????outkey ??sql?? select outkey from hrmresource where id in (${ids}) ?? +# 新增待办接口发送人转换sql 如果后面要改成传outkey 则将sql改为 select outkey from hrmresource where id in (${ids}) 即可 hrmSenderConvertRuleSql=select lastname from hrmresource where id in (${ids}) -# ????? +# 与上面同理 hrmReceiveConvertRuleSql=select lastname from hrmresource where id in (${ids}) -# oa token?????????? -expiryBeforeTime=5 \ No newline at end of file +# 统一待办pc端链接地址 +taskPcUrl= +# 统一待办移动端链接地址 +taskMobileUrl= +# oa token缓存对象提前过期时间 +expiryBeforeTime=5 + +# ================ 组织架构同步新增 ================ +# 分部最大的层级 +maxLevel=3 +# 组织结架构同步时是否递归获取 0递归 1非递归 +orgNoFetchChild=0 +# 组织结架构同步时同步增量数据 0 全量 1增量 +orgUpdateTime=0 +# 人员同步时同步增量数据 0 全量 1增量 +hrmUpdateTime=0 +# 组织架构同步日志模块id +orgHrmAsyncLogModelId=115 + + +# ================ sso ================ +# 根据code获取用户信息接口地址 +getUserInfoByCodeUrl= +# 人员校验成功后oa跳转地址 +loginSuccessSendRedirectUrl=/wui/index.html#/main +# 人员校验失败后oa跳转地址 +loginErrorSendRedirectUrl=/login/login.jsp +#debug +getUserIdDebug= +#debug key +getUserIdDebugOutKey= + diff --git a/src/test/java/xuanran/wang/big_data/BigDataTest.java b/src/test/java/xuanran/wang/big_data/BigDataTest.java new file mode 100644 index 0000000..fb032cb --- /dev/null +++ b/src/test/java/xuanran/wang/big_data/BigDataTest.java @@ -0,0 +1,400 @@ +package xuanran.wang.big_data; + +import aiyh.utils.Util; +import basetest.BaseTest; +import com.alibaba.fastjson.JSONObject; +import com.icbc.api.internal.apache.http.impl.cookie.S; +import com.weaver.esb.server.cache.ResourceComInfo; +import emo.macro.ob.OB; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import weaver.email.EmailWorkRunnable; +import weaver.general.TimeUtil; +import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.OrganizationHrmSyncFromOtherSys; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigMain; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.mapper.OrgHrmAsyncMapper; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncApiService; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl.OrgHrmAsyncApiServiceImpl; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl.OrgHrmAsyncServiceImpl; + +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/4/10 10:49 + */ +public class BigDataTest extends BaseTest { + private final OrgHrmAsyncServiceImpl orgHrmAsyncService = new OrgHrmAsyncServiceImpl(); + private final OrgHrmAsyncApiService orgHrmAsyncApiService = new OrgHrmAsyncApiServiceImpl(); + private final List departmentWhiteList; + private final List subCompanyWhiteList; + private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class); + + { + departmentWhiteList = orgHrmAsyncMapper.selectCusDepart(); + subCompanyWhiteList = orgHrmAsyncMapper.selectCusSubCompany(); + } + + @Test + public void testA() throws IOException { +// List rootDepList = departmentInfo +// .stream() +// .filter(item -> 1 == item.getHasChild()) +// .sorted(Comparator.comparing(OtherSysDepartment::getId)) +// .collect(Collectors.toList()); +// for (OtherSysDepartment department : rootDepList) { +// setChildList(department, departmentInfo); +// } +// List departmentInfo = orgHrmAsyncApiService.getDepartmentInfo(); +// List convert = Util.listToTree(departmentInfo, +// OtherSysDepartment::getId, OtherSysDepartment::getParentid, +// OtherSysDepartment::getChildList, OtherSysDepartment::setChildList, +// parentid -> parentid == -1); +// System.out.println("convert => " + JSONObject.toJSONString(convert, SerializerFeature.DisableCircularReferenceDetect)); +// List hrmSubCompany = new ArrayList<>(); +// List hrmDepartment = new ArrayList<>(); +// int maxLevel = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("maxLevel"), 3); +// System.out.println(countNodes(convert.get(0))); +// parseSubCompanyAndDepartment(convert, 0,maxLevel, hrmSubCompany, hrmDepartment); +// parseSubCompanyAndDepartment(convert, hrmSubCompany); +// System.out.println("hrmSubCompany => " + hrmSubCompany.size()); +// System.out.println("convertLevel => " + JSONObject.toJSONString(convert, SerializerFeature.DisableCircularReferenceDetect)); +// System.out.println("hrmSubCompany => " + JSONObject.toJSONString(hrmSubCompany)); +// System.out.println("hrmDepartment => " + JSONObject.toJSONString(hrmDepartment)); +// orgHrmAsyncService.asyncDepartment(); + Map res = JSONObject.parseObject("{\n" + + "\t\t\"code\":0,\n" + + "\t\t\"msg\":\"ok\",\n" + + "\t\t\"data\":{\n" + + "\t\t\t\"UserId\":\"13800000000\",\n" + + "\t\t\t\"errcode\":0,\n" + + "\t\t\t\"errmsg\":\"ok\",\n" + + "\t\t\t\"id\":109,\n" + + "\t\t\t\"userid\":\"13800000000\",\n" + + "\t\t\t\"name\":\"祝芳\",\n" + + "\t\t\t\"mobile\":\"13800000000\",\n" + + "\t\t\t\"gender\":1,\n" + + "\t\t\t\"department\":[\n" + + "\t\t\t\t539\n" + + "\t\t\t],\n" + + "\t\t\t\"order\":[\n" + + "\t\t\t\t6\n" + + "\t\t\t]\n" + + "\t\t}\n" + + "\t}", Map.class); + System.out.println(getRes(res)); + } + + public String getRes(Map res){ + return (String) parseRes(res, cusSuccess); + } + + private final CusSuccess cusSuccess = CusSuccess.builder() + .successField("code") + .successValue(0) + .errorMsg("msg") + .dataKey("data.id") + .build(); + + public T parseRes(Map response, CusSuccess cusSuccess){ + String[] split = Util.null2DefaultStr(cusSuccess.getDataKey(),"").split("\\."); + int len = split.length; + if(len == 0 || StringUtils.isBlank(cusSuccess.getDataKey())){ + return (T)response; + } + for (int i = 0; i < len - 1; i++) { + response = (Map) response.get(split[i]); + } + return (T) response.get(split[len - 1]); + } + + @Test + public void testMap(){ + List> list = orgHrmAsyncApiService.getDepartmentInfoMap(); + // 将列表转换为以id为键的Map + List> tree = convertListToTree(list); + List> department = new ArrayList<>(); + List> subCompany = new ArrayList<>(); + orgHrmAsyncService.parseSubCompanyAndDepartmentMap(tree, 0, 3, department, subCompany); + System.out.println(JSONObject.toJSONString(department)); + System.out.println(JSONObject.toJSONString(subCompany)); + } + + @Test + public void testMapper(){ +// System.setProperty("_isDebug", "false"); +// System.out.println("分部执行结果 => " + JSONObject.toJSONString(orgHrmAsyncService.asyncOrgDep(0))); +// System.out.println("部门执行结果 => " + JSONObject.toJSONString(orgHrmAsyncService.asyncOrgDep(1))); +// List orgHrmAsyncConfigMains = orgHrmAsyncMapper.selectSubCompanyAsyncConfig(2); +// System.out.println(JSONObject.toJSONString(orgHrmAsyncConfigMains)); + ArrayList ids = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + ids.add("'" + UUID.randomUUID().toString().replace("-","") + "'"); + } + String updateDelStatus = "update cus_fielddata set field0 = 1 where " + + weaver.general.Util.getSubINClause(StringUtils.join(ids,","),"field2","not in"); + System.out.println(updateDelStatus); + } + + @Test + public void testAsync(){ + System.out.println(TimeUtil.getCurrentTimeString()); + OrganizationHrmSyncFromOtherSys async = new OrganizationHrmSyncFromOtherSys(); + async.SynTimingToOASubCompany(); + async.SynTimingToOADepartment(); + HashMap synResult = async.getSynResult(); + System.out.println("res => \n" + JSONObject.toJSONString(synResult)); + System.out.println(TimeUtil.getCurrentTimeString()); + } + + @Test + public void testExtra(){ + orgHrmAsyncService.asyncHrm(); + } + + public List> convertListToTree(List> list){ + Map> map = new HashMap<>(); + for (Map item : list) { + map.put((Integer) item.get("id"), item); + } + + // 构建树形结构 + List> tree = new ArrayList<>(); + for (Map item : list) { + int parentId = (Integer) item.get("parentid"); + if (parentId == -1) { + // 添加根节点 + tree.add(item); + } else { + // 添加子节点 + Map parent = map.get(parentId); + if (parent != null) { + List> childList = (List>) parent.get("childList"); + if (childList == null) { + childList = new ArrayList<>(); + parent.put("childList", childList); + } + childList.add(item); + } + } + } + return tree; + } + public int countNodes(OtherSysDepartment node) { + int count = 1; // 当前节点也算一条数据 + List childList = node.getChildList(); + if (CollectionUtils.isNotEmpty(childList)) { + for (OtherSysDepartment otherSysDepartment : childList) { + count += countNodes(otherSysDepartment); + } + } + return count; + } + + public int countNodes(Map node) { + int count = 1; // 当前节点也算一条数据 + List> childList = (List>) node.get("childList"); + if (CollectionUtils.isNotEmpty(childList)) { + for (Map map : childList) { + count += countNodes(map); + } + } + return count; + } + + + /** + *

解析部门or分部

+ * @author xuanran.wang + * @dateTime 2023/4/10 12:13 + * @param list 树形集合 + * @param hrmDepartment 部门 + **/ + public void parseSubCompanyAndDepartment(List list, List hrmDepartment){ + for (OtherSysDepartment department : list) { + List childList = department.getChildList(); + if(CollectionUtils.isNotEmpty(childList)){ + parseSubCompanyAndDepartment(childList,hrmDepartment); + department.setChildList(null); + } + hrmDepartment.add(department); + } + } + + + /** + *

解析部门or分部

+ * @author xuanran.wang + * @dateTime 2023/4/10 12:13 + * @param list 树形集合 + * @param n 层级 + * @param hrmSubCompany 分部 + * @param hrmDepartment 部门 + **/ + public void parseSubCompanyAndDepartment(List list, int n, int maxLevel,List hrmSubCompany, List hrmDepartment){ + n++; + for (OtherSysDepartment department : list) { + department.setLevel(n); + List childList = department.getChildList(); + String departmentId = department.getId() + ""; + if(CollectionUtils.isNotEmpty(childList)){ + List collect = department.getChildList().stream().map(item -> Util.null2DefaultStr(item.getId(), "")).collect(Collectors.toList()); + if(departmentWhiteList.contains(departmentId)){ + departmentWhiteList.addAll(collect); + }else if(subCompanyWhiteList.contains(departmentId)){ + subCompanyWhiteList.addAll(collect); + } + parseSubCompanyAndDepartment(childList, n, maxLevel, hrmSubCompany, hrmDepartment); + department.setChildList(null); + } + if(n > maxLevel || departmentWhiteList.contains(departmentId)){ + hrmDepartment.add(department); + }else { + hrmSubCompany.add(department); + } + + } + } + + @Test + public void testParseObj(){ + String json = "{\n" + + " \"code\":0,\n" + + " \"msg\":\"ok\",\n" + + " \"data\":\n" + + " {\n" + + " \"errcode\": 0,\n" + + " \"errmsg\": \"ok\",\n" + + " \"id\": \"1\",\n" + + " \"userid\": \"superAdmin\",\n" + + " \"name\": \"超级管理员\",\n" + + " \"mobile\":\"12345678911\",\n" + + " \"email\":\"123@321.com\",\n" + + " \"gender\":0,\n" + + " \"position\":\"position\",\n" + + " \"avatarImg\":\"avatarImg\",\n" + + " \"workPhone\":\"workPhone\",\n" + + " \"fixedTelephone\":\"fixedTelephone\",\n" + + " \"extName\":\"extName\",\n" + + " \"userType\":0,\n" + + " \"department\": [\n" + + " 1\n" + + " ],\n" + + " \"order\": [\n" + + " 0\n" + + " ],\n" + + " \"rank\":\"rank\"\n" + + " }\n" + + "}"; + Map response = JSONObject.parseObject(json, Map.class); + String obj = Util.null2DefaultStr(getObj("data.id", response),""); + System.out.println("obj => " + obj); + } + + public T getObj(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]); + } + + @Test + public void testMsg(){ + String html = "\n" + + "\n" + + "\n" + + "\tInvestment Calculator\n" + + "\t\n" + + "\n" + + "\n" + + "\t\n" + + "\t\t\n" + + "\t\t\t\n" + + "\t\t\n" + + "\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\n" + + "\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\t\n" + + "\t\t\n" + + "\t\t\n" + + " \t
投资试算(场外基金)
ABCDEFGHIJKLM
Cell A1Cell B1Cell C1Cell D1Cell E1Cell F1Cell G1Cell H1Cell I1Cell J1Cell K1Cell L1Cell M1
\n" + + " \n" + + "\n"; + EmailWorkRunnable.threadModeReminder("3055088966@qq.com,xuanran.wang@weaver.com.cn", "test11", html); + + } + + @Test + public void testG(){ +// String sql =" select case '$t{test1}' when '03' then '场外基金' when '04' then '基金赎回' else '测试下' end"; +// HashMap param = new HashMap<>(); +// param.put("test1","04"); +// String s = orgHrmAsyncMapper.selectCustomerSql(sql, param); +// System.out.println("s => " + s); + HashMap map = new HashMap<>(); + map.put("tiem", new Date()); + System.out.println("map => " + JSONObject.toJSONString(map)); + } +} diff --git a/src/test/java/xuanran/wang/cssc/FileTest.java b/src/test/java/xuanran/wang/cssc/FileTest.java new file mode 100644 index 0000000..4d558da --- /dev/null +++ b/src/test/java/xuanran/wang/cssc/FileTest.java @@ -0,0 +1,204 @@ +package xuanran.wang.cssc; + +import aiyh.utils.excention.CustomerException; +import basetest.BaseTest; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import weaver.general.Util; +import weaver.xuanran.wang.cssc.cms.entity.CusSuccess; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.*; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/4/26 13:30 + */ +public class FileTest extends BaseTest { + @Test + public void testA(){ +// compressToZip("/Users/wangxuanran/company/test/1231233","/Users/wangxuanran/company/test/1231233","test.zip"); + try { +// File file = new File("/Users/wangxuanran/company/test/1231233/test.zip"); +// long length = file.length(); +// System.out.println("length => " + length); +// String md5 = DigestUtils.md5Hex(Files.newInputStream(Paths.get("/Users/wangxuanran/company/test/1231233/test.zip"))); +// String fileName = "hfsh.txt"; +// System.out.println(fileName.substring(fileName.lastIndexOf(".") + 1)); +// System.out.println("md5 => " + md5); +// System.out.println(System.currentTimeMillis()); + +// String xml = "\n" + +// "\n" + +// "\t\n" + +// "\t\tEIPPACK\t\t\n" + +// "\t\tP-TC____-20190821144756-1 \n" + +// "\t\tTC \n" + +// "\t\tTC \n" + +// "\t\t主机厂文件 \n" + +// "\t\t1 \n" + +// "\t\n" + +// "\t\n" + +// "\t\t \n" + +// "\t\t\t<公司代码>1001\n" + +// "\t\t\t<流程id>2341234123j8jhsu\n" + +// "\t\t\t<题名>我是用来测试归档接口123\n" + +// "\t\t\t<文号>[xin]129号\n" + +// "\t\t\t<成文日期>20230301\n" + +// "\t\t\t<主机厂名称>红旗\n" + +// "\t\t\n" + +// "\t\t \n" + +// "\t\t\t\n" + +// "\t\t\t\t1.pdf \n" + +// "\t\t\t\tOA审批结果 \n" + +// "\t\t\t\t81098 \n" + +// "\t\t\t\t20190821144756 \n" + +// "\t\t\t\t05cc9c29599ae67cf545fe380d679326 \n" + +// "\t\t\t\tpdf \n" + +// "\t\t\t\t1.pdf\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\t1.pdf \n" + +// "\t\t\t\tOA审批结果 \n" + +// "\t\t\t\t81098 \n" + +// "\t\t\t\t20190821144756 \n" + +// "\t\t\t\t05cc9c29599ae67cf545fe380d679326 \n" + +// "\t\t\t\tpdf \n" + +// "\t\t\t\t1.pdf\n" + +// "\t\t\t\n" + +// "\t\t\n" + +// "\t\n" + +// "\n"; +// FileWriter fileWriter; +// try +// { +// fileWriter = new FileWriter("/Users/wangxuanran/company/test/1231233/test.xml", false); +// fileWriter.write(xml); +// fileWriter.flush(); +// fileWriter.close(); +// } catch (IOException e) +// { +// e.printStackTrace(); +// } + //按changerule排序 +// HashMap map = new HashMap<>(); +// map.put("success", false); +// HashMap token = new HashMap<>(); +// token.put("asscess", "121223213213"); +// map.put("result", token); +// map.put("error","报错了!!!!"); +// +// CusSuccess build = CusSuccess.builder().successField("success").successValue("true").errorMsg("error").dataKey("result.asscess").build(); +// Object response = getResponse(build, map); +// System.out.println("response => " + response ); + + String str = ",w1,w2,we"; + System.out.println(str.substring(1)); + testC("1"); + }catch (Exception e){ + + log.error("e => " + e.getMessage()); + } + } + + public void testC(String type){ + switch (type){ + case "1":{ + System.out.println("1"); + return; + } + case "2":{ + System.out.println("2"); + return; + } + case "3":{ + System.out.println("3"); + return; + } + } + } + + public T getResponse(CusSuccess cusSuccess, Map response){ + String responseValue = aiyh.utils.Util.null2DefaultStr(response.get(cusSuccess.getSuccessField()), ""); + if (!cusSuccess.getSuccessValue().equals(responseValue)) { + throw new CustomerException(aiyh.utils.Util.logStr("接口地址:[{}], 接口响应码不为: [{}], 接口响应信息: {}", "", cusSuccess.getSuccessValue(), aiyh.utils.Util.null2DefaultStr(response.get(cusSuccess.getErrorMsg()), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + String[] split = aiyh.utils.Util.null2DefaultStr(cusSuccess.getDataKey(),"").split("\\."); + int len = split.length; + if(len == 0 || StringUtils.isBlank(cusSuccess.getDataKey())){ + return (T)response; + } + for (int i = 0; i < len - 1; i++) { + response = (Map) response.get(split[i]); + } + return (T) response.get(split[len - 1]); + } + + /** + * 压缩文件 + * + * @param sourceFilePath 源文件路径 + * @param zipFilePath 压缩后文件存储路径 + * @param zipFilename 压缩文件名 + */ + public void compressToZip(String sourceFilePath, String zipFilePath, String zipFilename) { + File sourceFile = new File(sourceFilePath); + File zipPath = new File(zipFilePath); + if (!zipPath.exists()) { + zipPath.mkdirs(); + } + File zipFile = new File(zipPath + File.separator + zipFilename); + try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))) { + writeZip(sourceFile, "", zos, zipFilename); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e.getMessage(), e.getCause()); + } + } + + /** + * 遍历所有文件,压缩 + * + * @param file 源文件目录 + * @param parentPath 压缩文件目录 + * @param zos 文件流 + */ + public void writeZip(File file, String parentPath, ZipOutputStream zos, String zipName) { + if (file.isDirectory()) { + //目录 + parentPath += file.getName() + File.separator; + File[] files = file.listFiles(); + for (File f : files) { + writeZip(f, parentPath, zos, zipName); + } + } else { + if(file.getName().equals(zipName)){ + return; + } + //文件 + try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) { + ZipEntry zipEntry = new ZipEntry(file.getName()); + zos.putNextEntry(zipEntry); + int len; + byte[] buffer = new byte[1024 * 10]; + while ((len = bis.read(buffer, 0, buffer.length)) != -1) { + zos.write(buffer, 0, len); + zos.flush(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e.getMessage(), e.getCause()); + } + } + } + +} diff --git a/src/test/java/xuanran/wang/eighty_five_degreec/SAPTest.java b/src/test/java/xuanran/wang/eighty_five_degreec/SAPTest.java new file mode 100644 index 0000000..da47043 --- /dev/null +++ b/src/test/java/xuanran/wang/eighty_five_degreec/SAPTest.java @@ -0,0 +1,52 @@ +package xuanran.wang.eighty_five_degreec; + +import aiyh.utils.tool.cn.hutool.core.lang.UUID; +import basetest.BaseTest; +import org.junit.Test; +import weaver.xuanran.wang.common.util.CusData2OA; +import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig; +import weaver.xuanran.wang.eighty_five_degreec.sap.util.ReadConfigUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/4/19 15:50 + */ +public class SAPTest extends BaseTest { + + @Test + public void testXml(){ + ReadConfigUtil configUtil = new ReadConfigUtil(); + String uniqueCode = "test1"; + String tableName = "formtable_main_161"; + String requestId = "419420"; + MainRequestConfig config = configUtil.getConfigByUniqueCode(uniqueCode, tableName); + String xml = configUtil.getXml(config, requestId, tableName); + System.out.println("xml => \n " + xml); + } + + @Test + public void testSQl(){ + String modelId = "119"; + String sql = " select id from #{tableName} where reqId = #{reqId}"; + List> list = new ArrayList<>(); + HashMap param = new HashMap<>(); + param.put("reqId",222222222); + param.put("requestXml",""); + list.add(param); + for (int i = 0; i < 10; i++) { + HashMap params = new HashMap<>(); + params.put("reqId",i + "1232"); + params.put("requestXml", UUID.randomUUID().toString()); + list.add(params); + } + List strings = CusData2OA.batchWriteToModel(modelId, sql, list); + System.out.println("data => " + strings); + } +} diff --git a/src/test/java/xuanran/wang/immc/Kafka/MQTest.java b/src/test/java/xuanran/wang/immc/Kafka/MQTest.java index d2d69fe..76fc915 100644 --- a/src/test/java/xuanran/wang/immc/Kafka/MQTest.java +++ b/src/test/java/xuanran/wang/immc/Kafka/MQTest.java @@ -324,7 +324,15 @@ public class MQTest extends BaseTest { } + private final SendTodoTaskMapper sendTodoTaskMapper = Util.getMapper(SendTodoTaskMapper.class); + @Test + public void testE(){ + ArrayList list = new ArrayList<>(); + list.add("146723321680844588"); + list.add("146723321680844588"); + sendTodoTaskMapper.updateStatusByTaskNum(list); + } SendTodoTaskUtil sendTodoTaskUtil = new SendTodoTaskUtil(); @Test public void testToken(){ diff --git a/src/test/java/xuanran/wang/traffic_bank/EmailOutSendTest.java b/src/test/java/xuanran/wang/traffic_bank/EmailOutSendTest.java new file mode 100644 index 0000000..cb11acf --- /dev/null +++ b/src/test/java/xuanran/wang/traffic_bank/EmailOutSendTest.java @@ -0,0 +1,45 @@ +package xuanran.wang.traffic_bank; + +import aiyh.utils.ThreadPoolConfig; +import aiyh.utils.Util; +import basetest.BaseTest; +import cn.hutool.extra.ssh.Sftp; +import com.alibaba.fastjson.JSONObject; +import com.api.xuanran.wang.traffic_bank.email.entity.EmailOutConfigMain; +import com.api.xuanran.wang.traffic_bank.email.service.EmailOutSendService; +import com.api.xuanran.wang.traffic_bank.email.service.impl.EmailOutSendServiceImpl; +import org.junit.Test; + +import java.util.*; +import java.util.concurrent.ExecutorService; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/4/18 16:31 + */ +public class EmailOutSendTest extends BaseTest { + private final EmailOutSendService service = new EmailOutSendServiceImpl(); + @Test + public void testA(){ + EmailOutConfigMain emailOutConfigMain = service.selectConfigByTransType(0); + log.info(JSONObject.toJSONString(emailOutConfigMain)); + HashMap param = new HashMap<>(); + HashMap param2 = new HashMap<>(); + List> list = new ArrayList<>(); + for (int i = 1; i <= 10; i++) { + param.put("a" + i, "测试记得回家的风刀霜剑方便的伤风败俗的肌肤都不舒服就不是的"+i); + param2.put("a"+i, "待会见阿富汗就啊好时机啊打开的健身卡的撒娇的v啊大把的挥洒都不会撒不对劲啊舍不得"+i); + } + list.add(param); + list.add(param2); + param.put("email",22); + param2.put("email",94); + ThreadPoolConfig.createThreadPoolInstance(); + param.put("type",0); + param.put("data", list); + service.sendEmail(param); + + } +}