use of com.cas.sim.tis.mapper.ResourceMapper in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceServiceImpl method findResourceInfoByID.
@Override
public ResourceInfo findResourceInfoByID(int id) {
ResourceMapper resourceMapper = (ResourceMapper) mapper;
ResourceInfo result = resourceMapper.selectResourceInfoByID(id);
return result;
}
use of com.cas.sim.tis.mapper.ResourceMapper 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);
}
}
use of com.cas.sim.tis.mapper.ResourceMapper in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceServiceImpl method collected.
@Override
public void collected(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.increaseCollection(id);
// 新增用户收藏记录
Collection collection = new Collection();
collection.setResourceId(id);
collection.setCreator(userId);
collectionService.save(collection);
transactionManager.commit(status);
} catch (Exception e) {
e.printStackTrace();
transactionManager.rollback(status);
}
}
use of com.cas.sim.tis.mapper.ResourceMapper 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);
}
}
use of com.cas.sim.tis.mapper.ResourceMapper in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceServiceImpl method findResourcesByBrowseHistory.
@Override
public PageInfo<Resource> findResourcesByBrowseHistory(int pagination, int pageSize, List<Integer> resourceTypes, String keyword, String orderByClause, Integer creator) {
ResourceMapper resourceMapper = (ResourceMapper) mapper;
// 开始分页查询
PageHelper.startPage(pagination, pageSize, orderByClause);
List<Resource> result = resourceMapper.findResourcesByBrowseHistory(resourceTypes, keyword, creator);
PageInfo<Resource> page = new PageInfo<Resource>(result);
// 查到的总记录数
// 解释一下:这个page.getTotal(),是所有符合条件的记录数。
// result.size():是当前页中的数据量 <= pageSize
LOG.info("成功查找到{}条资源,当前页码{},每页{}条资源,共{}页", result.size(), pagination, pageSize, page.getPages());
return page;
}
Aggregations