예제 #1
0
  @IdeaJdbcTx
  public int updateSubject(String id, String name, String desc) {
    UserContext uc = UserContext.getCurrentContext();
    User user = (User) uc.getContextAttribute(UserContext.SESSION_USER);
    Subject subject = IdeaJdbc.find(Subject.class, id);

    if (subject == null) {
      throw dataNotFoundException(id);
    } else {
      List<Subject> existsSubjects = subjectDao.querySubjectExceptSelf(ProductType.TEXT, name, id);

      if (existsSubjects.size() > 0) {
        throw duplicateException(name);
      } else {
        subject.setName(name);
        subject.setDesc(desc);
        subject.setModifier(user.getId());
        subject.setModifyTime(new Date());
        return IdeaJdbc.update(subject);
      }
    }
  }
예제 #2
0
  @IdeaJdbcTx
  public Subject createTextSubject(String name, String desc) {
    UserContext uc = UserContext.getCurrentContext();
    User user = (User) uc.getContextAttribute(UserContext.SESSION_USER);

    List<Subject> existsSubjects = subjectDao.querySubject(ProductType.TEXT, name, false);

    if (existsSubjects.size() > 0) {
      throw duplicateException(name);
    } else {
      int maxOrder = subjectDao.queryMaxOrder(ProductType.TEXT);
      Subject subject = new Subject();
      subject.setName(name);
      subject.setDesc(desc);
      subject.setOrder(maxOrder + 1);
      subject.setCreateTime(new Date());
      subject.setCreator(user.getId());

      IdeaJdbc.save(subject);

      return subject;
    }
  }