Exemplo n.º 1
0
  public String addLabel() {
    String path = ServletActionContext.getServletContext().getRealPath("/upload/tag");
    label.setTagName(biaoqianming);
    try {
      if (file != null) {
        String fileName = java.util.UUID.randomUUID().toString(); // 采用时间+UUID的方式随即命名
        String name =
            fileName + fileFileName.substring(fileFileName.lastIndexOf(".")); // 保存在硬盘中的文件名

        FileInputStream inputStream = new FileInputStream(file);
        FileOutputStream outputStream = new FileOutputStream(path + "\\" + name);
        byte[] buf = new byte[1024];
        int length = 0;
        while ((length = inputStream.read(buf)) != -1) {
          outputStream.write(buf, 0, length);
        }
        inputStream.close();
        outputStream.flush();
        outputStream.close();
        // 将封面上传,并将其路径保存到数据库中
        System.out.println(path + "\\" + name);
        String jdPath = path + "\\" + name;
        // 将绝对路径变成访问路径
        // 对保存的路径进行修改
        String allPath = changePath(jdPath);
        // 将当前的文件路径变成服务器访问路径=====================================
        // HchhUtil hu=new HchhUtil();
        Properties prop = HchhUtil.loadProperty();
        String urlHead = HchhUtil.getUrlHead(prop);
        String projectName = HchhUtil.getProjectName(prop);
        // 通过项目名对allPath截取
        String[] strs = allPath.split("/" + projectName);
        String allPath1 = urlHead + "" + strs[1];
        System.out.println(allPath1);
        label.setPhotoPath(allPath1);
        // 将treeCode和grade添加
        Label la = labelDao.findByID(xuanzexiang);
        label.setGrade(la.getGrade() + 1);
        label.setDateTime(new Date());
        label.setParentId(xuanzexiang);
        label.setPhotoNum(0);
        label.setType(0);
        labelDao.saveLabel(label);
        String treeCode = la.getTreeCode() + "-" + label.getId();
        label.setTreeCode(treeCode);
        labelDao.saveLabel(label);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return "success";
  }
Exemplo n.º 2
0
  public String shenHe() {
    User user = userDao.findById(userId);
    user.setHeadPhotoRZ(headPhotoState);
    List<Headphoto> hps = hpDao.findByUserid(userId);
    if (headPhotoState == 1) {
      // 根据时间排序第一个设置为1,其它都为0
      for (int i = 0; i < hps.size(); i++) {
        Headphoto hp = hps.get(i);
        if (i == 0) {
          hp.setHeadPhotoState(1);
          user.setHeadPhoto(hp.getHeadPhotoPath());
        }
        hp.setHeadPhotoState(0);
        hpDao.saveOrUpdateHeadPhoto(hp);
      }
    } else {
      // 根据时间排序第一个设置为2,其它都为0
      for (int i = 0; i < hps.size(); i++) {
        Headphoto hp = hps.get(i);
        if (i == 0) {
          hp.setHeadPhotoState(2);
          String headpath = HchhUtil.getUrlHead(HchhUtil.loadProperty());
          user.setHeadPhoto(headpath + "/frame/image/head.jpg");
        }
        hp.setHeadPhotoState(0);
        hpDao.saveOrUpdateHeadPhoto(hp);
      }
    }
    userDao.savaOrUpdateUser(user);
    User user1 = (User) session.get("user");
    if (headPhotoState == 1) {
      commService.saveUserRecord("审核通过", user1.getUserName(), user);
    } else {
      commService.saveUserRecord("审核不通过", user1.getUserName(), user);
    }

    ok = true;
    return "success";
  }