diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/AgentPayResultPluginInitializer.java b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/AgentPayResultPluginInitializer.java index ac1c5224..118e47b4 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/AgentPayResultPluginInitializer.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/AgentPayResultPluginInitializer.java @@ -1,8 +1,10 @@ package com.hzya.frame.plugin.cbs8.plugin; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.hzya.frame.base.PluginBaseEntity; import com.hzya.frame.cbs8.dto.req.AgentPayResultRequestDTO; +import com.hzya.frame.cbs8.dto.res.AgentPayQueryDTO; import com.hzya.frame.cbs8.dto.res.AgentPayResultResDTO; import com.hzya.frame.plugin.cbs8.service.ICbsPluginService; import com.hzya.frame.web.entity.JsonResultEntity; @@ -11,6 +13,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; + /** * @Description * @Author xiangerlin @@ -102,9 +106,8 @@ public class AgentPayResultPluginInitializer extends PluginBaseEntity { //1、查询代发代扣交易未完成代 //2、调用cbs接口 AgentPayResultRequestDTO agentPayResultRequestDTO = new AgentPayResultRequestDTO(); - agentPayResultRequestDTO.setBusNum(""); + agentPayResultRequestDTO.setBusNum("PA00034224062600011"); AgentPayResultResDTO agentPayResultResDTO = cbsPluginService.agentPayResult(agentPayResultRequestDTO); - //更新OA表单 //记录日志 return null; } diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/PayApplyAgentPluginInitializer.java b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/PayApplyAgentPluginInitializer.java index 3866684d..9c90a865 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/PayApplyAgentPluginInitializer.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/PayApplyAgentPluginInitializer.java @@ -109,20 +109,8 @@ public class PayApplyAgentPluginInitializer extends PluginBaseEntity { public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception { //1、查询代支付的 AgentPaymentEntity agentPaymentEntity = new AgentPaymentEntity(); - List agentPaymentList = agentPaymentService.queryUnpaid(agentPaymentEntity); - if (CollectionUtils.isNotEmpty(agentPaymentList)){ - for (AgentPaymentEntity paymentEntity : agentPaymentList) { - AgentPaymentDetailEntity detailEntity = new AgentPaymentDetailEntity(); - detailEntity.setFormmainId(paymentEntity.getId()); - List agentPaymentDetailList = agentPaymentService.queryDetails(detailEntity); - if (CollectionUtils.isNotEmpty(agentPaymentDetailList)){ - //调用代发代扣接口 - PayResponseDTO payResponseDTO = cbsPluginService.applyAgentPay(paymentEntity, agentPaymentDetailList); - //更新OA表单 - //记录日志 - } - } - } + agentPaymentEntity.setOaId("4442823497745714629"); + cbsPluginService.applyAgentPay(agentPaymentEntity); return null; } } diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/PayApplyPluginInitializer.java b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/PayApplyPluginInitializer.java index 83886054..36baa131 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/PayApplyPluginInitializer.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/plugin/PayApplyPluginInitializer.java @@ -105,7 +105,7 @@ public class PayApplyPluginInitializer extends PluginBaseEntity { if (null == paymentEntity) paymentEntity = new PaymentEntity(); //支付申请 - paymentEntity.setOaId("5490849762671477371"); + paymentEntity.setOaId("8475071606892874568"); cbsPluginService.applyPay(paymentEntity); return null; } diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/service/ICbsPluginService.java b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/service/ICbsPluginService.java index 8fc1f712..dd07a04b 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/service/ICbsPluginService.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/service/ICbsPluginService.java @@ -57,9 +57,8 @@ public interface ICbsPluginService { /** * 代发代扣 支付申请 * @param paymentEntity - * @param agentPaymentDetailList */ - PayResponseDTO applyAgentPay(AgentPaymentEntity paymentEntity, List agentPaymentDetailList); + void applyAgentPay(AgentPaymentEntity paymentEntity); /** * 代发代扣 结果详情查询 diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/service/impl/CbsPluginServiceImpl.java b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/service/impl/CbsPluginServiceImpl.java index cdf26b9e..f560a661 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/service/impl/CbsPluginServiceImpl.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/cbs8/service/impl/CbsPluginServiceImpl.java @@ -5,22 +5,23 @@ import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.map.MapBuilder; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.hzya.frame.cbs8.dto.req.*; import com.hzya.frame.cbs8.dto.res.*; import com.hzya.frame.cbs8.service.ICbs8Service; import com.hzya.frame.cbs8.util.CBSUtil; +import com.hzya.frame.cbs8.util.CurrencyEnum; import com.hzya.frame.cbs8.util.PayState; import com.hzya.frame.plugin.cbs8.service.ICbsPluginService; import com.hzya.frame.seeyon.cap4.form.dto.*; import com.hzya.frame.seeyon.cbs8.entity.*; -import com.hzya.frame.seeyon.cbs8.service.ICbsLogService; -import com.hzya.frame.seeyon.cbs8.service.IPaymentService; -import com.hzya.frame.seeyon.cbs8.service.ITransactionDetailService; +import com.hzya.frame.seeyon.cbs8.service.*; import com.hzya.frame.seeyon.entity.CtpAttachmentEntity; import com.hzya.frame.seeyon.entity.CtpFileEntity; import com.hzya.frame.seeyon.service.ICtpAttachmentService; @@ -38,6 +39,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @Description @@ -57,6 +59,10 @@ public class CbsPluginServiceImpl implements ICbsPluginService { private ICtpAttachmentService ctpAttachmentService; @Autowired private ITransactionDetailService transactionDetailService; + @Autowired + private IAgentPaymentService agentPaymentService; + @Autowired + private IAgentPaymentDetailService agentPaymentDetailService; @Autowired private RestUtil restUtil; @@ -104,6 +110,7 @@ public class CbsPluginServiceImpl implements ICbsPluginService { } //4、更新OA表单 pay.setDataSourceCode(oa_data_source_code); + pay.setApplyCode(payResponseDTO.getBusNum()); paymentService.updatePayState(pay); //5、记录操作日志 savePayLog(pay,payResponseDTO); @@ -174,6 +181,7 @@ public class CbsPluginServiceImpl implements ICbsPluginService { //如果支付状态为空,保存支付申请状态,如果支付状态不为空,则保存支付状态 PaymentEntity paymentEntity = new PaymentEntity(); paymentEntity.setOaId(entity.getOa_id()); + paymentEntity.setApplyCode(entity.getCbs_apply_code()); paymentEntity.setDataSourceCode(oa_data_source_code); List paymentList = paymentService.query(paymentEntity); if (CollectionUtils.isNotEmpty(paymentList)){ @@ -300,21 +308,53 @@ public class CbsPluginServiceImpl implements ICbsPluginService { * 代发代扣 支付申请 * * @param paymentEntity - * @param agentPaymentDetailList + */ @Override - public PayResponseDTO applyAgentPay(AgentPaymentEntity paymentEntity, List agentPaymentDetailList) { - if (null != paymentEntity && CollectionUtils.isNotEmpty(agentPaymentDetailList)){ - PaymentApplySubmitReqDTO paymentApplySubmitReqDTO = BeanUtil.copyProperties(paymentEntity,PaymentApplySubmitReqDTO.class); - List paymentApplyAgentList = new ArrayList<>(); - for (AgentPaymentDetailEntity detailEntity : agentPaymentDetailList) { - PaymentApplyAgentDTO detailDTO = BeanUtil.copyProperties(detailEntity,PaymentApplyAgentDTO.class); - paymentApplyAgentList.add(detailDTO); + public void applyAgentPay(AgentPaymentEntity paymentEntity) { + try { + if (null != paymentEntity ){ + paymentEntity.setDataSourceCode(oa_data_source_code); + List agentPaymentList = agentPaymentService.queryUnpaid(paymentEntity); + if (CollectionUtils.isNotEmpty(agentPaymentList)){ + for (AgentPaymentEntity agentPay : agentPaymentList) { + AgentPaymentDetailEntity detailEntity = new AgentPaymentDetailEntity(); + detailEntity.setFormmainId(agentPay.getOaId()); + detailEntity.setDataSourceCode(oa_data_source_code); + List agentPaymentDetailList = agentPaymentService.queryDetails(detailEntity); + if (CollectionUtils.isNotEmpty(agentPaymentDetailList)){ + PaymentApplySubmitReqDTO paymentApplySubmitReqDTO = BeanUtil.copyProperties(agentPay,PaymentApplySubmitReqDTO.class); + List paymentApplyAgentList = new ArrayList<>(); + for (AgentPaymentDetailEntity detail : agentPaymentDetailList) { + PaymentApplyAgentDTO detailDTO = BeanUtil.copyProperties(detail,PaymentApplyAgentDTO.class); + paymentApplyAgentList.add(detailDTO); + } + //招行这里要传203 + paymentApplySubmitReqDTO.setBankExtend5("203"); + PayResponseDTO payResponseDTO = cbs8Service.agentPayApply(paymentApplySubmitReqDTO,paymentApplyAgentList); + if (null != payResponseDTO){ + Boolean successed = payResponseDTO.getSuccessed(); + AgentPaymentEntity pay = new AgentPaymentEntity(); + pay.setOaId(paymentEntity.getOaId()); + pay.setDataSourceCode(oa_data_source_code); + if (successed){ + //更新申请单号到OA + pay.setApplyCode(payResponseDTO.getBusNum()); + pay.setPayResult("审批中"); + }else { + pay.setPayResult(payResponseDTO.getErrorMsg()); + } + agentPaymentService.updateResult(pay); + System.out.println(JSONObject.toJSONString(payResponseDTO)); + } + } + } + } + }else { + throw new BaseSystemException("参数不能为空"); } - PayResponseDTO payResponseDTO = cbs8Service.agentPayApply(paymentApplySubmitReqDTO,paymentApplyAgentList); - return payResponseDTO; - }else { - throw new BaseSystemException("参数不能为空"); + }catch (Exception e){ + logger.error("代发代扣出错:{}",e); } } @@ -326,9 +366,49 @@ public class CbsPluginServiceImpl implements ICbsPluginService { */ @Override public AgentPayResultResDTO agentPayResult(AgentPayResultRequestDTO agentPayResultRequestDTO) { - if (null != agentPayResultRequestDTO && StrUtil.isNotEmpty(agentPayResultRequestDTO.getBusNum())){ - AgentPayResultResDTO agentPayResultResDTO = cbs8Service.agentPayResult(agentPayResultRequestDTO); - return agentPayResultResDTO; + try { + if (null != agentPayResultRequestDTO && StrUtil.isNotEmpty(agentPayResultRequestDTO.getBusNum())){ + AgentPayResultResDTO agentPayResultResDTO = cbs8Service.agentPayResult(agentPayResultRequestDTO); + //更新OA表单 + String busNum = agentPayResultResDTO.getBusNum(); + if (StringUtils.isNotEmpty(busNum)){ + AgentPaymentEntity agentPaymentEntity = new AgentPaymentEntity(); + agentPaymentEntity.setApplyCode(busNum); + agentPaymentEntity.setDataSourceCode(oa_data_source_code); + AgentPaymentEntity entity = agentPaymentService.queryByApplyCode(agentPaymentEntity); + String pay_status = agentPayResultResDTO.getPayStatus(); + String status = agentPayResultResDTO.getStatus(); + if (null != entity){ + AgentPaymentEntity result = new AgentPaymentEntity(); + result.setOaId(entity.getOaId()); + result.setDataSourceCode(oa_data_source_code); + //更新主表 + if (StrUtil.isEmpty(pay_status)) { + result.setPayResult(PayState.payStateGetValue(status));//支付申请状态 支付状态和支付申请状态用一个 + } else { + result.setPayResult(PayState.payStateGetValue(pay_status));//支付状态 支付状态和支付申请状态用一个 + } + agentPaymentService.updateResult(result); + //更新明细表 + List agentDetails = agentPayResultResDTO.getAgentDetails(); + for (AgentPayQueryDTO d : agentDetails) { + AgentPaymentDetailEntity detail = new AgentPaymentDetailEntity(); + detail.setFormmainId(entity.getOaId()); + detail.setDtlAmount(d.getDtlAmount()); + detail.setDtlCnapsCode(d.getDtlCnapsCode()); + detail.setDtlRevName(d.getDtlRevName()); + detail.setDtlSeqNum(Integer.valueOf(d.getDtlSeqNum())); + detail.setPayResult(PayState.payStateGetValue(d.getDtlStatus())); + detail.setPayDate(CBSUtil.convertTimestampToString(d.getDtlPayTime())); + detail.setDataSourceCode(oa_data_source_code); + agentPaymentDetailService.updatePayResult(detail); + } + } + } + return agentPayResultResDTO; + } + }catch (Exception e){ + logger.error("代发代扣详情结果查询出错{}",e); } return null; } @@ -336,16 +416,38 @@ public class CbsPluginServiceImpl implements ICbsPluginService { /** * 保存交易明细到OA底表 * - * @param transactionDetailList + * @param transactionlList */ @Override - public void saveTransactionDetail(List transactionDetailList) { - if (CollectionUtils.isNotEmpty(transactionDetailList)){ + public void saveTransactionDetail(List transactionlList) { + if (CollectionUtils.isNotEmpty(transactionlList)){ //过滤已经保存过的数据 - for (TransactionDetailDTO dto : transactionDetailList) { - TransactionDetailEntity transactionDetail = new TransactionDetailEntity(); - BeanUtil.copyProperties(dto,transactionDetail); - transactionDetailService.restSave(transactionDetail); + //收款档案表的数据 + TransactionDetailEntity transactionDetailEntity = new TransactionDetailEntity(); + transactionDetailEntity.setBankTransactionDate(DateUtil.lastWeek().toDateStr()); + transactionDetailEntity.setDataSourceCode(oa_data_source_code); + List transactionDetailList = transactionDetailService.querySerialNumber(transactionDetailEntity); + //过滤已经保存的数据 + if (CollectionUtils.isNotEmpty(transactionDetailList)){ + //过滤transactionlList 去除已经存在transactionDetailList中的数据,条件为transactionSerialNumber相等 + if (CollectionUtils.isNotEmpty(transactionlList)){ + transactionlList = transactionlList.stream() + .filter(item -> transactionDetailList.stream() + .noneMatch(detailItem -> item.getTransactionSerialNumber().equals(detailItem.getTransactionSerialNumber()))) + .collect(Collectors.toList()); + } + } + if (CollectionUtils.isNotEmpty(transactionlList)){ + //保存到OA底表 + for (TransactionDetailDTO dto : transactionlList) { + TransactionDetailEntity transactionDetail = new TransactionDetailEntity(); + BeanUtil.copyProperties(dto,transactionDetail); + transactionDetail.setCurrency(CurrencyEnum.getChineseNameByCode(dto.getCurrency())); + if (NumberUtil.isNumber(dto.getBankTransactionDate())){//如果是时间戳 转换成日期字符串 + transactionDetail.setBankTransactionDate(CBSUtil.convertTimestampToString(dto.getBankTransactionDate())); + } + transactionDetailService.restSave(transactionDetail); + } } } }