package com.goafanti.common.dao;

import com.goafanti.common.model.Department;
import com.goafanti.common.model.FinanceCount;
import com.goafanti.common.model.TOrderBillNew;
import com.goafanti.common.model.TOrderNew;
import com.goafanti.expenseAccount.bo.ExpenseCountsBo;
import com.goafanti.expenseAccount.bo.ExpenseCountsInput;
import com.goafanti.order.bo.*;
import com.goafanti.order.bo.outStatistics.OutOrderSalesSourceAmount;
import com.goafanti.organization.bo.OrganizationListOut;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 订单表(TOrderNew)表数据库访问层
 *
 * @author makejava
 * @since 2024-09-27 16:04:11
 */
public interface TOrderNewMapper {

    /**
     * 通过ID查询单条数据
     *
     * @param orderNo 主键
     * @return 实例对象
     */
    TOrderNew queryById(String orderNo);


    /**
     * 查询指定行数据
     *
     * @param tOrderNew 查询条件
     * @param pageable  分页对象
     * @return 对象列表
     */
    List<TOrderNew> findTOrderNewList(TOrderNew tOrderNew, @Param("pageable") Pageable pageable);

    /**
     * 统计总行数
     *
     * @param tOrderNew 查询条件
     * @return 总行数
     */
    int findTOrderNewCount(TOrderNew tOrderNew);

    /**
     * 新增数据
     *
     * @param tOrderNew 实例对象
     * @return 影响行数
     */
    int insert(TOrderNew tOrderNew);

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<TOrderNew> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<TOrderNew> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<TOrderNew> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<TOrderNew> entities);

    /**
     * 修改数据
     *
     * @param tOrderNew 实例对象
     * @return 影响行数
     */
    int update(TOrderNew tOrderNew);

    /**
     * 通过主键删除数据
     *
     * @param orderNo 主键
     * @return 影响行数
     */
    int deleteById(String orderNo);

    int insertSelective(TOrderNew record);

    TOrderNewBo getOrderNewDetail(String orderNo);
    int getCountByIdAndStatus(TOrderNew orderNew);

    /**
     * 获取订单信息
     * @param ono
     * @return orderNo ,  salesmanId,salesmanName, contractNo,email , userName, orderDep,
     *          departmentName financeId（此财务编号为订单部门财务负责人）
     */
    TOrderNewBo getSaleIdByOno(String ono);

    TOrderNewBo agreeEmailData(Integer fid);

    OrderRefundDetailBo orderRefundDetail(String id);

    int updateFinance(@Param("aid")String aid, @Param("orderNos") List<String> orderNos, @Param("newFinance")String newFinance);
    int checkContractNo(String sno);
    Map<String, Object> countTotalAndActually(@Param("o") OrderListBo o, @Param("fids") List<String> fids, @Param("deps")List<String> listDep, @Param("types")List<String> types);
    TOrderBillNew getLastPayment(String orderNo);
    int updateSalesmanId(@Param("aid")String aid, @Param("transferId")String transferId);
    List<TOrderNewBo> selectUsedOrderByOrder(String orderNo);
    void updaterefund(TOrderNew o);

    List<BigDecimal> selectByUidAndNewUser(@Param("uid")String uid, @Param("aid")String aid, @Param("newUser")Integer newUser, @Param("date") Date date, @Param("now")Date now);

    List<OutStatisticsList> statisticsList(InputStatistics in);

    List<OutProvinceStatisticsList> provinceStatisticsList(InputStatistics in);

    List<Map<String, Object>> selectOrderByuid(String uid);

    List<OutOrderSalesSource> orderSalesSource(InputOrderSalesSource in);

    List<OutOrderSalesSourceAmount> orderSalesSourceAmount(InputOrderSalesSource in);

    TOrderNew  checkOrderProcessStatus(Integer tid);

    List<TOrderNew> selectgetAll();

    /**
     * 获取订单审核人列表
     * @param orderNo
     * @return
     */
    OrderProcessName getProcessName(String orderNo);


    void updateExamineById(@Param("id") String id,@Param("type")Integer type);




    List<TOrderNewBo> selectByuidandAid(@Param("uid")String uid,@Param("aid") String aid);

    List<StatisOrderList>  statisticsOrderList(InputStatistics in);

    List<UserOrder>  matchingOrderNoOrUserName(@Param("orderNo") String orderNo, @Param("userName")String userName);

    void updateTagByListOrderNo(List<String> orderNos, Integer tag);

    int selectAidAndDate(@Param("aid") String aid, @Param("startTime") String startTime,
                         @Param("endTime")String endTime);



    List<FinanceCount> selectCountByFinance(String id);

    OrganizationListOut selectOrderFinance(String orderNo);

    Department selectDepByOrderNo(String orderNo);

    List<String> selectByFinanceNotExamine(@Param("financeId") String financeId, @Param("depId") String depId);

    void updateOrderDepFinanceExamineName(@Param("list") List<String> list, @Param("processStatus") Integer processStatus);

    List<ExpenseCountsBo> selectExpenseCount(ExpenseCountsInput in);

    List<ExpenseCountsBo> selectExpenseDepCount(ExpenseCountsInput in);


    List<String> selectByDepAndProcess(@Param("depId") String depId, @Param("processStatus") Integer processStatus);

    TOrderNew selectByTid(Integer tid);

    /**
     *
     * @param buyerId   用户编号
     * @param signTime  签单时间
     * @param type   0=小于签单时间，1=大于签单时间
     */
    List<TOrderNew> selectBuyerIdAndSignTime(@Param("buyerId") String buyerId, @Param("signTime") Date signTime, @Param("type") Integer type);
}

