package com.ruoyi.web.controller.front;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BoolValues;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.syzy.criteria.UniversityTdxCriteria;
import com.ruoyi.syzy.domain.BBusiWishUniversitySubmits;
import com.ruoyi.syzy.service.IBBusiWishUniversitySubmitsService;
import com.ruoyi.voluntary.domain.BusiCards;
import com.ruoyi.voluntary.domain.SysLocations;
import com.ruoyi.voluntary.service.ISysLocationsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@Api(tags = "模拟志愿-投档线-院校")
@RequestMapping("front/syzy/tdx/university")
public class FrontSyzyTdxUniversityController extends BaseController {
    @Autowired
    private ISysLocationsService sysLocationsService;
    @Autowired
    private IBBusiWishUniversitySubmitsService universitySubmitsService;

    @GetMapping("locations")
    @ApiOperation("01.院校所在地")
    public TableDataInfo locations() {
        List<String> arr = sysLocationsService.getAllConfig().values().stream().filter(ll -> ll.getParentId()==1).collect(Collectors.toList())
                .stream().map(SysLocations::getSname).collect(Collectors.toList());
        return getDataTable(arr);
    }

    @GetMapping("levels")
    @ApiOperation("02.层次 本科,高职专科")
    public TableDataInfo levels(@ApiParam("年份")  Integer year) {
        String location = SecurityUtils.getLoginUser().getUser().getProvinceName();
//        if(null==year){
//            List<String> arr = universitySubmitsService.years(location, null, null);
//            if(CollectionUtils.isEmpty(arr)){
//                year = Calendar.getInstance().getWeekYear();
//            }else {
//                year = Integer.parseInt(Collections.max(arr));
//            }
//        }
        List<String> arr = universitySubmitsService.levels(location,year);
        return getDataTable(arr);
    }

    @GetMapping("types")
    @ApiOperation("03.科类 历史,物理")
    public TableDataInfo types(@ApiParam("年份") Integer year) {
        String location = SecurityUtils.getLoginUser().getUser().getProvinceName();
        List<String> arr = universitySubmitsService.types(location,year);
        return getDataTable(arr);
    }

    @GetMapping("years")
    @ApiOperation("04.录取年份")
    public TableDataInfo years() {
        String location = SecurityUtils.getLoginUser().getUser().getProvinceName();
        List<String> arr = universitySubmitsService.years(location, null, null);
        return getDataTable(arr);
    }

    @GetMapping("list")
    @ApiOperation("05.数据列表")
    public TableDataInfo search(UniversityTdxCriteria criteria, @ApiParam(value = "页数", example = "1") @RequestParam Integer pageNum,
        @ApiParam(value = "页大小", example = "15") @RequestParam Integer pageSize) {
        if (BoolValues.isFalse(SecurityUtils.getLoginUser().getUser().getIsBind())) {
            PageHelper.startPage(1, 1);
        } else {
            startPage();
        }
        criteria.setSpro(SecurityUtils.getLoginUser().getUser().getProvinceName());
        List<BBusiWishUniversitySubmits> arr = universitySubmitsService.search(criteria);
        return getDataTable(arr);
    }


    public static void main(String[] args) {
        List<String> list= Arrays.asList("2022","2021","2020");
        System.out.println(Collections.max(list));
        System.out.println(Calendar.getInstance().getWeekYear());
    }
}
