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.mapper.cbs.UfHkrdzbMapper; import com.engine.salary.remote.cbs8.client.AccountManagementClient; import com.engine.salary.remote.cbs8.config.EBS2ECConfig; import com.engine.salary.remote.cbs8.po.DepartmentPO; import com.engine.salary.remote.cbs8.po.UfHkrdzbPO; import com.engine.salary.remote.cbs8.request.GetTransactionDetailRequest; import com.engine.salary.remote.cbs8.response.GetTransactionDetailResponse; import com.engine.salary.remote.cbs8.JsonUtil; import com.engine.salary.remote.cbs8.SalaryEntityUtil; 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.hrm.User; import weaver.interfaces.schedule.BaseCronJob; import java.io.File; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.*; import java.util.stream.Collectors; /** * 获取境内账户明细 *

Copyright: Copyright (c) 2024

*

Company: 泛微软件

* * @author qiantao * @version 1.0 **/ @Slf4j public class SyncCBSAccountDetailsJob extends BaseCronJob { /** * 开始日期 格式为yyyy-mm-dd */ private String startDate; /** * 结束日期 格式为yyyy-mm-dd */ private String endDate; /** * 借贷类型 1-借;2-贷 */ private String loanType; /** * 款项性质列表 */ private String paymentNatureList; /** * 日期类型 0-交易日期 */ private String dateType; /** * 账户列表 查询账户列表,不传默认返回全部 */ private String accountNoList; /** * 银行类型列表 例如招行CMB,银行类型枚举见附录4.1.5 */ private String bankTypeList; /** * 币种列表 见附录币种枚举,4.1.1 */ private String currencyList; /** * 明细来源 * B:银行,即银行直联 * U:用户,即手工/ERP接口导入 * 不传默认查全部 */ private String detailedSources; /** * 明细类型 1-当日明细 2-历史明细 与明细日期无关,仅标识数据来源银行的不同接口 */ private String currentFlag; /** * 账户性质列表 客户在公共设置>基础信息>账户性质查询自定义内容,例如AA-综合户,此处传值“AA” */ private String accountNatureList; /** * 银行流水号 银行流水号 */ private String bankSerialNumber; /** * 交易流水号 交易流水号,由CBS8定义生成的唯一标识 */ private Long transactionSerialNumber; /** * 单位编码列表 客户在公共设置>基础信息>组织机构维护,例如0001-XX科技有限公司,此处传0001 */ private String unitCodeList; /** * ERP业务参考号 erpSerialNumber */ private String erpSerialNumber; private SQLMapper getSQLMapper() { return MapperProxyFactory.getProxy(SQLMapper.class); } private UfHkrdzbMapper getUfHkrdzbMapper() { return MapperProxyFactory.getProxy(UfHkrdzbMapper.class); } @Override public void execute() { User user = new User(); user.setUid(1); user.setLoginid("sysadmin"); try { GetTransactionDetailRequest requestParam = new GetTransactionDetailRequest(); requestParam.setCurrentPage(1); requestParam.setPageSize(1000); if (StrUtil.isNotBlank(startDate) && StrUtil.isNotBlank(endDate)) { requestParam.setStartDate(startDate); requestParam.setEndDate(endDate); } else { String nowDate = LocalDate.now().toString(); requestParam.setStartDate(nowDate); requestParam.setEndDate(nowDate); } requestParam.setLoanType(loanType); requestParam.setPaymentNatureList(paymentNatureList == null ? null : Arrays.stream(paymentNatureList.split(",")).collect(Collectors.toList())); requestParam.setDateType(dateType); requestParam.setAccountNoList(accountNoList == null ? null : Arrays.stream(accountNoList.split(",")).collect(Collectors.toList())); requestParam.setBankTypeList(bankTypeList == null ? null : Arrays.stream(bankTypeList.split(",")).collect(Collectors.toList())); requestParam.setCurrencyList(currencyList == null ? null : Arrays.stream(currencyList.split(",")).collect(Collectors.toList())); requestParam.setDetailedSources(detailedSources); requestParam.setCurrentFlag(currentFlag); requestParam.setAccountNatureList(accountNatureList == null ? null : Arrays.stream(accountNatureList.split(",")).collect(Collectors.toList())); requestParam.setBankSerialNumber(bankSerialNumber); requestParam.setTransactionSerialNumber(transactionSerialNumber); requestParam.setUnitCodeList(unitCodeList == null ? null : Arrays.stream(unitCodeList.split(",")).collect(Collectors.toList())); requestParam.setErpSerialNumber(erpSerialNumber); //查询前1000条数据 AccountManagementClient accountManagementClient = new AccountManagementClient(); GetTransactionDetailResponse response = accountManagementClient.transactionDetailQuery(requestParam); List list = response.getData().getList(); //判断是否还存在数据,递归查询 boolean hasNextPage = response.getData().isHasNextPage(); int nextPage = response.getData().getNextPage(); while (hasNextPage) { requestParam.setCurrentPage(nextPage); GetTransactionDetailResponse nextPageResponse = accountManagementClient.transactionDetailQuery(requestParam); List 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(0); 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 uniqueDataKeys = getSQLMapper().listString(String.format("select %s from %s", uniqueKey, tableName)); //获取汇款人与办事处的对照数据 List ufHkrdzbPOS = getUfHkrdzbMapper().listAll(); Map customerDepartmentMap = SalaryEntityUtil.convert2Map(ufHkrdzbPOS, UfHkrdzbPO::getKhmc); List departmentPOS = getUfHkrdzbMapper().listDepartment(); Map departmentMap = SalaryEntityUtil.convert2Map(departmentPOS, DepartmentPO::getCode, DepartmentPO::getId); for (GetTransactionDetailResponse.Detail detail : list) { Map 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 fields = new ArrayList() {{ //建模默认字段 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 values = new ArrayList() {{ add(modeId); add(1); add(0); add(String.format("'%s'", currDate)); add(String.format("'%s'", currTime)); }}; String hkr = ""; 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)); //汇款人 if ("hkr".equals(fieldName)) { hkr = value; } } //业务逻辑字段,收款类型,默认是银行存款 fields.add("sklx"); values.add(0); /* * 认领逻辑, * 如果币种不是人名币,认领部门是国际部 * 根据汇款人去表里匹配【汇款人与办事处的对照表】 * 如果能匹配到数据,则状态改为已自动认领,同时把办事处(部门)的值同步到办事处字段中,是否系统自动认领同步为是; * 如对照标准无数据,则状态为:未认领; */ UfHkrdzbPO ufHkrdzbPO = customerDepartmentMap.get(hkr); //币种不是人名币,国际部认领 String currency = detailMap.get("currency"); if (!"10".equals(currency)) { //认领 fields.add("zt"); values.add(1); //是否系统认领 fields.add("sfxtzdrl"); values.add(1); //办事处 fields.add("szbm"); values.add(String.format("'%s'", "1412")); if (ufHkrdzbPO != null && ufHkrdzbPO.getKhsx() != null) { //客户属性 fields.add("khsx"); values.add(ufHkrdzbPO.getKhsx()); } } else if (ufHkrdzbPO != null) { //客户属性 Integer khsx = ufHkrdzbPO.getKhsx(); if (khsx != null) { fields.add("khsx"); values.add(khsx); } String bmbms = ufHkrdzbPO.getBmbm(); if (StrUtil.isNotEmpty(bmbms)) { //认领 fields.add("zt"); values.add(1); //是否系统认领 fields.add("sfxtzdrl"); values.add(1); //办事处 fields.add("szbm"); List bmbmList = Arrays.stream(bmbms.split(",")).map(departmentMap::get).filter(StrUtil::isNotBlank).collect(Collectors.toList()); values.add(String.format("'%s'", String.join(",", bmbmList))); } else { //未认领 fields.add("zt"); values.add(0); } } else { //未认领 fields.add("zt"); values.add(0); } 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); } } }