You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
13 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.engine.salary.timer;
import cn.hutool.core.util.StrUtil;
import com.engine.salary.exception.CBS8RunTimeException;
import com.engine.salary.mapper.SQLMapper;
import com.engine.salary.remote.cbs8.client.BillManagementClient;
import com.engine.salary.remote.cbs8.config.EBS2ECConfig;
import com.engine.salary.remote.cbs8.request.GetDtaRequest;
import com.engine.salary.remote.cbs8.response.GetDtaResponse;
import com.engine.salary.remote.cbs8.JsonUtil;
import com.engine.salary.remote.cbs8.util.db.MapperProxyFactory;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.security.AnyTypePermission;
import lombok.extern.slf4j.Slf4j;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.GCONST;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.schedule.BaseCronJob;
import java.io.File;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
* 获取票据池
* <p>Copyright: Copyright (c) 2024</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
@Slf4j
public class SyncCBSBillPoolJob extends BaseCronJob {
/**
* 持票人单位编码 多选。填在cbs系统公共设置>基础信息>组织机构维护的单位编码
*/
private String displayHoldOrganizationCodeList;
/**
* 持票人账号 多选。
*/
private String holdAccountList;
/**
* 系统票据类型 多选。按附录4.1.3票据类型-票据状态-流通标志级联关系表选择后按顺序填写。系统票据类型枚举见附录4.1.3。票据状态枚举见附录4.1.4。流通标志枚举见附录4.1.5。
*/
private String billVarietyList;
/**
* 出票日期起 格式为yyyy-mm-dd出票日期起止不允许一边有值一边无值日期间隔最大为一年
*/
private String issueDateStart;
/**
* 出票日期止 格式为yyyy-mm-dd出票日期起止不允许一边有值一边无值日期间隔最大为一年
*/
private String issueDateEnd;
/**
* 到期日期起 格式为yyyy-mm-dd到期日期起止不允许一边有值一边无值日期间隔最大为一年
*/
private String dueDateStart;
/**
* 到期日期止 格式为yyyy-mm-dd到期日期起止不允许一边有值一边无值日期间隔最大为一年
*/
private String dueDateEnd;
/**
* 票据种类 AC01-银承AC02-商承
*/
private String billType;
/**
* 票据来源 多选。1-直联交易2-台账交易3-台账登记4-挑票同步5-任务同步
*/
private String draftSourceList;
/**
* 持票银行类型 多选。见附录4.1.1.银行类型枚举
*/
private String holdBankTypeList;
/**
* 持票签收日期起 格式为yyyy-mm-dd持票签收日期起止不允许一边有值一边无值日期间隔最大为一年
*/
private String holdSignDateStart;
/**
* 持票签收日期止 格式为yyyy-mm-dd持票签收日期起止不允许一边有值一边无值日期间隔最大为一年
*/
private String holdSignDateEnd;
/**
* 系统票据编号
*/
private String draftNbr;
/**
* 票据(包)号
*/
private String billNbr;
/**
* 票据金额起 大于等于0,最多为两位小数且整数位上限为13位。票据金额起止不允许一边有值一边无值。单位
*/
private BigDecimal billAmountStart;
/**
* 票据金额止 大于等于0,最多为两位小数且整数位上限为13位。票据金额起止不允许一边有值一边无值。单位
*/
private BigDecimal billAmountEnd;
/**
* 子票区间起 子票区间起止不允许一边有值一边无值最多12位
*/
private String subBillIntervalStart;
/**
* 子票区间止 子票区间起止不允许一边有值一边无值,最多12位
*/
private String subBillIntervalEnd;
/**
* 票据状态
*/
private String billStsList;
/**
* 流通标志
*/
private String billTrsStsList;
/**
* 库存状态 1-已入库2-已出库。 为空时默认查询全部数据
*/
private String stockFlag;
/**
* 出库方式 0-空2-背书3-质押4-解质5-贴现6-分包7-结清, 8-作废。 为空时默认查询全部数据
*/
private String outInvType;
/**
* 记录状态 NOR-正常USE-占用DEL-删除 SUC-完成。为空时默认查询全部数据
*/
private String lockFlag;
private SQLMapper getSQLMapper() {
return MapperProxyFactory.getProxy(SQLMapper.class);
}
@Override
public void execute() {
User user = new User();
user.setUid(1);
user.setLoginid("sysadmin");
try {
GetDtaRequest requestParam = new GetDtaRequest();
requestParam.setCurrentPage(1);
requestParam.setPageSize(1000);
if (StrUtil.isBlank(displayHoldOrganizationCodeList)) {
throw new CBS8RunTimeException("持票人单位编码为空,请在计划任务配置此项!");
}
requestParam.setDisplayHoldOrganizationCodeList(Arrays.stream(displayHoldOrganizationCodeList.split(",")).collect(Collectors.toList()));
if (StrUtil.isBlank(holdAccountList)) {
throw new CBS8RunTimeException("持票人账号为空,请在计划任务配置此项!");
}
requestParam.setHoldAccountList(Arrays.stream(holdAccountList.split(",")).collect(Collectors.toList()));
if (StrUtil.isNotBlank(holdSignDateStart) && StrUtil.isNotBlank(holdSignDateEnd)) {
requestParam.setHoldSignDateStart(holdSignDateStart);
requestParam.setHoldSignDateEnd(holdSignDateEnd);
} else {
String nowDate = LocalDate.now().toString();
requestParam.setHoldSignDateStart(nowDate);
requestParam.setHoldSignDateEnd(nowDate);
}
//系统票据类型
requestParam.setBillVarietyList(Arrays.stream(Util.null2String(billVarietyList).split(",")).collect(Collectors.toList()));
requestParam.setDueDateStart(dueDateStart);
requestParam.setDueDateEnd(dueDateEnd);
requestParam.setBillType(billType);
requestParam.setDraftSourceList(draftSourceList==null ? null :Arrays.stream(draftSourceList.split(",")).collect(Collectors.toList()));
requestParam.setHoldBankTypeList(holdBankTypeList==null ? null :Arrays.stream(holdBankTypeList.split(",")).collect(Collectors.toList()));
requestParam.setIssueDateStart(issueDateStart);
requestParam.setIssueDateEnd(issueDateEnd);
requestParam.setDraftNbr(draftNbr);
requestParam.setBillNbr(billNbr);
requestParam.setBillAmountStart(billAmountStart);
requestParam.setBillAmountEnd(billAmountEnd);
requestParam.setSubBillIntervalStart(subBillIntervalStart);
requestParam.setSubBillIntervalEnd(subBillIntervalEnd);
requestParam.setBillStsList(billStsList==null ? null :Arrays.stream(billStsList.split(",")).collect(Collectors.toList()));
requestParam.setBillTrsStsList(billTrsStsList==null ? null :Arrays.stream(billTrsStsList.split(",")).collect(Collectors.toList()));
requestParam.setStockFlag(stockFlag);
requestParam.setOutInvType(outInvType);
requestParam.setLockFlag(lockFlag);
//查询前1000条数据
BillManagementClient bailManagementClient = new BillManagementClient();
GetDtaResponse response = bailManagementClient.dtaQuery(requestParam);
List<GetDtaResponse.Detail> list = response.getData().getList();
//判断是否还存在数据,递归查询
boolean hasNextPage = response.getData().isHasNextPage();
int nextPage = response.getData().getNextPage();
while (hasNextPage) {
requestParam.setCurrentPage(nextPage);
GetDtaResponse nextPageResponse = bailManagementClient.dtaQuery(requestParam);
List<GetDtaResponse.Detail> pageData = nextPageResponse.getData().getList();
list.addAll(pageData);
hasNextPage = nextPageResponse.getData().isHasNextPage();
nextPage = nextPageResponse.getData().getNextPage();
}
//加载cbs配置
XStream xStream = new XStream();
String resource = GCONST.getRootPath() + "WEB-INF" + File.separatorChar + "CBS2ECConfig.xml";
File file = new File(resource);
xStream.addPermission(AnyTypePermission.ANY);
xStream.processAnnotations(EBS2ECConfig.class);
EBS2ECConfig dto = (EBS2ECConfig) xStream.fromXML(file);
EBS2ECConfig.Table table = dto.getTables().get(2);
Integer modeId = table.getModeId();
String tableName = table.getKey();
//获取已存在的数据
EBS2ECConfig.Table.Field uniqueField = table.getFields().stream().filter(EBS2ECConfig.Table.Field::isUnique).findFirst().orElse(null);
if (uniqueField == null) {
throw new CBS8RunTimeException("未设置唯一标识字段");
}
String uniqueKey = uniqueField.getKey();
String uniqueEbsKey = uniqueField.getEbsKey();
List<String> uniqueDataKeys = getSQLMapper().listString(String.format("select %s from %s", uniqueKey, tableName));
for (GetDtaResponse.Detail detail : list) {
Map<String, String> detailMap = JsonUtil.parseMap(detail, String.class);
String uniqueData = detailMap.get(uniqueEbsKey);
if (StrUtil.isBlank(uniqueData)) {
log.warn("跳过cbs票据池数据唯一标识返回空,uniqueKey:{},uniqueEbsKey:{}", uniqueKey, uniqueEbsKey);
continue;
}
if (uniqueDataKeys.contains(uniqueData)) {
log.warn("跳过cbs票据池数据数据已存在,uniqueKey:{},uniqueEbsKey:{},值{}", uniqueKey, uniqueEbsKey, uniqueData);
continue;
}
List<String> fields = new ArrayList<String>() {{
add("formmodeid");
add("modedatacreater");
add("modedatacreatertype");
add("modedatacreatedate");
add("modedatacreatetime");
}};
String currDate = TimeUtil.getCurrentDateString();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String currTime = sdf.format(new Date());
List<Object> values = new ArrayList<Object>() {{
add(modeId);
add(1);
add(0);
add(String.format("'%s'", currDate));
add(String.format("'%s'", currTime));
}};
for (EBS2ECConfig.Table.Field field : table.getFields()) {
//数据库字段
String fieldName = field.getKey();
fields.add(fieldName);
// 接口值
String value = detailMap.getOrDefault(field.getEbsKey(), "");
values.add(String.format("'%s'", value));
}
//业务逻辑字段,收款类型
fields.add("pjlx");
//应付票据
Integer pjlx;
if ("ISS".equals(detail.getBillVariety())) {
pjlx = 2;
} else {
//应收票据 0银承 1商承
pjlx = "AC01".equals(detail.getBillType()) ? 0 : 1;
}
values.add(pjlx);
String sql = String.format("insert into %s (%s) values (%s)", tableName, String.join(",", fields), values.stream().map(Object::toString).collect(Collectors.joining(",")));
RecordSet rs = new RecordSet();
rs.execute(sql);
if (modeId != null) {
rs.executeQuery("select max(id) from " + tableName);
int mainId = 0;
if (rs.next()) {
mainId = rs.getInt(1);
}
ModeRightInfo ModeRightInfo = new ModeRightInfo();
ModeRightInfo.setNewRight(true);
ModeRightInfo.editModeDataShare(1, modeId, mainId);
}
}
} catch (Exception e) {
log.error("获取CBS票据池数据失败", e);
throw new CBS8RunTimeException("获取CBS票据池数据失败," + e.getMessage(), e);
}
}
}