package net.northking.cctp.device.api.pcDevice;


import cn.gjing.tools.auth.annotation.RequiredPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.db.Pagination;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.device.api.pcDevice.service.CdPcDeviceApiService;
import net.northking.cctp.device.dto.pcDevice.CdPcDeviceDetailDto;
import net.northking.cctp.device.dto.pcDevice.CdPcDeviceQueryDto;
import net.northking.cctp.device.dto.pcDevice.CdPcDeviceScriptDto;
import net.northking.cctp.device.dto.pcDevice.ScriptPcResultDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.integration.redis.util.RedisLockRegistry;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "PC设备信息(Platform)")
@RequestMapping("/v1")
@RestController
public class CdPcDevicePlatformCtrl {
    /**
     * 日志
     */
    private final static Logger logger = LoggerFactory.getLogger(CdPcDevicePlatformCtrl.class);

    @Autowired
    private CdPcDeviceApiService cdPcDeviceApiService;

    @Autowired
    private RedisLockRegistry redisLockRegistry;


    /**
     * 查询用户列表
     *
     * @param queryByPage  查询条件
     * @return 数据列表
     */
    @ApiOperation(value = "分页查询列表(平台)")
    @RequiredPermissions("pcDeviceManag")
    @PostMapping(value = "/paging/query/pc-devices",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<Pagination<CdPcDeviceDetailDto>> pagingQuery(
            @RequestBody QueryByPage<CdPcDeviceQueryDto> queryByPage)
    {
        ResultWrapper<Pagination<CdPcDeviceDetailDto>> wrapper = new ResultWrapper<>();
        Pagination<CdPcDeviceDetailDto> page = cdPcDeviceApiService.pagingQuery(queryByPage);

        return wrapper.success(page);
    }

    @ApiOperation(value = "查询未分配系统的pc设备")
    @PostMapping(value = "/paging/query/pc-devices/none/project",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<Pagination<CdPcDeviceDetailDto>> pagingNoneProject(
            @RequestBody QueryByPage<CdPcDeviceQueryDto> queryByPage){
        ResultWrapper<Pagination<CdPcDeviceDetailDto>> wrapper = new ResultWrapper<>();
        Pagination<CdPcDeviceDetailDto> page = cdPcDeviceApiService.pagingNoneProject(queryByPage);
        return wrapper.success(page);
    }

    @ApiOperation(value = "查询已分配系统的PC设备")
    @PostMapping(value = "/paging/query/pc-devices/deviceByProject",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<Pagination<CdPcDeviceDetailDto>> deviceByProject(
            @RequestBody QueryByPage<CdPcDeviceQueryDto> queryByPage){
        ResultWrapper<Pagination<CdPcDeviceDetailDto>> wrapper = new ResultWrapper();
        Pagination<CdPcDeviceDetailDto> page = cdPcDeviceApiService.pagingByProject(queryByPage);
        return wrapper.success(page);
    }

    @ApiOperation(value = "分页查询Pc设备(脚本查询可用设备)")
    @PostMapping(value = "/paging/query/pc-devices/scriptByPro",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<Pagination<ScriptPcResultDto>> scriptDeviceByPro(
            @RequestBody QueryByPage<CdPcDeviceScriptDto> queryByPage){
        ResultWrapper<Pagination<ScriptPcResultDto>> wrapper = new ResultWrapper();
        Pagination<ScriptPcResultDto> result = this.cdPcDeviceApiService.scriptDeviceByPro(queryByPage);
        return wrapper.success(result);
    }
}
