MWTools.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.xcgl.middleware;
  2. import java.text.ParsePosition;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import org.jeecgframework.core.common.service.CommonService;
  7. import org.jeecgframework.core.util.ApplicationContextUtil;
  8. import org.jeecgframework.web.system.service.SystemService;
  9. import org.joda.time.DateTime;
  10. import com.xcgl.sensorrecord.entity.SensorRecordEntity;
  11. import cn.com.lzt.common.util.StringUtil;
  12. public class MWTools {
  13. private static java.util.List<SensorRecordEntity> lsRecords ;
  14. private static SystemService systemService;
  15. private MWTools() {}
  16. /**
  17. * 制作一套空数据传感器记录数组,每次采集数据均为一套
  18. *
  19. * */
  20. public static java.util.List<SensorRecordEntity> getInitRecords(CommonService service) {
  21. if(lsRecords != null && !lsRecords.isEmpty())
  22. return lsRecords;
  23. String querySql = " select point.typeid, type.type_name as typename, type.type_code as typecode, point.id as pointid, \r\n" +
  24. "point.name as pointname, point.code as pointcode, device.id as deviceid, device.name as devicename,point.room as roomname, \r\n" +
  25. "type_unit as typeunit,point.upper as upper, point.floor as floor, now() as recordtime, \r\n" +
  26. "device.department as departmentname,point.projectid as projectid\r\n" +
  27. "from p_sensor_monitor_point point \r\n" +
  28. "left join p_sensor_type type on point.typeid = type.id\r\n" +
  29. "left join p_device device on point.deviceid = device.id ";
  30. java.util.List<Object[]> qrRet = service.findListbySql(querySql);
  31. lsRecords = new ArrayList<SensorRecordEntity>();
  32. if(!qrRet.isEmpty()){
  33. for (int i = 0; i < qrRet.size(); i++) {
  34. lsRecords.add(buildEntity(qrRet.get(i)));
  35. }
  36. }
  37. return lsRecords;
  38. }
  39. private static SensorRecordEntity buildEntity(Object[] re)
  40. {
  41. SensorRecordEntity record = new SensorRecordEntity();
  42. record.setTypeid(re[0].toString());
  43. record.setTypename(re[1].toString());
  44. record.setTypecode(re[2].toString());
  45. record.setPointid(re[3].toString());
  46. record.setPointname(re[4].toString());
  47. record.setPointcode(re[5].toString());
  48. record.setDeviceid(re[6].toString());
  49. record.setDevicename(re[7].toString());
  50. record.setRoomname(re[8].toString());
  51. record.setTypeunit(re[9].toString());
  52. record.setUpper(re[10]==null||re[10].toString().length()==0 ? null: Double.valueOf(re[10].toString()));
  53. record.setFloor(re[11]==null||re[11].toString().length()==0 ? null: Double.valueOf(re[11].toString()));
  54. //record.setRecordtime( new Date());
  55. record.setDepartmentname(re[13].toString());
  56. record.setProjectid(re[14].toString());
  57. return record;
  58. }
  59. /**
  60. * 获取现在时间
  61. *
  62. * @return返回长时间格式 yyyy-MM-dd HH:mm:ss
  63. */
  64. public static Date getNowDate() {
  65. Date currentTime = new Date();
  66. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  67. String dateString = formatter.format(currentTime);
  68. ParsePosition pos = new ParsePosition(8);
  69. Date currentTime_2 = formatter.parse(dateString, pos);
  70. return currentTime_2;
  71. }
  72. }