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.BusMountainFloodVillageDao;
import com.zcloud.modules.kangzai.entity.BusMountainFloodVillageEntity;
import com.zcloud.modules.kangzai.service.BusMountainFloodVillageService;
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 山洪灾害村基本信息表(BusMountainFloodVillage)表服务实现类
 * @Date 2025-06-09 10:14:59
 */
@Service("busMountainFloodVillageService")
public class BusMountainFloodVillageServiceImpl extends ServiceImpl<BusMountainFloodVillageDao, BusMountainFloodVillageEntity> implements BusMountainFloodVillageService {

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

        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<BusMountainFloodVillageEntity> queryListByFlexibleParams(String paramName, Object paramValue) {
        QueryWrapper<BusMountainFloodVillageEntity> 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<BusMountainFloodVillageEntity> ipage = baseMapper.listPage(page, params);
        return new PageUtils(ipage);
    }


    @Override
    public void delete(String mountainFloodVillageId, String userId) {
        UpdateWrapper<BusMountainFloodVillageEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("mountain_flood_village_id", mountainFloodVillageId);

        BusMountainFloodVillageEntity busMountainFloodVillage = new BusMountainFloodVillageEntity();
        busMountainFloodVillage.setOperator(userId);
        busMountainFloodVillage.setIsDelete(1);

        this.update(busMountainFloodVillage, updateWrapper);
    }
}
