package com.zcloud.modules.qps.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.datasource.annotation.DataSource;
import com.zcloud.modules.qps.dao.BusQpsLogDao;
import com.zcloud.modules.qps.entity.BusQpsLogEntity;
import com.zcloud.modules.qps.service.BusQpsLogService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author makejava
 * @Desc QPS购买记录(BusQpsLog)表服务实现类
 * @Date 2024-04-08 09:01:22
 */
@Service("busQpsLogService")
public class BusQpsLogServiceImpl extends ServiceImpl<BusQpsLogDao, BusQpsLogEntity> implements BusQpsLogService {

	@Resource
	private BusQpsLogDao busQpsLogDao;

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

		return baseMapper.selectOne(queryWrapper);
	}

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


   @Override
	public void delete(Integer qpsLogId,String userId){
		UpdateWrapper<BusQpsLogEntity> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("qps_log_id",qpsLogId);

		BusQpsLogEntity busQpsLog = new BusQpsLogEntity();

		this.update(busQpsLog, updateWrapper);
	}
	@Override
	public BusQpsLogEntity getInfoById(Integer qpsLogId){
		return busQpsLogDao.getInfoById(qpsLogId);
	}

	@Override
	@DataSource("slave1")
	public BusQpsLogEntity info(String orderId) {
		return baseMapper.selectById(orderId);
	}
}
