柏美流水创建,团校mq代码修改
parent
65ebec9fa3
commit
dfc89e7d21
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>安波福从AD域中校验用户是否存在</h1>
|
||||
|
@ -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);
|
||||
|
|
|
@ -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<String, Object> 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<String, Object> res = new HashMap<>();
|
||||
if(has){
|
||||
SearchResult sr = (SearchResult) answer.next();
|
||||
String dn = sr.getName();
|
||||
log.info("dn " + dn);
|
||||
// String dn = sr.getName();
|
||||
NamingEnumeration<? extends Attribute> 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 {
|
||||
|
|
|
@ -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 {
|
|||
* <h2>存货分类编码字段</h2>
|
||||
**/
|
||||
@RequiredMark
|
||||
@PrintParamMark
|
||||
private String invClassificationCode;
|
||||
|
||||
/**
|
||||
* <h2>存货编码 生成编号后写入这个字段</h2>
|
||||
**/
|
||||
@RequiredMark
|
||||
@PrintParamMark
|
||||
private String inventoryCode;
|
||||
|
||||
/**
|
||||
* <h2>生成流水号日志记录模块id</h2>
|
||||
**/
|
||||
@RequiredMark
|
||||
@PrintParamMark
|
||||
private String serialNumberModelId;
|
||||
|
||||
private static final String START_NO = "0101";
|
||||
/**
|
||||
* <h2>明细表下标 如果配置了就会把主表生成的存货编码复制到明细表中</h2>
|
||||
**/
|
||||
@PrintParamMark
|
||||
private String detailIndex;
|
||||
|
||||
/**
|
||||
* <h2>明细表存货编码字段名</h2>
|
||||
**/
|
||||
@PrintParamMark
|
||||
private String detailInventoryCode;
|
||||
|
||||
/**
|
||||
* <h2>创建流水的条件</h2>
|
||||
**/
|
||||
@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<String, String> 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<String, Object> 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<Object> 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<String, Object> 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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>参数打印</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/2/9 13:37
|
||||
*/
|
||||
@Target({ElementType.FIELD,ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ParamPrint {
|
||||
boolean value() default true;
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>实体类-数据库字段映射</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/2/9 11:12
|
||||
*/
|
||||
@Target({ElementType.FIELD,ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface SqlFieldMapping {
|
||||
String value() default "";
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>数据库主键</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/2/9 11:13
|
||||
*/
|
||||
@Target({ElementType.FIELD,ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface SqlUpdateWhereField {
|
||||
boolean value() default false;
|
||||
}
|
|
@ -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 <T> void checkParamNotNull(T t){
|
||||
Class<?> clazz = t.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
HashMap<String, Object> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<List<String>> whereParams,
|
||||
boolean needDel,
|
||||
List<LinkedHashMap<String, Object>> 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>将实体类数据插入到建模表中</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/2/9 11:51
|
||||
* @param modelId 模块id
|
||||
* @param list 插入参数集合
|
||||
* @param whereSql 更新条件
|
||||
* @return 建模数据id
|
||||
**/
|
||||
public static List<String> executeBatchByEntity(int modelId, List<?> list, String whereSql){
|
||||
String tableName = checkModelId(modelId);
|
||||
List<LinkedHashMap<String, Object>> params = new ArrayList<>();
|
||||
List<List<String>> whereParams = new ArrayList<>();
|
||||
for (Object o : list) {
|
||||
if(Objects.isNull(o)){
|
||||
continue;
|
||||
}
|
||||
Class<?> clazz = o.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
|
||||
ArrayList<String> 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<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>将自定义信息写入建模</h1>
|
||||
* @author xuanran.wang
|
||||
|
@ -303,4 +359,22 @@ public class CusInfoToOAUtil {
|
|||
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,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;
|
||||
|
||||
/**
|
||||
* <h1>教研资系统数据同步学员</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/2/9 13:11
|
||||
*/
|
||||
@Data
|
||||
public class Student {
|
||||
/**
|
||||
* <h2>学员主键ID</h2>
|
||||
**/
|
||||
@SqlFieldMapping("studentId")
|
||||
@SqlUpdateWhereField(value = true)
|
||||
private String id;
|
||||
/**
|
||||
* <h2>学员编号</h2>
|
||||
**/
|
||||
@SqlFieldMapping
|
||||
private String studentNo;
|
||||
/**
|
||||
* <h2>学员名称</h2>
|
||||
**/
|
||||
@SqlFieldMapping
|
||||
private String studentName;
|
||||
/**
|
||||
* <h2>班级主键ID</h2>
|
||||
**/
|
||||
@SqlFieldMapping
|
||||
private String classId;
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>教研资系统数据同步班级信息</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/2/9 10:59
|
||||
*/
|
||||
@Data
|
||||
public class StudentClass {
|
||||
/**
|
||||
* <h2>班级id</h2>
|
||||
**/
|
||||
@SqlUpdateWhereField(value = true)
|
||||
@SqlFieldMapping("classId")
|
||||
private String id;
|
||||
/**
|
||||
* <h2>班级编号</h2>
|
||||
**/
|
||||
@SqlFieldMapping()
|
||||
private String classNo;
|
||||
/**
|
||||
* <h2>班级名称</h2>
|
||||
**/
|
||||
@SqlFieldMapping()
|
||||
private String className;
|
||||
/**
|
||||
* <h2>班级所属年度</h2>
|
||||
**/
|
||||
@SqlFieldMapping()
|
||||
private int belongYear;
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>上海团校班级/学员数据同步</h1>
|
||||
*
|
||||
* @author xuanran.wang
|
||||
* @date 2023/2/9 10:02
|
||||
*/
|
||||
public class CusDataAsyncJob extends BaseCronJob {
|
||||
|
||||
/**
|
||||
* <h2>教研资系统ip地址</h2>
|
||||
**/
|
||||
@ParamPrint
|
||||
@ParamNotNull
|
||||
private String baseAddr;
|
||||
/**
|
||||
* <h2>教研资系统动态码地址</h2>
|
||||
**/
|
||||
@ParamPrint
|
||||
@ParamNotNull
|
||||
private String dynamicCodeUrl;
|
||||
/**
|
||||
* <h2>教研资系统登陆地址</h2>
|
||||
**/
|
||||
@ParamPrint
|
||||
@ParamNotNull
|
||||
private String loginUrl;
|
||||
/**
|
||||
* <h2>查询班级列表url</h2>
|
||||
**/
|
||||
@ParamPrint
|
||||
@ParamNotNull
|
||||
private String queryClassUrl;
|
||||
/**
|
||||
* <h2>查询学员列表Url</h2>
|
||||
**/
|
||||
@ParamPrint
|
||||
@ParamNotNull
|
||||
private String queryStuUrl;
|
||||
/**
|
||||
* <h2>班级模块id</h2>
|
||||
**/
|
||||
@ParamPrint
|
||||
@ParamNotNull
|
||||
private String classModelId;
|
||||
/**
|
||||
* <h2>学员模块id</h2>
|
||||
**/
|
||||
@ParamPrint
|
||||
@ParamNotNull
|
||||
private String studentModelId;
|
||||
/**
|
||||
* <h2>教研资系统用户名</h2>
|
||||
**/
|
||||
@ParamPrint
|
||||
@ParamNotNull
|
||||
private String userName;
|
||||
/**
|
||||
* <h2>教研资系统密码</h2>
|
||||
**/
|
||||
@ParamPrint
|
||||
@ParamNotNull
|
||||
private String userPwd;
|
||||
/**
|
||||
* <h2>更新班级建模条件sql</h2>
|
||||
**/
|
||||
private static final String updateClassSql = "select id from #{tableName} where classId = ?";
|
||||
/**
|
||||
* <h2>更新学员建模条件sql</h2>
|
||||
**/
|
||||
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<String, Object> loginParams = new HashMap<>();
|
||||
loginParams.put("username", userName);
|
||||
loginParams.put("password", userPwd);
|
||||
loginParams.put("authType", "normal");
|
||||
|
||||
Object token = dataAsyncService.getToken(dynamicCodeUrl, loginUrl, loginParams);
|
||||
HashMap<String, String> 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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>班级列表/学员数据同步业务方法</h1>
|
||||
*
|
||||
* @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();
|
||||
|
||||
/**
|
||||
* <h2>接口响应成功状态码</h2>
|
||||
**/
|
||||
private static final int RESPONSE_SUCCESS_CODE = 0;
|
||||
|
||||
{
|
||||
httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>数据同步</h1>
|
||||
* @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<String, String> headers){
|
||||
Object data = getResponseDataByPost(url, new HashMap<>(), headers,"");
|
||||
List<?> list = JSONObject.parseArray(data.toString(), clazz);
|
||||
CusInfoToOAUtil.executeBatchByEntity(Util.getIntValue(modelId, -1), list, updateSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取token</h1>
|
||||
* @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<String, Object> loginParams){
|
||||
// 先获取动态码
|
||||
HashMap<String, Object> 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>请求接口获取响应数据</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/2/9 16:22
|
||||
* @param url 教研资地址
|
||||
* @param params 参数
|
||||
* @param headers 请求头
|
||||
* @param key 响应字段
|
||||
* @return 接口响应数据
|
||||
**/
|
||||
private Object getResponseDataByPost(String url, Map<String, Object> params,
|
||||
Map<String, String> 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()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>请求接口获取响应数据</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/2/9 16:22
|
||||
* @param url 教研资地址
|
||||
* @param params 参数
|
||||
* @param headers 请求头
|
||||
* @return 接口响应数据
|
||||
* @param key 响应字段
|
||||
**/
|
||||
private Object getResponseDataByGet(String url, Map<String, Object> params,
|
||||
Map<String, String> 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>请求接口获取响应数据</h1>
|
||||
* @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<String, String> 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<String, Object> 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);
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ public class RocketMQFactory {
|
|||
/**
|
||||
* <h2>生产者map</h2>
|
||||
**/
|
||||
private static Map<String, DefaultMQProducer> PRODUCER_MAP = new ConcurrentHashMap<>(16);
|
||||
private static final Map<String, DefaultMQProducer> PRODUCER_MAP = new ConcurrentHashMap<>(16);
|
||||
|
||||
/**
|
||||
* <h1>根据配置文件生成消费者对象</h1>
|
||||
|
@ -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<String, Object> 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<String, Object> 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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>生产者action 将流程数据发送到mq中</h1>
|
||||
|
@ -17,15 +21,24 @@ public class ProducerAction extends SafeCusBaseAction {
|
|||
* <h2>mq配置文件名称</h2>
|
||||
**/
|
||||
@RequiredMark
|
||||
@PrintParamMark
|
||||
private String MQConfigName;
|
||||
/**
|
||||
* <h2>配置文件唯一标识</h2>
|
||||
**/
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, String> SEX_MAPPING = new HashMap<>();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* <h1>通过outKey删除部门信息</h1>
|
||||
* <h1>通过outKey封存部门</h1>
|
||||
* @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<String, Integer> 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);
|
||||
|
||||
/**
|
||||
* <h1>获取第一个分部id</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2023/1/18 10:36
|
||||
* @return 分部id
|
||||
**/
|
||||
@Select("select id from hrmsubcompany")
|
||||
String getDefaultSubId();
|
||||
}
|
||||
|
|
|
@ -19,11 +19,19 @@ public abstract class CusInfoActionService implements CreateAction, DeleteAction
|
|||
protected final RecordSet recordSet = new RecordSet();
|
||||
|
||||
protected final Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* <h2>consumer-mapper</h2>
|
||||
**/
|
||||
protected final ConsumerMapper consumerMapper = Util.getMapper(ConsumerMapper.class);
|
||||
/**
|
||||
* <h2>分部id</h2>
|
||||
**/
|
||||
protected String subId;
|
||||
// 默认初始化分部ID
|
||||
{
|
||||
subId = consumerMapper.getDefaultSubId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>获取下一个人员id</h1>
|
||||
|
|
|
@ -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();
|
||||
|
||||
/**
|
||||
* <h1>作为生产者将流程数据推送至mq中</h1>
|
||||
* @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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
// 密码
|
||||
|
|
|
@ -137,26 +137,39 @@ public class RocketUtil {
|
|||
// 获取配置信息
|
||||
Map<String, Object> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
ConsumerGroup=weaver-car
|
||||
NameServer=183.192.65.118:9876
|
||||
Topic=OA_CAR_TOPIC
|
||||
Tag=*
|
|
@ -0,0 +1,4 @@
|
|||
ConsumerGroup=weaver-meal
|
||||
NameServer=183.192.65.118:9876
|
||||
Topic=OA_MEAL_TOPIC
|
||||
Tag=*
|
|
@ -0,0 +1,4 @@
|
|||
ConsumerGroup=weaver-meeting
|
||||
NameServer=183.192.65.118:9876
|
||||
Topic=OA_MEETING_TOPIC
|
||||
Tag=*
|
|
@ -0,0 +1,4 @@
|
|||
ConsumerGroup=weaver-visitor
|
||||
NameServer=183.192.65.118:9876
|
||||
Topic=OA_VISITOR_TOPIC
|
||||
Tag=*
|
|
@ -0,0 +1,4 @@
|
|||
ConsumerGroup=weaver-org
|
||||
NameServer=183.192.65.118:9876
|
||||
Topic=AUTH_CONSOLE_ORG_TOPIC
|
||||
Tag=*
|
|
@ -0,0 +1,4 @@
|
|||
ConsumerGroup=weaver-password
|
||||
NameServer=183.192.65.118:9876
|
||||
Topic=AUTH_CONSOLE_USERINFO_PASSWORD_TOPIC
|
||||
Tag=*
|
|
@ -0,0 +1,4 @@
|
|||
ConsumerGroup=weaver-userinfo
|
||||
NameServer=183.192.65.118:9876
|
||||
Topic=AUTH_CONSOLE_USERINFO_TOPIC
|
||||
Tag=*
|
|
@ -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);
|
||||
|
|
|
@ -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.*;
|
||||
|
||||
/**
|
||||
* <h1>上海团校测试类</h1>
|
||||
*
|
||||
* @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<String, Object> responseMap = JSONObject.parseObject(json, HashMap.class);
|
||||
log.info("responseMap : " + responseMap);
|
||||
Object data = responseMap.get("data");
|
||||
List<?> list = JSONObject.parseArray(data.toString(), StudentClass.class);
|
||||
List<LinkedHashMap<String, Object>> params = new ArrayList<>();
|
||||
List<List<String>> whereParams = new ArrayList<>();
|
||||
for (Object o : list) {
|
||||
if(Objects.isNull(o)){
|
||||
continue;
|
||||
}
|
||||
Class<?> clazz = o.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
|
||||
ArrayList<String> 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue