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

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.po.PqsProtectcontrolword;
import com.njcn.device.pq.service.IPqsProtectcontrolwordService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

/**
 * @Description: 定值控制定义表，管理
 * @Author: wr
 * @Date: 2023/8/11 8:51
 */
@Api(tags = "定值控制字定义管理")
@Controller
@RequestMapping(value = "protectcw")
@RequiredArgsConstructor
public class ProtectControlWordController extends BaseController {

    private final IPqsProtectcontrolwordService iPqsProtectcontrolwordService;

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getAll")
    @ApiOperation("获取定值信息")
    public HttpResult<List<PqsProtectcontrolword>> getAll(String pvIndex) {
        String methodDescribe = getMethodDescribe("getAll");
        List<PqsProtectcontrolword> list = iPqsProtectcontrolwordService.list(new LambdaQueryWrapper<PqsProtectcontrolword>()
                .eq(PqsProtectcontrolword::getPvIndex, pvIndex)
        );
        if (CollUtil.isEmpty(list)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, list, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getIsFT")
    @ApiOperation("获取定值信息")
    public HttpResult<Integer> getIsFT(String pvIndex) {
        String methodDescribe = getMethodDescribe("getIsFT");
        List<PqsProtectcontrolword> list = iPqsProtectcontrolwordService.list(new LambdaQueryWrapper<PqsProtectcontrolword>()
                .eq(PqsProtectcontrolword::getPvIndex, pvIndex)
        );
        if (CollUtil.isEmpty(list)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, 0, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, 1, methodDescribe);
    }
}
