| | |
| | | package com.lf.server.service.data; |
| | | |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.FileHelper; |
| | | import com.lf.server.helper.PathHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | |
| | | /** |
| | | * 上传文件 |
| | | */ |
| | | public <T> List<MetaFileEntity> uploadData(T t, UserEntity ue, HttpServletRequest request, HttpServletResponse res) throws Exception { |
| | | StandardMultipartHttpServletRequest req = (StandardMultipartHttpServletRequest) request; |
| | | public <T> List<MetaFileEntity> uploadData(T t, String path, HttpServletRequest req, HttpServletResponse res) throws Exception { |
| | | StandardMultipartHttpServletRequest request = (StandardMultipartHttpServletRequest) req; |
| | | req.setCharacterEncoding("utf-8"); |
| | | res.setContentType("application/json;charset=utf-8"); |
| | | |
| | | if (t != null) { |
| | | setEntity(t, req); |
| | | setEntity(t, request); |
| | | } |
| | | List<MetaFileEntity> list = getFiles(ue, req); |
| | | List<MetaFileEntity> list = getFiles(path,request); |
| | | |
| | | return list; |
| | | } |
| | |
| | | /** |
| | | * 获取文件 |
| | | */ |
| | | private List<MetaFileEntity> getFiles(UserEntity ue, StandardMultipartHttpServletRequest req) throws Exception { |
| | | private List<MetaFileEntity> getFiles(String subPath,StandardMultipartHttpServletRequest req) throws Exception { |
| | | List<MetaFileEntity> list = new ArrayList<MetaFileEntity>(); |
| | | |
| | | String path = pathHelper.getTempPath(ue.getId()); |
| | | String path = pathHelper.getTempPath(subPath); |
| | | Iterator<String> iterator = req.getFileNames(); |
| | | while (iterator.hasNext()) { |
| | | MultipartFile file = req.getFile(iterator.next()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 自理实体集合 |
| | | */ |
| | | public void dealEntities(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity entity : list) { |
| | | entity.setPath(FileHelper.getRelativePath(entity.getPath())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除文件 |
| | | * @param list 实体集合 |
| | | * @return |
| | | */ |
| | | public Integer deleteFiles(List<MetaFileEntity> list){ |
| | | String root=pathHelper.getConfig().getTempPath(); |
| | | |
| | | int count = 0; |
| | | for (MetaFileEntity entity : list) { |
| | | if (!StringHelper.isEmpty(entity.getPath())){ |
| | | String file=root+File.separator+entity.getPath(); |
| | | |
| | | File f=new File(file); |
| | | if (f.exists()){ |
| | | f.delete(); |
| | | count++; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return count; |
| | | } |
| | | |
| | | /** |
| | | * 获取参数 |
| | | * Enumeration<String> headers = req.getHeaderNames(); |
| | | * Enumeration<String> attributes = req.getAttributeNames(); |