package com.dky.tool; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import com.dky.modelI.DntdModelI; import com.dky.security.GetCpuInfo; import com.dky.utils.ConfigReader; import com.dky.utils.entity.SysDeviceHeatScene; import com.dky.utils.enums.Code; import com.dky.utils.result.ResponseUtil; import java.lang.reflect.InvocationTargetException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; public class ModelTool { public static List specList = new ArrayList<>(); // 制热锅炉,单功率单价,单位。建缓冲区。List实体。 public ModelTool(JSONObject list) { JSONArray specArray = list.getJSONArray("devSpecList"); for (int i = 0; i < specArray.size(); i++) { SysDeviceHeatScene devSpec = specArray.getJSONObject(i).toBean(SysDeviceHeatScene.class); specList.add(devSpec); } } public static JSONObject exeModel2Report(JSONObject jsonObject, String key) { JSONObject jsonObjectResult = new JSONObject(); try { // 根据给定的类名初始化类 加密不需要反实例化new Class sm4UtilsClass = Class.forName("com.dky.security.SM4Utils"); // 实例化这个类 Object obj = sm4UtilsClass.newInstance(); // 调用指定方法 Map map = (Map) sm4UtilsClass.getMethod("decrypt", String.class).invoke(obj, key); String cpuIds = (String) map.get("cpuIds"); String expireTime = (String) map.get("expireTime"); // 定义日期时间格式 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = formatter.parse(expireTime); //拿到解析后的cpuid。获取本地的cpuid. String localCpuId = GetCpuInfo.getCpuId(); if (cpuIds.contains(localCpuId)){ if (new Date().before(date)){ // 判断模型使用权限 // 根据给定的类名初始化类 加密不需要反实例化new Class modelI = Class.forName("com.dky"+"."+ ConfigReader.getProperty(jsonObject.getStr("type"))); // 实例化这个类 DntdModelI modelI1 = (DntdModelI)modelI.newInstance(); // 调用指定方法 jsonObjectResult = modelI1.createReport(jsonObject); }else { jsonObjectResult = ResponseUtil.createResponse(Code.KEY_EXPIRATION.getCode(), Code.KEY_EXPIRATION.getDesc(), null); } }else { jsonObjectResult = ResponseUtil.createResponse(Code.KEY_UNAUTHORIZED.getCode(), Code.KEY_UNAUTHORIZED.getDesc(), null); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { jsonObjectResult = ResponseUtil.createResponse(Code.KEY_CONTEXT_ERROR.getCode(), Code.KEY_CONTEXT_ERROR.getDesc(), null); e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (Exception e) { throw new RuntimeException(e); } return jsonObjectResult; } }