package com.ruoyi.hezhi.api.kaoshi;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.hezhi.domain.vo.DictParamVO;
import com.ruoyi.hezhi.service.*;
import com.ruoyi.system.service.ISysDictDataService;
import io.swagger.annotations.Api;
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 javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: LCL
 * @Date: 2024/10/08
 * @Description:通用API
 */
@Api("分类")
@RestController
@RequestMapping("/api/class")
public class ApiClassController {

    @Resource
    private ITbCareerClassService tbCareerClassService;
    @Resource
    private ITbMajorClassService majorClassService;
    @Resource
    private ITbRegionService regionService;
    @Resource
    private ITbConfigService configService;
    @Resource
    private ITbEvaluateAgencyClassService evaluateAgencyClassService;
    @Resource
    private ITbStudyCenterClassService studyCenterClassService;
    @Resource
    private ITbContinuingEducationClassService continuingEducationClassService;
    @Resource
    private ISysDictDataService dictDataService;
    @Resource
    private ITbDownloadService downloadService;
    @Resource
    private ITbEnterpriseProgressService enterpriseProgressService;


    /**
     * 获取字典参数列表
     *
     * @param paramType 字典类型（0-企业规模）
     * @return 结果
     */
    @GetMapping("/getDictParamList")
    public AjaxResult getDictParamList(String paramType) {
        List<DictParamVO> dictParamList = dictDataService.getDictParamList(paramType);
        return AjaxResult.success(dictParamList);
    }

    /**
     * 职业分类树列表
     *
     * @return success
     */
    @GetMapping("/getCareerClassTreeList")
    public AjaxResult getCareerClassTreeList() {
        try {
            return AjaxResult.success().put("data", tbCareerClassService.selectTbCareerClassTreeList());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("职业分类树列表异常");
        }
    }

    /**
     * 职业分类列表
     *
     * @param params careerId 1-职业技能，2-职业教育
     * @return success
     */
    @GetMapping("/getCareerClassMapList")
    public AjaxResult getCareerClassMapList(@RequestParam Map<String, Object> params) {
        try {
            return AjaxResult.success().put("data", tbCareerClassService.selectTbCareerClassMapList(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("职业分类列表异常");
        }
    }

    /**
     * 专业分类列表
     *
     * @param params pid
     * @return success
     */
    @GetMapping("/getMajorClassMapList")
    public AjaxResult getMajorClassMapList(@RequestParam Map<String, Object> params) {
        try {
            return AjaxResult.success().put("data", majorClassService.selectTbMajorClassMapList(params));
        } catch (Exception e) {
            e.printStackTrace();

            return AjaxResult.error("专业分类列表异常");
        }
    }

    /**
     * 专业分类树列表
     *
     * @return success
     */
    @GetMapping("/getMajorClassTreeList")
    public AjaxResult getMajorClassTreeList() {
        try {
            return AjaxResult.success().put("data", majorClassService.selectTbMajorClassTreeList());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业分类列表异常");
        }
    }

    /**
     * 行政区域列表
     *
     * @param params pid 上级ID
     * @return success
     */
    @GetMapping("/getRegionList")
    public AjaxResult getRegionList(@RequestParam Map<String, Object> params) {
        try {
            return AjaxResult.success().put("data", regionService.getRegionList(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("行政区域列表异常");
        }
    }

    /**
     * 行政区域树列表
     *
     * @return success
     */
    @GetMapping("/getRegionTreeList")
    public AjaxResult getRegionTreeList() {
        try {
            return AjaxResult.success().put("data", regionService.selectTbRegionTreeList());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("行政区域树列表异常");
        }
    }

    /**
     * 相关设置
     *
     * @param params identifying 设置标识
     * @return ok
     */
    @GetMapping("/getConfigInfo")
    public AjaxResult getConfigInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("identifying") || StringUtils.isBlank(params.get("identifying").toString())) {
            return AjaxResult.error("缺少 identifying 设置标识");
        }
        try {
            return AjaxResult.success().put("data", configService.getLiveBroadcastInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("相关设置异常");
        }
    }

    /**
     * 评价机构分类列表
     *
     * @param params
     * @return success
     */
    @GetMapping("/getEvaluateAgencyClassMapList")
    public AjaxResult getEvaluateAgencyClassMapList(@RequestParam Map<String, Object> params) {
        try {
            return AjaxResult.success().put("data", evaluateAgencyClassService.getEvaluateAgencyClassMapList(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("评价机构分类列表异常");
        }
    }

    /**
     * 学习中心分类列表
     *
     * @param params
     * @return success
     */
    @GetMapping("/getStudyCenterClassMapList")
    public AjaxResult getStudyCenterClassMapList(@RequestParam Map<String, Object> params) {
        try {
            return AjaxResult.success().put("data", studyCenterClassService.getStudyCenterClassMapList(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("学习中心分类列表异常");
        }
    }

    /**
     * 继续教育分类列表
     *
     * @param params
     * @return success
     */
    @GetMapping("/getContinuingEducationClassMapList")
    public AjaxResult getContinuingEducationClassMapList(@RequestParam Map<String, Object> params) {
        try {
            return AjaxResult.success().put("data", continuingEducationClassService.getContinuingEducationClassMapList(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("继续教育分类列表异常");
        }
    }

    /**
     * 在线下载列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   searchValue 搜索词
     * @return success
     */
    @GetMapping("/getDownloadList")
    public AjaxResult getDownloadList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                      @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                      @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = downloadService.getDownloadList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("在线下载列表异常");
        }
    }


    /**
     * 企业历程列表
     *
     * @return success
     */
    @GetMapping("/getEnterpriseProgressList")
    public AjaxResult getEnterpriseProgressList() {
        try {
            return AjaxResult.success().put("data", enterpriseProgressService.getEnterpriseProgressList());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("企业历程列表异常");
        }
    }

}
