package org.dromara.system.service.impl;

import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.system.domain.bo.ImgTypeBo;
import org.dromara.system.domain.bo.ResponseBo;
import org.dromara.system.domain.bo.SysImgBo;
import org.springframework.stereotype.Service;
import org.dromara.system.domain.bo.RegionFacilitiesBo;
import org.dromara.system.domain.vo.RegionFacilitiesVo;
import org.dromara.system.domain.RegionFacilities;
import org.dromara.system.mapper.RegionFacilitiesMapper;
import org.dromara.system.service.IRegionFacilitiesService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author Lion Li
 * @date 2024-12-16
 */
@RequiredArgsConstructor
@Service
public class RegionFacilitiesServiceImpl implements IRegionFacilitiesService {

    private final RegionFacilitiesMapper baseMapper;

    /**
     * 查询【请填写功能名称】
     */
    @Override
    public RegionFacilitiesVo queryById(String regionId){
        return baseMapper.selectVoById(regionId);
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @Override
    public TableDataInfo<RegionFacilitiesVo> queryPageList(RegionFacilitiesBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<RegionFacilities> lqw = buildQueryWrapper(bo);
        Page<RegionFacilitiesVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @Override
    public List<RegionFacilitiesVo> queryList(RegionFacilitiesBo bo) {
        LambdaQueryWrapper<RegionFacilities> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<RegionFacilities> buildQueryWrapper(RegionFacilitiesBo bo) {
        //Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<RegionFacilities> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getRegionId()), RegionFacilities::getRegionId, bo.getRegionId());
        return lqw;
    }

    /**
     * 新增【请填写功能名称】
     */
    @Override
    public Boolean insertByBo(RegionFacilitiesBo bo) {
        RegionFacilities add = MapstructUtils.convert(bo, RegionFacilities.class);
        validEntityBeforeSave(add);
        return baseMapper.insert(add) > 0;
    }

    /**
     * 修改【请填写功能名称】
     */
    @Override
    public Boolean updateByBo(RegionFacilitiesBo bo) {
        RegionFacilities update = MapstructUtils.convert(bo, RegionFacilities.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(RegionFacilities entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除【请填写功能名称】
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    public Boolean batchDelete(List<String> list) {
        return baseMapper.batchDelete(list);
    }


}
