Search in sources :

Example 6 with Condition

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

Example 7 with 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);
    }
}
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 Condition

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

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

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

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