代码备份提交
parent
aa83695461
commit
d78176c580
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>第三方系统登录oa</h1>
|
||||
*
|
||||
* @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<String, String> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>第三方系统登录oa mapper</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/4/18 09:54
|
||||
*/
|
||||
@SqlMapper
|
||||
public interface OtherSystemToOAMapper {
|
||||
/**
|
||||
* <h1>根据outKey查oa ID</h1>
|
||||
* @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);
|
||||
/**
|
||||
* <h1>根据appId 查跳转的地址</h1>
|
||||
* @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);
|
||||
/**
|
||||
* <h1>根据appId 查跳转的地址</h1>
|
||||
* @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<String, String> selectRedirectUrlAndSecretByAppId(@ParamMapper("appId") String appId);
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>第三方系统登录oa</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/4/17 14:27
|
||||
*/
|
||||
public interface OtherSystemToOAService {
|
||||
/**
|
||||
* <h1>发请求根据code获取第三方系统用户id</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/18 13:29
|
||||
* @param url 请求地址
|
||||
* @param params 参数
|
||||
* @param headers 请求头
|
||||
* @param cusSuccess 自定义接口成功/失败标识
|
||||
* @return 接口响应字段
|
||||
**/
|
||||
int getUserIdByCode(String url, Map<String, Object> params, Map<String, String> headers, CusSuccess cusSuccess, Map<String, String> redirectUrlSecret);
|
||||
/**
|
||||
* <h1>根据第三方系统人员code匹配oa人员id</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/18 13:30
|
||||
* @param code 第三方系统人员code
|
||||
* @return oa人员id
|
||||
**/
|
||||
int getUserFromOtherSys(String code, Map<String, String> redirectUrlSecret);
|
||||
/**
|
||||
* <h1>根据appId获取oa地址</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/20 11:14
|
||||
* @param appId 建模appId
|
||||
* @return 跳转应用地址
|
||||
**/
|
||||
String getLoginSuccessSendRedirectUrl(String appId);
|
||||
/**
|
||||
* <h1>根据appId获取跳转地址和corpsecret</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/20 11:14
|
||||
* @param appId 建模appId
|
||||
* @return 跳转应用地址
|
||||
**/
|
||||
Map<String, String> getRedirectUrlAndCorpsecret(String appId);
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>第三方系统登录oa</h1>
|
||||
*
|
||||
* @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<String, Object> params, Map<String, String> headers, CusSuccess cusSuccess, Map<String, String> 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<String, String> redirectUrlSecret) {
|
||||
HashMap<String, Object> 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<String, String> getRedirectUrlAndCorpsecret(String appId) {
|
||||
Map<String, String> 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import javax.ws.rs.core.Context;
|
|||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
* <h1><学员接口/h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/3/1 10:56
|
||||
|
|
|
@ -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();
|
||||
/**
|
||||
* <h1>取消会议 支持多个</h1>
|
||||
|
@ -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){
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>交银理财邮件外发</h1>
|
||||
*
|
||||
* @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<String, Object> 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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.api.xuanran.wang.traffic_bank.email.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <h1>邮件外发配置表明细</h1>
|
||||
*
|
||||
* @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;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.api.xuanran.wang.traffic_bank.email.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <h1>邮件外发配置表主表</h1>
|
||||
*
|
||||
* @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<EmailOutConfigDetail> configDetailList;
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>邮件外发mapper</h1>
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* <h1>查询配置表明细表信息</h1>
|
||||
* @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<EmailOutConfigDetail> selectConfigDetail(@ParamMapper("mainId") int mainId);
|
||||
|
||||
@Select(custom = true)
|
||||
String selectCustomerSql(@SqlString String sql, Map<String, Object> map);
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>邮件外发</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/4/18 14:15
|
||||
*/
|
||||
public interface EmailOutSendService {
|
||||
EmailOutConfigMain selectConfigByTransType(int type);
|
||||
void sendEmail(Map<String, Object> params);
|
||||
}
|
|
@ -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.*;
|
||||
|
||||
/**
|
||||
* <h1>邮件外发业务方法</h1>
|
||||
*
|
||||
* @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<EmailOutConfigDetail> 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<String, Object> param) {
|
||||
int type = Util.getIntValue(Util.null2DefaultStr(param.get("type"), ""), -1);
|
||||
EmailOutConfigMain outConfigMain = selectConfigByTransType(type);
|
||||
List<Map<String, Object>> data = (List<Map<String, Object>>) param.get("data");
|
||||
Map<String, Object> map = convertConfigToMail(outConfigMain, data);
|
||||
List<String> addressList = (List<String>) 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>根据配置将参数进行转换</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/19 11:05
|
||||
* @param outConfigMain 配置表对象
|
||||
* @param params 邮件参数
|
||||
* @return 转换后的邮件参数map
|
||||
**/
|
||||
public Map<String, Object> convertConfigToMail(EmailOutConfigMain outConfigMain, List<Map<String, Object>> params){
|
||||
List<EmailOutConfigDetail> detailConfig = outConfigMain.getConfigDetailList();
|
||||
String title = "";
|
||||
String titleField = Util.null2DefaultStr(outConfigMain.getTitleField(),"");
|
||||
String emailAddressCusSql = outConfigMain.getEmailAddressCusSql();
|
||||
String sql = Util.sbc2dbcCase(emailAddressCusSql);
|
||||
List<String> emailList = new ArrayList<>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int size = 0;
|
||||
// 表头
|
||||
for (EmailOutConfigDetail detail : detailConfig) {
|
||||
sb.append("<td>").append(detail.getFieldName()).append("</td>");
|
||||
size++;
|
||||
}
|
||||
sb.append("</tr>");
|
||||
for (Map<String, Object> param : params) {
|
||||
sb.append("<tr>");
|
||||
for (EmailOutConfigDetail detail : detailConfig) {
|
||||
int mergeCell = detail.getMergeCell();
|
||||
if(mergeCell > 0){
|
||||
sb.append("<td ")
|
||||
.append(" colspan=\"")
|
||||
.append(mergeCell)
|
||||
.append("\"").append(">");
|
||||
sb.append(Util.null2DefaultStr(param.get(detail.getInterfaceField()),""));
|
||||
}else {
|
||||
sb.append("<td>").append(Util.null2DefaultStr(param.get(detail.getInterfaceField()),""));
|
||||
}
|
||||
sb.append("</td>");
|
||||
}
|
||||
sb.append("</tr>");
|
||||
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<String, Object> email = new HashMap<>();
|
||||
email.put("title", title);
|
||||
email.put("email", html);
|
||||
email.put("address", emailList);
|
||||
return email;
|
||||
}
|
||||
|
||||
}
|
|
@ -112,4 +112,13 @@ public interface CommonMapper {
|
|||
|
||||
@Update("update meeting set meetingstatus = 4 where requestid in (${requestIds})")
|
||||
boolean cancelMeeting(@ParamMapper("requestIds") List<String> requestIds);
|
||||
|
||||
@Select(custom = true)
|
||||
String selectCustomerSql(@SqlString String sql, Map<String, Object> map);
|
||||
|
||||
@Update(custom = true)
|
||||
boolean updateModelInfo(@SqlString String sql, Map<String, Object> params);
|
||||
|
||||
@BatchUpdate(custom = true)
|
||||
boolean updateModelInfoList(@SqlString String sql, @BatchSqlArgs List<Map<String, Object>> params);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>删除建模数据</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2022/11/23 21:02
|
||||
* @param modelId 模块id
|
||||
* @param ids 数据集合
|
||||
* @return 删除是否成功
|
||||
**/
|
||||
public static boolean deleteModelDataByIds(String modelId, List<String> ids){
|
||||
String tableName = commonMapper.getModelNameByModelId(modelId);
|
||||
return commonMapper.deleteModelDataByIds(tableName, ids);
|
||||
}
|
||||
/**
|
||||
* <h1>获取建模数据id</h1>
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>校验模块id 并获取表名</h1>
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>自定义数据写入oa</h1>
|
||||
*
|
||||
* @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<String, Object> params){
|
||||
return baseExecute(modelId, uniqueSql, Collections.singletonList(params)).get(0);
|
||||
}
|
||||
|
||||
public static String writeToModel(String modelId, Map<String, Object> params){
|
||||
return baseExecute(modelId, "", Collections.singletonList(params)).get(0);
|
||||
}
|
||||
|
||||
public static List<String> batchWriteToModel(String modelId, List<Map<String, Object>> params){
|
||||
return baseExecute(modelId, "", params);
|
||||
}
|
||||
|
||||
public static List<String> batchWriteToModel(String modelId, String uniqueSql, List<Map<String, Object>> params){
|
||||
return baseExecute(modelId, uniqueSql, params);
|
||||
}
|
||||
|
||||
@BatchUpdate
|
||||
public static List<String> baseExecute(String modelId, String uniqueSql, List<Map<String, Object>> 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<String> delList = new ArrayList<>();
|
||||
List<String> modelDataList = new ArrayList<>();
|
||||
String updateSql = "";
|
||||
|
||||
for (Map<String, Object> 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<String, Object> params) {
|
||||
StringBuilder sqlSb = new StringBuilder("update ")
|
||||
.append(tableName)
|
||||
.append(" set ");
|
||||
for (Map.Entry<String, Object> 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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>中国船舶研究所流程数据推送到科研综合管理系统</h1>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
* <h1>自定义请求条件</h1>
|
||||
*
|
||||
* @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;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package weaver.xuanran.wang.cssc.cms.service;
|
||||
|
||||
import weaver.xuanran.wang.cssc.cms.entity.CusSuccess;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
*
|
||||
* @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);
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>vms业务方法</h1>
|
||||
*
|
||||
* @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<String, Object> param = dealWithMapping.getRequestParam(recordSet, requestMappingConfig);
|
||||
return requestMasterPlate.apiPost(url, param, new HashMap<>(), cusSuccess);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>推送数据</h1>
|
||||
*
|
||||
* @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<String, String> 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<String, Object> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>请求模版方法</h1>
|
||||
*
|
||||
* @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> T apiGet(String url, Map<String, Object> params, Map<String, String> 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> T apiPost(String url, Object o, Map<String, String> 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> 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<String, Object> 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]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>将流程数据推送到sap中</h1>
|
||||
*
|
||||
* @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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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<DetailRequestConfig> detailRequestConfigList;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package weaver.xuanran.wang.eighty_five_degreec.sap.service;
|
||||
|
||||
import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig;
|
||||
|
||||
/**
|
||||
* <h1>流程数据推送sap</h1>
|
||||
*
|
||||
* @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);
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
* <h1>将流程数据推送至sap</h1>
|
||||
*
|
||||
* @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<String, Object> 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));
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
/**
|
||||
* <h1>读取配置文件</h1>
|
||||
* @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<DetailRequestConfig> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取对象</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2022/11/15 22:20
|
||||
* @param queryRs 查询结果集
|
||||
* @param clazz 返回类class
|
||||
* @return 返回类对象
|
||||
**/
|
||||
public static <T> T getInstance(RecordSet queryRs, Class<T> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取参数值</h1>
|
||||
* @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("<br>", " ")
|
||||
.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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>日期解析</h1>
|
||||
* @param dateStr 日期字符串
|
||||
* @return 日期对象
|
||||
*/
|
||||
public static Date parseDate(String dateStr) {
|
||||
ThreadLocal<SimpleDateFormat> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>自定义时间格式化</h1>
|
||||
* @param date 日期
|
||||
* @param tempStr 格式化字符串
|
||||
* @return 格式化字符串
|
||||
*/
|
||||
private static String diyDateFortMat(Date date,String tempStr){
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(tempStr);
|
||||
return simpleDateFormat.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>根据配置对象生成xml</h1>
|
||||
* @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<DetailRequestConfig> 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 "";
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取主xml</h1>
|
||||
* @param requestConfigList 配置明细集合
|
||||
* @param mainRs 主表recordSet
|
||||
* @param detailRs 明细recordSet
|
||||
* @return 主表xml
|
||||
*/
|
||||
public String getMainXml(List<DetailRequestConfig> requestConfigList,
|
||||
RecordSet mainRs,
|
||||
RecordSet detailRs){
|
||||
List<DetailRequestConfig> 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取明细xml</h1>
|
||||
* @param requestConfigList 配置集合
|
||||
* @param mainRs 主表recordSet
|
||||
* @param detailRs 明细表recordSet
|
||||
* @param detailIndex 明细下标
|
||||
* @param tableName 表名
|
||||
* @param mainId 主数据id
|
||||
* @return 明细xml
|
||||
*/
|
||||
public String getDetailXml(List<DetailRequestConfig> requestConfigList,
|
||||
RecordSet mainRs, RecordSet detailRs, String detailIndex,
|
||||
String tableName, String mainId){
|
||||
// 明细
|
||||
String[] detailIdArr = detailIndex.split(",");
|
||||
StringBuilder detailSb = new StringBuilder();
|
||||
for (String detailId : detailIdArr) {
|
||||
List<DetailRequestConfig> 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>xml拼接</h1>
|
||||
* @param xml xml对象
|
||||
* @param configList 配置对象集合
|
||||
* @param mainRs 主表recordSet
|
||||
* @param detailRs 明细recordSet
|
||||
* @param count 序号
|
||||
*/
|
||||
public void appendXml(StringBuilder xml, List<DetailRequestConfig> 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");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>解析请求xml模板位置</h1>
|
||||
* 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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>解析响应数据</h1>
|
||||
* @param responseMap 响应map
|
||||
* @param responseField 需要从map中获取指定字段的标识 Response.Execution
|
||||
* @return 响应数据
|
||||
*/
|
||||
public String parseMap(Map<String, Object> 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<String, Object>) o;
|
||||
}else if(o instanceof List){
|
||||
List<Map<String, Object>> list = (List<Map<String, Object>>) o;
|
||||
if(CollectionUtils.isEmpty(list)){
|
||||
return "";
|
||||
}
|
||||
responseMap = list.get(0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return Util.null2String(responseMap.get(strArr[strArr.length - 1]));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>vms业务方法</h1>
|
||||
|
@ -115,32 +119,41 @@ public class WorkFlowToVmsAndMQService {
|
|||
**/
|
||||
public void sendToMQ(String kafkaConfig, Map<String, Object> message){
|
||||
KafkaProducer<String, String> producer = null;
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
Map<String, Object> 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<String, String> record = new ProducerRecord<>(topic, JSONObject.toJSONString(message));
|
||||
try {
|
||||
RecordMetadata recordMetadata = producer.send(record).get();
|
||||
log.info(Util.logStr("send mq recordMetadata: {}", JSONObject.toJSONString(recordMetadata)));
|
||||
producer.send(record).get();
|
||||
}catch (Exception e){
|
||||
throw new CustomerException(Util.logStr("producer send error: {}!", e.getMessage()));
|
||||
}
|
||||
}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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>自定义请求条件</h1>
|
||||
|
@ -23,4 +23,5 @@ public class CusSuccess {
|
|||
private String errorMsg;
|
||||
private String dataKey;
|
||||
private Object response;
|
||||
private CusDataDecipher cusDataDecipher;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package weaver.xuanran.wang.sh_bigdata.common.service;
|
||||
|
||||
import aiyh.utils.httpUtil.ResponeVo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>自定义解密类</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/4/10 13:20
|
||||
*/
|
||||
public interface CusDataDecipher {
|
||||
Map<String, Object> decoder(ResponeVo responeVo);
|
||||
}
|
|
@ -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<String, Object> response = responseVo.getResponseMap(); // 根据相应结果转化为map集合
|
||||
Map<String, Object> 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;
|
||||
|
|
|
@ -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(),"");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取token</h1>
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>给post请求的url添加token</h1>
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取配置文件</h1>
|
||||
* @author xuanran.wang
|
||||
|
@ -90,6 +120,19 @@ public class ShBigDataUtil {
|
|||
* @return 参数
|
||||
**/
|
||||
public static LinkedHashMap<String, Object> parseCusDbEntityMapping(int type, Object o) throws IllegalAccessException {
|
||||
return parseCusDbEntityMapping(type, 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>解析注解并将实体类转换成map</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/6 12:27
|
||||
* @param type 表类型 0: 分部, 1: 部门
|
||||
* @param o 对象
|
||||
* @param addSysParam 是否添加系统默认参数
|
||||
* @return 参数
|
||||
**/
|
||||
public static LinkedHashMap<String, Object> parseCusDbEntityMapping(int type, Object o, boolean addSysParam) throws IllegalAccessException {
|
||||
Class<?> clazz = o.getClass();
|
||||
LinkedHashMap<String, Object> 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>token 工具类</h1>
|
||||
|
@ -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<String, CusToken> TOKEN_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* <h1>获取token</h1>
|
||||
* @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<String, Object> params = new HashMap<>();
|
||||
// 接口调用地址
|
||||
String tokenUrl = ShBigDataUtil.getPropertiesValByKey("tokenUrl");
|
||||
// 密钥
|
||||
String corpSecret = ShBigDataUtil.getPropertiesValByKey("corpSecret");
|
||||
params.put("corpsecret", corpSecret);
|
||||
params.put("corpsecret", secret);
|
||||
Map<String, Object> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, Object> synResult;
|
||||
|
||||
private final OrgHrmAsyncService asyncService = new OrgHrmAsyncServiceImpl();
|
||||
|
||||
private final Logger log = Util.getLogger();
|
||||
|
||||
public OrganizationHrmSyncFromOtherSys(){
|
||||
this.removeSynResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String SynTimingToOASubCompany() {
|
||||
List<Map<String, Object>> subCompany = asyncService.asyncOrgDep(0);
|
||||
List<Map<String, Object>> list = buildItemList(subCompany);
|
||||
this.synResult.put("1", list);
|
||||
log.info("subCompany : \n" + JSONObject.toJSONString(list));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String SynTimingToOADepartment() {
|
||||
List<Map<String, Object>> subCompany = asyncService.asyncOrgDep(1);
|
||||
List<Map<String, Object>> 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<Map<String, Object>> hrmList = asyncService.asyncHrm();
|
||||
List<Map<String, Object>> 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<Map<String, Object>> buildItemList(List<Map<String, Object>> list){
|
||||
List<Map<String, Object>> synResultlist = new ArrayList<>();
|
||||
for (Map<String, Object> 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<String, Object> buildItemMap(String pkCode, String pk, String memo, String success, String error) {
|
||||
//保存结果
|
||||
Map<String, Object> res = new HashMap<>();
|
||||
|
@ -103,4 +138,6 @@ public class OrganizationHrmSyncFromOtherSys implements HrmSynService {
|
|||
res.put(HrmSynDAO.ErrorMessage, error);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>自定义转换接口</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/4/11 16:49
|
||||
*/
|
||||
public interface CusOrgHrmAsyncConvert {
|
||||
Object cusConvert(OrgHrmAsyncConfigDetail detail, OrgHrmAsyncCache cache, Map<String, String> pathParam);
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>人员同步接口缓存对象</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/4/11 17:19
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class OrgHrmAsyncCache {
|
||||
/**
|
||||
* <h2>分部缓存</h2>
|
||||
**/
|
||||
private Map<String, Integer> subCompanyCache;
|
||||
/**
|
||||
* <h2>部门缓存</h2>
|
||||
**/
|
||||
private Map<String, Integer> departmentCache;
|
||||
/**
|
||||
* <h2>接口数据</h2>
|
||||
**/
|
||||
private Map<String, Object> interfaceVal;
|
||||
/**
|
||||
* <h2>人员缓存</h2>
|
||||
**/
|
||||
private Map<String, Integer> hrmCache;
|
||||
/**
|
||||
* <h2>岗位缓存</h2>
|
||||
**/
|
||||
private Map<String, Integer> jobTitleCache;
|
||||
private int arrIndex;
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>组织架构同步配置表-明细</h1>
|
||||
*
|
||||
* @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;
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>组织架构同步配置表</h1>
|
||||
*
|
||||
* @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<OrgHrmAsyncConfigDetail> orgHrmAsyncConfigDetailList;
|
||||
}
|
|
@ -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 {
|
||||
/**
|
||||
* <h2>创建的部门id</h2>
|
||||
|
@ -37,17 +41,26 @@ public class OtherSysDepartment {
|
|||
**/
|
||||
@CusDbEntityMapping(dbFiled = {"showorder"})
|
||||
private int order;
|
||||
/**
|
||||
* <h2>所属分部id</h2>
|
||||
**/
|
||||
@CusDbEntityMapping(dbFiled = {"supsubcomid","supsubcomid1"})
|
||||
private int subCompanyId;
|
||||
/**
|
||||
* <h2>
|
||||
* 是否有子部门,0:否,1:是
|
||||
* </h2>
|
||||
**/
|
||||
private int hasChild;
|
||||
/**
|
||||
* <h2>层级</h2>
|
||||
**/
|
||||
@CusDbEntityMapping(dbFiled = {"tlevel"})
|
||||
private int level;
|
||||
/**
|
||||
* <h2>删除 0:有效</h2>
|
||||
**/
|
||||
private int isDeleted;
|
||||
/**
|
||||
* <h2>所属分部</h2>
|
||||
**/
|
||||
@CusDbEntityMapping(dbFiled = {"","subcompanyid1"})
|
||||
private int division;
|
||||
|
||||
private List<OtherSysDepartment> childList;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>组织架构-人员同步 计划任务</h1>
|
||||
*
|
||||
* @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<String, Function<String, String>> 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<String, String> function = maps.get(asyncType);
|
||||
if(function != null){
|
||||
function.apply("");
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("OrganizationHrmSyncJob execute error! " + e.getMessage());
|
||||
log.info(Util.getErrString(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <h1>组织架构同步</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/14 16:12
|
||||
**/
|
||||
private void orgAsync(){
|
||||
List<Map<String, Object>> subCompanyList = asyncService.asyncOrgDep(0);
|
||||
poolExecute(subCompanyList, 0);
|
||||
List<Map<String, Object>> departmentList = asyncService.asyncOrgDep(1);
|
||||
poolExecute(departmentList, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>人员同步</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/14 16:12
|
||||
**/
|
||||
private void hrmAsync(){
|
||||
List<Map<String, Object>> hrmList = asyncService.asyncHrm();
|
||||
poolExecute(hrmList, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>线程池提交任务</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/14 14:11
|
||||
* @param list 数据
|
||||
**/
|
||||
private void poolExecute(List<Map<String, Object>> list, int type){
|
||||
executorService.execute(()->{
|
||||
try {
|
||||
log.info("subCompanyList : \n" + JSONObject.toJSONString(list));
|
||||
List<LinkedHashMap<String, Object>> convert = convert(list, type);
|
||||
CusInfoToOAUtil.executeBatch(Util.getIntValue(this.orgHrmAsyncLogModelId, -1), convert);
|
||||
}catch (Exception e){
|
||||
log.info("写入日志建模异常! " + e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>将同步数据转换成日志记录map对象</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/14 14:12
|
||||
* @param dataList 数据集合
|
||||
* @param type 同步类型
|
||||
* @return 转换后的集合
|
||||
**/
|
||||
private List<LinkedHashMap<String, Object>> convert(List<Map<String, Object>> dataList, int type){
|
||||
List<LinkedHashMap<String, Object>> res = new ArrayList<>();
|
||||
for (Map<String, Object> map : dataList) {
|
||||
LinkedHashMap<String, Object> 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;
|
||||
}
|
||||
}
|
|
@ -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<Integer, Integer> selectSubCompany();
|
||||
/**
|
||||
* <h1>查询配置表主表信息</h1>
|
||||
* @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<OrgHrmAsyncConfigMain> selectSubCompanyAsyncConfig(@ParamMapper("asyncType") int asyncType);
|
||||
|
||||
/**
|
||||
* <h1>查询配置表明细表信息</h1>
|
||||
* @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<OrgHrmAsyncConfigDetail> selectSubCompanyAsyncConfigDetail(@ParamMapper("mainId") int mainId);
|
||||
|
||||
@Select("select outkey, id from HrmSubCompany where outkey <> '' and outkey is not null")
|
||||
List<Map<String, Integer>> selectSubCompanyAll();
|
||||
|
||||
@Select("select outkey, id from hrmdepartment where outkey <> '' and outkey is not null")
|
||||
List<Map<String, Integer>> selectDepartmentAll();
|
||||
|
||||
@Select("select outkey, id, tlevel from HrmSubCompany where outkey <> '' and outkey is not null and canceled <> 1")
|
||||
List<Map<String, Integer>> selectSubCompanyActive();
|
||||
|
||||
@Select("select outkey, id from hrmdepartment where outkey <> '' and outkey is not null and canceled <> 1")
|
||||
List<Map<String, Integer>> selectDepartmentActive();
|
||||
|
||||
@Select("select jobtitlename,id from hrmjobtitles")
|
||||
List<Map<String, Integer>> 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<String, Object> params);
|
||||
|
||||
@Update(custom = true)
|
||||
boolean updateSubInfo(@SqlString String sql, Map<String, Object> params);
|
||||
boolean updateOrgInfo(@SqlString String sql, Map<String, Object> params);
|
||||
|
||||
@Select("select interfaceDataId from uf_depart_or_sub where depOrSub = 0")
|
||||
List<String> selectCusSubCompany();
|
||||
|
||||
@Select("select interfaceDataId from uf_depart_or_sub where depOrSub = 1")
|
||||
List<String> selectCusDepart();
|
||||
|
||||
@Select(custom = true)
|
||||
String selectCustomerSql(@SqlString String sql, Map<String, Object> map);
|
||||
@Select(custom = true)
|
||||
List<String> selectCustomerSqlArr(@SqlString String sql, Map<String, Object> map);
|
||||
@Update("update HrmSubCompany set canceled = 1 where outkey in (${outKeys})")
|
||||
boolean updateHrmSubCompanyCanceled(List<String> outKeys);
|
||||
|
||||
@Update("update hrmdepartment set canceled = 1 where outkey in (${outKeys})")
|
||||
boolean updateHrmDepartmentCanceled(List<String> outKeys);
|
||||
|
||||
@Select("select min(outkey) from hrmsubcompany where outkey <> '' and outkey is not null")
|
||||
String selectTopLevelOutKey();
|
||||
|
||||
@Select("select outkey, id from hrmresource ")
|
||||
List<Map<String, Integer>> selectHrmIdAndOutKey();
|
||||
|
||||
@Insert(custom = true)
|
||||
boolean insertHrmInfo(@SqlString String sql, Map<String, Object> params);
|
||||
|
||||
@Select("select 1 from hrmresource where departmentid = (select id from hrmdepartment where outkey = #{outKey})")
|
||||
int selectDepartHasUser(@ParamMapper("outKey") String outKey);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>上海大数据中心人员/组织架构同步 接口调用</h1>
|
||||
|
@ -14,12 +16,13 @@ public interface OrgHrmAsyncApiService {
|
|||
|
||||
|
||||
/**
|
||||
* <h1>获取用户信息</h1>
|
||||
* <h1>获取用户信息 通过传入顶级组织id 并且递归获取所有用户</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/4 11:13
|
||||
* @param topLevelId 三方系统顶级组织id
|
||||
* @return 响应对象
|
||||
**/
|
||||
List<Object> getUserInfo();
|
||||
List<Map<String, Object>> getUserInfo(int topLevelId);
|
||||
|
||||
/**
|
||||
* <h1>获取部门信息</h1>
|
||||
|
@ -29,4 +32,12 @@ public interface OrgHrmAsyncApiService {
|
|||
**/
|
||||
List<OtherSysDepartment> getDepartmentInfo();
|
||||
|
||||
/**
|
||||
* <h1>获取部门信息</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/4 11:13
|
||||
* @return 响应对象
|
||||
**/
|
||||
List<Map<String, Object>> getDepartmentInfoMap();
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
* <h1>获取分部表中 outKey 与 id对应到map集合</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/6 13:44
|
||||
* @return 分部表中 outKey 与 id对应到map集合
|
||||
**/
|
||||
Map<Integer, Integer> initSubCompany();
|
||||
/**
|
||||
* <h1>部门数据同步</h1>
|
||||
* @author xuanran.wang
|
||||
|
@ -28,4 +20,13 @@ public interface OrgHrmAsyncService {
|
|||
**/
|
||||
List<OtherSysDepartment> asyncDepartment();
|
||||
|
||||
/**
|
||||
* <h1>部门数据同步</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/6 13:44
|
||||
**/
|
||||
List<Map<String, Object>> asyncOrgDep(int type);
|
||||
|
||||
List<Map<String, Object>> asyncHrm();
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Object> getUserInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OtherSysDepartment> getDepartmentInfo() {
|
||||
String departmentInfoUrl = ShBigDataUtil.getPropertiesValByKey("departmentInfoUrl");
|
||||
public List<Map<String, Object>> getUserInfo(int topLevelId) {
|
||||
String departmentInfoUrl = ShBigDataUtil.getPropertiesValByKey("userInfoUrl");
|
||||
HashMap<String, Object> 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<Map<String, Object>> list = requestMasterPlate.apiGet(departmentInfoUrl, params, new HashMap<>(), cusSuccess);
|
||||
return requestMasterPlate.apiGet(departmentInfoUrl, params, new HashMap<>(), cusSuccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OtherSysDepartment> getDepartmentInfo() {
|
||||
List<Map<String, Object>> list = getDepartmentInfoMap();
|
||||
List<OtherSysDepartment> 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<Map<String, Object>> getDepartmentInfoMap() {
|
||||
String departmentInfoUrl = ShBigDataUtil.getPropertiesValByKey("departmentInfoUrl");
|
||||
HashMap<String, Object> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>组织架构同步</h1>
|
||||
*
|
||||
* @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();
|
||||
/**
|
||||
* <h2>配置表中部门白名单</h2>
|
||||
**/
|
||||
private final List<String> departmentWhiteList;
|
||||
/**
|
||||
* <h2>配置表中分部白名单</h2>
|
||||
**/
|
||||
private final List<String> subCompanyWhiteList;
|
||||
/**
|
||||
* <h2>分部缓存</h2>
|
||||
**/
|
||||
private Map<String, Integer> subCompanyCache = new HashMap<>();
|
||||
/**
|
||||
* <h2>部门缓存</h2>
|
||||
**/
|
||||
private Map<String, Integer> departmentCache = new HashMap<>();
|
||||
/**
|
||||
* <h2>分部最大层级</h2>
|
||||
**/
|
||||
int maxLevel;
|
||||
/**
|
||||
* <h2>接口中 上级分部字段</h2>
|
||||
**/
|
||||
private String interfaceSupSubCompany;
|
||||
|
||||
{
|
||||
departmentWhiteList = orgHrmAsyncMapper.selectCusDepart();
|
||||
subCompanyWhiteList = orgHrmAsyncMapper.selectCusSubCompany();
|
||||
|
||||
List<Map<String, Integer>> subCompany = orgHrmAsyncMapper.selectSubCompanyAll();
|
||||
subCompanyCache = OrgHrmAsyncUtil.parseListMap2Map(subCompany);
|
||||
|
||||
List<Map<String, Integer>> department = orgHrmAsyncMapper.selectDepartmentAll();
|
||||
departmentCache = OrgHrmAsyncUtil.parseListMap2Map(department);
|
||||
maxLevel = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("maxLevel"), 3);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<OtherSysDepartment> asyncDepartment() {
|
||||
List<OtherSysDepartment> departmentInfo = orgHrmAsyncApiService.getDepartmentInfo();
|
||||
// 将部门信息转换成树
|
||||
List<OtherSysDepartment> convetList = Util.listToTree(departmentInfo,
|
||||
OtherSysDepartment::getId, OtherSysDepartment::getParentid,
|
||||
OtherSysDepartment::getChildList, OtherSysDepartment::setChildList,
|
||||
parentid -> parentid == -1);
|
||||
// 进行部门分部解析
|
||||
List<OtherSysDepartment> hrmSubCompany = new ArrayList<>();
|
||||
List<OtherSysDepartment> 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>同步数据到分部</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/6 13:37
|
||||
* @param departmentList 部门数据集合
|
||||
**/
|
||||
public void addHrmSubCompany(List<OtherSysDepartment> 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>同步数据到分部</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/6 13:37
|
||||
* @param departmentList 部门数据集合
|
||||
**/
|
||||
public void addHrmDepartment(List<OtherSysDepartment> 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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>解析部门or分部</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/10 12:13
|
||||
* @param list 树形集合
|
||||
* @param n 层级
|
||||
* @param hrmSubCompany 分部
|
||||
* @param hrmDepartment 部门
|
||||
**/
|
||||
public void parseSubCompanyAndDepartment(List<OtherSysDepartment> list, int n, int maxLevel,List<OtherSysDepartment> hrmSubCompany, List<OtherSysDepartment> hrmDepartment){
|
||||
n++;
|
||||
for (OtherSysDepartment department : list) {
|
||||
department.setLevel(n);
|
||||
List<OtherSysDepartment> childList = department.getChildList();
|
||||
String departmentId = department.getId() + "";
|
||||
if(CollectionUtils.isNotEmpty(childList)){
|
||||
List<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>更新表数据</h1>
|
||||
* @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<String, Object> params;
|
||||
try {
|
||||
params = ShBigDataUtil.parseCusDbEntityMapping(type, o, true);
|
||||
}catch (Exception e){
|
||||
throw new CustomerException("parseCusDbEntityMapping error!" + e.getMessage());
|
||||
}
|
||||
for (Map.Entry<String, Object> 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<Map<String, Object>> asyncOrgDep(int type) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> asyncHrm() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>解析部门or分部</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/10 12:13
|
||||
* @param list 树形集合
|
||||
* @param n 层级
|
||||
* @param hrmSubCompany 分部
|
||||
* @param hrmDepartment 部门
|
||||
**/
|
||||
// public void parseSubCompanyAndDepartment(List<OtherSysDepartment> list, int n, int maxLevel,List<OtherSysDepartment> hrmSubCompany, List<OtherSysDepartment> hrmDepartment){
|
||||
// n++;
|
||||
// for (OtherSysDepartment department : list) {
|
||||
// department.setLevel(n);
|
||||
// List<OtherSysDepartment> 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>组织架构同步</h1>
|
||||
|
@ -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;
|
||||
/**
|
||||
* <h2>配置表中部门白名单</h2>
|
||||
**/
|
||||
private final List<String> departmentWhiteList;
|
||||
/**
|
||||
* <h2>配置表中分部白名单</h2>
|
||||
**/
|
||||
private final List<String> subCompanyWhiteList;
|
||||
/**
|
||||
* <h2>分部缓存</h2>
|
||||
**/
|
||||
private final Map<String, Integer> subCompanyCache;
|
||||
/**
|
||||
* <h2>部门缓存</h2>
|
||||
**/
|
||||
private final Map<String, Integer> departmentCache;
|
||||
/**
|
||||
* <h2>岗位缓存</h2>
|
||||
**/
|
||||
private final Map<String, Integer> jobTitleCache;
|
||||
/**
|
||||
* <h2>人员缓存</h2>
|
||||
**/
|
||||
private final Map<String, Integer> hrmCache;
|
||||
/**
|
||||
* <h2>分部最大层级</h2>
|
||||
**/
|
||||
int maxLevel;
|
||||
/**
|
||||
* <h2>分部同步配置表对象</h2>
|
||||
**/
|
||||
private final List<OrgHrmAsyncConfigMain> subCompanyConfig;
|
||||
/**
|
||||
* <h2>部门同步配置表对象</h2>
|
||||
**/
|
||||
private final List<OrgHrmAsyncConfigMain> departmentConfig;
|
||||
/**
|
||||
* <h2>人员同步配置表对象</h2>
|
||||
**/
|
||||
private final List<OrgHrmAsyncConfigMain> hrmReSourceConfig;
|
||||
/**
|
||||
* <h2>分部同步记录</h2>
|
||||
**/
|
||||
private final List<Map<String, Object>> asyncHrmSubCompany = new ArrayList<>();
|
||||
/**
|
||||
* <h2>部门同步记录</h2>
|
||||
**/
|
||||
private final List<Map<String, Object>> asyncHrmDepartment = new ArrayList<>();
|
||||
private final Map<Integer, String> typeTableName = new HashMap<>();
|
||||
private final HashMap<Integer, Function<Object, Integer>> getNextIdTypeMap = new HashMap<>();
|
||||
private final Map<String, Integer> subCompanyLevelCache;
|
||||
|
||||
@Override
|
||||
public Map<Integer, Integer> initSubCompany() {
|
||||
return orgHrmAsyncMapper.selectSubCompany();
|
||||
// 创建按order值进行排序的比较器
|
||||
Comparator<Map<String, Object>> 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<Map<String, Object>> 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<Map<String, Integer>> subCompany = orgHrmAsyncMapper.selectSubCompanyActive();
|
||||
subCompanyCache = OrgHrmAsyncUtil.parseListMap2Map(subCompany);
|
||||
subCompanyLevelCache = OrgHrmAsyncUtil.parseListMap2Map("outkey","tlevel", subCompany);
|
||||
List<Map<String, Integer>> department = orgHrmAsyncMapper.selectDepartmentActive();
|
||||
departmentCache = OrgHrmAsyncUtil.parseListMap2Map(department);
|
||||
List<Map<String, Integer>> jobTitle = orgHrmAsyncMapper.selectJobTitle();
|
||||
jobTitleCache = OrgHrmAsyncUtil.parseListMap2Map("jobtitlename","id", jobTitle);
|
||||
List<Map<String, Integer>> 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<OtherSysDepartment> asyncDepartment() {
|
||||
List<OtherSysDepartment> departmentInfo = orgHrmAsyncApiService.getDepartmentInfo();
|
||||
//TODO 分部(条件待确认)
|
||||
List<OtherSysDepartment> subList = departmentInfo
|
||||
.stream()
|
||||
.filter(item -> -1 == item.getParentid())
|
||||
.sorted(Comparator.comparing(OtherSysDepartment::getId))
|
||||
.collect(Collectors.toList());
|
||||
addHrmSubCompany(subList);
|
||||
|
||||
// 过滤出父节点并根据id进行升序排序
|
||||
List<OtherSysDepartment> rootDepList = departmentInfo
|
||||
.stream()
|
||||
.filter(item -> 0 == item.getHasChild() && -1 != item.getParentid())
|
||||
.sorted(Comparator.comparing(OtherSysDepartment::getId))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<Map<String, Object>> asyncOrgDep(int type) {
|
||||
if(CollectionUtils.isEmpty(asyncHrmSubCompany) || CollectionUtils.isEmpty(asyncHrmDepartment)){
|
||||
initWhiteList();
|
||||
List<Map<String, Object>> departmentInfoMap = orgHrmAsyncApiService.getDepartmentInfoMap();
|
||||
// 解析成树形
|
||||
List<Map<String, Object>> 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<Map<String, Object>> 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<Map<String, Object>> userInfo = orgHrmAsyncApiService.getUserInfo(topLevelOutKey);
|
||||
try {
|
||||
List<String> 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<Map<String, Object>> 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<>();
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("校验可用license数量失败! " + e.getMessage());
|
||||
}
|
||||
addHrmResourceMap(userInfo);
|
||||
List<OrgHrmAsyncConfigMain> hrmExtraConfig = hrmReSourceConfig.stream()
|
||||
.filter(item -> StringUtils.isNotBlank(item.getUpdateTableName())
|
||||
&& !"hrmresource".equalsIgnoreCase(item.getUpdateTableName()))
|
||||
.collect(Collectors.toList());
|
||||
threadPoolInstance.execute(()-> asyncExtraData(userInfo, hrmExtraConfig));
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>同步非树形的数据</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/14 15:14
|
||||
* @param list 接口数据
|
||||
* @param hrmSubCompany 分部数据
|
||||
* @param hrmDepartment 部门数据
|
||||
**/
|
||||
public void subDepIncrementDataAsync(List<Map<String, Object>> list, List<Map<String, Object>> hrmSubCompany, List<Map<String, Object>> hrmDepartment){
|
||||
for (Map<String, Object> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>处理分部与部门别的表同步数据</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/14 15:17
|
||||
**/
|
||||
public void asyncOrgExtraData(){
|
||||
List<OrgHrmAsyncConfigMain> subCompanyAsyncOtherConfig = subCompanyConfig.stream()
|
||||
.filter(item -> StringUtils.isNotBlank(item.getUpdateTableName()) && !"hrmsubcompany".equalsIgnoreCase(item.getUpdateTableName()))
|
||||
.collect(Collectors.toList());
|
||||
List<OrgHrmAsyncConfigMain> departOtherAsyncConfig = subCompanyConfig.stream()
|
||||
.filter(item -> StringUtils.isNotBlank(item.getUpdateTableName()) && !"hrmdepartment".equalsIgnoreCase(item.getUpdateTableName()))
|
||||
.collect(Collectors.toList());
|
||||
threadPoolInstance.execute(()->{
|
||||
// 同步部门其他表数据
|
||||
asyncExtraData(asyncHrmSubCompany, subCompanyAsyncOtherConfig);
|
||||
// 同步分部其他表数据
|
||||
asyncExtraData(asyncHrmDepartment, departOtherAsyncConfig);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>执行自定义表数据同步</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/13 13:20
|
||||
* @param data 数据
|
||||
* @param configs 同步配置
|
||||
**/
|
||||
public void asyncExtraData(List<Map<String, Object>> data, List<OrgHrmAsyncConfigMain> configs){
|
||||
for (OrgHrmAsyncConfigMain config : configs) {
|
||||
for (Map<String, Object> 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<String, Object> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>初始化配置表中部门与分部的白名单</h1>
|
||||
* @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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <h1>同步数据到分部</h1>
|
||||
*
|
||||
* @param departmentList 部门数据集合
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/6 13:37
|
||||
* @param departmentList 部门数据集合
|
||||
**/
|
||||
public void addHrmSubCompany(List<OtherSysDepartment> departmentList){
|
||||
//新增的分部id
|
||||
int subId;
|
||||
char separator = weaver.general.Util.getSeparator();
|
||||
RecordSet rsSch = new RecordSet();
|
||||
// 分部数据
|
||||
Map<Integer, Integer> 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);
|
||||
}
|
||||
}
|
||||
updateTable("HrmSubCompany", subId, 0, department);
|
||||
}
|
||||
//清除全部分部缓存
|
||||
sci.removeCompanyCache();
|
||||
public void addHrmSubCompanyMap(List<Map<String, Object>> departmentList) {
|
||||
List<OrgHrmAsyncConfigMain> 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<OtherSysDepartment> 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<Map<String, Object>> departmentList){
|
||||
List<OrgHrmAsyncConfigMain> collect = departmentConfig.stream().filter(item -> StringUtils.isBlank(item.getUpdateTableName())).collect(Collectors.toList());
|
||||
baseAddOrgDepByMap(departmentList, 1, departmentCache, collect.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>更新分部数据</h1>
|
||||
* <h1>同步数据到人员信息</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/6 13:35
|
||||
* @dateTime 2023/4/6 13:37
|
||||
* @param hrmList 部门数据集合
|
||||
**/
|
||||
public void addHrmResourceMap(List<Map<String, Object>> hrmList){
|
||||
List<OrgHrmAsyncConfigMain> hrmAsyncConf = hrmReSourceConfig.stream()
|
||||
.filter(item -> StringUtils.isBlank(item.getUpdateTableName()) || !"hrmresource".equalsIgnoreCase(item.getUpdateTableName()))
|
||||
.collect(Collectors.toList());
|
||||
baseAddOrgDepByMap(hrmList, 2, hrmCache, hrmAsyncConf.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>同步数据</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/12 10:36
|
||||
* @param dataList 集合
|
||||
* @param type 类型 0 分部 1 部门
|
||||
**/
|
||||
public void baseAddOrgDepByMap(List<Map<String, Object>> dataList,
|
||||
int type, Map<String, Integer> cache,
|
||||
OrgHrmAsyncConfigMain config){
|
||||
for (Map<String, Object> 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<String, Object> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取下一个分部id</h1>
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取下一个部门id</h1>
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取下一个人员id</h1>
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>执行存储过程</h1>
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>更新表数据</h1>
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param id 数据id
|
||||
* @param type 类型
|
||||
* @param o 对象
|
||||
* @param params 参数
|
||||
* @param type 操作类型 0: 更新 1: 新增
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/6 13:35
|
||||
**/
|
||||
public void updateTable(String tableName, int id, int type, Object o){
|
||||
StringBuilder sb = new StringBuilder("update ");
|
||||
sb.append(tableName).append(" set ");
|
||||
Map<String, Object> params;
|
||||
try {
|
||||
params = ShBigDataUtil.parseCusDbEntityMapping(type, o);
|
||||
}catch (Exception e){
|
||||
throw new CustomerException("parseCusDbEntityMapping error!");
|
||||
public boolean executeSql(String tableName, int id, Map<String, Object> params, int type) {
|
||||
return executeSql(tableName, id, params, type, "id");
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>更新表数据</h1>
|
||||
*
|
||||
* @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<String, Object> 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<String, Object> 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);
|
||||
sqlSb.deleteCharAt(sqlSb.length() - 1);
|
||||
if(type == 0){
|
||||
sqlSb.append(" where ")
|
||||
.append(primaryKey)
|
||||
.append(" = ")
|
||||
.append(id);
|
||||
}
|
||||
boolean success;
|
||||
if(type == 1){
|
||||
success = orgHrmAsyncMapper.insertHrmInfo(sqlSb.toString(), params);
|
||||
}else {
|
||||
success = orgHrmAsyncMapper.updateOrgInfo(sqlSb.toString(), params);
|
||||
}
|
||||
if (!success) {
|
||||
throw new CustomerException(Util.logStr("update {} sql error!", tableName));
|
||||
throw new CustomerException(operationType + tableName + " fail!");
|
||||
}
|
||||
//同步分部数据到矩阵
|
||||
MatrixUtil.updateSubcompayData(String.valueOf(id));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setChildList(List<OtherSysDepartment> departmentList){
|
||||
if(departmentList.size() == 0){
|
||||
return;
|
||||
|
||||
/**
|
||||
* <h1>解析部门or分部</h1>
|
||||
*
|
||||
* @param list 树形集合
|
||||
* @param n 层级
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/10 12:13
|
||||
**/
|
||||
public void asyncOrDepByTree(List<Map<String, Object>> list, int n, int maxLevel, List<Map<String, Object>> hrmSubCompany, List<Map<String, Object>> hrmDepartment) {
|
||||
n++;
|
||||
for (Map<String, Object> department : list) {
|
||||
department.put("level", n);
|
||||
List<Map<String, Object>> childList = (List<Map<String, Object>>) 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);
|
||||
}
|
||||
for (OtherSysDepartment department : departmentList) {
|
||||
List<OtherSysDepartment> childList = departmentList
|
||||
.stream()
|
||||
.filter(item -> department.getId() == item.getParentid())
|
||||
.collect(Collectors.toList());
|
||||
department.setChildList(childList);
|
||||
if (CollectionUtils.isNotEmpty(childList)) {
|
||||
setChildList(childList);
|
||||
childList.sort(orderByOrder.thenComparing(orderById));
|
||||
List<String> 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<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>解析部门or分部(方法弃用)</h1>
|
||||
*
|
||||
* @param list 树形集合
|
||||
* @param n 层级
|
||||
* @param hrmSubCompany 分部
|
||||
* @param hrmDepartment 部门
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/10 12:13
|
||||
**/
|
||||
@Deprecated
|
||||
public void parseSubCompanyAndDepartmentMap(List<Map<String, Object>> list, int n, int maxLevel, List<Map<String, Object>> hrmSubCompany, List<Map<String, Object>> hrmDepartment) {
|
||||
n++;
|
||||
for (Map<String, Object> department : list) {
|
||||
department.put("level", n);
|
||||
List<Map<String, Object>> childList = (List<Map<String, Object>>) department.get("childList");
|
||||
String departmentId = Util.null2DefaultStr(department.get("id"), "");
|
||||
if (CollectionUtils.isNotEmpty(childList)) {
|
||||
List<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>通过parentId将集合转成树</h1>
|
||||
*
|
||||
* @param list 接口返回集合
|
||||
* @return 树形结构
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/11 13:26
|
||||
**/
|
||||
public List<Map<String, Object>> convertListToTree(List<Map<String, Object>> list) {
|
||||
Map<Integer, Map<String, Object>> map = new HashMap<>();
|
||||
for (Map<String, Object> item : list) {
|
||||
map.put((Integer) item.get("id"), item);
|
||||
}
|
||||
// 构建树形结构
|
||||
List<Map<String, Object>> tree = new ArrayList<>();
|
||||
for (Map<String, Object> item : list) {
|
||||
int parentId = (Integer) item.get("parentid");
|
||||
if (parentId == -1) {
|
||||
// 添加根节点
|
||||
tree.add(item);
|
||||
} else {
|
||||
// 添加子节点
|
||||
Map<String, Object> parent = map.get(parentId);
|
||||
if (parent != null) {
|
||||
List<Map<String, Object>> childList = (List<Map<String, Object>>) parent.get("childList");
|
||||
if (childList == null) {
|
||||
childList = new ArrayList<>();
|
||||
parent.put("childList", childList);
|
||||
}
|
||||
childList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>组织架构-人员同步</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/4/11 15:48
|
||||
*/
|
||||
public class OrgHrmAsyncUtil {
|
||||
|
||||
/**
|
||||
* <h1>将接口数据按照建模配置转成map</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/11 18:21
|
||||
* @param orgHrmAsyncCache 缓存对象
|
||||
* @param hrmAsyncConfig 建模配置对象
|
||||
* @return 参数map
|
||||
**/
|
||||
public static Map<String, Object> convertInterfaceValToOA(OrgHrmAsyncCache orgHrmAsyncCache, OrgHrmAsyncConfigMain hrmAsyncConfig){
|
||||
return convertInterfaceValToOA(orgHrmAsyncCache, hrmAsyncConfig, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>将接口数据按照建模配置转成map</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/11 18:21
|
||||
* @param orgHrmAsyncCache 缓存对象
|
||||
* @param hrmAsyncConfig 建模配置对象
|
||||
* @return 参数map
|
||||
**/
|
||||
public static Map<String, Object> convertInterfaceValToOA(OrgHrmAsyncCache orgHrmAsyncCache, OrgHrmAsyncConfigMain hrmAsyncConfig, boolean addSystemParam){
|
||||
List<OrgHrmAsyncConfigDetail> configDetailList = hrmAsyncConfig.getOrgHrmAsyncConfigDetailList();
|
||||
LinkedHashMap<String, Object> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>将集合数据放到缓存中</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/10 18:33
|
||||
* @param listMap 集合数据
|
||||
**/
|
||||
public static HashMap<String, Integer> parseListMap2Map( List<Map<String, Integer>> listMap){
|
||||
return parseListMap2Map("outkey","id", listMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>将集合数据放到缓存中</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/10 18:33
|
||||
* @param listMap 集合数据
|
||||
**/
|
||||
public static HashMap<String, Integer> parseListMap2Map(String key, String value, List<Map<String, Integer>> listMap){
|
||||
if(CollectionUtils.isEmpty(listMap)){
|
||||
return new HashMap<>();
|
||||
}
|
||||
HashMap<String, Integer> 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<String, Object> res){
|
||||
String dateTime = TimeUtil.getCurrentTimeString();
|
||||
res.put("modifier", 1);
|
||||
res.put("modified", dateTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>值处理方法</h1>
|
||||
*
|
||||
* <p>create: 2023-02-02 15:15</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
|
||||
public class ValueRuleMethod {
|
||||
|
||||
|
||||
public static final Map<Integer, BiFunction<OrgHrmAsyncConfigDetail, OrgHrmAsyncCache, Object>> VALUE_RULE_FUNCTION = new HashMap<>();
|
||||
|
||||
private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class);
|
||||
|
||||
private final Logger log = Util.getLogger();
|
||||
|
||||
static {
|
||||
Class<ValueRuleMethod> 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<String, Object> 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<String> 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<String> 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<String, String> pathParam = Util.parseCusInterfacePathParam(cusText);
|
||||
return o.cusConvert(configDetail, cache, pathParam);
|
||||
}catch (Exception e){
|
||||
log.error("getCusConvertInterface error! " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>从缓存中找数据</h1>
|
||||
* @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<String, Object> interfaceVal, OrgHrmAsyncCache cache, String oaField, String interfaceFieldVal){
|
||||
Map<String, Integer> subCompanyCache = cache.getSubCompanyCache();
|
||||
Map<String, Integer> 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<String, Integer> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package weaver.xuanran.wang.sh_bigdata.org_hrm_async.util;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* <h1>值处理方法编号注解</h1>
|
||||
*
|
||||
* <p>create: 2023-02-02 15:18</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface ValueRuleMethodNo {
|
||||
int value();
|
||||
String desc();
|
||||
}
|
|
@ -19,5 +19,5 @@ public class CusDoneTask {
|
|||
@SqlFieldMapping
|
||||
private String taskNum;
|
||||
private int status;
|
||||
private String appId;
|
||||
private String agentid;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -33,4 +33,6 @@ public class StudentClass {
|
|||
**/
|
||||
@SqlFieldMapping()
|
||||
private int belongYear;
|
||||
@SqlFieldMapping()
|
||||
private String teacherId;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Object> dataList = new ArrayList<>();
|
||||
ArrayList<String> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>数据同步</h1>
|
||||
* @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<Object> dataList = new ArrayList<>();
|
||||
ArrayList<String> 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("更新删除状态失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取token</h1>
|
||||
* @author xuanran.wang
|
||||
|
|
|
@ -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<String, Integer> 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);
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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??????????
|
||||
# 统一待办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=
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
*
|
||||
* @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<String> departmentWhiteList;
|
||||
private final List<String> subCompanyWhiteList;
|
||||
private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class);
|
||||
|
||||
{
|
||||
departmentWhiteList = orgHrmAsyncMapper.selectCusDepart();
|
||||
subCompanyWhiteList = orgHrmAsyncMapper.selectCusSubCompany();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testA() throws IOException {
|
||||
// List<OtherSysDepartment> rootDepList = departmentInfo
|
||||
// .stream()
|
||||
// .filter(item -> 1 == item.getHasChild())
|
||||
// .sorted(Comparator.comparing(OtherSysDepartment::getId))
|
||||
// .collect(Collectors.toList());
|
||||
// for (OtherSysDepartment department : rootDepList) {
|
||||
// setChildList(department, departmentInfo);
|
||||
// }
|
||||
// List<OtherSysDepartment> departmentInfo = orgHrmAsyncApiService.getDepartmentInfo();
|
||||
// List<OtherSysDepartment> 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<OtherSysDepartment> hrmSubCompany = new ArrayList<>();
|
||||
// List<OtherSysDepartment> 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> T parseRes(Map<String, Object> 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<Map<String, Object>> list = orgHrmAsyncApiService.getDepartmentInfoMap();
|
||||
// 将列表转换为以id为键的Map
|
||||
List<Map<String, Object>> tree = convertListToTree(list);
|
||||
List<Map<String, Object>> department = new ArrayList<>();
|
||||
List<Map<String, Object>> 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<OrgHrmAsyncConfigMain> orgHrmAsyncConfigMains = orgHrmAsyncMapper.selectSubCompanyAsyncConfig(2);
|
||||
// System.out.println(JSONObject.toJSONString(orgHrmAsyncConfigMains));
|
||||
ArrayList<String> 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<Map<String, Object>> convertListToTree(List<Map<String, Object>> list){
|
||||
Map<Integer, Map<String, Object>> map = new HashMap<>();
|
||||
for (Map<String, Object> item : list) {
|
||||
map.put((Integer) item.get("id"), item);
|
||||
}
|
||||
|
||||
// 构建树形结构
|
||||
List<Map<String, Object>> tree = new ArrayList<>();
|
||||
for (Map<String, Object> item : list) {
|
||||
int parentId = (Integer) item.get("parentid");
|
||||
if (parentId == -1) {
|
||||
// 添加根节点
|
||||
tree.add(item);
|
||||
} else {
|
||||
// 添加子节点
|
||||
Map<String, Object> parent = map.get(parentId);
|
||||
if (parent != null) {
|
||||
List<Map<String, Object>> childList = (List<Map<String, Object>>) 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<OtherSysDepartment> childList = node.getChildList();
|
||||
if (CollectionUtils.isNotEmpty(childList)) {
|
||||
for (OtherSysDepartment otherSysDepartment : childList) {
|
||||
count += countNodes(otherSysDepartment);
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public int countNodes(Map<String, Object> node) {
|
||||
int count = 1; // 当前节点也算一条数据
|
||||
List<Map<String, Object>> childList = (List<Map<String, Object>>) node.get("childList");
|
||||
if (CollectionUtils.isNotEmpty(childList)) {
|
||||
for (Map<String, Object> map : childList) {
|
||||
count += countNodes(map);
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>解析部门or分部</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/10 12:13
|
||||
* @param list 树形集合
|
||||
* @param hrmDepartment 部门
|
||||
**/
|
||||
public void parseSubCompanyAndDepartment(List<OtherSysDepartment> list, List<OtherSysDepartment> hrmDepartment){
|
||||
for (OtherSysDepartment department : list) {
|
||||
List<OtherSysDepartment> childList = department.getChildList();
|
||||
if(CollectionUtils.isNotEmpty(childList)){
|
||||
parseSubCompanyAndDepartment(childList,hrmDepartment);
|
||||
department.setChildList(null);
|
||||
}
|
||||
hrmDepartment.add(department);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>解析部门or分部</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/4/10 12:13
|
||||
* @param list 树形集合
|
||||
* @param n 层级
|
||||
* @param hrmSubCompany 分部
|
||||
* @param hrmDepartment 部门
|
||||
**/
|
||||
public void parseSubCompanyAndDepartment(List<OtherSysDepartment> list, int n, int maxLevel,List<OtherSysDepartment> hrmSubCompany, List<OtherSysDepartment> hrmDepartment){
|
||||
n++;
|
||||
for (OtherSysDepartment department : list) {
|
||||
department.setLevel(n);
|
||||
List<OtherSysDepartment> childList = department.getChildList();
|
||||
String departmentId = department.getId() + "";
|
||||
if(CollectionUtils.isNotEmpty(childList)){
|
||||
List<String> 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> T getObj(String dataKey, Map<String, Object> 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 = "<!DOCTYPE html>\n" +
|
||||
"<html>\n" +
|
||||
"<head>\n" +
|
||||
"\t<title>Investment Calculator</title>\n" +
|
||||
"\t<style>\n" +
|
||||
"\t\ttable {\n" +
|
||||
"\t\t\tborder-collapse: collapse;\n" +
|
||||
"\t\t\twidth: 80%;\n" +
|
||||
"\t\t\tmargin: 0 auto;\n" +
|
||||
"\t\t\tmargin-top: 50px;\n" +
|
||||
"\t\t\tmargin-bottom: 50px;\n" +
|
||||
"\t\t}\n" +
|
||||
"\t\tth, td {\n" +
|
||||
"\t\t\tborder: 1px solid black;\n" +
|
||||
"\t\t\tpadding: 10px;\n" +
|
||||
"\t\t\ttext-align: center;\n" +
|
||||
"\t\t}\n" +
|
||||
"\t\tth {\n" +
|
||||
"\t\t\tbackground-color: #f2f2f2;\n" +
|
||||
"\t\t}\n" +
|
||||
"\t\t.first-row {\n" +
|
||||
"\t\t\ttext-align: center;\n" +
|
||||
"\t\t\tfont-size: 24px;\n" +
|
||||
"\t\t\tfont-weight: bold;\n" +
|
||||
"\t\t\theight: 50px;\n" +
|
||||
"\t\t\tline-height: 50px;\n" +
|
||||
"\t\t}\n" +
|
||||
"\t</style>\n" +
|
||||
"</head>\n" +
|
||||
"<body>\n" +
|
||||
"\t<table>\n" +
|
||||
"\t\t<tr class=\"first-row\">\n" +
|
||||
"\t\t\t<td colspan=\"26\">投资试算(场外基金)</td>\n" +
|
||||
"\t\t</tr>\n" +
|
||||
"\t\t<tr>\n" +
|
||||
"\t\t\t<td>A</td>\n" +
|
||||
"\t\t\t<td>B</td>\n" +
|
||||
"\t\t\t<td>C</td>\n" +
|
||||
"\t\t\t<td>D</td>\n" +
|
||||
"\t\t\t<td>E</td>\n" +
|
||||
"\t\t\t<td>F</td>\n" +
|
||||
"\t\t\t<td>G</td>\n" +
|
||||
"\t\t\t<td>H</td>\n" +
|
||||
"\t\t\t<td>I</td>\n" +
|
||||
"\t\t\t<td>J</td>\n" +
|
||||
"\t\t\t<td>K</td>\n" +
|
||||
"\t\t\t<td>L</td>\n" +
|
||||
"\t\t\t<td>M</td>\n" +
|
||||
"\t\t\t\n" +
|
||||
"\t\t</tr>\n" +
|
||||
"\t\t<tr>\n" +
|
||||
"\t\t\t<td>Cell A1</td>\n" +
|
||||
"\t\t\t<td>Cell B1</td>\n" +
|
||||
"\t\t\t<td>Cell C1</td>\n" +
|
||||
"\t\t\t<td>Cell D1</td>\n" +
|
||||
"\t\t\t<td>Cell E1</td>\n" +
|
||||
"\t\t\t<td>Cell F1</td>\n" +
|
||||
"\t\t\t<td>Cell G1</td>\n" +
|
||||
"\t\t\t<td>Cell H1</td>\n" +
|
||||
"\t\t\t<td>Cell I1</td>\n" +
|
||||
"\t\t\t<td>Cell J1</td>\n" +
|
||||
"\t\t\t<td>Cell K1</td>\n" +
|
||||
"\t\t\t<td>Cell L1</td>\n" +
|
||||
"\t\t\t<td>Cell M1</td>\n" +
|
||||
"\t\t\n" +
|
||||
"\t\t</tr>\n" +
|
||||
" \t</table>\n" +
|
||||
" </body>\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<String, Object> param = new HashMap<>();
|
||||
// param.put("test1","04");
|
||||
// String s = orgHrmAsyncMapper.selectCustomerSql(sql, param);
|
||||
// System.out.println("s => " + s);
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("tiem", new Date());
|
||||
System.out.println("map => " + JSONObject.toJSONString(map));
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
*
|
||||
* @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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
// "<SIP>\n" +
|
||||
// "\t<PackageDescription>\n" +
|
||||
// "\t\t<PackageFormat>EIPPACK</PackageFormat>\t\t\n" +
|
||||
// "\t\t<PackageName>P-TC____-20190821144756-1</PackageName><!-- 和文件名一致 --> \n" +
|
||||
// "\t\t<SystemCode>TC</SystemCode><!-- 给业务系统分配的系统编码 --> \n" +
|
||||
// "\t\t<BusinessCode>TC</BusinessCode><!-- 给业务系统分配的业务编码,默认与系统编码一致 --> \n" +
|
||||
// "\t\t<BusinessType>主机厂文件</BusinessType><!-- 业务类型 --> \n" +
|
||||
// "\t\t<PackageLevel>1</PackageLevel><!-- 传递的层级,1:卷内级。2:案卷级。3:项目级。 --> \n" +
|
||||
// "\t</PackageDescription>\n" +
|
||||
// "\t<Package>\n" +
|
||||
// "\t\t<ContentDescription><!-- 双方确定的字段描述,接口只做归档,不做逻辑判断,所以归档前需要完成业务逻辑操作。像题名需要项目编号和项目名称合起来,这个操作需要在归档前进行,如果放在接口放来操作,就会破坏了接口的通用性。--> \n" +
|
||||
// "\t\t\t<公司代码>1001</公司代码>\n" +
|
||||
// "\t\t\t<流程id>2341234123j8jhsu</流程id>\n" +
|
||||
// "\t\t\t<题名>我是用来测试归档接口123</题名>\n" +
|
||||
// "\t\t\t<文号>[xin]129号</文号>\n" +
|
||||
// "\t\t\t<成文日期>20230301</成文日期>\n" +
|
||||
// "\t\t\t<主机厂名称>红旗</主机厂名称>\n" +
|
||||
// "\t\t</ContentDescription>\n" +
|
||||
// "\t\t<Content><!-- 电子文件描述信息,案卷级或者项目级可以不传这个节点 --> \n" +
|
||||
// "\t\t\t<FileDescription>\n" +
|
||||
// "\t\t\t\t<OriginalFileName>1.pdf</OriginalFileName><!-- 电子文件的原始文件名(带后缀) --> \n" +
|
||||
// "\t\t\t\t<DocumentType>OA审批结果</DocumentType><!-- 文档类型(双方讨论确定) --> \n" +
|
||||
// "\t\t\t\t<FileSize>81098</FileSize><!-- 电子文件大小 --> \n" +
|
||||
// "\t\t\t\t<FileTimeStamp>20190821144756</FileTimeStamp><!-- 电子文件时间戳(可以是创建时间) --> \n" +
|
||||
// "\t\t\t\t<FileChecksum>05cc9c29599ae67cf545fe380d679326</FileChecksum><!-- 电子文件MD5 --> \n" +
|
||||
// "\t\t\t\t<FileFormat>pdf</FileFormat><!-- 电子文件后缀 --> \n" +
|
||||
// "\t\t\t\t<FileName>1.pdf</FileName>\n" +
|
||||
// "\t\t\t</FileDescription>\n" +
|
||||
// "\t\t\t<FileDescription>\n" +
|
||||
// "\t\t\t\t<OriginalFileName>1.pdf</OriginalFileName><!-- 电子文件的原始文件名(带后缀) --> \n" +
|
||||
// "\t\t\t\t<DocumentType>OA审批结果</DocumentType><!-- 文档类型(双方讨论确定) --> \n" +
|
||||
// "\t\t\t\t<FileSize>81098</FileSize><!-- 电子文件大小 --> \n" +
|
||||
// "\t\t\t\t<FileTimeStamp>20190821144756</FileTimeStamp><!-- 电子文件时间戳(可以是创建时间) --> \n" +
|
||||
// "\t\t\t\t<FileChecksum>05cc9c29599ae67cf545fe380d679326</FileChecksum><!-- 电子文件MD5 --> \n" +
|
||||
// "\t\t\t\t<FileFormat>pdf</FileFormat><!-- 电子文件后缀 --> \n" +
|
||||
// "\t\t\t\t<FileName>1.pdf</FileName>\n" +
|
||||
// "\t\t\t</FileDescription>\n" +
|
||||
// "\t\t</Content>\n" +
|
||||
// "\t</Package>\n" +
|
||||
// "</SIP>\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<String, Object> map = new HashMap<>();
|
||||
// map.put("success", false);
|
||||
// HashMap<String, Object> 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> T getResponse(CusSuccess cusSuccess, Map<String, Object> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
*
|
||||
* @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<Map<String, Object>> list = new ArrayList<>();
|
||||
HashMap<String, Object> param = new HashMap<>();
|
||||
param.put("reqId",222222222);
|
||||
param.put("requestXml","");
|
||||
list.add(param);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put("reqId",i + "1232");
|
||||
params.put("requestXml", UUID.randomUUID().toString());
|
||||
list.add(params);
|
||||
}
|
||||
List<String> strings = CusData2OA.batchWriteToModel(modelId, sql, list);
|
||||
System.out.println("data => " + strings);
|
||||
}
|
||||
}
|
|
@ -324,7 +324,15 @@ public class MQTest extends BaseTest {
|
|||
|
||||
}
|
||||
|
||||
private final SendTodoTaskMapper sendTodoTaskMapper = Util.getMapper(SendTodoTaskMapper.class);
|
||||
|
||||
@Test
|
||||
public void testE(){
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("146723321680844588");
|
||||
list.add("146723321680844588");
|
||||
sendTodoTaskMapper.updateStatusByTaskNum(list);
|
||||
}
|
||||
SendTodoTaskUtil sendTodoTaskUtil = new SendTodoTaskUtil();
|
||||
@Test
|
||||
public void testToken(){
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
*
|
||||
* @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<String, Object> param = new HashMap<>();
|
||||
HashMap<String, Object> param2 = new HashMap<>();
|
||||
List<Map<String, Object>> 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);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue