| | |
| | | package com.lf.server.service.all; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.lf.server.controller.all.BaseController; |
| | | import com.lf.server.entity.all.*; |
| | |
| | | private final static Map<String, String> ATTACH_TABS = new HashMap<>(); |
| | | |
| | | private final static Log log = LogFactory.getLog(UploadAttachService.class); |
| | | |
| | | private static final String NO_FILE = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.NOT_FOUND, "文件找不到")); |
| | | |
| | | /** |
| | | * 获取表名 |
| | |
| | | * 下载文件 |
| | | */ |
| | | public void download(String guid, HttpServletResponse res) { |
| | | download(guid, res); |
| | | download(guid, false, res); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void download(String guid, boolean inline, HttpServletResponse res) { |
| | | try { |
| | | if (StringHelper.isEmpty(guid)) { |
| | | WebHelper.writeStr2Page(res, NO_FILE); |
| | | WebHelper.writeStr2Page(res, StaticData.NO_FILE); |
| | | return; |
| | | } |
| | | |
| | | AttachEntity entity = attachService.selectByGuid(guid); |
| | | if (entity == null) { |
| | | WebHelper.writeStr2Page(res, NO_FILE); |
| | | WebHelper.writeStr2Page(res, StaticData.NO_FILE); |
| | | return; |
| | | } |
| | | |
| | | String filePath = pathHelper.getConfig().getUploadPath() + File.separator + entity.getPath(); |
| | | File file = new File(filePath); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | String msg = JSON.toJSONString(new ResponseMsg<>(HttpStatus.ERROR, "文件不存在")); |
| | | WebHelper.writeStr2Page(res, msg); |
| | | WebHelper.writeJson2Page(res, "文件不存在"); |
| | | } |
| | | |
| | | WebHelper.download(filePath, entity.getName(), inline, res); |
| | | } catch (Exception ex) { |
| | | try { |
| | | String msg = JSON.toJSONString(new ResponseMsg<>(HttpStatus.ERROR, "文件下载出错")); |
| | | WebHelper.writeStr2Page(res, msg); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | WebHelper.writeJson2Page(res, "文件下载出错"); |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | /** |
| | | * 请求下载 |
| | | */ |
| | | public String downloadReqForGuids(UserEntity ue, String[] guids) { |
| | | List<AttachEntity> list = attachService.selectByGuids(guids); |
| | | |
| | | return downloadReq(ue, list); |
| | | } |
| | | |
| | | /** |
| | | * 请求下载 |
| | | */ |
| | | public String downloadReqForTabGuids(UserEntity ue, String tab, String[] guids) { |
| | | List<AttachEntity> list = attachService.selectByTabGuids(tab, guids); |
| | | |
| | | return downloadReq(ue, list); |
| | | } |
| | | |
| | | /** |
| | | * 请求下载 |
| | | */ |
| | | protected String downloadReq(UserEntity ue, List<AttachEntity> list) { |
| | | if (null == list || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | } |