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

import java.util.*;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.unis.framework.common.pojo.PageResult;
import com.unis.framework.common.util.object.ObjectUtils;
import com.unis.framework.mybatis.core.mapper.BaseMapperX;
import com.unis.framework.mybatis.core.query.LambdaQueryWrapperX;
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.controller.admin.province.vo.ProvincePageReqVO;
import com.unis.module.coding.dal.dataobject.bank.BankDO;
import com.unis.module.coding.dal.dataobject.caxx.CaxxDO;
import com.unis.module.coding.dal.dataobject.province.ProvinceDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;


/**
 * 省已选 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface ProvinceMapper extends BaseMapperX<ProvinceDO> {

    default PageResult<ProvinceDO> selectPage(ProvincePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProvinceDO>()
                .eqIfPresent(ProvinceDO::getKqId, reqVO.getKqId())
                .eqIfPresent(ProvinceDO::getCaId, reqVO.getCaId())
                .betweenIfPresent(ProvinceDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ProvinceDO::getHyryId, reqVO.getHyryId())
                .likeIfPresent(ProvinceDO::getHyryName, reqVO.getHyryName())
                .eqIfPresent(ProvinceDO::getHyState, reqVO.getHyState())
                .eqIfPresent(ProvinceDO::getFileIds, reqVO.getFileIds())
                .orderByDesc(ProvinceDO::getId));
    }

    default void updateByKqId(ProvinceDO provinceDO,Long kqId){
        update(provinceDO, new LambdaQueryWrapperX<ProvinceDO>().eq(ProvinceDO::getKqId,kqId));
    }
    default List<ProvinceDO> selectListByKqId(Long  kqId) {
        List<ProvinceDO> provinceList = selectList(
                new LambdaQueryWrapperX<ProvinceDO>()
                        .eqIfPresent(ProvinceDO::getKqId, kqId)

        );
        return provinceList;
    }

    default List<ProvinceDO> selectListBycaIds(List<Long>  caIds) {
        return selectList(
                new LambdaQueryWrapperX<ProvinceDO>()
                        .inIfPresent(ProvinceDO::getCaId, caIds)

        );
    }


    default int deleteListByKqIdAndCaIds(Long  kqId, List<Long> caIds) {
        return delete(
                new LambdaUpdateWrapper<ProvinceDO>()
                        .eq(kqId!=null,ProvinceDO::getKqId, kqId)
                        .in(!ObjectUtil.isEmpty(caIds),ProvinceDO::getCaId, caIds)

        );
    }
    List<StoreRespVO> getStoreListForProvinceOnly(@Param("kqId") Long  kqId,@Param("type")Integer type);

    List<StoreRespVO> getStoreListForProvince(@Param("pageReqVO") StorePageReqVO pageReqVO);
    default int deleteListByKqIds(List<Long> kqIds) {
        return delete(
                new LambdaUpdateWrapper<ProvinceDO>()
                        .in(!ObjectUtil.isEmpty(kqIds),ProvinceDO::getKqId, kqIds)
        );
    }
}