package com.njcn.device.device.controller;


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.device.service.NodeDeviceService;
import com.njcn.device.pq.pojo.dto.DeviceInfo;
import com.njcn.device.pq.pojo.dto.NodeProcessDeviceTree;
import com.njcn.device.pq.pojo.param.NodeDeviceParam;
import com.njcn.device.pq.pojo.po.DeviceProcess;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 前置程序控制器
 * @author cdf
 * @since 2022-01-07
 */
@Slf4j
@Api(tags = "前置机终端管理")
@RestController
@RequestMapping("nodeDevice")
@RequiredArgsConstructor
public class NodeDeviceController extends BaseController {

    private final NodeDeviceService nodeDeviceService;


    /**
     * 根据前置ip获取对应的终端台账信息
     * @author cdf
     * @date 2021/6/23
     */
    @ApiOperation("根据前置ip获取对应的终端台账信息")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
    @PostMapping("nodeDeviceList")
    public HttpResult<List<DeviceInfo>> nodeDeviceList(@RequestBody NodeDeviceParam nodeDeviceParam){
        String methodDescribe = getMethodDescribe("nodeDeviceList");
        List<DeviceInfo> list =  nodeDeviceService.nodeDeviceList(nodeDeviceParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @ApiOperation("查询前置-进程-设备-设备树")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
    @PostMapping("nodeDeviceTree")
    public HttpResult<NodeProcessDeviceTree> nodeDeviceTree(@RequestParam("nodeId") String nodeId){
        String methodDescribe = getMethodDescribe("nodeDeviceTree");
        NodeProcessDeviceTree list =  nodeDeviceService.nodeDeviceTree(nodeId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @ApiOperation("一键分配装置所属进程号")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
    @PostMapping("oneKeyDistribution")
    public HttpResult<Boolean> oneKeyDistribution(@RequestParam("nodeId") String nodeId){
        String methodDescribe = getMethodDescribe("oneKeyDistribution");
        nodeDeviceService.oneKeyDistribution(nodeId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    @ApiOperation("更新设备进程号")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
    @PostMapping("updateDeviceProcess")
    public HttpResult<Boolean> updateDeviceProcess(@RequestBody DeviceProcess deviceProcess){
        String methodDescribe = getMethodDescribe("updateDeviceProcess");
        Boolean flag =  nodeDeviceService.updateDeviceProcess(deviceProcess);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }


}

