package cn.superdesk.uniorder.controller._thirdpart.szhtxx.electronicInvoice;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import cn.hutool.extra.mail.MailUtil;
import cn.hutool.json.JSONUtil;
import cn.superdesk.uniorder.common.constants.ResponseMsgConstants;
import cn.superdesk.uniorder.common.enums.common.CommonFormStateEnum;
import cn.superdesk.uniorder.common.enums.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxSentEmailStatusEnum;
import cn.superdesk.uniorder.common.enums.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceResponseCodeEnum;
import cn.superdesk.uniorder.common.excel.ExcelResponse;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import cn.superdesk.uniorder.common.numerical.AnBigDecimalUtils;
import cn.superdesk.uniorder.common.numerical.AnStringUtils;
import cn.superdesk.uniorder.common.rest.response.AnResponseStreamUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.rest.response.ResponseResultOuterUtils;
import cn.superdesk.uniorder.config.mail.MailAccountConfigFactory;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.invoice.customer.InvoiceApply;
import cn.superdesk.uniorder.dao.entity.sys.notify.SysNotify;
import cn.superdesk.uniorder.dao.entity.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxx;
import cn.superdesk.uniorder.dao.entity.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxExtendInfo;
import cn.superdesk.uniorder.dto._constant.ResourceConstant;
import cn.superdesk.uniorder.dto._constant.ResourceStruct;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.common.singleBilling.SzhtxxInvoiceFptxxOpSingleBillingForm;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.electronicInvoice.*;
import cn.superdesk.uniorder.dto.vo.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxDetailVo;
import cn.superdesk.uniorder.dto.vo.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxHeadDataVo;
import cn.superdesk.uniorder.dto.vo.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxListItemVo;
import cn.superdesk.uniorder.dto.vo.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxOpRedWriteVo;
import cn.superdesk.uniorder.dubbo.consumer._common.ProviderEnvConstantDubboCustomerService;
import cn.superdesk.uniorder.dubbo.consumer.invoice.customer.InvoiceApplyCustomerDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxExtendInfoDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxResultDubboConsumerService;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.electronicInvoice.dto.request.SingleBillingRequestBodyKpContent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * @Description: 第三方-深圳航信电子票
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2022-01-24 11:50:43
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022-01-24 11:50:43
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "第三方-深圳航天信息有限公司-电子发票-发票主体", tags = {"第三方-深圳航天信息有限公司-电子发票-发票主体"})
@Slf4j
@RestController
@RequestMapping("/thirdpart/szhtxx/electronicInvoiceFptxx")
public class SzhtxxElectronicInvoiceFptxxController extends BaseController {

    @Autowired
    private SzhtxxElectronicInvoiceFptxxDubboConsumerService           szhtxxElectronicInvoiceFptxxDubboConsumerService;
    @Autowired
    private SzhtxxElectronicInvoiceFptxxResultDubboConsumerService     szhtxxElectronicInvoiceFptxxResultDubboConsumerService;
    @Autowired
    private SzhtxxElectronicInvoiceFptxxExtendInfoDubboConsumerService szhtxxElectronicInvoiceFptxxExtendInfoDubboConsumerService;

    @Autowired
    private InvoiceApplyCustomerDubboConsumerService invoiceApplyCustomerDubboConsumerService;

    @Autowired
    private MailAccountConfigFactory mailAccountConfigFactory;
    @Autowired
    private TemplateEngine           templateEngine;

    @Resource
    private ProviderEnvConstantDubboCustomerService providerEnvConstantDubboCustomerService;

//	@ApiOperation(value = "分页查询 - 默认不用")
//	@RequestMapping(value = "listByObscure", method = RequestMethod.POST)
//	@ResponseBody
//	public R<List<SzhtxxElectronicInvoiceFptxx>> pageQuerySzhtxxElectronicInvoiceFptxx(@RequestBody PageQueryParam param) {
//
//		log.info("pageQuerySzhtxxElectronicInvoiceFptxx:\n{}", JSONUtil.toJsonStr(param));
//
//		R<List<SzhtxxElectronicInvoiceFptxx>> result = new R<>();
//
//		// TODO 参数合法性判定
//
//		result = szhtxxElectronicInvoiceFptxxDubboConsumerService.pageQuery(param.getConditions(), param.getPageNo(), param.getPageSize());
//
//		return result;
//	}

    @ApiOperation(value = "op页头统计")
    @RequestMapping(value = "head", method = RequestMethod.POST)
    @ResponseBody
    public R<SzhtxxElectronicInvoiceFptxxHeadDataVo> headDataGenericParamSzhtxxElectronicInvoiceFptxx(@RequestBody SzhtxxElectronicInvoiceFptxxQueryCriteria queryCriteria) {

        log.info("pageQuerySzhtxxElectronicInvoiceFptxx:\n{}", JSONUtil.toJsonStr(queryCriteria));

        // TODO 参数合法性判定

        SzhtxxElectronicInvoiceFptxxHeadDataVo dataVo = szhtxxElectronicInvoiceFptxxDubboConsumerService.headDataGenericParam(queryCriteria, getToken());

        return ResponseResultOuterUtils.createSuccesResult("", dataVo);
    }

    @ApiOperation(value = "op列表分页")
    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ResponseBody
    public R<List<SzhtxxElectronicInvoiceFptxxListItemVo>> pageQueryGenericParamSzhtxxElectronicInvoiceFptxx(
            @RequestBody SzhtxxElectronicInvoiceFptxxQueryCriteria queryCriteria) {

        log.info("pageQuerySzhtxxElectronicInvoiceFptxx:\n{}", JSONUtil.toJsonStr(queryCriteria));

        R<List<SzhtxxElectronicInvoiceFptxxListItemVo>> result = new R<>();

        // TODO 参数合法性判定

        result = szhtxxElectronicInvoiceFptxxDubboConsumerService.pageQueryGenericParam(queryCriteria, getToken());

        return result;
    }

    @ApiOperation(value = "op导出报表(列表)", notes = "积分结算2.1")
    @RequestMapping(value = "/exportExcelSzhtxxElectronicInvoiceFptxxList", method = RequestMethod.POST)
    public R<String> exportExcelSzhtxxElectronicInvoiceFptxxList(
            @RequestBody SzhtxxElectronicInvoiceFptxxQueryCriteria queryCriteria) {


        //【【结算中心-测试环境】积分结算-金税盘发票-【导出列表】Excel数据的排序需按发票的创建时间“升序”依次排列显示】
        // https://www.tapd.cn/33003868/bugtrace/bugs/view?bug_id=1133003868001005577
        queryCriteria.setOrderByClause("szhteif.create_time asc");

        log.info("pageQuerySzhtxxElectronicInvoiceFptxx:\n{}", JSONUtil.toJsonStr(queryCriteria));

        return new R<String>(szhtxxElectronicInvoiceFptxxDubboConsumerService
                .exportExcelSzhtxxElectronicInvoiceFptxxList(
                        queryCriteria,
                        getToken()
                ));

    }

    /**
     * @param queryCriteria
     * @return
     * @url /thirdpart/szhtxx/electronicInvoiceFptxx/exportExcelSzhtxxElectronicInvoiceDetail
     */
    @ApiOperation(value = "op导出发票数据", notes = "积分结算2.1")
    @RequestMapping(value = "/exportExcelSzhtxxElectronicInvoiceDetail", method = RequestMethod.POST)
    public R<String> exportExcelSzhtxxElectronicInvoiceDetail(@RequestBody SzhtxxElectronicInvoiceFptxxQueryCriteria queryCriteria) {

        log.info("pageQuerySzhtxxElectronicInvoiceFptxx:\n{}", JSONUtil.toJsonStr(queryCriteria));

        return new R<String>(szhtxxElectronicInvoiceFptxxDubboConsumerService.exportExcelSzhtxxElectronicInvoiceDetail(queryCriteria, getToken()));

    }

    /**
     * @param queryCriteria
     * @return
     * @url http://192.168.6.223:8089/web/thirdpart/szhtxx/electronicInvoiceFptxx/detail
     */
    @ApiOperation(value = "op详情")
    @RequestMapping(value = "detail", method = RequestMethod.POST)
    @ResponseBody
    public R<SzhtxxElectronicInvoiceFptxxDetailVo> detailGenericParamSzhtxxElectronicInvoiceFptxx(@RequestBody SzhtxxElectronicInvoiceFptxxQueryCriteria queryCriteria) {

        log.info("pageQuerySzhtxxElectronicInvoiceFptxx:\n{}", JSONUtil.toJsonStr(queryCriteria));


        // TODO 参数合法性判定

        SzhtxxElectronicInvoiceFptxxDetailVo detailVo = szhtxxElectronicInvoiceFptxxDubboConsumerService.detailGenericParamSzhtxxElectronicInvoiceFptxx(queryCriteria, getToken());

        return ResponseResultOuterUtils.createSuccesResult("", detailVo);
    }


    @ApiOperation(value = "op按id查询")
    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    @ResponseBody
    public R<List<SzhtxxElectronicInvoiceFptxx>> getById(@PathVariable("id") long id) {

        R<List<SzhtxxElectronicInvoiceFptxx>> result = new R<>();

        // TODO 参数合法性判定

        SzhtxxElectronicInvoiceFptxx entity = szhtxxElectronicInvoiceFptxxDubboConsumerService.findSzhtxxElectronicInvoiceFptxxById(id);

        List<SzhtxxElectronicInvoiceFptxx> data = new ArrayList<>();
        data.add(entity);

        result.setData(data);

        return result;
    }

    @ApiOperation(value = "op新增")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    @ResponseBody
    public R<String> addSzhtxxElectronicInvoiceFptxx(@RequestBody SzhtxxElectronicInvoiceFptxxParam param) {

        log.info("addSzhtxxElectronicInvoiceFptxx:\n{}", JSONUtil.toJsonStr(param));


        // TODO 参数合法性判定

        szhtxxElectronicInvoiceFptxxDubboConsumerService.addSzhtxxElectronicInvoiceFptxx(param);

        return new R<>("200", "操作成功", true);
    }

    @ApiOperation(value = "op更新")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public R<String> updateSzhtxxElectronicInvoiceFptxx(@RequestBody SzhtxxElectronicInvoiceFptxxParam param) {

        log.info("updateSzhtxxElectronicInvoiceFptxx:\n{}", JSONUtil.toJsonStr(param));

        szhtxxElectronicInvoiceFptxxDubboConsumerService.updateSzhtxxElectronicInvoiceFptxx(param);

        return new R<>("200", "操作成功", true);
    }

    @ApiOperation(value = "op删除")
    @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> deleteSzhtxxElectronicInvoiceFptxx(@PathVariable("id") long id) {

        // TODO 参数合法性判定

        szhtxxElectronicInvoiceFptxxDubboConsumerService.deleteSzhtxxElectronicInvoiceFptxx(id);

        return new R<>("200", "操作成功", true);
    }

    @ApiOperation(value = "op批量删除")
    @RequestMapping(value = "delete_ids", method = RequestMethod.POST)
    @ResponseBody
    public R<String> deleteIdsSzhtxxElectronicInvoiceFptxx(@RequestParam(value = "ids") long[] ids) {

        log.info(JSONUtil.toJsonStr(ids));

        for (long id : ids) {
            szhtxxElectronicInvoiceFptxxDubboConsumerService.deleteSzhtxxElectronicInvoiceFptxx(id);
        }

        return new R<>("200", "操作成功", true);

    }

    /**
     * SingleBillingRequestBodyKpContent
     *
     * @param form
     * @return
     */
    @ApiOperation(value = "op红冲开票Pre(电子普通发票)(深圳航信电子发票)")
    @RequestMapping(value = "/opRedWritePre", method = RequestMethod.POST)
    @ResponseBody
    public R<SzhtxxElectronicInvoiceFptxxOpRedWriteVo> opRedWritePre(@RequestBody SzhtxxInvoiceFptxxOpSingleBillingForm form) {

        R<SzhtxxElectronicInvoiceFptxxOpRedWriteVo> result = new R<>();

        form.setFormState(CommonFormStateEnum.预览);

        try {


            /******************************************** 初始化 start ********************************************/

            InvoiceApply entity = invoiceApplyCustomerDubboConsumerService.findByInvoiceApplySn(form.getFpqqlsh(), getToken());

            List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                    SzhtxxElectronicInvoiceFptxxQueryCriteria.builder()
                            .szhtxxElectronicInvoiceFptxxId(form.getSzhtxxElectronicInvoiceFptxxId())
                            .build(),
                    getToken()
            );

            if (CollUtil.isEmpty(resultList)) {
                return ResponseResultOuterUtils.createErrorResult("500", "未查找到相关的信息");
            }

            SzhtxxElectronicInvoiceFptxxListItemVo szhtxxElectronicInvoiceFptxxListItemVo = resultList.get(0);

            /******************************************** 初始化   end ********************************************/

            /**************************************** 蓝票主体 start ****************************************/

            SzhtxxElectronicInvoiceFptxxDetailVo fptxxOrigin = szhtxxElectronicInvoiceFptxxDubboConsumerService.detailGenericParamSzhtxxElectronicInvoiceFptxx(
                    SzhtxxElectronicInvoiceFptxxQueryCriteria.builder()
                            .fpqqlsh(form.getFpqqlsh())
                            .szhtxxElectronicInvoiceFptxxId(form.getSzhtxxElectronicInvoiceFptxxId())
                            .build(),
                    getToken()
            );

            /**************************************** 蓝票主体 start ****************************************/


            /******************************************** 红票主体 start ********************************************/

            SingleBillingRequestBodyKpContent singleBillingRequestBodyKpContent = szhtxxElectronicInvoiceFptxxDubboConsumerService.opRedWritePre(
                    form,
                    szhtxxElectronicInvoiceFptxxListItemVo,
                    getToken()
            );

            /******************************************** 红票主体   end ********************************************/

            result.setSuccess(true);
            result.setData(SzhtxxElectronicInvoiceFptxxOpRedWriteVo.builder()
                    .fptxxOrigin(fptxxOrigin)
                    .fttxxRedWrite(singleBillingRequestBodyKpContent)
                    .build());

        } catch (Exception e) {

            result.setSuccess(false);
            result.setMessage(ResponseMsgConstants.ERROR_UNKNOW);
            log.error(ExceptionUtils.getMessage(e));
            e.printStackTrace();
        }

        return result;
    }

    @ApiOperation(value = "op红冲开票(电子普通发票)(深圳航信电子发票)")
    @RequestMapping(value = "/opRedWrite", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opRedWrite(@RequestBody SzhtxxInvoiceFptxxOpSingleBillingForm form) {

        form.setFormState(CommonFormStateEnum.提交);

        try {
            InvoiceApply invoiceApplyEntity = invoiceApplyCustomerDubboConsumerService.findByInvoiceApplySn(form.getFpqqlsh(), getToken());

            List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                    SzhtxxElectronicInvoiceFptxxQueryCriteria
                            .builder()
                            .szhtxxElectronicInvoiceFptxxId(form.getSzhtxxElectronicInvoiceFptxxId())
                            .build(),
                    getToken()
            );

            if (CollUtil.isEmpty(resultList)) {
                return ResponseResultOuterUtils.createErrorResult("500", "未查找到相关的信息");
            }

            SzhtxxElectronicInvoiceFptxxListItemVo szhtxxElectronicInvoiceFptxxListItemVo = resultList.get(0);

            SysNotify sysNotify = szhtxxElectronicInvoiceFptxxDubboConsumerService
                    .opRedWrite(
                            form,
                            szhtxxElectronicInvoiceFptxxListItemVo,
                            invoiceApplyEntity,
                            getToken()
                    );

            if (sysNotify.getTitle().equals(SzhtxxElectronicInvoiceResponseCodeEnum.SUCCESS.getReturnCode())) {
                return ResponseResultOuterUtils.createSuccesResult(sysNotify.getContent());
            } else {
                return ResponseResultOuterUtils.createErrorResult("500", sysNotify.getContent());
            }


        } catch (Exception e) {

            log.error(ExceptionUtils.getMessage(e));
            e.printStackTrace();

            return ResponseResultOuterUtils.createErrorResult("500", ResponseMsgConstants.ERROR_UNKNOW);
        }
    }

    /**
     * @param form
     * @return
     * @url http://192.168.6.223:8089/web/thirdpart/szhtxx/electronicInvoiceFptxx/opSendEmailPdfAttachment
     */
    @ApiOperation(value = "op推送发票", notes = "积分结算2.1")
    @RequestMapping(value = "/opSendEmailPdfAttachment", method = RequestMethod.POST)
    @ResponseBody
    public R<SzhtxxElectronicInvoiceFptxxListItemVo> opSendEmailPdfAttachment(@RequestBody SzhtxxElectronicInvoiceFptxxOpSendEmailPdfAttachmentForm form) {

        log.info("opSendEmailPdfAttachment \n{}", JSONUtil.toJsonPrettyStr(form));

        R<SzhtxxElectronicInvoiceFptxxListItemVo> result = new R<>();

        String fpqqlsh = null;

        try {

            List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                    SzhtxxElectronicInvoiceFptxxQueryCriteria.builder()
                            .szhtxxElectronicInvoiceFptxxId(form.getSzhtxxElectronicInvoiceFptxxId())
                            .build(),
                    getToken()
            );

            if (CollUtil.isEmpty(resultList)) {
                return ResponseResultOuterUtils.createErrorResult("500", "发送邮件失败, 未查找到相关的信息");
            }

            SzhtxxElectronicInvoiceFptxxListItemVo szhtxxElectronicInvoiceFptxxListItemVo = resultList.get(0);
            fpqqlsh = szhtxxElectronicInvoiceFptxxListItemVo.getFpqqlsh();


            /****************************************** 邮件正文 start ******************************************/

            // 利用 Thymeleaf 模板构建 html 文本
            Context templateEngineContext = new Context();
            // 给模板的参数的上下文
            templateEngineContext.setVariable("emailParam", szhtxxElectronicInvoiceFptxxListItemVo);
            // 执行模板引擎,执行模板引擎需要传入模板名、上下文对象
            // Thymeleaf的默认配置期望所有HTML文件都放在 **resources/templates ** 目录下,以.html扩展名结尾。
            // String emailText = templateEngine.process("email/templates", ctx);
            String htmlContent = templateEngine.process("mail_qch_thirdpart_szhtxx_electronicInvoice", templateEngineContext);

            /****************************************** 邮件正文   end ******************************************/

            /****************************************** 邮件附件 start ******************************************/

            ResourceStruct res = getPdfUrlOriginalUri(szhtxxElectronicInvoiceFptxxListItemVo);

            String fullpath = res.getPath();

            if (!FileUtil.isFile(fullpath)) {
                int ret = szhtxxElectronicInvoiceFptxxResultDubboConsumerService.savedPdfUrl(szhtxxElectronicInvoiceFptxxListItemVo.getFpqqlsh(), getToken());
            }

            /****************************************** 邮件附件   end ******************************************/

            /****************************************** 邮件标题 start ******************************************/


//			String subject = StrUtil.format("侨城汇-{}-{}-{}-{}-{}-电子发票",
//					szhtxxElectronicInvoiceFptxxListItemVo.getSsyf(),
//					szhtxxElectronicInvoiceFptxxListItemVo.getFpdm(),
//					szhtxxElectronicInvoiceFptxxListItemVo.getFphm(),
//					szhtxxElectronicInvoiceFptxxListItemVo.getFpqqlsh(),
//					szhtxxElectronicInvoiceFptxxListItemVo.getAccountingOrderSn()
//			);

            String subject = StrUtil.format("{}-{}-{}",
                    szhtxxElectronicInvoiceFptxxListItemVo.getFpdm(),
                    szhtxxElectronicInvoiceFptxxListItemVo.getFphm(),
                    szhtxxElectronicInvoiceFptxxListItemVo.getXhfmc()
            );

            /****************************************** 邮件标题   end ******************************************/

            /****************************************** 邮件发送 start ******************************************/

            MailUtil.send(
                    mailAccountConfigFactory.newInstance(),
                    AnStringUtils.stringArrayConvertToStringList(form.getTargetEmail(), ","),
                    subject,
                    htmlContent, true,
                    new File(fullpath)
            );

            /****************************************** 邮件发送   end ******************************************/


        } catch (cn.hutool.extra.mail.MailException me) {

            return ResponseResultOuterUtils.createErrorResult("500", "发送邮件失败[TP],请稍后再试" + me.getMessage());

        } catch (Exception e) {

            log.error(ExceptionUtils.getMessage(e));
            e.printStackTrace();

            return ResponseResultOuterUtils.createErrorResult("500", "发送邮件失败[TP],请联系管理员:" + e.getMessage());

        } finally {

            if (ObjectUtil.isNotNull(fpqqlsh)) {

                /**************************************** 更新邮件状态 start ****************************************/

                szhtxxElectronicInvoiceFptxxExtendInfoDubboConsumerService.saveOrUpdate(
                        SzhtxxElectronicInvoiceFptxxExtendInfo
                                .builder()
                                .fpqqlsh(fpqqlsh)

                                /**************************************** 更新内容 start ****************************************/

//                                .updateTime(DateUtil.date())
//                              .updateUserId()
//                              .updateUserName()
                                .sentEmailStatus(SzhtxxElectronicInvoiceFptxxSentEmailStatusEnum.已发送.getKey())

                                /**************************************** 更新内容 start ****************************************/

                                .build(), getToken()
                );

                /**************************************** 更新邮件状态   end ****************************************/
            }


        }


        return ResponseResultOuterUtils.createSuccesResult("发送邮件成功");
    }

    @ApiOperation(value = "op发票交付(调用深圳航信电子票-1.1.6_发票交付接口)", notes = "积分结算2.1")
    @RequestMapping(value = "/opCallSzhtxxElectronicInvoiceApiDeliver", method = RequestMethod.POST)
    @ResponseBody
    public R<SzhtxxElectronicInvoiceFptxxListItemVo> opCallSzhtxxElectronicInvoiceApiDeliver(@RequestBody SzhtxxElectronicInvoiceFptxxOpSendEmailPdfAttachmentForm form) {

        log.info("opSendEmailPdfAttachment \n{}", JSONUtil.toJsonPrettyStr(form));

        R<SzhtxxElectronicInvoiceFptxxListItemVo> result = new R<>();

        String fpqqlsh = null;

        try {

            List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                    SzhtxxElectronicInvoiceFptxxQueryCriteria
                            .builder()
                            .szhtxxElectronicInvoiceFptxxId(form.getSzhtxxElectronicInvoiceFptxxId())
                            .fpqqlsh(form.getFpqqlsh())
                            .build(),
                    getToken()
            );

            if (CollUtil.isEmpty(resultList)) {
                return ResponseResultOuterUtils.createErrorResult("500", "发送邮件失败, 未查找到相关的信息");
            }

            SzhtxxElectronicInvoiceFptxxListItemVo szhtxxElectronicInvoiceFptxxListItemVo = resultList.get(0);
            fpqqlsh = szhtxxElectronicInvoiceFptxxListItemVo.getFpqqlsh();


            SysNotify sysNotify = szhtxxElectronicInvoiceFptxxDubboConsumerService.callDeliverApi(form, szhtxxElectronicInvoiceFptxxListItemVo, getToken());

            if (sysNotify.getTitle().equals(SzhtxxElectronicInvoiceResponseCodeEnum.SUCCESS.getReturnCode())) {
                return ResponseResultOuterUtils.createSuccesResult(sysNotify.getContent());
//                return ResponseResultOuterUtils.createSuccesResult("发送邮件成功");
            }
//            {"returnCode":"1000","returnMsg":"交付成功","datas":{"serialNum":"muqgsy2snxyyn67.slsmbllgpdge1ucg","returnCode":"1000","returnMsg":"交付成功","fphm":null,"fpdm":null}}
            else if (sysNotify.getTitle().equals("1000")) {
                return ResponseResultOuterUtils.createSuccesResult(sysNotify.getContent());
            } else {
                return ResponseResultOuterUtils.createErrorResult("500", sysNotify.getContent());
            }


        } catch (cn.hutool.extra.mail.MailException me) {

            return ResponseResultOuterUtils.createErrorResult("500", "发送邮件失败," + me.getMessage());

        } catch (Exception e) {

            log.error(ExceptionUtils.getMessage(e));
            e.printStackTrace();

            return ResponseResultOuterUtils.createErrorResult("500", "发送邮件失败,请联系管理员！" + e.getMessage());
        } finally {

            if (ObjectUtil.isNotNull(fpqqlsh)) {

                /**************************************** 更新邮件状态 start ****************************************/

                szhtxxElectronicInvoiceFptxxExtendInfoDubboConsumerService.saveOrUpdate(
                        SzhtxxElectronicInvoiceFptxxExtendInfo
                                .builder()
                                .fpqqlsh(fpqqlsh)

                                /**************************************** 更新内容 start ****************************************/

//                                .updateTime(DateUtil.date())
//                              .updateUserId()
//                              .updateUserName()
                                .sentEmailStatus(SzhtxxElectronicInvoiceFptxxSentEmailStatusEnum.已发送.getKey())

                                /**************************************** 更新内容 start ****************************************/

                                .build(),
                        getToken()
                );

                /**************************************** 更新邮件状态   end ****************************************/
            }


        }


    }


    @ApiOperation(value = "op金税盘信息查询(调用深圳航信电子票-1.1.7_金税盘信息查询接口)", notes = "积分结算2.1")
    @RequestMapping(value = "/opCallSzhtxxElectronicInvoiceApiTaxInfo/{nsrsbh}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opCallSzhtxxElectronicInvoiceApiTaxInfo(@PathVariable("nsrsbh") String nsrsbh) {


        SysNotify sysNotify = szhtxxElectronicInvoiceFptxxDubboConsumerService.callTaxInfoApi(nsrsbh, getToken());

        if (sysNotify.getTitle().equals(SzhtxxElectronicInvoiceResponseCodeEnum.SUCCESS.getReturnCode())) {
            return ResponseResultOuterUtils.createSuccesResult(sysNotify.getContent());
        } else {
            return ResponseResultOuterUtils.createErrorResult("500", sysNotify.getContent());
        }

    }

    /**
     * @param form
     * @return
     * @url
     */
    @ApiOperation(value = "op在线预览发票001")
    @RequestMapping(value = "opGetPdfUrl", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opGetPdfUrl(@RequestBody SzhtxxElectronicInvoiceFptxxOpDownloadSinglePdfForm form) {

        List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                SzhtxxElectronicInvoiceFptxxQueryCriteria
                        .builder()
                        .szhtxxElectronicInvoiceFptxxId(form.getSzhtxxElectronicInvoiceFptxxId())
                        .build(),
                getToken()
        );

        if (CollUtil.isEmpty(resultList)) {
            return ResponseResultOuterUtils.createErrorResult("500", "未查找到相关的信息");
        }

        SzhtxxElectronicInvoiceFptxxListItemVo szhtxxElectronicInvoiceFptxxListItemVo = resultList.get(0);

        ResourceStruct res = getPdfUrlOriginalUri(szhtxxElectronicInvoiceFptxxListItemVo);

        return new R<>("200", res.getUri(), true);
    }


    /**
     * @param form
     * @return
     * @url
     */
    @ApiOperation(value = "op在线预览发票001DimAccountingOrder")
    @RequestMapping(value = "opGetPdfUrl/dim/accountingOrder", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opGetPdfUrlDimAccountingOrder(@RequestBody SzhtxxElectronicInvoiceFptxxOpDownloadSinglePdfForm form) {

        List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                SzhtxxElectronicInvoiceFptxxQueryCriteria
                        .builder()
                        .szhtxxElectronicInvoiceFptxxId(form.getSzhtxxElectronicInvoiceFptxxId())
                        .build(),
                getToken()
        );

        if (CollUtil.isEmpty(resultList)) {
            return ResponseResultOuterUtils.createErrorResult("500", "未查找到相关的信息");
        }

        SzhtxxElectronicInvoiceFptxxListItemVo szhtxxElectronicInvoiceFptxxListItemVo = resultList.get(0);

        ResourceStruct res = getPdfUrlOriginalUri(szhtxxElectronicInvoiceFptxxListItemVo);

        return new R<>("200", res.getUri(), true);
    }

    /**
     * @param form
     * @return
     * @url http://192.168.6.223:8089/web/thirdpart/szhtxx/electronicInvoiceFptxx/opPreviewPdf/CIA2022030851533312
     */
    @ApiOperation(value = "op在线预览发票002")
    @RequestMapping(value = "opPreviewPdf/{fpqqlsh}", method = RequestMethod.GET)
    public void opPreviewPdf(HttpServletResponse response, @PathVariable("fpqqlsh") String fpqqlsh) throws IOException {

        List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                SzhtxxElectronicInvoiceFptxxQueryCriteria
                        .builder()
                        .fpqqlsh(fpqqlsh)
                        .build(),
                getToken()
        );

        if (CollUtil.isEmpty(resultList)) {
            AnResponseStreamUtils.outputJson(JSONUtil.toJsonPrettyStr(ResponseResultOuterUtils.createErrorResult("500", "未查找到相关的信息")), response);
            return;
        }

        SzhtxxElectronicInvoiceFptxxListItemVo szhtxxElectronicInvoiceFptxxListItemVo = resultList.get(0);

        ResourceStruct res = getPdfUrlOriginalUri(szhtxxElectronicInvoiceFptxxListItemVo);

        /******************************************** 重复 ********************************************/

        String fullpath = res.getPath();

        if (!FileUtil.isFile(fullpath)) {
            int ret = szhtxxElectronicInvoiceFptxxResultDubboConsumerService.savedPdfUrl(szhtxxElectronicInvoiceFptxxListItemVo.getFpqqlsh(), getToken());
        }

        /******************************************** 重复 ********************************************/

        AnResponseStreamUtils.previewPdf(res.getPath(), res.getFileName(), response);

    }

    /**
     * @param response
     * @param form
     * @return
     * @throws IOException
     * @url
     */
    @ApiOperation(value = "op下载发票")
    @RequestMapping(value = "opDownLoadPdfUrl", method = RequestMethod.POST)
    public void opDownLoadPdfUrl(HttpServletResponse response, @RequestBody SzhtxxElectronicInvoiceFptxxOpDownloadSinglePdfForm form) throws IOException {

        List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                SzhtxxElectronicInvoiceFptxxQueryCriteria
                        .builder()
                        .szhtxxElectronicInvoiceFptxxId(form.getSzhtxxElectronicInvoiceFptxxId())
                        .fpqqlsh(form.getFpqqlsh())
                        .invoiceApplySn(form.getInvoiceApplySn())
                        .build(),
                getToken()
        );

        if (CollUtil.isEmpty(resultList)) {
            AnResponseStreamUtils.outputJson(JSONUtil.toJsonPrettyStr(ResponseResultOuterUtils.createErrorResult("500", "未查找到相关的信息")), response);
            return;
        }


        SzhtxxElectronicInvoiceFptxxListItemVo szhtxxElectronicInvoiceFptxxListItemVo = resultList.get(0);

        ResourceStruct res = getPdfUrlOriginalUri(szhtxxElectronicInvoiceFptxxListItemVo);

        /******************************************** 重复 ********************************************/

        String fullpath = res.getPath();

        String fileName = StrUtil.format("{}_{}_{}_{}.pdf",
                szhtxxElectronicInvoiceFptxxListItemVo.getFpdm(),
                szhtxxElectronicInvoiceFptxxListItemVo.getFphm(),
                szhtxxElectronicInvoiceFptxxListItemVo.getFpqqlsh(),
                szhtxxElectronicInvoiceFptxxListItemVo.getAccountingOrderSn()
        );

//        【4.新增优化需求[20220425]-4.3 金税盘发票PDF文件命名调整】mark by linjinyu at 20220506
//        https://www.tapd.cn/33003868/prong/stories/view/1133003868001004492
//4.3 金税盘发票PDF文件命名调整
//（1）深圳航信电子发票PDF文件命名调整：
//①原文件命名：发票代码_发票号_开票申请编号_对账单编号.pdf
//②调整文件命名：对账单编号_发票号_企业名称_发票金额.pdf
//·对账单编号：取该发票所属的对账单编号内容；
//·发票号：取该发票号的内容；
//·企业名称：取该发票的购买方名称，即企业的开票抬头内容；
//·发票金额：取该发票金额（含税）值，保留小数点两位，红冲时金额为负数；
//③此版本发布时需将线上已产生的深圳航信电子发票的发票PDF命名内容一同按调整后的要求修正；
//（2）注：积分结算模块下所有下载的深圳航信电子发票PDF文件均为此命名。
//        String aliasBasePath     = res.getBasePath();
//        String aliasRelativePath = res.getRelativePath();
        String aliasFileName = StrUtil.format("{}_{}_{}_{}.pdf",
                szhtxxElectronicInvoiceFptxxListItemVo.getAccountingOrderSn(),
                szhtxxElectronicInvoiceFptxxListItemVo.getFphm(),
                szhtxxElectronicInvoiceFptxxListItemVo.getGhfmc(),
                AnBigDecimalUtils.getBigDecimalFormat(szhtxxElectronicInvoiceFptxxListItemVo.getKphjje())
        );

        // 初始化Excel文件列表
        List<SzhtxxElectronicInvoiceFptxxListItemVo> fileNotFound = new ArrayList<>();

        if (!FileUtil.isFile(fullpath)) {
            FileUtil.touch(fullpath);
            fileNotFound.add(szhtxxElectronicInvoiceFptxxListItemVo);
//            int ret = szhtxxElectronicInvoiceFptxxResultDubboConsumerService.savedPdfUrl(szhtxxElectronicInvoiceFptxxListItemVo.getFpqqlsh(), getToken());
        }

        /******************************************** 重复 ********************************************/

        if (CollUtil.isNotEmpty(fileNotFound)) {
            int ret = szhtxxElectronicInvoiceFptxxResultDubboConsumerService.entryFileNotFoundPdf(fileNotFound, getToken());
        }


//		String fileUrl  = "/Users/linjinyu/tmp/_storage/excel/invoice/customer/客户结算_开票申请(发票)详情_电子发票_createAt_202103021503.xlsx";
//		String fileName = "客户结算_开票申请(发票)详情_电子发票_createAt_202103021503.xlsx";

        AnResponseStreamUtils.download(fullpath, aliasFileName, response);

    }

    @ApiOperation(value = "op多选下载发票-尝试")
    @RequestMapping(value = "opDownLoadPdfUrl/zip/entry", method = RequestMethod.POST)
    @ResponseBody
    public R<List<SzhtxxElectronicInvoiceFptxxListItemVo>> opDownLoadPdfUrlZipEntry(@RequestBody SzhtxxElectronicInvoiceFptxxOpDownloadMultPdfForm form) {

        List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                SzhtxxElectronicInvoiceFptxxQueryCriteria.builder()
                        .szhtxxElectronicInvoiceFptxxIdSelected(form.getSzhtxxElectronicInvoiceFptxxIdSelected())
                        .fpqqlshSelected(form.getFpqqlshSelected())
                        .build(),
                getToken()
        );

        if (CollUtil.isEmpty(resultList)) {
            return ResponseResultOuterUtils.createErrorResult("500", "未查找到相关的信息");
        }

        // 初始化Excel文件列表
        List<SzhtxxElectronicInvoiceFptxxListItemVo> fileNotFound = new ArrayList<>();

        resultList.forEach(szhtxxElectronicInvoiceFptxxListItemVo -> {

            ResourceStruct res = getPdfUrlSavedUri(szhtxxElectronicInvoiceFptxxListItemVo);

            /******************************************** 重复 ********************************************/

            String fullpath = res.getPath();

            // 文件不存在?
            if (!FileUtil.isFile(fullpath) || FileUtil.isEmpty(FileUtil.file(fullpath))) {
                fileNotFound.add(szhtxxElectronicInvoiceFptxxListItemVo);
            }

            /******************************************** 重复 ********************************************/

        });

        if (CollUtil.isNotEmpty(fileNotFound)) {
            log.info("\n存在 发票pdf文件不存在问题，尝试后台下载 {} ... ", JSONUtil.toJsonStr(fileNotFound));
            int ret = szhtxxElectronicInvoiceFptxxResultDubboConsumerService.entryFileNotFoundPdf(fileNotFound, getToken());
        }

        return ResponseResultOuterUtils.createSuccesResult("200", fileNotFound);


    }

    //    @ResponseBody
    @ApiOperation(value = "op多选下载发票")
    @RequestMapping(value = "opDownLoadPdfUrl/zip", method = RequestMethod.POST)
    public void opDownLoadPdfUrlZip(@RequestBody SzhtxxElectronicInvoiceFptxxOpDownloadMultPdfForm form, HttpServletResponse response) throws IOException {

        List<SzhtxxElectronicInvoiceFptxxListItemVo> resultList = szhtxxElectronicInvoiceFptxxDubboConsumerService.queryGenericParam(
                SzhtxxElectronicInvoiceFptxxQueryCriteria
                        .builder()
                        .szhtxxElectronicInvoiceFptxxIdSelected(form.getSzhtxxElectronicInvoiceFptxxIdSelected())
                        .fpqqlshSelected(form.getFpqqlshSelected())
                        .build(),
                getToken()
        );

        if (CollUtil.isEmpty(resultList)) {
            AnResponseStreamUtils.outputJson(JSONUtil.toJsonPrettyStr(ResponseResultOuterUtils.createErrorResult("500", "未查找到相关的信息")), response);
            return;
        }

        ResourceConstant excelExportConstant = providerEnvConstantDubboCustomerService.getResourceConstant();

        String excelExportPathRoot             = excelExportConstant.getPathRoot();
        String excelExportRelativePathTemplate = excelExportConstant.getPathTemplate();
        String excelExportRelativePathStorage  = excelExportConstant.getPathStorage();

        String relativePath = File.separator + "zip" + File.separator + "thirdpart" + File.separator + "szhtxx" + File.separator + "electronicInvoice" + File.separator;

        String targetFullPath             = excelExportPathRoot + excelExportRelativePathStorage;
        String targetZipFileName          = "金税盘发票" + "_" + "op下载PDF" + ExcelResponse.addTail() + ".zip";
        String targetZipWriteFileFullPath = targetFullPath + relativePath + targetZipFileName;

        FileUtil.touch(targetZipWriteFileFullPath);

        // 初始化Excel文件列表
        List<File> excelFileList = new ArrayList<>();


        List<String> fileNotFound = new ArrayList<>();

        resultList.forEach(szhtxxElectronicInvoiceFptxxListItemVo -> {

            ResourceStruct res = getPdfUrlSavedUri(szhtxxElectronicInvoiceFptxxListItemVo);

            /******************************************** 重复 ********************************************/

            String sourceFullPath = res.getPath();

            if (!FileUtil.isFile(sourceFullPath)) {
//                int ret = szhtxxElectronicInvoiceFptxxResultDubboConsumerService.savedPdfUrl(szhtxxElectronicInvoiceFptxxListItemVo.getFpqqlsh(), getToken());
                FileUtil.touch(sourceFullPath);
            }

            /******************************************** 重复 ********************************************/

            // 添加逻辑 如果文件 不存在 先尝试去下载一下


//        【4.新增优化需求[20220425]-4.3 金税盘发票PDF文件命名调整】mark by linjinyu at 20220506
//        https://www.tapd.cn/33003868/prong/stories/view/1133003868001004492
//4.3 金税盘发票PDF文件命名调整
//（1）深圳航信电子发票PDF文件命名调整：
//①原文件命名：发票代码_发票号_开票申请编号_对账单编号.pdf
//②调整文件命名：对账单编号_发票号_企业名称_发票金额.pdf
//·对账单编号：取该发票所属的对账单编号内容；
//·发票号：取该发票号的内容；
//·企业名称：取该发票的购买方名称，即企业的开票抬头内容；
//·发票金额：取该发票金额（含税）值，保留小数点两位，红冲时金额为负数；
//③此版本发布时需将线上已产生的深圳航信电子发票的发票PDF命名内容一同按调整后的要求修正；
//（2）注：积分结算模块下所有下载的深圳航信电子发票PDF文件均为此命名。

            String aliasBasePath     = res.getBasePath();
            String aliasRelativePath = res.getRelativePath();
            String aliasFileName = StrUtil.format("{}_{}_{}_{}.pdf",
                    szhtxxElectronicInvoiceFptxxListItemVo.getAccountingOrderSn(),
                    szhtxxElectronicInvoiceFptxxListItemVo.getFphm(),
                    szhtxxElectronicInvoiceFptxxListItemVo.getGhfmc(),
                    AnBigDecimalUtils.getBigDecimalFormat(szhtxxElectronicInvoiceFptxxListItemVo.getKphjje())
            );

            String aliasFullPath = StrUtil.format("{}{}{}", aliasBasePath, aliasRelativePath, aliasFileName);

            FileUtil.copy(
                    FileUtil.file(sourceFullPath),
                    FileUtil.file(aliasFullPath),
                    true
            );

            excelFileList.add(FileUtil.file(aliasFullPath));
        });


        if (CollUtil.isNotEmpty(excelFileList)) {
            // 生成zip
            ZipUtil.zip(FileUtil.file(targetZipWriteFileFullPath), true, excelFileList.toArray(new File[excelFileList.size()]));

            AnResponseStreamUtils.download(targetZipWriteFileFullPath, targetZipFileName, response);
        } else {
            AnResponseStreamUtils.outputJson(JSONUtil.toJsonPrettyStr(ResponseResultOuterUtils.createErrorResult("500", "没有要下载的文件")), response);
        }


    }

    private ResourceStruct getPdfUrlOriginalUri(SzhtxxElectronicInvoiceFptxxListItemVo fptxxResult) {

        ResourceConstant excelExportConstant = providerEnvConstantDubboCustomerService.getResourceConstant();

        String excelExportPathRoot             = excelExportConstant.getPathRoot();
        String excelExportRelativePathTemplate = excelExportConstant.getPathTemplate();
        String excelExportRelativePathStorage  = excelExportConstant.getPathStorage();

//		thirdpart.szhtxx.electronicInvoice
        String relativePath = File.separator + "pdf" + File.separator + "thirdpart" + File.separator + "szhtxx" + File.separator + "electronicInvoice" + File.separator;

        String targetBasePath = excelExportPathRoot + excelExportRelativePathStorage;
        // 原本文件名 https://eitest.szhtxx.com/dzfpTest/downPdf/VN4n47kq
        String targetFileNameOriginal = StrUtil.format("{}_{}_{}.pdf", fptxxResult.getFpqqlsh(), fptxxResult.getFpdm(), fptxxResult.getFphm());
        // 转换文件名 发票代码_发票号_开票申请编号_对账单编号.pdf
        String targetFileNameSaved = StrUtil.format("{}_{}_{}_{}.pdf",
                fptxxResult.getFpdm(),
                fptxxResult.getFphm(),
                fptxxResult.getFpqqlsh(),
                fptxxResult.getAccountingOrderSn()
        );

        String targetWriteFileRelativePathOriginal = relativePath + "original" + File.separator;
        String targetWriteFileRelativePathSaved    = relativePath + "saved" + File.separator + fptxxResult.getAccountingOrderSn() + File.separator;


        String targetWriteFileFullPath = targetBasePath + targetWriteFileRelativePathOriginal + targetFileNameOriginal;

        return ResourceStruct.builder()
                .basePath(targetBasePath)
                .relativePath(targetWriteFileRelativePathOriginal)
                .fileName(targetFileNameOriginal)
                .build();
    }

    private ResourceStruct getPdfUrlSavedUri(SzhtxxElectronicInvoiceFptxxListItemVo fptxxResult) {

        ResourceConstant excelExportConstant = providerEnvConstantDubboCustomerService.getResourceConstant();

        String excelExportPathRoot             = excelExportConstant.getPathRoot();
        String excelExportRelativePathTemplate = excelExportConstant.getPathTemplate();
        String excelExportRelativePathStorage  = excelExportConstant.getPathStorage();

//		thirdpart.szhtxx.electronicInvoice
        String relativePath = File.separator + "pdf" + File.separator + "thirdpart" + File.separator + "szhtxx" + File.separator + "electronicInvoice" + File.separator;

        String targetBasePath = excelExportPathRoot + excelExportRelativePathStorage;
        // 原本文件名 https://eitest.szhtxx.com/dzfpTest/downPdf/VN4n47kq
        String targetFileNameOriginal = StrUtil.format("{}_{}_{}.pdf", fptxxResult.getFpqqlsh(), fptxxResult.getFpdm(), fptxxResult.getFphm());
        // 转换文件名 发票代码_发票号_开票申请编号_对账单编号.pdf
        String targetFileNameSaved = StrUtil.format("{}_{}_{}_{}.pdf",
                fptxxResult.getFpdm(),
                fptxxResult.getFphm(),
                fptxxResult.getFpqqlsh(),
                fptxxResult.getAccountingOrderSn()
        );

        String targetWriteFileRelativePathOriginal = relativePath + "original" + File.separator;
        String targetWriteFileRelativePathSaved    = relativePath + "saved" + File.separator + fptxxResult.getAccountingOrderSn() + File.separator;

        String targetWriteFileFullPath = targetBasePath + targetWriteFileRelativePathSaved + targetFileNameSaved;

        return ResourceStruct.builder()
                .basePath(targetBasePath)
                .relativePath(targetWriteFileRelativePathSaved)
                .fileName(targetFileNameSaved)
                .build();
    }


}
