| | |
| | | import net.lingala.zip4j.ZipFile; |
| | | import net.lingala.zip4j.model.FileHeader; |
| | | import net.lingala.zip4j.model.ZipParameters; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | private static String tabs = "''"; |
| | | |
| | | private final static Map<String, String> ATTACH_TABS = new HashMap<>(); |
| | | public final static Map<String, String> ATTACH_TABS = new HashMap<>(); |
| | | |
| | | private final static Log log = LogFactory.getLog(UploadAttachService.class); |
| | | |
| | |
| | | |
| | | int rows = 0; |
| | | for (Object obj : list) { |
| | | String name = getAnnexName(obj, field); |
| | | if (StringHelper.isEmpty(name)) { |
| | | String[] names = getNames(getAnnexName(obj, field)); |
| | | if (null == names || names.length == 0) { |
| | | continue; |
| | | } |
| | | |
| | | String file = findAnnexFile(name, folder, files); |
| | | if (null == file) { |
| | | continue; |
| | | } |
| | | for (String name : names) { |
| | | String file = findAnnexFile(name, folder, files); |
| | | if (null == file) { |
| | | continue; |
| | | } |
| | | |
| | | BaseEntity be = (BaseEntity) obj; |
| | | rows += insertXlsAnnex(ue, meta, be, file); |
| | | files.remove(file); |
| | | rows += insertXlsAnnex(ue, meta, (BaseEntity) obj, file); |
| | | } |
| | | } |
| | | |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 获取名称 |
| | | */ |
| | | private String[] getNames(String str) { |
| | | if (StringHelper.isEmpty(str)) { |
| | | return null; |
| | | } |
| | | |
| | | return str.replace(";", ",").replace(",", ",").split(","); |
| | | } |
| | | |
| | | /** |
| | |
| | | String md5 = FileHelper.getFileMd5(file); |
| | | AttachEntity old = attachService.selectByTabAndGuid(meta.getTab(), be.getEventid(), md5); |
| | | if (null != old) { |
| | | f.delete(); |
| | | return 0; |
| | | } |
| | | |
| | |
| | | AttachEntity ae = getAttachEntity(ue, meta.getTab(), be.getEventid(), fileName, md5, sizes); |
| | | String targetPath = pathHelper.getConfig().getUploadPath() + File.separator + ae.getPath(); |
| | | |
| | | f.renameTo(new File(targetPath)); |
| | | int rows = attachService.insert(ae); |
| | | try { |
| | | FileUtils.copyFile(f, new File(targetPath)); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return rows > 0 ? 1 : 0; |
| | | return attachService.insert(ae); |
| | | } |
| | | |
| | | /** |