Browse Source

签证进度拍照上传功能补充

jiangjc 1 year ago
parent
commit
e0af3bd8a7

+ 114 - 1
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -25,6 +25,7 @@ using OASystem.Domain.Dtos.CRM;
 using System.Diagnostics;
 using MathNet.Numerics.Statistics.Mcmc;
 using AlibabaCloud.OpenApiClient.Models;
+using System;
 
 namespace OASystem.API.Controllers
 {
@@ -483,6 +484,118 @@ namespace OASystem.API.Controllers
         }
 
 
+        /// <summary>
+        ///  IOS获取团组签证拍照上传进度03(相册)
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<ActionResult> PostIOSVisaProgressImageList(IOS_VisaImageListDto dto)
+        {
+            if (dto == null)
+            {
+                return Ok(JsonView(false, "请求错误:"));
+            }
+
+            List<VisaProgressImageView> list = _delegationVisaRep.GetVisaProgressImageList(dto.visaProgressCustomerId, dto.picType);
+
+            return Ok(JsonView(list));
+        }
+
+
+        /// <summary>
+        /// IOS获取团组签证拍照上传进度04(图片上传)
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<ActionResult> PostIOSVisaProgressUploadImage(IOS_VisaUploadImageDto dto)
+        {
+
+            //string result = decodeBase64ToImage(dto.base64DataURL, dto.imageName);
+
+            //if (!string.IsNullOrEmpty(result))
+            //{
+
+            //}
+            //else {
+            //    return Ok(JsonView(false, "上传失败"));
+            //}
+
+            DateTime dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
+            int sucNum = 0;
+            foreach (var item in dto.base64DataList)
+            {
+                string imageName = dto.imageName + ((DateTime.Now.Ticks - dt1970.Ticks) / 10000).ToString();
+                string result = decodeBase64ToImage(item, imageName);
+
+                if (!string.IsNullOrEmpty(result))
+                {
+                    Grp_VisaProgressCustomerPicture pic = new Grp_VisaProgressCustomerPicture();
+                    pic.CreateUserId = dto.CreateUserId;
+                    pic.PicName = imageName;
+                    pic.PicPath = result;
+                    pic.VisaProgressCustomerId = dto.visaProgressCustomerId;
+
+                    int insertResult = await _delegationVisaRep.AddAsync<Grp_VisaProgressCustomerPicture>(pic);
+                    if (insertResult > 0)
+                    {
+                        sucNum++;
+                    }
+                }
+            }
+
+            string msg = string.Format(@"成功上传{0}张", sucNum);
+
+            return Ok(JsonView(true, msg));
+        }
+
+        private string decodeBase64ToImage(string base64DataURL, string imgName)
+        {
+            string filename = "";//声明一个string类型的相对路径
+
+            String base64 = base64DataURL.Substring(base64DataURL.IndexOf(",") + 1);      //将‘,’以前的多余字符串删除
+            System.Drawing.Bitmap bitmap = null;//定义一个Bitmap对象,接收转换完成的图片
+
+            try//会有异常抛出,try,catch一下
+            {
+
+                byte[] arr = Convert.FromBase64String(base64);//将纯净资源Base64转换成等效的8位无符号整形数组
+
+                System.IO.MemoryStream ms = new System.IO.MemoryStream(arr);//转换成无法调整大小的MemoryStream对象
+                bitmap = new System.Drawing.Bitmap(ms);//将MemoryStream对象转换成Bitmap对象
+
+                var fileDir = AppSettingsHelper.Get("VisaProgressImageFtpPath");
+                //文件名称
+                filename = "VisaProgress_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + imgName + ".jpg";//所要保存的相对路径及名字
+                //上传的文件的路径
+                string filePath = "";
+                if (!Directory.Exists(fileDir))
+                {
+                    Directory.CreateDirectory(fileDir);
+                }
+                //上传的文件的路径
+                filePath = fileDir + filename;
+
+                //string url = HttpRuntime.AppDomainAppPath.ToString();
+                //string tmpRootDir = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString()); //获取程序根目录 
+                //string imagesurl2 = tmpRootDir + filename; //转换成绝对路径 
+                bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);//保存到服务器路径
+                //bitmap.Save(filePath + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
+                //bitmap.Save(filePath + ".gif", System.Drawing.Imaging.ImageFormat.Gif);
+                //bitmap.Save(filePath + ".png", System.Drawing.Imaging.ImageFormat.Png);
+                ms.Close();//关闭当前流,并释放所有与之关联的资源
+                bitmap.Dispose();
+            }
+            catch (Exception e)
+            {
+                string massage = e.Message;
+            }
+            return filename;//返回相对路径
+        }
+
+
         #endregion
 
         #region 团组任务分配
@@ -906,7 +1019,7 @@ namespace OASystem.API.Controllers
         {
             try
             {
-                
+
 
                 Result groupData = await _airTicketResRep.OpAirTicketRes(dto);
                 if (groupData.Code != 0)

+ 4 - 0
OASystem/OASystem.Api/appsettings.json

@@ -120,6 +120,10 @@
 
   "GrpFileBaseUrl": "http://132.232.92.186:24/",
   "GrpFileBasePath": "C:/Server/File/OA2023/Office/GrpFile/",
+
+  "VisaProgressImageBaseUrl": "http://132.232.92.186:24/",
+  "VisaProgressImageFtpPath": "C:/Server/File/OA2023/Image/Visa/",
+
   //节假日
   "HoliDayDataSource": [
     {

+ 17 - 2
OASystem/OASystem.Domain/Dtos/Groups/VisaDto.cs

@@ -6,13 +6,28 @@ using System.Threading.Tasks;
 
 namespace OASystem.Domain.Dtos.Groups
 {
-    public class IOS_VisaDto:DtoBase
+    public class IOS_VisaDto : DtoBase
     {
 
     }
 
-    public class IOS_VisaCustomerListDto:DtoBase
+    public class IOS_VisaCustomerListDto : DtoBase
     {
         public int diId { get; set; }
     }
+
+    public class IOS_VisaImageListDto : DtoBase {
+        public int visaProgressCustomerId { get; set; }
+        public int picType { get; set; }
+    }
+
+    public class IOS_VisaUploadImageDto : DtoBase
+    {
+        //public string base64DataURL { get; set; }
+        public List<string> base64DataList { get; set; }
+        public string imageName { get; set; }
+        public int picType { get; set; }
+        public int visaProgressCustomerId { get; set; }
+        public int CreateUserId { get; set; }
+    }
 }

+ 15 - 9
OASystem/OASystem.Domain/ViewModels/Groups/Grp_DelegationVisaView.cs

@@ -52,15 +52,17 @@ namespace OASystem.Domain.ViewModels.Groups
         {
             get
             {
-                switch (StatusSign) {
-                    case 0: statusstr= "未完成"; break;
-                    case 1: statusstr= "已完成";break;
-                    case 2: statusstr= "已忽略";break;
-                    default: statusstr= "未知";break;
+                switch (StatusSign)
+                {
+                    case 0: statusstr = "未完成"; break;
+                    case 1: statusstr = "已完成"; break;
+                    case 2: statusstr = "已忽略"; break;
+                    default: statusstr = "未知"; break;
                 }
                 return statusstr;
             }
-            set {
+            set
+            {
                 this.statusstr = value;
             }
         }
@@ -82,8 +84,6 @@ namespace OASystem.Domain.ViewModels.Groups
         }
     }
 
-    
-
     public class DelegationVisaVisitCountryView
     {
         public int CountryViewId { get; set; }
@@ -93,5 +93,11 @@ namespace OASystem.Domain.ViewModels.Groups
         public string PicPath { get; set; }
     }
 
-
+    public class VisaProgressImageView
+    {
+        public int imageId { get; set; }
+        public string url { get; set; }
+        public string path { get; set; }
+        public string picName { get; set; }
+    }
 }

+ 14 - 1
OASystem/OASystem.Infrastructure/Repositories/Groups/DelegationVisaRepository.cs

@@ -118,7 +118,7 @@ Group by PicType Order By PicType ", pro.ProgressViewId);
                         case 3: countList.DispatchCount = tempCount; break;
                         case 4: countList.VisaCount = tempCount; break;
                         case 5: countList.InvoiceCount = tempCount; break;
-                        default:break;
+                        default: break;
                     }
                 }
                 countList.totalCount();
@@ -161,5 +161,18 @@ Group by PicType Order By PicType ", pro.ProgressViewId);
             //return listVisaCustomer;
         }
 
+        public List<VisaProgressImageView> GetVisaProgressImageList(int visaProgressCustomerId, int picType)
+        {
+            string sql1 = string.Format(@" Select 
+Id as imageId,
+PicPath as 'path',
+PicName as picName
+From Grp_VisaProgressCustomerPicture
+Where VisaProgressCustomerId = {0} And PicType = {1} ", visaProgressCustomerId, picType);
+            List<VisaProgressImageView> imageList = _sqlSugar.SqlQueryable<VisaProgressImageView>(sql1).ToList();
+
+            return imageList;
+        }
+
     }
 }