package com.ruoyi.web.controller.api;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ApiResult;
import com.ruoyi.web.controller.spi.CheckSensitiveWordSpi;
import com.ruoyi.mall.domain.BusinessArticle;
import com.ruoyi.mall.domain.MallMajorClass;
import com.ruoyi.mall.domain.MallMemberUser;
import com.ruoyi.mall.domain.Vo.BusinessArticleVo;
import com.ruoyi.mall.mapper.MallMemberUserMapper;
import com.ruoyi.mall.service.*;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

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

/**
 * @ClassName 专业分析接口
 * @Description 专业分析接口
 * @Author LCL
 * @Date 2023/10/18
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/majorAnalysis")
public class ApiMajorAnalysisController {

    @Resource
    private MallMemberUserMapper memberUserMapper;

    @Resource
    private CheckSensitiveWordSpi checkSensitiveWordSpi;

    @Resource
    private IMallMajorClassService mallMajorClassService;

    @Resource
    private IMallCareerService mallCareerService;

    @Resource
    private IMallCareerSalaryService mallCareerSalaryService;

    @Resource
    private IMallCareerMajorService mallCareerMajorService;

    /**
     * 专业分类（一级、二级分类）
     *
     * @param type  1-以保研为导向下的硕士点建设院校
     * @return
     */
    @GetMapping("/getOneOrTwoMajorClass")
    public AjaxResult getOneOrTwoMajorClass(Integer type) {
        try {
            return AjaxResult.success().put("data", mallMajorClassService.selectOneOrTwoMallMajorClassList(type));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业分类（一级、二级分类）异常");
        }
    }

    /**
     * 专业解读、就业领域
     *
     * @param majorId 专业分类ID
     * @return
     */
    @GetMapping("/getMajorInterpret")
    public AjaxResult getMajorInterpret(@RequestParam Long majorId) {
        try {
            return AjaxResult.success().put("data", mallMajorClassService.selectMallMajorClassByMajorId(majorId));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业解读异常");
        }
    }

    /**
     * 专业前景-就业岗位
     *
     * @param pageNum  页码
     * @param pageSize 每页个数
     * @param majorId  专业分类ID
     * @return
     */
    @GetMapping("/getMajorProspect")
    public AjaxResult getMajorProspect(@RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam Long majorId) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> mapList = mallMajorClassService.selectMajorProspectList(majorId);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(mapList);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业前景-就业岗位异常");
        }
    }

    /**
     * 专业前景-职业介绍
     *
     * @param careerId 职业ID
     * @return
     */
    @GetMapping("/getMajorCareerObtainIntroduce")
    public AjaxResult getMajorCareerObtainIntroduce(@RequestParam Long careerId) {
        try {
            return AjaxResult.success().put("data", mallCareerService.selectMallCareerByCareerId(careerId));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业前景-职业介绍异常");
        }
    }

    /**
     * 专业前景-职业薪资
     *
     * @param cityLevel   城市等级
     * @return
     */
    @GetMapping("/getCareerSalaryList")
    public AjaxResult getCareerSalaryList(@RequestParam Long careerId,@RequestParam String cityLevel) {
        try {
            return AjaxResult.success().put("data", mallCareerSalaryService.selectMallCareerSalaryListByCareerId(careerId,cityLevel));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业前景-职业薪资异常");
        }
    }


    /**
     * 硕士点专业分类列表
     * @param majorId 专业id
     * @return 结果
     */
    @GetMapping("/selectOneOrTwoMallMajorClassListForMaster")
    public AjaxResult selectOneOrTwoMallMajorClassListForMaster(@RequestParam Long majorId){
        try {
            if(ObjectUtils.isEmpty(majorId)){
                return AjaxResult.error("缺少majorId");
            }
            return AjaxResult.success(mallMajorClassService.selectOneOrTwoMallMajorClassListByMaster(majorId));
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

    /**
     * 专业查 职位列表
     * @param majorId
     * @return
     */
     @GetMapping("/selectCareerMajorListByMajor")
     public AjaxResult selectCareerMajorListByMajor(@RequestParam Long majorId,
                                                    @RequestParam(required = false)Long orderType){
         try {
             if(ObjectUtils.isEmpty(majorId)){
                 return AjaxResult.error("缺少majorId");
             }
             return AjaxResult.success(mallCareerMajorService.selectListByMajor(majorId,orderType));
         }catch (Exception e){
                 e.printStackTrace();
             return AjaxResult.error("服务器异常");
         }
     }

}
