package org.springblade.openinterface.dianxin.DataIntegration.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springblade.community.building.entity.Building;
import org.springblade.community.building.service.IBuildingService;
import org.springblade.community.car.entity.Car;
import org.springblade.community.car.service.ICarService;
import org.springblade.community.elevator.elevator.entity.Elevator;
import org.springblade.community.elevator.elevator.service.IElevatorService;
import org.springblade.community.houseuser.entity.Houseuser;
import org.springblade.community.houseuser.service.IHouseuserService;
import org.springblade.community.parkingveh.entity.ParkingVeh;
import org.springblade.community.parkingveh.service.IParkingVehService;
import org.springblade.community.residential.entity.Residential;
import org.springblade.community.residential.service.IResidentialService;
import org.springblade.community.room.entity.Room;
import org.springblade.community.room.service.IRoomService;
import org.springblade.community.staff.entity.EnterpriseStaff;
import org.springblade.community.staff.service.IEnterpriseStaffService;
import org.springblade.community.unit.entity.Unit;
import org.springblade.community.unit.service.IUnitService;
import org.springblade.core.tool.api.R;
import org.springblade.jiyueplatform.entity.JiyueDeviceOrder;
import org.springblade.openinterface.dianxin.DataIntegration.service.IBaseDataPushService;
import org.springblade.openinterface.dianxin.constants.JiYueConf;
import org.springblade.openinterface.dianxin.util.MyHttpUtil;
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.sysarea.entity.SysArea;
import org.springblade.sysarea.service.ISysAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

/**
 * @author lidexi
 * @date 2021/7/15 16:18
 */
@Service
public class BaseDataPushServiceImpl implements IBaseDataPushService {
	@Autowired
	private ISysAreaService sysAreaService;
	@Autowired
	private IResidentialService residentialService;
	@Autowired
	private IBuildingService buildingService;
	@Autowired
	private IUnitService unitService;
	@Autowired
	private IRoomService roomService;

	@Autowired
	private IHouseuserService houseuserService;


	@Autowired
	private IEnterpriseStaffService enterpriseStaffService;

	@Autowired
	private ICarService carService;

	@Autowired
	private IFaceDeviceService faceDeviceService;

	@Autowired
	private IElevatorService elevatorService;

	@Autowired
	private IVideoCloudDeviceService videoCloudDeviceService;

	@Autowired
	private ISmartDeviceService smartDeviceService;

	@Autowired
	private IParkingVehService parkingVehService;

	private final static String DEVICEMAP = "deviceMap";
	private final static String DEVICESTATUSMAP = "deviceStatusMap";


	@Override
	public R pushResidential(Residential residential) {
		Map<String, Object> map = this.residentialToMap(residential);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.RESIDENTIAL_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		if(result1 != null){
			Object communityId = result1.get("communityId");
			if(communityId != null){
				residential.setInhabitantId(communityId.toString());
				residentialService.updateById(residential);
			}

		}

		return R.data(result);
	}

	@Override
	public R pushArea(Residential residential) {
		Map<String, Object> map = this.areaToMap(residential);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.AREA_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		if(result1 != null){
			Object areaId = result1.get("areaId");
			if(areaId != null){
				residential.setAreaInhabitantId(areaId.toString());
				residentialService.updateById(residential);
			}
		}


		return R.data(result);
	}

	@Override
	public R pushBuilding(Building building) {
		Map<String, Object> map = this.buildingToMap(building);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.BUILDING_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object buildId = null;
		if (result1 != null) {
			buildId = result1.get("buildId");
			if (buildId != null){
				building.setInhabitantId(buildId.toString());
				buildingService.updateById(building);
			}

		}

		return R.data(result);
	}

	@Override
	public R pushUnit(Unit unit) {
		Map<String, Object> map = this.unitToMap(unit);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.UNIT_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object unitId = null;
		if (result1 != null) {
			unitId = result1.get("unitId");
			if(unitId != null){
				unit.setInhabitantId(unitId != null ? unitId.toString() : "");
				unitService.updateById(unit);
			}
		}

		return R.data(result);
	}

	@Override
	public R pushRoom(Room room) {
		Map<String, Object> map = this.roomToMap(room);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.ROOM_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object houseId = null;
		if (result1 != null) {
			houseId = result1.get("houseId");
			if(houseId != null){
				room.setInhabitantId(houseId != null ? houseId.toString() : "");
				roomService.updateById(room);
			}
		}

		return R.data(result);
	}

	@Override
	public R pushHouseuser(Houseuser houseuser) {
		Map<String, Object> map = this.userToMap(houseuser);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.HOUSEUSER_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object inhabitantId = null;
		if (result1 != null) {
			inhabitantId = result1.get("inhabitantId");
			if(inhabitantId != null){
				houseuser.setInhabitantId(inhabitantId != null ? inhabitantId.toString() : "");
				houseuserService.updateById(houseuser);
			}
		}

		return R.data(result);
	}

	@Override
	public R pushHouseuserAndRoom(Houseuser houseuser) {
		Map<String, Object> map = this.userAndHouseToMap(houseuser);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.HOUSEUSERANDROOM_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object id = null;
		if (result1 != null) {
			id = result1.get("id");
			if(id != null){
				houseuser.setUserRoomInhabitantId(id != null ? id.toString() : "");
				houseuserService.updateById(houseuser);
			}
		}

		return R.data(result);
	}

	@Override
	public R pushStaff(EnterpriseStaff enterpriseStaff) {

		if (!"".equals(enterpriseStaff.getIdcard())) {
			Map<String, Object> map = this.staffToMap(enterpriseStaff);
			ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.ENTERPRISESTAFF_PUSH);
			Map body = (Map) result.getBody();
			Map result1 = (Map) body.get("result");
			Object staffId = null;
			if (result1 != null) {
				staffId = result1.get("staffId");
				enterpriseStaff.setInhabitantId(staffId != null ? staffId.toString() : "");
				enterpriseStaffService.updateById(enterpriseStaff);
			} else {

			}

		}


		return R.data("success");
	}

	@Override
	public R pushCar(Car car) {
		Map<String, Object> map = this.carToMap(car);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.CAR_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object id = null;
		if (result1 != null) {
			id = result1.get("carId");
			if (id != null) {
				car.setInhabitantId(id.toString());
				carService.updateById(car);
			}

		}

		return R.data(result);
	}


	@Override
	public R pushFaceDevice(FaceDevice faceDevice) {
		Map deviceMap = this.faceDeviceToMap(faceDevice);
		ResponseEntity result = MyHttpUtil.post(deviceMap, JiYueConf.UrlConstant.DEVICE_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object id = null;
		if (result1 != null) {
			id = result1.get("deviceId");
			if (id != null) {
				faceDevice.setInhabitantId(id.toString());
				faceDeviceService.updateById(faceDevice);
				Map deviceStatusMap = this.faceDeviceStatusToMap(faceDevice);
				MyHttpUtil.post(deviceStatusMap, JiYueConf.UrlConstant.DEVICE_STATUS_PUSH);
			}

		}


		return null;
	}

	@Override
	public R pushVideoCloudDevice(VideoCloudDevice videoCloudDevice) {
		Map map = this.videoCloudDeviceToMap(videoCloudDevice);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.DEVICE_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object id = null;
		if (result1 != null) {
			id = result1.get("deviceId");
			if (id != null) {
				videoCloudDevice.setInhabitantId(id.toString());
				videoCloudDeviceService.updateById(videoCloudDevice);
				Map deviceStatusMap = this.videoCloudStatusToMap(videoCloudDevice);
				MyHttpUtil.post(deviceStatusMap, JiYueConf.UrlConstant.DEVICE_STATUS_PUSH);
			}

		}
		return null;
	}

	private Map videoCloudStatusToMap(VideoCloudDevice videoCloudDevice) {
		Map<String, Object> map = new HashMap<>();
		if (videoCloudDevice.getResidentialId() != null) {
			Residential residential = residentialService.getById(videoCloudDevice.getResidentialId());
			if (residential != null) {
				map.put("id", videoCloudDevice.getInhabitantId());
				map.put("deviceStatus", videoCloudDevice.getIsOnline() == 1 ? 1 : 0);//设备状态包括：1 在线；0 离线
				map.put("communityId", residential.getInhabitantId());
			}
		}


		return map;
	}

	private Map<String, Object> videoCloudDeviceToMap(VideoCloudDevice videoCloudDevice) {
		Map<String, Object> deviceMap = new HashMap<>();

		if (videoCloudDevice.getResidentialId() != null) {
			Residential residential = residentialService.getById(videoCloudDevice.getResidentialId());
			if (residential != null) {
				deviceMap.put("type", JiYueConf.deviceRelationMap.get(VideoCloudDevice.class.getName()));
				deviceMap.put("deviceName", videoCloudDevice.getDeviceName());
				deviceMap.put("firm", "视频云设备");
				deviceMap.put("typeId", videoCloudDevice.getDeviceType());
				deviceMap.put("communityId", residential.getInhabitantId());
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				deviceMap.put("createTime", sdf.format(videoCloudDevice.getCreateTime()!=null?videoCloudDevice.getCreateTime():new Date()));
				deviceMap.put("localId", videoCloudDevice.getId().toString());


			}
		}

		return deviceMap;
	}

	@Override
	public R pushIotDevice(SmartDevice smartDevice) {
		Map map = this.smartDeviceToMap(smartDevice);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.DEVICE_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object id = null;
		if (result1 != null) {
			id = result1.get("deviceId");
			if (id != null) {
				smartDevice.setInhabitantId(id.toString());
				smartDeviceService.updateById(smartDevice);
				Map deviceStatusMap = this.iotStatusToMap(smartDevice);
				MyHttpUtil.post(deviceStatusMap, JiYueConf.UrlConstant.DEVICE_STATUS_PUSH);
			}

		}
		return null;
	}

	private Map iotStatusToMap(SmartDevice smartDevice) {
		Map<String, Object> map = new HashMap<>();
		if (smartDevice.getResidentialId() != null) {
			Residential residential = residentialService.getById(smartDevice.getResidentialId());
			if (residential != null) {
				map.put("id", smartDevice.getInhabitantId());
				map.put("deviceStatus", smartDevice.getDeviceStatus()!=null&&smartDevice.getDeviceStatus() == 1 ? 1 : 0);//设备状态包括：1 在线；0 离线
				map.put("communityId", residential.getInhabitantId());
			}
		}


		return map;
	}

	private Map smartDeviceToMap(SmartDevice smartDevice) {
		Map<String, Object> map = new HashMap<>();

		if (smartDevice.getResidentialId() != null) {
			Residential residential = residentialService.getById(smartDevice.getResidentialId());
			if (residential != null) {
				map.put("type", JiYueConf.deviceRelationMap.get(smartDevice.getDeviceType()));
				map.put("deviceName", smartDevice.getDeviceName());
				map.put("firm", smartDevice.getManufacturers() == null ? "未知" : smartDevice.getDeviceName());
				map.put("typeId", smartDevice.getProductId() == null || smartDevice.getProductId().equals("")? "未知" : smartDevice.getProductId());
				map.put("communityId", residential.getInhabitantId());
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				map.put("createTime", sdf.format(smartDevice.getCreateTime()!=null?smartDevice.getCreateTime():new Date()));
				map.put("localId", smartDevice.getId().toString());
			}
		}


		return map;
	}

	@Override
	public R pushElevator(Elevator elevator) {
		Map map = this.elevatorToMap(elevator);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.DEVICE_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object id = null;
		if (result1 != null) {
			id = result1.get("deviceId");
			if (id != null) {
				elevator.setInhabitantId(id.toString());
				elevatorService.updateById(elevator);
				Map deviceStatusMap = this.elevatorStatusToMap(elevator);
				MyHttpUtil.post(deviceStatusMap, JiYueConf.UrlConstant.DEVICE_STATUS_PUSH);
			}

		}
		return null;
	}

	@Override
	public R pushParkingVeh(ParkingVeh parkingVeh) {
		Map map = this.parkingVehToMap(parkingVeh);
		ResponseEntity result = MyHttpUtil.post(map, JiYueConf.UrlConstant.DEVICE_PUSH);
		Map body = (Map) result.getBody();
		Map result1 = (Map) body.get("result");
		Object id = null;
		if (result1 != null) {
			id = result1.get("deviceId");
			if (id != null) {
				parkingVeh.setInhabitantId(id.toString());
				parkingVehService.updateById(parkingVeh);
				Map deviceStatusMap = this.parkingVehStatusToMap(parkingVeh);
				MyHttpUtil.post(deviceStatusMap, JiYueConf.UrlConstant.DEVICE_STATUS_PUSH);
			}

		}
		return null;
	}

	private Map parkingVehStatusToMap(ParkingVeh parkingVeh) {
		Map<String, Object> map = new HashMap<>();
		if (parkingVeh.getResidentialId() != null) {
			Residential residential = residentialService.getById(parkingVeh.getResidentialId());
			if (residential != null) {
				map.put("id", parkingVeh.getInhabitantId());
				map.put("deviceStatus", 1);//设备状态包括：1 在线；0 离线
				map.put("communityId", residential.getInhabitantId());
			}
		}


		return map;
	}

	private Map parkingVehToMap(ParkingVeh parkingVeh) {
		Map<String, Object> map = new HashMap<>();

		if (parkingVeh.getResidentialId() != null) {
			Residential residential = residentialService.getById(parkingVeh.getResidentialId());
			if (residential != null) {
				map.put("type", JiYueConf.deviceRelationMap.get(ParkingVeh.class.getName()));
				map.put("deviceName", parkingVeh.getVehName());
				map.put("firm", "安快");
				map.put("typeId", parkingVeh.getParkKey());
				map.put("communityId", residential.getInhabitantId());
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				map.put("createTime", sdf.format(new Date()));
				map.put("localId", parkingVeh.getId().toString());
			}
		}


		return map;
	}

	private Map elevatorStatusToMap(Elevator elevator) {
		Map<String, Object> map = new HashMap<>();
		if (elevator.getResidentialId() != null) {
			Residential residential = residentialService.getById(elevator.getResidentialId());
			if (residential != null) {
				map.put("id", elevator.getInhabitantId());
				map.put("deviceStatus", "1".equals(elevator.getOnlineStatus()) ? 1 : 0);//设备状态包括：1 在线；0 离线
				map.put("communityId", residential.getInhabitantId());
			}
		}


		return map;
	}

	private Map elevatorToMap(Elevator elevator) {
		Map<String, Object> map = new HashMap<>();

		if (elevator.getResidentialId() != null) {
			Residential residential = residentialService.getById(elevator.getResidentialId());
			if (residential != null) {
				map.put("type", JiYueConf.deviceRelationMap.get(Elevator.class.getName()));
				map.put("deviceName", elevator.getLiftName());
				map.put("firm", "新再灵");
				map.put("typeId", elevator.getElevatorNo());
				map.put("communityId", residential.getInhabitantId());
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				map.put("createTime", sdf.format(elevator.getCreateTime()!=null?elevator.getCreateTime():new Date()));
				map.put("localId", elevator.getId().toString());
			}
		}


		return map;
	}

	private Map faceDeviceStatusToMap(FaceDevice faceDevice) {
		Map<String, Object> map = new HashMap<>();
		if (faceDevice.getResidentialId() != null) {
			Residential residential = residentialService.getById(faceDevice.getResidentialId());
			if (residential != null) {
				map.put("id", faceDevice.getInhabitantId());
				map.put("deviceStatus", faceDevice.getDeviceStatus() == 1 ? 1 : 0);//设备状态包括：1 在线；0 离线
				map.put("communityId", residential.getInhabitantId());
			}
		}


		return map;
	}

	private Map faceDeviceToMap(FaceDevice faceDevice) {
		Map<String, Object> map = new HashMap<>();

		if (faceDevice.getResidentialId() != null) {
			Residential residential = residentialService.getById(faceDevice.getResidentialId());
			if (residential != null) {
				map.put("type", JiYueConf.deviceRelationMap.get(FaceDevice.class.getName()));
				map.put("deviceName", faceDevice.getCameraName());
				map.put("firm", faceDevice.getDeviceFactory() != null ? faceDevice.getDeviceFactory() : "未知");
				map.put("typeId", faceDevice.getCameraCode());
				map.put("communityId", residential.getInhabitantId());
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				map.put("createTime", sdf.format(faceDevice.getCreateTime()));
				map.put("localId", faceDevice.getId().toString());
			}
		}


		return map;
	}


	/**
	 * 小区对象转数据融通map
	 *
	 * @param residential
	 * @return
	 */
	private Map<String, Object> residentialToMap(Residential residential) {
		Map<String, Object> map = new HashMap<>();

		map.put("communityId", residential.getId());
		map.put("communityName", residential.getName());
		map.put("location", residential.getAddress() == null ? "" : residential.getAddress());
		map.put("type", 0);
		map.put("tatitude", residential.getLatitude() == null ? "" : residential.getLatitude());
		map.put("longitude", residential.getLongitude() == null ? "" : residential.getLongitude());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("createTime", sdf.format(residential.getCreateTime()));

		//省市区中文
		SysArea province = sysAreaService.getDetailByCode(Long.valueOf(residential.getRegionProvince()));
		SysArea city = sysAreaService.getDetailByCode(Long.valueOf(residential.getRegionCity()));
		SysArea area = sysAreaService.getDetailByCode(Long.valueOf(residential.getRegionArea()));
		map.put("province", province != null ? province.getSName() : "");
		map.put("city", city != null ? city.getSName() : "");
		map.put("district", area != null ? area.getSName() : "");
		map.put("localId", residential.getId().toString());

		return map;
	}

	/**
	 * 区域对象转数据融通map
	 *
	 * @param residential
	 * @return
	 */
	private Map<String, Object> areaToMap(Residential residential) {
		Map<String, Object> map = new HashMap<>();

		map.put("areaName", residential.getName() + "区域");
		map.put("communityId", residential.getInhabitantId());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("gmtCreate", sdf.format(residential.getCreateTime()));
		map.put("localId", residential.getId().toString());
		return map;
	}

	/**
	 * 楼栋对象转数据融通map
	 *
	 * @param building
	 * @return
	 */
	private Map<String, Object> buildingToMap(Building building) {
		Map<String, Object> map = new HashMap<>();

		map.put("name", building.getName());
		Residential residential = residentialService.getById(building.getResidentialId());
		map.put("communityId", residential != null ? residential.getInhabitantId() : "");
		map.put("areaId", residential != null ? residential.getAreaInhabitantId() : "");
		map.put("buildingType", 0);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("gmtCreate", sdf.format(building.getCreateTime()));
		map.put("localId", building.getId().toString());
		return map;
	}

	/**
	 * 单元对象转数据融通map
	 *
	 * @param unit
	 * @return
	 */
	private Map<String, Object> unitToMap(Unit unit) {
		Map<String, Object> map = new HashMap<>();

		map.put("name", unit.getName());

		//小区区域
		Residential residential = residentialService.getById(unit.getResidentialId());
		map.put("communityId", residential != null ? residential.getInhabitantId() : "");
		map.put("areaId", residential != null ? residential.getAreaInhabitantId() : "");
		//楼栋
		Building building = buildingService.getById(unit.getBuildingId());
		map.put("buildId", building != null ? building.getInhabitantId() : "");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("createTime", sdf.format(unit.getCreateTime()));
		map.put("localId", unit.getId().toString());
		return map;
	}

	/**
	 * 房屋对象转数据融通map
	 *
	 * @param room
	 * @return
	 */
	private Map<String, Object> roomToMap(Room room) {
		Map<String, Object> map = new HashMap<>();
		try {
			map.put("floor", Integer.valueOf(room.getFloorName().replaceAll("层", "")));

		} catch (Exception e) {
			e.printStackTrace();
			map.put("floor", 1);
		}

		map.put("houseNo", room.getName());

		//小区区域
		Residential residential = residentialService.getById(room.getResidentialId());
		map.put("communityId", residential != null ? residential.getInhabitantId() : "");
		map.put("areaId", residential != null ? residential.getAreaInhabitantId() : "");
		//楼栋
		Building building = buildingService.getById(room.getBuildingId());
		map.put("buildId", building != null ? building.getInhabitantId() : "");

		//单元
		Unit unit = unitService.getById(room.getUnitId());
		map.put("unitId", unit != null ? unit.getInhabitantId() : "");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("gmtCreate", sdf.format(room.getCreateTime()));
		map.put("localId", room.getId().toString());
		return map;
	}

	/**
	 * 用户对象转数据融通map
	 *
	 * @param houseuser
	 * @return
	 */
	private Map<String, Object> userToMap(Houseuser houseuser) {
		Map<String, Object> map = new HashMap<>();

		map.put("name", houseuser.getName());
		//小区区域
		Residential residential = residentialService.getById(houseuser.getResidentialId());
		map.put("communityId", residential != null ? residential.getInhabitantId() : "");

		//type:0家庭成员 1业主 2租户 3其他
		int type = 3;
		if (houseuser.getType() == null) {

		} else if (houseuser.getType() == 1) {
			type = 1;
		} else if (houseuser.getType() == 2) {
			type = 0;
		} else if (houseuser.getType() == 3) {
			type = 2;
		}
		map.put("type", type);

		//性别 0女 1男
		int sex = 0;
		if (houseuser.getSex() != null && houseuser.getSex() == 2) {
			sex = 0;
		} else if (houseuser.getSex() != null && houseuser.getSex() == 1) {
			sex = 1;
		}

		map.put("sex", sex);
		map.put("idcardType", "身份证");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("gmtCreate", sdf.format(houseuser.getCreateTime()));
		map.put("idcardNo", houseuser.getIdCard());
		map.put("localId", houseuser.getId().toString());
		map.put("imgs", houseuser.getImageUri());
		return map;
	}

	/**
	 * 用户房屋关系对象转数据融通map
	 *
	 * @param houseuser
	 * @return
	 */
	private Map<String, Object> userAndHouseToMap(Houseuser houseuser) {
		Map<String, Object> map = new HashMap<>();

		map.put("inhabitantId", houseuser.getInhabitantId());
		map.put("name", houseuser.getName());
		//小区区域
		Residential residential = residentialService.getById(houseuser.getResidentialId());
		map.put("communityId", residential != null ? residential.getInhabitantId() : "");
		map.put("areaId", residential != null ? residential.getAreaInhabitantId() : "");
		//楼栋
		Building building = buildingService.getById(houseuser.getBuildingId());
		map.put("buildId", building != null ? building.getInhabitantId() : "");

		//单元
		Unit unit = unitService.getById(houseuser.getUnitId());
		map.put("unitId", unit != null ? unit.getInhabitantId() : "");

		//房间
		Room room = roomService.getById(houseuser.getRoomId());
		map.put("houseId", room != null ? room.getInhabitantId() : "");
		map.put("personHouse", "其他");

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("gmtCreate", sdf.format(houseuser.getCreateTime()));
		map.put("localId", houseuser.getId().toString());
		return map;
	}

	/**
	 * 员工对象转数据融通map
	 *
	 * @param enterpriseStaff
	 * @return
	 */
	private Map<String, Object> staffToMap(EnterpriseStaff enterpriseStaff) {
		Map<String, Object> map = new HashMap<>();
		map.put("name", enterpriseStaff.getName());
		//小区区域
		Residential residential = residentialService.getById(enterpriseStaff.getResidentialId());
		map.put("communityId", residential != null ? residential.getInhabitantId() : "");
		map.put("tel", enterpriseStaff.getPhone());
		map.put("status", 0);
		map.put("sex", enterpriseStaff.getSex() != null && enterpriseStaff.getSex() == 1 ? 1 : 0);
		map.put("idcardType", "身份证");
		map.put("idcardNo", enterpriseStaff.getIdcard());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("gmtCreate", sdf.format(enterpriseStaff.getCreateTime()));
		map.put("localId", enterpriseStaff.getId().toString());
		return map;
	}

	/**
	 * 机动车对象转数据融通map
	 *
	 * @param car
	 * @return
	 */
	private Map<String, Object> carToMap(Car car) {
		Map<String, Object> map = new HashMap<>();

		map.put("plateNum", car.getNumber());

		Residential residential = residentialService.getById(car.getResidentialId());
		if(residential != null){
			map.put("communityId", residential.getInhabitantId().toString());
			map.put("CommunityName", residential != null ? residential.getName() : "");
		}

		Houseuser houseuser = houseuserService.getById(car.getPersonId());
		if(houseuser != null){
			map.put("inhabitantId", houseuser != null ? houseuser.getInhabitantId() : "");
			map.put("carBelonger", houseuser != null ? houseuser.getName() : "");
			map.put("carTel", houseuser != null ? houseuser.getTel() : "");
		}

		map.put("img", car.getCarImg());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("gmtCreate", sdf.format(car.getCreateTime()));
		map.put("localId", car.getId());
		return map;
	}


}
