package com.fs.his.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.common.utils.DateUtils;
import com.fs.his.domain.FsQuestionAndAnswer;
import com.fs.his.mapper.FsQuestionAndAnswerMapper;
import com.fs.his.service.IFsQuestionAndAnswerService;
import com.fs.his.vo.AnswerVO;
import com.fs.his.vo.FsQuestionAndAnswerVO;
import com.fs.his.vo.OptionsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 问答Service业务层处理
 *
 * @author fs
 * @date 2025-09-29
 */
@Service
public class FsQuestionAndAnswerServiceImpl extends ServiceImpl<FsQuestionAndAnswerMapper, FsQuestionAndAnswer> implements IFsQuestionAndAnswerService {


    @Autowired
    private FsQuestionAndAnswerMapper fsQuestionAndAnswerMapper;
    /**
     * 查询问答
     *
     * @param id 问答主键
     * @return 问答
     */
    @Override
    public FsQuestionAndAnswerVO selectFsQuestionAndAnswerById(Long id)
    {
        FsQuestionAndAnswer fsQuestionAndAnswer = baseMapper.selectFsQuestionAndAnswerById(id);
        FsQuestionAndAnswerVO vo = new FsQuestionAndAnswerVO();
        vo.setQuestionName(fsQuestionAndAnswer.getQuestionName());
        List<AnswerVO> answerVOS = JSON.parseArray(fsQuestionAndAnswer.getJsonInfo(), AnswerVO.class);
        vo.setAnswers(answerVOS);
        vo.setId(fsQuestionAndAnswer.getId());
        return vo;
    }

    /**
     * 查询问答列表
     *
     * @param fsQuestionAndAnswer 问答
     * @return 问答
     */
    @Override
    public List<FsQuestionAndAnswer> selectFsQuestionAndAnswerList(FsQuestionAndAnswer fsQuestionAndAnswer)
    {
        return baseMapper.selectFsQuestionAndAnswerList(fsQuestionAndAnswer);
    }

    /**
     * 新增问答
     *
     * @param fsQuestionAndAnswer 问答
     * @return 结果
     */
    @Override
    public int insertFsQuestionAndAnswer(FsQuestionAndAnswer fsQuestionAndAnswer)
    {
        fsQuestionAndAnswer.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertFsQuestionAndAnswer(fsQuestionAndAnswer);
    }

    /**
     * 修改问答
     *
     * @param fsQuestionAndAnswer 问答
     * @return 结果
     */
    @Override
    public int updateFsQuestionAndAnswer(FsQuestionAndAnswer fsQuestionAndAnswer)
    {
        fsQuestionAndAnswer.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateFsQuestionAndAnswer(fsQuestionAndAnswer);
    }

    /**
     * 批量删除问答
     *
     * @param ids 需要删除的问答主键
     * @return 结果
     */
    @Override
    public int deleteFsQuestionAndAnswerByIds(Long[] ids)
    {
        return baseMapper.deleteFsQuestionAndAnswerByIds(ids);
    }

    /**
     * 删除问答信息
     *
     * @param id 问答主键
     * @return 结果
     */
    @Override
    public int deleteFsQuestionAndAnswerById(Long id)
    {
        return baseMapper.deleteFsQuestionAndAnswerById(id);
    }

    @Override
    public List<OptionsVO> selectAllQuestionOptions() {
        return fsQuestionAndAnswerMapper.selectAllQuestionOptions();
    }
}
