package cn.iocoder.yudao.module.member.dal.mysql.storegoodsinventoryrecord;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.member.dal.dataobject.storegoodsinventoryrecord.StoreGoodsInventoryRecordDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.member.controller.admin.storegoodsinventoryrecord.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 商品出入库记录 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface StoreGoodsInventoryRecordMapper extends BaseMapperX<StoreGoodsInventoryRecordDO> {

    default PageResult<StoreGoodsInventoryRecordDO> selectPage(StoreGoodsInventoryRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<StoreGoodsInventoryRecordDO>()
                .eqIfPresent(StoreGoodsInventoryRecordDO::getGoodsId, reqVO.getGoodsId())
                .eqIfPresent(StoreGoodsInventoryRecordDO::getCarteenId, reqVO.getCarteenId())
                .eqIfPresent(StoreGoodsInventoryRecordDO::getNumber, reqVO.getNumber())
                .eqIfPresent(StoreGoodsInventoryRecordDO::getWeight, reqVO.getWeight())
                .eqIfPresent(StoreGoodsInventoryRecordDO::getType, reqVO.getType())
                .eqIfPresent(StoreGoodsInventoryRecordDO::getOutType, reqVO.getOutType())
                .betweenIfPresent(StoreGoodsInventoryRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StoreGoodsInventoryRecordDO::getId));
    }


    @Select({"<script>",
            "select sum(price*number) from member_store_goods_inventory_record",
            "where type = #{type} ",
            "and DATE_FORMAT(create_time, '%Y-%m-%d') between #{vo.startTime} and #{vo.endTime}",
            "<if test='vo.carteenId != null '>",
            "and carteen_id = #{vo.carteenId}",
            "</if>",
            "<if test='vo.goodsName != null and vo.goodsName != \"\"'>",
            "and goods_name LIKE concat('%',#{vo.goodsName},'%')",
            "</if>",
            "</script>"})
    Double count(@Param("type") Integer type,@Param("vo") InventoryRecordPageReqVO pageReqVO);
}