package jnpf.personnels.controller.app.transfer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.personnels.req.transfer.FtbHandleTransferDTO;
import jnpf.model.personnels.vo.transfer.FtbHandleTransferPageVO;
import jnpf.personnels.service.FtbPersonnelsTransferManageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * app人事调离调动管理模块
 */
@RestController
@RequestMapping("/app/ftb-personnels-transfer-manage")
public class FtbPersonnelsTransferManageAppController {

    @Resource
    private FtbPersonnelsTransferManageService ftbPersonnelsTransferManageService;

    /**
     * 办理调动，直接办理
     */
    @PostMapping("/handle-transfer")
    public ActionResult<String> handleTransfer(@RequestBody @Validated FtbHandleTransferDTO ftbHandleTransferDTO) {
        String handleTransfer = ftbPersonnelsTransferManageService.handleTransfer(ftbHandleTransferDTO);
        return ActionResult.success("操作成功", handleTransfer);
    }

    /**
     * 删除调动记录
     *
     * @param id 主键id，必传
     * @return {@link ActionResult}
     */
    @DeleteMapping("/delete/{id}")
    public ActionResult delete(@PathVariable("id") String id) {
        ftbPersonnelsTransferManageService.delete(id);
        return ActionResult.success();
    }

    /**
     * 办理调动列表
     */
    @GetMapping("/transfer-list")
    public ActionResult<PageListVO<FtbHandleTransferPageVO>> transferListApp(CultivatePage cultivatePage, String userName) {
        Page<FtbHandleTransferPageVO> page = cultivatePage.coverCultivatePage();
        page = ftbPersonnelsTransferManageService.transferListApp(page, userName);
        PageListVO<FtbHandleTransferPageVO> pageListVO = CultivatePage.coverPageList(page);
        return ActionResult.success(pageListVO);
    }

    /**
     * 我的调动
     */
    @GetMapping("/my-transfer")
    public ActionResult<PageListVO<FtbHandleTransferPageVO>> myTransferApp(CultivatePage cultivatePage) {
        Page<FtbHandleTransferPageVO> page = cultivatePage.coverCultivatePage();
        page = ftbPersonnelsTransferManageService.myTransferApp(page);
        PageListVO<FtbHandleTransferPageVO> pageListVO = CultivatePage.coverPageList(page);
        return ActionResult.success(pageListVO);
    }

}
