/** * ** 下载整表,单sheet文件 * * @param model * @param request * @param response * @return */ @RequestMapping(value = "/download_clients", method = RequestMethod.POST) public void single( Model model, HttpServletRequest request, HttpServletResponse response, String titles, String fields, String fileName) { logger.debug("下载单sheet文件"); HttpServletRequestUtil.debugParams(request); try { // 获取类 List list = this.clientService.downLoadAllClientByUserId(this.getUserId()); String[] titleNames = Client.getTitlesForDownLoad(); String[] fieldNames = Client.getFieldsForDownLoad(); Map<String, Integer> fieldWidths = Client.getWidthsForDownLoad(); String sheetName = "sheet0"; WorkbookConfig wcg = new WorkbookConfig(); wcg.setWorkbookName(fileName); wcg.addSheetName(sheetName); wcg.addSheetField(sheetName, fieldNames); wcg.addSheetTitle(sheetName, titleNames); wcg.addSheetWidth(sheetName, fieldWidths); HSSFWorkbook wb = ExportUtils.createSingSheetHSSFWorkbook(wcg, list); ExportUtils.setHeader(response, fileName); // 获取输出流,写入excel 并关闭 ServletOutputStream out = response.getOutputStream(); wb.write(out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } }
/** * ** 查询系统用户信息(条件查询,查询多笔,按照系统用户码或名称) * * @param model * @param request * @return */ @RequestMapping(value = "/list", method = RequestMethod.POST) @ResponseBody public Object list( Model model, HttpServletRequest request, String userId, String search_condition) { HttpServletRequestUtil.debugParams(request); try { DBObject query = new BasicDBObject(); if (StringUtil.isNotEmpty(userId)) { query.put("owner_user_id", userId); } query.put("useflg", "1"); if (StringUtil.isNotEmpty(search_condition)) { String name = search_condition.trim(); Pattern namePattern = RegexPatternUtil.getLikePattern(name); BasicDBList values = new BasicDBList(); values.add(new BasicDBObject("client_name", namePattern)); values.add(new BasicDBObject("pinyin_name", namePattern)); values.add(new BasicDBObject("first_char_header", namePattern)); values.add(new BasicDBObject("all_char_header", namePattern)); query.put("$or", values); } DBObject sort = new BasicDBObject(); sort.put("client_name_full_py", 1); DBObject returnFields = null; return this.clientService.batchSearchPage(query, sort, returnFields); } catch (Exception e) { return this.handleException(e); } }
/** * ** 添加 * * @return */ @RequestMapping(value = "/add", method = RequestMethod.POST) @ResponseBody public Object add(@Validated Client client, BindingResult br, HttpServletRequest request) { HttpServletRequestUtil.debugParams(request); String phone_info = request.getParameter("phone_info"); String address_info = request.getParameter("address_info"); String interesting_services = request.getParameter("interesting_service"); List<Phone> phones = JsonUtil.getGson().fromJson(phone_info, new TypeToken<List<Phone>>() {}.getType()); List<Address> addresses = JsonUtil.getGson().fromJson(address_info, new TypeToken<List<Address>>() {}.getType()); List<String> interesting_service = JsonUtil.getGson() .fromJson(interesting_services, new TypeToken<List<String>>() {}.getType()); client.setInteresting_service(interesting_service); client.setPhone_info(phones); client.setAddress_info(addresses); logger.debug("传入的用户对象\n{}", client); // String userId = this.getUserId(); // if (StringUtil.isEmpty(userId)) { // return this.handleValidateFalse("所属用户id不能为空"); // } // // client.setOwner_user_id(userId); if (br.hasErrors()) { return ErrorHandler.getRequestResultFromBindingResult(br); } try { // 1.校验是否已存在相同的类型码 // boolean isExist = this.clientService // .isExistSameTypecode(client.getTypecode()); // if (isExist) { // RequestResult rr = new RequestResult(); // rr.setSuccess(false); // rr.setMessage("已经存在类型码【" + client.getTypecode().trim() // + "】的用户!"); // return rr; // } // 2.新增 client.setUseflg("1"); String _id = this.clientService.add(client); RequestResult rr = new RequestResult(); rr.setSuccess(true); rr.setMessage(_id); return rr; } catch (Exception e) { return this.handleException(e); } }