Search in sources :

Example 11 with Resource

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();
}
Also used : Resource(com.cas.sim.tis.entity.Resource) JSONArray(com.alibaba.fastjson.JSONArray) ResourceAction(com.cas.sim.tis.action.ResourceAction)

Example 12 with Resource

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);
        }
    });
}
Also used : Button(javafx.scene.control.Button) Resource(com.cas.sim.tis.entity.Resource) FTPUtils(com.cas.sim.tis.util.FTPUtils) ResourceAction(com.cas.sim.tis.action.ResourceAction)

Example 13 with Resource

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;
}
Also used : PageInfo(com.github.pagehelper.PageInfo) ResourceMapper(com.cas.sim.tis.mapper.ResourceMapper) Resource(com.cas.sim.tis.entity.Resource)

Example 14 with Resource

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;
}
Also used : PageInfo(com.github.pagehelper.PageInfo) ResourceMapper(com.cas.sim.tis.mapper.ResourceMapper) Resource(com.cas.sim.tis.entity.Resource)

Example 15 with Resource

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;
}
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)

Aggregations

Resource (com.cas.sim.tis.entity.Resource)15 ResourceAction (com.cas.sim.tis.action.ResourceAction)6 JSONArray (com.alibaba.fastjson.JSONArray)4 PageInfo (com.github.pagehelper.PageInfo)4 FTPUtils (com.cas.sim.tis.util.FTPUtils)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Button (javafx.scene.control.Button)3 ResourceMapper (com.cas.sim.tis.mapper.ResourceMapper)2 ResourceViewer (com.cas.sim.tis.view.control.imp.ResourceViewer)2 PageController (com.cas.sim.tis.view.controller.PageController)2 FXML (javafx.fxml.FXML)2 PreparationResourceAction (com.cas.sim.tis.action.PreparationResourceAction)1 ResourceConsts (com.cas.sim.tis.consts.ResourceConsts)1 ResourceType (com.cas.sim.tis.consts.ResourceType)1 PreparationResource (com.cas.sim.tis.entity.PreparationResource)1 TypicalCase (com.cas.sim.tis.entity.TypicalCase)1 ResourceService (com.cas.sim.tis.services.ResourceService)1 SVGGlyph (com.cas.sim.tis.svg.SVGGlyph)1 AlertUtil (com.cas.sim.tis.util.AlertUtil)1