From dfc89e7d210806863e31d9d30cc90ffd46aa749b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=A3=E7=84=B6?= Date: Sun, 12 Feb 2023 21:08:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=8F=E7=BE=8E=E6=B5=81=E6=B0=B4=E5=88=9B?= =?UTF-8?q?=E5=BB=BA,=E5=9B=A2=E6=A0=A1mq=E4=BB=A3=E7=A0=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CheckUserController.java | 4 +- .../checkuser/service/CheckUserService.java | 51 +++--- .../bme/action/CusCreateWaterNoAction.java | 104 +++++++++--- .../wang/common/annocation/ParamPrint.java | 18 ++ .../common/annocation/SqlFieldMapping.java | 18 ++ .../annocation/SqlUpdateWhereField.java | 18 ++ .../xuanran/wang/common/util/CommonUtil.java | 14 +- .../wang/common/util/CusInfoToOAUtil.java | 88 +++++++++- .../wang/shyl/dataasync/entity/Student.java | 36 ++++ .../shyl/dataasync/entity/StudentClass.java | 36 ++++ .../shyl/dataasync/job/CusDataAsyncJob.java | 113 +++++++++++++ .../service/CusDataAsyncService.java | 159 ++++++++++++++++++ .../xuanran/wang/shyl/mq/RocketMQFactory.java | 38 ++--- .../wang/shyl/mq/action/ProducerAction.java | 15 +- .../shyl/mq/constant/RocketMQConstant.java | 1 + .../wang/shyl/mq/mapper/ConsumerMapper.java | 20 ++- .../shyl/mq/service/CusInfoActionService.java | 10 +- .../wang/shyl/mq/service/ProducerService.java | 11 +- .../shyl/mq/service/impl/OrgServiceImpl.java | 8 +- .../shyl/mq/service/impl/UserServiceImpl.java | 8 +- .../xuanran/wang/shyl/mq/util/RocketUtil.java | 43 +++-- .../WEB-INF/prop/prop2map/OACar.properties | 4 + .../WEB-INF/prop/prop2map/OAMeal.properties | 4 + .../prop/prop2map/OAMeeting.properties | 4 + .../prop/prop2map/OAVisitor.properties | 4 + .../prop/prop2map/OrgConsumer.properties | 4 + .../prop/prop2map/PassWordConsumer.properties | 4 + .../prop/prop2map/UserInfoConsumer.properties | 4 + .../wang/ambofo/checkuser/CheckUserTest.java | 2 +- .../wang/shyl/dataasync/AsyncTest.java | 94 +++++++++++ src/test/resources/ application.properties | 0 31 files changed, 820 insertions(+), 117 deletions(-) create mode 100644 src/main/java/weaver/xuanran/wang/common/annocation/ParamPrint.java create mode 100644 src/main/java/weaver/xuanran/wang/common/annocation/SqlFieldMapping.java create mode 100644 src/main/java/weaver/xuanran/wang/common/annocation/SqlUpdateWhereField.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/Student.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/StudentClass.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/dataasync/job/CusDataAsyncJob.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/dataasync/service/CusDataAsyncService.java create mode 100644 src/main/resources/WEB-INF/prop/prop2map/OACar.properties create mode 100644 src/main/resources/WEB-INF/prop/prop2map/OAMeal.properties create mode 100644 src/main/resources/WEB-INF/prop/prop2map/OAMeeting.properties create mode 100644 src/main/resources/WEB-INF/prop/prop2map/OAVisitor.properties create mode 100644 src/main/resources/WEB-INF/prop/prop2map/OrgConsumer.properties create mode 100644 src/main/resources/WEB-INF/prop/prop2map/PassWordConsumer.properties create mode 100644 src/main/resources/WEB-INF/prop/prop2map/UserInfoConsumer.properties create mode 100644 src/test/java/xuanran/wang/shyl/dataasync/AsyncTest.java delete mode 100644 src/test/resources/ application.properties diff --git a/src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java index d33caa7..ab3a016 100644 --- a/src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java +++ b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java @@ -13,6 +13,7 @@ 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; /** *

安波福从AD域中校验用户是否存在

@@ -32,8 +33,7 @@ public class CheckUserController { String checkContent = request.getParameter("checkContent"); try { CheckUserService checkUserService = new CheckUserService(); - boolean has = checkUserService.checkADHasUser(checkContent); - return ApiResult.success(has,"ok"); + return ApiResult.success(checkUserService.checkADHasUser(checkContent),"ok"); }catch (Exception e){ String error = Util.logStr("AD查询接口发生异常:{}", e.getMessage()); log.error(error); diff --git a/src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java index 1ced546..df6393e 100644 --- a/src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java +++ b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java @@ -9,10 +9,13 @@ import org.apache.log4j.Logger; import javax.naming.Context; import javax.naming.NamingEnumeration; import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; import javax.naming.ldap.InitialLdapContext; import javax.naming.ldap.LdapContext; +import java.util.HashMap; import java.util.Hashtable; import java.util.Map; @@ -37,7 +40,6 @@ public class CheckUserService { if(MapUtils.isEmpty(ADConfig)){ throw new CustomerException("请检查/filesystem/prop/prop2map 文件夹下是否存在AmbofoADConfig.properties文件!"); } - log.info(Util.logStr("AD配置对象 : [{}]", JSONObject.toJSONString(ADConfig))); } @@ -46,9 +48,9 @@ public class CheckUserService { * @author xuanran.wang * @dateTime 2022/12/12 15:22 * @param checkInfo 校验内容 - * @return true/false 有/没有 + * @return map 人员信息 mail:****,userName **/ - public boolean checkADHasUser(String checkInfo) { + public Map checkADHasUser(String checkInfo) { //连接到AD LdapContext ldapContext = login(); try { @@ -66,39 +68,24 @@ public class CheckUserService { NamingEnumeration answer = ldapContext.search(searchBase, searchFilter, searchControl); boolean has = answer.hasMoreElements(); log.info("has " + has); + HashMap res = new HashMap<>(); if(has){ SearchResult sr = (SearchResult) answer.next(); - String dn = sr.getName(); - log.info("dn " + dn); +// String dn = sr.getName(); + NamingEnumeration attrs = sr.getAttributes().getAll(); + while (attrs.hasMore()) { + Attribute attr = attrs.next(); + String id = attr.getID(); + Object value = attr.get(); + if("mail".equals(id)){ + res.put("mail", value); + }else if ("displayName".equals(id)){ + res.put("userName", value); + } + } } // 初始化搜索结果数为0 - return has; - } catch (NamingException e) { - throw new CustomerException(Util.logStr("从AD搜索用户异常:[{}]",e.getMessage())); - } finally { - close(ldapContext); - } - } - - public void logAllUser() { - //连接到AD - LdapContext ldapContext = login(); - try { - // 域节点 - String searchBase = Util.null2String(ADConfig.get("searchBase")); - // LDAP搜索过滤器类 cn=*name*模糊查询 cn=name 精确查询 String searchFilter = "(objectClass="+type+")"; - // 创建搜索控制器 - SearchControls searchControl = new SearchControls(); - // 设置搜索范围 深度 - searchControl.setSearchScope(SearchControls.SUBTREE_SCOPE); - // 根据设置的域节点、过滤器类和搜索控制器搜索LDAP得到结果 - NamingEnumeration answer = ldapContext.search(searchBase, "", searchControl); - //4. 获取查询的内容 - while (answer.hasMoreElements()) { - SearchResult sr = (SearchResult) answer.next(); - String dn = sr.getName(); - log.info("dn " + dn); - } + return res; } catch (NamingException e) { throw new CustomerException(Util.logStr("从AD搜索用户异常:[{}]",e.getMessage())); } finally { diff --git a/src/main/java/weaver/xuanran/wang/bme/action/CusCreateWaterNoAction.java b/src/main/java/weaver/xuanran/wang/bme/action/CusCreateWaterNoAction.java index ca7d9eb..e129c0b 100644 --- a/src/main/java/weaver/xuanran/wang/bme/action/CusCreateWaterNoAction.java +++ b/src/main/java/weaver/xuanran/wang/bme/action/CusCreateWaterNoAction.java @@ -2,8 +2,11 @@ package weaver.xuanran.wang.bme.action; import aiyh.utils.Util; import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.PrintParamMark; import aiyh.utils.annotation.RequiredMark; import aiyh.utils.excention.CustomerException; +import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl; +import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSet; import weaver.conn.RecordSetTrans; import weaver.hrm.User; @@ -11,7 +14,9 @@ import weaver.soa.workflow.request.RequestInfo; import weaver.xuanran.wang.common.util.CommonUtil; import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; /** @@ -29,20 +34,42 @@ public class CusCreateWaterNoAction extends SafeCusBaseAction { *

存货分类编码字段

**/ @RequiredMark + @PrintParamMark private String invClassificationCode; /** *

存货编码 生成编号后写入这个字段

**/ @RequiredMark + @PrintParamMark private String inventoryCode; /** *

生成流水号日志记录模块id

**/ + @RequiredMark + @PrintParamMark private String serialNumberModelId; - private static final String START_NO = "0101"; + /** + *

明细表下标 如果配置了就会把主表生成的存货编码复制到明细表中

+ **/ + @PrintParamMark + private String detailIndex; + + /** + *

明细表存货编码字段名

+ **/ + @PrintParamMark + private String detailInventoryCode; + + /** + *

创建流水的条件

+ **/ + @PrintParamMark + private String createWhere; + + private static final String START_NO = "01.01"; @Override public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { @@ -50,6 +77,19 @@ public class CusCreateWaterNoAction extends SafeCusBaseAction { RecordSetTrans rsts = new RecordSetTrans(); rsts.setAutoCommit(false); try { + RecordSet rs = new RecordSet(); + String sql = " select id from " + billTable + " where requestid = ? "; + if(StringUtils.isNotBlank(createWhere)){ + sql += " and " + createWhere; + } + String mainId = ""; + if(rs.executeQuery(sql, requestId) && rs.next()) { + mainId = Util.null2DefaultStr(rs.getString(1),""); + } + if(StringUtils.isBlank(mainId)){ + log.info(Util.logStr("本条流程跳过生成编号!当前sql:{}", sql)); + return; + } Map mainTableValue = getMainTableValue(requestInfo); String invClassificationCodeVal = mainTableValue.get(invClassificationCode); String nextInventoryCode = getNextInventoryCode(invClassificationCodeVal); @@ -58,7 +98,24 @@ public class CusCreateWaterNoAction extends SafeCusBaseAction { log.error(Util.logStr("sql :{}, nextInventoryCode : {}, requestId: {}", updateSql, nextInventoryCode, requestId)); throw new CustomerException("更新表单存货编码字段失败!"); } + // 将主表的存货编码插入到明细表中 + if(StringUtils.isNotBlank(detailIndex) + && StringUtils.isNotBlank(mainId) + && StringUtils.isNotBlank(detailInventoryCode)){ + Map detailParams = new HashMap<>(); + detailParams.put("mainid", mainId); + detailParams.put(detailInventoryCode, nextInventoryCode); + PrepSqlResultImpl insertSql = Util.createSqlBuilder().insertSql(billTable + "_dt" + detailIndex, detailParams); + String sqlStr = insertSql.getSqlStr(); + List args = insertSql.getArgs(); + if(!rsts.executeUpdate(sqlStr, args)){ + log.error(Util.logStr("明细表插入sql:{}, 参数:{}", sqlStr, args)); + throw new CustomerException("插入明细表数据失败!"); + } + } + rsts.commit(); }catch (Exception e){ + rsts.rollback(); throw new CustomerException(Util.logStr("生成存货编码Action异常: [{}]",e.getMessage())); } } @@ -73,38 +130,43 @@ public class CusCreateWaterNoAction extends SafeCusBaseAction { private synchronized String getNextInventoryCode(String inventoryCode){ RecordSet rs = new RecordSet(); String modelTableName = CommonUtil.getModelTableNameById(Util.getIntValue(serialNumberModelId, -1)); - String sql = "select max(serialNumber) serialNumber from " + modelTableName + " where invClassificationCode = ? order by createDateTime"; + String sql = "select max(serialNumber) serialNumber from " + modelTableName + " where invClassificationCode = ?"; String res = ""; if(rs.executeQuery(sql, inventoryCode)){ if (!rs.next()) { - res = inventoryCode + START_NO; + res = START_NO; }else { String serialNumber = rs.getString(1); - String front = serialNumber.substring(0,2); - String end = serialNumber.substring(3); - int frontInt = Util.getIntValue(front); - int endInt = Util.getIntValue(end); - String endStr = ""; - String frontStr = ""; - if(++endInt >= 100){ - frontInt += 1; - endInt = 1; + if(StringUtils.isBlank(serialNumber)){ + res = START_NO; + }else { + String front = serialNumber.substring(0,2); + String end = serialNumber.substring(3); + int frontInt = Util.getIntValue(front); + int endInt = Util.getIntValue(end); + String endStr = ""; + String frontStr = ""; + if(++endInt >= 100){ + frontInt += 1; + endInt = 1; + } + if(endInt < 10){ + endStr = "0" + endInt; + } + if(frontInt < 10){ + frontStr = "0" + frontInt; + } + res = frontStr + "." + endStr; } - if(endInt < 10){ - endStr = "0" + endInt; - } - if(frontInt < 10){ - frontStr = "0" + frontInt; - } - res = frontStr + endStr; } } LinkedHashMap map = new LinkedHashMap<>(); + String serialCode = inventoryCode + "." + res; map.put("invClassificationCode", inventoryCode); map.put("serialNumber", res); - map.put("serialCode", inventoryCode + res); + map.put("serialCode", serialCode); CusInfoToOAUtil.getDataId(Util.getIntValue(serialNumberModelId, -1), map); - return res; + return serialCode; } diff --git a/src/main/java/weaver/xuanran/wang/common/annocation/ParamPrint.java b/src/main/java/weaver/xuanran/wang/common/annocation/ParamPrint.java new file mode 100644 index 0000000..6b0b50d --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/common/annocation/ParamPrint.java @@ -0,0 +1,18 @@ +package weaver.xuanran.wang.common.annocation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

参数打印

+ * + * @author xuanran.wang + * @date 2023/2/9 13:37 + */ +@Target({ElementType.FIELD,ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface ParamPrint { + boolean value() default true; +} diff --git a/src/main/java/weaver/xuanran/wang/common/annocation/SqlFieldMapping.java b/src/main/java/weaver/xuanran/wang/common/annocation/SqlFieldMapping.java new file mode 100644 index 0000000..52a34ab --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/common/annocation/SqlFieldMapping.java @@ -0,0 +1,18 @@ +package weaver.xuanran.wang.common.annocation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

实体类-数据库字段映射

+ * + * @author xuanran.wang + * @date 2023/2/9 11:12 + */ +@Target({ElementType.FIELD,ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface SqlFieldMapping { + String value() default ""; +} diff --git a/src/main/java/weaver/xuanran/wang/common/annocation/SqlUpdateWhereField.java b/src/main/java/weaver/xuanran/wang/common/annocation/SqlUpdateWhereField.java new file mode 100644 index 0000000..afcd0db --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/common/annocation/SqlUpdateWhereField.java @@ -0,0 +1,18 @@ +package weaver.xuanran.wang.common.annocation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

数据库主键

+ * + * @author xuanran.wang + * @date 2023/2/9 11:13 + */ +@Target({ElementType.FIELD,ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface SqlUpdateWhereField { + boolean value() default false; +} diff --git a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java index ef493ae..2ddb52d 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java @@ -3,7 +3,6 @@ package weaver.xuanran.wang.common.util; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; import com.alibaba.fastjson.JSONObject; -import com.weaverboot.tools.logTools.LogTools; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.io.FileUtils; @@ -16,13 +15,11 @@ import weaver.xiao.commons.config.entity.RequestMappingConfig; import weaver.xiao.commons.config.service.DealWithMapping; import weaver.xuanran.wang.common.annocation.CusDateFormat; import weaver.xuanran.wang.common.annocation.ParamNotNull; +import weaver.xuanran.wang.common.annocation.ParamPrint; import weaver.xuanran.wang.common.mapper.CommonMapper; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; import java.io.*; import java.lang.reflect.Field; -import java.net.URLEncoder; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; @@ -199,6 +196,7 @@ public class CommonUtil { public static void checkParamNotNull(T t){ Class clazz = t.getClass(); Field[] fields = clazz.getDeclaredFields(); + HashMap printParams = new HashMap<>(); for (Field field : fields) { ParamNotNull paramNotNull = field.getDeclaredAnnotation(ParamNotNull.class); if(paramNotNull == null){ @@ -231,6 +229,14 @@ public class CommonUtil { if(isNull){ throw new CustomerException("classPath : [ " + clazz.getName() + " ], field : [ " + field.getName() + " ] is not be null!"); } + ParamPrint printAnno = field.getAnnotation(ParamPrint.class); + if(null == printAnno || !printAnno.value()){ + continue; + } + printParams.put(field.getName(), value); + } + if(MapUtils.isNotEmpty(printParams)){ + logger.info("params : \n " + JSONObject.toJSONString(printParams)); } } diff --git a/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java index 125fd16..0496f10 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java @@ -13,8 +13,11 @@ import weaver.conn.RecordSet; import weaver.formmode.data.ModeDataIdUpdate; import weaver.formmode.setup.ModeRightInfo; import weaver.general.TimeUtil; +import weaver.xuanran.wang.common.annocation.SqlFieldMapping; +import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField; import weaver.xuanran.wang.common.mapper.CommonMapper; +import java.lang.reflect.Field; import java.util.*; import java.util.stream.Collectors; @@ -136,16 +139,69 @@ public class CusInfoToOAUtil { List> whereParams, boolean needDel, List> updateParams) { - if(modelId < 0){ - throw new RuntimeException("建模模块id不能小于0!"); - } - String tableName = commonMapper.getModelNameByModelId(String.valueOf(modelId)); - if(StringUtils.isBlank(tableName)){ - throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!"); - } + String tableName = checkModelId(modelId); return executeBatch(modelId, tableName, params, whereSql, whereParams, needDel, updateParams); } + + /** + *

将实体类数据插入到建模表中

+ * @author xuanran.wang + * @dateTime 2023/2/9 11:51 + * @param modelId 模块id + * @param list 插入参数集合 + * @param whereSql 更新条件 + * @return 建模数据id + **/ + public static List executeBatchByEntity(int modelId, List list, String whereSql){ + String tableName = checkModelId(modelId); + List> params = new ArrayList<>(); + List> whereParams = new ArrayList<>(); + for (Object o : list) { + if(Objects.isNull(o)){ + continue; + } + Class clazz = o.getClass(); + Field[] fields = clazz.getDeclaredFields(); + LinkedHashMap linkedHashMap = new LinkedHashMap<>(); + ArrayList whereParam = new ArrayList<>(); + for (Field field : fields) { + field.setAccessible(true); + String fieldName = field.getName(); + Object fieldValue; + try { + fieldValue = field.get(o); + } catch (IllegalAccessException e) { + throw new CustomerException(Util.logStr("field get error! the error is :[{}]," + + "current field is: [{}], current obj is: [{}]", e.getMessage(), fieldName, JSONObject.toJSONString(o))); + } + if(Objects.isNull(fieldValue)){ + continue; + } + // 数据库字段映射 如果注解中没有值那么写入数据库就是实体类字段名 + SqlFieldMapping sqlFieldMapping = field.getAnnotation(SqlFieldMapping.class); + if(null == sqlFieldMapping){ + continue; + } + String sqlFieldMappingValue = sqlFieldMapping.value(); + if(StringUtils.isNotBlank(sqlFieldMappingValue)){ + fieldName = sqlFieldMappingValue; + } + linkedHashMap.put(fieldName, fieldValue); + + // 更新条件字段注解 + SqlUpdateWhereField sqlUpdateWhereField = field.getAnnotation(SqlUpdateWhereField.class); + if(null == sqlUpdateWhereField || !sqlUpdateWhereField.value()){ + continue; + } + whereParam.add(fieldValue.toString()); + } + params.add(linkedHashMap); + whereParams.add(whereParam); + } + return executeBatch(modelId, tableName, params, whereSql, whereParams, true, new ArrayList<>()); + } + /** *

将自定义信息写入建模

* @author xuanran.wang @@ -303,4 +359,22 @@ public class CusInfoToOAUtil { String currentTime = currentDateTime.substring(11); return modeDataIdUpdate.getModeDataNewId(modelTableName, modelId, 1, 0, currentDate, currentTime); } + + /** + *

校验模块id 并获取表名

+ * @author xuanran.wang + * @dateTime 2023/2/9 11:18 + * @param modelId 模块id + * @return 表名 + **/ + public static String checkModelId(int modelId){ + if(modelId < 0){ + throw new RuntimeException("建模模块id不能小于0!"); + } + String tableName = commonMapper.getModelNameByModelId(String.valueOf(modelId)); + if(StringUtils.isBlank(tableName)){ + throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!"); + } + return tableName; + } } diff --git a/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/Student.java b/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/Student.java new file mode 100644 index 0000000..ea19b7b --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/Student.java @@ -0,0 +1,36 @@ +package weaver.xuanran.wang.shyl.dataasync.entity; + +import lombok.Data; +import weaver.xuanran.wang.common.annocation.SqlFieldMapping; +import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField; + +/** + *

教研资系统数据同步学员

+ * + * @author xuanran.wang + * @date 2023/2/9 13:11 + */ +@Data +public class Student { + /** + *

学员主键ID

+ **/ + @SqlFieldMapping("studentId") + @SqlUpdateWhereField(value = true) + private String id; + /** + *

学员编号

+ **/ + @SqlFieldMapping + private String studentNo; + /** + *

学员名称

+ **/ + @SqlFieldMapping + private String studentName; + /** + *

班级主键ID

+ **/ + @SqlFieldMapping + private String classId; +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/StudentClass.java b/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/StudentClass.java new file mode 100644 index 0000000..914d78b --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/dataasync/entity/StudentClass.java @@ -0,0 +1,36 @@ +package weaver.xuanran.wang.shyl.dataasync.entity; + +import lombok.Data; +import weaver.xuanran.wang.common.annocation.SqlFieldMapping; +import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField; + +/** + *

教研资系统数据同步班级信息

+ * + * @author xuanran.wang + * @date 2023/2/9 10:59 + */ +@Data +public class StudentClass { + /** + *

班级id

+ **/ + @SqlUpdateWhereField(value = true) + @SqlFieldMapping("classId") + private String id; + /** + *

班级编号

+ **/ + @SqlFieldMapping() + private String classNo; + /** + *

班级名称

+ **/ + @SqlFieldMapping() + private String className; + /** + *

班级所属年度

+ **/ + @SqlFieldMapping() + private int belongYear; +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/dataasync/job/CusDataAsyncJob.java b/src/main/java/weaver/xuanran/wang/shyl/dataasync/job/CusDataAsyncJob.java new file mode 100644 index 0000000..e649494 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/dataasync/job/CusDataAsyncJob.java @@ -0,0 +1,113 @@ +package weaver.xuanran.wang.shyl.dataasync.job; + +import aiyh.utils.Util; +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; + +/** + *

上海团校班级/学员数据同步

+ * + * @author xuanran.wang + * @date 2023/2/9 10:02 + */ +public class CusDataAsyncJob extends BaseCronJob { + + /** + *

教研资系统ip地址

+ **/ + @ParamPrint + @ParamNotNull + private String baseAddr; + /** + *

教研资系统动态码地址

+ **/ + @ParamPrint + @ParamNotNull + private String dynamicCodeUrl; + /** + *

教研资系统登陆地址

+ **/ + @ParamPrint + @ParamNotNull + private String loginUrl; + /** + *

查询班级列表url

+ **/ + @ParamPrint + @ParamNotNull + private String queryClassUrl; + /** + *

查询学员列表Url

+ **/ + @ParamPrint + @ParamNotNull + private String queryStuUrl; + /** + *

班级模块id

+ **/ + @ParamPrint + @ParamNotNull + private String classModelId; + /** + *

学员模块id

+ **/ + @ParamPrint + @ParamNotNull + private String studentModelId; + /** + *

教研资系统用户名

+ **/ + @ParamPrint + @ParamNotNull + private String userName; + /** + *

教研资系统密码

+ **/ + @ParamPrint + @ParamNotNull + private String userPwd; + /** + *

更新班级建模条件sql

+ **/ + private static final String updateClassSql = "select id from #{tableName} where classId = ?"; + /** + *

更新学员建模条件sql

+ **/ + private static final String updateStudentSql = "select id from #{tableName} where studentId = ?"; + + private final CusDataAsyncService dataAsyncService = new CusDataAsyncService(); + + private final Logger log = Util.getLogger(); + + @Override + public void execute() { + try { + CommonUtil.checkParamNotNull(this); + + // 获取token参数 + HashMap loginParams = new HashMap<>(); + loginParams.put("username", userName); + loginParams.put("password", userPwd); + loginParams.put("authType", "normal"); + + Object token = dataAsyncService.getToken(dynamicCodeUrl, loginUrl, loginParams); + HashMap headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + token); + // 数据同步 + dataAsyncService.asyncData(baseAddr + queryClassUrl, classModelId, StudentClass.class, updateClassSql,headers); + dataAsyncService.asyncData(baseAddr + queryStuUrl, studentModelId, Student.class, updateStudentSql, headers); + }catch (Exception e){ + log.error(Util.logStr("CusDataAsyncJob execute error! the error is :{}, " + + "error stack trace msg is: \n{}", e.getMessage(), Util.getErrString(e))); + } + } +} + diff --git a/src/main/java/weaver/xuanran/wang/shyl/dataasync/service/CusDataAsyncService.java b/src/main/java/weaver/xuanran/wang/shyl/dataasync/service/CusDataAsyncService.java new file mode 100644 index 0000000..04377ac --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/dataasync/service/CusDataAsyncService.java @@ -0,0 +1,159 @@ +package weaver.xuanran.wang.shyl.dataasync.service; + +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 com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.xuanran.wang.common.util.CusInfoToOAUtil; + +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + *

班级列表/学员数据同步业务方法

+ * + * @author xuanran.wang + * @date 2023/2/9 10:09 + */ +public class CusDataAsyncService { + + private final HttpUtils httpUtils = new HttpUtils(); + + private static final int SUCCESS_CODE = 200; + + private static final Logger log = Util.getLogger(); + + /** + *

接口响应成功状态码

+ **/ + private static final int RESPONSE_SUCCESS_CODE = 0; + + { + httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头 + } + + /** + *

数据同步

+ * @author xuanran.wang + * @dateTime 2023/2/9 10:10 + * @param url 请求地址 + * @param modelId 建模模块id + * @param clazz 实体类class + * @param updateSql 建模更新数据sql + * @param headers 请求头 + **/ + public void asyncData(String url, String modelId, + Class clazz,String updateSql, + HashMap headers){ + Object data = getResponseDataByPost(url, new HashMap<>(), headers,""); + List list = JSONObject.parseArray(data.toString(), clazz); + CusInfoToOAUtil.executeBatchByEntity(Util.getIntValue(modelId, -1), list, updateSql); + } + + /** + *

获取token

+ * @author xuanran.wang + * @dateTime 2023/2/10 15:50 + * @param dynamicCodeUrl 动态码地址url + * @param loginUrl 登陆地址url + * @param loginParams 登陆参数 + * @return token + **/ + public Object getToken(String dynamicCodeUrl, String loginUrl,Map loginParams){ + // 先获取动态码 + HashMap params = new HashMap<>(); + params.put("_allow_anonymous", true); + Object state = getResponseDataByGet(dynamicCodeUrl, params, new HashMap<>(),"state"); + loginParams.put("state", state); + return getResponseDataByPost(loginUrl, loginParams, new HashMap<>(), "token"); + } + + /** + *

请求接口获取响应数据

+ * @author xuanran.wang + * @dateTime 2023/2/9 16:22 + * @param url 教研资地址 + * @param params 参数 + * @param headers 请求头 + * @param key 响应字段 + * @return 接口响应数据 + **/ + private Object getResponseDataByPost(String url, Map params, + Map headers, String key){ + try { + ResponeVo responseVo = httpUtils.apiPost(url, params, headers); + return getResponseData(url, responseVo, key); + }catch (IOException e) { + throw new CustomerException(Util.logStr("api get error! current url is : {}, error is :{}",url, e.getMessage())); + } + } + + /** + *

请求接口获取响应数据

+ * @author xuanran.wang + * @dateTime 2023/2/9 16:22 + * @param url 教研资地址 + * @param params 参数 + * @param headers 请求头 + * @return 接口响应数据 + * @param key 响应字段 + **/ + private Object getResponseDataByGet(String url, Map params, + Map headers, String key){ + try { + ResponeVo responseVo = httpUtils.apiGet(url, params, headers); + return getResponseData(url, responseVo, key); + }catch (IOException e) { + throw new CustomerException(Util.logStr("api get error! current url is : {}, error is :{}",url, e.getMessage())); + } + } + + + /** + *

请求接口获取响应数据

+ * @author xuanran.wang + * @dateTime 2023/2/9 16:22 + * @param url 请求地址 + * @param responseVo 接口响应数据 + * @param key 响应字段 + **/ + private Object getResponseData(String url,ResponeVo responseVo, String key){ + Map headers = httpUtils.getGlobalCache().header; + if(SUCCESS_CODE != responseVo.getCode()){ + log.error(Util.logStr("can not fetch [{}]" + + "this request heard is [{}],but response status code is [{}]," + + "this response is [{}]", url, JSON.toJSONString(headers), responseVo.getCode(),responseVo.getEntityString())); // 相应内容 + throw new CustomerException(Util.logStr("can not fetch [{}]", url)); + } + Map responseMap = responseVo.getResponseMap(); + // 接口响应码 + int responseCode = Util.getIntValue(Util.null2DefaultStr(responseMap.get("code"), ""), -1); + // 接口响应信息 + String msg = Util.null2DefaultStr(responseMap.get("msg"), ""); + if(RESPONSE_SUCCESS_CODE != responseCode){ + throw new CustomerException(Util.logStr("the url is : [{}], but the responseCode is not success!, " + + " current code is :[{}], the msg is : [{}]", url, responseCode, msg)); + } + Object data = responseMap.get("data"); + if(Objects.isNull(data)) { + throw new CustomerException("The response data in the interface is null!"); + } + if(StringUtils.isNotBlank(key)){ + return data; + } + Map map = JSONObject.parseObject(data.toString(), Map.class); + if(MapUtils.isEmpty(map) || Objects.isNull(map.get(key))){ + throw new CustomerException("Exception in getting interface response field!"); + } + return map.get(key); + } +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java index ee9bee2..2df840a 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java @@ -31,7 +31,7 @@ public class RocketMQFactory { /** *

生产者map

**/ - private static Map PRODUCER_MAP = new ConcurrentHashMap<>(16); + private static final Map PRODUCER_MAP = new ConcurrentHashMap<>(16); /** *

根据配置文件生成消费者对象

@@ -62,7 +62,7 @@ public class RocketMQFactory { consumer.registerMessageListener(messageListenerConcurrently); return consumer; }catch (Exception e){ - throw new CustomerException(Util.logStr("consumer init error, now config name is : {} error : {}",configName, e.getMessage())); + throw new CustomerException(Util.logStr("consumer init error, now config name is : {} error : {}",configName, e.getMessage()), e); } } @@ -73,29 +73,27 @@ public class RocketMQFactory { * @param configName 配置文件名称 * @return 生产者对象 **/ - public static DefaultMQProducer getMQProducer(String configName){ + public synchronized static DefaultMQProducer getMQProducer(String configName){ DefaultMQProducer defaultMQProducer = null; if(PRODUCER_MAP.containsKey(configName)){ return PRODUCER_MAP.get(configName); }else { - synchronized (RocketMQFactory.class){ - if(PRODUCER_MAP.containsKey(configName)){ - return PRODUCER_MAP.get(configName); - }else { - Map configMap = getConfigMapByName(configName); - defaultMQProducer = new DefaultMQProducer(); - // 发送消息最大超时时间 默认60000 - int sendMsgTimeOut = Util.getIntValue(Util.null2String(configMap.get("sendMsgTimeOut")), RocketMQConstant.PRODUCER_SEND_MSG_TIME_OUT); - defaultMQProducer.setSendMsgTimeout(sendMsgTimeOut); - try { - defaultMQProducer.start(); - }catch (MQClientException e){ - throw new CustomerException("producer start error!"); - } - // mq地址 - defaultMQProducer.setNamesrvAddr(Util.null2String(configMap.get("NameServer"))); - PRODUCER_MAP.put(configName, defaultMQProducer); + if(PRODUCER_MAP.containsKey(configName)){ + return PRODUCER_MAP.get(configName); + }else { + Map configMap = getConfigMapByName(configName); + defaultMQProducer = new DefaultMQProducer(); + // 发送消息最大超时时间 默认60000 + int sendMsgTimeOut = Util.getIntValue(Util.null2String(configMap.get("sendMsgTimeOut")), RocketMQConstant.PRODUCER_SEND_MSG_TIME_OUT); + defaultMQProducer.setSendMsgTimeout(sendMsgTimeOut); + try { + defaultMQProducer.start(); + }catch (MQClientException e){ + throw new CustomerException("producer start error!",e); } + // mq地址 + defaultMQProducer.setNamesrvAddr(Util.null2String(configMap.get("NameServer"))); + PRODUCER_MAP.put(configName, defaultMQProducer); } } return defaultMQProducer; diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/action/ProducerAction.java b/src/main/java/weaver/xuanran/wang/shyl/mq/action/ProducerAction.java index f117afd..d12b20f 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/action/ProducerAction.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/action/ProducerAction.java @@ -1,9 +1,13 @@ package weaver.xuanran.wang.shyl.mq.action; +import aiyh.utils.Util; import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.PrintParamMark; import aiyh.utils.annotation.RequiredMark; +import aiyh.utils.excention.CustomerException; import weaver.hrm.User; import weaver.soa.workflow.request.RequestInfo; +import weaver.xuanran.wang.shyl.mq.service.ProducerService; /** *

生产者action 将流程数据发送到mq中

@@ -17,15 +21,24 @@ public class ProducerAction extends SafeCusBaseAction { *

mq配置文件名称

**/ @RequiredMark + @PrintParamMark private String MQConfigName; /** *

配置文件唯一标识

**/ @RequiredMark + @PrintParamMark private String onlyMark; + private final ProducerService producerService = new ProducerService(); + @Override public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { - + try { + producerService.pushWorkFlowToMQ(MQConfigName, onlyMark, billTable, requestId); + }catch (Exception e){ + String error = Util.logStr("push workFlow to MQ error! the error is :[{}]", e.getMessage()); + throw new CustomerException(error); + } } } diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java b/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java index db980e2..9af0e6a 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java @@ -26,6 +26,7 @@ public class RocketMQConstant { public static final String ID_TYPE_SOLDIER_CARD = "5"; public static final String DEFAULT_PASSWORD = "1"; public static final int PRODUCER_SEND_MSG_TIME_OUT = 60000; + public static final int SEND_MAX_COUNT = 3; public static Map SEX_MAPPING = new HashMap<>(); diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/mapper/ConsumerMapper.java b/src/main/java/weaver/xuanran/wang/shyl/mq/mapper/ConsumerMapper.java index e3f87d7..7a74f64 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/mapper/ConsumerMapper.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/mapper/ConsumerMapper.java @@ -1,6 +1,7 @@ package weaver.xuanran.wang.shyl.mq.mapper; import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Select; import aiyh.utils.annotation.recordset.Update; import java.util.Map; @@ -23,13 +24,13 @@ public interface ConsumerMapper { boolean updateUserStatusByOutKey(@ParamMapper("outKey") String outKey); /** - *

通过outKey删除部门信息

+ *

通过outKey封存部门

* @author xuanran.wang * @dateTime 2022/12/30 14:33 * @param outKey 外部系统id * @return 删除是否成功 **/ - @Update("delete hrmdepartment where outkey = #{outKey}") + @Update("update hrmdepartment set canceled = 1 where outkey = #{outKey}") boolean deleteDepartmentByOutKey(@ParamMapper("outKey") String outKey); /** @@ -39,7 +40,7 @@ public interface ConsumerMapper { * @param outKey 外部系统id * @return map key : id, val : 分部id **/ - @Update("select id departmentId, subcompanyid1 subCompanyId from hrmdepartment where outkey = #{outKey}") + @Update("select id departmentId, subcompanyid1 subCompanyId from hrmdepartment where outkey = #{outKey} and canceled != 1") Map getDepInfoByOutKey(@ParamMapper("outKey") String outKey); /** @@ -59,7 +60,7 @@ public interface ConsumerMapper { * @param outKey 外部系统id * @return id **/ - @Update("select id from hrmdepartment where outkey = #{outKey}") + @Update("select id from hrmdepartment where outkey = #{outKey} and canceled != 1") String getDepIdByOutKey(@ParamMapper("outKey") String outKey); /** @@ -71,5 +72,14 @@ public interface ConsumerMapper { **/ @Update("update hrmresource set password = #{password} where id = #{id}") boolean updatePasswordById(@ParamMapper("id") String id, - @ParamMapper("password") String password); + @ParamMapper("password") String password); + + /** + *

获取第一个分部id

+ * @author xuanran.wang + * @dateTime 2023/1/18 10:36 + * @return 分部id + **/ + @Select("select id from hrmsubcompany") + String getDefaultSubId(); } diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/CusInfoActionService.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/CusInfoActionService.java index d9727a5..4dd8f42 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/service/CusInfoActionService.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/CusInfoActionService.java @@ -19,11 +19,19 @@ public abstract class CusInfoActionService implements CreateAction, DeleteAction protected final RecordSet recordSet = new RecordSet(); protected final Logger logger = Util.getLogger(); - /** *

consumer-mapper

**/ protected final ConsumerMapper consumerMapper = Util.getMapper(ConsumerMapper.class); + /** + *

分部id

+ **/ + protected String subId; + // 默认初始化分部ID + { + subId = consumerMapper.getDefaultSubId(); + } + /** *

获取下一个人员id

diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/ProducerService.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/ProducerService.java index fb9580f..e028dae 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/service/ProducerService.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/ProducerService.java @@ -1,10 +1,8 @@ package weaver.xuanran.wang.shyl.mq.service; -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.conn.RecordSet; import weaver.xiao.commons.config.entity.RequestMappingConfig; import weaver.xiao.commons.config.service.DealWithMapping; @@ -24,6 +22,15 @@ public class ProducerService { private final DealWithMapping dealWithMapping = new DealWithMapping(); + /** + *

作为生产者将流程数据推送至mq中

+ * @author xuanran.wang + * @dateTime 2023/1/18 10:22 + * @param configName mq配置文件名称 + * @param onlyMark 建模配置唯一标识 + * @param requestId 请求id + * @param tableName 主表表名 + **/ public void pushWorkFlowToMQ(String configName, String onlyMark, String requestId, String tableName){ RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); String selectMainSql = CommonUtil.getSelectSql(requestMappingConfig, tableName); diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java index c944603..a569617 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java @@ -39,7 +39,6 @@ public class OrgServiceImpl extends CusInfoActionService { Org org = JSONObject.parseObject(content, Org.class); char separator = weaver.general.Util.getSeparator(); // 分部id - String subId = ""; RecordSet insertRs = new RecordSet(); if(StringUtils.isBlank(subId)){ throw new CustomerException("SubCompany can not be empty!"); @@ -54,7 +53,7 @@ public class OrgServiceImpl extends CusInfoActionService { } return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; }catch (Exception e){ - throw new CustomerException(Util.logStr("orgCreateAction error : {}", e.getMessage())); + throw new CustomerException(Util.logStr("orgCreateAction error : {}", e.getMessage()), e); } } @@ -80,7 +79,7 @@ public class OrgServiceImpl extends CusInfoActionService { } return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; }catch (Exception e){ - throw new CustomerException(Util.logStr("orgDeleteAction execute error : [{}]!", e.getMessage())); + throw new CustomerException(Util.logStr("orgDeleteAction execute error : [{}]!", e.getMessage()), e); } } @@ -98,7 +97,6 @@ public class OrgServiceImpl extends CusInfoActionService { Org org = JSONObject.parseObject(content, Org.class); String outKey = org.getId(); // 分部待明确 - String subId = ""; String depId = consumerMapper.getDepIdByOutKey(outKey); if(StringUtils.isBlank(depId)){ throw new CustomerException(Util.logStr("The department information data obtained by foreign key is empty!")); @@ -106,7 +104,7 @@ public class OrgServiceImpl extends CusInfoActionService { updateDepartmentInfo(depId, subId, org); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; }catch (Exception e){ - throw new CustomerException(Util.logStr("orgUpdateAction error : {}", e.getMessage())); + throw new CustomerException(Util.logStr("orgUpdateAction error : {}", e.getMessage()), e); } } diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/UserServiceImpl.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/UserServiceImpl.java index 2078bae..c95c7b0 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/UserServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/UserServiceImpl.java @@ -44,6 +44,12 @@ public class UserServiceImpl extends CusInfoActionService { try { String content = message.getContent(); UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class); + String outKey = userInfo.getId(); + String userId = consumerMapper.getHrmIdByOutKey(outKey); + // 如果存在就走更新 + if(StringUtils.isNotBlank(userId)){ + return cusUpdateAction(message); + } String userInfoDepartmentId = userInfo.getDepartmentId(); // 部门id if(StringUtils.isBlank(userInfoDepartmentId)){ @@ -210,7 +216,7 @@ public class UserServiceImpl extends CusInfoActionService { // 人员名称 params.add(Util.null2DefaultStr(userInfo.getDisplayName(), "")); // 性别 如果没传就默认男 - params.add(RocketMQConstant.SEX_MAPPING.get(Util.null2DefaultStr(userInfo.getGender(), "1"))); + params.add(RocketMQConstant.SEX_MAPPING.get(Util.null2DefaultStr(userInfo.getGender(), RocketMQConstant.SEX_BOY))); // 登陆名 params.add(userName); // 密码 diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java b/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java index d1782fe..c5ef4d6 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java @@ -137,26 +137,39 @@ public class RocketUtil { // 获取配置信息 Map configMap = RocketMQFactory.CONFIG_MAPS.get(configName); // 队列名 - String topic = Util.null2DefaultStr(configMap.get("Topic"),""); + String topic = Util.null2DefaultStr(configMap.get("Topic"), ""); // tag - String tag = Util.null2DefaultStr(configMap.get("Tag"),""); + String tag = Util.null2DefaultStr(configMap.get("Tag"), ""); Message message; try { message = new Message(topic, tag, msg.getBytes(RemotingHelper.DEFAULT_CHARSET)); - }catch (Exception e){ + } catch (Exception e) { throw new CustomerException(Util.logStr("init message error : {} !", e.getMessage())); } - SendResult result; - try { - result = producer.send(message); - } catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) { - throw new CustomerException(Util.logStr("producer send message error!", e.getMessage())); - } - SendStatus sendStatus = result.getSendStatus(); - // 如果成功 - if(SendStatus.SEND_OK.equals(sendStatus)){ - log.error(Util.logStr("producer send message call back status is not ok! the message is {}, the status is {}.", msg, sendStatus)); - } + // 发送成功标识 + boolean sendOk = false; + // 发送次数 + int count = 0; + do { + SendResult result; + count++; + try { + result = producer.send(message); + } catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) { + throw new CustomerException(Util.logStr("producer send message error!", e.getMessage())); + } + SendStatus sendStatus = result.getSendStatus(); + // 如果失败 + if (!SendStatus.SEND_OK.equals(sendStatus)) { + String error = Util.logStr("producer send message call back status is not ok! the message is {}, the status is {}.", msg, sendStatus); + log.error(error); + // 如果重试超过最大次数 + if(count >= RocketMQConstant.SEND_MAX_COUNT){ + throw new CustomerException(error); + } + }else { + sendOk = true; + } + } while (!sendOk || count < RocketMQConstant.SEND_MAX_COUNT); } - } diff --git a/src/main/resources/WEB-INF/prop/prop2map/OACar.properties b/src/main/resources/WEB-INF/prop/prop2map/OACar.properties new file mode 100644 index 0000000..0606409 --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/OACar.properties @@ -0,0 +1,4 @@ +ConsumerGroup=weaver-car +NameServer=183.192.65.118:9876 +Topic=OA_CAR_TOPIC +Tag=* \ No newline at end of file diff --git a/src/main/resources/WEB-INF/prop/prop2map/OAMeal.properties b/src/main/resources/WEB-INF/prop/prop2map/OAMeal.properties new file mode 100644 index 0000000..4bbdaf5 --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/OAMeal.properties @@ -0,0 +1,4 @@ +ConsumerGroup=weaver-meal +NameServer=183.192.65.118:9876 +Topic=OA_MEAL_TOPIC +Tag=* \ No newline at end of file diff --git a/src/main/resources/WEB-INF/prop/prop2map/OAMeeting.properties b/src/main/resources/WEB-INF/prop/prop2map/OAMeeting.properties new file mode 100644 index 0000000..a693a32 --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/OAMeeting.properties @@ -0,0 +1,4 @@ +ConsumerGroup=weaver-meeting +NameServer=183.192.65.118:9876 +Topic=OA_MEETING_TOPIC +Tag=* \ No newline at end of file diff --git a/src/main/resources/WEB-INF/prop/prop2map/OAVisitor.properties b/src/main/resources/WEB-INF/prop/prop2map/OAVisitor.properties new file mode 100644 index 0000000..9d47d17 --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/OAVisitor.properties @@ -0,0 +1,4 @@ +ConsumerGroup=weaver-visitor +NameServer=183.192.65.118:9876 +Topic=OA_VISITOR_TOPIC +Tag=* \ No newline at end of file diff --git a/src/main/resources/WEB-INF/prop/prop2map/OrgConsumer.properties b/src/main/resources/WEB-INF/prop/prop2map/OrgConsumer.properties new file mode 100644 index 0000000..024092c --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/OrgConsumer.properties @@ -0,0 +1,4 @@ +ConsumerGroup=weaver-org +NameServer=183.192.65.118:9876 +Topic=AUTH_CONSOLE_ORG_TOPIC +Tag=* \ No newline at end of file diff --git a/src/main/resources/WEB-INF/prop/prop2map/PassWordConsumer.properties b/src/main/resources/WEB-INF/prop/prop2map/PassWordConsumer.properties new file mode 100644 index 0000000..04f8b6b --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/PassWordConsumer.properties @@ -0,0 +1,4 @@ +ConsumerGroup=weaver-password +NameServer=183.192.65.118:9876 +Topic=AUTH_CONSOLE_USERINFO_PASSWORD_TOPIC +Tag=* \ No newline at end of file diff --git a/src/main/resources/WEB-INF/prop/prop2map/UserInfoConsumer.properties b/src/main/resources/WEB-INF/prop/prop2map/UserInfoConsumer.properties new file mode 100644 index 0000000..b285ae1 --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/UserInfoConsumer.properties @@ -0,0 +1,4 @@ +ConsumerGroup=weaver-userinfo +NameServer=183.192.65.118:9876 +Topic=AUTH_CONSOLE_USERINFO_TOPIC +Tag=* \ No newline at end of file diff --git a/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java b/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java index a7fe51f..f3b1562 100644 --- a/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java +++ b/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java @@ -18,7 +18,7 @@ public class CheckUserTest extends BaseTest { public void testProperties(){ try{ CheckUserService checkUserService = new CheckUserService(); - checkUserService.logAllUser(); +// checkUserService.logAllUser(); }catch (Exception e){ String error = Util.logStr("AD查询接口发生异常:{}", e.getMessage()); log.error(error); diff --git a/src/test/java/xuanran/wang/shyl/dataasync/AsyncTest.java b/src/test/java/xuanran/wang/shyl/dataasync/AsyncTest.java new file mode 100644 index 0000000..8257758 --- /dev/null +++ b/src/test/java/xuanran/wang/shyl/dataasync/AsyncTest.java @@ -0,0 +1,94 @@ +package xuanran.wang.shyl.dataasync; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import basetest.BaseTest; +import cfca.sadk.org.bouncycastle.jcajce.provider.digest.SHA1; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import weaver.xuanran.wang.common.annocation.SqlFieldMapping; +import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField; +import weaver.xuanran.wang.shyl.dataasync.entity.StudentClass; + +import java.lang.reflect.Field; +import java.security.acl.LastOwnerException; +import java.util.*; + +/** + *

上海团校测试类

+ * + * @author xuanran.wang + * @date 2023/2/9 13:23 + */ +public class AsyncTest extends BaseTest { + + @Test + public void testExecuteBatchByEntity(){ + String json = "{\n" + + "\t\"msg\": \"success\",\n" + + "\t\"code\": 0,\n" + + "\t\"data\": [{\n" + + "\t\t\"id\": \"2f44f6c8626c4e328af10fd3af4122a3\",\n" + + "\t\t\"classNo\": null,\n" + + "\t\t\"className\": \"BB班202301\",\n" + + "\t\t\"belongYear\": 2023\n" + + "\t}, {\n" + + "\t\t\"id\": \"134fdb4ef8b4432cb66c03eb34dc94f7\",\n" + + "\t\t\"classNo\": null,\n" + + "\t\t\"className\": \"1\",\n" + + "\t\t\"belongYear\": 2023\n" + + "\t}]\n" + + "}"; + HashMap responseMap = JSONObject.parseObject(json, HashMap.class); + log.info("responseMap : " + responseMap); + Object data = responseMap.get("data"); + List list = JSONObject.parseArray(data.toString(), StudentClass.class); + List> params = new ArrayList<>(); + List> whereParams = new ArrayList<>(); + for (Object o : list) { + if(Objects.isNull(o)){ + continue; + } + Class clazz = o.getClass(); + Field[] fields = clazz.getDeclaredFields(); + LinkedHashMap linkedHashMap = new LinkedHashMap<>(); + ArrayList whereParam = new ArrayList<>(); + for (Field field : fields) { + field.setAccessible(true); + String fieldName = field.getName(); + Object fieldValue; + try { + fieldValue = field.get(o); + } catch (IllegalAccessException e) { + throw new CustomerException(Util.logStr("field get error! the error is :[{}]," + + "current field is: [{}], current obj is: [{}]", e.getMessage(), fieldName, JSONObject.toJSONString(o))); + } + if(Objects.isNull(fieldValue)){ + continue; + } + // 数据库字段映射 如果注解中没有值那么写入数据库就是实体类字段名 + SqlFieldMapping sqlFieldMapping = field.getAnnotation(SqlFieldMapping.class); + if(null == sqlFieldMapping){ + continue; + } + String sqlFieldMappingValue = sqlFieldMapping.value(); + if(StringUtils.isNotBlank(sqlFieldMappingValue)){ + fieldName = sqlFieldMappingValue; + } + linkedHashMap.put(fieldName, fieldValue); + + // 更新条件字段注解 + SqlUpdateWhereField sqlUpdateWhereField = field.getAnnotation(SqlUpdateWhereField.class); + if(null == sqlUpdateWhereField || !sqlUpdateWhereField.value()){ + continue; + } + whereParam.add(fieldValue.toString()); + } + params.add(linkedHashMap); + whereParams.add(whereParam); + } + log.info("params : " + JSONObject.toJSONString(params)); + log.info("wheres : " + whereParams); + } +} diff --git a/src/test/resources/ application.properties b/src/test/resources/ application.properties deleted file mode 100644 index e69de29..0000000