use of com.cas.sim.tis.entity.Collection 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.entity.Collection 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);
}
}
Aggregations