Search in sources :

Example 6 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria 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);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 7 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria 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);
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) Preparation(com.cas.sim.tis.entity.Preparation) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 8 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria 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;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) PageInfo(com.github.pagehelper.PageInfo) Question(com.cas.sim.tis.entity.Question) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 9 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria 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);
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) BrowseHistory(com.cas.sim.tis.entity.BrowseHistory) ResourceMapper(com.cas.sim.tis.mapper.ResourceMapper) TransactionStatus(org.springframework.transaction.TransactionStatus) Criteria(tk.mybatis.mapper.entity.Example.Criteria) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager)

Example 10 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria 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);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Aggregations

Condition (tk.mybatis.mapper.entity.Condition)25 Criteria (tk.mybatis.mapper.entity.Example.Criteria)25 PageInfo (com.github.pagehelper.PageInfo)6 User (com.cas.sim.tis.entity.User)4 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)3 Library (com.cas.sim.tis.entity.Library)2 Resource (com.cas.sim.tis.entity.Resource)2 ResourceMapper (com.cas.sim.tis.mapper.ResourceMapper)2 ArrayList (java.util.ArrayList)2 TooManyResultsException (org.apache.ibatis.exceptions.TooManyResultsException)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 BrowseHistory (com.cas.sim.tis.entity.BrowseHistory)1 Catalog (com.cas.sim.tis.entity.Catalog)1 Collection (com.cas.sim.tis.entity.Collection)1 ElecComp (com.cas.sim.tis.entity.ElecComp)1 LibraryAnswer (com.cas.sim.tis.entity.LibraryAnswer)1 LibraryPublish (com.cas.sim.tis.entity.LibraryPublish)1