package com.njcn.energy.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.energy.pojo.param.DataSetParam;
import com.njcn.energy.pojo.po.DataMould;
import com.njcn.energy.pojo.po.DataSet;
import com.njcn.energy.service.IDataSetService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/9 10:06
 */
@Slf4j
@RestController
@RequestMapping("/dataSet")
@RequiredArgsConstructor
@Api(tags = "装置数据集管理")
public class DataSetController extends BaseController {

    private final IDataSetService dataSetService;

    @PostMapping("/add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("新增装置数据集")
    @ApiImplicitParam(name = "dataSetParam", value = "装置数据集", required = true)
    public HttpResult<DataMould> add(@RequestBody DataSetParam dataSetParam){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，装置数据集为：{}", methodDescribe, dataSetParam);
        DataSet dataSet = dataSetService.add(dataSetParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @DeleteMapping("/delete")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.DELETE)
    @ApiOperation("删除数据集")
    @ApiImplicitParam(name = "id", value = "模板id", required = true)
    public HttpResult<Boolean> delete(@RequestParam String id){
        String methodDescribe = getMethodDescribe("delete");
        LogUtil.njcnDebug(log, "{}，模板id：{}", methodDescribe, id);
        boolean result = dataSetService.delete(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @GetMapping("/findSetById")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("根据id获取数据集")
    @ApiImplicitParam(name = "id", value = "模板id", required = true)
    public HttpResult<List<DataSet>> findSetById(@RequestParam String id){
        String methodDescribe = getMethodDescribe("findSetById");
        LogUtil.njcnDebug(log, "{}，模板id：{}", methodDescribe, id);
        List<DataSet> list = dataSetService.findSetById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

}
