package com.jeeplus.human.depart.registration.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.human.depart.registration.domain.DepartRegistration;
import com.jeeplus.human.depart.registration.service.DepartService;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author 王强
 * @version 1.0
 * @date 2023-10-25 9:53
 */
@RestController
@Api("离职申请信息")
@RequestMapping(value = "/departRegistration")
public class DepartRegistrationController {

    @Resource
    private DepartService departService;

    /**
     * 查询财务项目信息列表
     * @param projectReportData
     * @param page
     * @return
     */
    @ApiLog("查询离职申请信息列表")
    @GetMapping("list")
    public ResponseEntity<IPage<DepartRegistration>> data(DepartRegistration projectReportData, Page<DepartRegistration> page) throws Exception {
        IPage<DepartRegistration> result = new Page<DepartRegistration>();
        result = departService.findList (page,projectReportData);
        return ResponseEntity.ok (result);
    }

    /**
     * 保存离职申请信息
     * @param departRegistration
     * @return
     */
    @ApiLog(value = "保存离职申请信息", type = LogTypeEnum.SAVE)
    @PostMapping("save")
    public ResponseEntity save(@Valid @RequestBody DepartRegistration departRegistration) throws Exception {
        DepartRegistration s = departService.saveRegistration(departRegistration);
        return ResponseUtil.newInstance().add("businessTable", "human_resources_depart_registration")
                .add("businessId", s.getId())
                .ok ("操作成功");
    }

    /**
     * 查询
     * @param id
     * @return
     */
    @ApiOperation(value = "查询")
    @GetMapping("/findById")
    public ResponseEntity<DepartRegistration> findById(@RequestParam String id) throws Exception{
        DepartRegistration dto = departService.findById(id);
        return ResponseEntity.ok(dto);
    }

    /**
     * 查询
     * @param handoverId
     * @return
     */
    @ApiOperation(value = "查询")
    @GetMapping("/getByHandoverId")
    public ResponseEntity<DepartRegistration> getByHandoverId(@RequestParam String handoverId) {
        DepartRegistration dto = departService.getByHandoverId(handoverId);
        return ResponseEntity.ok(dto);
    }

    /**
     * 根据id修改状态status
     */
    @ApiOperation(value = "根据id修改状态status")
    @PostMapping(value = "updateStatusById")
    public void updateStatusById(@RequestBody DepartRegistration dto) {
        departService.updateStatusById(dto);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation(value = "删除")
    @GetMapping("/remove")
    public ResponseEntity<String> remove(@RequestParam String id){
        String s = departService.remove(id);
        return ResponseEntity.ok(s);
    }

    /**
     * 查询是否有已完成的流程数据
     * @param
     * @return
     */
    @ApiOperation(value = "查询是否有已完成的流程数据")
    @GetMapping("/selectComplete")
    public ResponseEntity<Boolean> selectComplete(){
        Boolean s = departService.selectComplete();
        return ResponseEntity.ok(s);
    }
}
