Commit 8e0b807d55a8611c2717a8fb2ce0e0a9b5dc4a52
1 parent
e4677acde0
Exists in
master
and in
6 other branches
分娩记录导出
Showing 3 changed files with 111 additions and 0 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java
View file @
8e0b807
... | ... | @@ -234,6 +234,57 @@ |
234 | 234 | |
235 | 235 | } |
236 | 236 | |
237 | + public static void writeWhExclFile(String filePath,OutputStream out,List<Map<String,Object>> values) { | |
238 | + File file = new File(filePath); | |
239 | + InputStream in = null; | |
240 | + Workbook wb = null; | |
241 | + try { | |
242 | + in = new FileInputStream(file); | |
243 | + wb = Workbook.getWorkbook(in); | |
244 | + | |
245 | + WritableWorkbook book = wb.createWorkbook(out,wb); | |
246 | + WritableSheet ws = book.getSheet(0); | |
247 | + | |
248 | + WritableFont contentFont = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); | |
249 | + WritableCellFormat contentFormt = new WritableCellFormat(contentFont); | |
250 | + contentFormt.setAlignment(jxl.format.Alignment.CENTRE); | |
251 | + contentFormt.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); | |
252 | + contentFormt.setVerticalAlignment(VerticalAlignment.CENTRE); | |
253 | + | |
254 | + int arrayIndex = 0; | |
255 | + for (int i = 2, len = values.size()+2; i < len; i++, arrayIndex++) | |
256 | + { | |
257 | + | |
258 | + Set<String> sets = values.get(arrayIndex).keySet(); | |
259 | + int j = 0; | |
260 | + for (String key : sets) | |
261 | + { | |
262 | + String value = values.get(arrayIndex).get(key)+""; | |
263 | + if (StringUtils.isNotEmpty(value) && StringUtils.isNum(value)) | |
264 | + { | |
265 | + WritableCellFormat wcfN = new WritableCellFormat(contentFont); | |
266 | + wcfN.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); | |
267 | + wcfN.setAlignment(jxl.format.Alignment.CENTRE); | |
268 | + wcfN.setVerticalAlignment(VerticalAlignment.CENTRE); | |
269 | + Number labelNF = new Number(j, i,Integer.parseInt(value), wcfN); | |
270 | + ws.addCell(labelNF); | |
271 | + } | |
272 | + else | |
273 | + { | |
274 | + ws.addCell(new Label(j, i,value, contentFormt)); | |
275 | + } | |
276 | + j++; | |
277 | + } | |
278 | + } | |
279 | + | |
280 | + book.write(); | |
281 | + book.close(); | |
282 | + wb.close(); | |
283 | + }catch (Exception e) | |
284 | + { | |
285 | + e.printStackTrace(); | |
286 | + } | |
287 | + } | |
237 | 288 | |
238 | 289 | public static void writeExclFile(String filePath,OutputStream out,List<String> areaNams,String titleName,String area,String time,List<Map<String,String>> values) |
239 | 290 | { |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/MatDeliverController.java
View file @
8e0b807
... | ... | @@ -287,6 +287,66 @@ |
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
290 | + | |
291 | + @TokenRequired | |
292 | + @RequestMapping(value = "fmRecordExportExcl", method = RequestMethod.POST) | |
293 | + public void fmRecordExportExcl(HttpServletRequest httpServletRequest, @RequestBody ChildbirthManagerRequest childbirthManagerRequest, HttpServletResponse httpServletResponse) { | |
294 | + try { | |
295 | + childbirthManagerRequest.setOperatorId(((LoginContext) httpServletRequest.getAttribute("loginContext")).getId()); | |
296 | + | |
297 | + Map<String, String> query; | |
298 | + if (StringUtils.isNotEmpty(childbirthManagerRequest.getInitQuery())) { | |
299 | + // 自定义查询 | |
300 | + query = new HashMap<>(); | |
301 | + String initQuery = childbirthManagerRequest.getInitQuery(); | |
302 | + for (String key : childbirthManagerRequest.getInitQueryMap().keySet()) { | |
303 | + if (initQuery.contains(key)) { | |
304 | + query.put(key, query.get(key)); | |
305 | + } | |
306 | + } | |
307 | + } else { | |
308 | + // 没有自定义查询,开始构造普通查询 | |
309 | + if (StringUtils.isEmpty(childbirthManagerRequest.getIsArea())) { | |
310 | + // 非区域 | |
311 | + query = childbirthManagerRequest.getNormalQueryMap(); | |
312 | + } else { | |
313 | + // 区域 | |
314 | + query = childbirthManagerRequest.getAreaQueryMap(); | |
315 | + } | |
316 | + String queryStr = ""; | |
317 | + for (String key : query.keySet()) { | |
318 | + queryStr += key + ","; | |
319 | + } | |
320 | + childbirthManagerRequest.setInitQuery(queryStr.substring(0, queryStr.length() - 1)); | |
321 | + } | |
322 | + | |
323 | + childbirthManagerRequest.setExcel(true); | |
324 | + // 这里返回的结果必然是这个泛型,之所以query返回的结果集没有用泛型是为了更好的传递数据 | |
325 | + @SuppressWarnings("unchecked") | |
326 | + List<ChildbirthManagerQueryModel> childbirthManagerQueryModelList = matDeliverFacade.childbirthManager(childbirthManagerRequest).getData(); | |
327 | + List<Map<String, Object>> list = new ArrayList<>(); | |
328 | + for (ChildbirthManagerQueryModel childbirthManagerQueryModel : childbirthManagerQueryModelList) { | |
329 | + Map<String, Object> map = BeanUtils.objectToObjectMap(childbirthManagerQueryModel); | |
330 | + for (String key : map.keySet()) { | |
331 | + if (StringUtils.isEmpty(String.valueOf(map.get(key)))) { | |
332 | + map.put(key, "-"); | |
333 | + } | |
334 | + } | |
335 | + list.add(map); | |
336 | + } | |
337 | + | |
338 | + httpServletResponse.setContentType("application/force-download"); | |
339 | + httpServletResponse.setHeader("Content-Disposition", "attachment;filename=" + new String(("分娩登记表.xls").getBytes("UTF-8"), "ISO-8859-1")); | |
340 | + String path = this.getClass().getResource("/").getPath()+ "fm_record.xlsx"; | |
341 | + ExcelUtil.writeWhExclFile(path, httpServletResponse.getOutputStream(), list); | |
342 | + | |
343 | + } catch (Exception e) { | |
344 | + ExceptionUtils.catchException(e, "fmRecordExportExcl异常"); | |
345 | + } | |
346 | + } | |
347 | + | |
348 | + | |
349 | + | |
290 | 350 | /** |
291 | 351 | * @auther HuJiaqi |
292 | 352 | * @createTime 2016年12月07日 17时50分 |
platform-operate-api/src/main/resources/fm_record.xlsx
View file @
8e0b807