package com.lz.modules.performance.controller;


import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.modules.flow.entity.ResultTagetLib;
import com.lz.modules.flow.model.ResultTagetLibDto;
import com.lz.modules.flow.req.ResultTagetLibSearchReq;
import com.lz.modules.performance.service.ResultTagetLibService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/resultTagetLib")
@Api(tags = "考核指标相关")
@Slf4j
public class ResultTagetLibController {


    @Autowired
    private ResultTagetLibService resultTagetLibService;





    @PostMapping("/GetTargetLibs")
    @ApiOperation("搜索指标库")
    @ApiResponses({@ApiResponse(code = 200,message = "成功",response = ResultTagetLibDto.class)})
    public R GetTargetLibs(@RequestBody @ApiParam ResultTagetLibSearchReq req) {
        log.info("搜索指标请求的数据{}", req);
        PageUtils pageUtils = resultTagetLibService.selectResultTagetLibByReq(req);
        return R.ok().put("data",pageUtils);
    }


     @RequestMapping("/getById")
     public R getById(@RequestBody ResultTagetLib resultTagetLib) {
        resultTagetLib = resultTagetLibService.selectResultTagetLibById(resultTagetLib.getId());
        return R.ok().put("resultTagetLib",resultTagetLib);
     }


     @RequestMapping("/update")
     public R update(@RequestBody ResultTagetLib resultTagetLib) {
        resultTagetLibService.updateResultTagetLibById(resultTagetLib);
        return R.ok();
     }


     @PostMapping("/save")
     @ApiOperation("保存考核指标")
     public R save(@RequestBody @ApiParam ResultTagetLib resultTagetLib) {
        log.info("保存考核指标{}", resultTagetLib);
        if(resultTagetLib.getId() != null && resultTagetLib.getId().intValue() > 0){
            return update(resultTagetLib);
        }
        return resultTagetLibService.insertResultTagetLib(resultTagetLib);

     }


    @GetMapping("/delete")
    @ApiOperation("删除指标")
    public R delete(@RequestParam @ApiParam("指标id") Long id) {
        resultTagetLibService.deleteResultTagetLibById(id);
        return R.ok();
     }
}
