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.DateUtil;
 import com.zcloud.common.utils.PageUtils;
 import com.zcloud.modules.feedback.dao.BusFeedbackDao;
 import com.zcloud.modules.feedback.dao.BusFeedbackReplyDao;
 import com.zcloud.modules.feedback.entity.BusFeedbackEntity;
 import com.zcloud.modules.feedback.entity.BusFeedbackReplyEntity;
 import com.zcloud.modules.feedback.service.BusFeedbackReplyService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

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

/**
 * @Author wangpeng
 * @Desc 意见反馈-回复表(BusFeedbackReply)表服务实现类
 * @Date 2024-03-30 15:20:00
 */
@Service("busFeedbackReplyService")
public class BusFeedbackReplyServiceImpl extends ServiceImpl<BusFeedbackReplyDao, BusFeedbackReplyEntity> implements BusFeedbackReplyService {

    @Autowired
    private BusFeedbackDao busFeedbackDao;


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

		return baseMapper.selectOne(queryWrapper);
	}

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

    public void saveFeedbackReply(BusFeedbackReplyEntity param) throws Exception {
        save(param);
        BusFeedbackEntity entity = new BusFeedbackEntity();
        entity.setStatus("1");
        entity.setOperatTime(DateUtil.date2Str(new Date()));
        entity.setFeedbackId(param.getFeedbackId());
        busFeedbackDao.update(entity);
    }


   @Override
	public void delete(String feedbackReplyId,String userId){
		UpdateWrapper<BusFeedbackReplyEntity> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("feedback_reply_id",feedbackReplyId);

		BusFeedbackReplyEntity busFeedbackReply = new BusFeedbackReplyEntity();
		busFeedbackReply.setOperator(userId);
		busFeedbackReply.setIsDelete(1);

		this.update(busFeedbackReply, updateWrapper);
	}
}
