package com.ruoyi.web.controller.api;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.mall.domain.Bo.CountScoreBO;
import com.ruoyi.mall.service.IMallCountMethodService;
import com.ruoyi.mall.service.IMallSchoolPositionService;
import com.ruoyi.mall.service.IMallSchoolSuggestService;
import org.aspectj.weaver.loadtime.Aj;
import org.checkerframework.checker.units.qual.A;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 计算方法控制层
 * @author 萌
 */
@RestController
@RequestMapping("/api/count")
public class ApiCountController {

    @Resource
    private IMallCountMethodService mallCountMethodService;

    @Resource
    private IMallSchoolSuggestService mallSchoolSuggestService;

    @Resource
    private IMallSchoolPositionService mallSchoolPositionService;

    /**
     * 计算方法- 本科分计算方法
     *
     * @return 结果
     */
    @PostMapping("/countScore")
    public AjaxResult countScore(@RequestBody @Validated CountScoreBO countScoreBO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return mallCountMethodService.countScore(countScoreBO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

    /**
     * 专科计算方法
     *
     * @return 结果
     */
    @GetMapping("/getTrainingSchoolMethod")
    public AjaxResult getTrainingSchoolMethod(@RequestParam Integer cultureScore, @RequestParam Integer majorScore) {
        try {
            return mallCountMethodService.getTrainingSchoolMethod(cultureScore, majorScore);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

    /**
     * 计算规则匹配学校
     *
     * @param id           用户id
     * @param acceptRuleId 规则id
     * @param batchId      批次id
     * @param positionId   定位id
     * @param suggestId    推荐id
     * @param pageNum      页码
     * @param pageSize     每页个数
     * @return 结果
     */
    @GetMapping("/ruleMatchSchoolList")
    public AjaxResult ruleMatchSchoolList(@RequestParam Long id,
                                          @RequestParam Long acceptRuleId,
                                          @RequestParam(required = false) Long batchId,
                                          @RequestParam(required = false) Long positionId,
                                          @RequestParam(required = false) Long suggestId,
                                          @RequestParam(defaultValue = "1") Integer pageNum,
                                          @RequestParam(defaultValue = "10") Integer pageSize) {
        try {
            return AjaxResult.success(mallCountMethodService.ruleMatchSchoolList(id, acceptRuleId, batchId, positionId, suggestId, pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

    /**
     * 推荐度列表
     * @return 结果
     */
    @GetMapping("/selectSuggestList")
    public AjaxResult selectSuggestList(){
        try {
            return AjaxResult.success(mallSchoolSuggestService.selectSuggestList());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

    /**
     * 定位列表
     * @return 结果
     */
    @GetMapping("/selectPositionList")
    public AjaxResult selectPositionList(){
        try {
            return AjaxResult.success(mallSchoolPositionService.selectPositionList());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }
}
