package com.unis.module.coding.dal.mysql.caxx;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.unis.framework.common.pojo.PageResult;
import com.unis.framework.mybatis.core.mapper.BaseMapperX;
import com.unis.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.unis.module.coding.controller.admin.caxx.vo.CaxxPageReqVO;
import com.unis.module.coding.controller.admin.delivery.vo.SparePageReqVO;
import com.unis.module.coding.controller.admin.delivery.vo.SpareRespVO;
import com.unis.module.coding.controller.admin.delivery.vo.StorePageReqVO;
import com.unis.module.coding.controller.admin.delivery.vo.StoreRespVO;
import com.unis.module.coding.dal.dataobject.caxx.CaxxDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 仓廒信息; Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface CaxxMapper extends BaseMapperX<CaxxDO> {

    default PageResult<CaxxDO> selectPage(CaxxPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CaxxDO>()
                .eqIfPresent(CaxxDO::getKqid, reqVO.getKqid())
                .eqIfPresent(CaxxDO::getKqmc, reqVO.getKqmc())
                .eqIfPresent(CaxxDO::getCfmc, reqVO.getCfmc())
                .eqIfPresent(CaxxDO::getCfbm, reqVO.getCfbm())
                .eqIfPresent(CaxxDO::getAjmc, reqVO.getAjmc())
                .eqIfPresent(CaxxDO::getAjbm, reqVO.getAjbm())
                .eqIfPresent(CaxxDO::getCamc, reqVO.getCamc())
                .eqIfPresent(CaxxDO::getCflx, reqVO.getCflx())
                .eqIfPresent(CaxxDO::getSjcr, reqVO.getSjcr())
                .eqIfPresent(CaxxDO::getSjsynx, reqVO.getSjsynx())
                .eqIfPresent(CaxxDO::getCazt, reqVO.getCazt())
                .eqIfPresent(CaxxDO::getJfsyrq, reqVO.getJfsyrq())
                .eqIfPresent(CaxxDO::getQtcxsm, reqVO.getQtcxsm())
                .eqIfPresent(CaxxDO::getBz, reqVO.getBz())
                .betweenIfPresent(CaxxDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(CaxxDO::getCfcht, reqVO.getCfcht())
                .eqIfPresent(CaxxDO::getCfcxt, reqVO.getCfcxt())
                .eqIfPresent(CaxxDO::getYxcf, reqVO.getYxcf())
                .orderByDesc(CaxxDO::getId));
    }

    Page<SpareRespVO> getDeliverySparePage(Page<Object> objectPage, @Param("pageReqVO")SparePageReqVO pageReqVO);

    Page<SpareRespVO> selectWrapperPageForBank(Page<Object> objectPage, @Param("pageReqVO")SparePageReqVO pageReqVO);

    Page<SpareRespVO> selectWrapperPageForSheng(Page<Object> objectPage, @Param("pageReqVO")SparePageReqVO pageReqVO);

    default List<CaxxDO> selectList(StorePageReqVO pageReqVO) {
          List<CaxxDO> caxxList = selectList(
                new LambdaQueryWrapperX<CaxxDO>()
                        .eqIfPresent(CaxxDO::getKqid, pageReqVO.getKqId())
                        .eqIfPresent(CaxxDO::getCflx, pageReqVO.getCflx())
                        .eqIfPresent(CaxxDO::getCazt, pageReqVO.getCfzt())
                        .between(pageReqVO.getCfStart() != null && pageReqVO.getCfEnd() != null,CaxxDO::getSjcr, pageReqVO.getCfStart(), pageReqVO.getCfEnd())
                        .le(pageReqVO.getCfStart() == null && pageReqVO.getCfEnd() != null,CaxxDO::getSjcr, pageReqVO.getCfEnd())
                        .ge(pageReqVO.getCfStart() != null && (pageReqVO.getCfEnd() == null ),CaxxDO::getSjcr, pageReqVO.getCfStart())
        );
        return caxxList;
    }
   int deleteListByKqId(@Param("kqId")Long  kqId) ;
   int deleteByIds(@Param("ids")List<Long> ids);

    Page<SpareRespVO> getIdentifySparePage(Page<Object> objectPage, @Param("pageReqVO")SparePageReqVO pageReqVO);

    Page<SpareRespVO> getIdentifyPageForBank(Page<Object> objectPage, @Param("pageReqVO")SparePageReqVO pageReqVO);

    Page<SpareRespVO> getIdentifyPageForSheng(Page<Object> objectPage, @Param("pageReqVO")SparePageReqVO pageReqVO);

    List<StoreRespVO> selectListForIdentify(@Param("kqId")Long  kqId,@Param("yhmc") String yhmc);
    List<StoreRespVO> selectListForSelect(@Param("kqId")Long  kqId,@Param("yhmc") String yhmc);

    Page<SpareRespVO> getSelectSparePage(Page<Object> objectPage, @Param("pageReqVO")SparePageReqVO pageReqVO);

    Page<SpareRespVO> getSelectPageForBank(Page<Object> objectPage, @Param("pageReqVO")SparePageReqVO pageReqVO);

    Page<SpareRespVO> getSelectPageForSheng(Page<Object> objectPage, @Param("pageReqVO")SparePageReqVO pageReqVO);

    default  List<CaxxDO> selectListByKqId(Long kqId){
        List<CaxxDO> caxxList = selectList(
                new LambdaQueryWrapperX<CaxxDO>()
                        .eqIfPresent(CaxxDO::getKqid, kqId)
        );
        return caxxList;
    }
}