package com.ruoyi.web.work.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.work.domain.Feedback;
import com.ruoyi.web.work.mapper.FeedbackMapper;
import com.ruoyi.web.work.service.IFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.rmi.ServerException;
import java.util.List;

/**
 * @author lsw
 * @date 2024-04-24
 */
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements IFeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    @Override
    public List<Feedback> selectList(Feedback feedback) {
        return feedbackMapper.selectList(feedback);
    }

    @Override
    public AjaxResult add(Feedback feedback) throws ServerException {
        feedback.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        feedback.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        feedback.setState(0);
        feedback.setMsg(null);
        if (!save(feedback)) {
            throw new ServerException("提交问题失败,请联系平台");
        }
        return AjaxResult.success();
    }

    @Override
    public boolean delByUser(Long id) {
        Feedback feedback = new Feedback();
        feedback.setId(id);
        feedback.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        return feedbackMapper.delByUser(feedback);
    }
}
