package org.springblade.modules.external.ycbigdata.smartapplication.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.community.agency.entity.Agency;
import org.springblade.community.building.entity.Building;
import org.springblade.community.residential.entity.Residential;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springblade.modules.external.ycbigdata.community.vo.AgencyVO;
import org.springblade.modules.external.ycbigdata.community.vo.BuildingVO;
import org.springblade.modules.external.ycbigdata.community.vo.ResidentialVO;
import org.springblade.modules.external.ycbigdata.community.wrapper.AgencyWrapper;
import org.springblade.modules.external.ycbigdata.community.wrapper.BuildingWrapper;
import org.springblade.modules.external.ycbigdata.community.wrapper.ResidentialWrapper;
import org.springblade.modules.external.ycbigdata.smartapplication.vo.FaceDeviceVO;
import org.springblade.modules.external.ycbigdata.smartapplication.vo.SmartDeviceVO;
import org.springblade.modules.external.ycbigdata.smartapplication.vo.VideoCloudDeviceVO;
import org.springblade.modules.external.ycbigdata.smartapplication.wrapper.FaceDeviceWrapper;
import org.springblade.modules.external.ycbigdata.smartapplication.wrapper.SmartDeviceWrapper;
import org.springblade.modules.external.ycbigdata.smartapplication.wrapper.VideoCloudDeviceWrapper;
import org.springblade.smartapplication.facedevice.entity.FaceDevice;
import org.springblade.smartapplication.facedevice.service.IFaceDeviceService;
import org.springblade.smartapplication.smartsmoke.entity.SmartDevice;
import org.springblade.smartapplication.smartsmoke.service.ISmartDeviceService;
import org.springblade.smartapplication.vcdevice.entity.VideoCloudDevice;
import org.springblade.smartapplication.vcdevice.service.IVideoCloudDeviceService;
import org.springblade.system.orgposition.service.IOrgPositionService;
import org.springblade.utils.QueryWrapperUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created By lidexi in 2021/3/17
 **/
@RestController
@AllArgsConstructor
@RequestMapping("/bigdata/smartapplication")
@Api(value = "智能应用-对外（银川大数据）接口", tags = "智能应用-对外（银川大数据）接口")
public class SmartApplicationExternalController {

	private IOrgPositionService orgPositionService;
	private ISmartDeviceService smartDeviceService;
	private IVideoCloudDeviceService videoCloudDeviceService;
	private IFaceDeviceService faceDeviceService;

	/**
	 * 获取物联网设备列表
	 */
	@GetMapping("/smartdevice/get")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "获取物联网设备列表", notes = "获取物联网设备列表")
	public R<IPage<SmartDeviceVO>> smartDeviceList(SmartDevice smartDevice, Query query, BladeUser bladeUser) {
		LambdaQueryWrapper<SmartDevice> smartDeviceLambdaQueryWrapper = new QueryWrapperUtil<SmartDevice>().getBasicQueryWrapper(SmartDevice::getOrgPosition, smartDevice, bladeUser, orgPositionService);
		IPage<SmartDevice> page = smartDeviceService.page(Condition.getPage(query), smartDeviceLambdaQueryWrapper.eq(SmartDevice::getTenantId, bladeUser.getTenantId()));
		return R.data(SmartDeviceWrapper.build().pageVO(page));
	}

	/**
	 * 获取门禁设备列表
	 */
	@GetMapping("/facedevice/get")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "获取门禁设备列表", notes = "获取门禁设备列表")
	public R<IPage<FaceDeviceVO>> residentialList(FaceDevice faceDevice, Query query, BladeUser bladeUser) {
		LambdaQueryWrapper<FaceDevice> faceDeviceLambdaQueryWrapper = new QueryWrapperUtil<FaceDevice>().getBasicQueryWrapper(FaceDevice::getOrgPosition, faceDevice, bladeUser, orgPositionService);
		IPage<FaceDevice> page = faceDeviceService.page(Condition.getPage(query), faceDeviceLambdaQueryWrapper.eq(FaceDevice::getTenantId, bladeUser.getTenantId()));
		return R.data(FaceDeviceWrapper.build().pageVO(page));
	}

	/**
	 * 获取视频云设备列表
	 */
	@GetMapping("/videoclouddevice/get")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "获取视频云设备列表", notes = "获取视频云设备列表")
	public R<IPage<VideoCloudDeviceVO>> vcdeviceList(VideoCloudDevice videoCloudDevice, Query query, BladeUser bladeUser) {
		LambdaQueryWrapper<VideoCloudDevice> videoCloudDeviceLambdaQueryWrapper = new QueryWrapperUtil<VideoCloudDevice>().getBasicQueryWrapper(VideoCloudDevice::getOrgPosition, videoCloudDevice, bladeUser, orgPositionService);
		IPage<VideoCloudDevice> page = videoCloudDeviceService.page(Condition.getPage(query), videoCloudDeviceLambdaQueryWrapper.eq(VideoCloudDevice::getTenantId, bladeUser.getTenantId()));
		return R.data(VideoCloudDeviceWrapper.build().pageVO(page));
	}
}
