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.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zcloud.common.utils.PageUtils;
import com.zcloud.modules.kangzai.dao.BusEmergencyStorageDao;
import com.zcloud.modules.kangzai.entity.BusEmergencyStorageEntity;
import com.zcloud.modules.kangzai.service.BusEmergencyStorageService;
import org.springframework.stereotype.Service;

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

/**
 * @Author fangjiakai
 * @Desc 应急储备库信息表(BusEmergencyStorage)表服务实现类
 * @Date 2025-06-09 10:14:58
 */
@Service("busEmergencyStorageService")
public class BusEmergencyStorageServiceImpl extends ServiceImpl<BusEmergencyStorageDao, BusEmergencyStorageEntity> implements BusEmergencyStorageService {

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

        return baseMapper.selectOne(queryWrapper);
    }

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


    @Override
    public void delete(String emergencyStorageId, String userId) {
        UpdateWrapper<BusEmergencyStorageEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("emergency_storage_id", emergencyStorageId);

        BusEmergencyStorageEntity busEmergencyStorage = new BusEmergencyStorageEntity();
        busEmergencyStorage.setOperator(userId);
        busEmergencyStorage.setIsDelete(1);

        this.update(busEmergencyStorage, updateWrapper);
    }
}
