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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.handover.domain.Handover;
import com.jeeplus.human.depart.handover.domain.HandoverProject;
import com.jeeplus.human.depart.handover.domain.dto.HandoverProjectDto;
import com.jeeplus.human.depart.handover.service.HandoverProjectService;
import com.jeeplus.human.depart.handover.service.HandoverService;
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;
import java.util.List;

/**
 * @author 王强
 * @version 1.0
 * @date 2023-10-27 9:04
 */
@RestController
@Api("离职交接")
@RequestMapping(value = "/handover")
public class HandoverController {

    @Resource
    private HandoverService handoverService;

    @Resource
    private HandoverProjectService handoverProjectService;

    /**
     * 保存离职交接信息
     * @param handover
     * @return
     */
    @ApiLog(value = "保存离职交接信息", type = LogTypeEnum.SAVE)
    @PostMapping("save")
    public ResponseEntity save(@Valid @RequestBody Handover handover) throws Exception {
        Handover s = handoverService.saveRegistration(handover);
        return ResponseUtil.newInstance().add("businessTable", "human_resources_depart_handover")
                .add("businessId", s.getId())
                .ok ("操作成功");
    }

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

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

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

    /**
     * 固定保存项目信息
     * @return
     */
    @ApiLog(value = "固定保存项目信息", type = LogTypeEnum.SAVE)
    @PostMapping("saveProject")
    public String saveProject(@RequestBody List<HandoverProject> handoverProject) throws Exception {
        return handoverProjectService.saveProject(handoverProject);
    }


    /**
     * 查询已固定的项目信息
     * @return
     */
    @ApiOperation(value = "查询已固定的项目信息")
    @GetMapping("/findProjectList")
    public ResponseEntity<IPage<HandoverProject> > findProjectList(Page<HandoverProject> page, HandoverProjectDto handoverProjectDto) throws Exception{
        IPage<HandoverProject> projectList = handoverProjectService.findProjectList(page, handoverProjectDto);
        return ResponseEntity.ok(projectList);
    }
}
