package jnpf.personnels.controller.app.regular;

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.regular.FtbPersonnelsRegularCreateDTO;
import jnpf.model.personnels.dto.regular.FtbPersonnelsSalaryAuditDto;
import jnpf.model.personnels.vo.app.FtbPersonnelsBubbleCountVO;
import jnpf.model.personnels.vo.regular.FtbPersonnelsRegularInfoVO;
import jnpf.model.personnels.vo.regular.FtbPersonnelsRegularManagementVO;
import jnpf.personnels.service.FtbPersonnelsRegularManagementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * app转正管理模块
 *
 * @author peng.hao
 */
@RestController
@RequestMapping("/app/personnels-regular")
public class FtbPersonnelsRegularManagementForAppController {

    @Resource
    FtbPersonnelsRegularManagementService service;

    /**
     * 转正管理列表查询，返回分页列表数据
     *
     * @param dto 查询参数对象
     * @return 返回分页列表数据的结果
     */
    @GetMapping("/list-query")
    public ActionResult<PageListVO<FtbPersonnelsRegularManagementVO>> pageList(FtbPersonnelsForAppQueryDTO dto,
                                                                               CultivatePage page) {
        PageListVO<FtbPersonnelsRegularManagementVO> pageListVO = service.pageForAppList(dto,page);
        return ActionResult.success(pageListVO);
    }
    /**
     * 我的审批,抄送,小气泡统计数
     * @param flag "1" 我的审批 "2" 抄送
     */
    @GetMapping("/getListCont")
    public ActionResult<FtbPersonnelsBubbleCountVO> getListCont(@RequestParam String flag) {
        FtbPersonnelsBubbleCountVO  countVO = service.getListCont(flag);
        return ActionResult.success(countVO);
    }


    /**
     * 办理转正
     *
     * @param createDTO 申请参数对象
     * @return 返回申请结果
     */
    @PutMapping("/apply-regularization")
    public ActionResult<String> applyForRegularization(@Validated @RequestBody FtbPersonnelsRegularCreateDTO createDTO) {
        return ActionResult.success("", service.applyForRegularization(createDTO));
    }



    /**
     * 查看审批的详细信息
     *
     * @param id 审批id
     * @return 返回 regularization 审批的详细信息结果
     */
    @GetMapping("/details-process/{id}")
    public ActionResult<FtbPersonnelsRegularInfoVO> checkTheDetailsOfRegularizationApproval(@PathVariable("id")String id) {
        return ActionResult.success(service.checkTheDetailsOfRegularizationApproval(id));
    }

    /**
     * 进行转正审批
     *
     * @param auditDto 审批信息
     * @return 返回 regularization 审批结果
     */
    @PutMapping("/regularization-approval")
    public ActionResult<String> regularizationApproval(@Validated @RequestBody FtbPersonnelsSalaryAuditDto auditDto) {
        service.regularizationApproval(auditDto);
        return ActionResult.success();
    }

    /**
     * 进行转正审批
     *
     * @param auditDto 审批信息
     * @return 返回 regularization 审批结果
     */
    @PostMapping("/regularization-approval")
    public ActionResult<String> regularizationApprovalWithPost(@Validated @RequestBody FtbPersonnelsSalaryAuditDto auditDto) {
        service.regularizationApproval(auditDto);
        return ActionResult.success();
    }


    /**
     * 撤销申请
     * @param id
     * @return
     */
    @GetMapping("/cancellation-rectification")
    public ActionResult<String> cancellationOfApplicationForRectification(@RequestParam String id){
        service.cancellationOfApplicationForRectification(id, null);
        return ActionResult.success();
    }
    /**
     * 删除转正申请
     * @param id
     * @return
     */
    @PutMapping("/delete-rectification/{id}")
    public ActionResult<String> deleteApplicationForRectification(@PathVariable("id")String id){
        service.removeById(id);
        return ActionResult.success();
    }
}
