Search in sources :

Example 1 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class CollectionServiceImpl method checkCollected.

@Override
public boolean checkCollected(Integer rid) {
    Condition condition = new Condition(Collection.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("resourceId", rid);
    int total = getTotalBy(condition);
    if (total == 0) {
        return false;
    } else {
        return true;
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 2 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class DrawServiceImpl method findByCreatorId.

@Override
public List<Draw> findByCreatorId(int creatorId) {
    DrawMapper mapper = (DrawMapper) this.mapper;
    Condition condition = new Condition(Draw.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("creatorId", creatorId);
    criteria.andEqualTo("del", 0);
    return mapper.selectByCondition(condition);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) DrawMapper(com.cas.sim.tis.mapper.DrawMapper) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Example 3 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class LibraryRecordServiceImpl method addRecord.

@Override
public void addRecord(LibraryRecord record, List<LibraryAnswer> answers) {
    // 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 {
        saveUseGeneratedKeys(record);
        int recordId = record.getId();
        for (LibraryAnswer answer : answers) {
            answer.setRecordId(recordId);
        }
        answerService.save(answers);
        LibraryPublish publish = publishService.findById(record.getPublishId());
        // 获得班级总人数
        if (publish.getClassId() == null) {
            publish.setAverage(MathUtil.round(2, record.getScore()));
        } else {
            Condition userCon = new Condition(User.class);
            Criteria criteria = userCon.createCriteria();
            criteria.andEqualTo("classId", publish.getClassId());
            criteria.andEqualTo("del", 0);
            int total = userService.getTotalBy(userCon);
            // 获得已交卷成绩总和
            LibraryRecordMapper recordMapper = (LibraryRecordMapper) mapper;
            float sum = recordMapper.getRecordScoresSumByPublishId(publish.getId());
            publish.setAverage(MathUtil.round(2, sum / total));
        }
        // 更新平均成绩
        publishService.update(publish);
        transactionManager.commit(status);
    } catch (Exception e) {
        e.printStackTrace();
        transactionManager.rollback(status);
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) LibraryRecordMapper(com.cas.sim.tis.mapper.LibraryRecordMapper) TransactionStatus(org.springframework.transaction.TransactionStatus) Criteria(tk.mybatis.mapper.entity.Example.Criteria) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager) LibraryPublish(com.cas.sim.tis.entity.LibraryPublish)

Example 4 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class LibraryServiceImpl method findLibraryByType.

@Override
public List<Library> findLibraryByType(int type, String key) {
    Condition condition = new Condition(Library.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("type", type);
    criteria.andEqualTo("del", 0);
    if (!StringUtils.isEmpty(key)) {
        criteria.andLike("name", "%" + key + "%");
    }
    List<Library> result = findByCondition(condition);
    if (result == null) {
        return new ArrayList<>();
    } else {
        return result;
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) ArrayList(java.util.ArrayList) Criteria(tk.mybatis.mapper.entity.Example.Criteria) Library(com.cas.sim.tis.entity.Library)

Example 5 with Criteria

use of tk.mybatis.mapper.entity.Example.Criteria in project TeachingInSimulation by ScOrPiOzzy.

the class LibraryServiceImpl method findLibraryByType.

@Override
public PageInfo<Library> findLibraryByType(int pageIndex, int pageSize, int type) {
    Condition condition = new Condition(Library.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("type", type);
    criteria.andEqualTo("del", 0);
    PageHelper.startPage(pageIndex, pageSize);
    List<Library> result = findByCondition(condition);
    PageInfo<Library> page = new PageInfo<Library>(result);
    LOG.info("成功查找到{}条资源,当前页码{},每页{}条资源,共{}页", result.size(), pageIndex, pageSize, page.getPages());
    return page;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) PageInfo(com.github.pagehelper.PageInfo) Criteria(tk.mybatis.mapper.entity.Example.Criteria) Library(com.cas.sim.tis.entity.Library)

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