package jnpf.cultivate.controller.web.promotion;

import io.swagger.v3.oas.annotations.Operation;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.FtbCultivatePromotionNewService;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.dto.promotion.FtbCultivatePromotionCreatNewDto;
import jnpf.model.cultivate.dto.promotion.FtbCultivatePromotionDto;
import jnpf.model.cultivate.vo.promotion.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

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

    /**
     * 获取学习地图管理列表
     * @param page 分页参数
     * @return
     */
    @GetMapping("/list")
    public ActionResult<PageListVO<FtbCultivatePromotionNewVO>> list(FtbCultivatePromotionDto dto, CultivatePage page) {
        PageListVO<FtbCultivatePromotionNewVO> listVo = promotionService.getList(page,dto);
        return ActionResult.success(listVo);
    }

    /**
     * 新增学习地图
     * @param creatDto
     * @return
     */
    @PostMapping("/save")
    public ActionResult<String> save(@Validated @RequestBody FtbCultivatePromotionCreatNewDto creatDto) {
        promotionService.add(creatDto);
        return ActionResult.success("新增成功");

    }

    /**
     * 修改学习地图
     * @param creatDto
     * @return
     */
    @PutMapping("/update")
    public ActionResult<String> update(@Validated @RequestBody FtbCultivatePromotionCreatNewDto creatDto) {
        promotionService.updatePromotion(creatDto);
        return ActionResult.success("修改成功");
    }

    /**
     * 获取学习地图详情
     * @param id
     * @return
     */
    @GetMapping("/getDetails/{id}")
    public ActionResult<FtbCultivateStudyMemberVO> getDetails(@PathVariable("id") String id) {
        FtbCultivateStudyMemberVO memberVO = promotionService.getDetails(id);
        return ActionResult.success(memberVO);
    }


    /**
     * 删除学习地图
     * @param id 主键ID
     * @param isTwoDelete 是否执行2次删除操作。
     *                    如果`isTwoDelete`为`0`，
     *                    则进行一次删除操作；
     *                    如果为`1`，则执行2次删除操作。
     * @return 删除结果  "1"表示删除失败需要弹窗展示数据，空 表示删除成功。
     */
    @Operation(summary = "删除学习地图")
    @DeleteMapping("/{id}/{isTwoDelete}")
    public ActionResult<Boolean> delete(@PathVariable("id") String id,
                                        @PathVariable("isTwoDelete") int isTwoDelete) {
        String isDeleted = promotionService.deleteById(id, isTwoDelete == 1);
        return ActionResult.success(isDeleted);
    }

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

    /**
     * 删除时二次校验 获取当前地图绑定成员信息
     * @param id 地图主键id
     * @return
     */
    @GetMapping("/getTheCurrentMapBindingMembers")
    public ActionResult<FtbCultivatePromotionStudyDeleteInfo> getTheCurrentMapBindingMembers(@RequestParam("id")String id){
        FtbCultivatePromotionStudyDeleteInfo resultList =  promotionService.getTheCurrentMapBindingMembers(id);
        return ActionResult.success(resultList);
    }

    /**
     * 根据地图主键id 获取地图成员信息
     * @param id
     * @return
     */
    @GetMapping("/getPromotionById")
    public ActionResult<FtbCultivateStudyMemberInfo> getPromotionById(@RequestParam("id")String id,CultivatePage page){
        FtbCultivateStudyMemberInfo promotionNewVO = promotionService.getPromotionById(id,page);
        return ActionResult.success(promotionNewVO);
    }

    /**
     * 校验岗位是否再学习地图 (岗位删除限制)
     * @param postId
     * @return false 不存在 ture 存在
     */
    @GetMapping("/check-post-have-map")
    public ActionResult<Boolean> verifyingThePostWillRelearnTheMap(@RequestParam("postId") String postId){
        return ActionResult.success(promotionService.verifyingThePostWillRelearnTheMap(postId));
    }

    /**
     * 根据人查询学习地图详情
     * @param userId
     * @param postId
     * @return
     */
    @GetMapping("/queryMapLearningStatusBasedOnPeople")
    public ActionResult<FtbCultivatePromotionWithPersonelVO> queryMapLearningStatusBasedOnPeople(String userId,String postId){
        FtbCultivatePromotionWithPersonelVO personelVO = promotionService.queryTrainData(userId, postId);
        return ActionResult.success(personelVO);
    }
}
