@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; } }
@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; } }