package com.huimv.env.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.env.admin.common.utils.Result;
import com.huimv.env.admin.common.utils.ResultCode;
import com.huimv.env.admin.entity.TerminalPort;
import com.huimv.env.admin.entity.vo.PortListByGatewayIdParam;
import com.huimv.env.admin.entity.vo.TerminalPortConfigParam;
import com.huimv.env.admin.service.ITerminalPortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 端口 前端控制器
 * </p>
 *
 * @author newspaper
 * @since 2024-05-07
 */
@RestController
@CrossOrigin
@RequestMapping("/port")
public class TerminalPortController {
    @Autowired
    private ITerminalPortService portService;

    @PostMapping("/listByTerminalId")
    public Result list(@RequestBody PortListByGatewayIdParam portListByGatewayIdParam){
        Integer gatewayId = portListByGatewayIdParam.getGatewayId();
        List<TerminalPort> terminalPorts = portService.list(new QueryWrapper<TerminalPort>().lambda()
                .eq(TerminalPort::getTerminalId, gatewayId));
        return new Result(ResultCode.SUCCESS,terminalPorts);
    }

    @PostMapping("/config")
    public Result config(@RequestBody TerminalPortConfigParam terminalPortConfigParam){
        TerminalPort terminalPort = portService.getById(terminalPortConfigParam.getPortId());
        terminalPort.setLocationId(terminalPortConfigParam.getLocationId());
        return Result.SUCCESS();
    }

}
