package com.lz.modules.performance.controller;


import com.lz.common.utils.R;
import com.lz.modules.flow.entity.ResultCalculate;
import com.lz.modules.flow.model.ResultCalculateDto;
import com.lz.modules.flow.service.ResultCalculateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/resultCalculate")
@Api(tags = "模板计算公式相关")
public class ResultCalculateController {


    @Autowired
    private ResultCalculateService resultCalculateService;


    @GetMapping("/getModelCalculates")
    @ApiOperation("获取绩效模板支持的计算公式列表")
    @ApiResponses({@ApiResponse(code = 200,message = "成功",response = ResultCalculateDto.class)})
    public R getModelCalculates(){
        List<ResultCalculateDto> resultCalculates = resultCalculateService.selectResultCalculateByBusinessId(1l);
        return R.ok().put("list",resultCalculates);
    }



     @RequestMapping("/getById")
     public R getById(@RequestBody ResultCalculate resultCalculate) {
        resultCalculate = resultCalculateService.selectResultCalculateById(resultCalculate.getId());
        return R.ok().put("resultCalculate",resultCalculate);
     }


     @RequestMapping("/update")
     public R update(@RequestBody ResultCalculate resultCalculate) {
        resultCalculateService.updateResultCalculateById(resultCalculate);
        return R.ok();
     }


     @RequestMapping("/save")
     public R save(@RequestBody ResultCalculate resultCalculate) {
        resultCalculateService.insertResultCalculate(resultCalculate);
        return R.ok();
     }


    @RequestMapping("/delete")
    public R list(@RequestBody Long id) {
        resultCalculateService.deleteResultCalculateById(id);
        return R.ok();
     }
}
