Browse Source

成本历史数据API完善

yuanrf 9 months ago
parent
commit
c3dde41d45

+ 144 - 30
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -73,6 +73,7 @@ using OASystem.Domain.ViewModels.Statistics;
 using NPOI.XSSF.Model;
 using NetTaste;
 using Microsoft.AspNetCore.Http;
+using EyeSoft.Collections.Generic;
 
 namespace OASystem.API.Controllers
 {
@@ -5802,7 +5803,7 @@ namespace OASystem.API.Controllers
             }
             else
             {
-                jw.Msg = "城市数据空!";
+                jw.Msg = "城市数据空!";
                 jw.Data = new string[0];
             }
 
@@ -9002,46 +9003,159 @@ namespace OASystem.API.Controllers
             return Ok(jw);
         }
 
+        /// <summary>
+        /// 成本获取OP历史车费用
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
         [HttpPost]
         public async Task<IActionResult> GetHistoryCarData(HistoryCarDataDto dto)
         {
             var jw = JsonView(false);
-            List<HistoryCarDataView> view = new List<HistoryCarDataView>();
-            //获取现有所有车的数据
-            if (dto.Param.IsNullOrWhiteSpace())
+
+            try
             {
-                if (dto.Param.Contains("、")) //
+                List<HistoryCarDataView> dbResult = new List<HistoryCarDataView>();
+                //获取现有所有车的数据
+                if (!dto.Param.IsNullOrWhiteSpace())
                 {
 
+                   
+
+                    string sql = $@"
+SELECT gdi.TeamName , gctggr.Area, gctggr.PriceName  , gctggrc.Id  ,gctggrc.Price , gctggrc.DatePrice , gctggrc.PriceContent , gctggrc.Currency , gctggr.ServiceStartTime , gctggr.ServiceEndTime 
+FROM  Grp_CarTouristGuideGroundReservationsContent gctggrc inner join Grp_CarTouristGuideGroundReservations gctggr  on 
+gctggrc.CTGGRId  = gctggr.Id  inner JOIN  Grp_DelegationInfo gdi  on gctggr.DiId = gdi.Id  LEFT JOIN  Sys_SetData ssd  on ssd.Id  = gctggr.PriceType  
+WHERE gctggr.IsDel  = 0  and gctggrc.SId  = 91  AND  gdi.IsDel  = 0 AND  gctggrc.Price != 0   AND (ssd.Id in (1061,1069) or ssd.Id is NULL) AND  gctggr.ServiceStartTime is not null 
+AND  gctggr.ServiceEndTime is not NULL 
+ORDER by  gctggrc.id DESC 
+";
+
+                    dbResult = await _sqlSugar.SqlQueryable<HistoryCarDataView>(sql).ToListAsync();
+
+                    
+
+                    var numeberResult = await Task.Run(() =>
+                    {
+                        var numberArr = dbResult.Where(x => int.TryParse(x.Area, out int number)).ToList();
+                        _ = dbResult.RemoveAll(x => int.TryParse(x.Area, out int number));
+                        return numberArr;
+                    });
+
+                    var cityArr = await _sqlSugar.Queryable<Grp_NationalTravelFee>().ToListAsync();
+
+                    foreach (var item in numeberResult)
+                    {
+                        var find = cityArr.Find(x => x.Id == int.Parse(item.Area)) ?? new Grp_NationalTravelFee
+                        {
+                            Country = "数据异常!",
+                            City = string.Empty,
+                        };
+                        item.Area = find.Country + " " + find.City;
+                    }
+
+                    dbResult.AddRange(numeberResult);
+
+                    if (dto.Param.Contains("、"))
+                    {
+                        var sp = dto.Param.Split("、");
+                        dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
+                           .Where(x =>
+                           {
+                               return System.Array.Exists(sp, e =>
+                               {
+                                   bool where = false;
+                                   if (x.Area != null)
+                                   {
+                                       where = x.Area.Contains(e);
+                                       if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
+                                       {
+                                           return false;
+                                       }
+                                   }
+                                   if (x.PriceName != null && !where)
+                                   {
+                                       where = x.PriceName.Contains(e);
+                                       if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
+                                       {
+                                           return false;
+                                       }
+                                   }
+                                   return where;
+                               });
+                           }).ToList();
+                    }
+                    else
+                    {
+                        dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
+                            .Where(x =>
+                            {
+                                bool where = false;
+                                if (x.Area != null)
+                                {
+                                    where = x.Area.Contains(dto.Param);
+                                    if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
+                                    {
+                                        return false;
+                                    }
+                                }
+                                if (x.PriceName != null && !where)
+                                {
+                                    where = x.PriceName.Contains(dto.Param);
+                                    if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
+                                    {
+                                        return false;
+                                    }
+                                }
+                                return where;
+                            }
+                            )
+                            .ToList();
+                    }
                 }
-                else
-                {
-                    view = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent, Sys_SetData, Grp_DelegationInfo>((c, cc, s, d) =>
-                        cc.CTGGRId == c.Id && cc.SId == s.Id && c.DiId == d.Id
-                         ).Where((c, cc, s) => s.Id == 91 && (c.Area.Contains(dto.Param) || c.PriceName.Contains(dto.Param)) 
-                         && cc.Price != 0 && (c.Area.IndexOf("尾款") == -1))
-                         .Select((c, cc, s, d) => new HistoryCarDataView
-                         {
-                             TeamName = d.TeamName,
-                             Area = c.Area,
-                             PriceName = c.PriceName,
-                             Price = cc.Price,
-                             Start = c.ServiceStartTime,
-                             End = c.ServiceEndTime
-                         }).ToListAsync();
-
-                    view = view.Where(x =>
+
+                var view = dbResult.Select(x => {
+
+                    decimal dp = 0.00M;
+                    var startB = DateTime.TryParse(x.Start.ToString(),out DateTime startD);
+                    var endB = DateTime.TryParse(x.End.ToString(), out DateTime endD);
+                    if (string.IsNullOrWhiteSpace(x.DatePrice))
                     {
-                        var a = DateTime.TryParse(x.Start, out DateTime startTime);
-                        var b = DateTime.TryParse(x.End, out DateTime endTime);
-                        if (a && b)
+                        if (startB && endB)
                         {
-                            x.Start = startTime.ToString("yyyy-MM-dd"); 
-                            x.End = endTime.ToString("yyyy-MM-dd");
+                            var timesp = endD.Subtract(startD);
+                            if ((timesp.Days + 1) != 0 )
+                            {
+                                dp = x.Price / (timesp.Days + 1);
+                            }
+                            
                         }
-                        return a && b; 
-                    }).ToList();
-                }
+                    }
+                    else
+                    {
+                        dp = x.Price;
+                    }
+
+                    return new
+                    {
+                        start = startB ? startD.ToString("yyyy-MM-dd") : "",
+                        end = endB ? endD.ToString("yyyy-MM-dd") : "",
+                        x.Area,
+                        x.id,
+                        price = x.Price.ToString("F2"),
+                        x.PriceName,
+                        x.PriceContent,
+                        x.TeamName,
+                        x.DatePrice,
+                        dayPrice = dp.ToString("F2"),
+                    };
+                }).OrderByDescending(x=>x.id).ToList();
+
+                jw = JsonView(true, "获取成功!", view);
+            }
+            catch (Exception e)
+            {
+                jw = JsonView(false,e.Message);
             }
 
             return Ok(jw);

+ 34 - 3
OASystem/OASystem.Domain/Dtos/Groups/GroupCostSavaDto.cs

@@ -1,4 +1,5 @@
-using OASystem.Domain.Entities;
+using Google.Protobuf.WellKnownTypes;
+using OASystem.Domain.Entities;
 using OASystem.Domain.Entities.Groups;
 using System;
 using System.Collections.Generic;
@@ -1343,6 +1344,8 @@ namespace OASystem.Domain.Dtos.Groups
 
     public class HistoryCarDataView
     {
+        public int id { get; set; }
+
         public string TeamName { get; set; }
 
         public decimal Price { get; set; }
@@ -1351,9 +1354,37 @@ namespace OASystem.Domain.Dtos.Groups
 
         public string PriceName { get; set; }
 
-        public string Start { get; set; }
+        public string DatePrice { get; set; }
+
+        public string PriceContent { get; set; }
+
+        public string ServiceStartTime { get; set; }
 
-        public string End { get; set; }
+        public string ServiceEndTime { get; set; }
+
+        public DateTime? Start
+        {
+            get
+            {
+                if (DateTime.TryParse(this.ServiceStartTime, out DateTime time))
+                {
+                    return time;
+                }
+                return null;
+            }
+        }
+
+        public DateTime? End
+        {
+            get
+            {
+                if (DateTime.TryParse(this.ServiceEndTime, out DateTime time))
+                {
+                    return time;
+                }
+                return null;
+            }
+        }
     }
 
 }

+ 2 - 1
OASystem/OASystem.Infrastructure/Repositories/BaseRepository.cs

@@ -229,10 +229,11 @@ namespace OASystem.Infrastructure.Repositories
             return result > 0;
         }
 
-        public virtual async Task<bool> SoftDeleteAsync(Expression<Func<TEntity, bool>> wherexp)
+        public virtual async Task<bool> SoftDeleteAsync(Expression<Func<TEntity, bool>> wherexp, int userid)
         {
             var result = await _sqlSugar.Updateable<TEntity>().Where(wherexp).SetColumns(a => new TEntity()
             {
+                DeleteUserId = userid,
                 IsDel = 1,
                 DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
             }).ExecuteCommandAsync();

+ 3 - 3
OASystem/OASystem.Infrastructure/Repositories/Groups/CostTypeHotelNumberRepository.cs

@@ -17,9 +17,9 @@ namespace OASystem.Infrastructure.Repositories.Groups
             return Query(x=>x.Diid == diid).ToList();
         }
 
-        public async Task<bool> DeleteCostTypeHotelNumberByDiid(int diid)
+        public async Task<bool> DeleteCostTypeHotelNumberByDiid(int diid,int userid)
         {
-            return await SoftDeleteAsync(x => x.Diid == diid);
+            return await SoftDeleteAsync(x => x.Diid == diid && x.IsDel == 0,userid);
         }
 
 
@@ -29,7 +29,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
             try
             {
                 BeginTran();
-                isTrue = await DeleteCostTypeHotelNumberByDiid(diid);
+                isTrue = await DeleteCostTypeHotelNumberByDiid(diid,Userid);
                 if (List.Count > 0)
                 {
                     List.ForEach(x => { x.CreateUserId = Userid; x.CreateTime = DateTime.Now; });

+ 3 - 3
OASystem/OASystem.Infrastructure/Repositories/Groups/GroupCostParameterRepository.cs

@@ -30,9 +30,9 @@ namespace OASystem.Infrastructure.Repositories.Groups
             return await UpdateAsync(x => x.Id == id, x=>new Grp_GroupCostParameter { IsShare = IsShare });
         }
 
-        public async Task<bool> DeleteGroupCostParameterListByDiid(int diid) 
+        public async Task<bool> DeleteGroupCostParameterListByDiid(int diid, int userid) 
         {
-            return await SoftDeleteAsync(x=>x.DiId == diid);
+            return await SoftDeleteAsync(x=>x.DiId == diid && x.IsDel == 0, userid);
         }
 
         public async Task<bool> SaveAsync(List<Grp_GroupCostParameter> List,int Userid, int diid)
@@ -41,7 +41,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
             try
             {
                 BeginTran();
-                isTrue = await DeleteGroupCostParameterListByDiid(diid);
+                isTrue = await DeleteGroupCostParameterListByDiid(diid, Userid);
                 if (List.Count > 0)
                 {
                     List.ForEach(x => { x.CreateUserId = Userid; x.CreateTime = DateTime.Now; });