package com.jeeplus.finance.invoice.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jeeplus.finance.invoice.domain.CwFinanceInvoice;
import com.jeeplus.finance.invoice.domain.CwFinanceInvoiceBase;
import com.jeeplus.finance.invoice.domain.WorkInvoiceTaxClassificationCode;
import com.jeeplus.finance.invoice.service.dto.CwFinanceInvoiceBaseDTO;
import com.jeeplus.finance.invoice.service.dto.CwFinanceInvoiceDTO;
import com.jeeplus.finance.invoice.service.dto.CwWorkInvoiceReceipt;
import com.jeeplus.finance.invoice.service.dto.CwWorkInvoiceReceiptInfo;
import com.jeeplus.sys.service.dto.AreaDTO;
import com.jeeplus.sys.service.dto.UserDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Mapper
//@InterceptorIgnore(tenantLine = "true")
public interface CwFinanceInvoiceMapper extends BaseMapper<CwFinanceInvoice> {

    public IPage<CwFinanceInvoiceDTO> findList(Page<CwFinanceInvoiceDTO> page, @Param(Constants.WRAPPER) QueryWrapper<CwFinanceInvoice> queryWrapper);

    /**
     * 下载导出
     * @param page
     * @param queryWrapper
     * @return
     */
    public IPage<CwFinanceInvoiceDTO> findExportList(Page<CwFinanceInvoiceDTO> page, @Param(Constants.WRAPPER) QueryWrapper<CwFinanceInvoice> queryWrapper);
    @InterceptorIgnore(tenantLine = "true")
    public CwFinanceInvoiceDTO queryById(@Param("id") String id);

    public List<String> getIdByProjectId(@Param("id") String id);

    public List<CwFinanceInvoiceDTO> getByIds(@Param(Constants.WRAPPER) QueryWrapper<CwFinanceInvoice> queryWrapper);

    public List<String> getIdByContractId(@Param("id") String id);

    public List<String> getIdByClientId(@Param("id") String id);

    /**
     * 根据发票id清空发票的收款日期
     * @param id
     */
    void setReceivablesDateNull(@Param("id") String id);

    /**
     * 根据发票id清空发票的收款日期
     * @param cwFinanceInvoice
     */
    @InterceptorIgnore(tenantLine = "true")
    void updateInfoById(CwFinanceInvoice cwFinanceInvoice);

    IPage<CwFinanceInvoiceDTO> listByProgramId(Page<CwFinanceInvoiceDTO> page,@Param(Constants.WRAPPER) QueryWrapper<CwFinanceInvoiceDTO> queryWrapper);

    CwFinanceInvoiceBase getByNo(String invoiceNumber);

    Integer getCountByNo(@Param("no") String no);

    List<CwFinanceInvoiceDTO> getExceedCwFinance();

    /**
     * 根据id查询发票号
     * @param invoiceId
     * @return
     */
    String getInvoiceNumberStr(String invoiceId);
    //查询全部发票数据
    List<CwFinanceInvoiceDTO> getList(@Param("userId")String userId);

    //获取所有的区域
    List<AreaDTO> getAllArea();

    void insertBatch(@Param("invoiceArrayList") List<CwFinanceInvoice> invoiceArrayList);

    @InterceptorIgnore(tenantLine = "true")
    List<UserDTO> findZhglgsUserList();

    @InterceptorIgnore(tenantLine = "true")
    List<UserDTO> findZsUserList(@Param("zsOfficeName")String zsOfficeName);

    @InterceptorIgnore(tenantLine = "true")
    List<UserDTO> findCwglgsUserList();

    @InterceptorIgnore(tenantLine = "true")
    List<UserDTO> finduserAllList();
    @InterceptorIgnore(tenantLine = "true")
    List<UserDTO> findDtoList(@Param("tenantId") String tenantId);


    /**
     * 修改开票获取accesstoken失败结果
     * @param workInvoice
     * @return
     */
    Integer updateAccessTokenErrorById(CwFinanceInvoiceDTO workInvoice);

    /**
     * 修改开票获取的url以及发票号结果
     * @param workInvoice
     * @return
     */
    Integer updateOmsUrlById(CwFinanceInvoiceDTO workInvoice);

    /**
     * 修改订单提交接口返回值信息
     * @param workInvoice
     * @return
     */
    Integer updateOrderForGoodsResultStrById(CwFinanceInvoiceDTO workInvoice);

    /**
     * 修改红字确认单返回结果信息
     * @param workInvoice
     * @return
     */
    Integer updateConfirmationSlipResultStr(CwFinanceInvoiceDTO workInvoice);

    /**
     * 查询税收分类对应信息
     * @param workInvoice
     * @return
     */
    WorkInvoiceTaxClassificationCode getBillingContentDetail(CwFinanceInvoiceDTO workInvoice);

    /**
     * 修改开票信息对应个节点redis保存的数据
     * @param workInvoice
     * @return
     */
    Integer updateRedInvoiceJsonByWorkInvoiceId(CwFinanceInvoiceDTO workInvoice);


    /**
     * 根据发票编号查询已经收款的信息
     * @param invoiceNumberList
     * @return
     */
    List<CwWorkInvoiceReceipt> getByInvoiceNumber(@Param("list") List<String> invoiceNumberList);


    /**
     * 批量导入
     * @param list
     */
    void batchInsert(@Param("list") List<CwWorkInvoiceReceipt> list);


    /**
     * 批量修改（拼接多条UPDATE）
     * @param list 待修改的数据集（moneyEqualList/moneyPartialList）
     * @return 影响的行数
     */
    int batchUpdateByForeach(@Param("list") List<CwWorkInvoiceReceiptInfo> list);
}




