/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.xrtygis.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
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.dto.TfKpiManageDto;
import com.tofly.xrtygis.service.TfKpiManageService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;
/**
 * 绩效考核管理
 *
 * @author JF
 * @date Fri Mar 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tfkpimanage")
@Api(tags="绩效考核管理接口")
public class TfKpiManageController {

    private final  TfKpiManageService tfKpiManageService;

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

    }

    /**
     * 汇总分页查询
     * @param page 汇总分页对象
     * @param tfKpiManageDto 绩效考核管理Dto
     * @return
     */
    @GetMapping("/censusPage" )
    @ToFlyAppLog(title="汇总分页查询" )
    @ApiOperation(value = "汇总分页查询")
    public ResultRespone getTfKpiCensusPage(Page page, @ModelAttribute TfKpiManageDto tfKpiManageDto) {
        try{
            return ResultRespone.success(tfKpiManageService.getTfKpiCensusPage(page,tfKpiManageDto));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 考核明细分页查询
     * @param page 分页对象
     * @param tfKpiManageDto 绩效考核管理Dto
     * @return
     */
    @GetMapping("/detailedPage" )
    @ToFlyAppLog(title="考核明细分页查询" )
    @ApiOperation(value = "考核明细分页查询")
    public ResultRespone getTfKpiDetailedPage(Page page, @ModelAttribute TfKpiManageDto tfKpiManageDto) {
        try{
            return ResultRespone.success(tfKpiManageService.getTfKpiDetailedPage(page,tfKpiManageDto));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 统计图查询
     * @param tfKpiManageDto 绩效考核管理Dto
     * @return
     */
    @GetMapping("/censusPhoto" )
    @ToFlyAppLog(title="统计图查询" )
    @ApiOperation(value = "统计图查询")
    public ResultRespone getCensusInfo(TfKpiManageDto tfKpiManageDto) {
        try{
            return ResultRespone.success(tfKpiManageService.getTfKpiCensusPhoto(tfKpiManageDto));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 通过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(tfKpiManageService.getById(id));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 新增绩效考核管理
     * @param tfKpiManageDto 绩效考核管理
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增绩效考核管理" )
    @ApiOperation(value = "新增绩效考核管理")
    @PostMapping
    public ResultRespone save(TfKpiManageDto tfKpiManageDto) {
        try{
            return ResultRespone.success(tfKpiManageService.save(tfKpiManageDto));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 修改绩效考核管理
     * @param tfKpiManage 绩效考核管理
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改绩效考核管理" )
    @ApiOperation(value = "修改绩效考核管理")
    @PutMapping
    public ResultRespone updateById(@RequestBody TfKpiManage tfKpiManage) {
        try{
//            if(StringUtils.isNotBlank(tfKpiManage.getAssessScore())&& StringUtils.isBlank(tfKpiManage.getIsQualify())){
//                if(Integer.parseInt(tfKpiManage.getAssessScore())>=60&&Integer.parseInt(tfKpiManage.getAssessScore())<=100){
//                    tfKpiManage.setIsQualify("2");
//                }else {
//                    tfKpiManage.setIsQualify("1");
//                }
//            }
            return ResultRespone.success(tfKpiManageService.updateById(tfKpiManage));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 通过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(tfKpiManageService.removeById(id));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 通过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(tfKpiManageService.removeByIds(Arrays.asList(ids.split(","))));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }
}
