package cn.superdesk.uniorder.service.thirdpart.szhtxx.paperInvoice.impl;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.superdesk.uniorder.dto._constant.ResourceConstant;
import cn.superdesk.uniorder.service.thirdpart.szhtxx.paperInvoice.SzhtxxPaperInvoiceFptxxLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2022/7/18 3:51 下午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/7/18 3:51 下午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class SzhtxxPaperInvoiceFptxxLogServiceImpl implements SzhtxxPaperInvoiceFptxxLogService {

    @Autowired
    private ResourceConstant resourceConstant;

    String SID1SingleBilling = "SID1SingleBilling";

    public void tmpLog(String type,
                       String interfaceName,
                       String fpqqlsh,
                       String batchId,
                       String messageBody, String now) {


        /**
         * 1. api前
         * 2. api ---- 当前
         * 3. excel
         */

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

        String relativePath = File.separator + "thirdpart" +
                File.separator + "szhtxx" +
                File.separator + "paperInvoice" +
//                File.separator + "SID1SingleBilling" +
                File.separator + interfaceName +
                File.separator + fpqqlsh +
                File.separator;

        String targetFullPath = excelExportPathRoot + excelExportRelativePathStorage;

        // 请求记录
        tmpLogWithFpqqlsh(targetFullPath, relativePath, type, fpqqlsh, batchId, messageBody, now);
    }

    public void tmpLogWithFpqqlsh(
            String targetFullPath,
            String relativePath,
            String type,
            String fpqqlsh,
            String batchId,
            String jsonBody,
            String now) {

        String targetResponseFileName          = StrUtil.format("{}_{}_{}_{}.json", fpqqlsh, batchId, type, now);
        String targetResponseWriteFileFullPath = targetFullPath + relativePath + targetResponseFileName;
        targetResponseWriteFileFullPath = targetResponseWriteFileFullPath.replaceAll(":","_");
        FileUtil.touch(targetResponseWriteFileFullPath);
        FileUtil.writeUtf8String(jsonBody, targetResponseWriteFileFullPath);// CharsetUtil.CHARSET_UTF_8

    }
}
