package jnpf.cultivate.controller.app.promotion;

import jnpf.base.ActionResult;
import jnpf.cultivate.service.FtbCultivatePromotionNewService;
import jnpf.model.cultivate.dto.promotion.FtbCultivateCreatMeMapInfoDTO;
import jnpf.model.cultivate.vo.promotion.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * app 学习地图管理(v1.1)
 *
 * @author hao.peng
 */
@RestController
@RequestMapping("/cul-pro-map-app")
public class FtbCultivatePromotionNewForAppController {
    /**
     * 服务对象
     */
    @Resource
    private FtbCultivatePromotionNewService promotionService;

    /**
     * 根据岗位id获取地图层级
     *
     * @param postId
     * @return
     */
    @GetMapping("/getLearnMapLevels")
    public ActionResult<FtbCultivatePromotionLevelMapVO> getMapLevel(@RequestParam("postId") String postId) {
        FtbCultivatePromotionLevelMapVO learnMapLevels = promotionService.getLearnMapLevels(postId);
        return ActionResult.success(learnMapLevels);
    }


    /**
     * 查询当前用户的学习地图 学习阶段
     *
     * @param userId 用户id
     * @param postId 岗位id
     * @return 学习阶段初始化为 1 阶段
     */
    @GetMapping("/queryTheCurrentUserLearningMapLevel")
    public ActionResult<Integer> queryTheCurrentUserLearningMapLevel(@RequestParam("userId") String userId,
                                                                     @RequestParam("postId") String postId) {
        return ActionResult.success(promotionService.queryTheCurrentUserLearningMapLevel(userId, postId));
    }

    /**
     * 校验前一个阶段岗位是否已经学习完成
     *
     * @param level  需要校验的岗位阶段
     * @param userId 用户id
     * @param postId 用户岗位id
     * @return 空为已完成, 1 当前阶段未学习完成, 2岗位学习考试未完成, 3岗位学习实操鉴定未完成 ,
     * ( 4,岗位学习考试未合格, 5 岗位学习实操鉴定未合格 ) v1.2 新增
     */
    @GetMapping("/check-studying")
    public ActionResult<String> checkPreviousStagePostAveYouFinishedStudying(@RequestParam Integer level,
                                                                             @RequestParam("userId") String userId,
                                                                             @RequestParam("postId") String postId) {

        return ActionResult.success(promotionService.checkStudying(level, userId, postId));
    }

    /**
     * 查询对应阶段选择岗位列表
     *
     * @param userId     用户id
     * @param postId     岗位id
     * @param level      等级
     * @param compulsory 是否必修，0必修，1选修
     * @return
     */
    @GetMapping("/selectPositionsCorrespondingToTheStages")
    public ActionResult<FtbCultivateNextCourseVO> selectPositionsCorrespondingToTheStages(@RequestParam("userId") String userId,
                                                                                          @RequestParam("postId") String postId,
                                                                                          @RequestParam("level") Integer level,
                                                                                          @RequestParam("compulsory") Integer compulsory) {
        return ActionResult.success(promotionService.selectPositionsCorrespondingToTheStages(userId, postId, level, compulsory));
    }

    /**
     * 根据初始岗位 和对应学习阶段 查询对应选择的岗位
     *
     * @param userId 用户id
     * @param postId 岗位id
     * @param level  学习阶段
     * @return
     */
    @GetMapping("/viewLearningMapBasedOnPosition")
    public ActionResult<List<FtbCultivateLearnMapInfoVO>> viewLearningMapBasedOnPosition(@RequestParam("userId") String userId,
                                                                                         @RequestParam("postId") String postId,
                                                                                         @RequestParam("level") Integer level) {
        List<FtbCultivateLearnMapInfoVO> result = promotionService.viewLearningMapBasedOnPosition(userId, postId, level);
        return ActionResult.success(result);
    }

    /**
     * 对应人员选择岗位
     *
     * @return
     */
    @PostMapping("/correspondingPersonnelSelectPositions")
    public ActionResult<String> correspondingPersonnelSelectPositions(@Validated @RequestBody FtbCultivateCreatMeMapInfoDTO creatMeMapInfoDTO) {
        promotionService.correspondingPersonnelSelectPositions(creatMeMapInfoDTO);
        return ActionResult.success();
    }

    /**
     * 查询下属学习阶段
     *
     * @param userId 下属id
     * @param postId 下属岗位id
     * @return
     */
    @GetMapping("/queryTheLearningStageOfSubordinates")
    public ActionResult<FtbCultivateUnderMemberInfo> queryTheLearningStageOfSubordinates(@RequestParam("userId") String userId,
                                                                                         @RequestParam("postId") String postId) {
        return ActionResult.success(promotionService.queryTheLearningStageOfSubordinates(userId, postId));
    }

    /**
     * 岗位学习地图发生变更重新选择
     *
     * @param userId
     * @param postId
     * @return ture 变更 false 未变更
     */
    @GetMapping("/whetherTheJobLearningMapHasChanged")
    public ActionResult<Boolean> whetherTheJobLearningMapHasChanged(@RequestParam("userId") String userId,
                                                                    @RequestParam("postId") String postId) {
        return ActionResult.success(promotionService.whetherTheJobLearningMapHasChanged(userId, postId));
    }

    /**
     * 学习地图-学习进度
     *
     * @param userId 用户id(必传)
     * @param postId 岗位id(必传)
     * @return
     */
    @GetMapping("/learningProgress")
    public ActionResult<FtbCultivatelearningProgressVO> learningProgress(@RequestParam("userId") String userId,
                                                                         @RequestParam("postId") String postId) {
        return ActionResult.success(promotionService.learningProgress(userId, postId));
    }


}
