package com.ruoyi.web.controller.front;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BoolValues;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.syzy.domain.BBusiWishUniversitySubmitRecruitPlan;
import com.ruoyi.syzy.service.IBBusiWishUniversitySubmitRecruitPlanService;
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.Calendar;
import java.util.List;

@RestController
@Api(tags = "院校招生计划")
@RequestMapping("front/syzy/recruitPlan/")
public class FrontSyzyUniversitiesRecruitPlanController extends BaseController {

    @Autowired
    private IBBusiWishUniversitySubmitRecruitPlanService recruitPlanService;

    @GetMapping("years")
    @ApiOperation("01.报考年份")
    public TableDataInfo years() {
        String location = SecurityUtils.getLoginUser().getUser().getProvinceName();
        List<String> arr = recruitPlanService.years(location, null, null);
        return getDataTable(arr);
    }

    @GetMapping("types")
    @ApiOperation("02.报考科类")
    public TableDataInfo types(@RequestParam(required = false) Integer year) {
        if (null == year) {
            year = Calendar.getInstance().get(Calendar.YEAR);
        }
        String location = SecurityUtils.getLoginUser().getUser().getProvinceName();
        List<String> arr = recruitPlanService.types(location,year);
        return getDataTable(arr);
    }

    /**
     * 暂不使用
     * @param year
     * @return
     */
    @GetMapping("levels")
    @ApiOperation("03.报考批次")
    public TableDataInfo levels(@ApiParam("年份") @RequestParam Integer year) {
        String location = SecurityUtils.getLoginUser().getUser().getProvinceName();
        List<String> arr = recruitPlanService.levels(location,year);
        return getDataTable(arr);
    }

    @GetMapping("getUniversityNameText")
    @ApiOperation("03-2.专业组名称")
    public AjaxResult getUniversityNameText(@ApiParam("院校编码") @RequestParam String universityCode,@ApiParam("年份") @RequestParam Integer year,
        @ApiParam("文理科/物理历史") @RequestParam String type, @ApiParam("批次")  String level) {
        String location = SecurityUtils.getLoginUser().getUser().getProvinceName();
        List<String> arr = recruitPlanService.getUniversityNameText(universityCode,location,year,type,level);
        return AjaxResult.success(arr);
    }

    @GetMapping("list")
    @ApiOperation("04.数据列表")
    public TableDataInfo search(BBusiWishUniversitySubmitRecruitPlan criteria, @ApiParam(value = "页数", example = "1") @RequestParam Integer pageNum,
                                @ApiParam(value = "页大小", example = "15") @RequestParam Integer pageSize) {
        if (null == criteria.getYear()) {
            criteria.setYear(String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
        }
        criteria.setLocation(SecurityUtils.getLoginUser().getUser().getProvinceName());
        if (BoolValues.isFalse(SecurityUtils.getLoginUser().getUser().getIsBind())) {
            PageHelper.startPage(1, 1);
        } else {
            startPage();
        }
        List<BBusiWishUniversitySubmitRecruitPlan> arr = recruitPlanService.selectBBusiWishUniversitySubmitRecruitPlanList(criteria);
        return getDataTable(arr);
    }
}
