package com.jojubanking.boot.module.system.dal.mysql.childitem;

import java.util.*;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jojubanking.boot.framework.common.pojo.PageResult;
import com.jojubanking.boot.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.jojubanking.boot.framework.mybatis.core.mapper.BaseMapperX;
import com.jojubanking.boot.module.system.controller.app.xytjinfo.vo.ItemListReqVO;
import com.jojubanking.boot.module.system.dal.dataobject.childitem.ChilditemDO;
import com.jojubanking.boot.module.system.dal.dataobject.item.ItemDO;
import org.apache.ibatis.annotations.Mapper;
import com.jojubanking.boot.module.system.controller.admin.childitem.vo.*;

/**
 * 检查项目子 Mapper
 *
 * @author admin
 */
@Mapper
public interface ChilditemMapper extends BaseMapperX<ChilditemDO> {

    default PageResult<ChilditemDO> selectPage(ChilditemPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ChilditemDO>()
                .eqIfPresent(ChilditemDO::getPackageno, reqVO.getPackageno())
                .eqIfPresent(ChilditemDO::getItemflag, reqVO.getItemflag())
                .eqIfPresent(ChilditemDO::getItemno, reqVO.getItemno())
                .likeIfPresent(ChilditemDO::getItemname, reqVO.getItemname())
                .eqIfPresent(ChilditemDO::getItemprice, reqVO.getItemprice())
                .betweenIfPresent(ChilditemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ChilditemDO::getId));
    }

    default List<ChilditemDO> selectList(ChilditemExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ChilditemDO>()
                .eqIfPresent(ChilditemDO::getPackageno, reqVO.getPackageno())
                .eqIfPresent(ChilditemDO::getItemflag, reqVO.getItemflag())
                .eqIfPresent(ChilditemDO::getItemno, reqVO.getItemno())
                .likeIfPresent(ChilditemDO::getItemname, reqVO.getItemname())
                .eqIfPresent(ChilditemDO::getItemprice, reqVO.getItemprice())
                .betweenIfPresent(ChilditemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ChilditemDO::getId));
    }

    default List<ChilditemDO> selectSimpleList(ItemListReqVO reqVO) {
            return selectList(new LambdaQueryWrapperX<ChilditemDO>()
                    .eqIfPresent(ChilditemDO::getPackageno, reqVO.getPackageno())
                    .eqIfPresent(ChilditemDO::getItemflag, reqVO.getItemflag())
                    .eqIfPresent(ChilditemDO::getItemno, reqVO.getItemno())
                    .eqIfPresent(ChilditemDO::getDeleted, false)
                    .likeIfPresent(ChilditemDO::getItemname, reqVO.getItemname())
                    .orderByDesc(ChilditemDO::getId));
        }

    default void updateItemPriceByNo(ChilditemDO itemDO){
        update(itemDO, Wrappers.lambdaUpdate(ChilditemDO.class)
                .eq(ChilditemDO::getItemno, itemDO.getItemno()));
    }

}
