| | |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | */ |
| | | @Override |
| | | public Map<String, Object> home(HomeQuery monitorQuery) { |
| | | |
| | | System.out.println(monitorQuery + "~~~~~~~~~~~~~打印"); |
| | | Map<String, Object> dataMap = new HashMap<>(); |
| | | Map<String, Object> monthMap1 = new HashMap<>(); |
| | | Map<String, Object> monthMap2 = new HashMap<>(); |
| | | List<Map<String, Object>> home = baseMapper.home(monitorQuery); |
| | | if (ObjectUtils.isNotEmpty(home)) { |
| | | //拿到数据库 循环查询 |
| | | System.out.println(home + "~~~~~~~~~~~~~打印"); |
| | | for (Map<String, Object> map : home) { |
| | | //得到map的 months键的值 num1键的值 组装为新对象 |
| | | monthMap1.put(map.get("months").toString(), map.get("num1")); |
| | | //得到map的 months键的值 num2键的值 组装为新对象 |
| | | monthMap2.put(map.get("months").toString(), map.get("num2")); |
| | | } |
| | | //home 的下标0的 map的 name键的值 |
| | | dataMap.put("name", home.get(0).get("name")); |
| | | dataMap.put("state", monthMap1); |
| | | dataMap.put("state2", monthMap2); |
| | |
| | | )) |
| | | .append("loseCount", new Document("$sum", |
| | | new Document("$cond", Arrays.asList( |
| | | new Document("$eq", Arrays.asList("$recordStatus", 0)), |
| | | 1, |
| | | 0 |
| | | )) |
| | | )) |
| | | .append("errCount", new Document("$sum", |
| | | new Document("$cond", Arrays.asList( |
| | | new Document("$eq", Arrays.asList("$recordStatus", -1)), |
| | | 1, |
| | | 0 |
| | |
| | | homeVideoVO.setCreateDate(doc.getDate("_id")); |
| | | homeVideoVO.setIntegrityNum(doc.getInteger("normalCount")); |
| | | homeVideoVO.setLoseNum(doc.getInteger("loseCount")); |
| | | homeVideoVO.setErrNum(doc.getInteger("errCount")); |
| | | results.add(homeVideoVO); |
| | | } |
| | | |
| | |
| | | private void setLoseDaily(VideoDailyExp videoDailyExp, List<RecordMetaDSumResult> recordResults) throws NoSuchFieldException, IllegalAccessException { |
| | | //一个设备当月在线情况 |
| | | for (RecordMetaDSumResult recordResult : recordResults) { |
| | | int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime()); |
| | | int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime()); //获取启动日期是当月第几天 |
| | | //反射赋值,字段统一定义为day+1,2,3... |
| | | Field field = videoDailyExp.getClass().getDeclaredField("day" + dayOfMonth); |
| | | field.setAccessible(true); |
| | | //防止转换为科学计数法 |
| | | BigDecimal bigDecimal = BigDecimal.valueOf(recordResult.getMissDuration() == null ? 0 : recordResult.getMissDuration()); |
| | | field.set(videoDailyExp, bigDecimal.toString()); |
| | | BigDecimal bigDecimal = BigDecimal.valueOf(recordResult.getMissDuration() == null ? 0 : (recordResult.getMissDuration()) * 60); |
| | | field.set(videoDailyExp, bigDecimal.setScale(2, RoundingMode.HALF_UP).toString()); |
| | | } |
| | | } |
| | | } |