package com.bonus.canteen.core.nutrition.service;

import cn.hutool.core.collection.CollectionUtil;
import com.bonus.canteen.core.nutrition.mapper.HealthMedicalReportTmplMapper;
import com.bonus.canteen.core.nutrition.common.vo.HealthMedicalReportDetailVO;
import com.bonus.canteen.core.nutrition.common.vo.HealthMedicalReportProjectVO;
import com.bonus.canteen.core.nutrition.common.vo.HealthMedicalReportTmplVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;

@Service
public class HealthMedicalReportTmplService {
   @Resource
   private HealthMedicalReportTmplMapper healthMedicalReportTmplMapper;

   public List<HealthMedicalReportTmplVO> listTemplate() {
      return this.healthMedicalReportTmplMapper.listTemplate();
   }

   public List<HealthMedicalReportProjectVO> getTemplateInfoByTmplId(Long medicalTemplateId) {
      List<HealthMedicalReportProjectVO> healthMedicalReportProjectVOS = this.healthMedicalReportTmplMapper.listReportProject(medicalTemplateId);
      if (CollectionUtil.isEmpty(healthMedicalReportProjectVOS)) {
         return healthMedicalReportProjectVOS;
      } else {
         Iterator iterator = healthMedicalReportProjectVOS.iterator();

         while(iterator.hasNext()) {
            HealthMedicalReportProjectVO project = (HealthMedicalReportProjectVO)iterator.next();
            List<HealthMedicalReportDetailVO> medicalReportDetailVOList = this.healthMedicalReportTmplMapper.listReportDetail(project.getMedicalProjectId());
            project.setMedicalReportDetailVOList(medicalReportDetailVOList);
         }

         return healthMedicalReportProjectVOS;
      }
   }

}
