package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.complaintSuggestion.ComplaintSuggestion;
import com.ruoyi.system.domain.suggestionFj.SuggestionFj;
import com.ruoyi.system.mapper.ComplaintSuggestionMapper;
import com.ruoyi.system.mapper.SuggestionFjMapper;
import com.ruoyi.system.service.IComplaintSuggestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 投诉建议Service业务层处理
 * 
 * @author boman
 * @date 2025-02-14
 */
@Service
public class ComplaintSuggestionServiceImpl implements IComplaintSuggestionService 
{
    @Autowired
    private ComplaintSuggestionMapper complaintSuggestionMapper;

    @Autowired
    private SuggestionFjMapper suggestionFjMapper;

    /**
     * 查询投诉建议
     * 
     * @param suggestionId 投诉建议主键
     * @return 投诉建议
     */
    @Override
    public ComplaintSuggestion selectComplaintSuggestionBySuggestionId(Long suggestionId)
    {
        ComplaintSuggestion complaintSuggestion = complaintSuggestionMapper.selectComplaintSuggestionBySuggestionId(suggestionId);
        SuggestionFj suggestionFj = new SuggestionFj();
        suggestionFj.setSuggestionId(suggestionId);
        List<SuggestionFj> suggestionFjs = suggestionFjMapper.selectSuggestionFjList(suggestionFj);
        if (suggestionFjs != null && suggestionFjs.size() > 0){
            complaintSuggestion.setSuggestionFjList(suggestionFjs);
        }
        return complaintSuggestion;
    }

    /**
     * 查询投诉建议列表
     * 
     * @param complaintSuggestion 投诉建议
     * @return 投诉建议
     */
    @Override
    public List<ComplaintSuggestion> selectComplaintSuggestionList(ComplaintSuggestion complaintSuggestion)
    {
        return complaintSuggestionMapper.selectComplaintSuggestionList(complaintSuggestion);
    }

    /**
     * 新增投诉建议
     * 
     * @param complaintSuggestion 投诉建议
     * @return 结果
     */
    @Override
    public int insertComplaintSuggestion(ComplaintSuggestion complaintSuggestion)
    {
        complaintSuggestion.setCreateTime(DateUtils.getNowDate());
        complaintSuggestion.setUserId(SecurityUtils.getUserId());
        return complaintSuggestionMapper.insertComplaintSuggestion(complaintSuggestion);
    }

    /**
     * 修改投诉建议
     * 
     * @param complaintSuggestion 投诉建议
     * @return 结果
     */
    @Override
    public int updateComplaintSuggestion(ComplaintSuggestion complaintSuggestion)
    {
        //判断是否有附件
        List<SuggestionFj> suggestionFjList = complaintSuggestion.getSuggestionFjList();
        if (suggestionFjList != null && suggestionFjList.size() > 0){
            suggestionFjMapper.batchSuggestionFj(suggestionFjList);
        }
        complaintSuggestion.setUpdateTime(DateUtils.getNowDate());
        return complaintSuggestionMapper.updateComplaintSuggestion(complaintSuggestion);
    }

    /**
     * 批量删除投诉建议
     * 
     * @param suggestionIds 需要删除的投诉建议主键
     * @return 结果
     */
    @Override
    public int deleteComplaintSuggestionBySuggestionIds(Long[] suggestionIds)
    {
        return complaintSuggestionMapper.deleteComplaintSuggestionBySuggestionIds(suggestionIds);
    }

    /**
     * 删除投诉建议信息
     * 
     * @param suggestionId 投诉建议主键
     * @return 结果
     */
    @Override
    public int deleteComplaintSuggestionBySuggestionId(Long suggestionId)
    {
        return complaintSuggestionMapper.deleteComplaintSuggestionBySuggestionId(suggestionId);
    }
}
