package org.springblade.device.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.plugins.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springblade.common.constant.DeviceConstant;
import org.springblade.core.mp.support.BladePage;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.device.dto.IotDeviceDTO;
import org.springblade.device.entity.IotDevice;
import org.springblade.device.service.IIotDeviceService;
import org.springblade.device.vo.IotDeviceVO;
import org.springblade.device.vo.SingleDeviceStatistics;
import org.springblade.device.wrapper.IotDeviceWrapper;
import org.springblade.system.entity.DictBiz;
import org.springblade.system.expand.entity.OrgPosition;
import org.springblade.system.expand.feign.IOrgPositionClient;
import org.springblade.system.expand.util.QueryWrapperUtil;
import org.springblade.system.expand.vo.OrgPositionVO;
import org.springblade.system.feign.IDictBizClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 智能设备 client
 *
 * @author lianghanqiang
 * @since 2021-04-19
 */

@RequiredArgsConstructor
@RestController
@RequestMapping("/feign/iotdevice")
public class IotDeviceClient implements IIotDeviceClient {

	private final IIotDeviceService iotDeviceService;
	private final IOrgPositionClient orgPositionClient;
	private final IDictBizClient dictBizClient;

	/**
	 * 详情
	 */
	@Override
	@GetMapping("/detail")
	public IotDeviceVO detail(@SpringQueryMap IotDevice iotDevice) {
		IotDevice detail = iotDeviceService.getOne(Condition.getQueryWrapper(iotDevice));
		if (detail != null) {
			return IotDeviceWrapper.build().entityVO(detail);
		}
		return null;
	}

	@Override
	@GetMapping("/getById")
	public IotDevice getById(@RequestParam Long id) {
		return this.iotDeviceService.getById(id);
	}

	@Override
	@PostMapping("/getList")
	public BladePage<IotDeviceVO> getList(@RequestBody IotDeviceDTO iotDeviceDTO) {
		IotDevice iotDevice = Objects.requireNonNull(BeanUtil.copy(iotDeviceDTO, IotDevice.class));
		LambdaQueryWrapper<IotDevice> queryWrapper = null;
		if (iotDeviceDTO.getEnterpriseIds() != null) {
			String enterpriseIds = iotDevice.getEnterpriseIds();
			iotDevice.setEnterpriseIds(null);
			queryWrapper = Condition.getQueryWrapper(iotDevice).lambda().like(IotDevice::getEnterpriseIds, enterpriseIds);
		} else {
			queryWrapper = Condition.getQueryWrapper(iotDevice).lambda();
		}
		IPage<IotDevice> page = this.iotDeviceService.page(Condition.getPage(iotDeviceDTO.getQuery()), queryWrapper);
		IPage<IotDeviceVO> pageVO = IotDeviceWrapper.build().pageVO(page);
		return BladePage.of(pageVO);
	}

	@Override
	public List<IotDeviceVO> list(IotDevice iotDevice) {
		LambdaQueryWrapper<IotDevice> queryWrapper = new QueryWrapperUtil<IotDevice>().getBasicQueryWrapper(IotDevice::getOrgPosition, iotDevice, AuthUtil.getUser(), orgPositionClient);
		return IotDeviceWrapper.build().listVO(iotDeviceService.list(queryWrapper));
	}


	/**
	 * 查询 智能设备
	 */
	@Override
	@GetMapping("/listMap")
	public List<IotDeviceVO> listMap(@RequestParam Map<String, Object> iotDevice) {
		LambdaQueryWrapper<IotDevice> queryWrapper = new QueryWrapperUtil<IotDevice>().getBasicQueryWrapperByMap(IotDevice::getOrgPosition, iotDevice, new IotDevice(), AuthUtil.getUser(), orgPositionClient);
		return IotDeviceWrapper.build().listVO(iotDeviceService.list(queryWrapper));
	}

	@Override
	@GetMapping("/getListByRoomIds")
	public List<IotDeviceVO> getListByRoomIds(@RequestParam List<Long> roomIds) {
		LambdaQueryWrapper<IotDevice> lambdaQueryWrapper = new QueryWrapper<>(new IotDevice()).lambda().in(IotDevice::getRoomId, roomIds);

		return IotDeviceWrapper.build().listVO(iotDeviceService.list(lambdaQueryWrapper));
	}


	/**
	 * 新增 智能设备
	 */
	@Override
	@PostMapping("/save")
	public boolean save(@Valid @RequestBody IotDevice iotDevice) {
		return iotDeviceService.save(iotDevice);
	}

	/**
	 * 修改 智能设备
	 */
	@Override
	@PostMapping("/update")
	public boolean update(@Valid @RequestBody IotDevice iotDevice) {
		return iotDeviceService.updateById(iotDevice);
	}

	/**
	 * 新增或修改 智能设备
	 */
	@Override
	@PostMapping("/submit")
	public boolean submit(@Valid @RequestBody IotDevice iotDevice) {
		return iotDeviceService.saveOrUpdate(iotDevice);
	}


	/**
	 * 删除 智能设备
	 */
	@Override
	@PostMapping("/remove")
	public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return iotDeviceService.deleteLogic(Func.toLongList(ids));
	}

	@Override
	@GetMapping("/getSmokeDeviceList")
	public List<IotDevice> getSmokeDeviceList(IotDevice iotDevice) {
		return iotDeviceService.getBaseMapper().selectList(new QueryWrapper<>(new IotDevice()).lambda()
			.eq(IotDevice::getDeviceType, DeviceConstant.DeviceType.SMOKE.getValue()).or()
			.eq(IotDevice::getDeviceType, DeviceConstant.DeviceType.SMOKE_MODEL.getValue())
			.eq(IotDevice::getTenantId, iotDevice.getTenantId()));
	}

	@Override
	@GetMapping("/getGasDeviceList")
	public List<IotDevice> getGasDeviceList(IotDevice iotDevice) {
		return iotDeviceService.getBaseMapper().selectList(new QueryWrapper<>(new IotDevice()).lambda()
			.eq(IotDevice::getDeviceType, DeviceConstant.DeviceType.GAS.getValue()).or()
			.eq(IotDevice::getDeviceType, DeviceConstant.DeviceType.GAS_MODEL.getValue())
			.eq(IotDevice::getTenantId, iotDevice.getTenantId()));
	}


	/**
	 * 设备分类统计
	 */
	@Override
	@GetMapping("/getIotDeviceStaticVo")
	public R<IotDeviceVO> getIotDeviceStaticVo(IotDevice iotDevice) {
		BladeUser bladeUser = SecureUtil.getUser();
		LambdaQueryWrapper<IotDevice> initWrapper1 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper2 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper3 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper4 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper5 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper6 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper7 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper8 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper9 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper10 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper11 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper12 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper13 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper14 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper15 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper16 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper17 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper18 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper19 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper20 = Condition.getQueryWrapper(iotDevice).lambda();

		LambdaQueryWrapper<IotDevice> initWrapper21 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper22 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper23 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper24 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper25 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper26 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper27 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper28 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper29 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper30 = Condition.getQueryWrapper(iotDevice).lambda();

		LambdaQueryWrapper<IotDevice> initWrapper31 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper32 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper33 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper34 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper35 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper36 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper37 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper38 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper39 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper40 = Condition.getQueryWrapper(iotDevice).lambda();

		LambdaQueryWrapper<IotDevice> initWrapper41 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper42 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper43 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper44 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper45 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper46 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper47 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper48 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper49 = Condition.getQueryWrapper(iotDevice).lambda();

		LambdaQueryWrapper<IotDevice> initWrapper50 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper51 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper52 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper53 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper54 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper55 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper56 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper57 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper58 = Condition.getQueryWrapper(iotDevice).lambda();
		LambdaQueryWrapper<IotDevice> initWrapper59 = Condition.getQueryWrapper(iotDevice).lambda();

		String deptId = bladeUser.getDeptId();
		String[] deptIds = deptId.split(",");

		for (int i = 0; i < deptIds.length; i++) {
			OrgPosition orgPosition = new OrgPosition();
			orgPosition.setOrgId(Long.valueOf(deptIds[i]));
			OrgPositionVO orgPositionVO = orgPositionClient.detail(orgPosition);
//			OrgPosition orgPosition = orgPositionClient.detail(new QueryWrapper<>(new OrgPosition()).lambda().eq(OrgPosition::getOrgId,deptIds[i]));
			if (i == 0) {
				initWrapper1.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper2.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper3.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper4.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper5.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper6.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper7.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper8.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper9.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper10.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());

				initWrapper11.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper12.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper13.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper14.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper15.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper16.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper17.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper18.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper19.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper20.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());

				initWrapper21.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper22.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper23.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper24.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper25.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper26.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper27.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper28.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper29.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper30.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());

				initWrapper31.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper32.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper33.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper34.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper35.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper36.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper37.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper38.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper39.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper40.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());

				initWrapper41.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper42.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper43.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper44.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper45.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper46.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper47.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper48.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper49.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());

				initWrapper50.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper51.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper52.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper53.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper54.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper55.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper56.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper57.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper58.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper59.like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
			} else {
				initWrapper1.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper2.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper3.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper4.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper5.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper6.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper7.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper8.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper9.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper10.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());

				initWrapper11.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper12.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper13.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper14.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper15.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper16.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper17.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper18.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper19.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper20.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());

				initWrapper21.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper22.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper23.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper24.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper25.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper26.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper27.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper28.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper29.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper30.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());

				initWrapper31.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper32.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper33.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper34.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper35.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper36.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper37.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper38.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper39.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper40.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper41.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper42.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper43.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper44.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper45.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper46.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper47.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper48.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper49.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());

				initWrapper50.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper51.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper52.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper53.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper54.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper55.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper56.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper57.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper58.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
				initWrapper59.or().like(IotDevice::getOrgPosition, orgPositionVO.getOrgPosition());
			}
		}

		IotDeviceVO IotDeviceVO = new IotDeviceVO();

		if (iotDevice != null) {
			//传入设备类型的统计
			if (iotDevice.getDeviceType() != null) {
//				Integer deviceCount = this.IotDeviceService.count(Condition.getQueryWrapper(IotDevice));
//				Integer normalCount = this.IotDeviceService.count(Condition.getQueryWrapper(IotDevice).lambda().eq(IotDevice::getDeviceStatus,1));
//				Integer outlineCount = this.IotDeviceService.count(Condition.getQueryWrapper(IotDevice).lambda().eq(IotDevice::getDeviceStatus, 3));
//				Integer alarmCount = this.IotDeviceService.count(Condition.getQueryWrapper(IotDevice).lambda().eq(IotDevice::getDeviceStatus, 2));
//				Integer pauseCount = this.IotDeviceService.count(Condition.getQueryWrapper(IotDevice).lambda().eq(IotDevice::getDeviceStatus, 4));
				Integer deviceCount = this.iotDeviceService.count(initWrapper1);
				Integer normalCount = this.iotDeviceService.count(initWrapper1.eq(IotDevice::getDeviceStatus, 1));
				Integer outlineCount = this.iotDeviceService.count(initWrapper2.eq(IotDevice::getDeviceStatus, 3));
				Integer alarmCount = this.iotDeviceService.count(initWrapper3.eq(IotDevice::getDeviceStatus, 2));
				Integer pauseCount = this.iotDeviceService.count(initWrapper4.eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setDeviceCount(deviceCount);
				IotDeviceVO.setNormalCount(normalCount);
				IotDeviceVO.setOutlineCount(outlineCount);
				IotDeviceVO.setAlarmCount(alarmCount);
				IotDeviceVO.setPauseCount(pauseCount);
			} else {
				//设备列表统计
				//设备总数
				Integer deviceCount = this.iotDeviceService.count(initWrapper1);
				IotDeviceVO.setDeviceCount(deviceCount);
				//正常数
//				Integer normalCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceStatus,1));
				Integer normalCount = this.iotDeviceService.count(initWrapper1.eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setNormalCount(normalCount);
				//失联数
//				Integer outlineCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceStatus, 3));
				Integer outlineCount = this.iotDeviceService.count(initWrapper2.eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setOutlineCount(outlineCount);
				//告警数
//				Integer alarmCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceStatus, 2));
				Integer alarmCount = this.iotDeviceService.count(initWrapper3.eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setAlarmCount(alarmCount);
				//停用数
//				Integer pauseCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceStatus, 4));
				Integer pauseCount = this.iotDeviceService.count(initWrapper4.eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setPauseCount(pauseCount);

				//烟感总数
//				Integer smokeCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1));
//				Integer smokeCount = this.iotDeviceService.count(initWrapper5.eq(IotDevice::getDeviceType, 1));
				Integer smokeCount = this.iotDeviceService.count(initWrapper5.eq(IotDevice::getDeviceType, "100004"));
				IotDeviceVO.setSmokeCount(smokeCount);
				//正常数
//				Integer smokeNormal = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1).eq(IotDevice::getDeviceStatus,1));
				Integer smokeNormal = this.iotDeviceService.count(initWrapper6.eq(IotDevice::getDeviceType, "100004").eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setSmokeNormal(smokeNormal);
				//失联数
//				Integer smokeOutline = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1).eq(IotDevice::getDeviceStatus, 3));
				Integer smokeOutline = this.iotDeviceService.count(initWrapper7.eq(IotDevice::getDeviceType, "100004").eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setSmokeOutline(smokeOutline);
				//告警数
//				Integer smokeAlarm = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1).eq(IotDevice::getDeviceStatus, 2));
				Integer smokeAlarm = this.iotDeviceService.count(initWrapper8.eq(IotDevice::getDeviceType, "100004").eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setSmokeAlarm(smokeAlarm);
				//停用数
//				Integer smokePause = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1).eq(IotDevice::getDeviceStatus, 4));
				Integer smokePause = this.iotDeviceService.count(initWrapper9.eq(IotDevice::getDeviceType, "100004").eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setSmokePause(smokePause);

				//烟感物模型总数
//				Integer smokeModelCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1));
//				Integer smokeModelCount = this.iotDeviceService.count(initWrapper5.eq(IotDevice::getDeviceType, 1));
				Integer smokeModelCount = this.iotDeviceService.count(initWrapper50.eq(IotDevice::getDeviceType, "10000002"));
				IotDeviceVO.setSmokeModelCount(smokeModelCount);
				//正常数
//				Integer smokeNormal = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1).eq(IotDevice::getDeviceStatus,1));
				Integer smokeModelNormal = this.iotDeviceService.count(initWrapper51.eq(IotDevice::getDeviceType, "10000002").eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setSmokeModelNormal(smokeModelNormal);
				//失联数
//				Integer smokeOutline = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1).eq(IotDevice::getDeviceStatus, 3));
				Integer smokeModelOutline = this.iotDeviceService.count(initWrapper52.eq(IotDevice::getDeviceType, "10000002").eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setSmokeModelOutline(smokeModelOutline);
				//告警数
//				Integer smokeAlarm = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1).eq(IotDevice::getDeviceStatus, 2));
				Integer smokeModelAlarm = this.iotDeviceService.count(initWrapper53.eq(IotDevice::getDeviceType, "10000002").eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setSmokeModelAlarm(smokeModelAlarm);
				//停用数
//				Integer smokePause = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 1).eq(IotDevice::getDeviceStatus, 4));
				Integer smokeModelPause = this.iotDeviceService.count(initWrapper54.eq(IotDevice::getDeviceType, "10000002").eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setSmokeModelPause(smokeModelPause);

				//燃气监控总数
//				Integer gasCount = iotDeviceService.getBaseMapper().selectCount(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2));
				//燃气监控
//				Integer gasCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2));
				Integer gasCount = this.iotDeviceService.count(initWrapper10.eq(IotDevice::getDeviceType, "100020"));
				IotDeviceVO.setGasCount(gasCount);
				//正常数
//				Integer gasNormal = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2).eq(IotDevice::getDeviceStatus,1));
				Integer gasNormal = this.iotDeviceService.count(initWrapper11.eq(IotDevice::getDeviceType, "100020").eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setGasNormal(gasNormal);
				//失联数
//				Integer gasOutline = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2).eq(IotDevice::getDeviceStatus, 3));
				Integer gasOutline = this.iotDeviceService.count(initWrapper12.eq(IotDevice::getDeviceType, "100020").eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setGasOutline(gasOutline);
				//告警数
//				Integer gasAlarm = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2).eq(IotDevice::getDeviceStatus, 2));
				Integer gasAlarm = this.iotDeviceService.count(initWrapper13.eq(IotDevice::getDeviceType, "100020").eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setGasAlarm(gasAlarm);
				//停用数
//				Integer gasPause = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2).eq(IotDevice::getDeviceStatus, 4));
				Integer gasPause = this.iotDeviceService.count(initWrapper14.eq(IotDevice::getDeviceType, "100020").eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setGasPause(gasPause);

				//燃气监控物模型总数
//				Integer gasCount = iotDeviceService.getBaseMapper().selectCount(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2));
				//燃气监控
//				Integer gasCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2));
				Integer gasModelCount = this.iotDeviceService.count(initWrapper55.eq(IotDevice::getDeviceType, "10000017"));
				IotDeviceVO.setGasModelCount(gasModelCount);
				//正常数
//				Integer gasNormal = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2).eq(IotDevice::getDeviceStatus,1));
				Integer gasModelNormal = this.iotDeviceService.count(initWrapper56.eq(IotDevice::getDeviceType, "10000017").eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setGasModelNormal(gasModelNormal);
				//失联数
//				Integer gasOutline = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2).eq(IotDevice::getDeviceStatus, 3));
				Integer gasModelOutline = this.iotDeviceService.count(initWrapper57.eq(IotDevice::getDeviceType, "10000017").eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setGasModelOutline(gasModelOutline);
				//告警数
//				Integer gasAlarm = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2).eq(IotDevice::getDeviceStatus, 2));
				Integer gasModelAlarm = this.iotDeviceService.count(initWrapper58.eq(IotDevice::getDeviceType, "10000017").eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setGasModelAlarm(gasModelAlarm);
				//停用数
//				Integer gasPause = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 2).eq(IotDevice::getDeviceStatus, 4));
				Integer gasModelPause = this.iotDeviceService.count(initWrapper59.eq(IotDevice::getDeviceType, "10000017").eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setGasModelPause(gasModelPause);

				//井盖监控总数
//		Integer coverCount = iotDeviceService.getBaseMapper().selectCount(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 3));
//				Integer coverCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 3));
				Integer coverCount = this.iotDeviceService.count(initWrapper15.eq(IotDevice::getDeviceType, 3));
				IotDeviceVO.setCoverCount(coverCount);
				//正常数
//				Integer coverNormal = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 3).eq(IotDevice::getDeviceStatus,1));
				Integer coverNormal = this.iotDeviceService.count(initWrapper16.eq(IotDevice::getDeviceType, 3).eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setCoverNormal(coverNormal);
				//失联数
//				Integer coverOutline = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 3).eq(IotDevice::getDeviceStatus, 3));
				Integer coverOutline = this.iotDeviceService.count(initWrapper17.eq(IotDevice::getDeviceType, 3).eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setCoverOutline(coverOutline);
				//告警数
//				Integer coverAlarm = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 3).eq(IotDevice::getDeviceStatus, 2));
				Integer coverAlarm = this.iotDeviceService.count(initWrapper18.eq(IotDevice::getDeviceType, 3).eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setCoverAlarm(coverAlarm);
				//停用数
//				Integer coverPause = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 3).eq(IotDevice::getDeviceStatus, 4));
				Integer coverPause = this.iotDeviceService.count(initWrapper19.eq(IotDevice::getDeviceType, 3).eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setCoverPause(coverPause);

				//一键告警总数
//		Integer alarmDeviceCount = iotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceType, 4));
//				Integer alarmDeviceCount = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 4));
				Integer alarmDeviceCount = this.iotDeviceService.count(initWrapper20.eq(IotDevice::getDeviceType, 4));
				IotDeviceVO.setAlarmDeviceCount(alarmDeviceCount);
				//正常数
//				Integer alarmDeviceNormal = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 4).eq(IotDevice::getDeviceStatus,1));
				Integer alarmDeviceNormal = this.iotDeviceService.count(initWrapper21.eq(IotDevice::getDeviceType, 4).eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setAlarmDeviceNormal(alarmDeviceNormal);
				//失联数
//				Integer alarmDeviceOutline = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 4).eq(IotDevice::getDeviceStatus, 3));
				Integer alarmDeviceOutline = this.iotDeviceService.count(initWrapper22.eq(IotDevice::getDeviceType, 4).eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setAlarmDeviceOutline(alarmDeviceOutline);
				//告警数
//				Integer alarmDeviceAlarm = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 4).eq(IotDevice::getDeviceStatus, 2));
				Integer alarmDeviceAlarm = this.iotDeviceService.count(initWrapper23.eq(IotDevice::getDeviceType, 4).eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setAlarmDeviceAlarm(alarmDeviceAlarm);
				//停用数
//				Integer alarmDevicePause = this.iotDeviceService.count(Condition.getQueryWrapper(new IotDevice()).lambda().eq(IotDevice::getDeviceType, 4).eq(IotDevice::getDeviceStatus, 4));
				Integer alarmDevicePause = this.iotDeviceService.count(initWrapper24.eq(IotDevice::getDeviceType, 4).eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setAlarmDevicePause(alarmDevicePause);

				//智慧路灯总数
//		Integer lampCount = iotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceType, 5));
				Integer lampCount = this.iotDeviceService.count(initWrapper25.eq(IotDevice::getDeviceType, 5));
				IotDeviceVO.setLampCount(lampCount);
				//正常数
				Integer lampNormal = this.iotDeviceService.count(initWrapper26.eq(IotDevice::getDeviceType, 5).eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setLampNormal(lampNormal);
				//失联数
				Integer lampOutline = this.iotDeviceService.count(initWrapper27.eq(IotDevice::getDeviceType, 5).eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setLampOutline(lampOutline);
				//告警数
				Integer lampAlarm = this.iotDeviceService.count(initWrapper28.eq(IotDevice::getDeviceType, 5).eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setLampAlarm(lampAlarm);
				//停用数
				Integer lampPause = this.iotDeviceService.count(initWrapper29.eq(IotDevice::getDeviceType, 5).eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setLampPause(lampPause);

				//智慧消防
//		Integer xfCount = iotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceType, 6));
				Integer xfCount = this.iotDeviceService.count(initWrapper30.eq(IotDevice::getDeviceType, 960417));
				IotDeviceVO.setXfCount(xfCount);
				//正常数
				Integer xfNormal = this.iotDeviceService.count(initWrapper31.eq(IotDevice::getDeviceType, 960417).eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setXfNormal(xfNormal);
				//失联数
				Integer xfOutline = this.iotDeviceService.count(initWrapper32.eq(IotDevice::getDeviceType, 960417).eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setXfOutline(xfOutline);
				//告警数
				Integer xfAlarm = this.iotDeviceService.count(initWrapper33.eq(IotDevice::getDeviceType, 960417).eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setXfAlarm(xfAlarm);
				//停用数
				Integer xfPause = this.iotDeviceService.count(initWrapper34.eq(IotDevice::getDeviceType, 960417).eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setXfPause(xfPause);

				//垃圾桶
//		Integer trashBinCount = iotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceType, 7));
				Integer trashBinCount = this.iotDeviceService.count(initWrapper35.eq(IotDevice::getDeviceType, 7));
				IotDeviceVO.setTrashbinCount(trashBinCount);
				//正常数
				Integer trashBinNormal = this.iotDeviceService.count(initWrapper36.eq(IotDevice::getDeviceType, 7).eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setTrashbinNormal(trashBinNormal);
				//失联数
				Integer trashBinOutline = this.iotDeviceService.count(initWrapper37.eq(IotDevice::getDeviceType, 7).eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setTrashbinOutline(trashBinOutline);
				//告警数
				Integer trashBinAlarm = this.iotDeviceService.count(initWrapper38.eq(IotDevice::getDeviceType, 7).eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setTrashbinAlarm(trashBinAlarm);
				//停用数
				Integer trashBinPause = this.iotDeviceService.count(initWrapper39.eq(IotDevice::getDeviceType, 7).eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setTrashbinPause(trashBinPause);

				//停车监控
//		Integer parkCount = iotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceType, 8));
				Integer parkCount = this.iotDeviceService.count(initWrapper40.eq(IotDevice::getDeviceType, 8));
				IotDeviceVO.setParkCount(parkCount);
				//正常数
				Integer parkNormal = this.iotDeviceService.count(initWrapper41.eq(IotDevice::getDeviceType, 8).eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setParkNormal(parkNormal);
				//失联数
				Integer parkOutline = this.iotDeviceService.count(initWrapper42.eq(IotDevice::getDeviceType, 8).eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setParkOutline(parkOutline);
				//告警数
				Integer parkAlarm = this.iotDeviceService.count(initWrapper43.eq(IotDevice::getDeviceType, 8).eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setParkAlarm(parkAlarm);
				//停用数
				Integer parkPause = this.iotDeviceService.count(initWrapper44.eq(IotDevice::getDeviceType, 8).eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setParkPause(parkPause);

				//门磁
//		Integer gateCount = iotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceType, 9));
				Integer gateCount = this.iotDeviceService.count(initWrapper45.eq(IotDevice::getDeviceType, 9));
				IotDeviceVO.setGateCount(gateCount);
				//正常数
				Integer gateNormal = this.iotDeviceService.count(initWrapper46.eq(IotDevice::getDeviceType, 9).eq(IotDevice::getDeviceStatus, 1));
				IotDeviceVO.setGateNormal(gateNormal);
				//失联数
				Integer gateOutline = this.iotDeviceService.count(initWrapper47.eq(IotDevice::getDeviceType, 9).eq(IotDevice::getDeviceStatus, 3));
				IotDeviceVO.setGateOutline(gateOutline);
				//告警数
				Integer gateAlarm = this.iotDeviceService.count(initWrapper48.eq(IotDevice::getDeviceType, 9).eq(IotDevice::getDeviceStatus, 2));
				IotDeviceVO.setGateAlarm(gateAlarm);
				//停用数
				Integer gatePause = this.iotDeviceService.count(initWrapper49.eq(IotDevice::getDeviceType, 9).eq(IotDevice::getDeviceStatus, 4));
				IotDeviceVO.setGatePause(gatePause);
			}
		}

		/*if (IotDevice.getDeviceType() != null) {
			normalCount = IotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(new IotDevice()).lambda().eq(IotDevice::getDeviceStatus, 1).eq(IotDevice::getDeviceType, IotDevice.getDeviceType()));
			outlineCount = IotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(new IotDevice()).lambda().eq(IotDevice::getDeviceStatus, 3).eq(IotDevice::getDeviceType, IotDevice.getDeviceType()));
			alarmCount = IotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(new IotDevice()).lambda().eq(IotDevice::getDeviceStatus, 2).eq(IotDevice::getDeviceType, IotDevice.getDeviceType()));
			pauseCount = IotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(new IotDevice()).lambda().eq(IotDevice::getDeviceStatus, 4).eq(IotDevice::getDeviceType, IotDevice.getDeviceType()));
		} else {
		}*/
//		normalCount = IotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceStatus, 1));
//		outlineCount = IotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceStatus, 3));
//		alarmCount = IotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceStatus, 2));
//		pauseCount = IotDeviceService.getBaseMapper().selectCount(new QueryWrapper<>(IotDevice).lambda().eq(IotDevice::getDeviceStatus, 4));


/*		IotDeviceVO.setPauseCount(pauseCount);
		IotDeviceVO.setAlarmCount(alarmCount);
		IotDeviceVO.setOutlineCount(outlineCount);
		IotDeviceVO.setNormalCount(normalCount);

		IotDeviceVO.setCoverCount(coverCount);
		IotDeviceVO.setAlarmDeviceCount(alarmDeviceCount);
		IotDeviceVO.setGasCount(gasCount);
		IotDeviceVO.setGateCount(gateCount);
		IotDeviceVO.setSmokeCount(smokeCount);
		IotDeviceVO.setLampCount(lampCount);
		IotDeviceVO.setXfCount(xfCount);
		IotDeviceVO.setTrashbinCount(trashBinCount);
		IotDeviceVO.setParkCount(parkCount);*/
		return R.data(IotDeviceVO);
	}

	/**
	 * 设备列表统计
	 */
	@GetMapping("/deviceListCount")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "设备列表统计")
	@Override
	public R<List<SingleDeviceStatistics>> deviceListCount(IotDevice iotDevice) {
		List<SingleDeviceStatistics> singleDeviceStatisticsList = new ArrayList<>();
		//获取当前请求用户
		BladeUser bladeUser = SecureUtil.getUser();
		List<DictBiz> deviceTypes = this.dictBizClient.getList("iot_device_type").getData();
		for (int i = 0; i < deviceTypes.size(); i++) {
			DictBiz item = deviceTypes.get(i);
			SingleDeviceStatistics singleDeviceStatistics = new SingleDeviceStatistics();
			//设备类型
			singleDeviceStatistics.setDeviceType(item.getDictKey());
			singleDeviceStatistics.setDeviceTypeName(item.getDictValue());
			//总数
			LambdaQueryWrapper<IotDevice> deviceLambdaQueryWrapper = this.getWrapper(iotDevice, bladeUser, item.getDictKey(), null);
			int deviceCount = this.iotDeviceService.count(deviceLambdaQueryWrapper);
			singleDeviceStatistics.setDeviceCount(deviceCount);
			//正常
			LambdaQueryWrapper<IotDevice> normalCountWrapper = this.getWrapper(iotDevice, bladeUser, item.getDictKey(), 1);
			int normalCount = this.iotDeviceService.count(normalCountWrapper);
			singleDeviceStatistics.setNormalCount(normalCount);
			//告警
			LambdaQueryWrapper<IotDevice> alarmCountWrapper = this.getWrapper(iotDevice, bladeUser, item.getDictKey(), 2);
			int alarmCount = this.iotDeviceService.count(alarmCountWrapper);
			singleDeviceStatistics.setAlertCount(alarmCount);
			//失联
			LambdaQueryWrapper<IotDevice> outlineCountWrapper = this.getWrapper(iotDevice, bladeUser, item.getDictKey(), 3);
			int outlineCount = this.iotDeviceService.count(outlineCountWrapper);
			singleDeviceStatistics.setOutlineCount(outlineCount);
			//停用
			LambdaQueryWrapper<IotDevice> pauseCountWrapper = this.getWrapper(iotDevice, bladeUser, item.getDictKey(), 4);
			int pauseCount = this.iotDeviceService.count(pauseCountWrapper);
			singleDeviceStatistics.setPauseCount(pauseCount);
			//待布防
			LambdaQueryWrapper<IotDevice> armedCountWrapper = this.getWrapper(iotDevice, bladeUser, item.getDictKey(), 5);
			int armedCount = this.iotDeviceService.count(armedCountWrapper);
			singleDeviceStatistics.setArmedCount(armedCount);
			singleDeviceStatisticsList.add(singleDeviceStatistics);
		}
		return R.data(singleDeviceStatisticsList);
	}

	public LambdaQueryWrapper<IotDevice> getWrapper(IotDevice iotDevice, BladeUser bladeUser, String deviceType, Integer deviceStatus) {
		LambdaQueryWrapper<IotDevice> iotDeviceLambdaQueryWrapper = new QueryWrapperUtil<IotDevice>().getBasicQueryWrapper(
			IotDevice::getOrgPosition, iotDevice, bladeUser, orgPositionClient);
		//设备类型过滤
		iotDeviceLambdaQueryWrapper.eq(IotDevice::getDeviceType, deviceType);
		//设备状态过滤
		iotDeviceLambdaQueryWrapper.eq(deviceStatus != null, IotDevice::getDeviceStatus, deviceStatus);
		return iotDeviceLambdaQueryWrapper;
	}

	/**
	 * 设备列表统计
	 */
//	@GetMapping("/deviceListCount")
//	@ApiOperationSupport(order = 9)
//	@ApiOperation(value = "设备列表统计")
//	public R<List<SingleDeviceStatistics>> deviceListCount(SmartDevice smartDevice,BladeUser bladeUser){
//		List<SingleDeviceStatistics> singleDeviceStatisticsList = new ArrayList<>();
//		List<DictBiz> deviceTypes = this.dictBizService.getList("device_type");
//		for (int i =0;i<deviceTypes.size();i++) {
//			DictBiz item =deviceTypes.get(i);
//			SingleDeviceStatistics singleDeviceStatistics = new SingleDeviceStatistics();
//			//设备类型
//			singleDeviceStatistics.setDeviceType(item.getDictKey());
//			singleDeviceStatistics.setDeviceTypeName(item.getDictValue());
//			//总数
//			LambdaQueryWrapper<SmartDevice> deviceLambdaQueryWrapper = this.getWrapper(smartDevice, bladeUser, item.getDictKey(), null);
//			int deviceCount = this.smartDeviceService.count(deviceLambdaQueryWrapper);
//			singleDeviceStatistics.setDeviceCount(deviceCount);
//			//正常
//			LambdaQueryWrapper<SmartDevice> normalCountWrapper = this.getWrapper(smartDevice, bladeUser, item.getDictKey(), 1);
//			int normalCount = this.smartDeviceService.count(normalCountWrapper);
//			singleDeviceStatistics.setNormalCount(normalCount);
//			//告警
//			LambdaQueryWrapper<SmartDevice> alarmCountWrapper = this.getWrapper(smartDevice, bladeUser, item.getDictKey(), 2);
//			int alarmCount = this.smartDeviceService.count(alarmCountWrapper);
//			singleDeviceStatistics.setAlertCount(alarmCount);
//			//失联
//			LambdaQueryWrapper<SmartDevice> outlineCountWrapper = this.getWrapper(smartDevice, bladeUser, item.getDictKey(), 3);
//			int outlineCount = this.smartDeviceService.count(outlineCountWrapper);
//			singleDeviceStatistics.setOutlineCount(outlineCount);
//			//停用
//			LambdaQueryWrapper<SmartDevice> pauseCountWrapper = this.getWrapper(smartDevice, bladeUser, item.getDictKey(), 4);
//			int pauseCount = this.smartDeviceService.count(pauseCountWrapper);
//			singleDeviceStatistics.setPauseCount(pauseCount);
//			//待布防
//			LambdaQueryWrapper<SmartDevice> armedCountWrapper = this.getWrapper(smartDevice, bladeUser, item.getDictKey(), 5);
//			int armedCount = this.smartDeviceService.count(armedCountWrapper);
//			singleDeviceStatistics.setArmedCount(armedCount);
//			singleDeviceStatisticsList.add(singleDeviceStatistics);
//		}
//		return R.data(singleDeviceStatisticsList);
//	}
//
//	public LambdaQueryWrapper<SmartDevice> getWrapper(SmartDevice smartDevice, BladeUser bladeUser,String deviceType, Integer deviceStatus){
//		LambdaQueryWrapper<SmartDevice> smartDeviceLambdaQueryWrapper = new QueryWrapperUtil<SmartDevice>().getBasicQueryWrapper(
//			SmartDevice::getOrgPosition,smartDevice,bladeUser,orgPositionService);
//		//设备类型过滤
//		smartDeviceLambdaQueryWrapper.eq(SmartDevice::getDeviceType,deviceType);
//		//设备状态过滤
//		smartDeviceLambdaQueryWrapper.eq(deviceStatus != null, SmartDevice::getDeviceStatus, deviceStatus);
//		return smartDeviceLambdaQueryWrapper;
//	}

	@Override
	@GetMapping("/getDeviceByDeviceIdOrImei")
	public IotDeviceVO getDeviceByDeviceIdOrImei(@RequestParam String deviceId) {
		IotDevice iotDevice = iotDeviceService.lambdaQuery().eq(IotDevice::getDeviceType, deviceId).or().eq(IotDevice::getImei, deviceId).one();
		IotDeviceVO iotDeviceVO = new IotDeviceVO();
		BeanUtil.copy(iotDevice, iotDeviceVO);
		return iotDeviceVO;
	}
}
