package jnpf.personnels.controller.app.turnover;

import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.personnels.dto.regular.FtbPersonnelsForAppQueryDTO;
import jnpf.model.personnels.dto.turnover.FtbPersonnelsTurnoverCreateDTO;
import jnpf.model.personnels.dto.turnover.FtbPersonnelsTurnoverDTO;
import jnpf.model.personnels.vo.app.FtbPersonnelsBubbleCountVO;
import jnpf.model.personnels.vo.turnover.FtbPersonnelsTurnoverInfoVO;
import jnpf.model.personnels.vo.turnover.FtbPersonnelsTurnoverManagementVO;
import jnpf.personnels.service.FtbPersonnelsTurnoverManagementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * app离职管理模块
 *
 * @author peng.hao
 */
@RestController
@RequestMapping("/app/personnels-turnover")
public class FtbPersonnelsTurnoverManagementForAppController {

    @Resource
    FtbPersonnelsTurnoverManagementService service;

    /**
     * 获取人事变动管理中的人员流动列表
     *
     * @param dto 人事变动查询参数
     * @return 查询结果
     */
    @GetMapping("/list-query")
    public ActionResult<PageListVO<FtbPersonnelsTurnoverManagementVO>> getTurnoverList(FtbPersonnelsForAppQueryDTO dto,
                                                                                       CultivatePage page){
        PageListVO<FtbPersonnelsTurnoverManagementVO> listVO = service.getTurnoverForList(dto,page);
        return ActionResult.success(listVO);
    }
    /**
     * 我的审批,抄送,小气泡统计数
     * @param flag "1" 我的审批 "2" 抄送
     */
    @GetMapping("/getListCont")
    public ActionResult<FtbPersonnelsBubbleCountVO> getListCont(@RequestParam String flag) {
        FtbPersonnelsBubbleCountVO  countVO = service.getListCont(flag);
        return ActionResult.success(countVO);
    }

    /**
     * 获取辞职审批流程详情
     *
     * @param id 流程id
     * @return 返回辞职审批流程详情结果
     */
    @GetMapping("/details-process/{id}")
    public ActionResult<FtbPersonnelsTurnoverInfoVO> detailsOfResignationApprovalProcess(@PathVariable("id")String id){
        FtbPersonnelsTurnoverInfoVO info =  service.detailsOfResignationApprovalProcess(id);
        return ActionResult.success(info);
    }


    /**
     * 申请辞职
     *
     * @param createDTO 创建DTO对象
     * @return
     */
    @PostMapping("/apply-resignation")
    public ActionResult<Object> applyForResignation(@Validated @RequestBody FtbPersonnelsTurnoverCreateDTO createDTO){
        String s = service.applyForResignation(createDTO);
        return ActionResult.success("成功",s);
    }

    /**
     * 撤销辞职申请
     *
     * @param id 应用程序的ID
     * @return 返回String类型的ActionResult对象
     */
    @PutMapping("/withdraw-application/{id}")
    public ActionResult<String> withdrawResignationApplication(@PathVariable("id")String id){
        service.withdrawResignationApplication(id, null);
        return ActionResult.success();
    }
    /**
     * 审核离职申请
     *
     * @param auditDto 审核DTO对象
     * @return   "1" 为是否为审批人 2 是否为门店负责人 3是否存在角色组 4存在下属
     */
    @PutMapping("/review-resignation-application")
    public ActionResult<String> ReviewResignationApplication(@RequestBody FtbPersonnelsTurnoverDTO auditDto ){
        String string = service.reviewResignationApplication(auditDto);
        return ActionResult.success("",string);
    }


    /**
     * 审核离职申请
     *
     * @param auditDto 审核DTO对象
     * @return   "1" 为是否为审批人 2 是否为门店负责人 3是否存在角色组 4存在下属
     */
    @PostMapping("/review-resignation-application")
    public ActionResult<String> ReviewResignationApplicationWithPost(@RequestBody FtbPersonnelsTurnoverDTO auditDto ){
        String string = service.reviewResignationApplication(auditDto);
        return ActionResult.success("",string);
    }

    /**
     * 获取用户绑定审批结果
     * @param flag 用户离职申请信息
     * @return 动态数据
     */
    @GetMapping("/get-user-bound-approval")
    public ActionResult<List<Map<String,Object>>> getUserBoundApproval(@RequestParam("flag") String flag,
                                                                       @RequestParam("userId") String userId){
        return ActionResult.success(service.getUserBoundApproval(flag,userId));
    }


}
