예제 #1
0
  public InfoImg getInfoMainImg(Long infoId) {
    Criteria cri = getSession().createCriteria(InfoImg.class);
    Info info = new Info();
    info.setId(infoId);

    cri.add(Restrictions.eq("info", info));
    cri.add(Restrictions.eq("isMainImg", true));

    return (InfoImg) cri.uniqueResult();
  }
예제 #2
0
  @Override
  public List<Criterion> getCriterions(ParamCondition paramCondition) {
    List<Criterion> criterions = new ArrayList<Criterion>();

    if (!paramCondition.isParameterNull("infoId")) {
      Long infoId = paramCondition.getLong("infoId");
      Info info = new Info();
      info.setId(infoId);
      criterions.add(Restrictions.eq("info", info));
    }

    return criterions;
  }
예제 #3
0
  @Override
  public String insert() {

    info.setStatus(Info.STATUS_UNAUDIT);

    super.insert();

    // begin 处理图片
    if (upload != null && !upload.isEmpty()) {
      ScaleImage scaleImage = new ScaleImage();
      int size = upload.size();
      for (int i = 0; i < size; i++) {
        File upl = upload.get(i);
        String uplName = uploadFileName.get(i);

        IFileSystem fileSystem = new LocalFileSystem();
        String extension = FilenameUtils.getExtension(uplName);
        FileItemInfo fileItemInfo =
            fileSystem.saveFile(upl, extension, SystemConfig.UPLOAD_FILE_DIR);

        // 生产缩略图
        String uniqueFileName = FileNameUtil.getUniqueFileName(extension);
        String fullPath = SystemConfig.UPLOAD_FILE_DIR + "/" + uniqueFileName;
        File targetFile = new File(fullPath);
        try {
          scaleImage.saveImageAsJpg(
              upl,
              targetFile,
              SystemConfig.IMAGE_ABBREVIATIVE_WIDTH,
              SystemConfig.IMAGE_ABBREVIATIVE_HEIGHT);
        } catch (Exception e) {
          e.printStackTrace();
          log.error("生成缩略图失败:", e);
        }

        log.debug("原图:" + fileItemInfo.getFileId() + "\n缩略图:" + fullPath);

        InfoImg infoImg = new InfoImg();
        infoImg.setInfo(info);
        infoImg.setImgUrl(fileItemInfo.getFileId());
        infoImg.setSmallImgUrl(uniqueFileName);
        infoImg.setName(uplName);
        infoImg.setDescription(description.get(i));
        infoImg.setIsMainImg(i == 0);

        infoImgService.insert(infoImg);
      }
    }

    // end 处理图片

    return ResultConstants.LIST;
  }