package cn.superdesk.uniorder.controller.invoice.customer.state;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import cn.superdesk.uniorder.common.constants.ResponseMsgConstants;
import cn.superdesk.uniorder.common.enums.accounting.customer.AccountingOrderCustomerAccountingStatusEnum;
import cn.superdesk.uniorder.common.enums.common.CommonFormStateEnum;
import cn.superdesk.uniorder.common.enums.invoice.customer.InvoiceApplyCustomerInvoiceProgressingStatusEnum;
import cn.superdesk.uniorder.common.enums.invoice.customer.InvoiceApplyCustomerMakeInvoiceStatusEnum;
import cn.superdesk.uniorder.common.enums.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxKplxEnum;
import cn.superdesk.uniorder.common.enums.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceResponseCodeEnum;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.rest.response.ResponseResultOuterUtils;
import cn.superdesk.uniorder.common.security.JwtUtil;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.accounting.score.customer.AccountingScoreCustomer;
import cn.superdesk.uniorder.dao.entity.invoice.customer.InvoiceApply;
import cn.superdesk.uniorder.dao.entity.sys.notify.SysNotify;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.common.singleBilling.SzhtxxInvoiceFptxxOpSingleBillingForm;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.common.singleSelect.SzhtxxInvoiceFptxxOpSingleSelectForm;
import cn.superdesk.uniorder.dubbo.consumer.accounting.customer.AccountingScoreCustomerDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.invoice.customer.InvoiceApplyCustomerDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.invoice.customer.state.InvoiceApplyFieldMakeInvoiceStatusDubboConsumerService;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.electronicInvoice.dto.request.SingleBillingRequestBodyKpContent;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.paperInvoice.dto.request.SID17SingleSelect.SID17SingleSelectRequestBody;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.paperInvoice.dto.request.SID1SingleBilling.SID1SingleBillingRequestBody;
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.*;

/**
 * @Description: 开票状态 - 简易状态机 星型结构
 * @Author: linjinyu
 * @CreateDate: 10/12/20 4:28 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 10/12/20 4:28 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "积分结算-发票单-开票状态-MakeInvoiceStatus", tags = {"积分结算-发票单-开票状态-MakeInvoiceStatus"})
@Slf4j
@RestController
@RequestMapping("/invoice/apply/customer/score/state/makeInvoiceStatus")
public class InvoiceApplyCustomerScoreFieldMakeInvoiceStatusController extends BaseController {

    @Autowired
    private InvoiceApplyCustomerDubboConsumerService               invoiceApplyCustomerDubboConsumerService;
    @Autowired
    private InvoiceApplyFieldMakeInvoiceStatusDubboConsumerService invoiceApplyFieldMakeInvoiceStatusDubboConsumerService;

    @Autowired
    private AccountingScoreCustomerDubboConsumerService accountingScoreCustomerDubboConsumerService;

//	@ApiOperation(value = "MakeInvoiceStatus-op待开票 状态改变为 待开票_0")
//	@RequestMapping(value = "/opInit/{id}", method = RequestMethod.POST)
//	@ResponseBody
//	public R<?> opInit(@PathVariable("id") Long id) {
//
//		R<?> result = new R<>();
//
//		try {
//			InvoiceApply entity = invoiceApplyCustomerDubboConsumerService.findById(id);
//			invoiceApplyFieldMakeInvoiceStatusDubboConsumerService.opInit(entity, getToken());
//			result.setSuccess(true);
//
//		} catch (Exception e) {
//
//			result.setSuccess(false);
//			result.setMessage(ResponseMsgConstants.ERROR_UNKNOW);
//			log.error(ExceptionUtils.getMessage(e));
//			e.printStackTrace();
//		}
//		return result;
//	}

    /**
     * /invoice/apply/customer/score/state/makeInvoiceStatus/opBecomeInvalid
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "MakeInvoiceStatus-操作 财务-作废票 状态改变为 已作废_2")
    @RequestMapping(value = "/opBecomeInvalid/{id}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opBecomeInvalid(@PathVariable("id") Long id) {

        try {
            InvoiceApply entity    = invoiceApplyCustomerDubboConsumerService.findById(id);
            SysNotify    sysNotify = invoiceApplyFieldMakeInvoiceStatusDubboConsumerService.opBecomeInvalid(entity, 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);
        }
    }


    /**
     * /invoice/apply/customer/score/state/makeInvoiceStatus/exportOngoing/invoiceType/1/invoiceMode/szhtxxElectronicInvoice/{invoiceApplyId}
     *
     * @param invoiceApplyId
     * @return
     */
    @ApiOperation(value = "MakeInvoiceStatus-export发起开票Pre(电子普通发票)(深圳航信电子发票)")
    @RequestMapping(value = "/exportOngoing/invoiceType/1/invoiceMode/szhtxxElectronicInvoice/{invoiceApplyId}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> exportOngoingInvoiceTypeEq1InvoiceModeEqSzhtxxElectronicInvoice(@PathVariable("invoiceApplyId") Long invoiceApplyId) {

        InvoiceApply entity = invoiceApplyCustomerDubboConsumerService.findById(invoiceApplyId);

        return new R<String>(invoiceApplyFieldMakeInvoiceStatusDubboConsumerService.exportOngoingInvoiceTypeEq1InvoiceModeEqSzhtxxElectronicInvoice(
                SzhtxxInvoiceFptxxOpSingleBillingForm
                        .builder()
                        .formState(CommonFormStateEnum.预览)
                        .build(),
                entity,
                getToken()
        ));
    }


    /**************************************** 电子普通发票-深圳航信电子发票 start ****************************************/

    @ApiOperation(value = "MakeInvoiceStatus-op发起开票Pre(电子普通发票)(深圳航信电子发票) 状态改变为 开票中_10")
    @RequestMapping(value = "/opOngoing/invoiceType/1/invoiceMode/szhtxxElectronicInvoice/{invoiceApplyId}", method = RequestMethod.POST)
    @ResponseBody
    public R<SingleBillingRequestBodyKpContent> opOngoingInvoiceTypeEq1InvoiceModeEqSzhtxxElectronicInvoice(
            @PathVariable("invoiceApplyId") Long invoiceApplyId) {

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

        try {
            InvoiceApply entity = invoiceApplyCustomerDubboConsumerService.findById(invoiceApplyId);

            SingleBillingRequestBodyKpContent singleBillingRequestBodyKpContent = invoiceApplyFieldMakeInvoiceStatusDubboConsumerService.opOngoingInvoiceTypeEq1InvoiceModeEqSzhtxxElectronicInvoice(
                    SzhtxxInvoiceFptxxOpSingleBillingForm
                            .builder()
                            .formState(CommonFormStateEnum.预览)
                            .build(),
                    entity,
                    getToken()
            );

            result.setSuccess(true);
            result.setData(singleBillingRequestBodyKpContent);

        } catch (Exception e) {

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

        return result;
    }


    /**
     * 界面位置 积分结算 发票申请管理 发起开票
     * op确认发起
     * |---- 线下开票
     * |---- 深圳航信电子发票
     * |---- 深圳航信纸质发票 ---- 不在这
     *
     * @param id
     * @param form
     * @return
     */
    @ApiOperation(value = "MakeInvoiceStatus-op发起开票-op确认发起(电子普通发票)(深圳航信电子发票) 状态改变为 开票中_10")
    @RequestMapping(value = "/opOngoing/{id}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opOngoing(
            @PathVariable("id") Long id,
            @RequestBody SzhtxxInvoiceFptxxOpSingleBillingForm form) {

        try {

            InvoiceApply invoiceApplyCustomerEntity = invoiceApplyCustomerDubboConsumerService.findById(id);

            /**************************************** 检查 start ****************************************/

            R<String> checkUpResponse = opConfirmLaunchBeforeCheckUp(invoiceApplyCustomerEntity, form);
            if ("500".equals(checkUpResponse.getCode())) {
                return ResponseResultOuterUtils.createErrorResult(checkUpResponse.getCode(), checkUpResponse.getMessage());
            }

            /**************************************** 检查   end ****************************************/


            form.setFormState(CommonFormStateEnum.提交);
            SysNotify sysNotify = invoiceApplyFieldMakeInvoiceStatusDubboConsumerService.opOngoing(
                    form,
                    invoiceApplyCustomerEntity,
                    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);
        }

    }

    /**************************************** 电子普通发票-深圳航信电子发票   end ****************************************/


    /**************************************** 共用 页面 时机 积分结算 发票申请管理 发起开票 op发起开票 op确认发起 start ****************************************/

    /**
     * 界面位置 积分结算 发票申请管理 发起开票(是否允许) 此处为门面 为什么不写在 `opOngoing` ? 慢慢你就会懂的
     * op确认发起
     * |---- 线下开票 ---- 与之差别就是 不提交
     * |---- 深圳航信电子发票 ---- 与之差别就是 不提交
     * |---- 深圳航信纸质发票
     *
     * @param id
     * @param form
     * @return
     */
    @ApiOperation(value = "MakeInvoiceStatus-op发起开票-op确认发起(纸质专用发票)(深圳航信纸质发票) 状态改变为 开票中_10")
    @RequestMapping(value = "/opOngoing/opConfirm/launchBefore/checkUpinvoiceMode/szhtxxPaperInvoice/{id}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opOngoingOpConfirmLaunchBeforeCheckUp(
            @PathVariable("id") Long id,
            @RequestBody SzhtxxInvoiceFptxxOpSingleBillingForm form) {

        log.info("opOngoingOpConfirmLaunchBeforeCheckUp:{}", JSONUtil.toJsonStr(form));

        InvoiceApply invoiceApplyCustomerEntity = invoiceApplyCustomerDubboConsumerService.findById(id);

        R<String> checkUpResponse = opConfirmLaunchBeforeCheckUp(invoiceApplyCustomerEntity, form);

        // 不等于 200 返回
        if (!checkUpResponse.getCode().equals("200")) {
            return checkUpResponse;
        }

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(getToken());

        int ret = invoiceApplyCustomerDubboConsumerService.updateInvoiceApplyByPrimaryKeySelective(
                InvoiceApply
                        .builder()

                        .id(invoiceApplyCustomerEntity.getId())
                        .makeInvoiceStatus(InvoiceApplyCustomerMakeInvoiceStatusEnum.开票中.getKey())
                        .makeInvoiceUserId(loginSysUser.getSysUserId())
                        .makeInvoiceTime(DateUtil.date())

                        .build()
        );

        if (ret > 0) {
            return ResponseResultOuterUtils.createSuccesResult("该开票申请的开票状态[开票中]锁定成功");
        } else {
            return ResponseResultOuterUtils.createErrorResult("500", "该开票申请的开票状态[开票中]锁定失败");
        }

    }


    /**
     * op确认发起(前检查)
     *
     * @param invoiceApplyCustomerEntity
     * @param form
     * @return
     */
    private R<String> opConfirmLaunchBeforeCheckUp(
            InvoiceApply invoiceApplyCustomerEntity,
            SzhtxxInvoiceFptxxOpSingleBillingForm form) {

        log.info("opConfirmLaunchBeforeCheckUp:\n{}\n{}", JSONUtil.toJsonStr(invoiceApplyCustomerEntity), JSONUtil.toJsonStr(form));

        if (ObjectUtil.isNull(invoiceApplyCustomerEntity)) {
            return ResponseResultOuterUtils.createErrorResult("500", "该开票申请数据发生变更，请返回检查");
        }

        /**************************************** 检查 start ****************************************/

//【2. 积分结算-2.2 发票申请管理-2.2.4 【操作项】-已整理-20220505-确认开票】
//https://www.tapd.cn/33003868/prong/stories/view/1133003868001004185
//·该开票申请所属的对账单状态为“已确认”，否则不允许确认发起，1.5s提示“该开票申请所属的对账单状态未确认或已取消，请检查”；
//·该开票申请的申请状态为“待开票”，否则不允许确认发起，1.5s提示“该开票申请的申请状态非待开票，请检查”；
//·该开票申请的开票状态为“待开票”，否则不允许确认发起，1.5s提示“该开票申请的开票状态开票中或已开票，请检查”
//
//【【结算中心-测试环境】积分结算-发票申请管理-确认发起-用户A【撤销开票】，用户B仍【确认开票】，提示语有误】
//https://www.tapd.cn/33003868/bugtrace/bugs/view?bug_id=1133003868001005063

        String accountingOrderSn = invoiceApplyCustomerEntity.getAccountingOrderSn();

        AccountingScoreCustomer accountingScoreCustomer = accountingScoreCustomerDubboConsumerService.findByAccountingOrderSn(accountingOrderSn);

        if (ObjectUtil.isNull(accountingScoreCustomer)) {
            return ResponseResultOuterUtils.createErrorResult("500", "对账单数据异常[对账单003]");
        }

        if (accountingScoreCustomer.getAccountingStatus()
                .compareTo(AccountingOrderCustomerAccountingStatusEnum.已确认.getKey()) != 0) {
            return ResponseResultOuterUtils.createErrorResult("500", "该开票申请所属的对账单状态未确认或已取消，请检查");
        }


        Integer[] invoiceProgressingStatusNeed = {
                InvoiceApplyCustomerInvoiceProgressingStatusEnum.待开票.getKey()
        };
        if (!ArrayUtil.contains(invoiceProgressingStatusNeed, invoiceApplyCustomerEntity.getInvoiceStatus())) {
            return ResponseResultOuterUtils.createErrorResult("500", "该开票申请的申请状态非待开票，请检查");
        }


        Integer[] makeInvoiceStatusNeed = {
                InvoiceApplyCustomerMakeInvoiceStatusEnum.待开票.getKey(),
                InvoiceApplyCustomerMakeInvoiceStatusEnum.开票中.getKey() // ---- 在上一步把 查询时 待开票->开票中
        };
        if (!ArrayUtil.contains(makeInvoiceStatusNeed, invoiceApplyCustomerEntity.getMakeInvoiceStatus())) {
            return ResponseResultOuterUtils.createErrorResult("500", "该开票申请的开票状态开票中或已开票，请检查");
        }

        return ResponseResultOuterUtils.createSuccesResult();


        /**************************************** 检查   end ****************************************/
    }

    /**************************************** 共用 页面 时机 积分结算 发票申请管理 发起开票 op发起开票 op确认发起   end ****************************************/


    /**************************************** 纸质专用发票-深圳航信纸质发票 start ****************************************/

    /**
     * 界面位置 积分结算 发票申请管理 列表
     * op发起开票Request(纸质专用发票)(深圳航信纸质发票)
     *
     * @param invoiceApplyId
     * @return
     */
    @ApiOperation(value = "MakeInvoiceStatus-op发起开票Request(纸质专用发票)(深圳航信纸质发票) 状态改变为 开票中_10")
    @RequestMapping(value = "/opOngoing/invoiceType/2/invoiceMode/szhtxxPaperInvoice/request/{invoiceApplyId}", method = RequestMethod.POST)
    @ResponseBody
    public R<SID1SingleBillingRequestBody> opOngoingInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceRequest(
            @PathVariable("invoiceApplyId") Long invoiceApplyId) {

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

        try {
            InvoiceApply entity = invoiceApplyCustomerDubboConsumerService.findById(invoiceApplyId);

            SID1SingleBillingRequestBody sid1SingleBillingRequestBody = invoiceApplyFieldMakeInvoiceStatusDubboConsumerService
                    .opOngoingInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoice(
                            SzhtxxInvoiceFptxxOpSingleBillingForm
                                    .builder()
                                    .formState(CommonFormStateEnum.预览)
                                    .szhtxxElectronicInvoiceFptxxKplxEnum(SzhtxxElectronicInvoiceFptxxKplxEnum.正常发票)
                                    .build(),
                            entity,
                            getToken()
                    );

            result.setSuccess(true);
            result.setData(sid1SingleBillingRequestBody.packing());

        } catch (Exception e) {

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

        return result;
    }


    /**
     * 界面位置 积分结算 发票申请管理 列表
     * op发起开票Response(纸质专用发票)(深圳航信纸质发票)
     *
     * @param id
     * @param form
     * @return
     */
    @ApiOperation(value = "MakeInvoiceStatus-op发起开票Response(纸质专用发票)(深圳航信纸质发票) 状态改变为 开票中_10")
    @RequestMapping(value = "/opOngoing/invoiceType/2/invoiceMode/szhtxxPaperInvoice/response/{id}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opOngoingInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceResponse(
            @PathVariable("id") Long id,
            @RequestBody SzhtxxInvoiceFptxxOpSingleBillingForm form) {

        try {

//            SID1SingleBillingResponseBody sid1SingleBillingResponseBody = SID1SingleBillingResponseBody
//                    .builder()
//                    .batchId(form.getBatchId())
////                    .fpqqlsh(form.getFpqqlsh()) // 这里是错的 fpqqlsh是发票红冲时用  invoiceApplySn是发起开票时用
//                    .fpqqlsh(form.getInvoiceApplySn())
//
//                    .ENCMSG(form.getENCMSG())
//                    .build();
//
//            sid1SingleBillingResponseBody.unPacking();
//
//            log.info("\n表单\n{}解密\n{}",
//                    JSONUtil.toJsonPrettyStr(form),
//                    JSONUtil.toJsonPrettyStr(sid1SingleBillingResponseBody.getEncmsgVo())
//            );

            /**************************************** debug start ****************************************/

//            return ResponseResultOuterUtils.createSuccesResult();

            /**************************************** debug   end ****************************************/


            InvoiceApply entity = invoiceApplyCustomerDubboConsumerService.findById(id);

            form.setFormState(CommonFormStateEnum.提交);
            form.setSzhtxxElectronicInvoiceFptxxKplxEnum(SzhtxxElectronicInvoiceFptxxKplxEnum.正常发票);

            SysNotify sysNotify = invoiceApplyFieldMakeInvoiceStatusDubboConsumerService.opOngoing(form, entity, getToken());

//            (SzhtxxElectronicInvoiceResponseCodeEnum.SUCCESS.getReturnCode())

            if ("4011".equals(sysNotify.getTitle())) {
                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);
        }

    }

    /**************************************** 纸质专用发票-深圳航信纸质发票   end ****************************************/


    @Deprecated
    @ApiOperation(value = "MakeInvoiceStatus-op确认开票 状态改变为 已开票_11")
    @RequestMapping(value = "/opComplete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opComplete(@PathVariable("id") Long id) {

        try {

            InvoiceApply entity = invoiceApplyCustomerDubboConsumerService.findById(id);

            SysNotify sysNotify = invoiceApplyFieldMakeInvoiceStatusDubboConsumerService.opComplete(entity, 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);
        }
    }


    /**************************************** 纸质专用发票-深圳航信纸质发票 start ****************************************/

    /**
     * 界面位置 积分结算 发票申请管理 列表
     * op确认开票(非op确认发起)
     *
     * @param invoiceApplyId
     * @param form
     * @return
     */
    @ApiOperation(value = "MakeInvoiceStatus-op确认开票Request(非op确认发起)(纸质专用发票)(深圳航信纸质发票) 状态改变为 已开票_11")
    @RequestMapping(value = "/opComplete/invoiceType/2/invoiceMode/szhtxxPaperInvoice/request/{invoiceApplyId}", method = RequestMethod.POST)
    @ResponseBody
    public R<SID17SingleSelectRequestBody> opCompleteInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceRequest(
            @PathVariable("invoiceApplyId") Long invoiceApplyId,
            @RequestBody SzhtxxInvoiceFptxxOpSingleSelectForm form
    ) {

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

        try {
            InvoiceApply entity = invoiceApplyCustomerDubboConsumerService.findById(invoiceApplyId);

            form.setFormState(CommonFormStateEnum.预览);

            SID17SingleSelectRequestBody sid17SingleSelectRequestBody = invoiceApplyFieldMakeInvoiceStatusDubboConsumerService
                    .opCompleteInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceRequest(
//                    SzhtxxInvoiceFptxxOpSingleSelectForm
//                            .builder()
//                            .formState(CommonFormStateEnum.预览)
//                            .build(),
                            form,
                            entity,
                            getToken()
                    );

            result.setSuccess(true);
            result.setData(sid17SingleSelectRequestBody.packing());

        } catch (Exception e) {

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

        return result;
    }


    /**
     * 界面位置 积分结算 发票申请管理 列表
     * op确认开票(非op确认发起)
     *
     * @param invoiceApplyId
     * @param form
     * @return
     */
    @ApiOperation(value = "MakeInvoiceStatus-op确认开票Response(非op确认发起)(纸质专用发票)(深圳航信纸质发票) 状态改变为 已开票_11")
    @RequestMapping(value = "/opComplete/invoiceType/2/invoiceMode/szhtxxPaperInvoice/response/{invoiceApplyId}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> opCompleteInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceResponse(
            @PathVariable("invoiceApplyId") Long invoiceApplyId,
            @RequestBody SzhtxxInvoiceFptxxOpSingleSelectForm form
    ) {

        try {

//            SID1SingleBillingResponseBody sid1SingleBillingResponseBody = SID1SingleBillingResponseBody
//                    .builder()
//                    .batchId(form.getBatchId())
////                    .fpqqlsh(form.getFpqqlsh()) // 这里是错的 fpqqlsh是发票红冲时用  invoiceApplySn是发起开票时用
//                    .fpqqlsh(form.getInvoiceApplySn())
//
//                    .ENCMSG(form.getENCMSG())
//                    .build();
//
//            sid1SingleBillingResponseBody.unPacking();
//
//            log.info("\n表单\n{}解密\n{}",
//                    JSONUtil.toJsonPrettyStr(form),
//                    JSONUtil.toJsonPrettyStr(sid1SingleBillingResponseBody.getEncmsgVo())
//            );

            /**************************************** debug start ****************************************/

//            return ResponseResultOuterUtils.createSuccesResult();

            /**************************************** debug   end ****************************************/

            InvoiceApply entity = invoiceApplyCustomerDubboConsumerService.findById(invoiceApplyId);

            form.setFormState(CommonFormStateEnum.提交);

            SysNotify sysNotify = invoiceApplyFieldMakeInvoiceStatusDubboConsumerService
                    .opCompleteInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceResponse(
                            form,
                            entity,
                            getToken()
                    );

            if ("0".equals(sysNotify.getTitle()) || "4011".equals(sysNotify.getTitle())) {
                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);
        }

    }

    /**************************************** 纸质专用发票-深圳航信纸质发票   end ****************************************/

}
