package com.xinelu.manage.service.patientquestionsubmitresult.impl;

import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.enums.QuestionTypeEnum;
import com.xinelu.common.utils.PageServiceUtil;
import com.xinelu.manage.domain.agency.Agency;
import com.xinelu.manage.domain.patientquestionsubmitresult.PatientQuestionSubmitResult;
import com.xinelu.manage.dto.patientquestionsubmitresult.PatientQuestionSubmitStatistisDto;
import com.xinelu.manage.mapper.agency.AgencyMapper;
import com.xinelu.manage.mapper.patientquestionsubmitresult.PatientQuestionSubmitResultMapper;
import com.xinelu.manage.service.patientquestionsubmitresult.IPatientQuestionSubmitResultService;
import com.xinelu.manage.vo.department.DepartmentBaseVo;
import com.xinelu.manage.vo.department.DepartmentVO;
import com.xinelu.manage.vo.patientquestionsubmitresult.PatientQuestionSubmitListVo;
import com.xinelu.manage.vo.patientquestionsubmitresult.SatisfactionSurveyVO;
import java.time.LocalDateTime;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

/**
 * 患者问卷提交结果信息Service业务层处理
 *
 * @author xinelu
 * @date 2024-03-28
 */
@Service
public class PatientQuestionSubmitResultServiceImpl implements IPatientQuestionSubmitResultService {
    @Resource
    private PatientQuestionSubmitResultMapper patientQuestionSubmitResultMapper;
	@Resource
	private AgencyMapper agencyMapper;
	@Resource
	private PageServiceUtil pageServiceUtil;

    /**
     * 查询患者问卷提交结果信息
     *
     * @param id 患者问卷提交结果信息主键
     * @return 患者问卷提交结果信息
     */
    @Override
    public PatientQuestionSubmitResult selectPatientQuestionSubmitResultById(Long id) {
        return patientQuestionSubmitResultMapper.selectPatientQuestionSubmitResultById(id);
    }

    /**
     * 查询患者问卷提交结果信息列表
     *
     * @param patientQuestionSubmitResult 患者问卷提交结果信息
     * @return 患者问卷提交结果信息
     */
    @Override
    public List<PatientQuestionSubmitResult> selectPatientQuestionSubmitResultList(PatientQuestionSubmitResult patientQuestionSubmitResult) {
        return patientQuestionSubmitResultMapper.selectPatientQuestionSubmitResultList(patientQuestionSubmitResult);
    }

    /**
     * 新增患者问卷提交结果信息
     *
     * @param patientQuestionSubmitResult 患者问卷提交结果信息
     * @return 结果
     */
    @Override
    public int insertPatientQuestionSubmitResult(PatientQuestionSubmitResult patientQuestionSubmitResult) {
        patientQuestionSubmitResult.setCreateTime(LocalDateTime.now());
        return patientQuestionSubmitResultMapper.insertPatientQuestionSubmitResult(patientQuestionSubmitResult);
    }

    /**
     * 修改患者问卷提交结果信息
     *
     * @param patientQuestionSubmitResult 患者问卷提交结果信息
     * @return 结果
     */
    @Override
    public int updatePatientQuestionSubmitResult(PatientQuestionSubmitResult patientQuestionSubmitResult) {
        patientQuestionSubmitResult.setUpdateTime(LocalDateTime.now());
        return patientQuestionSubmitResultMapper.updatePatientQuestionSubmitResult(patientQuestionSubmitResult);
    }

    /**
     * 批量删除患者问卷提交结果信息
     *
     * @param ids 需要删除的患者问卷提交结果信息主键
     * @return 结果
     */
    @Override
    public int deletePatientQuestionSubmitResultByIds(Long[] ids) {
        return patientQuestionSubmitResultMapper.deletePatientQuestionSubmitResultByIds(ids);
    }

    /**
     * 删除患者问卷提交结果信息信息
     *
     * @param id 患者问卷提交结果信息主键
     * @return 结果
     */
    @Override
    public int deletePatientQuestionSubmitResultById(Long id) {
        return patientQuestionSubmitResultMapper.deletePatientQuestionSubmitResultById(id);
    }

    /**
     * 满意度调查问卷列表
     *
     * @param satisfactionSurvey 居民信息
     * @return AjaxResult
     */
    @Override
    public List<SatisfactionSurveyVO> satisfactionSurvey(SatisfactionSurveyVO satisfactionSurvey) {
        satisfactionSurvey.setQuestionType(QuestionTypeEnum.SATISFACTION_QUESTIONNAIRE.getInfo());
        return patientQuestionSubmitResultMapper.selectSatisfactionSurvey(satisfactionSurvey);
    }


    /**
     * 满意度调查问卷
     *
     * @param patientQuestionSubmitResultId 问卷信息
     * @return AjaxResult
     */
    @Override
    public AjaxResult selectQuestionnaireResult(Long patientQuestionSubmitResultId) {
        return AjaxResult.success(patientQuestionSubmitResultMapper.selectResultByTaskExecuteRecordId(null, patientQuestionSubmitResultId));
    }

	@Override public AjaxResult departmenQuestionSubmitCount(PatientQuestionSubmitStatistisDto queryDto) {
		List<DepartmentVO> departmentVOS = patientQuestionSubmitResultMapper.departmenQuestionSubmitCount(queryDto);
		Agency agency = agencyMapper.selectAgencyById(queryDto.getHospitalAgencyId());
		return AjaxResult.success(DepartmentBaseVo.builder().hospitalAgencyName(ObjectUtils.isEmpty(agency) ? "" : agency.getAgencyName())
			.deptNumList(departmentVOS).build());
	}

	@Override
	public List<PatientQuestionSubmitListVo> patientQuestionSubmitList(PatientQuestionSubmitStatistisDto queryDto) {
		return patientQuestionSubmitResultMapper.patientQuestionSubmitList(queryDto);
	}
}
