package com.fjhx.common.service.problem.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.common.entity.problem.dto.ProblemFeedbackDto;
import com.fjhx.common.entity.problem.dto.ProblemFeedbackSelectDto;
import com.fjhx.common.entity.problem.po.ProblemFeedback;
import com.fjhx.common.entity.problem.vo.ProblemFeedbackVo;
import com.fjhx.common.mapper.problem.ProblemFeedbackMapper;
import com.fjhx.common.service.problem.ProblemFeedbackService;
import com.ruoyi.common.constant.StatusConstant;
import com.ruoyi.common.utils.wrapper.IWrapper;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 问题反馈 服务实现类
 * </p>
 *
 * @author
 * @since 2023-05-04
 */
@Service
public class ProblemFeedbackServiceImpl extends ServiceImpl<ProblemFeedbackMapper, ProblemFeedback> implements ProblemFeedbackService {

    @Override
    public Page<ProblemFeedbackVo> getPage(ProblemFeedbackSelectDto dto) {
        IWrapper<ProblemFeedback> wrapper = getWrapper();
        wrapper.eq("pf", ProblemFeedback::getTenantId, dto.getTenantId());
        wrapper.eq("pf", ProblemFeedback::getStatus, dto.getStatus());
        wrapper.orderByDesc("pf", ProblemFeedback::getId);
        Page<ProblemFeedbackVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

    @Override
    public ProblemFeedbackVo detail(Long id) {
        ProblemFeedback ProblemFeedback = this.getById(id);
        ProblemFeedbackVo result = BeanUtil.toBean(ProblemFeedback, ProblemFeedbackVo.class);
        return result;
    }

    @Override
    public void add(ProblemFeedbackDto problemFeedbackDto) {
        this.save(problemFeedbackDto);
    }

    @Override
    public void edit(ProblemFeedbackDto problemFeedbackDto) {
        problemFeedbackDto.setStatus(StatusConstant.YES);
        this.updateById(problemFeedbackDto);
    }

}
