Search in sources :

Example 16 with Criteria

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

Example 17 with Criteria

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

Example 18 with Criteria

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;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) ArrayList(java.util.ArrayList) Resource(com.cas.sim.tis.entity.Resource) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 19 with Criteria

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

Example 20 with Criteria

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