package com.zcloud.modules.feedback.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.feedback.dao.BusFeedbackDao;
 import com.zcloud.modules.feedback.entity.BusFeedbackEntity;
 import com.zcloud.modules.feedback.service.BusFeedbackService;
 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 wangpeng
 * @Desc 意见反馈表(BusFeedback)表服务实现类
 * @Date 2024-03-30 15:19:59
 */
@Service("busFeedbackService")
public class BusFeedbackServiceImpl extends ServiceImpl<BusFeedbackDao, BusFeedbackEntity> implements BusFeedbackService {

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

		return baseMapper.selectOne(queryWrapper);
	}

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

		return baseMapper.selectList(queryWrapper);
	}

    @Override
    @DataSource("slave1")
    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<BusFeedbackEntity> ipage = baseMapper.listPage(page,params);
        return new PageUtils(ipage);
    }


   @Override
	public void delete(String feedbackId,String userId){
		UpdateWrapper<BusFeedbackEntity> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("feedback_id",feedbackId);

		BusFeedbackEntity busFeedback = new BusFeedbackEntity();
		busFeedback.setOperator(userId);
		busFeedback.setIsDelete(1);

		this.update(busFeedback, updateWrapper);
	}

    @Override
    @DataSource("slave1")
    public BusFeedbackEntity replyInfo(String feedbackId) {

        return baseMapper.replyInfo(feedbackId);
    }
}
