Search in sources :

Example 1 with Condition

use of tk.mybatis.mapper.entity.Condition 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 Condition

use of tk.mybatis.mapper.entity.Condition 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 Condition

use of tk.mybatis.mapper.entity.Condition 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 Condition

use of tk.mybatis.mapper.entity.Condition 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 Condition

use of tk.mybatis.mapper.entity.Condition 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)59 Criteria (tk.mybatis.mapper.entity.Example.Criteria)25 Transactional (org.springframework.transaction.annotation.Transactional)17 PostMapping (org.springframework.web.bind.annotation.PostMapping)13 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)10 Machine (com.eservice.api.model.machine.Machine)8 PageInfo (com.github.pagehelper.PageInfo)8 TaskRecord (com.eservice.api.model.task_record.TaskRecord)6 PanoramicRealTimeConsumptionGather (com.monitor.model.realtimeconsumptiongather.PanoramicRealTimeConsumptionGather)6 Date (java.util.Date)6 Contract (com.eservice.api.model.contract.Contract)5 ContractSign (com.eservice.api.model.contract_sign.ContractSign)5 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)5 User (com.cas.sim.tis.entity.User)4 ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)4 Task (com.eservice.api.model.task.Task)4 OrderSign (com.eservice.api.model.order_sign.OrderSign)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