package com.yueqian.xingyun.sc.mappers;

import com.lframework.starter.web.core.mapper.BaseMapper;
import com.lframework.starter.web.core.annotations.permission.DataPermission;
import com.lframework.starter.web.core.annotations.permission.DataPermissions;
import com.lframework.starter.web.core.annotations.sort.Sort;
import com.lframework.starter.web.core.annotations.sort.Sorts;
import com.lframework.starter.web.inner.components.permission.OrderDataPermissionDataPermissionType;
import com.lframework.starter.web.inner.components.permission.ProductDataPermissionDataPermissionType;
import com.yueqian.xingyun.sc.dto.sale.SaleOrderFullDto;
import com.yueqian.xingyun.sc.dto.sale.SaleOrderWithOutDto;
import com.yueqian.xingyun.sc.dto.sale.SaleProductDto;
import com.yueqian.xingyun.sc.entity.SaleOrder;
import com.yueqian.xingyun.sc.vo.sale.QuerySaleOrderVo;
import com.yueqian.xingyun.sc.vo.sale.QuerySaleOrderWithOutVo;
import com.yueqian.xingyun.sc.vo.sale.QuerySaleProductVo;
import com.yueqian.xingyun.sc.vo.sale.SaleOrderSelectorVo;
import java.util.List;
import org.apache.ibatis.annotations.Param;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author zmj
 * @since 2021-10-21
 */
public interface SaleOrderMapper extends BaseMapper<SaleOrder> {

  /**
   * 查询列表
   *
   * @param vo
   * @return
   */
  @Sorts({
      @Sort(value = "code", alias = "o", autoParse = true),
      @Sort(value = "createTime", alias = "o", autoParse = true),
  })
  @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = {
      @DataPermission(template = "order", alias = "o")
  })
  List<SaleOrder> query(@Param("vo") QuerySaleOrderVo vo);

  /**
   * 根据ID查询
   *
   * @param id
   * @return
   */
  SaleOrderFullDto getDetail(String id);

  /**
   * 选择器
   *
   * @param vo
   * @return
   */
  @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = {
      @DataPermission(template = "order", alias = "o")
  })
  List<SaleOrder> selector(@Param("vo") SaleOrderSelectorVo vo);

  /**
   * 根据ID查询（出库业务）
   *
   * @param id
   * @return
   */
  SaleOrderWithOutDto getWithOut(@Param("id") String id, @Param("requireSale") Boolean requireSale);

  /**
   * 查询列表（出库业务）
   *
   * @param vo
   * @return
   */
  @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = {
      @DataPermission(template = "order", alias = "o")
  })
  List<SaleOrder> queryWithOut(@Param("vo") QuerySaleOrderWithOutVo vo,
      @Param("multipleRelate") boolean multipleRelate);

  /**
   * 根据关键字销售采购商品信息
   *
   * @param condition
   * @return
   */
  @DataPermissions(type = ProductDataPermissionDataPermissionType.class, value = {
      @DataPermission(template = "product", alias = "g"),
      @DataPermission(template = "brand", alias = "b"),
      @DataPermission(template = "category", alias = "c")
  })
  List<SaleProductDto> querySaleByCondition(
      @Param("condition") String condition, @Param("isReturn") Boolean isReturn);

  /**
   * 查询可销售商品信息
   *
   * @param vo
   * @return
   */
  @DataPermissions(type = ProductDataPermissionDataPermissionType.class, value = {
      @DataPermission(template = "product", alias = "g"),
      @DataPermission(template = "brand", alias = "b"),
      @DataPermission(template = "category", alias = "c")
  })
  List<SaleProductDto> querySaleList(@Param("vo") QuerySaleProductVo vo);

  /**
   * 根据ID查询
   *
   * @param id
   * @return
   */
  SaleProductDto getSaleById(String id);
}
