package com.xinelu.manage.service.evaluateresult.impl;
import com.xinelu.manage.mapper.evaluateresult.EvaluateResultMapper;
import com.xinelu.manage.service.evaluateresult.EvaluateResultService;
import com.xinelu.manage.vo.evaluateresult.EvaluateResultVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class EvaluateResultServiceimpl implements EvaluateResultService {

    @Resource
    private EvaluateResultMapper evaluateResultMapper;

    /**
     * 根据年龄端性别统计筛查结果
     * @param ageA
     * @param ageB
     * @param sex
     * @return
     */
    @Override
    public List<EvaluateResultVo> list(String ageA, String ageB, String sex) {
        String timeMinus = "-01"+"-01";
        //开始时间
        String startTime = calculateBirthYear(Integer.parseInt(ageB))+timeMinus;
        //结束时间
        String endTime = calculateBirthYear(Integer.parseInt(ageA))+timeMinus;
        return evaluateResultMapper.list(startTime, endTime, sex);
    }

    /**
     * 年龄转日期
     * @param age
     * @return
     */
    public static int calculateBirthYear(int age) {
        int currentYear = java.time.Year.now().getValue();
        int birthYear = currentYear - age;
        return birthYear;
    }
}
