Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
陈绍鑫 2025-05-16 10:25:37 +08:00
commit 855b64b4a7
2 changed files with 308 additions and 3 deletions

View File

@ -3,9 +3,8 @@ package shkd.sys.sys.mservice;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
//import com.google.gson.Gson;
//import com.kingdee.bos.webapi.entity.RepoRet;
//import com.kingdee.bos.webapi.sdk.K3CloudApi;
import com.kingdee.bos.webapi.entity.IdentifyInfo;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import kd.bos.bill.BillShowParameter;
import kd.bos.cache.CacheFactory;
import kd.bos.cache.TempFileCache;
@ -51,6 +50,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import shkd.sys.sys.common.PaymentRequest;
import java.net.URLConnection;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
@ -1055,4 +1055,139 @@ public class ApiService {
}
}
}
/**
* 构建星空K3CloudApi对象
* @param dataEntity
* @return
*/
public static K3CloudApi getK3CloudApi(DynamicObject dataEntity) {
IdentifyInfo iden = new IdentifyInfo();
iden.setUserName(dataEntity.getString("shkd_xkusername"));// properties.getProperty("X-KDApi-UserName")
iden.setAppId(dataEntity.getString("shkd_xkappid"));// properties.getProperty("X-KDApi-AppID")
iden.setdCID(dataEntity.getString("shkd_xkacctid"));// properties.getProperty("X-KDApi-AcctID")
iden.setAppSecret(dataEntity.getString("shkd_xkappsec"));// properties.getProperty("X-KDApi-AppSec")
iden.setlCID(2052);
iden.setServerUrl(dataEntity.getString("shkd_xkserverurl"));// properties.getProperty("X-KDApi-ServerUrl")
return new K3CloudApi(iden);
}
/**
* 查询星空收付款单
* @param dataEntity API映射元数据对象
* @param billMark 单据类型收付款
* @param billNumber 单据编码
* @return
*/
public static HashMap<String, Object> getBillObject(DynamicObject dataEntity, String billMark, String billNumber) {
logger.info("获取推送单据类型 → billMark{}", billMark);
String xkBillType = null;
if ("cas_paybill".equals(billMark)) {
xkBillType = "AP_PAYBILL";
} else if ("cas_recbill".equals(billMark)) {
xkBillType = "AR_RECEIVEBILL";
}
HashMap<String, Object> result = new HashMap<>();
K3CloudApi k3CloudApi = getK3CloudApi(dataEntity);
JSONObject jsonObject = new JSONObject();
jsonObject.put("OrderString", "");
jsonObject.put("TopRowCount", 0);
jsonObject.put("SubSystemId", "");
jsonObject.put("FieldKeys", "FBillNo,FID");
jsonObject.put("FormId", xkBillType);
jsonObject.put("Limit", 2000);
jsonObject.put("FilterString", "F_keed_SKDJBH='" + billNumber + "'");
jsonObject.put("StartRow", 0);
try {
List<List<Object>> lists = k3CloudApi.executeBillQuery(jsonObject.toString());
if (lists.isEmpty()) {
result.put("result", "false");
} else {
List<Object> objects = lists.get(0);
result.put("billNumber", objects.get(0));
result.put("billId", objects.get(1));
result.put("billType", xkBillType);
result.put("result", "true");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return result;
}
/**
* 推送星空单据附件
* @param dataEntity API映射元数据对象
* @return
*/
public static String pushBillAttachment(DynamicObject dataEntity) {
K3CloudApi k3CloudApi = getK3CloudApi(dataEntity);
// 获取想要推送单据类型
String billMark = dataEntity.getDynamicObject("shkd_sourcebill").getString("number");
// 获取想要推送单据编码
String billNumber = dataEntity.getString("shkd_sourcenumber");
logger.info("获取推送单据编码 → billNumber{}", billNumber);
HashMap<String, Object> xkBillData = getBillObject(dataEntity, billMark, billNumber);
String uploadAttachmentResult = null;
if ((Boolean)xkBillData.get("result")) {
List<Map<String, String>> attachmentData = get_attachment(dataEntity);
JSONObject jsonObject = new JSONObject();
jsonObject.put("FileName", attachmentData.get(0).get("name"));// 文件名
jsonObject.put("FormId", xkBillData.get("billType"));// 表单id付款单AP_PAYBILL
jsonObject.put("IsLast", true);// 是否最后一次上传
jsonObject.put("InterId", xkBillData.get("billId"));// 单据内码
jsonObject.put("BillNO", xkBillData.get("billNumber"));// 单据编码
jsonObject.put("SendByte", attachmentData.get(0).get("base64"));// 文件字节数组转base64后的字符串
try {
uploadAttachmentResult = k3CloudApi.attachmentUpload(jsonObject.toString());
logger.info("推送结果:" + uploadAttachmentResult);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return uploadAttachmentResult;
}
/**
* 获取附件将其转为base64
*
* @param dataEntity API映射元数据对象
* @return
*/
public static List<Map<String, String>> get_attachment(DynamicObject dataEntity) {
String entityId = dataEntity.getDataEntityType().toString();
List<Map<String, Object>> list = AttachmentServiceHelper.getAttachments(entityId, dataEntity.get("id"), "shkd_attachmentpanelap");
List<Map<String, String>> attachments = new ArrayList<>();
try {
for (Map map : list) {
String url = map.get("url").toString();
String name = (String) map.get("name");
URLConnection urlConnection = new URL(url).openConnection();
try (InputStream inputStream = urlConnection.getInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStream base64OutputStream = Base64.getEncoder().wrap(outputStream)) {
byte[] buffer = new byte[4096]; // 使用 4KB 缓冲区
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
base64OutputStream.write(buffer, 0, bytesRead);
}
base64OutputStream.flush(); // 确保所有数据都被写入
// 获取 Base64 编码后的字节数组
byte[] base64Data = outputStream.toByteArray();
// 打印 Base64 编码后的字符串
// 将名称和 Base64 编码后的数据添加到附件列表
Map<String, String> hashMap = new HashMap<>();
hashMap.put("name", name);
hashMap.put("base64", new String(base64Data, StandardCharsets.UTF_8));
attachments.add(hashMap);
}
}
} catch (IOException e) {
throw new RuntimeException("Error processing URLs", e);
}
return attachments;
}
}

View File

@ -0,0 +1,170 @@
package shkd.sys.sys.mservice;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.tmc.fpm.business.dataproc.save.ReportDataSDKService;
import kd.bos.login.actions.SerializationUtils;
import kd.tmc.fpm.business.dataproc.save.domain.*;
import kd.tmc.fpm.business.dataproc.save.ReportDataSaveObject;
import kd.tmc.fpm.business.domain.enums.AmountUnit;
import kd.tmc.fpm.business.domain.enums.ReportProcessStatus;
import kd.tmc.fpm.business.domain.enums.ReportStatus;
import kd.tmc.fpm.business.domain.enums.TemplateMetricType;
import kd.tmc.fpm.business.domain.service.FpmOperateResult;
import kd.tmc.fpm.common.enums.AdjustTypeEnum;
import microsoft.exchange.webservices.data.core.service.response.ResponseObject;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
* @Description 资金计划批量写入服务
* @Author Tao
* @Date 2025/3/6
*/
public class PlanningService {
private static final Log logger = LogFactory.getLog(PlanningService.class);
/**
* 计划编制批量写入服务
* @param periodCode 编报期间code
* @param orgCode 编报主体code
* @param subjectCode 计划科目code
* @param entryPeriodCode 主维度数据分录期间code
* @param amount 写入金额
* @return
*/
public static FpmResponse<Void> planningWrite(String periodCode, String orgCode, String subjectCode, String entryPeriodCode, int amount) {
// 1. 构造请求参数
ReportDataBatchSaveParam reportDataBatchSaveParam = new ReportDataBatchSaveParam();
// 体系code
reportDataBatchSaveParam.setSystemCode("SYS-005");// 川投计划填报
// 模板code
reportDataBatchSaveParam.setTemplateCode("FIX-013");// 月度计划测试
// 编报期间code
// reportDataBatchSaveParam.setReportPeriodCode("M_MW_FY2025.Q01.M03");// 2025年03月
reportDataBatchSaveParam.setReportPeriodCode(periodCode);// 2025年03月
// 编报主体code
// reportDataBatchSaveParam.setReportOrgCode("91510100MA7FY7GT7R");// 四川川投能源股份有限公司
reportDataBatchSaveParam.setReportOrgCode(orgCode);// 四川川投能源股份有限公司
// 单据状态code
reportDataBatchSaveParam.setBillStatus(ReportProcessStatus.SAVE);
// 计划状态code
reportDataBatchSaveParam.setPlanStatus(ReportStatus.DISABLE);
// 报表批量写入数据
ArrayList<ReportDataBatchSaveObject> reportDataBatchSaveObjects = new ArrayList<>();
ReportDataBatchSaveObject reportDataBatchSaveObject = new ReportDataBatchSaveObject();
// 币种code
reportDataBatchSaveObject.setCurrencyCode("CNY");// 人民币
// 计划科目code
// reportDataBatchSaveObject.setSubjectCode("CF1.02.01.01.01");// 计划科目销售商品提供劳务收到的现金
reportDataBatchSaveObject.setSubjectCode(subjectCode);// 计划科目销售商品提供劳务收到的现金
// 公司code
// reportDataBatchSaveObject.setCompanyCode();
// 结算方式code
// reportDataBatchSaveObject.setSettleTypeCode();
// 主维度数据分录期间code
// reportDataBatchSaveObject.setEntryPeriodCode("M_MW_FY2025.M03.MW01");// 2025年3月01周
reportDataBatchSaveObject.setEntryPeriodCode(entryPeriodCode);// 2025年3月01周
// 自定义维度1值code
// reportDataBatchSaveObject.setCustom1Code();
// 自定义维度2值code
// reportDataBatchSaveObject.setCustom2Code();
// 自定义维度3值code
// reportDataBatchSaveObject.setCustom3Code();
// 度量值列表
ArrayList<ReportDataBatchSaveObject.MetricMember> metricMembers = new ArrayList<>();
ReportDataBatchSaveObject.MetricMember metricMember = new ReportDataBatchSaveObject.MetricMember();
// 写入金额
// metricMember.setAmount(new BigDecimal(1000));
metricMember.setAmount(new BigDecimal(amount));
// 金额单位
metricMember.setAmountUnit(AmountUnit.ONE);//
// 度量值预置类型
metricMember.setTemplateMetricType(TemplateMetricType.PLANAMT);// 计划额度
metricMembers.add(metricMember);
reportDataBatchSaveObject.setMetricMembers(metricMembers);
reportDataBatchSaveObjects.add(reportDataBatchSaveObject);
reportDataBatchSaveParam.setBatchSaveData(reportDataBatchSaveObjects);
String qParam = SerializationUtils.serializeToBase64(reportDataBatchSaveParam);
// 3. 调用SDK接口
ReportDataSDKService reportDataSDKService = new ReportDataSDKService();
String result = reportDataSDKService.batchSaveReportData(qParam);
// 4. 反序列化响应结果
FpmResponse<Void> responseObject = SerializationUtils.deSerializeFromBase64(result);
logger.info("是否成功:{}\n消息列表{}", responseObject.isSuccess(), responseObject.getMessage());
return responseObject;
}
/**
* 计划调整服务
*
* @param adjustReason 调整原因
* @param orgCode 编报主体编码
* @param periodCode 编报期间编码
* @param subjectCode 计划科目
* @param entryPeriodCode 主维度数据分录期间 code
* @param amount 调整金额
* @return
*/
public static ReportAdjustBillBatchSaveResDTO planAdjustment(String adjustReason, String orgCode, String periodCode, String subjectCode, String entryPeriodCode, int amount) {
logger.info("计划调整服务入参adjustReason={},orgCode={},periodCode={},subjectCode={},entryPeriodCode={},amount={}", adjustReason, orgCode, periodCode, subjectCode, entryPeriodCode, amount);
ReportAdjustBillBatchSaveDTO reportAdjustBillBatchSaveDTO = new ReportAdjustBillBatchSaveDTO();
reportAdjustBillBatchSaveDTO.setSystemCode("SYS-005");// 体系编码
ArrayList<ReportAdjustBillSaveDTO> reportAdjustBillSaveDTOS = new ArrayList<>();
ReportAdjustBillSaveDTO reportAdjustBillSaveDTO = new ReportAdjustBillSaveDTO();
reportAdjustBillSaveDTO.setAdjustReason(adjustReason);// 调整原因
reportAdjustBillSaveDTO.setBillStatus(ReportProcessStatus.SAVE);// 单据状态
reportAdjustBillSaveDTO.setAdjustType(AdjustTypeEnum.AMOUNT_ADDITIONAL);// 调整类型
reportAdjustBillSaveDTO.setReportOrgCode(orgCode);// 编报主体编码
reportAdjustBillSaveDTO.setReportPeriodCode(periodCode);// 编报期间编码
// reportAdjustBillSaveDTO.setCustomDimSeqMap();
reportAdjustBillSaveDTO.setReportTypeCode("M-002");// 编报类型编码
ArrayList<ReportAdjustDataSaveDTO> reportAdjustDataSaveDTOS = new ArrayList<>();
ReportAdjustDataSaveDTO reportAdjustDataSaveDTO = new ReportAdjustDataSaveDTO();
// reportAdjustDataSaveDTO.setAdjustReason();// 维度组合下每一行的调整原因
// reportAdjustDataSaveDTO.setAmountUnit();// 单位
reportAdjustDataSaveDTO.setCurrencyCode("CNY");// 币别 code
reportAdjustDataSaveDTO.setSubjectCode(subjectCode);// 计划科目
reportAdjustDataSaveDTO.setTemplateCode("FIX-013");// 调整数据所属编制表的模板编码
// reportAdjustDataSaveDTO.setCompanyCode();// 公司code
reportAdjustDataSaveDTO.setCurrentAdjustAmt(new BigDecimal(amount));// 本次调整金额
// reportAdjustDataSaveDTO.setCustom1Code();// 自定义维度1值code
// reportAdjustDataSaveDTO.setCustom2Code();// 自定义维度2值code
// reportAdjustDataSaveDTO.setCustom3Code();// 自定义维度3值code
reportAdjustDataSaveDTO.setEntryPeriodCode(entryPeriodCode);// 主维度数据分录期间 code
// reportAdjustDataSaveDTO.setSettleTypeCode();// 结算方式 code
reportAdjustDataSaveDTOS.add(reportAdjustDataSaveDTO);
reportAdjustBillSaveDTO.setAdjustDataList(reportAdjustDataSaveDTOS);// 调整数据 List<ReportAdjustDataSaveDTO> adjustDataList
reportAdjustBillSaveDTOS.add(reportAdjustBillSaveDTO);
reportAdjustBillBatchSaveDTO.setAdjustBillInfoList(reportAdjustBillSaveDTOS);// 调整单据信息
String qParam = SerializationUtils.serializeToBase64(reportAdjustBillBatchSaveDTO);
// 3. 调用SDK接口
ReportDataSDKService reportDataSDKService = new ReportDataSDKService();
reportDataSDKService.batchSaveAdjustReport(qParam);
String result = reportDataSDKService.batchSaveReportData(qParam);
// 4. 反序列化响应结果
FpmResponse<ReportAdjustBillBatchSaveResDTO> responseObject = SerializationUtils.deSerializeFromBase64(result);
ReportAdjustBillBatchSaveResDTO reportAdjustBillBatchSaveResDTO = responseObject.getData();
reportAdjustBillBatchSaveResDTO.getTotalSize();// 请求写入的调整单据总数
reportAdjustBillBatchSaveResDTO.getSuccessSize();// 成功写入的调整单据总数
reportAdjustBillBatchSaveResDTO.getFailSize();// 失败写入的调整单据总数
List<String> adjustBillNoList = reportAdjustBillBatchSaveResDTO.getAdjustBillNoList();// 调整单据编号列表
logger.info("是否成功:{}\n消息列表{}", responseObject.isSuccess(), responseObject.getMessage());
if (responseObject.isSuccess()) {
logger.info("调整单据编号列表:{}", adjustBillNoList);
}
return reportAdjustBillBatchSaveResDTO;
}
}