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.DataGroupParam;
import com.njcn.energy.pojo.po.DataGroup;
import com.njcn.energy.service.IDataGroupService;
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;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/16 9:03
 */
@Slf4j
@RestController
@RequestMapping("/group")
@RequiredArgsConstructor
@Api(tags = "分组管理")
public class DataGroupController extends BaseController {

    private final IDataGroupService dataGroupService;

    @PostMapping("/add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("新增分组")
    @ApiImplicitParam(name = "dataGroupParam", value = "分组信息", required = true)
    public HttpResult<DataGroup> add(@RequestBody DataGroupParam dataGroupParam){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，分组信息：{}", methodDescribe, dataGroupParam);
        DataGroup dataGroup = dataGroupService.addDataGroup(dataGroupParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @GetMapping("/findGroupById")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("查询组")
    @ApiImplicitParam(name = "list", value = "数据集合", required = true)
    public HttpResult<List<DataGroup>> findGroupById(@RequestParam List<String> list){
        String methodDescribe = getMethodDescribe("findGroupById");
        LogUtil.njcnDebug(log, "{}，数据集合：{}", methodDescribe, list);
        List<DataGroup> result = dataGroupService.findGroupById(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

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


}
