修改dealwithmapping获取字段数据bug

main
youHong.ai 2023-02-12 22:17:44 +08:00
parent dfc89e7d21
commit 9dacdd2751
12 changed files with 5455 additions and 5045 deletions

View File

@ -298,3 +298,24 @@ $(() => {
}) })
/* ******************* apa(employee)流程明细分数控制end ******************* */ /* ******************* apa(employee)流程明细分数控制end ******************* */
const workflowInsertValueConfig = [
{
table: '',
targetTable: '',
filedMapping: [{
source: '',
target: ''
}]
}, {
table: '',
targetTable: '',
filedMapping: []
}
]
/* ******************* 流程明细数据整合插入start ******************* */
/* ******************* 流程明细数据整合插入end ******************* */

View File

@ -2818,7 +2818,7 @@ public class Util extends weaver.general.Util {
int finalSeconds = seconds; int finalSeconds = seconds;
new Thread(() -> { new Thread(() -> {
try { try {
Thread.sleep(1000 * finalSeconds); Thread.sleep(1000L * finalSeconds);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
Util.getLogger().error("线程休眠失败", e); Util.getLogger().error("线程休眠失败", e);
@ -3345,7 +3345,6 @@ public class Util extends weaver.general.Util {
} }
try { try {
action = cronJobClass.newInstance(); action = cronJobClass.newInstance();
if (declaredFields.length > 0) {
for (Field declaredField : declaredFields) { for (Field declaredField : declaredFields) {
// 必填参数验证 // 必填参数验证
boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class); boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class);
@ -3397,7 +3396,6 @@ public class Util extends weaver.general.Util {
Method method = cronJobClass.getMethod(setMethodName, String.class); Method method = cronJobClass.getMethod(setMethodName, String.class);
method.invoke(action, value); method.invoke(action, value);
} }
}
action.execute(); action.execute();
} catch (Exception e) { } catch (Exception e) {
throw new CustomerException("计划任务执行异常!异常信息:\n" + Util.getErrString(e)); throw new CustomerException("计划任务执行异常!异常信息:\n" + Util.getErrString(e));
@ -3426,7 +3424,6 @@ public class Util extends weaver.general.Util {
} }
try { try {
action = actionClass.newInstance(); action = actionClass.newInstance();
if (declaredFields.length > 0) {
for (Field declaredField : declaredFields) { for (Field declaredField : declaredFields) {
// 必填参数验证 // 必填参数验证
boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class); boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class);
@ -3460,7 +3457,6 @@ public class Util extends weaver.general.Util {
Method method = actionClass.getMethod(setMethodName, String.class); Method method = actionClass.getMethod(setMethodName, String.class);
method.invoke(action, value); method.invoke(action, value);
} }
}
RequestService requestService = new RequestService(); RequestService requestService = new RequestService();
requestInfo = requestService.getRequest(requestId); requestInfo = requestService.getRequest(requestId);
if (null == requestInfo) { if (null == requestInfo) {

View File

@ -4,8 +4,13 @@ import aiyh.utils.ApiResult;
import aiyh.utils.Util; import aiyh.utils.Util;
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service.ApaLevelByScoreService; import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service.ApaLevelByScoreService;
import org.apache.log4j.Logger; 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.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
/** /**
@ -35,4 +40,19 @@ public class ApaLevelByScoreController {
return ApiResult.error("get level error " + e.getMessage()); return ApiResult.error("get level error " + e.getMessage());
} }
} }
@GET
@Path("/get-data-id")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String getApaLastDateId(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
try {
return ApiResult.success(service.getApaLastDateId(user));
} catch (Exception e) {
log.error("get apa workflow param(mode id) error ! \n" + Util.getErrString(e));
return ApiResult.error(e.getMessage());
}
}
} }

View File

@ -1,5 +1,6 @@
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper; package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select; import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper; import aiyh.utils.annotation.recordset.SqlMapper;
@ -25,4 +26,10 @@ public interface ApaLevelByScoreMapper {
*/ */
@Select("select level1 from uf_APAlevel where #{score} between zdf and zgf") @Select("select level1 from uf_APAlevel where #{score} between zdf and zgf")
Integer selectLevelByScore(Double score); Integer selectLevelByScore(Double score);
@Select("select id from $t{tableName} where $t{userField} = #{uId}")
Integer selectLevelByUserId(@ParamMapper("uId") int uid,
@ParamMapper("tableName") String tableName,
@ParamMapper("userField") String userField);
} }

View File

@ -2,7 +2,9 @@ package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service;
import aiyh.utils.Util; import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException; import aiyh.utils.excention.CustomerException;
import cn.hutool.core.lang.Assert;
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper.ApaLevelByScoreMapper; import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper.ApaLevelByScoreMapper;
import weaver.hrm.User;
/** /**
* <h1></h1> * <h1></h1>
@ -31,4 +33,12 @@ public class ApaLevelByScoreService {
} }
return level; return level;
} }
public Integer getApaLastDateId(User user) {
String apaLastIdTableName = Util.getCusConfigValue("APA_LAST_ID_TABLE_NAME");
String apaLastIdUserField = Util.getCusConfigValue("APA_LAST_ID_USER_FIELD");
Assert.notBlank(apaLastIdTableName, "can not get config [APA_LAST_ID_TABLE_NAME] from uf_cus_dev_config!");
Assert.notBlank(apaLastIdUserField, "can not get config [APA_LAST_ID_USER_FIELD] from uf_cus_dev_config!");
return mapper.selectLevelByUserId(user.getUID(), apaLastIdTableName, apaLastIdUserField);
}
} }

View File

@ -0,0 +1,57 @@
package com.api.youhong.ai.zhishichanquan.ssocaiwu.controller;
import aiyh.utils.Util;
import cn.hutool.core.lang.Assert;
import com.alibaba.fastjson.JSON;
import com.api.youhong.ai.zhishichanquan.ssocaiwu.util.AES;
import com.sun.jersey.api.view.Viewable;
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.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* <h1></h1>
*
* <p>create: 2023/2/8 17:10</p>
*
* @author youHong.ai
*/
@Path("/aiyh/sso/caiwu/")
public class SingleSignOnController {
private final Logger log = Util.getLogger();
@Path("/send-redirect")
@GET
public Viewable ssoSendRedirect(@Context HttpServletRequest request, @Context HttpServletResponse response) {
try {
String url = Util.getCusConfigValue("FinancialAffairsURL");
String key = Util.getCusConfigValue("FinancialAffairsKey");
String initVector = Util.getCusConfigValue("FinancialAffairsInitVector");
Assert.notBlank(url, "sendRedirect url is null, check config [FinancialAffairsURL] on uf_cus_dev_config table!");
Assert.notBlank(key, "sendRedirect AES encrypt key is null, check config [FinancialAffairsKey] on uf_cus_dev_config table!");
Assert.notBlank(initVector, "sendRedirect AES encrypt initVector is null, check config [FinancialAffairsInitVector] on uf_cus_dev_config table!");
User user = HrmUserVarify.getUser(request, response);
String userCodeMethod = Util.getCusConfigValueNullOrEmpty("FinancialAffairsUserCodeMethod", "getLoginid");
Method method = User.class.getMethod(userCodeMethod);
Object value = method.invoke(user);
Map<String, Object> param = new HashMap<>(8);
param.put("user", value);
param.put("ts", System.currentTimeMillis());
String encrypt = AES.encrypt(key, initVector, JSON.toJSONString(param));
response.sendRedirect(url + "?params=" + encrypt);
} catch (Exception e) {
log.error("单点登录路径处理失败!" + e.getMessage() + "\n" + Util.getErrString(e));
}
return null;
}
}

View File

@ -0,0 +1,43 @@
package com.api.youhong.ai.zhishichanquan.ssocaiwu.util;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
public class AES {
public static String encrypt(String key, String initVector, String value) {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
byte[] encrypted = cipher.doFinal(value.getBytes());
return Base64.getEncoder().encodeToString(encrypted);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static String decrypt(String key, String initVector, String encrypted) {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
byte[] original = cipher.doFinal(Base64.getDecoder().decode(encrypted));
return new String(original);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
}

View File

@ -625,11 +625,18 @@ public class DealWithMapping extends ToolUtil {
int detailId = -1; int detailId = -1;
if (fieldMassage != null) { if (fieldMassage != null) {
String fieldName = fieldMassage.getFieldName(); String fieldName = fieldMassage.getFieldName();
String fieldNameLower = fieldName.toLowerCase();
if ("1".equals(childSource)) { if ("1".equals(childSource)) {
tempValue = Util.null2String(detailMap.get(fieldName)); tempValue = Util.null2String(detailMap.get(fieldName));
if ("".equals(tempValue)) {
tempValue = Util.null2String(detailMap.get(fieldNameLower));
}
detailId = Util.getIntValue(Util.null2String(detailMap.get("id")), -1); detailId = Util.getIntValue(Util.null2String(detailMap.get("id")), -1);
} else { } else {
tempValue = Util.null2String(mainMap.get(fieldName)); tempValue = Util.null2String(mainMap.get(fieldName));
if ("".equals(tempValue)) {
tempValue = Util.null2String(detailMap.get(fieldNameLower));
}
} }
} }
String requestId = Util.null2String(mainMap.get("requestid")); String requestId = Util.null2String(mainMap.get("requestid"));
@ -667,10 +674,17 @@ public class DealWithMapping extends ToolUtil {
fileNames.add(fileName);*/ fileNames.add(fileName);*/
FieldMessage fieldMassage = mappingDetail.getFieldMassage(); FieldMessage fieldMassage = mappingDetail.getFieldMassage();
String fieldName = fieldMassage.getFieldName(); String fieldName = fieldMassage.getFieldName();
String fieldNameLower = fieldName.toLowerCase();
if ("1".equals(childSource)) { if ("1".equals(childSource)) {
value = Util.null2String(detailMap.get(fieldName)); value = Util.null2String(detailMap.get(fieldName));
if ("".equals(value)) {
value = Util.null2String(detailMap.get(fieldNameLower));
}
} else { } else {
value = Util.null2String(mainMap.get(fieldName)); value = Util.null2String(mainMap.get(fieldName));
if ("".equals(value)) {
value = Util.null2String(detailMap.get(fieldNameLower));
}
} }
String fileIds = Util.null2String(value); String fileIds = Util.null2String(value);
if ("".equals(fileIds)) { if ("".equals(fileIds)) {
@ -699,10 +713,17 @@ public class DealWithMapping extends ToolUtil {
FieldMessage fieldMassage = mappingDetail.getFieldMassage(); FieldMessage fieldMassage = mappingDetail.getFieldMassage();
if (null != fieldMassage && !StringUtils.isEmpty(fieldMassage.getFieldName())) { if (null != fieldMassage && !StringUtils.isEmpty(fieldMassage.getFieldName())) {
String fieldName = fieldMassage.getFieldName(); String fieldName = fieldMassage.getFieldName();
String fieldNameLower = fieldName.toLowerCase();
if ("1".equals(childSource)) { if ("1".equals(childSource)) {
value = Util.null2String(detailMap.get(fieldName)); value = Util.null2String(detailMap.get(fieldName));
if ("".equals(value)) {
value = Util.null2String(detailMap.get(fieldNameLower));
}
} else { } else {
value = Util.null2String(mainMap.get(fieldName)); value = Util.null2String(mainMap.get(fieldName));
if ("".equals(value)) {
value = Util.null2String(detailMap.get(fieldNameLower));
}
} }
} }
value = o.execute(mainMap, detailMap, String.valueOf(value == null ? "" : value), pathParamMap); value = o.execute(mainMap, detailMap, String.valueOf(value == null ? "" : value), pathParamMap);
@ -926,14 +947,24 @@ public class DealWithMapping extends ToolUtil {
int detailId = -1; int detailId = -1;
if (fieldMassage != null) { if (fieldMassage != null) {
String fieldName = fieldMassage.getFieldName(); String fieldName = fieldMassage.getFieldName();
String fieldNameLower = fieldName.toLowerCase();
if ("1".equals(childSource)) { if ("1".equals(childSource)) {
tempValue = Util.null2String(detailMap.get(fieldName)); tempValue = Util.null2String(detailMap.get(fieldName));
if ("".equals(tempValue)) {
tempValue = Util.null2String(detailMap.get(fieldNameLower));
}
// 明细 // 明细
detailId = Util.getIntValue(Util.null2String(detailMap.get("id")), -1); detailId = Util.getIntValue(Util.null2String(detailMap.get("id")), -1);
} else if ("0".equals(childSource)) { } else if ("0".equals(childSource)) {
tempValue = Util.null2String(mainMap.get(fieldName)); tempValue = Util.null2String(mainMap.get(fieldName));
if ("".equals(tempValue)) {
tempValue = Util.null2String(detailMap.get(fieldNameLower));
}
} else { } else {
tempValue = Util.null2String(relationRs.getString(fieldName)); tempValue = Util.null2String(relationRs.getString(fieldName));
if ("".equals(tempValue)) {
tempValue = Util.null2String(detailMap.get(fieldNameLower));
}
requestId = Util.null2String(relationRs.getString("requestid")); requestId = Util.null2String(relationRs.getString("requestid"));
} }
if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) { if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) {
@ -979,10 +1010,17 @@ public class DealWithMapping extends ToolUtil {
fileNames.add(fileName);*/ fileNames.add(fileName);*/
FieldMessage fieldMassage = mappingDetail.getFieldMassage(); FieldMessage fieldMassage = mappingDetail.getFieldMassage();
String fieldName = fieldMassage.getFieldName(); String fieldName = fieldMassage.getFieldName();
String fieldNameLower = fieldName.toLowerCase();
if ("1".equals(childSource)) { if ("1".equals(childSource)) {
value = Util.null2String(detailMap.get(fieldName)); value = Util.null2String(detailMap.get(fieldName));
if ("".equals(value)) {
value = Util.null2String(detailMap.get(fieldNameLower));
}
} else { } else {
value = Util.null2String(mainMap.get(fieldName)); value = Util.null2String(mainMap.get(fieldName));
if ("".equals(value)) {
value = Util.null2String(detailMap.get(fieldNameLower));
}
} }
String fileIds = Util.null2String(value); String fileIds = Util.null2String(value);
if ("".equals(fileIds)) { if ("".equals(fileIds)) {
@ -1012,10 +1050,17 @@ public class DealWithMapping extends ToolUtil {
FieldMessage fieldMassage = mappingDetail.getFieldMassage(); FieldMessage fieldMassage = mappingDetail.getFieldMassage();
if (null != fieldMassage && !StringUtils.isEmpty(fieldMassage.getFieldName())) { if (null != fieldMassage && !StringUtils.isEmpty(fieldMassage.getFieldName())) {
String fieldName = fieldMassage.getFieldName(); String fieldName = fieldMassage.getFieldName();
String fieldNameLower = fieldName.toLowerCase();
if ("1".equals(childSource)) { if ("1".equals(childSource)) {
value = Util.null2String(detailMap.get(fieldName)); value = Util.null2String(detailMap.get(fieldName));
if ("".equals(value)) {
value = Util.null2String(detailMap.get(fieldNameLower));
}
} else { } else {
value = Util.null2String(mainMap.get(fieldName)); value = Util.null2String(mainMap.get(fieldName));
if ("".equals(value)) {
value = Util.null2String(detailMap.get(fieldNameLower));
}
} }
} }
value = o.execute(mainMap, detailMap, String.valueOf(value == null ? "" : value), pathParamMap); value = o.execute(mainMap, detailMap, String.valueOf(value == null ? "" : value), pathParamMap);

View File

@ -12,7 +12,10 @@ import lombok.ToString;
import weaver.hrm.User; import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo; import weaver.soa.workflow.request.RequestInfo;
import weaver.youhong.ai.haripijiu.action.sapdocking.service.VoucherPayableService; import weaver.youhong.ai.haripijiu.action.sapdocking.service.VoucherPayableService;
import weaver.youhong.ai.haripijiu.action.sapdocking.util.SmbjUtil;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List; import java.util.List;
/** /**
@ -46,9 +49,32 @@ public class ReceiptAndPaymentAction extends SafeCusBaseAction {
@RequiredMark("凭证类型1- 付款单; 2- 收款单") @RequiredMark("凭证类型1- 付款单; 2- 收款单")
private String voucherType; private String voucherType;
@PrintParamMark
@RequiredMark("收款单远程路径存储")
private String receiptPath;
@PrintParamMark
@RequiredMark("付款单远程路径存储")
private String paymentPath;
@PrintParamMark
@RequiredMark("用户名")
private String userName;
@PrintParamMark
@RequiredMark("密码")
private String password;
@PrintParamMark
@RequiredMark("ip")
private String ip;
@Override @Override
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
try { try {
SmbjUtil smbjUtil = new SmbjUtil();
VoucherPayableService server = new VoucherPayableService(); VoucherPayableService server = new VoucherPayableService();
String fileName = ""; String fileName = "";
if (Integer.parseInt(voucherType) == 1) { if (Integer.parseInt(voucherType) == 1) {
@ -57,17 +83,26 @@ public class ReceiptAndPaymentAction extends SafeCusBaseAction {
for (String filePath : paymentFilePathList) { for (String filePath : paymentFilePathList) {
fileName = "Receipt" + Util.getTime("yyyyMMddHHmmss") + ".txt"; fileName = "Receipt" + Util.getTime("yyyyMMddHHmmss") + ".txt";
// TODO 根据不同的规则生成不同的文件名并将文件存储到指定位置 // TODO 根据不同的规则生成不同的文件名并将文件存储到指定位置
log.info("远程连接地址:" + "smb://" + ip + receiptPath);
log.info("本地文件地址: " + filePath);
smbjUtil.smbPut("smb://" + ip + receiptPath, filePath, userName, password, fileName);
Files.delete(Paths.get(filePath));
} }
} else if (Integer.parseInt(voucherType) == 2) { } else if (Integer.parseInt(voucherType) == 2) {
String tempFilePath = server.sendReceiptVoucher(onlyMark, requestId, billTable); String tempFilePath = server.sendReceiptVoucher(onlyMark, requestId, billTable);
fileName = "Payment" + Util.getTime("yyyyMMddHHmmss") + ".txt"; fileName = "Payment" + Util.getTime("yyyyMMddHHmmss") + ".txt";
// TODO 根据不同的规则生成不同的文件名并将文件存储到指定位置 // TODO 根据不同的规则生成不同的文件名并将文件存储到指定位置
log.info("远程连接地址:" + "smb://" + ip + paymentPath);
log.info("本地文件地址: " + tempFilePath);
smbjUtil.smbPut("smb://" + ip + paymentPath, tempFilePath, userName, password, fileName);
Files.delete(Paths.get(tempFilePath));
} }
/* ******************* 是否提交流程 ******************* */ /* ******************* 是否提交流程 ******************* */
if (Boolean.parseBoolean(submitAction)) { if (Boolean.parseBoolean(submitAction)) {
this.submitWorkflow(requestId, user.getUID()); this.submitWorkflow(requestId, user.getUID());
} }
} catch (Exception e) { } catch (Exception e) {
log.error("推送收付款凭证失败!" + e.getMessage());
if (Boolean.parseBoolean(block)) { if (Boolean.parseBoolean(block)) {
throw new CustomerException(e.getMessage(), e); throw new CustomerException(e.getMessage(), e);
} }

View File

@ -12,6 +12,10 @@ import lombok.ToString;
import weaver.hrm.User; import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo; import weaver.soa.workflow.request.RequestInfo;
import weaver.youhong.ai.haripijiu.action.sapdocking.service.VoucherPayableService; import weaver.youhong.ai.haripijiu.action.sapdocking.service.VoucherPayableService;
import weaver.youhong.ai.haripijiu.action.sapdocking.util.SmbjUtil;
import java.nio.file.Files;
import java.nio.file.Paths;
/** /**
* <h1></h1> * <h1></h1>
@ -46,25 +50,54 @@ public class VoucherPayableAction extends SafeCusBaseAction {
private String voucherType; private String voucherType;
@PrintParamMark
@RequiredMark("应付凭证远程路径")
private String pavRemotePath;
@PrintParamMark
@RequiredMark("付款凭证远程路径")
private String pmvRemotePath;
@PrintParamMark
@RequiredMark("用户名")
private String userName;
@PrintParamMark
@RequiredMark("密码")
private String password;
@PrintParamMark
@RequiredMark("ip")
private String ip;
@Override @Override
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
try { try {
SmbjUtil smbjUtil = new SmbjUtil();
VoucherPayableService server = new VoucherPayableService(); VoucherPayableService server = new VoucherPayableService();
String tempFilePath = server.sendSapVoucher(onlyMark, requestId, billTable); String tempFilePath = server.sendSapVoucher(onlyMark, requestId, billTable);
String fileName = ""; String fileName = "";
String remotePath = "";
if (Integer.parseInt(voucherType) == 1) { if (Integer.parseInt(voucherType) == 1) {
fileName = "Pav" + Util.getTime("yyyyMMddHHmmss") + ".txt"; fileName = "Pav" + Util.getTime("yyyyMMddHHmmss") + ".txt";
remotePath = pavRemotePath;
} else if (Integer.parseInt(voucherType) == 2) { } else if (Integer.parseInt(voucherType) == 2) {
fileName = "Pmv" + Util.getTime("yyyyMMddHHmmss") + ".txt"; fileName = "Pmv" + Util.getTime("yyyyMMddHHmmss") + ".txt";
remotePath = pmvRemotePath;
} }
// TODO 根据不同的规则生成不同的文件名并将文件存储到指定位置 log.info("远程连接地址:" + "smb://" + ip + remotePath);
log.info("本地文件地址: " + tempFilePath);
smbjUtil.smbPut("smb://" + ip + remotePath, tempFilePath, userName, password, fileName);
Files.delete(Paths.get(tempFilePath));
/* ******************* 是否提交流程 ******************* */ /* ******************* 是否提交流程 ******************* */
if (Boolean.parseBoolean(submitAction)) { if (Boolean.parseBoolean(submitAction)) {
this.submitWorkflow(requestId, user.getUID()); this.submitWorkflow(requestId, user.getUID());
} }
} catch (Exception e) { } catch (Exception e) {
log.error("推送应付款凭证失败!" + e.getMessage());
if (Boolean.parseBoolean(block)) { if (Boolean.parseBoolean(block)) {
throw new CustomerException(e.getMessage(), e); throw new CustomerException(e.getMessage(), e);
} }

View File

@ -0,0 +1,120 @@
package weaver.youhong.ai.haripijiu.action.sapdocking.util;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.google.common.base.Strings;
import jcifs.smb.*;
import org.apache.log4j.Logger;
import java.io.*;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.util.Objects;
/**
* <h1>windows访</h1>
*
* <p>create: 2023/2/8 17:55</p>
*
* @author youHong.ai
*/
public class SmbjUtil {
private final Logger log = Util.getLogger();
/**
* Description:
*
* @param remoteUrl
* @param localFilePath
*/
public void smbPut(String remoteUrl, String localFilePath, String userName, String pwd, String fileName) {
InputStream in = null;
OutputStream out = null;
try {
File localFile = new File(localFilePath);
if (Strings.isNullOrEmpty(fileName)) {
fileName = localFile.getName();
}
// 这里推荐使用这种方式进行用户名密码的校验在url中拼接如果需要特殊字符可能无法转换
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, userName, pwd);
SmbFile remoteFile = new SmbFile(remoteUrl + "/" + fileName, auth);
in = new BufferedInputStream(Files.newInputStream(localFile.toPath()));
out = new BufferedOutputStream(new SmbFileOutputStream(remoteFile));
byte[] buffer = new byte[1024];
while (in.read(buffer) != -1) {
out.write(buffer);
buffer = new byte[1024];
}
} catch (Exception e) {
log.error("提交文件到 共享目录失败!\n" + Util.getErrString(e));
throw new CustomerException("提交文件到 共享目录失败");
} finally {
closeStream(in, out);
}
}
private void closeStream(InputStream in, OutputStream out) {
try {
if (!Objects.isNull(out)) {
out.close();
}
if (!Objects.isNull(in)) {
in.close();
}
} catch (IOException e) {
log.error("流关闭失败!\n" + Util.getErrString(e));
throw new CustomerException("流关闭失败");
}
}
/**
* Description:
*
* @param remoteUrl
* @param localDir
*/
public void smbGet(String remoteUrl, String localDir) {
InputStream in = null;
OutputStream out = null;
try {
SmbFile remoteFile = new SmbFile(remoteUrl);
String fileName = remoteFile.getName();
File localFile = new File(localDir + File.separator + fileName);
in = new BufferedInputStream(new SmbFileInputStream(remoteFile));
out = new BufferedOutputStream(Files.newOutputStream(localFile.toPath()));
byte[] buffer = new byte[1024];
while (in.read(buffer) != -1) {
out.write(buffer);
buffer = new byte[1024];
}
} catch (Exception e) {
log.error("从共享目录拷贝文件到本地失败!\n" + Util.getErrString(e));
throw new CustomerException("从共享目录拷贝文件到本地失败");
} finally {
closeStream(in, out);
}
}
/**
*
*
* @param remoteUrl
* @param fileName
*/
public void deleteFile(String remoteUrl, String fileName, String userName, String pwd) {
SmbFile smbFile;
try {
// smb://userName:passWord@host/path/shareFolderPath/fileName
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, userName, pwd);
smbFile = new SmbFile(remoteUrl + "/" + fileName, auth);
if (smbFile.exists()) {
smbFile.delete();
}
} catch (MalformedURLException | SmbException e) {
log.error("删除共享目录文件失败!\n" + Util.getErrString(e));
throw new CustomerException("删除共享目录文件失败");
}
}
}

View File

@ -0,0 +1,23 @@
package youhong.ai.haripijiu;
import aiyh.utils.GenerateFileUtil;
import basetest.BaseTest;
import org.junit.Test;
import weaver.youhong.ai.haripijiu.action.sapdocking.ReceiptAndPaymentAction;
import weaver.youhong.ai.haripijiu.action.sapdocking.VoucherPayableAction;
/**
* <h1></h1>
*
* <p>create: 2023/2/12 13:24</p>
*
* @author youHong.ai
*/
public class TestHaRiPiJiu extends BaseTest {
@Test
public void testA() {
GenerateFileUtil.createActionDocument(VoucherPayableAction.class);
GenerateFileUtil.createActionDocument(ReceiptAndPaymentAction.class);
}
}