package com.njcn.csdevice.controller.ledger;


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.csdevice.pojo.dto.DevDetailDTO;
import com.njcn.csdevice.service.CsCommTerminalService;
import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
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 wr
 * @description
 * @date 2023/4/26 10:00
 */
@RestController
@RequestMapping("/commTerminal")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "通用台账查询")
public class CsCommTerminalController extends BaseController {


    private final CsCommTerminalService commTerminalService;

    /**
     * 根据用户获取设备信息
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getDevIdsByUser")
    @ApiOperation("根据登录用户id获取用户所有设备id集合")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true)
    public HttpResult<List<String>> getDevIdsByUser(@RequestParam("userId") String userId) {
        String methodDescribe = getMethodDescribe("getDevIdsByUser");
        List<String> devIds = commTerminalService.commGetDevIds(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, devIds, methodDescribe);
    }

    /**
     * 根据用户获取设备信息
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getLineIdsByUser")
    @ApiOperation("根据登录用户id获取用户所有监测点id集合")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true)
    public HttpResult<List<String>> getLineIdsByUser(@RequestParam("userId") String userId) {
        String methodDescribe = getMethodDescribe("getLineIdsByUser");
        List<String> lineIds = commTerminalService.getLineIdsByUser(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineIds, methodDescribe);
    }


    /**
     * 根据用户获取设备信息
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getPqUserIdsByUser")
    @ApiOperation("根据登录用户id获取电能质量用户id集合")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true)
    public HttpResult<List<String>> getPqUserIdsByUser(@RequestParam("userId") String userId) {
        String methodDescribe = getMethodDescribe("getLineIdsByUser");
        List<String> lineIds = commTerminalService.getPqUserIdsByUser(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineIds, methodDescribe);
    }



    /**
     * 通过监测点获取监测点数据单位
     * @author cdf
     * @date 2023/9/21
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/lineUnitDetail")
    @ApiOperation("根据监测点id获取数据单位")
    @ApiImplicitParam(name = "lineId", value = "实体", required = true)
    public HttpResult<PqsDeviceUnit> lineUnitDetail(@RequestParam("lineId") String lineId) {
        String methodDescribe = getMethodDescribe("lineUnitDetail");
        PqsDeviceUnit pqsDeviceUnit = commTerminalService.lineUnitDetail(lineId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsDeviceUnit, methodDescribe);
    }

    /**
     * 根据监测点id集合，获取所有台账信息
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLedgerByLineId")
    @ApiOperation("根据监测点id集合获取所有台账信息")
    @ApiImplicitParam(name = "list", value = "实体", required = true)
    public HttpResult<List<DevDetailDTO>> getLedgerByLineId(@RequestBody List<String> list) {
        String methodDescribe = getMethodDescribe("getLedgerByLineId");
        List<DevDetailDTO> result = commTerminalService.getLedgerByLineId(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

}
