package cn.cecep.talroad.util;

import cn.cecep.talroad.domain.BasDevice;
import cn.cecep.talroad.domain.BasDeviceParam;
import cn.cecep.talroad.domain.BasParam;
import cn.cecep.talroad.enums.EnIndustry;
import cn.cecep.talroad.vo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * dcs系统拿过来的
 */
public class VoToStringBak
{
	private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");


	/** 转换数据-实时-钢铁
	 * @param forDataView true=数据查询，false=折线图
	 */
	public static List<MonDevGtStringVO> voToStringReal_GT(List<MonDevGtRealVO> lstIn, String deviceType, boolean forDataView)
			throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.GT;
		Class<MonDevGtRealVO> monOriVO = MonDevGtRealVO.class;
		Class<MonDevGtStringVO> monStringVO = MonDevGtStringVO.class;
		List<MonDevGtStringVO> result;
		MonDevGtStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id(), deviceType);
		for (MonDevGtRealVO record : lstIn)
		{
			stringVO = new MonDevGtStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);
			stringVO.setDataTime(record.getDataTime().format(formatter));

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-其它-钢铁 */
	public static List<MonDevGtStringVO> voToStringOther_GT(List<MonDevGtVO> lstIn, String deviceType, boolean forDataView)
					throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.GT;
		Class<MonDevGtVO> monOriVO = MonDevGtVO.class;
		Class<MonDevGtStringVO> monStringVO = MonDevGtStringVO.class;
		List<MonDevGtStringVO> result;
		MonDevGtStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id(), deviceType);
		for (MonDevGtVO record : lstIn)
		{
			stringVO = new MonDevGtStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);
			//stringVO.setDataTime(record.getDataTime().format(formatter));

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-实时-焦化 */
	public static List<MonDevJhStringVO> voToStringReal_JH(List<MonDevJhRealVo> lstIn, String deviceType, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
			//不同方法需更改的部分
		EnIndustry industry = EnIndustry.JH;
		Class<MonDevJhRealVo> monOriVO = MonDevJhRealVo.class;
		Class<MonDevJhStringVO> monStringVO = MonDevJhStringVO.class;
		List<MonDevJhStringVO> result;
		MonDevJhStringVO stringVO;
			//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id(), deviceType);
		for (MonDevJhRealVo record : lstIn)
		{
			stringVO = new MonDevJhStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-其它-焦化 */
	public static List<MonDevJhStringVO> voToStringOther_JH(List<MonDevJhVO> lstIn, String deviceType, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.JH;
		Class<MonDevJhVO> monOriVO = MonDevJhVO.class;
		Class<MonDevJhStringVO> monStringVO = MonDevJhStringVO.class;
		List<MonDevJhStringVO> result;
		MonDevJhStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id());
		for (MonDevJhVO record : lstIn)
		{
			stringVO = new MonDevJhStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);
			//stringVO.setDataTime(record.getDataTime().format(formatter));

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
			String shareDevId = basDevicePO.getShareDevId();
			String shareType = basDevicePO.getShareType();
			//当前设备为共用从设备
			if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
			{
				String[] types = shareType.split(",");
				for (String facilityType : types)
				{
					facilityType = facilityType.trim();
					if (StringUtils.isEmpty(facilityType))
						continue;
					//共用参数列表
					lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
					for (BasParam paramPo : lstParamPoType)
					{
						paramCode = paramPo.getParamCodeSvc();
						getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
						setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
						value =  monStringVO.getMethod(getMethodName).invoke(stringVO);
						if(value == null)   //共用值为空则设置标记
						{
							setMethod = monStringVO.getMethod(setMethodName, String.class);
							setMethod.invoke(stringVO, "(共用)");
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-实时-水泥 */
	public static List<MonDevSnStringVO> voToStringReal_SN(List<MonDevSnRealVo> lstIn, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.SN;
		Class<MonDevSnRealVo> monOriVO = MonDevSnRealVo.class;
		Class<MonDevSnStringVO> monStringVO = MonDevSnStringVO.class;
		List<MonDevSnStringVO> result;
		MonDevSnStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id());
		for (MonDevSnRealVo record : lstIn)
		{
			stringVO = new MonDevSnStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-其它-水泥 */
	public static List<MonDevSnStringVO> voToStringOther_SN(List<MonDevSnVO> lstIn, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.SN;
		Class<MonDevSnVO> monOriVO = MonDevSnVO.class;
		Class<MonDevSnStringVO> monStringVO = MonDevSnStringVO.class;
		List<MonDevSnStringVO> result;
		MonDevSnStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id());
		for (MonDevSnVO record : lstIn)
		{
			stringVO = new MonDevSnStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);
			//stringVO.setDataTime(record.getDataTime().format(formatter));

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-实时-玻璃 */
	public static List<MonDevBlStringVO> voToStringReal_BL(List<MonDevBlRealVo> lstIn, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.BL;
		Class<MonDevBlRealVo> monOriVO = MonDevBlRealVo.class;
		Class<MonDevBlStringVO> monStringVO = MonDevBlStringVO.class;
		List<MonDevBlStringVO> result;
		MonDevBlStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id());
		for (MonDevBlRealVo record : lstIn)
		{
			stringVO = new MonDevBlStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
			String shareDevId = basDevicePO.getShareDevId();
			String shareType = basDevicePO.getShareType();
			//当前设备为共用从设备
			if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
			{
				String[] types = shareType.split(",");
				for (String facilityType : types)
				{
					facilityType = facilityType.trim();
					if (StringUtils.isEmpty(facilityType))
						continue;
					//共用参数列表
					lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
					for (BasParam paramPo : lstParamPoType)
					{
						paramCode = paramPo.getParamCodeSvc();
						getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
						setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
						value =  monStringVO.getMethod(getMethodName).invoke(stringVO);
						if(value == null)   //共用值为空则设置标记
						{
							setMethod = monStringVO.getMethod(setMethodName, String.class);
							setMethod.invoke(stringVO, "(共用)");
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-其它-玻璃 */
	public static List<MonDevBlStringVO> voToStringOther_BL(List<MonDevBlVO> lstIn, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.BL;
		Class<MonDevBlVO> monOriVO = MonDevBlVO.class;
		Class<MonDevBlStringVO> monStringVO = MonDevBlStringVO.class;
		List<MonDevBlStringVO> result;
		MonDevBlStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id());
		for (MonDevBlVO record : lstIn)
		{
			stringVO = new MonDevBlStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);
			//stringVO.setDataTime(record.getDataTime().format(formatter));

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-实时-电力 */
	public static List<MonDevDlStringVO> voToStringReal_DL(List<MonDevDlRealVo> lstIn, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.DL;
		Class<MonDevDlRealVo> monOriVO = MonDevDlRealVo.class;
		Class<MonDevDlStringVO> monStringVO = MonDevDlStringVO.class;
		List<MonDevDlStringVO> result;
		MonDevDlStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id());
		for (MonDevDlRealVo record : lstIn)
		{
			stringVO = new MonDevDlStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-其它-电力 */
	public static List<MonDevDlStringVO> voToStringOther_DL(List<MonDevDlVO> lstIn, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.DL;
		Class<MonDevDlVO> monOriVO = MonDevDlVO.class;
		Class<MonDevDlStringVO> monStringVO = MonDevDlStringVO.class;
		List<MonDevDlStringVO> result;
		MonDevDlStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id());
		for (MonDevDlVO record : lstIn)
		{
			stringVO = new MonDevDlStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);
			//stringVO.setDataTime(record.getDataTime().format(formatter));

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-实时-垃圾焚烧 */
	public static List<MonDevFsStringVO> voToStringReal_FS(List<MonDevFsRealVo> lstIn, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.FS;
		Class<MonDevFsRealVo> monOriVO = MonDevFsRealVo.class;
		Class<MonDevFsStringVO> monStringVO = MonDevFsStringVO.class;
		List<MonDevFsStringVO> result;
		MonDevFsStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id());
		for (MonDevFsRealVo record : lstIn)
		{
			stringVO = new MonDevFsStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	/** 转换数据-其它-垃圾焚烧 */
	public static List<MonDevFsStringVO> voToStringOther_FS(List<MonDevFsVO> lstIn, boolean forDataView) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException
	{
		//不同方法需更改的部分
		EnIndustry industry = EnIndustry.FS;
		Class<MonDevFsVO> monOriVO = MonDevFsVO.class;
		Class<MonDevFsStringVO> monStringVO = MonDevFsStringVO.class;
		List<MonDevFsStringVO> result;
		MonDevFsStringVO stringVO;
		//所有方法都一样的部分
		List<BasParam> lstParamPo, lstParamPoType;
		Method setMethod;
		String getMethodName, setMethodName;
		String paramCode;
		Object value;

		result = new ArrayList<>();
		lstParamPo = AppBuffer.bufBasParam.getListByIndustry(industry.id());
		for (MonDevFsVO record : lstIn)
		{
			stringVO = new MonDevFsStringVO();

			//==== 将一般参数复制到新类
			BeanUtils.copyProperties(record, stringVO);
			//stringVO.setDataTime(record.getDataTime().format(formatter));

			//==== 将监测参数由Double转为String复制到新类（反射），并处理小数点位数
			for (BasParam paramPo : lstParamPo)
			{
				paramCode = paramPo.getParamCodeSvc();
				getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
				setMethod = monStringVO.getMethod(setMethodName, String.class);
				value = monOriVO.getMethod(getMethodName).invoke(record);
				if(value == null)	//无值：若属性为离线则设置值为"-"
				{
					BasDeviceParam devParamPo;
					devParamPo = AppBuffer.bufBasDeviceParam.getOneById(record.getDeviceId(), paramPo.getParamId());
					if(devParamPo!=null && devParamPo.getIsOnline().intValue()==0)
						setMethod.invoke(stringVO, "-");
				}
				else if(value instanceof Double)
					setMethod.invoke(stringVO, BigDecimal.valueOf((Double) value).setScale(paramPo.getScale(), RoundingMode.HALF_EVEN).toPlainString());
			}

			//==== 判断是否是共用
			if( forDataView )
			{
				BasDevice basDevicePO = AppBuffer.bufBasDevice.getObjById(record.getDeviceId());
				String shareDevId = basDevicePO.getShareDevId();
				String shareType = basDevicePO.getShareType();
				//当前设备为共用从设备
				if (StringUtils.isNotBlank(shareDevId) && StringUtils.isNotBlank(shareType))
				{
					String[] types = shareType.split(",");
					for (String facilityType : types)
					{
						facilityType = facilityType.trim();
						if (StringUtils.isEmpty(facilityType))
							continue;
						//共用参数列表
						lstParamPoType = AppBuffer.bufBasParam.getListByIndustry(industry.id(), basDevicePO.getType(), facilityType);
						for (BasParam paramPo : lstParamPoType)
						{
							paramCode = paramPo.getParamCodeSvc();
							getMethodName = "get" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							setMethodName = "set" + paramCode.substring(0, 1).toUpperCase().concat(paramCode.substring(1));
							value = monStringVO.getMethod(getMethodName).invoke(stringVO);
							if (value == null)   //共用值为空则设置标记
							{
								setMethod = monStringVO.getMethod(setMethodName, String.class);
								setMethod.invoke(stringVO, "(共用)");
							}
						}
					}
				}
			}
			result.add(stringVO);
		}
		return result;
	}

	public static ThreadLocal<List<BasParam>> paramThreadLocal = new ThreadLocal<>();
	public static ThreadLocal<List<BasDevice>> deviceThreadLocal = new ThreadLocal<>();
	public static ThreadLocal<List<BasDeviceParam>> deviceParamThreadLocal = new ThreadLocal<>();

	public static class AppBuffer {
		public static BufBasParam bufBasParam = new BufBasParam();
		public static BufBasDevice bufBasDevice = new BufBasDevice();
		public static BufBasDeviceParam bufBasDeviceParam = new BufBasDeviceParam();
	}

	public static class BufBasParam {
		public List<BasParam> getListByIndustry(String industryId) {
			return paramThreadLocal.get().stream()
					.filter(o -> industryId.equals(o.getIndustry()))
					.collect(Collectors.toList());
		}

		public List<BasParam> getListByIndustry(String industryId, String type, String facilityType) {
			return paramThreadLocal.get().stream()
					.filter(o -> industryId.equals(o.getIndustry()) && type.equals(o.getDeviceType()) && facilityType.equals(o.getFacilityType()))
					.collect(Collectors.toList());
		}

		public List<BasParam> getListByIndustry(String industryId, String deviceType) {
			return paramThreadLocal.get().stream()
					.filter(o -> industryId.equals(o.getIndustry()) && deviceType.equals(o.getDeviceType()))
					.collect(Collectors.toList());
		}
	}

	public static class BufBasDevice {
		public BasDevice getObjById(String deviceId) {
			return deviceThreadLocal.get().stream()
					.filter(o -> o.getDeviceId().equals(deviceId))
					.findFirst().orElse(null);
		}
	}

	public static class BufBasDeviceParam {
		public BasDeviceParam getOneById(String deviceId, String paramId) {
			return deviceParamThreadLocal.get().stream()
					.filter(o -> deviceId.equals(o.getDeviceId()) && paramId.equals(o.getParamId()))
					.findFirst().orElse(null);
		}
	}

}
