| | |
| | | /** |
| | | * 自定义分页 |
| | | */ |
| | | @GetMapping("/pages") |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "分页", notes = "传入equipment") |
| | | public R<IPage<EquipmentVO>> pages(EquipmentVO equipment, Query query, String pid, HttpServletResponse response) throws ParseException { |
| | | response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); |
| | | response.setHeader("Access-Control-Allow-Credentials", "true"); |
| | | |
| | | List<Map<String, Object>> treedatas = catalogService.selectCatalogEqNUmber(pid); |
| | | //根据传入的id递归出该节点下所有的设备 |
| | | List<Map<String, Object>> childList = treeIdList(treedatas, pid); |
| | | |
| | | |
| | | System.out.println(childList); |
| | | |
| | | |
| | | |
| | | |
| | | return R.data(null); |
| | | } |
| | | |
| | | /** |
| | | * 自定义分页 |
| | | */ |
| | | @GetMapping("/page") |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "分页", notes = "传入equipment") |
| | |
| | | childMenu = new ArrayList(); |
| | | |
| | | //根据查询条件得到所有设备 |
| | | IPage<EquipmentVO> pages = equipmentService.selectEquipmentPage(Condition.getPage(query), equipment); |
| | | IPage<EquipmentVO> pageData = equipmentService.selectEquipmentPage(Condition.getPage(query), equipment); |
| | | |
| | | //IPage<EquipmentVO> datas = new IPage<EquipmentVO> |
| | | List<EquipmentVO> pages = pageData.getRecords(); |
| | | List<EquipmentVO> datas = new ArrayList(); |
| | | |
| | | // if (pid == null || pid.equals("")) { |
| | | // for (int j = 0; j < pages.size(); j++) { |
| | | // String expireTime = pages.get(j).getExpireTime(); |
| | | // //1.获取当前时间 |
| | | // Date dd = new Date(); |
| | | // SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // String end = sim.format(dd); |
| | | // //把string类型转换为long类型的 |
| | | // long st = sim.parse(expireTime).getTime(); |
| | | // long en = sim.parse(end).getTime(); |
| | | // //计算天数 |
| | | // int day = (int) ((st - en) / 86400000); |
| | | // if (day <= 30) { |
| | | // pages.get(j).setType(1); |
| | | // } else { |
| | | // pages.get(j).setType(0); |
| | | // } |
| | | // } |
| | | // datas = pages; |
| | | // } else { |
| | | // List<Map<String, Object>> treedatas = catalogService.selectCatalogEqNUmber(pid); |
| | | // //根据传入的id递归出该节点下所有的设备 |
| | | // List<Map<String, Object>> childList = treeMenuList(treedatas, Integer.parseInt(pid)); |
| | | // //将得到的设备与查询所得设备进行匹配 |
| | | // for (int i = 0; i < childList.size(); i++) { |
| | | // for (int j = 0; j < pages.size(); j++) { |
| | | // String expireTime = pages.get(j).getExpireTime(); |
| | | // //1.获取当前时间 |
| | | // Date dd = new Date(); |
| | | // SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // String end = sim.format(dd); |
| | | // //把string类型转换为long类型的 |
| | | // long st = sim.parse(expireTime).getTime(); |
| | | // long en = sim.parse(end).getTime(); |
| | | // //计算天数 |
| | | // int day = (int) ((st - en) / 86400000); |
| | | // if (day <= 30) { |
| | | // pages.get(j).setType(1); |
| | | // } else { |
| | | // pages.get(j).setType(0); |
| | | // } |
| | | // |
| | | // if (childList.get(i).get("eqid") != null) { |
| | | // if (childList.get(i).get("eqid").equals(pages.get(j).getDeviceNumber())) { |
| | | // datas.add(pages.get(j)); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | return R.data(pages); |
| | | |
| | | |
| | | if (pid == null || pid.equals("")) { |
| | | for (int j = 0; j < pages.size(); j++) { |
| | | String expireTime = pages.get(j).getExpireTime(); |
| | | //1.获取当前时间 |
| | | Date dd = new Date(); |
| | | SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String end = sim.format(dd); |
| | | //把string类型转换为long类型的 |
| | | long st = sim.parse(expireTime).getTime(); |
| | | long en = sim.parse(end).getTime(); |
| | | //计算天数 |
| | | int day = (int) ((st - en) / 86400000); |
| | | if (day <= 30) { |
| | | pages.get(j).setType(1); |
| | | } else { |
| | | pages.get(j).setType(0); |
| | | } |
| | | } |
| | | datas = pages; |
| | | } else { |
| | | List<Map<String, Object>> treedatas = catalogService.selectCatalogEqNUmber(pid); |
| | | //根据传入的id递归出该节点下所有的设备 |
| | | List<Map<String, Object>> childList = treeMenuList(treedatas, pid); |
| | | //将得到的设备与查询所得设备进行匹配 |
| | | for (int i = 0; i < childList.size(); i++) { |
| | | for (int j = 0; j < pages.size(); j++) { |
| | | String expireTime = pages.get(j).getExpireTime(); |
| | | //1.获取当前时间 |
| | | Date dd = new Date(); |
| | | SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String end = sim.format(dd); |
| | | //把string类型转换为long类型的 |
| | | long st = sim.parse(expireTime).getTime(); |
| | | long en = sim.parse(end).getTime(); |
| | | //计算天数 |
| | | int day = (int) ((st - en) / 86400000); |
| | | if (day <= 30) { |
| | | pages.get(j).setType(1); |
| | | } else { |
| | | pages.get(j).setType(0); |
| | | } |
| | | |
| | | if (childList.get(i).get("eqid") != null) { |
| | | if (childList.get(i).get("eqid").equals(pages.get(j).getDeviceNumber())) { |
| | | datas.add(pages.get(j)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | pageData.setRecords(datas); |
| | | pageData.setTotal(datas.size()); |
| | | return R.data(pageData); |
| | | } |
| | | |
| | | //子节点 |
| | | private static List childMenu = new ArrayList(); |
| | | |
| | | public static List treeMenuList(List<Map<String, Object>> menuList, int pid) { |
| | | public static List treeMenuList(List<Map<String, Object>> menuList, String pid) { |
| | | for (int i = 0; i < menuList.size(); i++) { |
| | | //遍历出父id等于参数的id,add进子节点集合 |
| | | |
| | | if (pid != 0) { |
| | | if (menuList.get(i).get("pId").equals(pid)) { |
| | | if (!pid.equals(0)) { |
| | | if (menuList.get(i).get("pId").toString().equals(pid) ) { |
| | | //递归遍历下一级 |
| | | treeMenuList(menuList, Integer.valueOf((Integer) menuList.get(i).get("id"))); |
| | | treeMenuList(menuList, menuList.get(i).get("id").toString()); |
| | | childMenu.add(menuList.get(i)); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return childMenu; |
| | | } |
| | | |
| | | public static List treeIdList(List<Map<String, Object>> menuList, String pid) { |
| | | for (int i = 0; i < menuList.size(); i++) { |
| | | //遍历出父id等于参数的id,add进子节点集合 |
| | | |
| | | if (!pid.equals(0)) { |
| | | if (menuList.get(i).get("pId").toString().equals(pid) ) { |
| | | //递归遍历下一级 |
| | | treeIdList(menuList, menuList.get(i).get("id").toString()); |
| | | if (menuList.get(i).get("eqid") != null || menuList.get(i).get("eqid") != "") { |
| | | childMenu.add(menuList.get(i).get("eqid")); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | return childMenu; |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | @ApiOperationSupport(order = 6) |
| | | @ApiOperation(value = "新增或修改", notes = "传入equipment") |
| | | public R submit(@Valid @RequestBody Equipment equipment) { |
| | | if (equipment.getStime() != null && equipment.getStime().equals("")){ |
| | | equipment.setStime(null); |
| | | } |
| | | |
| | | if (equipment.getExpireTime() != null && equipment.getExpireTime().equals("")){ |
| | | equipment.setExpireTime(null); |
| | | } |
| | | |
| | | if (equipment.getHeartbeat() != null && equipment.getHeartbeat().equals("")){ |
| | | equipment.setHeartbeat(null); |
| | | } |
| | | |
| | | return R.status(equipmentService.saveOrUpdate(equipment)); |
| | | } |
| | | |