ソースを参照

票据上传 CommonSaveFile -> 文件重命名验证

Lyyyi 2 日 前
コミット
f6efb12371
共有1 個のファイルを変更した56 個の追加36 個の削除を含む
  1. 56 36
      OASystem/OASystem.Api/Controllers/GroupsController.cs

+ 56 - 36
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -4492,48 +4492,48 @@ FROM
                     }
 
                     //得到签证国家下的城市
-                    string RB_City = "";
-                    string RB_County = "";
+                    string city = "";
+                    string county = "";
                     //ResidenceTime1 机票三字码信息
 
                     var atbc = GeneralMethod.GetTableByBlackCode(groupId);
 
                     if (atbc != null)
                     {
-                        string R_startTime = ""; //开始停留时间
-                        string R_endTime = "";  //离开时间
-                        string R_Three = "";   //航司 
-                        string R_ThreeCode = "";  //入境口岸
+                        string startTime = ""; //开始停留时间
+                        string endTime = "";  //离开时间
+                        string three = "";   //航司 
+                        string threeCode = "";  //入境口岸
 
                         for (int i = 0; i < atbc.Rows.Count; i++)
                         {
                             if (i == 0)   //得到抵达日期
                             {
-                                R_Three = atbc.Rows[i]["Fliagtcode"].ToString();
-                                R_startTime = atbc.Rows[i]["Day"].ToString();
-                                R_ThreeCode = atbc.Rows[i]["Three"].ToString();
+                                three = atbc.Rows[i]["Fliagtcode"].ToString();
+                                startTime = atbc.Rows[i]["Day"].ToString();
+                                threeCode = atbc.Rows[i]["Three"].ToString();
                                 continue;
                             }
                             if (i == 1)
-                                R_endTime = atbc.Rows[i]["Day"].ToString();
+                                endTime = atbc.Rows[i]["Day"].ToString();
                         }
-                        dics.Add("ResidenceTime1", R_startTime);
-                        dics.Add("ResidenceTime2", R_endTime);
-                        dics.Add("EntryTime", R_startTime);
-                        if (!string.IsNullOrEmpty(R_Three))
+                        dics.Add("ResidenceTime1", startTime);
+                        dics.Add("ResidenceTime2", endTime);
+                        dics.Add("EntryTime", startTime);
+                        if (!string.IsNullOrEmpty(three))
                         {
                             //查询航司名称
-                            var ac = _sqlSugar.Queryable<Res_AirCompany>().Where(x => x.ShortCode.equals(R_Three.Substring(0, 2))).First();
+                            var ac = _sqlSugar.Queryable<Res_AirCompany>().Where(x => x.ShortCode.equals(three.Substring(0, 2))).First();
                             if (ac != null)
                             {
-                                dics.Add("AirName", ac.EnName + " " + R_Three);   //入境口岸
+                                dics.Add("AirName", ac.EnName + " " + three);   //入境口岸
                             }
 
-                            var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three.equals(R_Three.Substring(0, 2))).First();
+                            var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three.equals(three.Substring(0, 2))).First();
                             if (tc != null)
                             {
-                                RB_County = tc.Country;
-                                RB_City = tc.City;
+                                county = tc.Country;
+                                city = tc.City;
                                 dics.Add("PortOfEntry", tc.City);   //入境口岸
                             }
                         }
@@ -4546,7 +4546,7 @@ FROM
                         //DickeyValue.Add("Destination2", dgi.VisitCountry);  //出访目的地
                     }
                     //得到当前国家下的城市酒店信息
-                    var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.DiId == groupId && x.City.contains(RB_City)).First();
+                    var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.DiId == groupId && x.City.contains(city)).First();
                     //酒店住址
                     if (hotelInfo != null)
                     {
@@ -4566,25 +4566,25 @@ FROM
 
                     var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
                         .Where(x => x.IsDel == 0 && x.DiId == groupId)
-                        .Where(x => x.Country.Contains(RB_County))
-                        .Where(x => x.Area.Contains(RB_City))
+                        .Where(x => x.Country.Contains(county))
+                        .Where(x => x.Area.Contains(city))
                         .First();
 
                     //邀请 接待单位 
                     if (oa != null)
                     {
-                        dics.Add("OA12", oa.Contact);       //接待单位联系人
-                        dics.Add("OAJob", oa.Job);          //接待联系人职务
-                        dics.Add("OATel", oa.Tel);          //接待单位电话
-                        dics.Add("OAAddress", oa.Address);  //接待单位地址
-                        dics.Add("ApplicantGuanxi", "邀请方");//和申请人关系
-                        dics.Add("OACountry", "日本");      //邀请方国家
-                        dics.Add("OADan", "同上");          // 同上
-                        dics.Add("OAJob1", "同上");         //接待联系人职务
-                        dics.Add("OATel1", "同上");         // 同上
-                        dics.Add("OAAddress1", "同上");     // 同上
-                        dics.Add("ApplicantGuanxi1", "同上"); // 同上
-                        dics.Add("OACountry1", "同上");     //邀请方国家
+                        dics.Add("OA12", oa.Contact);          //接待单位联系人
+                        dics.Add("OAJob", oa.Job);             //接待联系人职务
+                        dics.Add("OATel", oa.Tel);             //接待单位电话
+                        dics.Add("OAAddress", oa.Address);     //接待单位地址
+                        dics.Add("ApplicantGuanxi", "邀请方"); //和申请人关系
+                        dics.Add("OACountry", "日本");         //邀请方国家
+                        dics.Add("OADan", "同上");             // 同上
+                        dics.Add("OAJob1", "同上");            //接待联系人职务
+                        dics.Add("OATel1", "同上");            // 同上
+                        dics.Add("OAAddress1", "同上");        // 同上
+                        dics.Add("ApplicantGuanxi1", "同上");  // 同上
+                        dics.Add("OACountry1", "同上");       //邀请方国家
                     }
 
                     dics.Add("NowTime", DateTime.Now.ToString("yyyy/MM/dd"));  //获取当前系统时间
@@ -8111,7 +8111,27 @@ FROM
 
                 foreach (var fileStream in dto.Files)
                 {
-                    var saveFilePath = fileBase + "\\" + fileStream.FileName;
+
+                    var fileName = fileStream.FileName;
+                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
+                    string extension = Path.GetExtension(fileName);
+                    int counter = 1;
+
+                    //文件重命名验证
+                    string newFilePath;
+                    string currFileName;
+                    do
+                    {
+                        string newFileName;
+                        if (counter == 1) newFileName = $"{fileNameWithoutExtension}{extension}";
+                        else newFileName = $"{fileNameWithoutExtension} ({counter}){extension}";
+
+                        currFileName = newFileName;
+                        newFilePath = Path.Combine(fileBase, newFileName);
+                        counter++;
+                    } while (System.IO.File.Exists(newFilePath));
+
+                    var saveFilePath = fileBase + "\\" + currFileName;
 
                     var file = new Grp_GroupModelFile()
                     {
@@ -8122,7 +8142,7 @@ FROM
                         Diid = dto.Diid,
                         IsDel = 0,
                         FilePath = saveFilePath,
-                        FileName = fileStream.FileName
+                        FileName = currFileName
                     };
 
                     using (FileStream fs = System.IO.File.Create(saveFilePath))