ASC 精品酒业 凭证相关接口开发

dev
weilin.zhu 2023-07-17 18:26:35 +08:00
parent e272a1f295
commit 97325c17df
21 changed files with 1645 additions and 13 deletions

View File

@ -32,15 +32,7 @@ public class PushModeDataUtil {
public Map<String,Object> getConfigurationByKeyId(String keyId){ public Map<String,Object> getConfigurationByKeyId(String keyId){
Map<String,Object> configMap = sqlMapper.getPushDataConfiguration(keyId); Map<String,Object> configMap = sqlMapper.getPushDataConfiguration(keyId);
if(configMap != null && configMap.size() > 0){ return getConfiguration(configMap);
int mainKeyId = (int) configMap.get("id");
List<Map<String, Object>> fieldList = sqlMapper.getPushDataDetailConfiguration(mainKeyId);
configMap.put("fieldList",fieldList);
}
return configMap;
} }
/** /**
@ -51,6 +43,15 @@ public class PushModeDataUtil {
public Map<String,Object> getConfigurationByModeId(int modeId){ public Map<String,Object> getConfigurationByModeId(int modeId){
Map<String,Object> configMap = sqlMapper.getPushDataConfigurationByModeId(modeId); Map<String,Object> configMap = sqlMapper.getPushDataConfigurationByModeId(modeId);
return getConfiguration(configMap);
}
/**
*
* @param configMap
* @return
*/
private Map<String, Object> getConfiguration(Map<String, Object> configMap) {
if(configMap != null && configMap.size() > 0){ if(configMap != null && configMap.size() > 0){
int mainKeyId = (int) configMap.get("id"); int mainKeyId = (int) configMap.get("id");

View File

@ -0,0 +1,104 @@
package weaver.weilin.zhu.asc.workflow;
import aiyh.utils.Util;
import aiyh.utils.httpUtil.HttpArgsType;
import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import com.alibaba.fastjson.JSONObject;
import org.apache.log4j.Logger;
import weaver.file.Prop;
import weaver.weilin.zhu.common.util.CommonUtil;
import weaver.weilin.zhu.common.voucher.action.CusActionPostInterface;
import weaver.weilin.zhu.common.voucher.action.ResultMessageUtil;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* ASC
* JSON NC Action
* @author bleach
* @version v1.0 2023-07-10
*/
public class VoucherPushAction implements CusActionPostInterface {
/**
*
*/
private final Logger logger = Util.getLogger();
/**
*
*
* @param params
* @return
*/
@SuppressWarnings("unchecked")
@Override
public ResultMessageUtil postProcessor(Map<String, Object> params) {
ResultMessageUtil resultMessageUtil = new ResultMessageUtil();
JSONObject postObj = (JSONObject) params.get("pushJsonObject");
Map<String,Object> workflowBaseMap = (Map<String,Object>) params.get("workflowBaseMap");
Map<String,String> pathParam = (Map<String,String>) params.get("pathParam");
Map<String,Object> logMap = new HashMap<>();
logMap.put("rid",workflowBaseMap.get("requestId"));
logMap.put("interface_name",Util.null2String(pathParam.get("pathParam")));
logMap.put("system_name",Util.null2String(pathParam.get("system_name")));
logMap.put("systemCode",Util.null2String(pathParam.get("systemCode")));
//获取接口请求地址
String requestURL = Util.null2String(Prop.getPropValue("AscVoucher", "url"));
Map<String,String> headerMap = new HashMap<>();
headerMap.put("Content-Type", HttpArgsType.APPLICATION_JSON);
HttpUtils httpUtils = new HttpUtils();
try {
//进行接口数据推送
ResponeVo responeVo = httpUtils.apiPostObject(requestURL, postObj, headerMap);
if(responeVo != null && responeVo.getCode() == 200){
logMap.put("message",responeVo.getEntityString());
//接口返回所有信息
resultMessageUtil.setResponseBody(responeVo.getEntityString());
Map<String,Object> resultMap = responeVo.getResponseMap();
if(resultMap != null){
String state = Util.null2String(resultMap.get("state"));
resultMessageUtil.setSuccess("1".equals(state));
logMap.put("result","1".equals(state) ? 0 : 1);
} else {
logMap.put("result",1);
logMap.put("message","接口返回信息为空!");
}
} else {
logMap.put("result",1);
logMap.put("message","接口返回信息为空或者请求失败!");
}
} catch (IOException e) {
logger.error("接口请求异常,异常信息:[" + e.getMessage() + "]");
logMap.put("result",1);
logMap.put("message","接口请求异常,异常信息:[" + e.getMessage() + "]");
throw new RuntimeException(e);
}
int modeid = Util.getIntValue(Prop.getPropValue("global", "interfacelog_modeid"));
CommonUtil.insertNewDataToMode(modeid,"uf_interface_log",logMap);
return resultMessageUtil;
}
}

View File

@ -0,0 +1,100 @@
package weaver.weilin.zhu.common.util;
import aiyh.utils.Util;
import weaver.conn.RecordSet;
import weaver.general.TimeUtil;
import weaver.weilin.zhu.common.util.mapper.CommonSqlMapper;
import java.util.Map;
/**
*
*/
public class CommonUtil {
/**
*
*/
private static final CommonSqlMapper sqlMapper = Util.getMapper(CommonSqlMapper.class);
/**
*
* @param fieldId ID
* @return
*/
public static FieldDetailInfo getFieldDetailInfo(int fieldId){
FieldDetailInfo fieldDetailInfo = new FieldDetailInfo();
if(fieldId != 0) {
RecordSet rs = new RecordSet();
String selectSQL = "select id,fieldName,viewType,detailTable,fieldDbType from workflow_billField where id = ?";
if (rs.executeQuery(selectSQL, fieldId) && rs.next()) {
//字段数据库名称
String fieldName = Util.null2String(rs.getString("fieldName"));
//字段所属
int viewType = Util.getIntValue(rs.getString("viewType"),0);
//字段明细表名称
String detailTable = Util.null2String(rs.getString("detailTable"));
//字段数据库类型
String fieldDbType = Util.null2String(rs.getString("fieldDbType"));
fieldDetailInfo.setId(fieldId);
fieldDetailInfo.setFieldName(fieldName);
fieldDetailInfo.setDetailTable(detailTable);
fieldDetailInfo.setDbType(fieldDbType);
if(viewType == 1 && !"".equals(detailTable)){
int detailIndex = Util.getIntValue(detailTable.substring(detailTable.indexOf("_dt") + 3),-1);
fieldDetailInfo.setDetailIndex(detailIndex);
} else {
fieldDetailInfo.setDetailIndex(0);
}
}
}
return fieldDetailInfo;
}
/**
* ID BUG
* @param modeTableName
* @return ID
*/
public static int getModeIdByTableName(String modeTableName) {
return sqlMapper.getModeIdByTableName(modeTableName);
}
/**
*
* @param modeId ID
* @param modeTableName
* @param dataMap
*/
public static void insertNewDataToMode(int modeId,String modeTableName, Map<String,Object> dataMap){
//获取新的记录ID
int newDataId = Util.getModeDataId(modeTableName,modeId,1);
if(newDataId > 0){
StringBuilder updateSql = new StringBuilder();
updateSql.append("update ").append(modeTableName).append(" set modeDataModifyDatetime = '").append(TimeUtil.getCurrentTimeString()).append("'");
for(String key : dataMap.keySet()){
updateSql.append(",").append(key).append("=?");
}
updateSql.append(" where id = #{id}");
dataMap.put("id",newDataId);
if(sqlMapper.insertModeData(updateSql.toString(),dataMap)){
sqlMapper.deleteRedundancyData(modeTableName,newDataId);
}
}
}
}

View File

@ -0,0 +1,42 @@
package weaver.weilin.zhu.common.util;
import lombok.Data;
/**
*
* @author bleach
* @version 2023-07-10
*/
@Data
public class FieldDetailInfo {
/**
* ID
*/
private int id;
/**
*
*/
private String fieldName;
/**
* 0- 1-
*/
private int viewType;
/**
*
*/
private String detailTable;
/**
*
*/
private String dbType;
/**
*
*/
private int detailIndex;
}

View File

@ -0,0 +1,42 @@
package weaver.weilin.zhu.common.util.mapper;
import aiyh.utils.annotation.recordset.*;
import java.util.Map;
/**
*
* @author bleach
* @version 2023-07-12
*/
public interface CommonSqlMapper {
/**
* ID BUG
* @param tableName
* @return ID
*/
@Select("select m.id from modeInfo m inner join workflow_bill wb on m.formId = wb.id where lower(wb.tableName) = #{tableName}")
int getModeIdByTableName(@ParamMapper("tableName") String tableName);
/**
*
* @param updateSql SQL
* @param dataMap
* @return
*/
@Update(custom = true)
boolean insertModeData(@SqlString String updateSql, Map<String,Object> dataMap);
/**
*
* @param tableName
* @param dataId ID
* @return
*/
@Delete("delete from $t{tableName} where id = #{dataId}")
boolean deleteRedundancyData(@ParamMapper("tableName") String tableName, @ParamMapper("dataId") int dataId);
}

View File

@ -0,0 +1,230 @@
package weaver.weilin.zhu.common.voucher.action;
import aiyh.utils.Util;
import aiyh.utils.action.SafeCusBaseAction;
import aiyh.utils.annotation.ActionDefaultTestValue;
import aiyh.utils.annotation.PrintParamMark;
import aiyh.utils.annotation.RequiredMark;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo;
import weaver.weilin.zhu.common.voucher.entity.BaseConfigDao;
import weaver.weilin.zhu.common.voucher.util.CommonVoucherUtil;
import weaver.weilin.zhu.common.voucher.mapper.CommVoucherSqlMapper;
import weaver.zwl.common.ToolUtilNew;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
/**
* Action
* @author bleach
* @version 2023-07-10
*/
public class CommonVoucherAction extends SafeCusBaseAction {
/**
*
*/
private final Logger logger = Util.getLogger();
/**
* SQL
*/
private final CommVoucherSqlMapper sqlMapper = Util.getMapper(CommVoucherSqlMapper.class);
/**
*
*/
private String cusParamValue;
/**
*
*/
@RequiredMark("具体接口请求实现接口类路径!")
@ActionDefaultTestValue("weaver.weilin.zhu.asc.workflow.VoucherPushAction")
@PrintParamMark
private String implementorPath;
/**
* <h2>action </h2>
* <p>
* log Util.actionFailException(requestManager,"error msg"); action
* </p>
*
* @param requestId ID
* @param billTable
* @param workflowId ID
* @param user
* @param requestInfo
*/
@Override
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
logger.info("--------------- CommonVoucherAction Begin ---------------");
Map<String,Object> workflowBaseMap = getWorkflowBaseInfo(requestInfo.getRsTrans(),requestId);
CommonVoucherUtil voucherUtil = new CommonVoucherUtil();
voucherUtil.setWorkflowBaseMap(workflowBaseMap);
//自定义配置
BaseConfigDao baseConfigDao = voucherUtil.getConfigurationByWorkflowId(String.valueOf(workflowId), cusParamValue);
assert baseConfigDao != null;
voucherUtil.setThisUser(user);
voucherUtil.setObjectMappingDaoList(baseConfigDao.getObjectMappingDaoList());
voucherUtil.setNodeFieldMappingDaoList(baseConfigDao.getNodeFieldMappingDaoList());
RecordSet rs ;
String dataCondition = baseConfigDao.getDataCondition();
if(StringUtils.isNotBlank(dataCondition)){
rs = sqlMapper.getWorkflowMainTableInfoAndCondition(billTable,requestId, ToolUtilNew.staticToDBC(dataCondition));
} else {
rs = sqlMapper.getWorkflowMainTableInfo(billTable,requestId);
}
if(!rs.next()){
logger.info("当前流程不满足自定义条件!");
}
workflowBaseMap.put("mainId",Util.null2String(rs.getString("id")));
//推送的报文
JSONObject postJsonObj = new JSONObject();
StringBuilder postXmlObj = new StringBuilder();
if(baseConfigDao.getDataFormat() == 1){
postXmlObj = voucherUtil.recursionGenerateXML("",null,null,0,0,0);
} else {
//推送的报文
postJsonObj = voucherUtil.recursionGenerateJsonObject("",null,null,0,0,0);
}
if(postJsonObj != null || postXmlObj.length() > 0){
if(StringUtils.isNotBlank(implementorPath)){
Map<String, String> pathParam = Util.parseCusInterfacePathParam(implementorPath);
String className = pathParam.remove("_ClassPath");
Map<String,Object> paramsMap = new HashMap<>();
paramsMap.put("pushJsonObject",postJsonObj);
paramsMap.put("pushXmlObject",postXmlObj);
paramsMap.put("pathParam",pathParam);
paramsMap.put("requestInfo",requestInfo);
paramsMap.put("workflowBaseMap",workflowBaseMap);
paramsMap.put("userInfo",user);
ResultMessageUtil resultMessageUtil = executePostProcessor(className,paramsMap);
if(resultMessageUtil.isSuccess()){
String backFieldname = baseConfigDao.getBackFieldname();
String backFieldValue = resultMessageUtil.getBackFieldValue();
sqlMapper.resultBackToWorkflowBill(billTable,backFieldname,backFieldValue,requestId);
} else {
//获取失败的错误提示
String tipMessage = resultMessageUtil.getTipMessage();
if(baseConfigDao.getExceptionContinue() == 0){
//阻止流程提交
Util.actionFail(requestInfo.getRequestManager(),tipMessage);
}
}
}
}
logger.info("--------------- CommonVoucherAction End ---------------");
}
/**
*
* @param trans
* @param requestId ID
* @return
*/
private Map<String,Object> getWorkflowBaseInfo(RecordSetTrans trans,String requestId){
Map<String,Object> baseInfo = new HashMap<>();
if(trans == null){
trans = new RecordSetTrans();
}
String selectSQL = "select requestName,requestMark from workflow_requestBase where requestId = ?";
try {
if(trans.executeQuery(selectSQL,requestId) && trans.next()){
baseInfo.put("requestName",Util.null2String(trans.getString(1)));
baseInfo.put("requestMark",Util.null2String(trans.getString(2)));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return baseInfo;
}
/**
*
*
* @param className
* @param params
* @return
*/
private ResultMessageUtil executePostProcessor(String className, Map<String, Object> params) {
Class<?> aClass;
try {
aClass = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("未能找到自定义action接口处理方法" + className);
}
Constructor<?> constructor;
try {
constructor = aClass.getConstructor();
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(className + "没有空参构造方法,无法获取构造方法对象!");
}
if (!CusActionPostInterface.class.isAssignableFrom(aClass)) {
throw new IllegalArgumentException("自定义后置处理接口:" + className + " 不是"
+ CusActionPostInterface.class.getName() + "的子类或实现类!");
}
CusActionPostInterface o;
try {
o = (CusActionPostInterface) constructor.newInstance();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException("无法构造" + className + "对象!");
}
return o.postProcessor(params);
}
public String getCusParamValue() {
return cusParamValue;
}
public void setCusParamValue(String cusParamValue) {
this.cusParamValue = cusParamValue;
}
public String getImplementorPath() {
return implementorPath;
}
public void setImplementorPath(String implementorPath) {
this.implementorPath = implementorPath;
}
}

View File

@ -0,0 +1,22 @@
package weaver.weilin.zhu.common.voucher.action;
import java.util.Map;
/**
*
* JSONObjectXML
*
*
* @author bleach
*/
public interface CusActionPostInterface {
/**
*
*
* @param params
* @return
*/
ResultMessageUtil postProcessor(Map<String, Object> params);
}

View File

@ -0,0 +1,32 @@
package weaver.weilin.zhu.common.voucher.action;
import lombok.Data;
/**
*
*
*/
@Data
public class ResultMessageUtil {
/**
*
*/
private boolean isSuccess;
/**
*
*/
private String tipMessage;
/**
*
*/
private String responseBody;
/**
*
*/
private String backFieldValue;
}

View File

@ -0,0 +1,21 @@
package weaver.weilin.zhu.common.voucher.convert;
import weaver.weilin.zhu.common.voucher.entity.NodeFieldMappingDao;
import java.util.Map;
/**
*
* @author bleach
*/
public interface CusAsyncConvert {
/**
*
* @param dao
* @param param
* @param pathParam
* @return
*/
String cusConvert(NodeFieldMappingDao dao, RuleMethodParam param, Map<String, String> pathParam);
}

View File

@ -0,0 +1,213 @@
package weaver.weilin.zhu.common.voucher.convert;
import aiyh.utils.Util;
import aiyh.utils.annotation.MethodRuleNo;
import aiyh.utils.excention.CustomerException;
import com.google.common.base.Strings;
import org.apache.commons.lang3.StringUtils;
import weaver.general.TimeUtil;
import weaver.weilin.zhu.common.util.FieldDetailInfo;
import weaver.weilin.zhu.common.voucher.entity.NodeFieldMappingDao;
import weaver.zwl.common.ToolUtilNew;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
/**
*
* @author bleach
* @version 2023-07-04
*/
public class FieldChangeRuleMethod {
public static final Map<Integer, BiFunction<NodeFieldMappingDao, RuleMethodParam,String>> VALUE_RULE_FUNCTION = new HashMap<>();
static {
Class<FieldChangeRuleMethod> valueRuleMethodClass = FieldChangeRuleMethod.class;
Method[] methods = valueRuleMethodClass.getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(MethodRuleNo.class)) {
MethodRuleNo annotation = method.getAnnotation(MethodRuleNo.class);
int value = annotation.value();//规则标识
VALUE_RULE_FUNCTION.put(value, (config, map) -> {
try {
FieldChangeRuleMethod valueRuleMethod = new FieldChangeRuleMethod();
return method.invoke(valueRuleMethod, config, map).toString();
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
});
}
}
}
/**
*
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 0, desc = "不转换")
public String noChange(NodeFieldMappingDao dao, RuleMethodParam param) {
String fieldValue = "";
FieldDetailInfo fieldInfo = dao.getWfField();
if(fieldInfo != null){
String fieldName = fieldInfo.getFieldName();//字段名称
if(StringUtils.isNotBlank(fieldName)){
int viewType = fieldInfo.getViewType();
if(viewType == 0){
fieldValue = Util.null2String(param.getRs().getString(fieldName));
} else if(viewType == 1 && param.getRs_detail() != null){
fieldValue = Util.null2String(param.getRs_detail().getString(fieldName));
}
}
}
return fieldValue;
}
/**
* ID
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 1, desc = "流程请求ID")
public String workflowRequestId(NodeFieldMappingDao dao,RuleMethodParam param) {
return Util.null2String(param.getWorkflowBaseMap().get("requestId"));
}
/**
*
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 2, desc = "流程请求标题")
public String workflowRequestTitle(NodeFieldMappingDao dao,RuleMethodParam param) {
return Util.null2String(param.getWorkflowBaseMap().get("requestName"));
}
/**
*
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 3, desc = "流程请求编号")
public String workflowRequestMark(NodeFieldMappingDao dao,RuleMethodParam param) {
return Util.null2String(param.getWorkflowBaseMap().get("requestMark"));
}
/**
*
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 4, desc = "系统日期")
public String systemDate(NodeFieldMappingDao dao,RuleMethodParam param) {
return TimeUtil.getCurrentDateString();
}
/**
*
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 5, desc = "系统日期时间")
public String systemDateTime(NodeFieldMappingDao dao,RuleMethodParam param) {
return TimeUtil.getCurrentTimeString();
}
/**
*
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 6, desc = "固定值")
public String fixValue(NodeFieldMappingDao dao,RuleMethodParam param) {
return Util.null2String(dao.getCusSQL());
}
/**
*
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 7, desc = "明细序列")
public String getDetailRowNum(NodeFieldMappingDao dao,RuleMethodParam param) {
return Util.null2String(param.getRowNum());
}
/**
* SQL
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 8, desc = "自定义SQL")
public String customizeSQL(NodeFieldMappingDao dao,RuleMethodParam param) {
String fieldName = dao.getNodeName();//字段名称
//字段值
String fieldValue = noChange(dao,param);
String cusSQL = dao.getCusSQL();
int detailKeyId = -1;
if(StringUtils.isNotBlank(cusSQL)){
if( cusSQL.contains("{dt.id}") && param.getRs_detail() != null) {
detailKeyId = Util.getIntValue(param.getRs_detail().getString("id"), -1);
}
if(param.getThisUser() != null){
cusSQL = cusSQL.replace("{userId}", String.valueOf(param.getThisUser().getUID()));
cusSQL = cusSQL.replace("{departmentId}", String.valueOf(param.getThisUser().getUserDepartment()));
cusSQL = cusSQL.replace("{subCompanyId}", String.valueOf(param.getThisUser().getUserSubCompany1()));
}
}
fieldValue = ToolUtilNew.getStaticValueByChangeRule(cusSQL,fieldValue,Util.null2String(param.getWorkflowBaseMap().get("requestId")),detailKeyId);
return fieldValue;
}
/**
*
* @param dao
* @param param
* @return
*/
@MethodRuleNo(value = 9, desc = "自定义接口")
public String getCusConvertInterface(NodeFieldMappingDao dao, RuleMethodParam param) {
String cusText = dao.getCusSQL();
if(Strings.isNullOrEmpty(cusText)){
return null;
}
try {
Class<?> clazz = Class.forName(cusText);
if(!CusAsyncConvert.class.isAssignableFrom(clazz)){
throw new CustomerException(cusText + " 接口不存在或者未实现 weaver.weilin.zhu.common.voucher.convert.CusAsyncConvert类!");
}
CusAsyncConvert o = (CusAsyncConvert) clazz.newInstance();
Map<String, String> pathParam = Util.parseCusInterfacePathParam(cusText);
return o.cusConvert(dao, param, pathParam);
}catch (Exception e){
return null;
}
}
}

View File

@ -0,0 +1,43 @@
package weaver.weilin.zhu.common.voucher.convert;
import lombok.Getter;
import lombok.Setter;
import weaver.conn.RecordSet;
import weaver.hrm.User;
import java.util.Map;
/**
*
* @author bleach
* @version 2023-07-04
*/
@Getter
@Setter
public class RuleMethodParam {
/**
*
*/
private RecordSet rs ;
/**
*
*/
private RecordSet rs_detail;
/**
*
*/
private Map<String,Object> workflowBaseMap;
/**
*
*/
private int rowNum;
/**
*
*/
private User thisUser;
}

View File

@ -0,0 +1,60 @@
package weaver.weilin.zhu.common.voucher.entity;
import lombok.Data;
import java.util.List;
/**
*
*
* @author bleach
* @version 2023-07-10
*/
@Data
public class BaseConfigDao {
/**
* ID
*/
private int id;
/**
* ID
*/
private String workflowId;
/**
*
*/
private String cusParamValue;
/**
*
*/
private String dataCondition;
/**
*
*/
private int exceptionContinue;
/**
* 0-JSON 1-XML
*/
private int dataFormat;
/**
*
*/
private String backFieldname;
/**
*
*/
private List<ObjectMappingDao> objectMappingDaoList;
/**
*
*/
private List<NodeFieldMappingDao> nodeFieldMappingDaoList;
}

View File

@ -0,0 +1,59 @@
package weaver.weilin.zhu.common.voucher.entity;
import lombok.Data;
import weaver.weilin.zhu.common.util.FieldDetailInfo;
/**
*
*
* @author bleach
* @version 2023-07-10
*/
@Data
public class NodeFieldMappingDao {
/**
* ID
*/
private int id;
/**
*
*/
private String nodeName;
/**
*
*/
private String parentNode;
/**
* 0- 1- 2- 3-
*/
private int nodeType;
/**
*
*/
private FieldDetailInfo wfField;
/**
*
*/
private String entriesDirection;
/**
*
*/
private int changeRule;
/**
*
*/
private String cusSQL;
/**
* 0- 1- 2-
*/
private int specialAttr;
}

View File

@ -0,0 +1,43 @@
package weaver.weilin.zhu.common.voucher.entity;
import lombok.Data;
/**
*
*
* @author bleach
* @version 2023-07-10
*/
@Data
public class ObjectMappingDao {
/**
* ID
*/
private int id;
/**
*
*/
private String objectName;
/**
*
*/
private int dtIndex;
/**
*
*/
private String alias;
/**
*
*/
private String entriesDirection;
/**
*
*/
private String dtCondition;
}

View File

@ -0,0 +1,62 @@
package weaver.weilin.zhu.common.voucher.entity;
/**
*
*
*/
public class VoucherConstants {
/**
* -
*/
public static final int EntriesDirection_NoVoucher = 0;
/**
* -
*/
public static final int EntriesDirection_Comm_Debit = 1;
/**
* -
*/
public static final int EntriesDirection_Tax_Debit = 2;
/**
* -
*/
public static final int EntriesDirection_Comm_Credit = 3;
/**
* -
*/
public static final int EntriesDirection_WriteOff_Credit = 4;
/**
* -
*/
public static final int Node_Type_Comm_Text = 0;
/**
* -
*/
public static final int Node_Type_Comm_Object = 1;
/**
* -
*/
public static final int Node_Type_Array_Text = 2;
/**
* -
*/
public static final int Node_Type_Array_Object = 3;
}

View File

@ -0,0 +1,143 @@
package weaver.weilin.zhu.common.voucher.mapper;
import aiyh.utils.annotation.recordset.*;
import weaver.conn.RecordSet;
import weaver.weilin.zhu.common.voucher.entity.BaseConfigDao;
import weaver.weilin.zhu.common.voucher.entity.NodeFieldMappingDao;
import weaver.weilin.zhu.common.voucher.entity.ObjectMappingDao;
import java.util.List;
/**
*
*
* @author bleach
*/
@SqlMapper
public interface CommVoucherSqlMapper {
/**
* ID
* @param workflowIds ID
* @return
*/
@Select("select * from uf_comm_voucher where wfId in ($t{workflowIds})")
@CollectionMappings({
@CollectionMapping(
property = "objectMappingDaoList",
column = "id",
id = @Id(value = Integer.class, methodId = 1)
),
@CollectionMapping(
property = "nodeFieldMappingDaoList",
column = "id",
id = @Id(value = Integer.class,methodId = 2)
)
})
BaseConfigDao getConfigurationByWorkflowId(@ParamMapper("workflowIds") String workflowIds);
/**
* ID
* @param workflowIds ID
* @return
*/
@Select("select * from uf_comm_voucher where wfId in ($t{workflowIds}) and cusParamValue = #{cusParamValue}")
@CollectionMappings({
@CollectionMapping(
property = "objectMappingDaoList",
column = "id",
id = @Id(value = Integer.class, methodId = 1)
),
@CollectionMapping(
property = "nodeFieldMappingDaoList",
column = "id",
id = @Id(value = Integer.class,methodId = 2)
)
})
BaseConfigDao getConfigurationByWorkflowIdAndCondition(@ParamMapper("workflowIds") String workflowIds,@ParamMapper("cusParamValue") String cusParamValue);
/**
*
* @param mainId ID
* @return
*/
@Select("select * from uf_comm_voucher_dt1 where mainId = #{mainId}")
@CollectionMethod(value = 1,desc = "获取对象与流程明细表映射配置信息")
List<ObjectMappingDao> getObjectMappingByMainKeyId(@ParamMapper("mainId") int mainId);
/**
*
* @param mainId ID
* @return
*/
@Select("select * from uf_comm_voucher_dt2 where mainId = #{mainId}")
@Associations({
@Association(
property = "wfField",
column = "wfField",
select = "weaver.weilin.zhu.common.util.CommonUtil.getFieldDetailInfo",
id = @Id(Integer.class)
)
})
@CaseConversion(value = false)
@CollectionMethod(value = 2,desc = "获取节点名称与字段详细配置信息")
List<NodeFieldMappingDao> getNodeFieldMappingByMainKeyId(@ParamMapper("mainId") int mainId);
/**
*
* @param billTableMain
* @param requestId D
* @return
*/
@Select("select * from $t{billTableMain} where requestId = #{requestId}")
RecordSet getWorkflowMainTableInfo(@ParamMapper("billTableMain") String billTableMain,@ParamMapper("requestId") String requestId);
/**
*
* @param billTableMain
* @param requestId D
* @return
*/
@Select("select * from $t{billTableMain} where requestId = #{requestId} and $t{condition}")
RecordSet getWorkflowMainTableInfoAndCondition(@ParamMapper("billTableMain") String billTableMain,@ParamMapper("requestId") String requestId,@ParamMapper("condition") String condition);
/**
*
* @param detailTableName
* @param mainId ID
* @return
*/
@Select("select * from $t{detailTableName} where mainId = #{mainId}")
RecordSet getWorkflowDetailTableInfo(@ParamMapper("detailTableName") String detailTableName,@ParamMapper("mainId") String mainId);
/**
*
* @param detailTableName
* @param mainId ID
* @return
*/
@Select("select * from $t{detailTableName} where mainId = #{mainId} and $t{condition}")
RecordSet getWorkflowDetailTableInfoAndCondition(@ParamMapper("detailTableName") String detailTableName,@ParamMapper("mainId") String mainId,@ParamMapper("condition") String condition);
/**
*
* @param billTable
* @param backFieldName
* @param backFieldValue
* @param requestId ID
*/
@Update("update $t{billTable} set $t{backFieldName} = #{backFieldValue} where requestId = #{requestId}")
void resultBackToWorkflowBill(@ParamMapper("billTable") String billTable,@ParamMapper("backFieldName") String backFieldName,@ParamMapper("backFieldValue") String backFieldValue,@ParamMapper("requestId") String requestId);
}

View File

@ -0,0 +1,416 @@
package weaver.weilin.zhu.common.voucher.util;
import aiyh.utils.Util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.hrm.User;
import weaver.weilin.zhu.common.util.FieldDetailInfo;
import weaver.weilin.zhu.common.voucher.convert.FieldChangeRuleMethod;
import weaver.weilin.zhu.common.voucher.convert.RuleMethodParam;
import weaver.weilin.zhu.common.voucher.entity.BaseConfigDao;
import weaver.weilin.zhu.common.voucher.entity.NodeFieldMappingDao;
import weaver.weilin.zhu.common.voucher.entity.ObjectMappingDao;
import weaver.weilin.zhu.common.voucher.mapper.CommVoucherSqlMapper;
import weaver.workflow.workflow.WorkflowVersion;
import weaver.weilin.zhu.common.voucher.entity.VoucherConstants;
import weaver.zwl.common.ToolUtilNew;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
*
*
* @author bleach
* @version 2023-07-10
*/
public class CommonVoucherUtil {
/**
*
*/
private final CommVoucherSqlMapper sqlMapper = Util.getMapper(CommVoucherSqlMapper.class);
/**
*
*/
private Map<String,Object> workflowBaseMap;
/**
*
*/
private User thisUser;
/**
*
*/
private List<ObjectMappingDao> objectMappingDaoList;
/**
*
*/
private List<NodeFieldMappingDao> nodeFieldMappingDaoList;
public CommonVoucherUtil() {
}
/**
* ID
* @param workflowId ID
* @param cusParamValue
* @return
*/
public BaseConfigDao getConfigurationByWorkflowId(String workflowId,String cusParamValue){
BaseConfigDao dao = new BaseConfigDao();
//获取该流程类型对应的所有版本ID
String allWorkflowIds = WorkflowVersion.getAllVersionStringByWFIDs(workflowId);
if(StringUtils.isNotBlank(cusParamValue)){
dao = sqlMapper.getConfigurationByWorkflowIdAndCondition(allWorkflowIds,cusParamValue);
} else {
dao = sqlMapper.getConfigurationByWorkflowId(allWorkflowIds);
}
return dao;
}
/**
* JSON
* @param parentNode
* @param rs
* @param rs_detail
* @param dtIndex
* @param itemDirection
* @param rowNum
* @return JSON
*/
public JSONObject recursionGenerateJsonObject(String parentNode, RecordSet rs,RecordSet rs_detail, int dtIndex, int itemDirection,int rowNum){
JSONObject jsonObject = new JSONObject();
for(NodeFieldMappingDao nodeFieldMappingDao : nodeFieldMappingDaoList){
//节点名称
String _nodeName = nodeFieldMappingDao.getNodeName();
if(StringUtils.isBlank(_nodeName)){
continue;
}
/* 父节点名称 */
String _parentNode = nodeFieldMappingDao.getParentNode();
if(!_parentNode.equals(parentNode)){
continue;
}
int _nodeType = nodeFieldMappingDao.getNodeType();
if(itemDirection > 0){//说明为会计分录
String _entriesDirection = nodeFieldMappingDao.getEntriesDirection();
if(!_entriesDirection.contains(String.valueOf(itemDirection))){//传进来的会计分录方向与当前不一致
continue;
}
}
//流程字段新
FieldDetailInfo workflowField = nodeFieldMappingDao.getWfField();
if(workflowField != null){
int _viewType = workflowField.getViewType();
int _detailIndex = workflowField.getDetailIndex();
if(_viewType == 1 && _detailIndex != dtIndex){
continue;
}
}
RuleMethodParam param = new RuleMethodParam();
param.setRs(rs);
param.setRs_detail(rs_detail);
param.setWorkflowBaseMap(workflowBaseMap);
param.setRowNum(rowNum);
param.setThisUser(thisUser);
switch (_nodeType){
case VoucherConstants.Node_Type_Comm_Text:
String nodeValue = FieldChangeRuleMethod.VALUE_RULE_FUNCTION.get(nodeFieldMappingDao.getChangeRule()).apply(nodeFieldMappingDao, param);
if(nodeFieldMappingDao.getSpecialAttr() == 1 && Util.getDoubleValue(nodeValue,0.0) == 0){
return null;
}
jsonObject.put(_nodeName,nodeValue);
break;
case VoucherConstants.Node_Type_Comm_Object:
JSONObject commObj = recursionGenerateJsonObject(_nodeName,rs,rs_detail,dtIndex,itemDirection,rowNum);
jsonObject.put(_nodeName,commObj);
break;
case VoucherConstants.Node_Type_Array_Text:
JSONArray arrayText = new JSONArray();
String arrayTextValue = FieldChangeRuleMethod.VALUE_RULE_FUNCTION.get(nodeFieldMappingDao.getChangeRule()).apply(nodeFieldMappingDao,param);
if(StringUtils.isNotBlank(arrayTextValue)){
arrayText.addAll(Arrays.asList(Util.TokenizerString2(arrayTextValue, ",")));
}
jsonObject.put(_nodeName,arrayText);
break;
case VoucherConstants.Node_Type_Array_Object:
JSONArray itemArray = new JSONArray();
int _rowNum = 1;
for(ObjectMappingDao objectMappingDao : objectMappingDaoList){
String _objectName = objectMappingDao.getObjectName();
//别名
String alias = objectMappingDao.getAlias();
if(!_objectName.equals(_nodeName) || (StringUtils.isNotBlank(alias) && !alias.equals(_nodeName))){//对象节点名称 与当前节点不一致
continue;
}
int _dtIndex = objectMappingDao.getDtIndex();
String _entriesDirection = objectMappingDao.getEntriesDirection();
//父节点名称
String tmpParentNode = StringUtils.isNotBlank(alias) ? alias : _objectName;
if(_dtIndex > 0){
String dtCondition = objectMappingDao.getDtCondition();
RecordSet _rs_detail;
//流程明细表名称
String detailTable = Util.null2String(workflowBaseMap.get("billTableName")) + "_dt" + _dtIndex;
if(StringUtils.isNotBlank(dtCondition)){
dtCondition = ToolUtilNew.staticToDBC(dtCondition);
_rs_detail = sqlMapper.getWorkflowDetailTableInfoAndCondition(detailTable,Util.null2String(workflowBaseMap.get("mainId")),dtCondition);
} else {
_rs_detail = sqlMapper.getWorkflowDetailTableInfo(detailTable,Util.null2String(workflowBaseMap.get("mainId")));
}
while(_rs_detail.next()){
for(String direction : Util.TokenizerString2(_entriesDirection,",")) {
JSONObject itemObj = recursionGenerateJsonObject(tmpParentNode, rs, _rs_detail, _dtIndex, Util.getIntValue(direction), _rowNum++);
if(itemObj == null || itemObj.isEmpty()){
_rowNum--;
} else {
itemArray.add(itemObj);
}
}
}
} else {//说明信息来自主表
for(String direction : Util.TokenizerString2(_entriesDirection,",")){
JSONObject itemObj = recursionGenerateJsonObject(tmpParentNode,rs,null,0,Util.getIntValue(direction),_rowNum++);
if(itemObj == null || itemObj.isEmpty()){
_rowNum--;
} else {
itemArray.add(itemObj);
}
}
}
}
jsonObject.put(_nodeName,itemArray);
break;
}
}
return jsonObject;
}
/**
* XML
* @param parentNode
* @param rs
* @param rs_detail
* @param dtIndex
* @param itemDirection
* @param rowNum
* @return XML
*/
public StringBuilder recursionGenerateXML(String parentNode, RecordSet rs,RecordSet rs_detail, int dtIndex, int itemDirection,int rowNum){
StringBuilder xmlBuilder = new StringBuilder();
for(NodeFieldMappingDao nodeFieldMappingDao : nodeFieldMappingDaoList) {
//节点名称
String _nodeName = nodeFieldMappingDao.getNodeName();
if (StringUtils.isBlank(_nodeName)) {
continue;
}
//父节点名称
String _parentNode = nodeFieldMappingDao.getParentNode();
if (!_parentNode.equals(parentNode)) {
continue;
}
int _nodeType = nodeFieldMappingDao.getNodeType();
if (itemDirection > 0) {//说明为会计分录
String _entriesDirection = nodeFieldMappingDao.getEntriesDirection();
if (!_entriesDirection.contains(String.valueOf(itemDirection))) {//传进来的会计分录方向与当前不一致
continue;
}
}
//流程字段新
FieldDetailInfo workflowField = nodeFieldMappingDao.getWfField();
if (workflowField != null) {
int _viewType = workflowField.getViewType();
int _detailIndex = workflowField.getDetailIndex();
if (_viewType == 1 && _detailIndex != dtIndex) {
continue;
}
}
RuleMethodParam param = new RuleMethodParam();
param.setRs(rs);
param.setRs_detail(rs_detail);
param.setWorkflowBaseMap(workflowBaseMap);
param.setRowNum(rowNum);
param.setThisUser(thisUser);
switch (_nodeType) {
case VoucherConstants.Node_Type_Comm_Text:
String nodeValue = FieldChangeRuleMethod.VALUE_RULE_FUNCTION.get(nodeFieldMappingDao.getChangeRule()).apply(nodeFieldMappingDao, param);
if (nodeFieldMappingDao.getSpecialAttr() == 1 && Util.getDoubleValue(nodeValue, 0.0) == 0) {
return null;
}
xmlBuilder.append("<").append(_nodeName).append(">");
xmlBuilder.append(nodeValue);
xmlBuilder.append("</").append(_nodeName).append(">\n");
break;
case VoucherConstants.Node_Type_Array_Text:
break;
case VoucherConstants.Node_Type_Comm_Object:
StringBuilder innerXML = recursionGenerateXML(_nodeName,rs,rs_detail,dtIndex,itemDirection,rowNum);
xmlBuilder.append("<").append(_nodeName).append(">");
xmlBuilder.append(innerXML);
xmlBuilder.append("</").append(_nodeName).append(">\n");
break;
case VoucherConstants.Node_Type_Array_Object:
int _rowNum = 1;
for(ObjectMappingDao objectMappingDao : objectMappingDaoList) {
String _objectName = objectMappingDao.getObjectName();
//别名
String alias = objectMappingDao.getAlias();
if (!_objectName.equals(_nodeName) || (StringUtils.isNotBlank(alias) && !alias.equals(_nodeName))) {//对象节点名称 与当前节点不一致
continue;
}
int _dtIndex = objectMappingDao.getDtIndex();
String _entriesDirection = objectMappingDao.getEntriesDirection();
//父节点名称
String tmpParentNode = StringUtils.isNotBlank(alias) ? alias : _objectName;
if (_dtIndex > 0) {
String dtCondition = objectMappingDao.getDtCondition();
RecordSet _rs_detail;
//流程明细表名称
String detailTable = Util.null2String(workflowBaseMap.get("billTableName")) + "_dt" + _dtIndex;
if (StringUtils.isNotBlank(dtCondition)) {
dtCondition = ToolUtilNew.staticToDBC(dtCondition);
_rs_detail = sqlMapper.getWorkflowDetailTableInfoAndCondition(detailTable, Util.null2String(workflowBaseMap.get("mainId")), dtCondition);
} else {
_rs_detail = sqlMapper.getWorkflowDetailTableInfo(detailTable, Util.null2String(workflowBaseMap.get("mainId")));
}
while (_rs_detail.next()) {
for (String direction : Util.TokenizerString2(_entriesDirection, ",")) {
StringBuilder innerItem = recursionGenerateXML(tmpParentNode,rs,_rs_detail,_dtIndex,Util.getIntValue(direction),_rowNum);
if(innerItem != null && innerItem.length() > 0){
xmlBuilder.append("<").append(_nodeName).append(">");
xmlBuilder.append(innerItem);
xmlBuilder.append("</").append(_nodeName).append(">\n");
} else {
_rowNum--;
}
}
}
} else { //说明数据来自主表
for(String direction : Util.TokenizerString2(_entriesDirection,",")){
StringBuilder innerItem = recursionGenerateXML(tmpParentNode,rs,null,0,Util.getIntValue(direction),_rowNum++);
if(innerItem != null && innerItem.length() > 0){
xmlBuilder.append("<").append(_nodeName).append(">");
xmlBuilder.append(innerItem);
xmlBuilder.append("</").append(_nodeName).append(">\n");
} else {
_rowNum--;
}
}
}
}
break;
}
}
return xmlBuilder;
}
public User getThisUser() {
return thisUser;
}
public void setThisUser(User thisUser) {
this.thisUser = thisUser;
}
public Map<String, Object> getWorkflowBaseMap() {
return workflowBaseMap;
}
public void setWorkflowBaseMap(Map<String, Object> workflowBaseMap) {
this.workflowBaseMap = workflowBaseMap;
}
public List<ObjectMappingDao> getObjectMappingDaoList() {
return objectMappingDaoList;
}
public void setObjectMappingDaoList(List<ObjectMappingDao> objectMappingDaoList) {
this.objectMappingDaoList = objectMappingDaoList;
}
public List<NodeFieldMappingDao> getNodeFieldMappingDaoList() {
return nodeFieldMappingDaoList;
}
public void setNodeFieldMappingDaoList(List<NodeFieldMappingDao> nodeFieldMappingDaoList) {
this.nodeFieldMappingDaoList = nodeFieldMappingDaoList;
}
}

View File

@ -48,7 +48,7 @@ public interface OrganizationSyncSqlMapper {
@Association( @Association(
property = "modeField", property = "modeField",
column = "modeField", column = "modeField",
select = "weaver.common.util.CommonUtil.getFieldInfo", select = "weaver.weilin.zhu.common.util.CommonUtil.getFieldDetailInfo",
id = @Id(Integer.class) id = @Id(Integer.class)
) )
}) })

View File

@ -22,7 +22,6 @@ public class SyncOrgDataTask extends BaseCronJob {
public void execute() { public void execute() {
if(StringUtils.isNotBlank(keyId)){ if(StringUtils.isNotBlank(keyId)){
OrganizationSyncUtil syncUtil = new OrganizationSyncUtil(); OrganizationSyncUtil syncUtil = new OrganizationSyncUtil();
syncUtil.syncData(Util.getIntValue(keyId,0)); syncUtil.syncData(Util.getIntValue(keyId,0));
} }
} }

View File

@ -67,7 +67,7 @@ public class RequestDataToApiAction implements Action {
} catch (Exception e) { } catch (Exception e) {
requestInfo.getRequestManager().setMessageid("2022052791002"); requestInfo.getRequestManager().setMessageid("2022052791002");
requestInfo.getRequestManager().setMessagecontent("Action接口发生异常,requestId:"+ requestId +",请联系管理员!"); requestInfo.getRequestManager().setMessagecontent("Action接口发生异常,requestId:"+ requestId +",请联系管理员!");
logger.error("VoucherAction.select * from workflow_requestBase error;requestId:" + requestId + "exception:" + e.getMessage() + ";e:" + e); logger.error("CommonVoucherAction.select * from workflow_requestBase error;requestId:" + requestId + "exception:" + e.getMessage() + ";e:" + e);
return Action.FAILURE_AND_CONTINUE; return Action.FAILURE_AND_CONTINUE;
} }
//获取当前流程信息 //获取当前流程信息

View File

@ -66,7 +66,7 @@ public class RequestDataToApiAction implements Action {
} catch (Exception e) { } catch (Exception e) {
requestInfo.getRequestManager().setMessageid("2022052791002"); requestInfo.getRequestManager().setMessageid("2022052791002");
requestInfo.getRequestManager().setMessagecontent("Action接口发生异常,requestId:"+ requestId +",请联系管理员!"); requestInfo.getRequestManager().setMessagecontent("Action接口发生异常,requestId:"+ requestId +",请联系管理员!");
logger.error("VoucherAction.select * from workflow_requestBase error;requestId:" + requestId + "exception:" + e.getMessage() + ";e:" + e); logger.error("CommonVoucherAction.select * from workflow_requestBase error;requestId:" + requestId + "exception:" + e.getMessage() + ";e:" + e);
return Action.FAILURE_AND_CONTINUE; return Action.FAILURE_AND_CONTINUE;
} }
//获取当前流程信息 //获取当前流程信息