package com.njcn.device.pq.controller.configuration;

import cn.hutool.core.collection.CollUtil;
import com.njcn.common.pojo.annotation.OperateInfo;
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.device.pq.pojo.param.ConstantValueParam;
import com.njcn.device.pq.service.IPqsProtectvalueService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:定值管理
 * @Author: wr
 * @Date: 2023/8/10 18:30
 */
@Api(tags = "定值管理")
@RestController
@RequestMapping("/constant")
@RequiredArgsConstructor
public class ConstantValueController extends BaseController {

    private final IPqsProtectvalueService iPqsProtectvalueService;


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/quarryOutValue")
    @ApiOperation("获取定值信息")
    public HttpResult<List<Object>> quarryOutValue(String id, String isOutIn) {
        String methodDescribe = getMethodDescribe("quarryOutValue");
        List<Object> objects = iPqsProtectvalueService.quarryOutValueBase(isOutIn, id);
        if (CollUtil.isEmpty(objects)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, objects, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, objects, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/updateDatabaseValue")
    @ApiOperation("定值更新数据库Value")
    public HttpResult<Boolean> updateDatabaseValue(String json) {
        String methodDescribe = getMethodDescribe("updateDatabaseValue");
        Boolean aBoolean = iPqsProtectvalueService.updateDatabaseValue(json);
        if (!aBoolean) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, true, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, false, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/updateDatabase")
    @ApiOperation("定值更新数据库")
    public HttpResult<Boolean> updateDatabase(@RequestBody ConstantValueParam param) {
        String methodDescribe = getMethodDescribe("updateDatabase");
        Boolean aBoolean = iPqsProtectvalueService.updateDatabase(param);
        if (!aBoolean) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, true, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, false, methodDescribe);
    }


}
