use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class QuestionServiceImpl method findQuestionsByLibraryAndQuestionType.
@Override
public List<Question> findQuestionsByLibraryAndQuestionType(int rid, int type) {
Condition condition = new Condition(Question.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("relateId", rid);
criteria.andEqualTo("type", type);
return findByCondition(condition);
}
use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceServiceImpl method uncollect.
@Override
public void uncollect(Integer id, Integer userId) {
// 1.获取事务控制管理器
DataSourceTransactionManager transactionManager = SpringUtil.getBean(DataSourceTransactionManager.class);
// 2.获取事务定义
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// 3.设置事务隔离级别,开启新事务
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
// 4.获得事务状态
TransactionStatus status = transactionManager.getTransaction(def);
try {
// 减少资源收藏数量
ResourceMapper resourceMapper = (ResourceMapper) mapper;
resourceMapper.decreaseCollection(id);
// 修改用户收藏记录
Condition condition = new Condition(Collection.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("creator", userId);
criteria.andEqualTo("resourceId", id);
criteria.andEqualTo("del", 0);
List<Collection> collections = collectionService.findByCondition(condition);
for (Collection collection : collections) {
collection.setDel(1);
collectionService.update(collection);
}
transactionManager.commit(status);
} catch (Exception e) {
e.printStackTrace();
transactionManager.rollback(status);
}
}
use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceServiceImpl method findResourcesByCreator.
@Override
public List<Resource> findResourcesByCreator(List<Integer> resourceTypes, String keyword, Integer creator) {
// 获取当前登陆者身份信息
Condition condition = new Condition(Resource.class);
// 条件1、查找用户指定的几种资源类型
if (resourceTypes.size() == 0) {
return new ArrayList<Resource>();
} else {
Criteria criteria = condition.createCriteria();
criteria.andIn("type", resourceTypes);
}
// 条件2、关键字搜索
if (keyword != null && !"".equals(keyword)) {
Criteria criteria = condition.createCriteria();
List<String> words = StringUtil.split(keyword, ' ');
for (String word : words) {
criteria.orLike("keyword", "%" + word + "%");
}
condition.and(criteria);
}
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("creator", creator);
condition.and(criteria);
List<Resource> result = findByCondition(condition);
return result;
}
use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class TypicalCaseServiceImpl method findTypicalCases.
@Override
public List<TypicalCase> findTypicalCases() {
Condition condition = new Condition(TypicalCase.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("del", 0);
return findByCondition(condition);
}
use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.
the class UserServiceImpl method findTeachers.
@Override
public List<User> findTeachers() {
Condition condition = new Condition(User.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("role", RoleConst.TEACHER);
criteria.andEqualTo("del", 0);
condition.orderBy("createDate").desc();
return findByCondition(condition);
}
Aggregations