From 73c8452a479ea83d4e9d28a7c66c019d9955d194 Mon Sep 17 00:00:00 2001
From: xinyb <574600396@qq.com>
Date: 星期日, 29 九月 2024 15:28:51 +0800
Subject: [PATCH] CRM邮箱删除和待处理功能

---
 src/com/yc/crm/mail/service/MailFileImpl.java |  102 ++++++++++++++++++++++++++-------------------------
 1 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/src/com/yc/crm/mail/service/MailFileImpl.java b/src/com/yc/crm/mail/service/MailFileImpl.java
index 1a4e122..46beb3e 100644
--- a/src/com/yc/crm/mail/service/MailFileImpl.java
+++ b/src/com/yc/crm/mail/service/MailFileImpl.java
@@ -44,9 +44,10 @@
  */
 @Service("MailFileImpl")
 public class MailFileImpl extends BaseService implements MailFileIfc {
-    private final ShoppingImageEntity shoppingImage =  new ShoppingImageEntity() ;
+    private final ShoppingImageEntity shoppingImage = new ShoppingImageEntity();
     @Autowired
     private DefaultLobHandler defaultLobHandler;
+
     @Override
     public void saveAttachment(List<MailFileEntity> mailFile) {
         try {
@@ -90,6 +91,7 @@
             attachment.setUnid(unId);
             attachment.setFileType(list.get(i).get("FileType") == null ? null : (String) list.get(i).get("FileType"));
             attachment.setFileSize(list.get(i).get("FileSize") == null ? 0 : (Long) list.get(i).get("FileSize"));
+            attachment.setSeq(list.get(i).get("seq") == null ? 0 : (Integer) list.get(i).get("seq"));
             attachment.setPhysicalFile(list.get(i).get("PhysicalFile") == null ? null : (String) list.get(i).get("PhysicalFile"));
             attachment.setOriginalFileName(list.get(i).get("OriginalFileName") == null ? null : (String) list.get(i).get("OriginalFileName"));
             attachment.setOriginalPicture(list.get(i).get("OriginalPicture") == null ? null : (byte[]) list.get(i).get("OriginalPicture"));  //闄勪欢澶勭悊
@@ -97,7 +99,6 @@
         }
         return attachmentList;
     }
-
 
 
     @Transactional(rollbackFor = Exception.class)
@@ -128,32 +129,32 @@
             width = null;
             height = null;
         }
-        ShoppingImageEntity shoppingImageEntity = null ;
+        ShoppingImageEntity shoppingImageEntity = null;
         DataSourceEntity dataSourceEntity = null;
         try {
-            dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
+            dataSourceEntity = MultiDataSource.getDataSourceMap(request);
             if (dataSourceEntity == null) {
-                throw new Exception("娌℃湁鎵惧埌鏁版嵁婧愶紝鑾峰彇鍥剧墖鏂囦欢澶辫触!" ) ;
+                throw new Exception("娌℃湁鎵惧埌鏁版嵁婧愶紝鑾峰彇鍥剧墖鏂囦欢澶辫触!");
             }
 
             String rootPath = session.getServletContext().getRealPath("/");
             //String uuid = UUID.randomUUID().toString().toUpperCase();
 
-            shoppingImageEntity = getImage( unid,rootPath ,dataSourceEntity.getDbId(),attachmentPath,formidPath);
+            shoppingImageEntity = getImage(unid, rootPath, dataSourceEntity.getDbId(), attachmentPath, formidPath);
 
             if (shoppingImageEntity == null || shoppingImageEntity.getImage() == null) {
                 return null;
             }
 
             //鍙栧師鍥捐矾寰�
-            String shoppingImageFileName = SettingKey.getShoppingImageFileName(rootPath,unid, width,height, isShowOrgImage, dataSourceEntity.getDbId()+"", shoppingImageEntity.getFileType(),attachmentPath,formidPath);
+            String shoppingImageFileName = SettingKey.getShoppingImageFileName(rootPath, unid, width, height, isShowOrgImage, dataSourceEntity.getDbId() + "", shoppingImageEntity.getFileType(), attachmentPath, formidPath);
             File file = shoppingImageEntity.getImage();
 
             if (file != null) {
 
-                if (width != null && height != null && shoppingImageEntity.getFileType()!=null
+                if (width != null && height != null && shoppingImageEntity.getFileType() != null
                         //鍥剧墖鏂囦欢鎵嶇缉鏀撅紝鍚﹀垯浼氭姤閿�
-                        && StringUtils.containsAny(shoppingImageEntity.getFileType().toLowerCase(),"jpg","png","gif","jpeg","tiff","bmp","raw","tga","fpx","webp")) {
+                        && StringUtils.containsAny(shoppingImageEntity.getFileType().toLowerCase(), "jpg", "png", "gif", "jpeg", "tiff", "bmp", "raw", "tga", "fpx", "webp")) {
                     // 缂╂斁鍥剧墖
                     ImageUtils.scale(file.getPath(), shoppingImageFileName, width, height);
                 } else {
@@ -166,10 +167,10 @@
                 return image;
             }
         } catch (IOException e) {
-            System.out.println("杈撳嚭缂╃暐鍥炬椂鍑洪敊,鍑洪敊鏂囦欢鍚嶏細" + (shoppingImageEntity!=null?shoppingImageEntity.getPhysicalFile():"") +  (dataSourceEntity!=null?"dbid:["+dataSourceEntity.getDbId() + "],绯荤粺鍚嶇О锛歔"+ dataSourceEntity.getSystemDescribe()+"]":"") );
+            System.out.println("杈撳嚭缂╃暐鍥炬椂鍑洪敊,鍑洪敊鏂囦欢鍚嶏細" + (shoppingImageEntity != null ? shoppingImageEntity.getPhysicalFile() : "") + (dataSourceEntity != null ? "dbid:[" + dataSourceEntity.getDbId() + "],绯荤粺鍚嶇О锛歔" + dataSourceEntity.getSystemDescribe() + "]" : ""));
             throw e;
-        }catch (Exception e) {
-            throw e ;
+        } catch (Exception e) {
+            throw e;
         } finally {
             //if (width != null && height != null && file != null && file.exists())
             //	file.delete();
@@ -178,18 +179,18 @@
     }
 
     private ShoppingImageEntity getImage(String unids, String rootPath, int dbId, String attachmentPath, String formidPath) {
-        if  (unids == null || "".equals(unids))  return null ;
-        String unid = "" ,mailSeq = "" ;
-        String unidStr[] = unids.split(SettingKey.NAVSPLIT) ;   //
-        unid = unidStr[0] ;
-        if (unidStr.length > 1 ) {
-            String seqs[] = unidStr[1].split(";") ;
-            mailSeq = seqs[seqs.length-1];   //鍙彇鏈�鍚庝竴涓� seq , 鍥犱负鏈夋椂鍊欎紶杩囨潵鐨勫�兼槸:  7394;7382 ,濡傛灉涓嶅鐞嗕細瀵艰嚧璇硶閿欒
+        if (unids == null || "".equals(unids)) return null;
+        String unid = "", mailSeq = "";
+        String unidStr[] = unids.split(SettingKey.NAVSPLIT);   //
+        unid = unidStr[0];
+        if (unidStr.length > 1) {
+            String seqs[] = unidStr[1].split(";");
+            mailSeq = seqs[seqs.length - 1];   //鍙彇鏈�鍚庝竴涓� seq , 鍥犱负鏈夋椂鍊欎紶杩囨潵鐨勫�兼槸:  7394;7382 ,濡傛灉涓嶅鐞嗕細瀵艰嚧璇硶閿欒
         }
 
         String sql = " set nocount on ; \n"
                 + " declare @myrowcount int,@myerror int \n"
-                + " declare @unid varchar(50) = "+ GridUtils.prossSqlParm(unid)+" \n"
+                + " declare @unid varchar(50) = " + GridUtils.prossSqlParm(unid) + " \n"
                 + " declare @FormId int,@DocCode varchar(50),@FieldId varchar(50),@RowId varchar(50) \n"
                 + " declare @OriginalFileName varchar(200),@PhysicalFile varchar(50),@FileType varchar(50),@FileSize bigint \n"
                 + " declare @AuthorCode varchar(50),@AuthorName varchar(50),@OriginalPicture varbinary(max) \n"
@@ -198,9 +199,9 @@
                 + "    @OriginalFileName = a.OriginalFileName ,@PhysicalFile = a.PhysicalFile,@FileType = a.FileType,\n"
                 + "    @FileSize = isnull(a.FileSize,0),@AuthorCode = a.AuthorCode,@AuthorName = a.AuthorName,\n"
                 + "    @OriginalPicture = a.OriginalPicture \n"
-                + " from " + (formidPath!=null&&"9747".equals(formidPath)?"_sys_AttachmentLog":"_sys_Attachment9") + " a \n"
+                + " from " + (formidPath != null && "9747".equals(formidPath) ? "_sys_AttachmentLog" : "_sys_Attachment9") + " a \n"
                 + " where a.UNID = @unid  \n"
-                + (mailSeq !=null && !"".equals(mailSeq)?" and a.fieldid = '" + mailSeq + "' \n":"")
+                + (mailSeq != null && !"".equals(mailSeq) ? " and a.fieldid = '" + mailSeq + "' \n" : "")
                 + " select @myrowcount  = @@rowcount,@myerror = @@error \n"
 
                 + " if isnull(@myrowcount,0) = 0 \n"
@@ -209,16 +210,16 @@
                 + "       @OriginalFileName = a.OriginalFileName ,@PhysicalFile = a.PhysicalFile,@FileType = a.FileType,\n"
                 + "       @FileSize = isnull(a.FileSize,0),@AuthorCode = a.AuthorCode,@AuthorName = a.AuthorName,\n"
                 + "       @OriginalPicture = a.OriginalPicture \n"
-                + "    from "+ (formidPath!=null&&"9747".equals(formidPath)?"_sys_AttachmentLog":"_sys_Attachment") +" a \n"
+                + "    from " + (formidPath != null && "9747".equals(formidPath) ? "_sys_AttachmentLog" : "_sys_Attachment") + " a \n"
                 + "    where a.UNID = @unid  \n"
-                + (mailSeq !=null && !"".equals(mailSeq)?"    and a.fieldid = '" + mailSeq + "' \n":"")
+                + (mailSeq != null && !"".equals(mailSeq) ? "    and a.fieldid = '" + mailSeq + "' \n" : "")
                 + " end \n "
                 + " select @FormId as FormId,@DocCode as DocCode,@FieldId as FieldId,@RowId as RowId, \n" +
                 "	   @OriginalFileName as OriginalFileName ,@PhysicalFile as PhysicalFile,@FileType as FileType,\n" +
                 "	   isnull(@FileSize,0) as FileSize,@AuthorCode as AuthorCode,@AuthorName as AuthorName,\n" +
                 "	   @OriginalPicture as OriginalPicture \n";
         try {
-            this.jdbcTemplate.query(sql,new AbstractLobStreamingResultSetExtractor(){
+            this.jdbcTemplate.query(sql, new AbstractLobStreamingResultSetExtractor() {
                 protected void handleNoRowFound() throws LobRetrievalFailureException {
                     System.out.println("鍦ㄦ暟鎹簱id涓猴細" + dbId + "涓紝瀵艰喘绠$悊  ShoppingImageImpl 鏈壘鍒� unid锛�" + unids + " 鐨勫浘鐗囨枃浠�(鎴栭檮浠�)!");
                     shoppingImage.setFormId(-1);
@@ -232,66 +233,67 @@
                     shoppingImage.setFileSize(0L);
                     shoppingImage.setAuthorCode("");
                     shoppingImage.setAuthorName("");
-                    shoppingImage.setImage(null) ;
+                    shoppingImage.setImage(null);
                 }
 
                 @Override
                 protected void streamData(ResultSet rs) throws SQLException, IOException, DataAccessException {
-                    shoppingImage.setFormId(rs.getString("FormId") == null?0:rs.getInt("FormId"));
-                    shoppingImage.setDocCode(rs.getString("DocCode") == null?"":rs.getString("DocCode"));
-                    shoppingImage.setFieldId(rs.getString("FieldId") == null?"":rs.getString("FieldId"));
-                    shoppingImage.setRowId(rs.getString("RowId") == null?"":rs.getString("RowId"));
+                    shoppingImage.setFormId(rs.getString("FormId") == null ? 0 : rs.getInt("FormId"));
+                    shoppingImage.setDocCode(rs.getString("DocCode") == null ? "" : rs.getString("DocCode"));
+                    shoppingImage.setFieldId(rs.getString("FieldId") == null ? "" : rs.getString("FieldId"));
+                    shoppingImage.setRowId(rs.getString("RowId") == null ? "" : rs.getString("RowId"));
 
-                    shoppingImage.setOriginalFileName(rs.getString("OriginalFileName") == null?null:rs.getString("OriginalFileName"));
-                    shoppingImage.setPhysicalFile(rs.getString("PhysicalFile") == null?null:rs.getString("PhysicalFile"));
-                    shoppingImage.setFileType(rs.getString("FileType") == null?null:rs.getString("FileType"));
+                    shoppingImage.setOriginalFileName(rs.getString("OriginalFileName") == null ? null : rs.getString("OriginalFileName"));
+                    shoppingImage.setPhysicalFile(rs.getString("PhysicalFile") == null ? null : rs.getString("PhysicalFile"));
+                    shoppingImage.setFileType(rs.getString("FileType") == null ? null : rs.getString("FileType"));
                     shoppingImage.setFileSize(rs.getLong("FileSize"));
-                    shoppingImage.setAuthorCode(rs.getString("AuthorCode") == null?null:rs.getString("AuthorName"));
-                    shoppingImage.setAuthorName(rs.getString("AuthorName") == null?null:rs.getString("AuthorName"));
+                    shoppingImage.setAuthorCode(rs.getString("AuthorCode") == null ? null : rs.getString("AuthorName"));
+                    shoppingImage.setAuthorName(rs.getString("AuthorName") == null ? null : rs.getString("AuthorName"));
 
 
                     //鍙栧師鍥捐矾寰�
-                    String shoppingImageFileName = SettingKey.getShoppingImageFileName(rootPath,unids, null, null, true, dbId+"", shoppingImage.getFileType(),attachmentPath,formidPath);
-                    InputStream is = null ;
-                    byte[] bytes = null ;
+                    String shoppingImageFileName = SettingKey.getShoppingImageFileName(rootPath, unids, null, null, true, dbId + "", shoppingImage.getFileType(), attachmentPath, formidPath);
+                    InputStream is = null;
+                    byte[] bytes = null;
                     try {
                         is = defaultLobHandler.getBlobAsBinaryStream(rs, "OriginalPicture");
                         if (is != null) {
-                            bytes = ShoppingImageEntity.InputStreamToByte( is); //鍙栦簩杩涘埗鍥剧墖
+                            bytes = ShoppingImageEntity.InputStreamToByte(is); //鍙栦簩杩涘埗鍥剧墖
 
-                            File file = BlobToFile.writeBytesToFile(bytes,shoppingImageFileName);  //
+                            File file = BlobToFile.writeBytesToFile(bytes, shoppingImageFileName);  //
                             if (file != null) {
                                 shoppingImage.setImage(file);
                             }
                         }
                     } catch (IOException e) {
                         e.printStackTrace();
-                        throw e ;
+                        throw e;
                     } finally {
-                        bytes = null ;
+                        bytes = null;
                         if (is != null) is.close();
                     }
 
                 }   // end function
             });
 
-            return shoppingImage ;
+            return shoppingImage;
 
-        }catch(DataAccessException e ) {
-            if (e instanceof EmptyResultDataAccessException){
-                return null ;
-            }else {
-                System.out.println("dbid:" + dbId + ",error:" + (e.getCause() != null ?e.getCause().getMessage():e.getMessage())) ;
+        } catch (DataAccessException e) {
+            if (e instanceof EmptyResultDataAccessException) {
+                return null;
+            } else {
+                System.out.println("dbid:" + dbId + ",error:" + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
                 e.printStackTrace();
                 throw e;
             }
-        }catch(Exception e){
-            System.out.println("dbid:" + dbId + ",error:" + (e.getCause() != null ?e.getCause().getMessage():e.getMessage())) ;
+        } catch (Exception e) {
+            System.out.println("dbid:" + dbId + ",error:" + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
             e.printStackTrace();
             throw e;
         }
 
     }
+
     /**
      * 鍒ゆ柇鏄惁涓烘暟瀛�
      *

--
Gitblit v1.8.0