/**
  * 从数据库查询信息供写文件使用
  *
  * @return JSONArray
  */
 public JSONArray loadInfo() {
   JSONArray jsonArray = new JSONArray();
   try {
     List<Asset> assetList = assetService.findAllAssetList();
     for (int i = 0; i < assetList.size(); i++) {
       JSONObject jsonObject = new JSONObject();
       Asset asset = new Asset();
       asset = assetList.get(i);
       jsonObject.put("number", asset.getNumber());
       jsonObject.put("name", asset.getName());
       jsonObject.put("uses", asset.getUses());
       jsonObject.put("category", asset.getCategory());
       jsonObject.put(
           "entryTime", new SimpleDateFormat("yyyy-MM-dd").format(asset.getEntryTime()));
       jsonObject.put("status", asset.getStatus());
       jsonObject.put("remarks", asset.getRemarks());
       jsonObject.put(
           "edit",
           "<a href='javascript:void(0)' onclick='editAsset("
               + '"'
               + asset.getId()
               + '"'
               + ")'>编辑</>/<a href='javascript:void(0)' onclick='deleteAsset("
               + '"'
               + asset.getId()
               + '"'
               + ")'>删除</>");
       jsonArray.add(jsonObject);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return jsonArray;
 }
 /**
  * 查询资产信息
  *
  * @param request
  * @param response
  * @param printWriter
  */
 public Map<String, Object> searchAsset(String id) {
   Map<String, Object> result_map = new HashMap<String, Object>();
   Asset asset = new Asset();
   asset = assetService.findById(id);
   String date = new SimpleDateFormat("yyyy-MM-dd").format(asset.getEntryTime());
   result_map.put("msg", asset);
   result_map.put("date", date);
   return result_map;
 }
  /**
   * 添加新资产方法
   *
   * @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();
    }
  }