@ResponseBody @RequestMapping(value = "chooseJobs", method = RequestMethod.POST, produces = MediaTypes.JSON) public Map<String, Object> chooseJobs(@RequestParam("id") Integer id) { /** * 根节点下不会直接挂载作业,其他节点下可以挂载子节点和作业 * * <p>如果传入的id是0,代表根节点,此时获取根节点下所有子节点 当点击一个子节点后,判断此节点是否为智能节点,如果是智能节点,则查找smart_group_query表 * 如果是非智能节点,则获取此节点下的子节点和作业 GROUP_TYPE_ID=9 代表智能节点; GROUP_TYPE_ID=4代表非智能节点 */ List<GroupBean> groupBeanList = new ArrayList<GroupBean>(); if (id == 0) { List<GroupBean> firstLevelJobGroupList = groupService.findFirstLevelJobGroup(); groupBeanList.addAll(firstLevelJobGroupList); } else { List<GroupBean> childJobGroup = groupService.findChildJobGroup(id); groupBeanList.addAll(childJobGroup); BLGroup groupNode = groupService.findByGroupId(id); if (groupNode.getGROUP_TYPE_ID() == 4) { List<GroupBean> staticJobList = groupService.findStaticJob(groupNode); groupBeanList.addAll(staticJobList); } else { List<GroupBean> smartJobList = groupService.findSmartJob(groupNode); groupBeanList.addAll(smartJobList); } } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put("data", groupBeanList); return resultMap; }
@ResponseBody @RequestMapping( value = "chooseDeviceBYBBSA", method = RequestMethod.POST, produces = MediaTypes.JSON) public Map<String, Object> chooseDeviceBYBBSA( @RequestParam("id") Integer id, HttpServletRequest request) throws SQLException { List<GroupBean> groupBeanList = new ArrayList<GroupBean>(); if (id == 0) { List<GroupBean> firstLevelDeviceList = groupService.findFirstLevelDeviceGroup(); groupBeanList.addAll(firstLevelDeviceList); } else { List<GroupBean> childDeviceGroup = groupService.findDeviceGroupWithId(id); groupBeanList.addAll(childDeviceGroup); BLGroup groupNode = groupService.findByGroupId(id); if (groupNode.getGROUP_TYPE_ID() == 1) { List<GroupBean> staticDeviceList = groupService.findStaticDeviceNode(id); groupBeanList.addAll(staticDeviceList); } else { List<GroupBean> smartDeviceList = groupService.findSmartDeviceNode(id); groupBeanList.addAll(smartDeviceList); } } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put("data", groupBeanList); // resultMap.put("data",deviceFilter.deviceFilterRole(groupBeanList,UserNameUtil.getUserNameByRequest(request)) ); return resultMap; }
@RequestMapping("/events/{eventName}/fields") public List<String> getAllFields(@PathVariable("eventName") String eventName) { List<String> fields = new ArrayList<>(); fields.addAll(FIXED_FIELDS); fields.addAll(ticketFieldRepository.findFieldsForEvent(eventName)); return fields; }
@RequestMapping(value = "/products", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public String getProducts() throws JsonProcessingException { List<Product> products = new ArrayList<>(); products.addAll(asList(new Product("Super Glue"), new Product("Kool-Aide"))); Optional<Product> externalProduct = Optional.empty(); try { String externalProductString = restTemplate.getForObject("http://localhost:6789/external-product", String.class); externalProduct = Optional.of(new Product(externalProductString)); } catch (RestClientException e) { // server is down - ignore } externalProduct.ifPresent(products::add); return jsonMapper.writeValueAsString(products); }
@RequestMapping("/events/{eventName}/sponsor-scan/export.csv") public void downloadSponsorScanExport( @PathVariable("eventName") String eventName, HttpServletResponse response, Principal principal) throws IOException { Event event = loadEvent(eventName, principal); List<TicketFieldConfiguration> fields = ticketFieldRepository.findAdditionalFieldsForEvent(event.getId()); response.setContentType("text/csv;charset=UTF-8"); response.setHeader( "Content-Disposition", "attachment; filename=" + eventName + "-sponsor-scan.csv"); try (ServletOutputStream out = response.getOutputStream(); CSVWriter writer = new CSVWriter(new OutputStreamWriter(out))) { for (int marker : BOM_MARKERS) { out.write(marker); } List<String> header = new ArrayList<>(); header.add("Username"); header.add("Timestamp"); header.add("Full name"); header.add("Email"); header.addAll( fields.stream().map(TicketFieldConfiguration::getName).collect(Collectors.toList())); writer.writeNext(header.toArray(new String[header.size()])); userManager .findAllUsers(principal.getName()) .stream() .map(u -> Pair.of(u, userManager.getUserRole(u))) .filter(p -> p.getRight() == Role.SPONSOR) .flatMap( p -> sponsorScanRepository .loadSponsorData( event.getId(), p.getKey().getId(), SponsorScanRepository.DEFAULT_TIMESTAMP) .stream() .map( v -> Pair.of( v, ticketFieldRepository.findAllValuesForTicketId( v.getTicket().getId())))) .map( p -> { DetailedScanData data = p.getLeft(); Map<String, String> descriptions = p.getRight(); return Pair.of( data, fields .stream() .map(x -> descriptions.getOrDefault(x.getName(), "")) .collect(Collectors.toList())); }) .map( p -> { List<String> line = new ArrayList<>(); Ticket ticket = p.getLeft().getTicket(); SponsorScan sponsorScan = p.getLeft().getSponsorScan(); line.add(userManager.findUser(sponsorScan.getUserId()).getUsername()); line.add(sponsorScan.getTimestamp().toString()); line.add(ticket.getFullName()); line.add(ticket.getEmail()); line.addAll(p.getRight()); return line.toArray(new String[line.size()]); }) .forEachOrdered(writer::writeNext); writer.flush(); out.flush(); } }