use of tk.mybatis.mapper.entity.Condition in project TeachingInSimulation by ScOrPiOzzy.
the class PreparationQuizServiceImpl method countFreeQuizByPreparationId.
@Override
public int countFreeQuizByPreparationId(Integer pid) {
Condition condition = new Condition(PreparationQuiz.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("preparationId", pid);
criteria.andEqualTo("type", PreparationQuizType.FREE.getType());
criteria.andEqualTo("del", 0);
return getTotalBy(condition);
}
use of tk.mybatis.mapper.entity.Condition in project TeachingInSimulation by ScOrPiOzzy.
the class PreparationServiceImpl method findPreparationByTaskIdAndCreator.
@Override
public Preparation findPreparationByTaskIdAndCreator(Integer cid, int creator) {
Condition condition = new Condition(Preparation.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("catalogId", cid);
criteria.andEqualTo("creator", creator);
criteria.andEqualTo("del", 0);
List<Preparation> preparations = findByCondition(condition);
if (preparations.size() == 1) {
return preparations.get(0);
} else if (preparations.size() == 0) {
return null;
} else {
LOG.warn("关联编号{},创建人{}的有效备课信息应仅有一条!", cid, creator);
return preparations.get(0);
}
}
use of tk.mybatis.mapper.entity.Condition in project TeachingInSimulation by ScOrPiOzzy.
the class QuestionServiceImpl method findQuestionsByLibrary.
@Override
public PageInfo<Question> findQuestionsByLibrary(int pageIndex, int pageSize, int rid) {
Condition condition = new Condition(Question.class);
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("relateId", rid);
PageHelper.startPage(pageIndex, pageSize);
List<Question> result = findByCondition(condition);
PageInfo<Question> page = new PageInfo<>(result);
LOG.info("成功查找到{}条资源,当前页码{},每页{}条资源,共{}页", result.size(), pageIndex, pageSize, page.getPages());
return page;
}
use of tk.mybatis.mapper.entity.Condition in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceServiceImpl method browsed.
@Override
public void browsed(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.increaseBrowse(id);
Condition condition = new Condition(BrowseHistory.class);
condition.orderBy("createDate").asc();
Criteria criteria = condition.createCriteria();
criteria.andEqualTo("creator", userId);
List<BrowseHistory> histories = browseHistoryService.findByCondition(condition);
// 查看历史记录是否超过100条,注意这里是物理删除!!!
if (histories.size() >= 100) {
BrowseHistory history = histories.get(0);
browseHistoryService.deleteById(history.getId());
}
BrowseHistory history = new BrowseHistory();
history.setResourceId(id);
history.setCreator(userId);
browseHistoryService.save(history);
transactionManager.commit(status);
} catch (Exception e) {
e.printStackTrace();
transactionManager.rollback(status);
}
}
use of tk.mybatis.mapper.entity.Condition in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceServiceImpl method countResourceByType.
@Override
public int countResourceByType(int type, String keyword, Integer creator) {
// 获取当前登陆者身份信息
Condition condition = new Condition(Resource.class);
Criteria criteria1 = condition.createCriteria();
// 条件1、查找用户指定的资源类型
criteria1.andEqualTo("type", type);
// 条件2、关键字搜索
if (keyword != null && !"".equals(keyword)) {
Criteria criteria2 = condition.createCriteria();
List<String> words = StringUtil.split(keyword, ' ');
for (String word : words) {
criteria2.orLike("keyword", "%" + word + "%");
}
condition.and(criteria2);
}
Criteria criteria3 = condition.createCriteria();
criteria3.andEqualTo("creator", creator);
condition.and(criteria3);
return getTotalBy(condition);
}
Aggregations