From fab35da3e1218a329e4acbe71e8d333c1dcbcadd Mon Sep 17 00:00:00 2001
From: qwj <qwjzorro@163.com>
Date: 星期一, 21 八月 2023 09:25:47 +0800
Subject: [PATCH] 资质管理

---
 DocumentServiceAPI.Application/DocManage/DocumentManageAppService.cs |  205 ++++++++++++++++++++++++++++----------------------
 1 files changed, 115 insertions(+), 90 deletions(-)

diff --git a/DocumentServiceAPI.Application/DocManage/DocumentManageAppService.cs b/DocumentServiceAPI.Application/DocManage/DocumentManageAppService.cs
index fd87b88..0365c1d 100644
--- a/DocumentServiceAPI.Application/DocManage/DocumentManageAppService.cs
+++ b/DocumentServiceAPI.Application/DocManage/DocumentManageAppService.cs
@@ -3,6 +3,7 @@
 using DocumentServiceAPI.Application.System.Services;
 using DocumentServiceAPI.Model.cyDocumentModel;
 using DocumentServiceAPI.Utility;
+using Microsoft.AspNetCore.Mvc.RazorPages;
 using System.Linq.Expressions;
 
 namespace DocumentServiceAPI.Application.DocManage
@@ -16,8 +17,6 @@
         private readonly DocumentManageService _docManageService;
         private readonly OrganizationService _organizationService;
         private readonly FileManageService _fileManageService;
-
-
 
         public DocumentManageAppService(DocClassificationService classService, DocumentManageService docService, OrganizationService orgService,FileManageService fileManageService)
         {
@@ -35,7 +34,17 @@
         public async Task<bool> CheckNameDuplicate(Document_Submit_Dto model)
         {
             var msg = false;
-            var ck =await _docManageService.GetFirstAsync(c=>c.doc_name==model.name && c.doc_code==model.code && c.classification_id==model.class_id && c.id!=model.id);
+            Expression<Func<Doc_Info, bool>> expression = t => true;
+            expression = expression.And(c => c.tenant_code == model.tenant_id && c.doc_name == model.name && c.doc_code == model.code );
+            if (model.class_id.HasValue && model.class_id!=0)
+            {
+                expression = expression.And(t => t.classification_id == model.class_id);
+            }
+            if (model.id > 0)
+            {
+                expression = expression.And(t => t.id != model.id);
+            }
+            var ck =await _docManageService.GetFirstAsync(expression);
             if (ck != null)
             {
                 msg = true;
@@ -56,7 +65,7 @@
             {
                 Expression<Func<Doc_Info, bool>> expression = t => true;
 
-                expression = expression.And(t => t.doc_code == page.Code && t.is_del==false);
+                expression = expression.And(t =>t.tenant_code==page.TenantID && t.doc_code == page.Code && t.is_del==false);
                 if (page.ClassCode.HasValue)
                 {
                     expression = expression.And(t => t.classification_id == page.ClassCode);
@@ -90,7 +99,7 @@
                         doc_name = c.doc_name,
                         id = c.id,
                         org_id = c.org_id,
-                        org_name = c.DocOrganization.UnitName,
+                        org_name = c.DocOrganization?.UnitName,
                         project_id = c.project_id,
                         project_name = "",
                         status = c.status
@@ -107,6 +116,24 @@
             }
             
             return new JsonResult(result);
+        }
+
+        /// <summary>
+        /// 鏍规嵁鏂囨。鍙锋煡璇�
+        /// </summary>
+        /// <param name="search"></param>
+        /// <returns></returns>
+        public async Task<IActionResult> PostDocumentInfo(DocumentSearch search)
+        {
+            var data = await _docManageService.GetFirstAsync(c => c.is_del == false && c.id == search.ID && c.tenant_code==search.TenantID);
+            if (data != null)
+            {
+                var list = await _fileManageService.GetListAsync(c =>c.status==1 && c.doc_id == search.ID);
+                Document_Info_Dto info = new Document_Info_Dto(data, list.Select(c => new FileInfo_List_Dto(c)).OrderBy(c => c.sort).ToList());
+                return new JsonResult(info);
+            }
+
+            return null;
         }
 
         /// <summary>
@@ -131,9 +158,9 @@
             var id =await _docManageService.InsertReturnIdentityAsync(doc);
             if (id > 0)
             {
-                if(info.files!=null&& info.files.Count > 0)
+                if(info.newfiles!=null&& info.newfiles.Count > 0)
                 {
-                    foreach (var item in info.files)
+                    foreach (var item in info.newfiles)
                     {
                         File_Info file = new File_Info();
                         file.doc_id = id;                        
@@ -148,6 +175,7 @@
                         file.uptime = DateTime.Now;
                         file.up_userid = item.up_userid;
                         file.up_username = item.up_username;
+                        file.sort = item.sort;
                         await _fileManageService.InsertAsync(file);
                     }
                 }
@@ -156,45 +184,90 @@
             return msg;
         }
 
-
-
-
-
-        /// <summary>
-        /// 鏍规嵁绫诲瀷鏌ヨ鏁版嵁
-        /// </summary>
-        /// <param name="page"></param>
-        /// <returns></returns>
-        public async Task<IActionResult> PostItemList(DocClassificationSearch page)
-        {
-            var data = await _classificationService.GetListAsync(c => c.status == 1 && c.parent_code == page.Code);
-            return new JsonResult(data);
-        }
-
-
         /// <summary>
         /// 淇敼鏁版嵁
         /// </summary>
         /// <param name="info"></param>
         /// <returns></returns>
-        public async Task<IActionResult> PostEdtInfo(Classification_Submit_Dto info)
+        public async Task<bool> PostEdtDocumentInfo(Document_Submit_Dto info)
         {
-            var msg = false;
-            var model = await _classificationService.GetByIdAsync(info.id);
-            if (model != null)
-            {
-                model.add_time = DateTime.Now;
-                model.doc_classification = info.name;
-                model.status = info.status;
+            bool msg = false;
 
-                msg = await _classificationService.UpdateAsync(model);
+            var doc= _docManageService.GetById(info.id);
+            if (info.tenant_id == doc.tenant_code && doc.is_del==false)
+            {
+                doc.add_time = DateTime.Now;
+                doc.classification_id = info.class_id;                
+                doc.doc_name = info.name;
+                doc.org_id = info.org_id;
+                doc.status = info.status;
+
+                if (await _docManageService.UpdateAsync(doc))
+                {
+                    //鏂版彁浜ょ殑鏂囦欢
+                    if (info.newfiles != null && info.newfiles.Count > 0)
+                    {
+                        foreach (var item in info.newfiles)
+                        {
+                            File_Info file = new File_Info();
+                            file.doc_id = doc.id;
+                            file.filenewname = item.filenewname.Length > 40 ? item.filenewname.Substring(item.filenewname.Length - 40) : item.filenewname;
+                            file.fileoldname = item.fileoldname.Length > 40 ? item.fileoldname.Substring(item.fileoldname.Length - 40) : item.fileoldname;
+                            file.filepath = item.filepath;
+                            file.fileservername = item.fileservername;
+                            file.filesize = item.filesize;
+                            file.filetype = item.filetype;
+                            file.status = 1;
+                            file.suffix = item.suffix;
+                            file.uptime = DateTime.Now;
+                            file.up_userid = item.up_userid;
+                            file.up_username = item.up_username;
+                            file.sort = item.sort;
+                            await _fileManageService.InsertAsync(file);
+                        }
+                    }
+
+                    //淇敼璧勬簮鍚嶇О鐨勬枃浠�
+                    if (info.editfiles != null && info.editfiles.Count > 0)
+                    {
+                        foreach (var item in info.editfiles)
+                        {
+                            var file= _fileManageService.GetById(item.id);
+                            if (file != null && file.doc_id==doc.id)
+                            {
+                                file.fileoldname = file.filenewname;
+                                file.filenewname = item.filenewname.Length > 40 ? item.filenewname.Substring(item.filenewname.Length - 40) : item.filenewname;                                
+                                file.uptime = DateTime.Now;
+                                file.sort = item.sort;
+                                await _fileManageService.UpdateAsync(file);
+                            }                            
+                        }
+                    }
+
+                    //鍒犻櫎璧勬簮
+                    if (info.delfiles != null && info.delfiles.Count > 0)
+                    {
+                        foreach (var item in info.delfiles)
+                        {
+                            var file = _fileManageService.GetById(item);
+                            if (file != null && file.doc_id == doc.id)
+                            {
+                                file.status = 0;
+                                file.uptime = DateTime.Now;
+                                await _fileManageService.UpdateAsync(file);
+                            }                            
+                        }
+                    }
+
+                    msg = true;
+                }
             }
             
-            return new JsonResult(msg);
+            return msg;
         }
 
         /// <summary>
-        /// 鍒犻櫎鏁版嵁
+        /// 鍒犻櫎鏂囨。鏁版嵁
         /// </summary>
         /// <param name="doc"></param>
         /// <returns></returns>
@@ -214,69 +287,21 @@
             return new JsonResult(msg);
         }
 
-
+        #region 鏂囨。鐨勬枃浠�
 
         /// <summary>
-        /// 娣诲姞鏁版嵁
+        /// 鏍规嵁鏂囨。鍙锋煡璇㈡枃浠舵暟鎹�
         /// </summary>
-        /// <param name="info"></param>
+        /// <param name="id"></param>
         /// <returns></returns>
-        public async Task<IActionResult> PostAddFilesInfo(Classification_Submit_Dto info)
+        public async Task<IActionResult> GetDocumentFilesList(int id)
         {
-            Doc_Classification doc = new Doc_Classification();
-            doc.add_time = DateTime.Now;
-            doc.doc_classification = info.name;
-            doc.doc_classification_code = "";
-            doc.is_system = false;
-            doc.parent_code = info.code;
-            doc.sort_id = 99;
-            doc.status = info.status;
-            doc.tenant_code = info.tenant_id;
+            var data = await _fileManageService.GetListAsync(c => c.status == 1 && c.doc_id == id);
+            var list = data.Select(c => new FileInfo_List_Dto(c)).OrderBy(c => c.sort).ToList();
 
-            var msg = await _classificationService.InsertAsync(doc);
-            return new JsonResult(msg);
+            return new JsonResult(list);
         }
 
-        /// <summary>
-        /// 淇敼鏁版嵁
-        /// </summary>
-        /// <param name="info"></param>
-        /// <returns></returns>
-        public async Task<IActionResult> PostEdtFileInfo(Classification_Submit_Dto info)
-        {
-            var msg = false;
-            var model = await _classificationService.GetByIdAsync(info.id);
-            if (model != null)
-            {
-                model.add_time = DateTime.Now;
-                model.doc_classification = info.name;
-                model.status = info.status;
-
-                msg = await _classificationService.UpdateAsync(model);
-            }
-
-            return new JsonResult(msg);
-        }
-
-        /// <summary>
-        /// 鍒犻櫎鏁版嵁
-        /// </summary>
-        /// <param name="doc"></param>
-        /// <returns></returns>
-        public async Task<IActionResult> PostDelFileInfo(Document_Submit_Dto doc)
-        {
-            bool msg = false;
-            //鍋囧垹闄�
-            var model = await _docManageService.GetByIdAsync(doc.id);
-            if (model != null)
-            {
-                if (model.tenant_code == doc.tenant_id && !model.is_del)
-                {
-                    model.is_del = true;
-                    msg = await _docManageService.UpdateAsync(model);
-                }
-            }
-            return new JsonResult(msg);
-        }
+        #endregion
     }
 }

--
Gitblit v1.9.1