| | |
| | | } |
| | | |
| | | BaseEntity be = (BaseEntity) obj; |
| | | rows += insertXlsAnnex(ue, be, files, file); |
| | | rows += insertXlsAnnex(ue, meta, be, file); |
| | | files.remove(file); |
| | | } |
| | | |
| | | return rows; |
| | |
| | | /** |
| | | * 插入Excel附件 |
| | | */ |
| | | private int insertXlsAnnex(UserEntity ue, BaseEntity be, List<String> files, String file) { |
| | | private int insertXlsAnnex(UserEntity ue, MetaEntity meta, BaseEntity be, String file) { |
| | | File f = new File(file); |
| | | if (!f.exists() || f.isDirectory()) { |
| | | return 0; |
| | | } |
| | | |
| | | String md5 = FileHelper.getFileMd5(file); |
| | | AttachEntity old = attachService.selectByTabAndGuid(meta.getTab(), be.getEventid(), md5); |
| | | if (null != old) { |
| | | f.delete(); |
| | | return 0; |
| | | } |
| | | |
| | | files.remove(file); |
| | | String fileName = FileHelper.getFileName(file); |
| | | double sizes = FileHelper.sizeToMb(f.length()); |
| | | |
| | | return 1; |
| | | 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); |
| | | |
| | | return rows > 0 ? 1 : 0; |
| | | } |
| | | |
| | | private AttachEntity getAttachEntity(UserEntity ue, String file) { |
| | | /** |
| | | * 获取附件实体类 |
| | | */ |
| | | protected AttachEntity getAttachEntity(UserEntity ue, String tabName, String eventid, String fileName, String md5, double sizes) { |
| | | AttachEntity entity = new AttachEntity(); |
| | | // entity.setTab(tabName); |
| | | // entity.setTabGuid(eventid); |
| | | // entity.setName(fileName); |
| | | // entity.setGuid(md5); |
| | | // String subPath = PathHelper.getUploadPath() + File.separator + md5+ FileHelper.getExtension(fileName); |
| | | // entity.setPath(subPath); |
| | | // entity.setSizes(sizes); |
| | | // if (ue != null) { |
| | | // entity.setCreateUser(ue.getId()); |
| | | // } |
| | | entity.setTab(tabName); |
| | | entity.setTabGuid(eventid); |
| | | entity.setName(fileName); |
| | | entity.setGuid(md5); |
| | | String subPath = PathHelper.getUploadPath() + File.separator + md5 + FileHelper.getExtension(fileName); |
| | | entity.setPath(subPath); |
| | | entity.setSizes(sizes); |
| | | if (ue != null) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | |
| | | return entity; |
| | | } |