package com.ruoyi.cms.controller.cms;

import com.ruoyi.cms.domain.StaticsJob;
import com.ruoyi.cms.domain.query.Staticsquery;
import com.ruoyi.cms.service.StaticsqueryService;
import com.ruoyi.cms.util.excel.StaticsExcelUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/cms/statics")
public class StaticsController extends BaseController {
    @Autowired
    private StaticsqueryService service;
    //分行业趋势分析
    @GetMapping("/industry")
    public AjaxResult  industry(Staticsquery staticsquery)
    {
        Map<String,Object> result = service.industry(staticsquery);
        return success(result);
    }
    //分行业趋势分析
    @GetMapping("/industryGen")
    public AjaxResult  industryGen()
    {
        service.industryGen();
        return success();
    }
    //分行业趋势分析
    @GetMapping("/industryAreaGen")
    public AjaxResult  industryAreaGen()
    {
        service.areaGen();
        return success();
    }
    //分行业趋势分析
    @GetMapping("/salaryGen")
    public AjaxResult  salarysalaryGen()
    {
        service.salarysalaryGen();
        return success();
    }
    @GetMapping("/salary")
    public AjaxResult  salary(Staticsquery staticsquery)
    {
        Map<String,Object> result = service.salary(staticsquery);
        return success(result);
    }
    @GetMapping("/industryArea")
    public AjaxResult  industryArea(Staticsquery staticsquery)
    {
        Map<String,Object> result = service.industryArea(staticsquery);
        return success(result);
    }
    //分行业趋势分析
    @GetMapping("/workYearGen")
    public AjaxResult  workYearGen()
    {
        service.workYearGen();
        return success();
    }
    @GetMapping("/workYear")
    public AjaxResult  workYear(Staticsquery staticsquery)
    {
        Map<String,Object> result = service.workYear(staticsquery);
        return success(result);
    }
    //分行业趋势分析
    @GetMapping("/educationGen")
    public AjaxResult  educationGen()
    {
        service.educationGen();
        return success();
    }
    @GetMapping("/education")
    public AjaxResult  education(Staticsquery staticsquery)
    {
        Map<String,Object> result = service.education(staticsquery);
        return success(result);
    }

    //分学历-分薪资
    @GetMapping("/educationSalaryGen")
    public AjaxResult  educationSalaryGen()
    {
        service.educationSalaryGen();
        return success();
    }

    @GetMapping("/educationSalary")
    public AjaxResult  educationSalary(Staticsquery staticsquery)
    {
        Map<String,Object> result = service.educationSalary(staticsquery);
        return success(result);
    }

    /**
     * 企业岗位统计
     * @param staticsquery
     * @return
     */
    @GetMapping("/qygwtjCount")
    public AjaxResult  qygwtjCount(Staticsquery staticsquery)
    {
        if(staticsquery==null){
            return error("参数为空!");
        }
        Map<String,Object> result = service.qygwtjCount(staticsquery);
        return success(result);
    }

    @GetMapping("/qygwtjDownload")
    public void   qygwtjDownload(Staticsquery staticsquery, HttpServletResponse response) throws Exception {
        if(staticsquery==null){
            throw new Exception("参数为空!");
        }
        String timeRange="";
        if(StringUtils.isBlank(staticsquery.getStartTime())){
            timeRange= "全部";
        }else{
            timeRange= staticsquery.getStartTime()+"至"+staticsquery.getEndTime();
        }
        String[] statLabels = {"注册企业数", "求职者实名数", "归集岗位合计", "简历投递数", "零工岗位数", "零工招聘人数"};
        Map<String,Object> result = service.qygwtjCount(staticsquery);
        List<StaticsJob> regionList = (List<StaticsJob>) result.get("group");
        StaticsJob staticsJob=(StaticsJob)result.get("hz");
        Integer[] statValues = {Integer.valueOf(staticsJob.getZcqys()),Integer.valueOf(staticsJob.getQzzsms()),
                Integer.valueOf(staticsJob.getGjgwhj()), Integer.valueOf(staticsJob.getJlsl()),
                Integer.valueOf(staticsJob.getLggws()), Integer.valueOf(staticsJob.getLgzprs())};
        StaticsExcelUtil<StaticsJob> excelUtil = new StaticsExcelUtil<>(StaticsJob.class);
        excelUtil.exportEmploymentExcel(response, timeRange, statLabels, statValues, regionList,
                "岗位归集统计", 12);
    }
}
