柏美流水创建,团校mq代码修改

main
王宣然 2023-02-12 21:08:09 +08:00
parent 65ebec9fa3
commit dfc89e7d21
31 changed files with 820 additions and 117 deletions

View File

@ -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);

View File

@ -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 {

View File

@ -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,13 +130,16 @@ 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);
if(StringUtils.isBlank(serialNumber)){
res = START_NO;
}else {
String front = serialNumber.substring(0,2);
String end = serialNumber.substring(3);
int frontInt = Util.getIntValue(front);
@ -96,15 +156,17 @@ public class CusCreateWaterNoAction extends SafeCusBaseAction {
if(frontInt < 10){
frontStr = "0" + frontInt;
}
res = frontStr + endStr;
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;
}

View File

@ -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;
}

View File

@ -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 "";
}

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)));
}
}
}

View File

@ -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);
}
}

View File

@ -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,12 +73,11 @@ 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 {
@ -90,14 +89,13 @@ public class RocketMQFactory {
try {
defaultMQProducer.start();
}catch (MQClientException e){
throw new CustomerException("producer start error!");
throw new CustomerException("producer start error!",e);
}
// mq地址
defaultMQProducer.setNamesrvAddr(Util.null2String(configMap.get("NameServer")));
PRODUCER_MAP.put(configName, defaultMQProducer);
}
}
}
return defaultMQProducer;
}

View File

@ -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);
}
}
}

View File

@ -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<>();

View File

@ -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);
/**
@ -72,4 +73,13 @@ public interface ConsumerMapper {
@Update("update hrmresource set password = #{password} where id = #{id}")
boolean updatePasswordById(@ParamMapper("id") String id,
@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();
}

View File

@ -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>

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
// 密码

View File

@ -146,17 +146,30 @@ public class RocketUtil {
} catch (Exception e) {
throw new CustomerException(Util.logStr("init message error : {} !", e.getMessage()));
}
// 发送成功标识
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)){
log.error(Util.logStr("producer send message call back status is not ok! the message is {}, the status is {}.", msg, sendStatus));
// 如果失败
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);
}
}
}

View File

@ -0,0 +1,4 @@
ConsumerGroup=weaver-car
NameServer=183.192.65.118:9876
Topic=OA_CAR_TOPIC
Tag=*

View File

@ -0,0 +1,4 @@
ConsumerGroup=weaver-meal
NameServer=183.192.65.118:9876
Topic=OA_MEAL_TOPIC
Tag=*

View File

@ -0,0 +1,4 @@
ConsumerGroup=weaver-meeting
NameServer=183.192.65.118:9876
Topic=OA_MEETING_TOPIC
Tag=*

View File

@ -0,0 +1,4 @@
ConsumerGroup=weaver-visitor
NameServer=183.192.65.118:9876
Topic=OA_VISITOR_TOPIC
Tag=*

View File

@ -0,0 +1,4 @@
ConsumerGroup=weaver-org
NameServer=183.192.65.118:9876
Topic=AUTH_CONSOLE_ORG_TOPIC
Tag=*

View File

@ -0,0 +1,4 @@
ConsumerGroup=weaver-password
NameServer=183.192.65.118:9876
Topic=AUTH_CONSOLE_USERINFO_PASSWORD_TOPIC
Tag=*

View File

@ -0,0 +1,4 @@
ConsumerGroup=weaver-userinfo
NameServer=183.192.65.118:9876
Topic=AUTH_CONSOLE_USERINFO_TOPIC
Tag=*

View File

@ -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);

View File

@ -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);
}
}