|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package com.qtzl.alterSales.manager.service;
-
- import cn.com.taiji.common.manager.net.http.ServiceHandleException;
- import cn.hutool.core.bean.BeanUtil;
- import com.qtzl.alterSales.dao.entity.primary.FssPaccountPay;
- import com.qtzl.alterSales.dao.entity.second.AflPaccountRefundCount;
- import com.qtzl.alterSales.dao.repo.jpa.primary.FssPaccountPayRepo;
- import com.qtzl.alterSales.dao.repo.jpa.second.AflPaccountRefundCountRepo;
- import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
- import com.qtzl.alterSales.manager.model.protocol.sales.AflPaccountRefundCountFindPageRequest;
- import com.qtzl.alterSales.manager.model.protocol.sales.AflPaccountRefundCountFindPageViewRequest;
- import com.qtzl.alterSales.manager.service.third.ConstantConfig;
- import com.qtzl.alterSales.manager.service.third.FmsService;
- import com.qtzl.alterSales.manager.tools.ExcelUtils;
- import com.qtzl.alterSales.manager.vo.AflPaccountRefundCountVo;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
-
- import javax.annotation.Resource;
- import java.io.File;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.List;
-
- @Service
- public class AflPaccountRefundCountServiceImpl implements AflPaccountRefundCountService{
- private static final Logger log = LoggerFactory.getLogger(AflPaccountRefundCountServiceImpl.class);
-
-
- @Resource
- AflPaccountRefundCountRepo aflPaccountRefundCountRepo;
- @Resource
- FssPaccountPayRepo fssPaccountPayRepo;
- @Resource
- FmsService fmsService;
- @Resource
- ConstantConfig constantConfig;
- @Override
- public String export(AflPaccountRefundCountFindPageViewRequest request, Logger logger) throws ServiceHandleException {
- String pathFile =null;
- try {
- AflPaccountRefundCountFindPageRequest queryRequest = new AflPaccountRefundCountFindPageRequest();
- BeanUtil.copyProperties(request, queryRequest);
- List<AflPaccountRefundCountVo> aflPaccountRefundCountVos = aflPaccountRefundCountRepo.list(queryRequest);
- if (aflPaccountRefundCountVos==null||aflPaccountRefundCountVos.size()==0) {
- pathFile = ExcelUtils.export(null, "部中心请款流水统计",constantConfig.getFilePath() ,null, AflPaccountRefundCountVo.class);
- } else {
- logger.info("选装-部中心请款流水统计导出我进来了");
- pathFile = ExcelUtils.export(null, "部中心请款流水统计",constantConfig.getFilePath(), aflPaccountRefundCountVos, AflPaccountRefundCountVo.class);
-
- }
- if (StringUtils.isEmpty(pathFile)){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("部中心请款流水统计导出失败");
- }
- String s = null;
- try {
- s = fmsService.uploadFile(constantConfig.getUploadFile(),pathFile, 90000);
- } catch (ServiceHandleException e) {
- logger.error("选装-部中心请款流水统计导出失败:{}", e.getMessage());
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(e.getMessage());
- }
-
- if (StringUtils.isEmpty(s)){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("部中心请款流水统计导出失败");
- }
- return s;
- } catch (Exception e) {
- if (e instanceof ServiceHandleException) {
- throw e;
- }
- logger.error("选装-部中心请款流水统计导出失败:{}", e.getMessage());
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("部中心请款流水统计导出失败");
- }finally {
- File file = null;
- try {
- file = new File(pathFile);
- } catch (Exception e) {
-
- }
- if (file!=null){
- file.delete();
- }
- }
- }
-
- @Override
- public void saveFind(String payId) {
- log.error("请求查询流水信息请求参数,payId={}",payId);
- if (StringUtils.isEmpty(payId)){
- log.error("请求查询流水信息请求参数为空");
- return;
- }
- FssPaccountPay fssPaccountPay = fssPaccountPayRepo.findByPayId(payId);
- if (fssPaccountPay==null){
- log.error("未查询到流水信息,payId ={}",payId);
- return;
- }
- if (fssPaccountPay.getStatus()==null ||fssPaccountPay.getStatus().equals(1)){
- log.error("查询到流水信息状态为已补缴或状态为空,payId ={},status={}",payId,fssPaccountPay.getStatus());
- return;
- }
- if (StringUtils.isEmpty(fssPaccountPay.getAgentId())||fssPaccountPay.getInserttime()==null||fssPaccountPay.getReceiptAmt()==null){
- log.error("查询到流水信息渠道id不存在或者插入时间为空或金额为空,payId ={}",payId);
- return;
- }
- String format =null;
- try {
- format = DateTimeFormatter.ofPattern("yyyyMMdd").format(fssPaccountPay.getInserttime());
- } catch (Exception e) {
- log.error("查询到流水信息插入时间转换有误,payId ={}",payId);
- return;
- }
- if (StringUtils.isEmpty(format)){
- log.error("查询到流水信息时间日期为空,payId ={}",payId);
- return;
- }
-
- AflPaccountRefundCount aflPaccountRefundCount = null;
- try {
- if ("52010188999".equals(fssPaccountPay.getAgentId())){
- fssPaccountPay.setAgentId("52010188930");
- }
- aflPaccountRefundCount = aflPaccountRefundCountRepo.finByDateAndAgentId(fssPaccountPay.getAgentId(),Integer.parseInt(format));
- } catch (NumberFormatException e) {
- log.error("格式转换有误,AgentId ={},accountDate={}",fssPaccountPay.getAgentId(),format);
- }
- if (aflPaccountRefundCount==null){
- log.error("未查询到部中心原始流水统计信息,AgentId ={},accountDate={}",fssPaccountPay.getAgentId(),format);
- return;
- }
- Long collectMoney =0l;
- if (aflPaccountRefundCount.getCollectMoney()!=null){
- collectMoney = aflPaccountRefundCount.getCollectMoney();
- }
- // Long collectMoney = aflPaccountRefundCount.getCollectMoney();
- log.info("查询到流水统计信息已收取金额为,collectMoney ={}",collectMoney);
- log.info("查询到流水信息扣款金额为,receiptAmt ={}",fssPaccountPay.getReceiptAmt());
- Long newCollectMoney=collectMoney;
- if (fssPaccountPay.getReceiptAmt()!=null){
- newCollectMoney = collectMoney + fssPaccountPay.getReceiptAmt();
- }
- log.info("查询到流水统计信息最新已收取金额为,newCollectMoney ={}",newCollectMoney);
- aflPaccountRefundCount.setCollectMoney(newCollectMoney);
- aflPaccountRefundCount.setUpdateTime(LocalDateTime.now());
- aflPaccountRefundCountRepo.save(aflPaccountRefundCount);
- }
- }
|