ic_excellent 2023-03-03 16:27:10 +08:00
commit 680e4b9343
9 changed files with 620 additions and 351 deletions

View File

@ -535,4 +535,35 @@ $(() => {
callback()
})
})
/* ******************* 流程明细字段包含某个字符串时给某个字段赋值为某个东西end ******************* */
/* ******************* 流程明细字段包含某个字符串时给某个字段赋值为某个东西end ******************* */
/* ******************* 提交外出流程 ******************* */
(function start() {
function fillNum(n) {
if (n < 10) {
return "0" + n;
} else {
return n;
}
}
let date = new Date()
let month = date.getMonth() + 1
let year = date.getFullYear();
let n = window.prompt("请输入日期:", date.getDate().toString())
let workDate = year + "-" + fillNum(month) + "-" + fillNum(n)
n = fillNum(n)
WfForm.changeFieldValue("field607", {value: workDate})
let workflowTitle = WfForm.getFieldValue("field-1");
WfForm.changeFieldValue("field-1", {value: workflowTitle.substring(0, workflowTitle.length - 2) + n})
WfForm.changeFieldValue("field609", {value: workDate})
WfForm.changeFieldValue("field608", {value: "00:00"})
WfForm.changeFieldValue("field610", {value: "23:59"})
WfForm.changeFieldValue("field30038", {value: 0})
WfForm.changeFieldValue("field611", {value: "出差"})
WfForm.changeFieldValue("field8715", {value: "2"})
$("button[ecid='_Route@vmt0lk_Comp@upn4fo_FormContent@g9f33k_MainLayout@kdmfyn_LayoutTr@ds2cqb@main_0_CellType@27chqt@main_17_10_FieldContent@r045n3_BrowserElement@2mq6lm_WeaBrowser@j1zg9h_WrappedComponent@i9q2c5_Component@iiw91q_Associative@zt8qgk_Button@ztqsd2_button@xq1ea3']").trigger("click")
})()
/* ******************* 提交外出流程 ******************* */

View File

@ -14,28 +14,40 @@ import java.lang.reflect.Field;
*/
public class DoubleTypeHandler implements TypeHandler {
@Override
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
String string = Util.null2DefaultStr(GetRsValueUtil.getRsValue(rs, fieldName, declaredField), "0.0");
return Double.parseDouble(string);
}
@Override
public Object getValue(RecordSet rs, int index, Field declaredField) {
String string = Util.null2DefaultStr(rs.getString(index), "0.0");
return Double.parseDouble(string);
}
@Override
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
String string = Util.null2DefaultStr(GetRsValueUtil.getRsValue(rs, fieldName, declaredField), "0.0");
return Double.parseDouble(string);
}
@Override
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
String string = Util.null2DefaultStr(rs.getString(index), "0.0");
return Double.parseDouble(string);
}
@Override
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
String string = Util.null2String(GetRsValueUtil.getRsValue(rs, fieldName, declaredField));
if ("".equals(string)) {
return null;
}
return Double.parseDouble(string);
}
@Override
public Object getValue(RecordSet rs, int index, Field declaredField) {
String string = Util.null2String(rs.getString(index));
if ("".equals(string)) {
return null;
}
return Double.parseDouble(string);
}
@Override
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
String string = Util.null2String(GetRsValueUtil.getRsValue(rs, fieldName, declaredField));
if ("".equals(string)) {
return null;
}
return Double.parseDouble(string);
}
@Override
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
String string = Util.null2String(rs.getString(index));
if ("".equals(string)) {
return null;
}
return Double.parseDouble(string);
}
}

View File

@ -14,28 +14,40 @@ import java.lang.reflect.Field;
*/
public class FloatTypeHandler implements TypeHandler {
@Override
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
String string = Util.null2DefaultStr(GetRsValueUtil.getRsValue(rs, fieldName, declaredField), "0.0");
return Float.parseFloat(string);
}
@Override
public Object getValue(RecordSet rs, int index, Field declaredField) {
String string = Util.null2DefaultStr(rs.getString(index), "0.0");
return Float.parseFloat(string);
}
@Override
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
String string = Util.null2DefaultStr(GetRsValueUtil.getRsValue(rs, fieldName, declaredField), "0.0");
return Float.parseFloat(string);
}
@Override
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
String string = Util.null2DefaultStr(rs.getString(index), "0.0");
return Float.parseFloat(string);
}
@Override
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
String string = Util.null2String(GetRsValueUtil.getRsValue(rs, fieldName, declaredField));
if ("".equals(string)) {
return null;
}
return Float.parseFloat(string);
}
@Override
public Object getValue(RecordSet rs, int index, Field declaredField) {
String string = Util.null2String(rs.getString(index), "0.0");
if ("".equals(string)) {
return null;
}
return Float.parseFloat(string);
}
@Override
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
String string = Util.null2String(GetRsValueUtil.getRsValue(rs, fieldName, declaredField));
if ("".equals(string)) {
return null;
}
return Float.parseFloat(string);
}
@Override
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
String string = Util.null2String(rs.getString(index));
if ("".equals(string)) {
return null;
}
return Float.parseFloat(string);
}
}

View File

@ -12,39 +12,51 @@ import java.lang.reflect.Field;
public class IntegerTypeHandler implements TypeHandler {
@Override
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
String string = Util.null2DefaultStr(GetRsValueUtil.getRsValue(rs, fieldName, declaredField), "-1");
if (string.contains(".")) {
string = string.substring(0, string.indexOf("."));
}
return Integer.parseInt(string);
}
@Override
public Object getValue(RecordSet rs, int index, Field declaredField) {
String string = Util.null2DefaultStr(rs.getString(index), "-1");
if (string.contains(".")) {
string = string.substring(0, string.indexOf("."));
}
return Integer.parseInt(string);
}
@Override
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
String string = Util.null2DefaultStr(GetRsValueUtil.getRsValue(rs, fieldName, declaredField), "-1");
if (string.contains(".")) {
string = string.substring(0, string.indexOf("."));
}
return Integer.parseInt(string);
}
@Override
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
String string = Util.null2DefaultStr(rs.getString(index), "-1");
if (string.contains(".")) {
string = string.substring(0, string.indexOf("."));
}
return Integer.parseInt(string);
}
@Override
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
String string = Util.null2String(GetRsValueUtil.getRsValue(rs, fieldName, declaredField));
if ("".equals(string)) {
return null;
}
if (string.contains(".")) {
string = string.substring(0, string.indexOf("."));
}
return Integer.parseInt(string);
}
@Override
public Object getValue(RecordSet rs, int index, Field declaredField) {
String string = Util.null2String(rs.getString(index));
if ("".equals(string)) {
return null;
}
if (string.contains(".")) {
string = string.substring(0, string.indexOf("."));
}
return Integer.parseInt(string);
}
@Override
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
String string = Util.null2String(GetRsValueUtil.getRsValue(rs, fieldName, declaredField));
if ("".equals(string)) {
return null;
}
if (string.contains(".")) {
string = string.substring(0, string.indexOf("."));
}
return Integer.parseInt(string);
}
@Override
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
String string = Util.null2String(rs.getString(index));
if ("".equals(string)) {
return null;
}
if (string.contains(".")) {
string = string.substring(0, string.indexOf("."));
}
return Integer.parseInt(string);
}
}

View File

@ -0,0 +1,64 @@
package com.api.youhong.ai.jitu.hrmlogintip.controller;
import aiyh.utils.ApiResult;
import aiyh.utils.Util;
import com.api.youhong.ai.jitu.hrmlogintip.service.HrmLoinTipService;
import org.apache.log4j.Logger;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
/**
* <h1></h1>
*
* <p>create: 2023/2/27 10:29</p>
*
* @author youHong.ai
*/
@Path("aiyh/hrm-login/tip")
public class HrmLoinTipController {
private final Logger log = Util.getLogger();
private final HrmLoinTipService service = new HrmLoinTipService();
@Path("/get/message")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String getMessage(@QueryParam("userAccount") String userAccount) {
try {
return ApiResult.success(service.getMessage(userAccount));
} catch (Exception e) {
log.error("get login before show message error! " + Util.getErrString(e));
return ApiResult.error("get message error!");
}
}
@Path("/get/message")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String readMessage(@Context HttpServletRequest request, @Context HttpServletResponse response,
@QueryParam("userAccount") String userAccount) {
User user = null;
try {
user = HrmUserVarify.getUser(request, response);
} catch (Exception ignore) {
}
try {
return ApiResult.success(service.updateMessageStatus(user, userAccount));
} catch (Exception e) {
log.error("update login before show message status error!" + Util.getErrString(e));
return ApiResult.error("update message status error");
}
}
}

View File

@ -0,0 +1,64 @@
package com.api.youhong.ai.jitu.hrmlogintip.mapper;
import aiyh.utils.annotation.recordset.*;
/**
* <h1></h1>
*
* <p>create: 2023/2/27 10:53</p>
*
* @author youHong.ai
*/
@SqlMapper
public interface HrmLoinTipMapper {
/**
* <h2>id</h2>
*
* @param account loginid
* @return id
*/
@Select("select id from hrmresource where loginid = #{account}")
Integer getUserIdByAccount(String account);
/**
* <h2></h2>
*
* @param showStatusField
* @param userId id
* @return
*/
@Select("select $t{showStatusField} from cus_fielddata where scope = 'HrmCustomFieldByInfoType'\n" +
" and scopeid = -1 and id = #{userId}")
Integer getMessageStatus(@ParamMapper("showStatusField") String showStatusField,
@ParamMapper("userId") Integer userId);
/**
* <h2></h2>
*
* @param showStatusField
* @param userId id
* @return
*/
@Update("update cus_fielddata set $t{showStatusField} = 1 where scope = 'HrmCustomFieldByInfoType'\n" +
" and scopeid = -1 and id = #{userId} ")
boolean updateStatus(@ParamMapper("showStatusField") String showStatusField,
@ParamMapper("userId") Integer userId);
/**
* <h2></h2>
*
* @param showStatusField
* @param userId id
* @return
*/
@Insert("insert into cus_fielddata (scope, scopeid, id, $t{showStatusField})\n" +
"values ('HrmCustomFieldByInfoType',-1,#{userId},0)")
boolean insertStatus(@ParamMapper("showStatusField") String showStatusField,
@ParamMapper("userId") Integer userId);
@Select("select SEQORDER from cus_fielddata where scope = 'HrmCustomFieldByInfoType'\n" +
" and scopeid = -1 and id = #{userId}")
Integer getMessageStatusId(@ParamMapper("userId") Integer userId);
}

View File

@ -0,0 +1,61 @@
package com.api.youhong.ai.jitu.hrmlogintip.service;
import aiyh.utils.Util;
import aiyh.utils.tool.Assert;
import com.api.youhong.ai.jitu.hrmlogintip.mapper.HrmLoinTipMapper;
import weaver.hrm.User;
import java.util.Objects;
/**
* <h1></h1>
*
* <p>create: 2023/2/27 10:33</p>
*
* @author youHong.ai
*/
public class HrmLoinTipService {
private final HrmLoinTipMapper mapper = Util.getMapper(HrmLoinTipMapper.class);
/**
* <h2></h2>
*
* @param userAccount
* @return
*/
public String getMessage(String userAccount) {
Integer userId = mapper.getUserIdByAccount(userAccount);
String showStatusField = Util.getCusConfigValue("LOGIN_BEFORE_SHOW_MESSAGE_FIELD");
Assert.notEmpty(showStatusField, "can not query config by only mark [LOGIN_BEFORE_SHOW_MESSAGE_FIELD](登录前显示消息状态字段_人员卡片自定义字段基本信息字段) on table [uf_cus_dev_config]");
Integer showStatus = mapper.getMessageStatus(showStatusField, userId);
// 没有展示过
if (Objects.isNull(showStatus) || showStatus <= 0) {
String loginBeforeShowMessage = Util.getCusConfigValue("LOGIN_BEFORE_SHOW_MESSAGE");
Assert.notEmpty(loginBeforeShowMessage, "can not query config by only mark [LOGIN_BEFORE_SHOW_MESSAGE](登录前显示消息) on table [uf_cus_dev_config]");
return loginBeforeShowMessage;
}
return null;
}
/**
* <h2></h2>
*
* @param user
* @param userAccount
* @return
*/
public boolean updateMessageStatus(User user, String userAccount) {
Integer userId = null;
if (Objects.isNull(user)) {
userId = mapper.getUserIdByAccount(userAccount);
}
String showStatusField = Util.getCusConfigValue("LOGIN_BEFORE_SHOW_MESSAGE_FIELD");
Assert.notEmpty(showStatusField, "can not query config by only mark [LOGIN_BEFORE_SHOW_MESSAGE_FIELD](登录前显示消息状态字段_人员卡片自定义字段基本信息字段) on table [uf_cus_dev_config]");
Integer id = mapper.getMessageStatusId(userId);
if (!Objects.isNull(id)) {
return mapper.updateStatus(showStatusField, userId);
}
return mapper.insertStatus(showStatusField, userId);
}
}

View File

@ -24,268 +24,268 @@ import java.util.stream.Collectors;
*/
public class SapConfigService {
private final SapConfigMapper mapper = Util.getMapper(SapConfigMapper.class);
private final Logger log = Util.getLogger();
public SapConfigService() {
}
/**
* <h2>getVoucherData </h2>
* <i>2023/2/2 13:29</i>
* ************************************************************
*
* @param onlyMark
* @param requestId id
* @param billTable
* @return Map<String, Object>
* @author youHong.ai ******************************************
*/
public SapVoucher getVoucherData(String onlyMark,
String requestId,
String billTable) {
SapConfigMain sapConfigMain = mapper.selectSapConfigByOnlyMark(onlyMark);
Assert.notNull(sapConfigMain, "can not query sap config main data by onlyMark : [{}]", onlyMark);
/* ******************* 查询凭证配置明细 ******************* */
List<SapConfigDetail> sapConfigVoucherHead = mapper.selectSapConfigDetail_1ByMainId(sapConfigMain.getId());
Assert.notEmpty(sapConfigVoucherHead, "sap voucher head config can not be null!");
List<SapConfigDetail> sapConfigVoucherDetails = mapper.selectSapConfigDetail_2ByMainId(sapConfigMain.getId());
Assert.notEmpty(sapConfigVoucherDetails, "sap voucher detail config can not be null!");
sapConfigMain.setVoucherHead(sapConfigVoucherHead);
sapConfigMain.setVoucherDetails(sapConfigVoucherDetails);
// 如果凭证数据来源于主表
if (sapConfigMain.getDocumentTableType() == 0) {
return parseByMainTable(requestId, billTable, sapConfigMain);
}
// 来源于明细表
return parseByDetailTable(requestId, billTable, sapConfigMain);
}
/**
* <h2>getReceiptPaymentData </h2>
* <i>2023/2/3 15:55</i>
* ************************************************************
*
* @param onlyMark
* @param requestId id
* @param billTable
* @return SapVoucher sap
* @author youHong.ai ******************************************
*/
public SapVoucher getReceiptPaymentData(String onlyMark, String requestId, String billTable) {
SapConfigMain sapConfigMain = mapper.selectSapConfigByOnlyMark(onlyMark);
Assert.notNull(sapConfigMain, "can not query sap payment config main data by onlyMark : [{}]", onlyMark);
/* ******************* 查询凭证配置明细 ******************* */
List<SapConfigDetail> sapConfigVoucherHead = mapper.selectSapConfigDetail_1ByMainId(sapConfigMain.getId());
Assert.notEmpty(sapConfigVoucherHead, "sap voucher payment head config can not be null!");
sapConfigMain.setVoucherHead(sapConfigVoucherHead);
// 如果凭证数据来源于主表
if (sapConfigMain.getDocumentTableType() == 0) {
return parsePaymentByMainTable(requestId, billTable, sapConfigMain);
}
// 来源于明细表
return parseByPaymentDetailTable(requestId, billTable, sapConfigMain);
}
private SapVoucher parseByPaymentDetailTable(String requestId, String billTable, SapConfigMain sapConfigMain) {
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId);
List<Map<String, Object>> workflowDetailData = mapper.selectWorkflowDataByMainId(Util.null2String(workflowMainData.get("id")),
sapConfigMain.getDocumentDetailTableName());
Assert.notNull(workflowDetailData, "payment: query workflow detail data fail, query request id is {}, mainId is {}",
requestId, workflowMainData.get("id"));
Map<String, Object> workflowData = new HashMap<>();
workflowData.put("main", workflowMainData);
workflowData.put("dt", workflowDetailData);
List<List<VoucherItem>> sapVoucherHead = parsePaymentVoucherHead(workflowData, sapConfigMain.getVoucherHead(), workflowDetailData);
return Builder.builder(SapVoucher::new)
.with(SapVoucher::setVoucherDetail, sapVoucherHead)
.build();
}
private List<List<VoucherItem>> parsePaymentVoucherHead(Map<String, Object> workflowData, List<SapConfigDetail> voucherHead,
List<Map<String, Object>> workflowDetailData) {
List<List<VoucherItem>> result = new ArrayList<>();
for (Map<String, Object> workflowDetailDatum : workflowDetailData) {
Map<String, Object> workflowDataTemp = new HashMap<>(workflowData);
workflowDataTemp.put("dt", workflowDetailDatum);
List<VoucherItem> voucherListRow = getVoucherItems(workflowDataTemp, voucherHead);
result.add(voucherListRow);
}
return result;
}
private SapVoucher parsePaymentByMainTable(String requestId, String billTable, SapConfigMain sapConfigMain) {
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId);
Map<String, Object> workflowData = new HashMap<>();
workflowData.put("main", workflowMainData);
List<VoucherItem> voucherListRow = getVoucherItems(workflowData, sapConfigMain.getVoucherHead());
return Builder.builder(SapVoucher::new)
.with(SapVoucher::setVoucherDetail, Collections.singletonList(voucherListRow))
.build();
}
/**
* <h2>parseByMainTable </h2>
* <i>2023/2/2 14:48</i>
* ************************************************************
*
* @param requestId id
* @param billTable
* @param sapConfigMain sap
* @return Map<String, Object>
* @author youHong.ai *****************************************
*/
private SapVoucher parseByMainTable(String requestId,
String billTable, SapConfigMain sapConfigMain) {
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId);
Map<String, Object> workflowData = new HashMap<>();
workflowData.put("main", workflowMainData);
List<VoucherItem> sapVoucherHead = parseVoucherHead(workflowData, sapConfigMain.getVoucherHead());
List<List<VoucherItem>> sapVoucherDetails = parseVoucherDetailByMainTable(workflowData, sapConfigMain.getVoucherDetails());
return Builder.builder(SapVoucher::new)
.with(SapVoucher::setVoucherHead, sapVoucherHead)
.with(SapVoucher::setVoucherDetail, sapVoucherDetails)
.build();
}
/**
* <h2>parseVoucherHead </h2>
* <i>2023/2/2 16:01</i>
* ************************************************************
*
* @param workflowData
* @param headConfigList
* @return List<VoucherItem>
* @author youHong.ai ******************************************
*/
private List<VoucherItem> parseVoucherHead(Map<String, Object> workflowData, List<SapConfigDetail> headConfigList) {
//Map<String, Object> result = new HashMap<>();
return getVoucherItems(workflowData, headConfigList);
}
/**
* <h2>parseVoucherDetailByMainTable </h2>
* <i>2023/2/2 16:50</i>
* ************************************************************
*
* @param workflowData
* @param detailConfigList
* @return List<Map < String, Object>>
* @author youHong.ai ******************************************
*/
private List<List<VoucherItem>> parseVoucherDetailByMainTable(Map<String, Object> workflowData,
List<SapConfigDetail> detailConfigList) {
List<List<VoucherItem>> result = new ArrayList<>();
Map<Integer, List<SapConfigDetail>> collect = detailConfigList.stream()
.collect(Collectors.groupingBy(SapConfigDetail::getVoucherType));
// 借方
List<SapConfigDetail> debit = collect.get(0);
//贷方
List<SapConfigDetail> credit = collect.get(1);
Assert.notEmpty(debit, "debit config not be null!");
Assert.notEmpty(credit, "credit config not be bull!");
List<VoucherItem> debtorList = getVoucherItems(workflowData, debit);
result.add(debtorList);
List<VoucherItem> creditorList = getVoucherItems(workflowData, credit);
result.add(creditorList);
return result;
}
@NotNull
private List<VoucherItem> getVoucherItems(Map<String, Object> workflowData, List<SapConfigDetail> debit) {
List<VoucherItem> debtorList = new ArrayList<>();
for (SapConfigDetail sapConfigDetail : debit) {
//debtorMap.put(sapConfigDetail.getVoucherField(), getValue(sapConfigDetail, workflowData));
VoucherItem voucherItem = Builder.builder(VoucherItem::new)
.with(VoucherItem::setId, sapConfigDetail.getId())
.with(VoucherItem::setName, sapConfigDetail.getVoucherField())
.with(VoucherItem::setValue, getValue(sapConfigDetail, workflowData))
.build();
debtorList.add(voucherItem);
}
return debtorList;
}
/**
* <h2>getValue </h2>
* <i>2023/2/2 16:00</i>
* ************************************************************
*
* @param sapConfigDetail
* @param workflowData
* @return Object
* @author youHong.ai ******************************************
*/
private Object getValue(SapConfigDetail sapConfigDetail, Map<String, Object> workflowData) {
return ValueRuleMethod.VALUE_RULE_FUNCTION.get(sapConfigDetail.getValueRule())
.apply(sapConfigDetail, workflowData);
}
/**
* <h2>parseByMainTable </h2>
* <i>2023/2/2 14:48</i>
* ************************************************************
*
* @param requestId id
* @param billTable
* @param sapConfigMain sap
* @return Map<String, Object>
* @author youHong.ai ******************************************
*/
private SapVoucher parseByDetailTable(String requestId,
String billTable, SapConfigMain sapConfigMain) {
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId);
List<Map<String, Object>> workflowDetailData = mapper.selectWorkflowDataByMainId(Util.null2String(workflowMainData.get("id")),
sapConfigMain.getDocumentDetailTableName());
Assert.notNull(workflowDetailData, "query workflow detail data fail, query request id is {}, mainId is {}",
requestId, workflowMainData.get("id"));
Map<String, Object> workflowData = new HashMap<>();
workflowData.put("main", workflowMainData);
workflowData.put("dt", workflowDetailData);
List<VoucherItem> sapVoucherHead = parseVoucherHead(workflowData, sapConfigMain.getVoucherHead());
List<List<VoucherItem>> sapVoucherDetails = parseVoucherDetail(workflowData, sapConfigMain.getVoucherDetails(), workflowDetailData);
return Builder.builder(SapVoucher::new)
.with(SapVoucher::setVoucherHead, sapVoucherHead)
.with(SapVoucher::setVoucherDetail, sapVoucherDetails)
.build();
}
/**
* <h2>parseVoucherDetailByMainTable </h2>
* <i>2023/2/2 16:50</i>
* ************************************************************
*
* @param workflowData
* @param detailConfigList
* @param workflowDetailData
* @return List<Map < String, Object>>
* @author youHong.ai ******************************************
*/
private List<List<VoucherItem>> parseVoucherDetail(Map<String, Object> workflowData,
List<SapConfigDetail> detailConfigList,
List<Map<String, Object>> workflowDetailData) {
List<List<VoucherItem>> result = new ArrayList<>();
for (Map<String, Object> workflowDetailDatum : workflowDetailData) {
Map<String, Object> workflowDataTemp = new HashMap<>(workflowData);
workflowDataTemp.put("dt", workflowDetailDatum);
List<List<VoucherItem>> voucherListRow = parseVoucherDetailByMainTable(workflowDataTemp, detailConfigList);
result.addAll(voucherListRow);
}
return result;
}
private final SapConfigMapper mapper = Util.getMapper(SapConfigMapper.class);
private final Logger log = Util.getLogger();
public SapConfigService() {
}
/**
* <h2>getVoucherData </h2>
* <i>2023/2/2 13:29</i>
* ************************************************************
*
* @param onlyMark
* @param requestId id
* @param billTable
* @return Map<String, Object>
* @author youHong.ai ******************************************
*/
public SapVoucher getVoucherData(String onlyMark,
String requestId,
String billTable) {
SapConfigMain sapConfigMain = mapper.selectSapConfigByOnlyMark(onlyMark);
Assert.notNull(sapConfigMain, "can not query sap config main data by onlyMark : [{}]", onlyMark);
/* ******************* 查询凭证配置明细 ******************* */
List<SapConfigDetail> sapConfigVoucherHead = mapper.selectSapConfigDetail_1ByMainId(sapConfigMain.getId());
Assert.notEmpty(sapConfigVoucherHead, "sap voucher head config can not be null!");
List<SapConfigDetail> sapConfigVoucherDetails = mapper.selectSapConfigDetail_2ByMainId(sapConfigMain.getId());
Assert.notEmpty(sapConfigVoucherDetails, "sap voucher detail config can not be null!");
sapConfigMain.setVoucherHead(sapConfigVoucherHead);
sapConfigMain.setVoucherDetails(sapConfigVoucherDetails);
// 如果凭证数据来源于主表
if (sapConfigMain.getDocumentTableType() == 0) {
return parseByMainTable(requestId, billTable, sapConfigMain);
}
// 来源于明细表
return parseByDetailTable(requestId, billTable, sapConfigMain);
}
/**
* <h2>getReceiptPaymentData </h2>
* <i>2023/2/3 15:55</i>
* ************************************************************
*
* @param onlyMark
* @param requestId id
* @param billTable
* @return SapVoucher sap
* @author youHong.ai ******************************************
*/
public SapVoucher getReceiptPaymentData(String onlyMark, String requestId, String billTable) {
SapConfigMain sapConfigMain = mapper.selectSapConfigByOnlyMark(onlyMark);
Assert.notNull(sapConfigMain, "can not query sap payment config main data by onlyMark : [{}]", onlyMark);
/* ******************* 查询凭证配置明细 ******************* */
List<SapConfigDetail> sapConfigVoucherHead = mapper.selectSapConfigDetail_1ByMainId(sapConfigMain.getId());
Assert.notEmpty(sapConfigVoucherHead, "sap voucher payment head config can not be null!");
sapConfigMain.setVoucherHead(sapConfigVoucherHead);
// 如果凭证数据来源于主表
if (sapConfigMain.getDocumentTableType() == 0) {
return parsePaymentByMainTable(requestId, billTable, sapConfigMain);
}
// 来源于明细表
return parseByPaymentDetailTable(requestId, billTable, sapConfigMain);
}
private SapVoucher parseByPaymentDetailTable(String requestId, String billTable, SapConfigMain sapConfigMain) {
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId);
List<Map<String, Object>> workflowDetailData = mapper.selectWorkflowDataByMainId(Util.null2String(workflowMainData.get("id")),
sapConfigMain.getDocumentDetailTableName());
Assert.notNull(workflowDetailData, "payment: query workflow detail data fail, query request id is {}, mainId is {}",
requestId, workflowMainData.get("id"));
Map<String, Object> workflowData = new HashMap<>();
workflowData.put("main", workflowMainData);
workflowData.put("dt", workflowDetailData);
List<List<VoucherItem>> sapVoucherHead = parsePaymentVoucherHead(workflowData, sapConfigMain.getVoucherHead(), workflowDetailData);
return Builder.builder(SapVoucher::new)
.with(SapVoucher::setVoucherDetail, sapVoucherHead)
.build();
}
private List<List<VoucherItem>> parsePaymentVoucherHead(Map<String, Object> workflowData, List<SapConfigDetail> voucherHead,
List<Map<String, Object>> workflowDetailData) {
List<List<VoucherItem>> result = new ArrayList<>();
for (Map<String, Object> workflowDetailDatum : workflowDetailData) {
Map<String, Object> workflowDataTemp = new HashMap<>(workflowData);
workflowDataTemp.put("dt", workflowDetailDatum);
List<VoucherItem> voucherListRow = getVoucherItems(workflowDataTemp, voucherHead);
result.add(voucherListRow);
}
return result;
}
private SapVoucher parsePaymentByMainTable(String requestId, String billTable, SapConfigMain sapConfigMain) {
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId);
Map<String, Object> workflowData = new HashMap<>();
workflowData.put("main", workflowMainData);
List<VoucherItem> voucherListRow = getVoucherItems(workflowData, sapConfigMain.getVoucherHead());
return Builder.builder(SapVoucher::new)
.with(SapVoucher::setVoucherDetail, Collections.singletonList(voucherListRow))
.build();
}
/**
* <h2>parseByMainTable </h2>
* <i>2023/2/2 14:48</i>
* ************************************************************
*
* @param requestId id
* @param billTable
* @param sapConfigMain sap
* @return Map<String, Object>
* @author youHong.ai *****************************************
*/
private SapVoucher parseByMainTable(String requestId,
String billTable, SapConfigMain sapConfigMain) {
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId);
Map<String, Object> workflowData = new HashMap<>();
workflowData.put("main", workflowMainData);
List<VoucherItem> sapVoucherHead = parseVoucherHead(workflowData, sapConfigMain.getVoucherHead());
List<List<VoucherItem>> sapVoucherDetails = parseVoucherDetailByMainTable(workflowData, sapConfigMain.getVoucherDetails());
return Builder.builder(SapVoucher::new)
.with(SapVoucher::setVoucherHead, sapVoucherHead)
.with(SapVoucher::setVoucherDetail, sapVoucherDetails)
.build();
}
/**
* <h2>parseVoucherHead </h2>
* <i>2023/2/2 16:01</i>
* ************************************************************
*
* @param workflowData
* @param headConfigList
* @return List<VoucherItem>
* @author youHong.ai ******************************************
*/
private List<VoucherItem> parseVoucherHead(Map<String, Object> workflowData, List<SapConfigDetail> headConfigList) {
// Map<String, Object> result = new HashMap<>();
return getVoucherItems(workflowData, headConfigList);
}
/**
* <h2>parseVoucherDetailByMainTable </h2>
* <i>2023/2/2 16:50</i>
* ************************************************************
*
* @param workflowData
* @param detailConfigList
* @return List<Map < String, Object>>
* @author youHong.ai ******************************************
*/
private List<List<VoucherItem>> parseVoucherDetailByMainTable(Map<String, Object> workflowData,
List<SapConfigDetail> detailConfigList) {
List<List<VoucherItem>> result = new ArrayList<>();
Map<Integer, List<SapConfigDetail>> collect = detailConfigList.stream()
.collect(Collectors.groupingBy(SapConfigDetail::getVoucherType));
// 借方
List<SapConfigDetail> debit = collect.get(0);
// 贷方
List<SapConfigDetail> credit = collect.get(1);
Assert.notEmpty(debit, "debit config not be null!");
Assert.notEmpty(credit, "credit config not be bull!");
List<VoucherItem> debtorList = getVoucherItems(workflowData, debit);
result.add(debtorList);
List<VoucherItem> creditorList = getVoucherItems(workflowData, credit);
result.add(creditorList);
return result;
}
@NotNull
private List<VoucherItem> getVoucherItems(Map<String, Object> workflowData, List<SapConfigDetail> debit) {
List<VoucherItem> debtorList = new ArrayList<>();
for (SapConfigDetail sapConfigDetail : debit) {
// debtorMap.put(sapConfigDetail.getVoucherField(), getValue(sapConfigDetail, workflowData));
VoucherItem voucherItem = Builder.builder(VoucherItem::new)
.with(VoucherItem::setId, sapConfigDetail.getId())
.with(VoucherItem::setName, sapConfigDetail.getVoucherField())
.with(VoucherItem::setValue, getValue(sapConfigDetail, workflowData))
.build();
debtorList.add(voucherItem);
}
return debtorList;
}
/**
* <h2>getValue </h2>
* <i>2023/2/2 16:00</i>
* ************************************************************
*
* @param sapConfigDetail
* @param workflowData
* @return Object
* @author youHong.ai ******************************************
*/
private Object getValue(SapConfigDetail sapConfigDetail, Map<String, Object> workflowData) {
return ValueRuleMethod.VALUE_RULE_FUNCTION.get(sapConfigDetail.getValueRule())
.apply(sapConfigDetail, workflowData);
}
/**
* <h2>parseByMainTable </h2>
* <i>2023/2/2 14:48</i>
* ************************************************************
*
* @param requestId id
* @param billTable
* @param sapConfigMain sap
* @return Map<String, Object>
* @author youHong.ai ******************************************
*/
private SapVoucher parseByDetailTable(String requestId,
String billTable, SapConfigMain sapConfigMain) {
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId);
List<Map<String, Object>> workflowDetailData = mapper.selectWorkflowDataByMainId(Util.null2String(workflowMainData.get("id")),
sapConfigMain.getDocumentDetailTableName());
Assert.notNull(workflowDetailData, "query workflow detail data fail, query request id is {}, mainId is {}",
requestId, workflowMainData.get("id"));
Map<String, Object> workflowData = new HashMap<>();
workflowData.put("main", workflowMainData);
workflowData.put("dt", workflowDetailData);
List<VoucherItem> sapVoucherHead = parseVoucherHead(workflowData, sapConfigMain.getVoucherHead());
List<List<VoucherItem>> sapVoucherDetails = parseVoucherDetail(workflowData, sapConfigMain.getVoucherDetails(), workflowDetailData);
return Builder.builder(SapVoucher::new)
.with(SapVoucher::setVoucherHead, sapVoucherHead)
.with(SapVoucher::setVoucherDetail, sapVoucherDetails)
.build();
}
/**
* <h2>parseVoucherDetailByMainTable </h2>
* <i>2023/2/2 16:50</i>
* ************************************************************
*
* @param workflowData
* @param detailConfigList
* @param workflowDetailData
* @return List<Map < String, Object>>
* @author youHong.ai ******************************************
*/
private List<List<VoucherItem>> parseVoucherDetail(Map<String, Object> workflowData,
List<SapConfigDetail> detailConfigList,
List<Map<String, Object>> workflowDetailData) {
List<List<VoucherItem>> result = new ArrayList<>();
for (Map<String, Object> workflowDetailDatum : workflowDetailData) {
Map<String, Object> workflowDataTemp = new HashMap<>(workflowData);
workflowDataTemp.put("dt", workflowDetailDatum);
List<List<VoucherItem>> voucherListRow = parseVoucherDetailByMainTable(workflowDataTemp, detailConfigList);
result.addAll(voucherListRow);
}
return result;
}
}

View File

@ -2,6 +2,8 @@ package weaver.youhong.ai.haripijiu.action.sapdocking.service;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSON;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import weaver.general.GCONST;
import weaver.youhong.ai.haripijiu.action.sapdocking.config.dto.SapVoucher;
@ -32,6 +34,9 @@ public class VoucherPayableService {
private final SapConfigService configService = new SapConfigService();
private final Logger logger = Util.getLogger();
@NotNull
private static String getFilePath() {
String sysFilePath = GCONST.getSysFilePath();
@ -69,6 +74,7 @@ public class VoucherPayableService {
public String sendSapVoucher(String onlyMark, String requestId, String billTable) {
SapVoucher voucherData = configService.getVoucherData(onlyMark, requestId, billTable);
logger.info("查询的凭证配置数据: " + JSON.toJSONString(voucherData));
/* ******************* 整理数据 ******************* */
StringBuilder voucherHeadBuilder = new StringBuilder();
List<VoucherItem> voucherHead = voucherData.getVoucherHead();
@ -77,6 +83,7 @@ public class VoucherPayableService {
.append("\t");
}
String voucherHeadStr = voucherHeadBuilder.substring(0, voucherHeadBuilder.lastIndexOf("\t")) + "\r\n";
logger.info("凭证头:" + voucherHeadStr);
StringBuilder voucherDetailBuilder = new StringBuilder();
List<List<VoucherItem>> voucherDetail = voucherData.getVoucherDetail();
for (List<VoucherItem> voucherItems : voucherDetail) {
@ -84,6 +91,7 @@ public class VoucherPayableService {
.append("\r\n");
}
String voucherDetailStr = voucherDetailBuilder.substring(0, voucherDetailBuilder.lastIndexOf("\r\n"));
logger.info("凭证数据:" + voucherHeadStr);
String filePath = getFilePath();
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
@ -102,6 +110,7 @@ public class VoucherPayableService {
public String sendReceiptVoucher(String onlyMark, String requestId, String billTable) {
SapVoucher voucherData = configService.getReceiptPaymentData(onlyMark, requestId, billTable);
logger.info("查询的凭证配置数据: " + JSON.toJSONString(voucherData));
/* ******************* 整理数据 ******************* */
StringBuilder voucherHeadBuilder = new StringBuilder();
List<List<VoucherItem>> voucherDetail = voucherData.getVoucherDetail();
@ -128,13 +137,15 @@ public class VoucherPayableService {
.substring(0, voucherHeadBuilder.lastIndexOf("\t")) + "");
}
}
String voucherHaredStr = voucherHeadBuilder.toString();
logger.info("凭证数据:" + voucherHaredStr);
String filePath = getFilePath();
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
Files.newOutputStream(Paths.get(filePath))
));
writer.write(voucherHeadBuilder.toString());
writer.write(voucherHaredStr);
writer.flush();
writer.close();
} catch (IOException e) {
@ -147,6 +158,7 @@ public class VoucherPayableService {
public List<String> sendPaymentVoucher(String onlyMark, String requestId, String billTable) {
SapVoucher voucherData = configService.getReceiptPaymentData(onlyMark, requestId, billTable);
logger.info("配置数据:" + JSON.toJSONString(voucherData));
List<String> filePathList = new ArrayList<>();
/* ******************* 整理数据 ******************* */
StringBuilder voucherHeadBuilder = new StringBuilder();
@ -165,13 +177,14 @@ public class VoucherPayableService {
}
voucherHeadBuilder = new StringBuilder(voucherHeadBuilder
.substring(0, voucherHeadBuilder.lastIndexOf("\t")) + "");
String voucherHeadStr = voucherHeadBuilder.toString();
logger.info("凭证数据:" + voucherHeadStr);
String filePath = getFilePath();
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
Files.newOutputStream(Paths.get(filePath))
));
writer.write(voucherHeadBuilder.toString());
writer.write(voucherHeadStr);
writer.flush();
writer.close();
} catch (IOException e) {