修改dealwithmapping获取字段数据bug
parent
dfc89e7d21
commit
9dacdd2751
|
@ -298,3 +298,24 @@ $(() => {
|
|||
})
|
||||
|
||||
/* ******************* apa(employee)流程明细分数控制end ******************* */
|
||||
|
||||
const workflowInsertValueConfig = [
|
||||
{
|
||||
table: '',
|
||||
targetTable: '',
|
||||
filedMapping: [{
|
||||
source: '',
|
||||
target: ''
|
||||
}]
|
||||
}, {
|
||||
table: '',
|
||||
targetTable: '',
|
||||
filedMapping: []
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
/* ******************* 流程明细数据整合插入start ******************* */
|
||||
|
||||
|
||||
/* ******************* 流程明细数据整合插入end ******************* */
|
||||
|
|
|
@ -2818,7 +2818,7 @@ public class Util extends weaver.general.Util {
|
|||
int finalSeconds = seconds;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(1000 * finalSeconds);
|
||||
Thread.sleep(1000L * finalSeconds);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Util.getLogger().error("线程休眠失败", e);
|
||||
|
@ -3345,9 +3345,8 @@ public class Util extends weaver.general.Util {
|
|||
}
|
||||
try {
|
||||
action = cronJobClass.newInstance();
|
||||
if (declaredFields.length > 0) {
|
||||
for (Field declaredField : declaredFields) {
|
||||
// 必填参数验证
|
||||
// 必填参数验证
|
||||
boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class);
|
||||
String name = declaredField.getName();
|
||||
String setMethodName = getSetMethodName(name);
|
||||
|
@ -3356,39 +3355,39 @@ public class Util extends weaver.general.Util {
|
|||
RequiredMark requiredMark = declaredField.getAnnotation(RequiredMark.class);
|
||||
ActionDefaultTestValue defaultTestValue = declaredField.getAnnotation(ActionDefaultTestValue.class);
|
||||
boolean hasOptional = declaredField.isAnnotationPresent(ActionOptionalParam.class);
|
||||
// 如果存在默认值,并且是必填参数
|
||||
// 如果存在默认值,并且是必填参数
|
||||
if (hasDefaultValue && hasRequiredMark) {
|
||||
// 如果参数map中没有则赋值为默认值
|
||||
// 如果参数map中没有则赋值为默认值
|
||||
if (null == value) {
|
||||
// 获取默认值赋值
|
||||
// 获取默认值赋值
|
||||
String defaultValue = defaultTestValue.value();
|
||||
if (defaultValue == null) {
|
||||
throw new CustomerException(String.format("必填参数[%s]未填写:%s", name, requiredMark.value()));
|
||||
}
|
||||
value = defaultValue;
|
||||
}
|
||||
// 如果没有默认值,并且是必填参数
|
||||
// 如果没有默认值,并且是必填参数
|
||||
} else if (!hasDefaultValue && hasRequiredMark) {
|
||||
// 如果没有从param中获取到,则抛出异常
|
||||
// 如果没有从param中获取到,则抛出异常
|
||||
if (Util.isNullOrEmpty(value)) {
|
||||
throw new CustomerException(String.format("必填参数[%s]未填写:%s", name, requiredMark.value()));
|
||||
}
|
||||
// 如果有默认值,并且没有从params中获得,则赋值
|
||||
// 如果有默认值,并且没有从params中获得,则赋值
|
||||
} else if (hasDefaultValue) {
|
||||
if (null == value) {
|
||||
value = defaultTestValue.value();
|
||||
}
|
||||
} else if (hasOptional) {
|
||||
// 如果存在可选值
|
||||
// 如果存在可选值
|
||||
ActionOptionalParam optionalParam = declaredField.getAnnotation(ActionOptionalParam.class);
|
||||
String defaultValue = optionalParam.value();
|
||||
// 可选值没有在param中存在
|
||||
// 可选值没有在param中存在
|
||||
if (null == value) {
|
||||
value = defaultValue;
|
||||
}
|
||||
} else {
|
||||
|
||||
// 都不符合必填和默认值的参数,判断params中是否存在,如果不存在则直接跳过
|
||||
// 都不符合必填和默认值的参数,判断params中是否存在,如果不存在则直接跳过
|
||||
if (null == value) {
|
||||
continue;
|
||||
}
|
||||
|
@ -3397,7 +3396,6 @@ public class Util extends weaver.general.Util {
|
|||
Method method = cronJobClass.getMethod(setMethodName, String.class);
|
||||
method.invoke(action, value);
|
||||
}
|
||||
}
|
||||
action.execute();
|
||||
} catch (Exception e) {
|
||||
throw new CustomerException("计划任务执行异常!异常信息:\n" + Util.getErrString(e));
|
||||
|
@ -3426,9 +3424,8 @@ public class Util extends weaver.general.Util {
|
|||
}
|
||||
try {
|
||||
action = actionClass.newInstance();
|
||||
if (declaredFields.length > 0) {
|
||||
for (Field declaredField : declaredFields) {
|
||||
// 必填参数验证
|
||||
// 必填参数验证
|
||||
boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class);
|
||||
String name = declaredField.getName();
|
||||
String setMethodName = getSetMethodName(name);
|
||||
|
@ -3460,7 +3457,6 @@ public class Util extends weaver.general.Util {
|
|||
Method method = actionClass.getMethod(setMethodName, String.class);
|
||||
method.invoke(action, value);
|
||||
}
|
||||
}
|
||||
RequestService requestService = new RequestService();
|
||||
requestInfo = requestService.getRequest(requestId);
|
||||
if (null == requestInfo) {
|
||||
|
|
|
@ -4,8 +4,13 @@ import aiyh.utils.ApiResult;
|
|||
import aiyh.utils.Util;
|
||||
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service.ApaLevelByScoreService;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -35,4 +40,19 @@ public class ApaLevelByScoreController {
|
|||
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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
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.SqlMapper;
|
||||
|
||||
|
@ -25,4 +26,10 @@ public interface ApaLevelByScoreMapper {
|
|||
*/
|
||||
@Select("select level1 from uf_APAlevel where #{score} between zdf and zgf")
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service;
|
|||
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.excention.CustomerException;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper.ApaLevelByScoreMapper;
|
||||
import weaver.hrm.User;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
|
@ -31,4 +33,12 @@ public class ApaLevelByScoreService {
|
|||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -625,11 +625,18 @@ public class DealWithMapping extends ToolUtil {
|
|||
int detailId = -1;
|
||||
if (fieldMassage != null) {
|
||||
String fieldName = fieldMassage.getFieldName();
|
||||
String fieldNameLower = fieldName.toLowerCase();
|
||||
if ("1".equals(childSource)) {
|
||||
tempValue = Util.null2String(detailMap.get(fieldName));
|
||||
if ("".equals(tempValue)) {
|
||||
tempValue = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
detailId = Util.getIntValue(Util.null2String(detailMap.get("id")), -1);
|
||||
} else {
|
||||
tempValue = Util.null2String(mainMap.get(fieldName));
|
||||
if ("".equals(tempValue)) {
|
||||
tempValue = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
}
|
||||
}
|
||||
String requestId = Util.null2String(mainMap.get("requestid"));
|
||||
|
@ -667,10 +674,17 @@ public class DealWithMapping extends ToolUtil {
|
|||
fileNames.add(fileName);*/
|
||||
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
||||
String fieldName = fieldMassage.getFieldName();
|
||||
String fieldNameLower = fieldName.toLowerCase();
|
||||
if ("1".equals(childSource)) {
|
||||
value = Util.null2String(detailMap.get(fieldName));
|
||||
if ("".equals(value)) {
|
||||
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
} else {
|
||||
value = Util.null2String(mainMap.get(fieldName));
|
||||
if ("".equals(value)) {
|
||||
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
}
|
||||
String fileIds = Util.null2String(value);
|
||||
if ("".equals(fileIds)) {
|
||||
|
@ -699,10 +713,17 @@ public class DealWithMapping extends ToolUtil {
|
|||
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
||||
if (null != fieldMassage && !StringUtils.isEmpty(fieldMassage.getFieldName())) {
|
||||
String fieldName = fieldMassage.getFieldName();
|
||||
String fieldNameLower = fieldName.toLowerCase();
|
||||
if ("1".equals(childSource)) {
|
||||
value = Util.null2String(detailMap.get(fieldName));
|
||||
if ("".equals(value)) {
|
||||
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
|
@ -926,14 +947,24 @@ public class DealWithMapping extends ToolUtil {
|
|||
int detailId = -1;
|
||||
if (fieldMassage != null) {
|
||||
String fieldName = fieldMassage.getFieldName();
|
||||
String fieldNameLower = fieldName.toLowerCase();
|
||||
if ("1".equals(childSource)) {
|
||||
tempValue = Util.null2String(detailMap.get(fieldName));
|
||||
if ("".equals(tempValue)) {
|
||||
tempValue = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
// 明细
|
||||
detailId = Util.getIntValue(Util.null2String(detailMap.get("id")), -1);
|
||||
} else if ("0".equals(childSource)) {
|
||||
tempValue = Util.null2String(mainMap.get(fieldName));
|
||||
if ("".equals(tempValue)) {
|
||||
tempValue = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
} else {
|
||||
tempValue = Util.null2String(relationRs.getString(fieldName));
|
||||
if ("".equals(tempValue)) {
|
||||
tempValue = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
requestId = Util.null2String(relationRs.getString("requestid"));
|
||||
}
|
||||
if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) {
|
||||
|
@ -979,10 +1010,17 @@ public class DealWithMapping extends ToolUtil {
|
|||
fileNames.add(fileName);*/
|
||||
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
||||
String fieldName = fieldMassage.getFieldName();
|
||||
String fieldNameLower = fieldName.toLowerCase();
|
||||
if ("1".equals(childSource)) {
|
||||
value = Util.null2String(detailMap.get(fieldName));
|
||||
if ("".equals(value)) {
|
||||
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
} else {
|
||||
value = Util.null2String(mainMap.get(fieldName));
|
||||
if ("".equals(value)) {
|
||||
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
}
|
||||
String fileIds = Util.null2String(value);
|
||||
if ("".equals(fileIds)) {
|
||||
|
@ -998,7 +1036,7 @@ public class DealWithMapping extends ToolUtil {
|
|||
multipartFile.setStream(fileInputStream);
|
||||
multipartFile.setFileName(docImageFile.getImageFileName());
|
||||
multipartFile.setFileSize(docImageFile.getFileSize() / 1024);
|
||||
this.writeDebuggerLog("multipartFile ==>"+multipartFile);
|
||||
this.writeDebuggerLog("multipartFile ==>" + multipartFile);
|
||||
multipartFileList.add(multipartFile);
|
||||
}
|
||||
return null;
|
||||
|
@ -1012,10 +1050,17 @@ public class DealWithMapping extends ToolUtil {
|
|||
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
||||
if (null != fieldMassage && !StringUtils.isEmpty(fieldMassage.getFieldName())) {
|
||||
String fieldName = fieldMassage.getFieldName();
|
||||
String fieldNameLower = fieldName.toLowerCase();
|
||||
if ("1".equals(childSource)) {
|
||||
value = Util.null2String(detailMap.get(fieldName));
|
||||
if ("".equals(value)) {
|
||||
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
|
@ -1307,7 +1352,7 @@ public class DealWithMapping extends ToolUtil {
|
|||
* @return 要插入的信息
|
||||
*/
|
||||
public Map<String, Map<String, Object>> dealResponse(List<ResponseMapping> responseMappingList, Map<String, Object> requestRes) {
|
||||
this.writeDebuggerLog("回写信息转换处理 responseMappingList==>" + responseMappingList + " requestRes==>" + requestRes + "mainTable ==>"+mainTable);
|
||||
this.writeDebuggerLog("回写信息转换处理 responseMappingList==>" + responseMappingList + " requestRes==>" + requestRes + "mainTable ==>" + mainTable);
|
||||
Map<String, Map<String, Object>> tableUpdateMap = new HashMap<>();
|
||||
if (responseMappingList != null && !responseMappingList.isEmpty()) {
|
||||
Map<String, Object> mainUpdateMap = new HashMap<>();
|
||||
|
|
|
@ -12,7 +12,10 @@ import lombok.ToString;
|
|||
import weaver.hrm.User;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -46,9 +49,32 @@ public class ReceiptAndPaymentAction extends SafeCusBaseAction {
|
|||
@RequiredMark("凭证类型,1- 付款单; 2- 收款单")
|
||||
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
|
||||
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
||||
try {
|
||||
SmbjUtil smbjUtil = new SmbjUtil();
|
||||
VoucherPayableService server = new VoucherPayableService();
|
||||
String fileName = "";
|
||||
if (Integer.parseInt(voucherType) == 1) {
|
||||
|
@ -57,17 +83,26 @@ public class ReceiptAndPaymentAction extends SafeCusBaseAction {
|
|||
for (String filePath : paymentFilePathList) {
|
||||
fileName = "Receipt" + Util.getTime("yyyyMMddHHmmss") + ".txt";
|
||||
// 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) {
|
||||
String tempFilePath = server.sendReceiptVoucher(onlyMark, requestId, billTable);
|
||||
fileName = "Payment" + Util.getTime("yyyyMMddHHmmss") + ".txt";
|
||||
// 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)) {
|
||||
this.submitWorkflow(requestId, user.getUID());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("推送收付款凭证失败!" + e.getMessage());
|
||||
if (Boolean.parseBoolean(block)) {
|
||||
throw new CustomerException(e.getMessage(), e);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ import lombok.ToString;
|
|||
import weaver.hrm.User;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
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>
|
||||
|
@ -46,25 +50,54 @@ public class VoucherPayableAction extends SafeCusBaseAction {
|
|||
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
|
||||
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
||||
|
||||
try {
|
||||
SmbjUtil smbjUtil = new SmbjUtil();
|
||||
VoucherPayableService server = new VoucherPayableService();
|
||||
String tempFilePath = server.sendSapVoucher(onlyMark, requestId, billTable);
|
||||
String fileName = "";
|
||||
String remotePath = "";
|
||||
if (Integer.parseInt(voucherType) == 1) {
|
||||
fileName = "Pav" + Util.getTime("yyyyMMddHHmmss") + ".txt";
|
||||
remotePath = pavRemotePath;
|
||||
} else if (Integer.parseInt(voucherType) == 2) {
|
||||
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)) {
|
||||
this.submitWorkflow(requestId, user.getUID());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("推送应付款凭证失败!" + e.getMessage());
|
||||
if (Boolean.parseBoolean(block)) {
|
||||
throw new CustomerException(e.getMessage(), e);
|
||||
}
|
||||
|
|
|
@ -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("删除共享目录文件失败");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue