@RequestMapping("/export") public ResponseEntity<byte[]> download() throws IOException { String fileName = String.format("菜品列表%s.xlsx", new SimpleDateFormat("yyyyMMdd").format(new Date())); ExcelFactory.exportProducts( fileName, productService.getAll(), productService.getTypeMap(), productService.getProcurement()); File file = new File(fileName); HttpHeaders headers = new HttpHeaders(); String cnfileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1"); headers.setContentDispositionFormData("attachment", cnfileName); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return new ResponseEntity<>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED); }
@RequestMapping(value = "/type_map", method = RequestMethod.GET) public @ResponseBody JSONArray getTypeMap() { JSONArray jsonArray = new JSONArray(); Map<Type, List<Category>> typeMap = productService.getTypeMap(); for (Type key : typeMap.keySet()) { List<Category> categoryList = typeMap.get(key); JSONArray categoryJsonArray = new JSONArray(); for (Category category : categoryList) { JSONObject jsonObject = new JSONObject(); jsonObject.put("key", category.getCategory()); jsonObject.put("value", category.toString()); categoryJsonArray.add(jsonObject); } JSONObject jsonObject = new JSONObject(); jsonObject.put("name", key.getType()); jsonObject.put("value", key.toString()); jsonObject.put("list", categoryJsonArray); jsonArray.add(jsonObject); } return jsonArray; }