Example #1
0
 @IdeaJdbcTx
 public int deleteSubject(String id) {
   boolean exists = subjectDao.checkExistsProductsOfSubject(id);
   if (exists) {
     throw new IdeaDataException(
         IdeaDataExceptionCode.CANT_DELETE_DUE_ASSO_DATA,
         String.format("Can not delete subject[%s] due having products.", id));
   } else {
     IdeaJdbc.delete(Subject.class, id);
     return 1;
   }
 }
Example #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;
    }
  }
Example #3
0
  @IdeaJdbcTx
  public int downSubject(String id) {
    Subject subject = IdeaJdbc.find(Subject.class, id);

    if (subject == null) {
      throw dataNotFoundException(id);
    } else {
      int order = subject.getOrder();
      Subject nextSubject = subjectDao.querySubjectByOrder(ProductType.TEXT, order + 1);

      nextSubject.setOrder(order);
      subject.setOrder(order + 1);

      IdeaJdbc.update(nextSubject);
      IdeaJdbc.update(subject);

      return 2;
    }
  }
Example #4
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);
      }
    }
  }
Example #5
0
 @IdeaJdbcTx
 public List<Subject> listTextSubjects(String key) {
   String type = ProductType.TEXT;
   return subjectDao.listSubjects(type, key);
 }
Example #6
0
 @IdeaJdbcTx
 public void batchDeleteSubjects(String[] idArray) {
   subjectDao.batchDeleteSubjects(idArray);
 }