package com.njcn.device.pms.controller.majornetwork;


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.biz.pojo.po.PqsDeviceUnit;
import com.njcn.device.pms.pojo.vo.DeviceUnitVo;
import com.njcn.device.pms.service.majornetwork.IPqsDeviceUnitService;
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 org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 数据单位管理
 * </p>
 *
 * @author wr
 * @since 2023-08-21
 */
@RestController
@Api(tags = "数据单位管理")
@RequestMapping("/pq/pqsDeviceUnit")
@RequiredArgsConstructor
public class PqsDeviceUnitController extends BaseController {

    private final IPqsDeviceUnitService iPqsDeviceUnitService;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/nodeTree")
    @ApiOperation("数据单位查询树")
    @ApiImplicitParam(name = "devFlag", value = "实体", required = true)
    public HttpResult<List<DeviceUnitVo>> nodeTree(String devFlag) {
        String methodDescribe = getMethodDescribe("nodeTree");
        List<DeviceUnitVo> pqsDeviceUnitVos = iPqsDeviceUnitService.nodeList(devFlag);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsDeviceUnitVos, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/saveDeviceUnit")
    @ApiOperation("数据单位修改")
    @ApiImplicitParam(name = "unit", value = "实体", required = true)
    public HttpResult<Boolean> saveDeviceUnit(@RequestBody PqsDeviceUnit unit) {
        String methodDescribe = getMethodDescribe("saveDeviceUnit");
        Boolean aBoolean = iPqsDeviceUnitService.saveDeviceUnit(unit);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, aBoolean, methodDescribe);

    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/lineUnitDetail")
    @ApiOperation("根据监测点id获取数据单位")
    @ApiImplicitParam(name = "lineID", value = "实体", required = true)
    public HttpResult<PqsDeviceUnit> lineUnitDetail(@RequestParam("lineID") String lineID) {
        String methodDescribe = getMethodDescribe("lineUnitDetail");
        PqsDeviceUnit pqsDeviceUnit = iPqsDeviceUnitService.lineUnitDetail(lineID);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsDeviceUnit, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/devUnitDetail")
    @ApiOperation("根据终端id获取数据单位")
    @ApiImplicitParam(name = "devID", value = "实体", required = true)
    public HttpResult<PqsDeviceUnit> devUnitDetail(@RequestParam("devID") String devID) {
        String methodDescribe = getMethodDescribe("devUnitDetail");
        PqsDeviceUnit pqsDeviceUnit = iPqsDeviceUnitService.devUnitDetail(devID);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsDeviceUnit, methodDescribe);

    }

}

