use of com.cas.sim.tis.entity.Resource in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceSelectedDialog method reload.
private void reload() {
List<Resource> resources = SpringUtil.getBean(ResourceAction.class).findResourcesByCreator(types, search.getText(), (Integer) group.getSelectedToggle().getUserData());
JSONArray array = new JSONArray();
array.addAll(resources);
table.setItems(array);
table.build();
}
use of com.cas.sim.tis.entity.Resource in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceUploadDialog method upload.
private void upload(ActionEvent event) {
// 禁用上传按钮
((Button) event.getSource()).setDisable(true);
uploadTip.setText(MsgUtil.getMessage("ftp.upload.waiting"));
AlertUtil.showConfirm(dialog.getOwner(), MsgUtil.getMessage("ftp.upload.confirmation"), (resp) -> {
if (ButtonType.NO == resp) {
((Button) event.getSource()).setDisable(false);
uploadTip.setText(null);
return;
}
String filePath = uploadFile.getAbsolutePath();
String fileName = FileUtil.getFileName(filePath);
String ext = FileUtil.getFileExt(filePath);
// 重命名
String rename = UUID.randomUUID() + "." + ext;
// 上传文件到FTP
boolean uploaded = SpringUtil.getBean(FTPUtils.class).uploadFile(ResourceConsts.FTP_RES_PATH, uploadFile, rename);
if (!uploaded) {
uploadTip.setText(MsgUtil.getMessage("ftp.upload.failure"));
// 启用上传按钮
((Button) event.getSource()).setDisable(false);
return;
}
// 封装资源记录
Resource resource = new Resource();
resource.setKeyword(keywords.getText());
resource.setPath(rename);
resource.setName(fileName);
try {
if (this.type == null) {
int type = ResourceType.parseType(ext);
resource.setType(type);
} else {
resource.setType(this.type.getType());
}
} catch (Exception e) {
LOG.warn("解析文件后缀名出现错误", e);
throw e;
}
// 记录到数据库
Integer id = SpringUtil.getBean(ResourceAction.class).addResource(resource);
if (id == null) {
uploadTip.setText(MsgUtil.getMessage("ftp.upload.converter.failure"));
// 启用上传按钮
((Button) event.getSource()).setDisable(false);
return;
} else {
setResult(id);
}
});
}
use of com.cas.sim.tis.entity.Resource 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;
}
use of com.cas.sim.tis.entity.Resource in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceServiceImpl method findResourcesByCollection.
@Override
public PageInfo<Resource> findResourcesByCollection(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.findResourcesByCollection(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;
}
use of com.cas.sim.tis.entity.Resource 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;
}
Aggregations