Browse Source

团组汇率 修改基础数据源字段

leiy 1 year ago
parent
commit
5ed7ca7126

+ 32 - 6
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -294,17 +294,42 @@ namespace OASystem.API.Controllers
             }
         }
 
+        ///// <summary>
+        ///// 团组汇率 changge
+        ///// </summary>
+        ///// <returns></returns>
+        //[HttpPost]
+        //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        //public async Task<IActionResult> ChangeGroupRateInfo()
+        //{
+        //    try
+        //    {
+        //        Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
+        //        if (teamRateData.Code != 0)
+        //        {
+        //            return Ok(JsonView(false, teamRateData.Msg));
+        //        }
+        //        return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        return Ok(JsonView(false, ex.Message));
+        //        throw;
+        //    }
+        //}
+
         /// <summary>
-        /// 团组汇率 changge
+        /// 团组汇率 Select汇率详情
         /// </summary>
+        /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> ChangeGroupRateInfo()
+        public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
         {
             try
             {
-                Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
+                Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
                 if (teamRateData.Code != 0)
                 {
                     return Ok(JsonView(false, teamRateData.Msg));
@@ -318,18 +343,19 @@ namespace OASystem.API.Controllers
             }
         }
 
+
         /// <summary>
-        /// 团组汇率 Select汇率详情
+        /// 团组汇率 添加 or 更新
         /// </summary>
         /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
+        public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
         {
             try
             {
-                Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
+                Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
                 if (teamRateData.Code != 0)
                 {
                     return Ok(JsonView(false, teamRateData.Msg));

+ 32 - 11
OASystem/OASystem.Api/OAMethodLib/JsonConvertOverride.cs

@@ -60,25 +60,46 @@ namespace OASystem.API.OAMethodLib
     #endregion
 
 
-    #region String null值转换(读/写)
-
+    #region decimal格式化
 
-    //public class Int32JsonConverter : System.Text.Json.Serialization.JsonConverter<int?>
+    ///// <summary>
+    ///// decimal格式化
+    ///// </summary>
+    //public class JsonConverterDecimal : Newtonsoft.Json.JsonConverter
     //{
-    //    private readonly string Format;
-    //    public Int32JsonConverter(string format)
+    //    /// <summary>
+    //    /// 是否可以转换
+    //    /// </summary>
+    //    /// <param name="objectType"></param>
+    //    /// <returns></returns>
+    //    public override bool CanConvert(Type objectType)
     //    {
-    //        Format = format;
+    //        return objectType == typeof(decimal) || objectType == typeof(decimal?);
     //    }
-    //    public override void Write(Utf8JsonWriter writer, int? value, JsonSerializerOptions options)
+
+    //    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
     //    {
-    //        writer.WriteStringValue((value ?? 0).ToString());
+    //        if (reader.ValueType == null && reader.Value == null)
+
+    //        {
+    //            return null;
+    //        }
+    //        else
+    //        {
+    //            decimal.TryParse(reader.Value != null ? reader.Value.ToString() : "", out decimal value);
+    //            return value.ToString("F2");
+    //        }
+
     //    }
-    //    public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+
+    //    public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
     //    {
-    //        return Convert.ToInt32(reader.GetString()) ?? 0; 
-    //    }
+    //        if (value == null)
 
+    //            writer.WriteValue(value);
+    //        else
+    //            writer.WriteValue(value + "");
+    //    }
     //}
 
     #endregion

+ 5 - 0
OASystem/OASystem.Api/Program.cs

@@ -13,6 +13,7 @@ using Quartz.Impl;
 using Quartz.Spi;
 using Quartz;
 using QuzrtzJob.Factory;
+using System.Runtime.CompilerServices;
 
 var builder = WebApplication.CreateBuilder(args);
 var basePath = AppContext.BaseDirectory;
@@ -33,8 +34,12 @@ builder.Services.AddControllers()
         //options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
 
         options.JsonSerializerOptions.Converters.Add(new NullJsonConverter());
+
         //时间格式化响应
         options.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss"));
+
+        ////decimal 四位小数
+        //options.JsonSerializerOptions.Converters.Add(new JsonConverterDecimal(0.0000M));
     });
 
 

+ 45 - 1
OASystem/OASystem.Domain/Dtos/Financial/TeamRateDto.cs

@@ -1,4 +1,5 @@
-using System;
+using OASystem.Domain.ViewModels.Financial;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -24,4 +25,47 @@ namespace OASystem.Domain.Dtos.Financial
         /// </summary>
         public int Diid { get; set; }
     }
+
+    /// <summary>
+    /// 团组汇率信息 Dto
+    /// </summary>
+    public class TeamRateUpdateDto : DtoBase
+    {
+        /// <summary>
+        /// 创建用户Id
+        /// </summary>
+        public int CreateUserId { get; set; }
+
+        /// <summary>
+        /// 团组Id
+        /// </summary>
+        public int DiId { get; set; }
+
+        /// <summary>
+        /// 团组汇率 信息
+        /// </summary>
+        public List<TeamRateUpdateInfo>? teamRateUpdateInfos { get; set; }
+    }
+
+    /// <summary>
+    /// 团组汇率信息
+    /// </summary>
+    public class TeamRateUpdateInfo
+    {
+        /// <summary>
+        /// 团组汇率Id
+        /// </summary>
+        public int Id { get; set; }
+
+
+        /// <summary>
+        /// 团组指向分类
+        /// </summary>
+        public int CTable { get; set; }
+
+        /// <summary>
+        /// 币种 Info
+        /// </summary>
+        public List<TeamRateDescView>? teamRates { get; set; }
+    }
 }

+ 6 - 0
OASystem/OASystem.Domain/ViewModels/Financial/TeamRateView.cs

@@ -3,6 +3,7 @@ using OASystem.Domain.Entities.Groups;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading.Tasks;
 
@@ -29,6 +30,11 @@ namespace OASystem.Domain.ViewModels.Financial
     #region 团组汇率 信息
     public class TeamRateModelView
     {
+        /// <summary>
+        /// 汇率Id
+        /// </summary>
+        public int Id { get; set; }
+
         /// <summary>
         /// 汇率模块 Id
         /// </summary>

+ 84 - 2
OASystem/OASystem.Infrastructure/Repositories/Groups/TeamRateRepository.cs

@@ -45,11 +45,24 @@ namespace OASystem.Infrastructure.Repositories.Groups
 
             var teamRateDatas = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); // STid=66 全球币种
 
+            
+
             dynamic _data = null;
 
             if (dto.PortType == 1)
             {
-                _data = new { GroupData = groups.Data, TeamRateData = teamRateDatas.Data };
+                List<Sys_SetData> sys_SetDatas = new List<Sys_SetData>();
+                sys_SetDatas = JsonConvert.DeserializeObject<List<Sys_SetData>>(JsonConvert.SerializeObject(teamRateDatas.Data));
+                List<TeamRateDescView> teamRateDescViews = new List<TeamRateDescView>();
+                foreach (Sys_SetData item in sys_SetDatas) 
+                {
+                    teamRateDescViews.Add(new TeamRateDescView() {
+                        CurrencyName = item.Remark,
+                        CurrencyCode = item.Name,
+                        Rate = 0.0000M
+                    });
+                }
+                _data = new { GroupData = groups.Data, TeamRateData = teamRateDescViews };
 
             }
             else if (dto.PortType == 2)
@@ -198,7 +211,6 @@ namespace OASystem.Infrastructure.Repositories.Groups
 
         }
 
-
         /// <summary>
         /// 团组汇率 Rep
         /// </summary>
@@ -296,6 +308,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                 {
                     TeamRateModelView teamRateModelInfo = new TeamRateModelView();
 
+                    teamRateModelInfo.Id = item.Id;
                     teamRateModelInfo.CTableId = item.CTable;
                     teamRateModelInfo.CTableName = item.Name;
                     List<TeamRateDescView> teamRateDescViews = new List<TeamRateDescView>();
@@ -347,5 +360,74 @@ namespace OASystem.Infrastructure.Repositories.Groups
             return result;
 
         }
+
+
+        /// <summary>
+        /// 团组汇率 更新 or 添加
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<Result> PostGroupRateUpdate(TeamRateUpdateDto dto)
+        {
+
+            Result result = new() { Code = -2 };
+
+            
+            List<Grp_TeamRate> teamRates = new List<Grp_TeamRate>();
+            foreach (TeamRateUpdateInfo item in dto.teamRateUpdateInfos)
+            {
+                Grp_TeamRate teamRateInfo = new Grp_TeamRate();
+                string currencyStr = string.Empty;
+                foreach (TeamRateDescView currency in item.teamRates)
+                {
+                    currencyStr += string.Format(@"{0}({1}):{2}|", currency.CurrencyName, currency.CurrencyCode, currency.Rate);
+                }
+                if (currencyStr.Length > 0)
+                {
+                    currencyStr = currencyStr.Substring(0, currencyStr.Length - 1);
+                }
+
+                teamRateInfo.DiId = dto.DiId;
+                teamRateInfo.CreateUserId = dto.CreateUserId;
+                teamRateInfo.Id = item.Id;
+                teamRateInfo.CreateTime = DateTime.Now;
+                teamRateInfo.CTable = item.CTable;
+                teamRateInfo.Remark = currencyStr;
+                teamRates.Add(teamRateInfo);
+            }
+
+
+            int addCount = 0, updateCount = 0;
+            if (dto.PortType == 1)
+            {
+                try
+                {
+                    var x = _sqlSugar.Storageable(teamRates).ToStorage();
+                    addCount= x.AsInsertable.ExecuteCommand();        //不存在插入
+                    updateCount = x.AsUpdateable.ExecuteCommand();    //存在更新
+                }
+                catch (Exception ex)
+                {
+
+                    result.Msg = ex.Message;
+                }
+                
+
+            }
+            else if (dto.PortType == 2)
+            {
+
+            }
+            else if (dto.PortType == 3)
+            {
+
+            }
+
+            result.Code = 0;
+            result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount,updateCount);
+
+            return result;
+
+        }
     }
 }