package com.tofly.xrtygis.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.xrtygis.entity.TfKpiManage;
import com.tofly.xrtygis.entity.TfKpiPersonManage;
import com.tofly.xrtygis.entity.dto.TfKpiManageDto;
import com.tofly.xrtygis.entity.dto.TfKpiPersonManageDto;
import com.tofly.xrtygis.service.TfKpiManageService;
import com.tofly.xrtygis.service.TfKpiPersonManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 绩效考核人员管理
 *
 * @author JF
 * @date
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tfkpipersonmanage")
@Api(tags="绩效考核人员管理接口")
public class TfKpiPersonManageController {

    private final TfKpiPersonManageService tfKpiPersonManageService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param tfKpiPersonManage 绩效考核人员管理
     * @return
     */
    @GetMapping("/page" )
    @ToFlyAppLog(title="分页查询" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getTfKpiPersonManagePage(Page page, @ModelAttribute TfKpiPersonManage tfKpiPersonManage) {
        try{
            return ResultRespone.success(tfKpiPersonManageService.page(page, Wrappers.query(tfKpiPersonManage)));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }

    }

    /**
     * 通过id查询绩效考核人员管理
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ToFlyAppLog(title="通过ID查询" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
        try{
            return ResultRespone.success(tfKpiPersonManageService.getById(id));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }

    }

    /**
     * 新增绩效考核人员管理
     * @param tfKpiPersonManageDto 绩效考核人员管理
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增绩效考核人员管理" )
    @ApiOperation(value = "新增绩效考核人员管理")
    @PostMapping
    public ResultRespone save(TfKpiPersonManageDto tfKpiPersonManageDto) {
        try{
            return ResultRespone.success(tfKpiPersonManageService.saveTfKpiPersonManage(tfKpiPersonManageDto));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }

    }

    /**
     * 修改绩效考核人员管理
     * @param tfKpiPersonManage 绩效考核人员管理
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改绩效考核人员管理" )
    @ApiOperation(value = "修改绩效考核人员管理")
    @PutMapping
    public ResultRespone updateById(@RequestBody TfKpiPersonManage tfKpiPersonManage) {
        try{
            return ResultRespone.success(tfKpiPersonManageService.updateById(tfKpiPersonManage));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }

    }

    /**
     * 通过id删除绩效考核人员管理
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除绩效考核人员管理" )
    @ApiOperation(value = "通过ID删除绩效考核人员管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
        try{
            return ResultRespone.success(tfKpiPersonManageService.removeById(id));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }

    }

    /**
     * 通过id批量删除绩效考核人员管理
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id批量删除绩效考核人员管理" )
    @ApiOperation(value = "通过ID批量删除绩效考核人员管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeById(String ids) {
        try{
            return ResultRespone.success(tfKpiPersonManageService.removeByIds(Arrays.asList(ids.split(","))));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }

    }
}
