Exemplo n.º 1
0
  public String getCodeJson(MobileServerConfig mobileServerConfig, Document doc, String urlPara) {
    String json = "";

    JSONObject jsonObjectResult = new JSONObject();

    try {
      List<Code> list = GetCodeCache();

      if (list != null && list.size() > 0) {
        JSONArray jsonArray = new JSONArray();

        for (Code code : list) {
          JSONObject jsonObjectData = new JSONObject();

          jsonObjectData.put("codeName", code.getCodeName());
          jsonObjectData.put("description", code.getDescription());
          jsonObjectData.put("category", code.getCategory());

          jsonArray.add(jsonObjectData);
        }

        jsonObjectResult.put("result", "1");
        jsonObjectResult.put("data", jsonArray);
      }
    } catch (Exception e) {
      // TODO: handle exception
      jsonObjectResult.put("result", "0");
      jsonObjectResult.put("message", e.getMessage());
    }

    json = jsonObjectResult.toString();

    return json;
  }
Exemplo n.º 2
0
 public Map<String, Object> getCodeCacheMap() {
   Map<String, Object> map = new HashMap<String, Object>();
   List<Code> list = GetCodeCache();
   for (Code entity : list) {
     map.put(entity.getCodeName(), entity.getDescription());
   }
   return map;
 }
Exemplo n.º 3
0
 public List<Code> getCodeCacheListByCategory(String category) {
   List<Code> resultList = new ArrayList<Code>();
   List<Code> list = GetCodeCache();
   for (Code entity : list) {
     if (entity.getCategory().equals(category)) {
       resultList.add(entity);
     }
   }
   return resultList;
 }
Exemplo n.º 4
0
 public Map<String, Object> getCodeCacheMapByCategory(String category) {
   Map<String, Object> map = new HashMap<String, Object>();
   List<Code> list = GetCodeCache();
   for (Code entity : list) {
     if (entity.getCategory().equals(category)) {
       map.put(entity.getCodeName(), entity.getDescription());
     }
   }
   return map;
 }
Exemplo n.º 5
0
 public List<Map<String, Object>> getCodeCacheByCategory(String category) {
   List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
   List<Code> list = GetCodeCache();
   for (Code entity : list) {
     if (entity.getCategory().equals(category)) {
       Map<String, Object> map = new HashMap<String, Object>();
       map.put("id", entity.getCodeName());
       map.put("text", entity.getDescription());
       maps.add(map);
     }
   }
   return maps;
 }
Exemplo n.º 6
0
  public String getCodeByCategoryJson(
      MobileServerConfig mobileServerConfig, Document doc, String urlPara) {
    String json = "";

    String paraJson = urlPara;
    JSONObject jsonObject = JSONObject.fromObject(paraJson);

    String category = "";
    if (jsonObject.containsKey("category")) {
      category = jsonObject.opt("category").toString();
    }

    JSONObject jsonObjectResult = new JSONObject();

    try {
      if (category != null && !category.equals("")) {
        List<Code> list = getCodeCacheListByCategory(category);

        if (list != null && list.size() > 0) {
          JSONArray jsonArray = new JSONArray();

          for (Code code : list) {
            JSONObject jsonObjectData = new JSONObject();

            jsonObjectData.put("codeName", code.getCodeName());
            jsonObjectData.put("description", code.getDescription());

            jsonArray.add(jsonObjectData);
          }

          jsonObjectResult.put("result", "1");
          jsonObjectResult.put("data", jsonArray);
        }
      } else {
        jsonObjectResult.put("result", "0");
        jsonObjectResult.put("message", "缺少必要参数");
      }
    } catch (Exception e) {
      // TODO: handle exception
      jsonObjectResult.put("result", "0");
      jsonObjectResult.put("message", e.getMessage());
    }

    json = jsonObjectResult.toString();

    return json;
  }
Exemplo n.º 7
0
  @SuppressWarnings("deprecation")
  public String ExpExcel(List<Code> list, String path) {
    String filePath = "";

    if (list.size() > 0) {
      /*第一步,创建一个webbook,对应一个Excel文件*/
      HSSFWorkbook wb = new HSSFWorkbook();
      /*第二步,在webbook中添加一个sheet,对应Excel文件中的sheet*/
      HSSFSheet sheet = wb.createSheet("用户列表");
      /*第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short*/
      HSSFRow row = sheet.createRow((int) 0);
      /*第四步,创建单元格,并设置值表头 设置表头居中*/
      HSSFCellStyle style = wb.createCellStyle();
      /*左对齐*/
      style.setAlignment(HSSFCellStyle.ALIGN_LEFT);

      HSSFCell cell = row.createCell((short) 0);
      cell.setCellValue("编码名称");
      cell.setCellStyle(style);

      cell = row.createCell((short) 1);
      cell.setCellValue("描述");
      cell.setCellStyle(style);

      cell = row.createCell((short) 2);
      cell.setCellValue("编码类型");
      cell.setCellStyle(style);

      cell = row.createCell((short) 3);
      cell.setCellValue("状态");
      cell.setCellStyle(style);

      cell = row.createCell((short) 4);
      cell.setCellValue("创建日期");
      cell.setCellStyle(style);

      /*第五步,写入实体数据 实际应用中这些数据从数据库得到,*/
      for (int i = 0; i < list.size(); i++) {
        row = sheet.createRow((int) i + 1);
        Code model = (Code) list.get(i);
        /*第四步,创建单元格,并设置值*/
        row.createCell((short) 0).setCellValue(model.getCodeName());
        row.createCell((short) 1).setCellValue(model.getDescription());
        row.createCell((short) 2).setCellValue(model.getCategory());
        row.createCell((short) 3).setCellValue(model.getStatus());
        cell = row.createCell((short) 4);
        cell.setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(model.getCreateTime()));
      }

      /*第六步,将文件存到指定位置*/
      try {
        String fileName = UUID.randomUUID() + ".xls";
        String tempFilePath = path + "\\" + fileName;

        FileOutputStream fout = new FileOutputStream(tempFilePath);
        wb.write(fout);
        fout.close();

        filePath = tempFilePath;
      } catch (Exception e) {
        System.out.print(e.getMessage());
      }
    }

    return filePath;
  }