package com.zcloud.modules.kangzai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcloud.common.utils.PageUtils;
import com.zcloud.modules.kangzai.dao.BusRiverRiskVillagesDao;
import com.zcloud.modules.kangzai.entity.BusRiverRiskVillagesEntity;
import com.zcloud.modules.kangzai.service.BusRiverRiskVillagesService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

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

/**
 * @Author fangjiakai
 * @Desc 河道行洪隐患区村庄清单(BusRiverRiskVillages)表服务实现类
 * @Date 2025-06-09 09:44:25
 */
@Service("busRiverRiskVillagesService")
public class BusRiverRiskVillagesServiceImpl extends ServiceImpl<BusRiverRiskVillagesDao, BusRiverRiskVillagesEntity> implements BusRiverRiskVillagesService {

    @Override
    public BusRiverRiskVillagesEntity queryByFlexibleParams(String paramName, Object paramValue) {
        QueryWrapper<BusRiverRiskVillagesEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(paramName, paramValue); // 根据传入的参数名和参数值动态构建查询条件

        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<BusRiverRiskVillagesEntity> queryListByFlexibleParams(String paramName, Object paramValue) {
        QueryWrapper<BusRiverRiskVillagesEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(paramName, paramValue); // 根据传入的参数名和参数值动态构建查询条件

        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public PageUtils listPage(Map<String, Object> params) {
        Page<Map<String, Object>> page = new Page<>(Integer.parseInt(params.get("curPage").toString()), Integer.parseInt(params.get("limit").toString()));
        params.put("isDelete", 0);
        IPage<BusRiverRiskVillagesEntity> ipage = baseMapper.listPage(page, params);
        return new PageUtils(ipage);
    }


    @Override
    public void delete(String riverRiskVillagesId, String userId) {
        UpdateWrapper<BusRiverRiskVillagesEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("river_risk_villages_id", riverRiskVillagesId);

        BusRiverRiskVillagesEntity busRiverRiskVillages = new BusRiverRiskVillagesEntity();
        busRiverRiskVillages.setIsDelete(1);

        this.update(busRiverRiskVillages, updateWrapper);
    }
}
