package com.nantian.cloud.dbcapp.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.nantian.cloud.dbcapp.entity.TEnergyTceCorrect;
import com.nantian.cloud.dbcapp.service.TEnergyTceCorrectService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/tEnergyTceCorrect")
public class TEnergyTceCorrectController {
    @Autowired
    private TEnergyTceCorrectService tEnergyTceCorrectService;

    @GetMapping("/getList")
    @SysLog("获取企业能耗计算耗能量修正")
    @ApiOperation(value = "获取企业能耗计算耗能量修正", notes = "获取企业能耗计算耗能量修正")
    @ApiImplicitParam(name = "epc", value = "企业信用编码", required = true, dataType = "string", paramType = "path")
    public R getList(String epc){
        if (epc == null) {
            return R.failed("企业信用编码为空，查询失败！");
        }
        return R.ok(tEnergyTceCorrectService.getList(epc));
    }

    @PostMapping("/addCorrect")
    @SysLog("新增企业能耗计算耗能量修正")
    @ApiOperation(value = "新增企业能耗计算耗能量修正", notes = "新增企业能耗计算耗能量修正")
    @ApiImplicitParam(name = "tEnergyTceCorrect", value = "新增企业能耗计算耗能量修正", required = true, dataType = "json", paramType = "path")
    public R save(@RequestBody TEnergyTceCorrect tEnergyTceCorrect) {
        TEnergyTceCorrect t = new TEnergyTceCorrect();
        if(tEnergyTceCorrectService.getOne(Wrappers.query(tEnergyTceCorrect))!=null){
            return R.failed("记录已经存在不能重复添加！");
        }
        Boolean state=tEnergyTceCorrectService.save(tEnergyTceCorrect);
        return state ? R.ok() : R.failed();
    }

    @ApiOperation(value = "修改企业能耗计算耗能量修正", notes = "修改企业能耗计算耗能量修正")
    @SysLog("修改企业能耗计算耗能量修正")
    @PutMapping("/updateCorrect")
    public R updateCorrect(@RequestBody TEnergyTceCorrect tEnergyTceCorrect){
        return R.ok(tEnergyTceCorrectService.updateById(tEnergyTceCorrect));
    }

    @ApiOperation(value = "删除企业能耗计算耗能量修正", notes = "删除企业能耗计算耗能量修正")
    @SysLog("删除企业能耗计算耗能量修正")
    @DeleteMapping("/delete")
    public R delete(Integer id) {
        TEnergyTceCorrect tEnergyTceCorrect = tEnergyTceCorrectService.getById(id);
        if (tEnergyTceCorrect == null) {
            return R.failed("企业能耗计算耗能量修正不存在，删除失败！");
        }

        return R.ok(tEnergyTceCorrectService.removeById(id));
    }
}
