Search in sources :

Example 51 with Condition

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

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

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

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

Example 55 with Condition

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

the class UserServiceImpl method login.

@Override
public User login(String usercode, String password) {
    Condition condition = new Condition(User.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("code", usercode);
    criteria.andEqualTo("password", password);
    criteria.andEqualTo("del", 0);
    List<User> user = null;
    try {
        user = mapper.selectByCondition(condition);
    } catch (Exception e) {
        throw new ServerException("服务器异常", e);
    }
    if (user.size() == 1) {
        return user.get(0);
    } else if (user.size() == 0) {
        throw new ServiceException("用户名或密码错误!");
    } else {
        throw new TooManyResultsException();
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) User(com.cas.sim.tis.entity.User) ServerException(com.cas.sim.tis.services.exception.ServerException) ServiceException(com.cas.sim.tis.services.exception.ServiceException) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) Criteria(tk.mybatis.mapper.entity.Example.Criteria) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) ServiceException(com.cas.sim.tis.services.exception.ServiceException) ServerException(com.cas.sim.tis.services.exception.ServerException)

Aggregations

Condition (tk.mybatis.mapper.entity.Condition)69 Criteria (tk.mybatis.mapper.entity.Example.Criteria)25 Transactional (org.springframework.transaction.annotation.Transactional)21 PostMapping (org.springframework.web.bind.annotation.PostMapping)21 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)15 Machine (com.eservice.api.model.machine.Machine)13 TaskRecord (com.eservice.api.model.task_record.TaskRecord)10 Date (java.util.Date)10 PageInfo (com.github.pagehelper.PageInfo)9 ArrayList (java.util.ArrayList)9 ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)8 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)7 Contract (com.eservice.api.model.contract.Contract)6 ContractSign (com.eservice.api.model.contract_sign.ContractSign)6 Task (com.eservice.api.model.task.Task)6 PanoramicRealTimeConsumptionGather (com.monitor.model.realtimeconsumptiongather.PanoramicRealTimeConsumptionGather)6 OrderSign (com.eservice.api.model.order_sign.OrderSign)5 User (com.cas.sim.tis.entity.User)4 User (com.eservice.api.model.user.User)4 AbnormalRecord (com.eservice.api.model.abnormal_record.AbnormalRecord)3