package jnpf.personnels.controller.app.secondment;

import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.personnels.dto.audit.FtbPersonnelsAuditDto;
import jnpf.model.personnels.dto.base.PersonnelsQueryDTO;
import jnpf.model.personnels.dto.secondment.FtbHandleSecondmentDTO;
import jnpf.model.personnels.vo.secondment.FtbPersonnelsSecondmentInfoVO;
import jnpf.model.personnels.vo.secondment.FtbPersonnelsSecondmentVO;
import jnpf.personnels.service.FtbPersonnelsSecondmentManagementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * app借调管理
 * @Author: peng.hao
 * @create: 2025/9/11
 */
@RestController
@RequestMapping("/app/secondment")
public class FtbPersonnelsSecondmentAppController {

    @Resource
    private FtbPersonnelsSecondmentManagementService ftbPersonnelsSecondmentService;

    /**
     * 列表查询
     */
    @GetMapping("/list-query")
    public ActionResult<PageListVO<FtbPersonnelsSecondmentVO>> pageList(PersonnelsQueryDTO dto,
                                                                        CultivatePage page) {
        PageListVO<FtbPersonnelsSecondmentVO> pageListVO = ftbPersonnelsSecondmentService.pageList(dto, page);
        return ActionResult.success(pageListVO);
    }

    /**
     * 详情
     */
    @GetMapping("/details/{id}")
    public ActionResult<FtbPersonnelsSecondmentInfoVO> details(@PathVariable String id) {
        return ActionResult.success(ftbPersonnelsSecondmentService.details(id));
    }

    /**
     * 办理借调
     */
    @PostMapping("/handle-secondment")
    public ActionResult<String> handleSecondment(@RequestBody @Validated FtbHandleSecondmentDTO ftbHandleSecondmentDTO) {
        return ActionResult.success("", ftbPersonnelsSecondmentService.handleSecondment(ftbHandleSecondmentDTO));
    }
    /**
     * 借调删除
     */
    @DeleteMapping("/delete/{id}")
    public ActionResult<Void> delete(@PathVariable String id) {
        ftbPersonnelsSecondmentService.delete(id);
        return ActionResult.success();
    }
    /**
     * 借调撤回
     */
    @PostMapping("/revoke")
    public ActionResult<Void> secondmentWithdrawal(@RequestBody FtbPersonnelsAuditDto ftbPersonnelsAuditDto) {
        ftbPersonnelsSecondmentService.secondmentWithdrawal(ftbPersonnelsAuditDto);
        return ActionResult.success();
    }

    /**
     * 提前结束
     */
    @PutMapping("/early-end/{id}")
    public ActionResult<Void> earlyEnd(@RequestBody Map<String, Object> map) {
        ftbPersonnelsSecondmentService.earlyEnd(map);
        return ActionResult.success();
    }

    /**
     * 延长借调时间
     *{
     *      "id": "借调id",
     *      "endTime" : "最新借调结束时间"
     * }
     */
    @PutMapping("/delay-time")
    public ActionResult<Void> delayTime(@RequestBody Map<String, Object> map) {
        ftbPersonnelsSecondmentService.delayTime(map);
        return ActionResult.success();
    }

}
