package cn.superdesk.uniorder.service.invoice.customer;

import cn.superdesk.uniorder.common.enums.accounting.AccountingOrderTypeDimEnum;
import cn.superdesk.uniorder.common.enums.invoice.customer.InvoiceApplyCustomerBackAccountStatusEnum;
import cn.superdesk.uniorder.common.exception.UnifiedOrderRuntimeException;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.customer.InvoiceApply;
import cn.superdesk.uniorder.dto.param.invoice.customer.InvoiceApplyCustomerOpAgainInvoiceApplyForm;
import cn.superdesk.uniorder.dto.param.invoice.customer.InvoiceApplyCustomerOpModifyInvoiceTitleForm;
import cn.superdesk.uniorder.dto.param.invoice.customer.InvoiceApplyCustomerQueryCriteria;
import cn.superdesk.uniorder.dto.param.invoice.customer.InvoiceApplyCustomerQueryCriteriaV2_1;
import cn.superdesk.uniorder.dto.vo.invoice.customer.*;
import cn.superdesk.uniorder.dto.vo.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxListItemVo;
import cn.superdesk.uniorder.event.invoiceApplyCustomerTrigger.TailUpdateAccountingScoreCustomerFieldInvoiceStatusEvent;

import java.util.List;
import java.util.Map;

/**
 * @Description: 开票申请 发票管理
 * @Author: linjinyu 重构
 * @CreateDate: 7/28/20 7:52 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 7/28/20 7:52 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public interface InvoiceApplyCustomerService {

    int updateInvoiceApplyByPrimaryKeySelective(InvoiceApply invoiceApply);

    int updateFieldBackAccountStatusByCheckRatio(Integer fullCount, Integer seizeCount, Long invoiceApplyId);

    int updateFieldBackAccountStatusByInvoiceApplyId(Long invoiceApplyId, InvoiceApplyCustomerBackAccountStatusEnum invoiceApplyBackAccountStatusEnum);


    /****************************************** 开票申请 列表的导出Excel数据 start ******************************************/

    /**
     * 客户结算-发票申请管理 列表-opt 导出报表
     *
     * @param params
     * @return
     * @throws UnifiedOrderRuntimeException
     */
    List<ExportExcelInvoiceApplyForceUnifiedDimGoodsVo> findInvoiceApplyFocusUnifiedDimGoods(Map<String, Object> params) throws UnifiedOrderRuntimeException;

    /**
     * 积分结算-发票申请管理 列表-opt 导出报表
     *
     * @param criteria
     * @return
     * @throws UnifiedOrderRuntimeException
     */
    List<ExportExcelInvoiceApplyCustomerForceScoreDimCreditVo> findInvoiceApplyFocusScoreDimCredit(InvoiceApplyCustomerQueryCriteria criteria) throws UnifiedOrderRuntimeException;

    /****************************************** 开票申请 列表的导出Excel数据   end ******************************************/

    /****************************************** 发票申请管理 start ******************************************/

    R<List<InvoiceApplyCustomerPageVo>> findViewByPageFocusUnified(Map<String, Object> params, int pageNum, int pageSize) throws UnifiedOrderRuntimeException;

    List<InvoiceApplyCustomerPageVo> findViewFocusUnified(Map<String, Object> params) throws UnifiedOrderRuntimeException;

    InvoiceApplyCustomerHeadDataVo findViewHeadDataFocusUnified(Map<String, Object> params) throws UnifiedOrderRuntimeException;


    R<List<InvoiceApplyCustomerPageVo>> findViewByPageFocusScore(InvoiceApplyCustomerQueryCriteria criteria, int pageNum, int pageSize) throws UnifiedOrderRuntimeException;

    List<InvoiceApplyCustomerPageVo> findViewFocusScore(InvoiceApplyCustomerQueryCriteria criteria);

    InvoiceApplyCustomerHeadDataVo findViewHeadDataFocusScore(InvoiceApplyCustomerQueryCriteria criteria) throws UnifiedOrderRuntimeException;


    R<List<InvoiceApplyCustomerPageVo>> pageQueryInvoiceApplyListFocusScoreV2_1(InvoiceApplyCustomerQueryCriteriaV2_1 criteria) throws UnifiedOrderRuntimeException;

    List<InvoiceApplyCustomerPageVo> queryInvoiceApplyListFocusScoreV2_1(InvoiceApplyCustomerQueryCriteriaV2_1 criteria);

    InvoiceApplyCustomerHeadDataVoV2_1 queryInvoiceApplyHeadDataFocusScoreV2_1(InvoiceApplyCustomerQueryCriteriaV2_1 criteria) throws UnifiedOrderRuntimeException;


    R<List<InvoiceApplyCustomerPageVo>> findInvoiceListByPageFocusScoreV2_1(InvoiceApplyCustomerQueryCriteriaV2_1 queryCriteriaV2_1, LoginSysUser loginSysUser) throws UnifiedOrderRuntimeException;

    List<InvoiceApplyCustomerPageVo> findInvoiceListFocusScoreV2_1(InvoiceApplyCustomerQueryCriteriaV2_1 queryCriteriaV2_1, LoginSysUser loginSysUser);

    InvoiceApplyCustomerHeadDataVoV2_1 findInvoiceHeadDataFocusScoreV2_1(InvoiceApplyCustomerQueryCriteriaV2_1 queryCriteriaV2_1, LoginSysUser loginSysUser) throws UnifiedOrderRuntimeException;

    /**
     * 开票申请后 反向更新对账单 开票状态
     * xml
     * 0 未开票
     * 1 全部开票
     * 2 部分开票
     * bean
     * 0-未开票;1-已开票;2-部分开票;
     *
     * @param affectedAccountingOrderIds
     * @param dim
     * @param loginSysUser
     */
    void processTailUpdateAccountingOrderInvoiceStatus(List<Long> affectedAccountingOrderIds, AccountingOrderTypeDimEnum dim, LoginSysUser loginSysUser);

    /****************************************** 发票申请管理   end ******************************************/


    InvoiceApplyCustomerDetailDimGoodsVo getUnifiedCustomerInvoice2GoodsDetail(Map<String, Object> params) throws UnifiedOrderRuntimeException;

    InvoiceApplyCustomerDetailDimCreditVo getInvoiceApplyCustomerDetailDimCredit(
            InvoiceApplyCustomerQueryCriteria criteria,
            LoginSysUser loginSysUser) throws UnifiedOrderRuntimeException;

    InvoiceApplyCustomerDetailDimCreditVoV2_1 getInvoiceApplyCustomerDetailDimCreditV2_1(
            InvoiceApplyCustomerQueryCriteriaV2_1 criteria,
            LoginSysUser loginSysUser) throws UnifiedOrderRuntimeException;


    /**
     * 积分结算-发票管理-导入寄票信息(批量操作)
     *
     * @param list
     * @param token
     * @throws UnifiedOrderRuntimeException
     */
    String importInvoiceExcel(List<Map<String, Object>> list, String token) throws UnifiedOrderRuntimeException;

    /**
     * 积分结算-发票管理-导入发票信息(批量操作)
     *
     * @param list
     * @param token
     * @throws UnifiedOrderRuntimeException
     */
    String importSendInvoiceExcel(List<Map<String, Object>> list, String token) throws UnifiedOrderRuntimeException;


    List<InvoiceApply> findAll(Map<String, Object> params);

    InvoiceApply findById(Long invoiceApplyId);

    List<InvoiceApply> findByIds(List<Long> invoiceApplyIds);

    List<InvoiceApply> findByOrderSn(Map<String, Object> invQuery);

    List<InvoiceApply> findByAccountingOrderSn(String accountingOrderSn, AccountingOrderTypeDimEnum accountingOrderTypeDimEnum);

    InvoiceApply findByInvoiceApplySn(String invoiceApplySn, LoginSysUser loginSysUser);

    R<List<InvoiceApply>> findInvoiceByPageNew(Map<String, Object> params, int pageNum, int pageSize);


    List<InvoiceApply> query4CheckIsOverdue();

    Map<String, InvoiceApply> findInvoiceByOrderSnList(List<String> orderSnList);


    void validatedInvoiceApplyRelationTable();


    TailUpdateAccountingScoreCustomerFieldInvoiceStatusEvent opAudit(Map<String, Object> params, LoginSysUser loginSysUser) throws UnifiedOrderRuntimeException;

    /**
     * 重新开票
     *
     * @param params
     * @param loginSysUser
     * @return
     * @throws UnifiedOrderRuntimeException
     */
    TailUpdateAccountingScoreCustomerFieldInvoiceStatusEvent opAgainSzhtxxElectronicInvoice(InvoiceApplyCustomerOpAgainInvoiceApplyForm form, InvoiceApply invoiceApplyEntity, SzhtxxElectronicInvoiceFptxxListItemVo fptxxListItemVo, LoginSysUser loginSysUser) throws UnifiedOrderRuntimeException;


    int opDelete(Long invoiceApplyId, LoginSysUser loginSysUser);

    void opRegister(Map<String, Object> params, LoginSysUser loginSysUser) throws UnifiedOrderRuntimeException;

    int opModifyInvoiceTitle(InvoiceApplyCustomerOpModifyInvoiceTitleForm form, LoginSysUser loginSysUser);

    /**
     * @param sendInvoiceRegisterList
     * @param loginSysUser
     * @throws UnifiedOrderRuntimeException
     */
    void invoiceRegisterSend(List<Map> sendInvoiceRegisterList, LoginSysUser loginSysUser) throws UnifiedOrderRuntimeException;

    /****************************************** 补丁程序 start ******************************************/

    void patchInvoiceApplyCustomerFixV2_1();

    void patchFixInfo(Long invoiceApplyId, LoginSysUser loginSysUser);

    void patchFixStatistics(Long invoiceApplyId, LoginSysUser loginSysUser);

    int pathFixFieldServiceNoSourceFrom(
            String accountingOrderSn, AccountingOrderTypeDimEnum accountingOrderTypeDimEnum,
            String serviceNo, String sourceFrom, LoginSysUser loginSysUser);

    void deleteByAccountingOrderSn(String accountingOrderSn);

    /****************************************** 补丁程序   end ******************************************/

}
