package com.jsh.erp.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jsh.erp.datasource.entities.DepotHead;
import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
import com.jsh.erp.datasource.vo.DepotHeadVo4InDetail;
import com.jsh.erp.datasource.vo.DepotHeadVo4InOutMCount;
import com.jsh.erp.datasource.vo.DepotHeadVo4List;
import com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount;
import com.jsh.erp.datasource.vo.DepotHeadXsddRequestVO;
import com.jsh.erp.datasource.vo.DepotItemXsddRequestVO;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface DepotHeadService extends IService<DepotHead> {

    /**
     * PDA查询订单
     * @param pdaDepotHeadDTO 筛选条件
     * @return
     */
    List<PDADepotHeadVO> pdaList(PDADepotHeadDTO pdaDepotHeadDTO);

    /**
     * PDA查询订单详情
     * @param id
     * @return
     */
    PDADepotHeadVO pdaDetail(Long id);

    DepotHead getDepotHead(long id)throws Exception;

    List<DepotHead> getDepotHead()throws Exception;

    List<DepotHeadVo4List> select(String type, String subType, String hasDebt, String status, String purchaseStatus, String number, String linkApply, String linkNumber,
                                  String beginTime, String endTime, String materialParam, Long organId, Long creator, Long depotId, Long accountId, String remark) throws Exception;

    String[] getDepotArray(String subType) throws Exception;

    String[] getCreatorArray() throws Exception;

    String[] getCreatorArrayByOrg(Long organizationId) throws Exception;

    String[] getOrganArray(String subType, String purchaseStatus) throws Exception;

    String getCreatorByCurrentUser() throws Exception;

    Map<String, BigDecimal> getFinishDepositMapByNumberList(List<String> numberList);

    Map<String, Integer> getBillSizeMapByLinkNumberList(List<String> numberList) throws Exception;

    Map<Long,Integer> getFinancialBillNoMapByBillIdList(List<Long> idList);

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int insertDepotHead(JSONObject obj, HttpServletRequest request)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int updateDepotHead(JSONObject obj, HttpServletRequest request) throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int deleteDepotHead(Long id, HttpServletRequest request)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int batchDeleteDepotHead(String ids, HttpServletRequest request)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int batchDeleteBillByIds(String ids)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int batchDeleteDepotHeadByIds(String ids)throws Exception;

    List<DepotHead> getDepotHeadListByIds(String ids)throws Exception;

    int checkIsBillNumberExist(Long id, String number)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int batchSetStatus(String status, String depotHeadIDs)throws Exception;

    Map<Long,String> findMaterialsListMapByHeaderIdList(List<Long> idList)throws Exception;

    Map<Long,BigDecimal> getMaterialCountListMapByHeaderIdList(List<Long> idList)throws Exception;

    List<DepotHeadVo4InDetail> findInOutDetail(String beginTime, String endTime, String type, String[] creatorArray,
                                               String[] organArray, List<Long> categoryList, Boolean forceFlag, Boolean inOutManageFlag,
                                               String materialParam, List<Long> depotList, Integer oId, String number,
                                               Long creator, String remark, String column, String order, Integer offset, Integer rows) throws Exception;

    int findInOutDetailCount(String beginTime, String endTime, String type, String[] creatorArray,
                             String[] organArray, List<Long> categoryList, Boolean forceFlag, Boolean inOutManageFlag, String materialParam, List<Long> depotList, Integer oId, String number,
                             Long creator, String remark) throws Exception;

    DepotHeadVo4InDetail findInOutDetailStatistic(String beginTime, String endTime, String type, String[] creatorArray,
                                                  String[] organArray, List<Long> categoryList, Boolean forceFlag, Boolean inOutManageFlag,
                                                  String materialParam, List<Long> depotList, Integer oId, String number,
                                                  Long creator, String remark) throws Exception;

    List<DepotHeadVo4InOutMCount> findInOutMaterialCount(String beginTime, String endTime, String type, List<Long> categoryList,
                                                         Boolean forceFlag, Boolean inOutManageFlag, String materialParam,
                                                         List<Long> depotList, Long organizationId, Integer oId, String column, String order,
                                                         Integer offset, Integer rows)throws Exception;

    int findInOutMaterialCountTotal(String beginTime, String endTime, String type, List<Long> categoryList,
                                    Boolean forceFlag, Boolean inOutManageFlag, String materialParam,
                                    List<Long> depotList, Long organizationId, Integer oId)throws Exception;

    DepotHeadVo4InOutMCount findInOutMaterialCountStatistic(String beginTime, String endTime, String type, List<Long> categoryList,
                                                            Boolean forceFlag, Boolean inOutManageFlag, String materialParam,
                                                            List<Long> depotList, Long organizationId, Integer oId) throws Exception;

    List<DepotHeadVo4InDetail> findAllocationDetail(String beginTime, String endTime, String subType, String number,
                                                    String[] creatorArray, List<Long> categoryList, Boolean forceFlag, String materialParam, List<Long> depotList, List<Long> depotFList,
                                                    String remark, String column, String order, Integer offset, Integer rows) throws Exception;

    int findAllocationDetailCount(String beginTime, String endTime, String subType, String number,
                                  String[] creatorArray, List<Long> categoryList, Boolean forceFlag, String materialParam, List<Long> depotList, List<Long> depotFList,
                                  String remark) throws Exception;

    DepotHeadVo4InDetail findAllocationStatistic(String beginTime, String endTime, String subType, String number,
                                                 String[] creatorArray, List<Long> categoryList, Boolean forceFlag, String materialParam, List<Long> depotList, List<Long> depotFList,
                                                 String remark) throws Exception;

    List<DepotHeadVo4StatementAccount> getStatementAccount(String beginTime, String endTime, Integer organId, String[] organArray,
                                                           Integer hasDebt, String supplierType, String type, String subType, String typeBack,
                                                           String subTypeBack, String billType, Integer offset, Integer rows);

    int getStatementAccountCount(String beginTime, String endTime, Integer organId, String[] organArray,
                                 Integer hasDebt, String supplierType, String type, String subType, String typeBack, String subTypeBack, String billType);

    List<DepotHeadVo4StatementAccount> getStatementAccountTotalPay(String beginTime, String endTime, Integer organId, String[] organArray,
                                                                   Integer hasDebt, String supplierType, String type, String subType,
                                                                   String typeBack, String subTypeBack, String billType);

    List<DepotHeadVo4List> getDetailByNumber(String number, HttpServletRequest request)throws Exception;

    List<DepotHead> getListByLinkNumberExceptCurrent(String linkNumber, String number, String type)throws Exception;

    List<DepotHead> getListByLinkApplyExceptCurrent(String linkApply, String number, String type)throws Exception;

    List<DepotHead> getBillListByLinkNumberList(List<String> linkNumberList)throws Exception;

    List<DepotHead> getBillListByLinkNumber(String linkNumber)throws Exception;

    /**
     * 新增单据主表及单据子表信息
     * @param beanJson 主表信息
     * @param rows  子表信息
     */
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void addDepotHeadAndDetail(String beanJson, String rows,
                               HttpServletRequest request) throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void updateDepotHeadAndDetail(String beanJson, String rows, HttpServletRequest request)throws Exception;

    Map<String, Object> getBuyAndSaleStatistics(String today, String monthFirstDay, String yesterdayBegin, String yesterdayEnd,
                                                String yearBegin, String yearEnd, HttpServletRequest request) throws Exception;

    DepotHead getDepotHead(String number)throws Exception;

    List<DepotHeadVo4List> debtList(Long organId, String materialParam, String number, String beginTime, String endTime,
                                    String status, Integer offset, Integer rows);

    int debtListCount(Long organId, String materialParam, String number, String beginTime, String endTime,
                      String status);

    void debtExport(Long organId, String materialParam, String number, String type, String subType,
                    String beginTime, String endTime, String status, String mpList,
                    HttpServletRequest request, HttpServletResponse response);

    List<DepotHeadVo4List> parseDebtBillList(List<DepotHeadVo4List> list) throws Exception;

    String getBillCategory(String subType);

    List<DepotHeadVo4List> waitBillList(String number, String materialParam, String type, String subType,
                                        String beginTime, String endTime, String status, int offset, int rows);

    Long waitBillCount(String number, String materialParam, String type, String subType,
                       String beginTime, String endTime, String status);

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void batchAddDepotHeadAndDetail(String ids, HttpServletRequest request) throws Exception;


    String syncOrderToXsdd(DepotHeadXsddRequestVO depotHead, List<DepotItemXsddRequestVO> depotItemList) throws Exception;

    /**
     * 根据商品id查询最后一条商品订单
     * @param mid 商品ID
     * @return
     */
    DepotHead getDepotLastByMaterialId(long mid);

    /**
     * pda订单提交
     * @param pdaDepotHeadDTO
     * @return
     */
    boolean pdaOrderSubmit(PDADepotHeadDTO pdaDepotHeadDTO) throws Exception;
}
