Pārlūkot izejas kodu

Program新增//时间格式化响应DateTimeJsonConverter;
团组流程管控新增单对象查询

jiangjc 1 gadu atpakaļ
vecāks
revīzija
32aef735a5

+ 67 - 0
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -0,0 +1,67 @@
+using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json.Serialization;
+using OASystem.Domain.Dtos.Groups;
+using OASystem.Domain.ViewModels.Groups;
+using OASystem.Infrastructure.Repositories.Groups;
+
+namespace OASystem.API.Controllers
+{
+    /// <summary>
+    /// 团组
+    /// </summary>
+    //[Authorize]
+    [Route("api/[controller]/[action]")]
+    public class GroupsController : ControllerBase
+    {
+        private readonly GrpScheduleRepository _grpScheduleRep;
+        private readonly IMapper _mapper;
+        public GroupsController(IMapper mapper, GrpScheduleRepository grpScheduleRep)
+        {
+            _mapper = mapper;
+            _grpScheduleRep = grpScheduleRep;
+        }
+
+        #region 流程管控
+
+        /// <summary>
+        /// 获取团组流程管控信息
+        /// </summary>
+        /// <param name="paras">参数Json字符串</param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostGrpSchedule(string paras)
+        {
+            if (string.IsNullOrEmpty(paras))
+            {
+                return Ok(JsonView(false, "参数为空"));
+            }
+
+            Grp_ScheduleDto _ScheduleDto = JsonConvert.DeserializeObject<Grp_ScheduleDto>(paras);
+            if (_ScheduleDto != null)
+            {
+                if (_ScheduleDto.SearchType == 2)//获取列表
+                {
+
+                }
+                else//获取对象
+                {
+                    Grp_ScheduleView _grpScheduleView = await _grpScheduleRep.GetView_GrpSchedule(_ScheduleDto);
+                    if (_grpScheduleView != null)
+                    {
+                        return Ok(JsonView(0, "获取成功", _grpScheduleView));
+                    }
+                }
+            }
+            else
+            {
+                return Ok(JsonView(false, "参数反序列化失败"));
+            }
+
+            return Ok(JsonView(false, "暂无数据!"));
+        }
+
+        #endregion
+
+    }
+}

+ 22 - 0
OASystem/OASystem.Api/OAMethodLib/DateTimeJsonConverter.cs

@@ -0,0 +1,22 @@
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace OASystem.API.OAMethodLib
+{
+    public class DateTimeJsonConverter : System.Text.Json.Serialization.JsonConverter<DateTime>
+    {
+        private readonly string Format;
+        public DateTimeJsonConverter(string format)
+        {
+            Format = format;
+        }
+        public override void Write(Utf8JsonWriter writer, DateTime date, JsonSerializerOptions options)
+        {
+            writer.WriteStringValue(date.ToString(Format));
+        }
+        public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+        {
+            return DateTime.ParseExact(reader.GetString(), Format, null);
+        }
+    }
+}

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

@@ -4,6 +4,8 @@ using Autofac.Core;
 using OASystem.API;
 using OASystem.RedisRepository.RedisAsyncHelper;
 using OASystem.RedisRepository.Config;
+using OASystem.API.OAMethodLib;
+using System.Text.Json.Serialization;
 
 var builder = WebApplication.CreateBuilder(args);
 var basePath = AppContext.BaseDirectory;
@@ -17,6 +19,15 @@ builder.Services.AddSingleton(new AppSettingsHelper(_config));
 
 // Add services to the container.
 builder.Services.AddControllersWithViews();
+builder.Services.AddControllers()
+    .AddJsonOptions(options =>
+    {
+        //空字段不响应Response
+        options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
+        //时间格式化响应
+        options.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss"));
+    });
+
 
 #region Cors
 

+ 3 - 0
OASystem/OASystem.Domain/Dtos/DtoBase.cs

@@ -16,5 +16,8 @@ namespace OASystem.Domain.Dtos
         /// 1 Web 2 Android 3 IOS
         /// </summary>
         public int PortType { get; set; }
+
+        public int PageIndex { get; set; }
+        public int PageSize { get; set; }
     }
 }

+ 35 - 0
OASystem/OASystem.Domain/Dtos/Groups/Grp_ScheduleDto.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.Groups
+{
+    public class Grp_ScheduleDto : DtoBase
+    {
+        /// <summary>
+        /// 查询类型(int)
+        /// <list type="table">
+        /// <item>1:对象</item>
+        /// <item>2:列表</item>
+        /// </list>
+        /// </summary>
+        public int SearchType { get; set; }
+
+        #region 对象
+
+        /// <summary>
+        /// 团组流程Id
+        /// </summary>
+        public int ScheduleId { get; set; }
+
+        #endregion
+
+        /// <summary>
+        /// 系统用户Id
+        /// </summary>
+        public int SysUserId { get; set; }
+
+    }
+}

+ 10 - 4
OASystem/OASystem.Domain/Entities/Groups/Grp_ScheduleInfo.cs

@@ -20,16 +20,16 @@ namespace OASystem.Domain.Entities.Groups
         public int DiId { get; set; }
 
         /// <summary>
-        /// 主流程
+        /// 当前主流程
         /// </summary>
         [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public GrpSchedulePrimaryStepEnum PrimaryStep { get; set; }
 
         /// <summary>
-        /// 子流程
+        /// 当前子流程
         /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
-        public int DetailStep { get; set; }
+        //[SugarColumn(IsNullable = true, ColumnDataType = "int")]
+        //public int DetailStep { get; set; }
 
         /// <summary>
         /// 预计开始时间
@@ -92,6 +92,12 @@ namespace OASystem.Domain.Entities.Groups
         [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public int ParentStep { get; set; }
 
+        /// <summary>
+        /// 流程状态(0/1/2 未完成/进行中/已完成)
+        /// </summary>
+        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
+        public int StepStatus { get; set; }
+
         /// <summary>
         /// 负责人员(SysUser.Id)
         /// </summary>

+ 39 - 0
OASystem/OASystem.Domain/Enums/EnumHelper.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Enums
+{
+    public static class EnumHelper
+    {
+        //--extension
+        /// <summary>
+        /// 获取当前枚举描述
+        /// </summary>
+        /// <param name="enumValue"></param>
+        /// <returns></returns>
+        public static string GetEnumDescription(this Enum enumValue)
+        {
+            try
+            {
+                Type type = enumValue.GetType();
+                MemberInfo[] memInfo = type.GetMember(enumValue.ToString());
+                if (null != memInfo && memInfo.Length > 0)
+                {
+                    object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
+                    if (null != attrs && attrs.Length > 0)
+                        return ((DescriptionAttribute)attrs[0]).Description;
+                }
+                return enumValue.ToString();
+            }
+            catch (Exception)
+            {
+                return "";
+            }
+        }
+    }
+}

+ 6 - 0
OASystem/OASystem.Domain/Enums/GrpScheduleEnum.cs

@@ -12,6 +12,12 @@ namespace OASystem.Domain.Enums
     /// </summary>
     public enum GrpSchedulePrimaryStepEnum
     {
+        /// <summary>
+        /// 未开始
+        /// </summary>
+        [Description("未开始")]
+        Wait = 0,
+
         /// <summary>
         /// 确认出团
         /// </summary>

+ 69 - 0
OASystem/OASystem.Domain/ViewModels/Groups/Grp_ScheduleView.cs

@@ -0,0 +1,69 @@
+using Newtonsoft.Json;
+using OASystem.Domain.Enums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.Groups
+{
+    public class Grp_ScheduleView
+    {
+        /// <summary>
+        /// 流程管控Id
+        /// </summary>
+        public int Id { get; set; }
+
+        /// <summary>
+        /// 团组Id
+        /// </summary>
+        public int DiId { get; set; }
+
+        /// <summary>
+        /// 团组名称
+        /// </summary>
+        public string DeleName { get; set; }
+
+        /// <summary>
+        /// 主流程(枚举)
+        /// </summary>
+        public GrpSchedulePrimaryStepEnum PrimaryStep { get; set; }
+
+        /// <summary>
+        /// 主流程中文描述
+        /// </summary>
+        public string PrimaryStep_Text
+        {
+            get
+            {
+                return EnumHelper.GetEnumDescription(PrimaryStep);
+            }
+        }
+
+        /// <summary>
+        /// 预计开始时间
+        /// </summary>
+        public DateTime ExpectBeginDt { get; set; }
+
+        /// <summary>
+        /// 预计结束时间
+        /// </summary>
+        public DateTime ExpectEndDt { get; set; }
+
+        /// <summary>
+        /// 总负责人Id
+        /// </summary>
+        public int Leader { get; set; }
+
+        /// <summary>
+        /// 总负责人
+        /// </summary>
+        public string LeaderName { get; set; }
+
+        /// <summary>
+        /// 异常状态0:正常 1:异常
+        /// </summary>
+        public int Exception { get; set; }
+    }
+}

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

@@ -82,7 +82,7 @@ namespace OASystem.Infrastructure.Repositories
         #region Extension
 
         /// <summary>
-        /// Sql语句 无锁
+        ///  获取单个对象  异步
         /// </summary>
         /// <param name="sql"></param>
         /// <returns></returns>
@@ -90,15 +90,32 @@ namespace OASystem.Infrastructure.Repositories
         {
             return await _sqlSugar.SqlQueryable<TEntity>(sql).FirstAsync();
         }
+
+        /// <summary>
+        /// 获取单个对象 
+        /// </summary>
+        /// <param name="sql"></param>
+        /// <returns></returns>
         public virtual TEntity GetSingleInfoBySqlWithNolock(string sql)
         {
             return _sqlSugar.SqlQueryable<TEntity>(sql).First();
         }
 
+        /// <summary>
+        /// 获取集合 异步
+        /// </summary>
+        /// <param name="sql"></param>
+        /// <returns></returns>
         public virtual async Task<List<TEntity>> GetListBySqlWithNolockAsync(string sql)
         {
             return await _sqlSugar.SqlQueryable<TEntity>(sql).ToListAsync();
         }
+
+        /// <summary>
+        /// 获取集合 
+        /// </summary>
+        /// <param name="sql"></param>
+        /// <returns></returns>
         public virtual List<TEntity> GetListBySqlWithNolock(string sql)
         {
             return _sqlSugar.SqlQueryable<TEntity>(sql).ToList();

+ 64 - 0
OASystem/OASystem.Infrastructure/Repositories/Groups/GrpScheduleRepository.cs

@@ -0,0 +1,64 @@
+using OASystem.Domain.Dtos.Groups;
+using OASystem.Domain.Entities.Groups;
+using OASystem.Domain.ViewModels.Groups;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Infrastructure.Repositories.Groups
+{
+    public class GrpScheduleRepository : BaseRepository<Grp_ScheduleInfo, Grp_ScheduleInfo>
+    {
+        public GrpScheduleRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
+        {
+        }
+
+        public string SetSqlWhere_GrpScheduleDto(Grp_ScheduleDto _dto)
+        {
+            string sqlWhere = string.Empty;
+
+            if (_dto.SysUserId > 0)
+            {
+                sqlWhere += string.Format(@" And s.Id in ( Select Id From Grp_SchedulePerson With(Nolock) Where SysUserId = '{0}' ) ", _dto.SysUserId);
+            }
+
+            if (_dto.ScheduleId > 0)
+            {
+                sqlWhere += string.Format(@" And s.Id = '{0}' ", _dto.ScheduleId);
+            }
+
+            if (!string.IsNullOrEmpty(sqlWhere.Trim()))
+            {
+                Regex r = new Regex("And");
+                sqlWhere = r.Replace(sqlWhere, "Where", 1);
+            }
+
+            return sqlWhere;
+        }
+
+        /// <summary>
+        /// 获取团组流程数据单个对象
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="_dto"></param>
+        /// <returns></returns>
+        public async Task<Grp_ScheduleView> GetView_GrpSchedule(Grp_ScheduleDto _dto)
+        {
+            Grp_ScheduleView _view = null;
+
+            string sqlWhere = this.SetSqlWhere_GrpScheduleDto(_dto);
+            string sql = string.Format(@" Select s.Id,s.DiId,di.TeamName as DeleName,s.PrimaryStep,s.ExpectBeginDt,s.ExpectEndDt,s.Leader,s.Exception,u.CnName as LeaderName
+            From Grp_Schedule as s With(Nolock) Inner Join Grp_DelegationInfo as di With(Nolock) On s.DiId=di.Id
+            Inner Join Sys_Users as u With(Nolock) On s.Leader=u.Id
+            {0} ", sqlWhere);
+
+            _view = await _sqlSugar.SqlQueryable<Grp_ScheduleView>(sql).FirstAsync();
+
+            return _view;
+        }
+
+
+    }
+}