package com.bonus.boot.manager.index.controller;

import com.bonus.boot.manager.index.dao.IndexDao;
import com.bonus.boot.manager.index.entity.IndexBean;
import com.bonus.boot.manager.index.service.IndexService;
import com.bonus.boot.manager.manager.utils.AjaxRes;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/index")
public class IndexController {

    @Resource
    private IndexService service;

    @Resource
    private IndexDao dao;

    /*
     获取男女年龄分布数量
    */
    @RequestMapping(value = "/age-distribution", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "男女年龄分布数量")
    public AjaxRes getListById (String date){
        AjaxRes ar = new AjaxRes();

        // 调用Service层的方法来获取男女年龄分布数量
        List<Map<Integer, Integer>> ageDistribution = new ArrayList<>();
        Map<Integer, Integer> map1 = new HashMap<>();
        Map<Integer, Integer> map2 = new HashMap<>();
        for (int i = 20;i < 90;i += 10){
            int num = service.getAgeDistribution(i,date);
            map1.put(i,num);
        }

        for (int i = 20;i < 90;i += 10){
            int j = i+9;
            int num = dao.getAgeDistribution2(i,j,date);
            map2.put(i,num);
        }

        ageDistribution.add(map1);
        ageDistribution.add(map2);
        // 设置响应结果
        ar.setSuccess(true);
        ar.setResult(ageDistribution);

        return ar;
    }


    /*
     男女员工疾病检出数量最高的几种异常结果
    */
    @RequestMapping(value = "/illness-count", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "男女员工疾病检出数量最高的几种异常结果")
    public List<IndexBean> getIllnessCount(String date) {
        return service.getIllnessCount(date);
    }

    /*
     男女疾病检出率的几种异常结果
    */
    @RequestMapping(value = "/disease-detection-rate", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "男女疾病检出率的几种异常结果")
    public List<IndexBean> getDiseaseDetectionRate(String date) {
        return service.getDiseaseDetectionRate(date);
    }

    /*
     男员工疾病检出数量最高的几种异常结果
    */
    @RequestMapping(value = "/male-illness-count", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "男员工疾病检出数量最高的几种异常结果")
    public List<IndexBean> getMaleIllnessCount(String date) {
        return service.getMaleIllnessCount(date);
    }

    /*
     女员工疾病检出数量最高的几种异常结果
    */
    @RequestMapping(value = "/female-illness-count", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "女员工疾病检出数量最高的几种异常结果")
    public List<IndexBean> getFemaleIllnessCount(String date) {
        return service.getFemaleIllnessCount(date);
    }


}