package com.djhk.uav.feedback.service.impl;


import com.djhk.common.core.domain.entity.SysUser;
import com.djhk.common.utils.DateUtils;
import com.djhk.common.utils.SecurityUtils;
import com.djhk.system.service.ISysUserService;
import com.djhk.uav.feedback.domain.QuestionFeedback;
import com.djhk.uav.feedback.mapper.QuestionFeedbackMapper;
import com.djhk.uav.feedback.service.IQuestionFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 问题反馈Service业务层处理
 * 
 * @author qpc
 * @date 2025-04-10
 */
@Service
public class QuestionFeedbackServiceImpl implements IQuestionFeedbackService
{
    @Autowired
    private QuestionFeedbackMapper questionFeedbackMapper;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询问题反馈
     * 
     * @param id 问题反馈主键
     * @return 问题反馈
     */
    @Override
    public QuestionFeedback selectQuestionFeedbackById(Long id)
    {
        return questionFeedbackMapper.selectQuestionFeedbackById(id);
    }

    /**
     * 查询问题反馈列表
     * 
     * @param questionFeedback 问题反馈
     * @return 问题反馈
     */
    @Override
    public List<QuestionFeedback> selectQuestionFeedbackList(QuestionFeedback questionFeedback)
    {
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        Long deptId = sysUser.getDeptId();
        if (deptId != 1)
        {
            questionFeedback.setDeptId(String.valueOf(deptId));
            return questionFeedbackMapper.selectQuestionFeedbackList(questionFeedback);
        }
        return questionFeedbackMapper.selectQuestionFeedbackList(questionFeedback);
    }

    /**
     * 新增问题反馈
     * 
     * @param questionFeedback 问题反馈
     * @return 结果
     */
    @Override
    public int insertQuestionFeedback(QuestionFeedback questionFeedback)
    {
//        SysUser sysUser = userService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        Long deptId = sysUser.getDeptId();
        questionFeedback.setDeptId(String.valueOf(deptId));
        questionFeedback.setCreateTime(DateUtils.getNowDate());
        questionFeedback.setCreateBy(sysUser.getNickName());
        return questionFeedbackMapper.insertQuestionFeedback(questionFeedback);
    }

    /**
     * 修改问题反馈
     * 
     * @param questionFeedback 问题反馈
     * @return 结果
     */
    @Override
    public int updateQuestionFeedback(QuestionFeedback questionFeedback)
    {
//        SysUser sysUser = userService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        questionFeedback.setUpdateBy(sysUser.getNickName());
        questionFeedback.setUpdateTime(DateUtils.getNowDate());
        return questionFeedbackMapper.updateQuestionFeedback(questionFeedback);
    }

    /**
     * 批量删除问题反馈
     * 
     * @param ids 需要删除的问题反馈主键
     * @return 结果
     */
    @Override
    public int deleteQuestionFeedbackByIds(Long[] ids)
    {
        return questionFeedbackMapper.deleteQuestionFeedbackByIds(ids);
    }

    /**
     * 删除问题反馈信息
     * 
     * @param id 问题反馈主键
     * @return 结果
     */
    @Override
    public int deleteQuestionFeedbackById(Long id)
    {
        return questionFeedbackMapper.deleteQuestionFeedbackById(id);
    }
}
