package com.ltkj.hosp.service.impl; import java.util.List; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ltkj.common.utils.DateUtils; import com.ltkj.hosp.domain.TjTeamSelectRecord; import com.ltkj.hosp.mapper.TjTeamSelectRecordMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import com.ltkj.common.utils.StringUtils; import org.springframework.transaction.annotation.Transactional; import com.ltkj.hosp.domain.TjSurveyOptions; import com.ltkj.hosp.mapper.TjSurveyQuestionMapper; import com.ltkj.hosp.domain.TjSurveyQuestion; import com.ltkj.hosp.service.ITjSurveyQuestionService; /** * 问卷问题Service业务层处理 * * @author ltkj_赵佳豪&李格 * @date 2023-04-07 */ @Service public class TjSurveyQuestionServiceImpl extends ServiceImpl implements ITjSurveyQuestionService { @Autowired private TjSurveyQuestionMapper tjSurveyQuestionMapper; /** * 查询问卷问题 * * @param qid 问卷问题主键 * @return 问卷问题 */ @Override public TjSurveyQuestion selectTjSurveyQuestionByQid(Long qid) { return tjSurveyQuestionMapper.selectTjSurveyQuestionByQid(qid); } /** * 查询问卷问题列表 * * @param tjSurveyQuestion 问卷问题 * @return 问卷问题 */ @Override public List selectTjSurveyQuestionList(TjSurveyQuestion tjSurveyQuestion) { return tjSurveyQuestionMapper.selectTjSurveyQuestionList(tjSurveyQuestion); } /** * 新增问卷问题 * * @param tjSurveyQuestion 问卷问题 * @return 结果 */ @Transactional @Override public int insertTjSurveyQuestion(TjSurveyQuestion tjSurveyQuestion) { tjSurveyQuestion.setCreateTime(DateUtils.getNowDate()); int rows = tjSurveyQuestionMapper.insertTjSurveyQuestion(tjSurveyQuestion); insertTjSurveyOptions(tjSurveyQuestion); return rows; } /** * 修改问卷问题 * * @param tjSurveyQuestion 问卷问题 * @return 结果 */ @Transactional @Override public int updateTjSurveyQuestion(TjSurveyQuestion tjSurveyQuestion) { tjSurveyQuestion.setUpdateTime(DateUtils.getNowDate()); tjSurveyQuestionMapper.deleteTjSurveyOptionsByQid(tjSurveyQuestion.getQid()) ; insertTjSurveyOptions(tjSurveyQuestion); return tjSurveyQuestionMapper.updateTjSurveyQuestion(tjSurveyQuestion); } /** * 批量删除问卷问题 * * @param qids 需要删除的问卷问题主键 * @return 结果 */ @Transactional @Override public int deleteTjSurveyQuestionByQids(Long[] qids) { tjSurveyQuestionMapper.deleteTjSurveyOptionsByQids(qids); return tjSurveyQuestionMapper.deleteTjSurveyQuestionByQids(qids); } /** * 删除问卷问题信息 * * @param qid 问卷问题主键 * @return 结果 */ @Transactional @Override public int deleteTjSurveyQuestionByQid(Long qid) { tjSurveyQuestionMapper.deleteTjSurveyOptionsByQid(qid); return tjSurveyQuestionMapper.deleteTjSurveyQuestionByQid(qid); } /** * 新增问卷选项信息 * * @param tjSurveyQuestion 问卷问题对象 */ public void insertTjSurveyOptions(TjSurveyQuestion tjSurveyQuestion) { List tjSurveyOptionsList = tjSurveyQuestion.getTjSurveyOptionsList(); Long qid = tjSurveyQuestion.getQid(); if (StringUtils.isNotNull(tjSurveyOptionsList)) { List list = new ArrayList(); for (TjSurveyOptions tjSurveyOptions : tjSurveyOptionsList) { tjSurveyOptions.setQid(qid); tjSurveyOptions.setDeleted(0); list.add(tjSurveyOptions); } if (list.size() > 0) { for (TjSurveyOptions tjSurveyOptions : list) { tjSurveyOptions.setDeleted(0); } tjSurveyQuestionMapper.batchTjSurveyOptions(list); } } } }