コード例 #1
0
 /**
  * 删除资产信息
  *
  * @param request
  * @param response
  * @param printWriter
  */
 @RequestMapping("/deleteAsset")
 public void deleteAsset(
     HttpServletRequest request, HttpServletResponse response, PrintWriter printWriter) {
   Map<String, Object> result_map = new HashMap<String, Object>();
   String id = request.getParameter("id");
   Boolean bon = assetService.deleteEntityById(id);
   result_map.put("success", bon);
   printWriter.print(JsonUtil.jsonObject(result_map, null, null));
   printWriter.flush();
   printWriter.close();
 }
コード例 #2
0
  /**
   * 添加新资产方法
   *
   * @param request
   * @param response
   * @param printWriter
   */
  @RequestMapping("/addAsset")
  public void addAsset(
      HttpServletRequest request, HttpServletResponse response, PrintWriter printWriter) {
    Map<String, Object> result_map = new HashMap<String, Object>();
    String idString = request.getParameter("id");
    String number = request.getParameter("number");
    String name = request.getParameter("name");
    String uses = request.getParameter("uses");
    String category = request.getParameter("category");
    String entryTime = request.getParameter("entryTime");
    String status = request.getParameter("status");
    String remarks = request.getParameter("remarks");

    Asset asset = new Asset();

    if (StringUtils.isNotBlank(idString)) {
      asset.setId(idString);
    } else {
      asset.setId(UUID.randomUUID() + "");
    }
    if (StringUtils.isNotBlank(number)) {
      asset.setNumber(number);
    }
    if (StringUtils.isNotBlank(name)) {
      asset.setName(name);
    }
    if (StringUtils.isNotBlank(uses)) {
      asset.setUses(uses);
    }
    if (StringUtils.isNotBlank(category)) {
      asset.setCategory(category);
    }
    if (StringUtils.isNotBlank(status)) {
      asset.setStatus(status);
    }
    if (StringUtils.isNotBlank(entryTime)) {
      try {
        asset.setEntryTime(new SimpleDateFormat("yyyy-MM-dd").parse(entryTime));
      } catch (ParseException e) {
        e.printStackTrace();
      }
    }
    if (StringUtils.isNotBlank(remarks)) {
      asset.setRemarks(remarks);
    }
    try {
      boolean bon = assetService.saveupdateAsset(asset);
      if (bon) {
        result_map.put("success", true);
        result_map.put("msg", "添加成功");
      } else {
        result_map.put("success", false);
        result_map.put("msg", "添加失败");
      }
    } catch (Exception e) {
      result_map.put("success", false);
      result_map.put("msg", "系统错误,请与管理员联系");
      e.printStackTrace();
    } finally {
      printWriter.print(JsonUtil.jsonObject(result_map, null, null));
      printWriter.flush();
      printWriter.close();
    }
  }