From 4a54e7f5c71462b99bc9443310eb80bd5340181b Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Mon, 27 Feb 2023 11:55:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=81=E5=85=94=E7=99=BB=E5=BD=95=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=9F=A5=E8=AF=A2=E3=80=81mapper=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../youhong.ai/pcn/workflow_code_block.js | 33 +- .../utils/recordset/DoubleTypeHandler.java | 60 +- .../utils/recordset/FloatTypeHandler.java | 60 +- .../utils/recordset/IntegerTypeHandler.java | 82 +-- .../controller/HrmLoinTipController.java | 64 +++ .../hrmlogintip/mapper/HrmLoinTipMapper.java | 64 +++ .../service/HrmLoinTipService.java | 61 ++ .../config/service/SapConfigService.java | 528 +++++++++--------- .../service/VoucherPayableService.java | 19 +- 9 files changed, 620 insertions(+), 351 deletions(-) create mode 100644 src/main/java/com/api/youhong/ai/jitu/hrmlogintip/controller/HrmLoinTipController.java create mode 100644 src/main/java/com/api/youhong/ai/jitu/hrmlogintip/mapper/HrmLoinTipMapper.java create mode 100644 src/main/java/com/api/youhong/ai/jitu/hrmlogintip/service/HrmLoinTipService.java diff --git a/javascript/youhong.ai/pcn/workflow_code_block.js b/javascript/youhong.ai/pcn/workflow_code_block.js index a6bb3d9..7efc27e 100644 --- a/javascript/youhong.ai/pcn/workflow_code_block.js +++ b/javascript/youhong.ai/pcn/workflow_code_block.js @@ -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") + })() + + +/* ******************* 提交外出流程 ******************* */ \ No newline at end of file diff --git a/src/main/java/aiyh/utils/recordset/DoubleTypeHandler.java b/src/main/java/aiyh/utils/recordset/DoubleTypeHandler.java index 6d9d9d0..ecc9e36 100644 --- a/src/main/java/aiyh/utils/recordset/DoubleTypeHandler.java +++ b/src/main/java/aiyh/utils/recordset/DoubleTypeHandler.java @@ -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); + } + } diff --git a/src/main/java/aiyh/utils/recordset/FloatTypeHandler.java b/src/main/java/aiyh/utils/recordset/FloatTypeHandler.java index 3dbe30b..7f5bde0 100644 --- a/src/main/java/aiyh/utils/recordset/FloatTypeHandler.java +++ b/src/main/java/aiyh/utils/recordset/FloatTypeHandler.java @@ -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); + } + } diff --git a/src/main/java/aiyh/utils/recordset/IntegerTypeHandler.java b/src/main/java/aiyh/utils/recordset/IntegerTypeHandler.java index 86d6c58..8d4f65c 100644 --- a/src/main/java/aiyh/utils/recordset/IntegerTypeHandler.java +++ b/src/main/java/aiyh/utils/recordset/IntegerTypeHandler.java @@ -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); + } } diff --git a/src/main/java/com/api/youhong/ai/jitu/hrmlogintip/controller/HrmLoinTipController.java b/src/main/java/com/api/youhong/ai/jitu/hrmlogintip/controller/HrmLoinTipController.java new file mode 100644 index 0000000..4d30fbf --- /dev/null +++ b/src/main/java/com/api/youhong/ai/jitu/hrmlogintip/controller/HrmLoinTipController.java @@ -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; + +/** + *

人员第一次登录时候显示提示信息

+ * + *

create: 2023/2/27 10:29

+ * + * @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"); + } + } + + +} diff --git a/src/main/java/com/api/youhong/ai/jitu/hrmlogintip/mapper/HrmLoinTipMapper.java b/src/main/java/com/api/youhong/ai/jitu/hrmlogintip/mapper/HrmLoinTipMapper.java new file mode 100644 index 0000000..836e5d3 --- /dev/null +++ b/src/main/java/com/api/youhong/ai/jitu/hrmlogintip/mapper/HrmLoinTipMapper.java @@ -0,0 +1,64 @@ +package com.api.youhong.ai.jitu.hrmlogintip.mapper; + +import aiyh.utils.annotation.recordset.*; + +/** + *

+ * + *

create: 2023/2/27 10:53

+ * + * @author youHong.ai + */ +@SqlMapper +public interface HrmLoinTipMapper { + + + /** + *

根据账号查询下用户id

+ * + * @param account 用户loginid + * @return 用户id + */ + @Select("select id from hrmresource where loginid = #{account}") + Integer getUserIdByAccount(String account); + + /** + *

查询消息显示状态

+ * + * @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); + + /** + *

更新消息状态

+ * + * @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); + + /** + *

插入消息状态信息

+ * + * @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); +} diff --git a/src/main/java/com/api/youhong/ai/jitu/hrmlogintip/service/HrmLoinTipService.java b/src/main/java/com/api/youhong/ai/jitu/hrmlogintip/service/HrmLoinTipService.java new file mode 100644 index 0000000..7c7dd9f --- /dev/null +++ b/src/main/java/com/api/youhong/ai/jitu/hrmlogintip/service/HrmLoinTipService.java @@ -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; + +/** + *

+ * + *

create: 2023/2/27 10:33

+ * + * @author youHong.ai + */ +public class HrmLoinTipService { + + private final HrmLoinTipMapper mapper = Util.getMapper(HrmLoinTipMapper.class); + + /** + *

获取显示消息

+ * + * @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; + } + + /** + *

更新消息状态

+ * + * @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); + } +} diff --git a/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/config/service/SapConfigService.java b/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/config/service/SapConfigService.java index 286aa9e..4429ea8 100644 --- a/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/config/service/SapConfigService.java +++ b/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/config/service/SapConfigService.java @@ -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() { - } - - - /** - *

getVoucherData 获取凭证配置信息

- * 2023/2/2 13:29 - * ************************************************************ - * - * @param onlyMark 唯一标识 - * @param requestId 流程请求id - * @param billTable 流程所在表 - * @return Map 凭证数据 - * @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 sapConfigVoucherHead = mapper.selectSapConfigDetail_1ByMainId(sapConfigMain.getId()); - Assert.notEmpty(sapConfigVoucherHead, "sap voucher head config can not be null!"); - List 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); - } - - /** - *

getReceiptPaymentData 获取收付款数据信息

- * 2023/2/3 15:55 - * ************************************************************ - * - * @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 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 workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable); - Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId); - List> 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 workflowData = new HashMap<>(); - workflowData.put("main", workflowMainData); - workflowData.put("dt", workflowDetailData); - List> sapVoucherHead = parsePaymentVoucherHead(workflowData, sapConfigMain.getVoucherHead(), workflowDetailData); - return Builder.builder(SapVoucher::new) - .with(SapVoucher::setVoucherDetail, sapVoucherHead) - .build(); - } - - private List> parsePaymentVoucherHead(Map workflowData, List voucherHead, - List> workflowDetailData) { - List> result = new ArrayList<>(); - for (Map workflowDetailDatum : workflowDetailData) { - Map workflowDataTemp = new HashMap<>(workflowData); - workflowDataTemp.put("dt", workflowDetailDatum); - List voucherListRow = getVoucherItems(workflowDataTemp, voucherHead); - result.add(voucherListRow); - } - return result; - } - - - private SapVoucher parsePaymentByMainTable(String requestId, String billTable, SapConfigMain sapConfigMain) { - Map workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable); - Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId); - Map workflowData = new HashMap<>(); - workflowData.put("main", workflowMainData); - List voucherListRow = getVoucherItems(workflowData, sapConfigMain.getVoucherHead()); - return Builder.builder(SapVoucher::new) - .with(SapVoucher::setVoucherDetail, Collections.singletonList(voucherListRow)) - .build(); - } - - - /** - *

parseByMainTable 凭证数据在主表处理方法

- * 2023/2/2 14:48 - * ************************************************************ - * - * @param requestId 请求id - * @param billTable 流程所在表 - * @param sapConfigMain sap配置数据 - * @return Map 凭证数据 - * @author youHong.ai ***************************************** - */ - private SapVoucher parseByMainTable(String requestId, - String billTable, SapConfigMain sapConfigMain) { - Map workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable); - Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId); - Map workflowData = new HashMap<>(); - workflowData.put("main", workflowMainData); - List sapVoucherHead = parseVoucherHead(workflowData, sapConfigMain.getVoucherHead()); - List> sapVoucherDetails = parseVoucherDetailByMainTable(workflowData, sapConfigMain.getVoucherDetails()); - return Builder.builder(SapVoucher::new) - .with(SapVoucher::setVoucherHead, sapVoucherHead) - .with(SapVoucher::setVoucherDetail, sapVoucherDetails) - .build(); - } - - /** - *

parseVoucherHead 解析凭证头配置数据

- * 2023/2/2 16:01 - * ************************************************************ - * - * @param workflowData 流程数据 - * @param headConfigList 凭证头配置数据 - * @return List 解析后数据 - * @author youHong.ai ****************************************** - */ - private List parseVoucherHead(Map workflowData, List headConfigList) { - //Map result = new HashMap<>(); - return getVoucherItems(workflowData, headConfigList); - } - - /** - *

parseVoucherDetailByMainTable 解析凭证明细单条数据

- * 2023/2/2 16:50 - * ************************************************************ - * - * @param workflowData 流程数据 - * @param detailConfigList 凭证明细配置数据 - * @return List> 凭证明细数据 - * @author youHong.ai ****************************************** - */ - private List> parseVoucherDetailByMainTable(Map workflowData, - List detailConfigList) { - List> result = new ArrayList<>(); - Map> collect = detailConfigList.stream() - .collect(Collectors.groupingBy(SapConfigDetail::getVoucherType)); - // 借方 - List debit = collect.get(0); - //贷方 - - List credit = collect.get(1); - - Assert.notEmpty(debit, "debit config not be null!"); - Assert.notEmpty(credit, "credit config not be bull!"); - - List debtorList = getVoucherItems(workflowData, debit); - result.add(debtorList); - List creditorList = getVoucherItems(workflowData, credit); - result.add(creditorList); - return result; - } - - @NotNull - private List getVoucherItems(Map workflowData, List debit) { - List 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; - } - - /** - *

getValue 更具取值规则获取凭证字段值

- * 2023/2/2 16:00 - * ************************************************************ - * - * @param sapConfigDetail 凭证配置数据明细条 - * @param workflowData 流程数据 - * @return Object - * @author youHong.ai ****************************************** - */ - private Object getValue(SapConfigDetail sapConfigDetail, Map workflowData) { - return ValueRuleMethod.VALUE_RULE_FUNCTION.get(sapConfigDetail.getValueRule()) - .apply(sapConfigDetail, workflowData); - } - - - /** - *

parseByMainTable 凭证数据在明细表处理方法

- * 2023/2/2 14:48 - * ************************************************************ - * - * @param requestId 请求id - * @param billTable 流程所在表 - * @param sapConfigMain sap配置数据 - * @return Map 凭证数据 - * @author youHong.ai ****************************************** - */ - private SapVoucher parseByDetailTable(String requestId, - String billTable, SapConfigMain sapConfigMain) { - Map workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable); - Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId); - List> 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 workflowData = new HashMap<>(); - workflowData.put("main", workflowMainData); - workflowData.put("dt", workflowDetailData); - List sapVoucherHead = parseVoucherHead(workflowData, sapConfigMain.getVoucherHead()); - List> sapVoucherDetails = parseVoucherDetail(workflowData, sapConfigMain.getVoucherDetails(), workflowDetailData); - return Builder.builder(SapVoucher::new) - .with(SapVoucher::setVoucherHead, sapVoucherHead) - .with(SapVoucher::setVoucherDetail, sapVoucherDetails) - .build(); - } - - - /** - *

parseVoucherDetailByMainTable 解析凭证明细数据

- * 2023/2/2 16:50 - * ************************************************************ - * - * @param workflowData 流程数据 - * @param detailConfigList 凭证明细配置数据 - * @param workflowDetailData 明细表数据 - * @return List> 凭证明细数据 - * @author youHong.ai ****************************************** - */ - private List> parseVoucherDetail(Map workflowData, - List detailConfigList, - List> workflowDetailData) { - List> result = new ArrayList<>(); - for (Map workflowDetailDatum : workflowDetailData) { - Map workflowDataTemp = new HashMap<>(workflowData); - workflowDataTemp.put("dt", workflowDetailDatum); - List> 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() { + } + + + /** + *

getVoucherData 获取凭证配置信息

+ * 2023/2/2 13:29 + * ************************************************************ + * + * @param onlyMark 唯一标识 + * @param requestId 流程请求id + * @param billTable 流程所在表 + * @return Map 凭证数据 + * @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 sapConfigVoucherHead = mapper.selectSapConfigDetail_1ByMainId(sapConfigMain.getId()); + Assert.notEmpty(sapConfigVoucherHead, "sap voucher head config can not be null!"); + List 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); + } + + /** + *

getReceiptPaymentData 获取收付款数据信息

+ * 2023/2/3 15:55 + * ************************************************************ + * + * @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 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 workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable); + Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId); + List> 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 workflowData = new HashMap<>(); + workflowData.put("main", workflowMainData); + workflowData.put("dt", workflowDetailData); + List> sapVoucherHead = parsePaymentVoucherHead(workflowData, sapConfigMain.getVoucherHead(), workflowDetailData); + return Builder.builder(SapVoucher::new) + .with(SapVoucher::setVoucherDetail, sapVoucherHead) + .build(); + } + + private List> parsePaymentVoucherHead(Map workflowData, List voucherHead, + List> workflowDetailData) { + List> result = new ArrayList<>(); + for (Map workflowDetailDatum : workflowDetailData) { + Map workflowDataTemp = new HashMap<>(workflowData); + workflowDataTemp.put("dt", workflowDetailDatum); + List voucherListRow = getVoucherItems(workflowDataTemp, voucherHead); + result.add(voucherListRow); + } + return result; + } + + + private SapVoucher parsePaymentByMainTable(String requestId, String billTable, SapConfigMain sapConfigMain) { + Map workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable); + Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId); + Map workflowData = new HashMap<>(); + workflowData.put("main", workflowMainData); + List voucherListRow = getVoucherItems(workflowData, sapConfigMain.getVoucherHead()); + return Builder.builder(SapVoucher::new) + .with(SapVoucher::setVoucherDetail, Collections.singletonList(voucherListRow)) + .build(); + } + + + /** + *

parseByMainTable 凭证数据在主表处理方法

+ * 2023/2/2 14:48 + * ************************************************************ + * + * @param requestId 请求id + * @param billTable 流程所在表 + * @param sapConfigMain sap配置数据 + * @return Map 凭证数据 + * @author youHong.ai ***************************************** + */ + private SapVoucher parseByMainTable(String requestId, + String billTable, SapConfigMain sapConfigMain) { + Map workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable); + Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId); + Map workflowData = new HashMap<>(); + workflowData.put("main", workflowMainData); + List sapVoucherHead = parseVoucherHead(workflowData, sapConfigMain.getVoucherHead()); + List> sapVoucherDetails = parseVoucherDetailByMainTable(workflowData, sapConfigMain.getVoucherDetails()); + return Builder.builder(SapVoucher::new) + .with(SapVoucher::setVoucherHead, sapVoucherHead) + .with(SapVoucher::setVoucherDetail, sapVoucherDetails) + .build(); + } + + /** + *

parseVoucherHead 解析凭证头配置数据

+ * 2023/2/2 16:01 + * ************************************************************ + * + * @param workflowData 流程数据 + * @param headConfigList 凭证头配置数据 + * @return List 解析后数据 + * @author youHong.ai ****************************************** + */ + private List parseVoucherHead(Map workflowData, List headConfigList) { + // Map result = new HashMap<>(); + return getVoucherItems(workflowData, headConfigList); + } + + /** + *

parseVoucherDetailByMainTable 解析凭证明细单条数据

+ * 2023/2/2 16:50 + * ************************************************************ + * + * @param workflowData 流程数据 + * @param detailConfigList 凭证明细配置数据 + * @return List> 凭证明细数据 + * @author youHong.ai ****************************************** + */ + private List> parseVoucherDetailByMainTable(Map workflowData, + List detailConfigList) { + List> result = new ArrayList<>(); + Map> collect = detailConfigList.stream() + .collect(Collectors.groupingBy(SapConfigDetail::getVoucherType)); + // 借方 + List debit = collect.get(0); + // 贷方 + + List credit = collect.get(1); + + Assert.notEmpty(debit, "debit config not be null!"); + Assert.notEmpty(credit, "credit config not be bull!"); + + List debtorList = getVoucherItems(workflowData, debit); + result.add(debtorList); + List creditorList = getVoucherItems(workflowData, credit); + result.add(creditorList); + return result; + } + + @NotNull + private List getVoucherItems(Map workflowData, List debit) { + List 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; + } + + /** + *

getValue 更具取值规则获取凭证字段值

+ * 2023/2/2 16:00 + * ************************************************************ + * + * @param sapConfigDetail 凭证配置数据明细条 + * @param workflowData 流程数据 + * @return Object + * @author youHong.ai ****************************************** + */ + private Object getValue(SapConfigDetail sapConfigDetail, Map workflowData) { + return ValueRuleMethod.VALUE_RULE_FUNCTION.get(sapConfigDetail.getValueRule()) + .apply(sapConfigDetail, workflowData); + } + + + /** + *

parseByMainTable 凭证数据在明细表处理方法

+ * 2023/2/2 14:48 + * ************************************************************ + * + * @param requestId 请求id + * @param billTable 流程所在表 + * @param sapConfigMain sap配置数据 + * @return Map 凭证数据 + * @author youHong.ai ****************************************** + */ + private SapVoucher parseByDetailTable(String requestId, + String billTable, SapConfigMain sapConfigMain) { + Map workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable); + Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId); + List> 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 workflowData = new HashMap<>(); + workflowData.put("main", workflowMainData); + workflowData.put("dt", workflowDetailData); + List sapVoucherHead = parseVoucherHead(workflowData, sapConfigMain.getVoucherHead()); + List> sapVoucherDetails = parseVoucherDetail(workflowData, sapConfigMain.getVoucherDetails(), workflowDetailData); + return Builder.builder(SapVoucher::new) + .with(SapVoucher::setVoucherHead, sapVoucherHead) + .with(SapVoucher::setVoucherDetail, sapVoucherDetails) + .build(); + } + + + /** + *

parseVoucherDetailByMainTable 解析凭证明细数据

+ * 2023/2/2 16:50 + * ************************************************************ + * + * @param workflowData 流程数据 + * @param detailConfigList 凭证明细配置数据 + * @param workflowDetailData 明细表数据 + * @return List> 凭证明细数据 + * @author youHong.ai ****************************************** + */ + private List> parseVoucherDetail(Map workflowData, + List detailConfigList, + List> workflowDetailData) { + List> result = new ArrayList<>(); + for (Map workflowDetailDatum : workflowDetailData) { + Map workflowDataTemp = new HashMap<>(workflowData); + workflowDataTemp.put("dt", workflowDetailDatum); + List> voucherListRow = parseVoucherDetailByMainTable(workflowDataTemp, detailConfigList); + result.addAll(voucherListRow); + } + return result; + + } + } diff --git a/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/service/VoucherPayableService.java b/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/service/VoucherPayableService.java index 7dfc1d4..61ad0bb 100644 --- a/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/service/VoucherPayableService.java +++ b/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/service/VoucherPayableService.java @@ -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 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> voucherDetail = voucherData.getVoucherDetail(); for (List 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> 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 sendPaymentVoucher(String onlyMark, String requestId, String billTable) { SapVoucher voucherData = configService.getReceiptPaymentData(onlyMark, requestId, billTable); + logger.info("配置数据:" + JSON.toJSONString(voucherData)); List 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) {