use of tk.mybatis.mapper.entity.Example.Criteria 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;
}
}
use of tk.mybatis.mapper.entity.Example.Criteria 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);
}
use of tk.mybatis.mapper.entity.Example.Criteria 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);
}
}
use of tk.mybatis.mapper.entity.Example.Criteria 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;
}
}
use of tk.mybatis.mapper.entity.Example.Criteria 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;
}
Aggregations