package cn.superdesk.uniorder.service.order.base;

import cn.superdesk.uniorder.common.enums.common.CommonAccountingStateEnum;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.base.UnifiedOrder;
import cn.superdesk.uniorder.dao.entity.base.UnifiedOrderGoods;
import cn.superdesk.uniorder.dao.entity.invoice.customer.InvoiceApplyXGoods;
import cn.superdesk.uniorder.dto.param._function.select.SelectOptionDepartmentCriteria;
import cn.superdesk.uniorder.dto.param.accounting.unified.supplier.AccountingSupplierNotYetDimGoodsQueryCriteria;
import cn.superdesk.uniorder.dto.param.accounting.unified.supplier.SuplierStatementOfAccountDetailQueryCriteria;
import cn.superdesk.uniorder.dto.vo._function.select.SelectOptionDepartment;
import cn.superdesk.uniorder.dto.vo.accounting.unified.customer.notyet.CustomerUnAccountingDimGoodsVo;
import cn.superdesk.uniorder.dto.vo.accounting.unified.customer.notyet.UnifiedOrderCustomerHeadSumVo;
import cn.superdesk.uniorder.dto.vo.accounting.unified.customer.notyet.UnifiedOrderCustomerNotCheckVo;
import cn.superdesk.uniorder.dto.vo.accounting.unified.supplier.notyet.UnifiedOrderJoinGoodsOfSupplierStatementOfAccountVo;
import cn.superdesk.uniorder.dto.vo.accounting.unified.supplier.notyet.UnifiedOrderSupplierHeadSumVo;
import cn.superdesk.uniorder.dto.vo.order.Org2VirtStatisticsVo;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedOrderCommonHeadSum;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedOrderGoodsVo;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedOrderSupplierDimOrderNotCheckVo;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedOrderSupplierNotCheckDetail2GoodsVo;
import cn.superdesk.uniorder.dto.vo.wechat.WxBillOrder;
import cn.superdesk.uniorder.service.base.BaseService;

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

/**
 * @Description: 基本数据 订单
 * @Author: linjinyu 重构 完善
 * @CreateDate: 2021/1/6 下午8:56
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/1/6 下午8:56
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public interface UnifiedOrderService extends BaseService<UnifiedOrder> {

    List<SelectOptionDepartment> getSelectPurchaseDepartment(SelectOptionDepartmentCriteria criteria, LoginSysUser loginSysUser);

    UnifiedOrder addObjTran(UnifiedOrder order, List<UnifiedOrderGoods> unifiedOrderGoodsList);

    /**
     * 单主体情况
     * 根据 orderSn 得出 订单 entity (此订单包含正负的商品)
     * <p>
     * 双主体情况
     * (假定是正单号) 根据 orderSn 得出 正订单 entity
     * (假定是退单号) 根据 orderSn 得出 退订单 entity
     *
     * @param orderSn
     * @return
     */
    UnifiedOrder findByOrderSn(String orderSn);

    /**
     * 单主体情况
     * 得不出
     * <p>
     * 双主体情况
     * 根据 正单 orderSn 找 订单表.refund_order_sn 字段 得出 退单List
     * 根据 退单 orderSn 找 订单表.refund_order_sn 字段 得出 正单List
     *
     * @param orderSn
     * @return
     */
    List<UnifiedOrder> findByRefundOrderSn(String orderSn);

    List<UnifiedOrder> findByRefundOrderSnAndSaleId(String orderSn, Long saleId);

    UnifiedOrder findByJdOrderSn(String jdOrderSn);

    UnifiedOrder findByJdOrderSnAndSaleId(String jdOrderSn, Long saleId);

    List<UnifiedOrder> findAll(Map<String, Object> queryMap);

    Integer countAll(Map<String, Object> queryMap);


    /****************************************** 供应商结算 dim order 未对账 订单 start ******************************************/

    UnifiedOrderSupplierHeadSumVo getSupplierUnAccountingDimOrderHeadSum(Map<String, Object> params);

    R<List<UnifiedOrderSupplierDimOrderNotCheckVo>> getSupplierUnAccountingDimOrderList(Map<String, Object> params, int pageNum, int pageSize);

    List<UnifiedOrderSupplierDimOrderNotCheckVo> getSupplierUnAccountingDimOrderList(Map<String, Object> params);

    List<UnifiedOrderSupplierNotCheckDetail2GoodsVo> getSupplierUnAccountingDetail2Goods(Map<String, Object> params);

    /****************************************** 供应商结算 dim order 未对账 订单   end ******************************************/


    /****************************************** 供应商结算 dim goods 未对账 商品 start ******************************************/

    UnifiedOrderSupplierHeadSumVo getSupplierUnAccountingDimGoodsHeadSum(AccountingSupplierNotYetDimGoodsQueryCriteria criteria);

    List<UnifiedOrderJoinGoodsOfSupplierStatementOfAccountVo> getSupplierUnAccountingDimGoodsList(AccountingSupplierNotYetDimGoodsQueryCriteria criteria, LoginSysUser loginSysUser);

    /**
     * 已添加 数据脱敏逻辑 20211203
     *
     * @param criteria
     * @param loginSysUser
     * @return
     */
    R<List<UnifiedOrderJoinGoodsOfSupplierStatementOfAccountVo>> getSupplierUnAccountingDimGoodsListByPageQuery(AccountingSupplierNotYetDimGoodsQueryCriteria criteria, LoginSysUser loginSysUser);

    /****************************************** 供应商结算 dim goods 未对账 商品   end ******************************************/

    /****************************************** 供应商结算 对账单详情 start ******************************************/

    List<UnifiedOrderJoinGoodsOfSupplierStatementOfAccountVo> getSupplierStatementOfAccountDetailDimOrder2Goods(SuplierStatementOfAccountDetailQueryCriteria queryCriteria, LoginSysUser loginSysUser);

    /**
     * 已添加 数据脱敏逻辑 20211203
     *
     * @param accountingOrderSn
     * @param loginSysUser
     * @return
     */
    List<UnifiedOrderJoinGoodsOfSupplierStatementOfAccountVo> getSupplierStatementOfAccountDetailDimGoods2Goods(String accountingOrderSn, LoginSysUser loginSysUser);

    /****************************************** 供应商结算 对账单详情   end ******************************************/


    /****************************************** 关于 供应商结算 对账单 设置 对账状态 或 恢复 对账状态 start ******************************************/

    int updateAccountingStateSupplierBySysUnifiedOrderIds(List<Long> sysUnifiedOrderIds, CommonAccountingStateEnum state);

    int updateAccountingStateSupplierByOrderSns(List<String> orderSns, CommonAccountingStateEnum state);

    /****************************************** 关于 供应商结算 对账单 设置 对账状态 或 恢复 对账状态   end ******************************************/

    /****************************************** 关于 客户结算 对账单 设置 对账状态 或 恢复 对账状态 start ******************************************/

    void updateAccountingStateCustomerBySysUnifiedOrderIds(List<Long> sysUnifiedOrderIds, CommonAccountingStateEnum state);

    void updateAccountingStateCustomerByOrderSns(List<String> orderSns, CommonAccountingStateEnum state);

    /****************************************** 关于 客户结算 对账单 设置 对账状态 或 恢复 对账状态   end ******************************************/


    /****************************************** 客户结算 dim order 未对账 订单 start ******************************************/

    UnifiedOrderCommonHeadSum getCustomerUnAccountingDimOrderHeadSum(Map<String, Object> params);

    List<UnifiedOrderCustomerNotCheckVo> getCustomerUnAccountingDimOrderList(Map<String, Object> params);

    R<List<UnifiedOrderCustomerNotCheckVo>> getCustomerUnAccountingDimOrderList(Map<String, Object> params, int pageNum, int pageSize);

    /****************************************** 客户结算 dim order 未对账 订单   end ******************************************/

    /****************************************** 客户结算 dim goods 未对账 商品 start ******************************************/

    UnifiedOrderCustomerHeadSumVo getCustomerUnAccountingDimGoodsHeadSum(Map<String, Object> params, LoginSysUser loginSysUser);

    List<CustomerUnAccountingDimGoodsVo> getCustomerUnAccountingDimGoodsList(Map<String, Object> params, LoginSysUser loginSysUser);

    R<List<CustomerUnAccountingDimGoodsVo>> getCustomerUnAccountingDimGoodsList(Map<String, Object> params, int pageNo, int pageSize, LoginSysUser loginSysUser);

    /****************************************** 客户结算 dim goods 未对账 商品   end ******************************************/


    /****************************************** 订单管理 start ******************************************/

    UnifiedOrderCommonHeadSum getOrderManagerGoodsPageHead(Map<String, Object> params);

    List<UnifiedOrderGoodsVo> getOrderManagerGoodsView(Map<String, Object> params);

    R<List<Org2VirtStatisticsVo>> getOrg2VirtStatistics(Map<String, Object> params, int pageNum, int pageSize);

    R<List<UnifiedOrderGoodsVo>> getOrderManagerGoodsByPage(Map<String, Object> params, int pageNum, int pageSize);

    /****************************************** 订单管理   end ******************************************/

    /****************************************** 订单 状态 回款状态 start ******************************************/

    void updateFieldBackAccountStatusByInvoiceX(List<InvoiceApplyXGoods> invoiceX);

    /****************************************** 订单 状态 回款状态   end ******************************************/


    BigDecimal getAmount(Map<String, Object> query);

    BigDecimal getPayAmount(Map<String, Object> upaymap);

    Integer getOrderCount(Map<String, Object> queryMap);

    List<WxBillOrder> getVirtOrder(Map<String, Object> params);

    /**
     * 存在问题 这个是什么对账单
     *
     * @param params
     * @return
     */
    List<UnifiedOrder> findByDzId(Map<String, Object> params);

    List<UnifiedOrder> findBySysUnifiedOrderIds(List<Long> sysUnifiedOrderIds);

    List<UnifiedOrder> findByOrderSns(List<String> orderSns);


    /****************************************** 工具方法 sysUnifiedOrderIds 推导 start ******************************************/

    List<String> convertSysUnifiedOrderIds2OrderSn(List<Long> sysUnifiedOrderIds);

    Map<Long, String> convertSysUnifiedOrderIds2MapSysUnifiedOrderId2OrderSn(List<Long> sysUnifiedOrderIds);

    Map<Long, UnifiedOrder> convertSysUnifiedOrderIds2MapSysUnifiedOrderId2Entity(List<Long> sysUnifiedOrderIds);

    Map<String, UnifiedOrder> convertSysUnifiedOrderIds2MapOrderSn2Entity(List<Long> sysUnifiedOrderIds);

    Map<String, Long> convertSysUnifiedOrderIds2MapOrderSn2SysUnifiedOrderId(List<Long> sysUnifiedOrderIds);

    /****************************************** 工具方法 sysUnifiedOrderIds 推导   end ******************************************/

    /****************************************** 工具方法 orderSns 推导 start ******************************************/

    Map<String, Long> convertOrderSns2MapOrderSn2SysUnifiedOrderId(List<String> orderSns);

    void deleteUnifiedOrderBatch(List<String> processOrderSn);

    void deleteUnifiedOrderBatchByOrderIds(List<Long> orderIds);

    /****************************************** 工具方法 orderSns 推导   end ******************************************/
}
