LEIYI 6 months ago
parent
commit
0e9dd9e157

+ 29 - 35
OASystem/OASystem.Api/Controllers/ResourceController.cs

@@ -1557,33 +1557,30 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
                                              From Res_InvitationOfficialActivityData i 
                                              Left Join Sys_Users u On i.CreateUserId = u.Id {0}", sqlWhere);
 
-                int totalCount = 0;
+                RefAsync<int> totalCount = 0;
 
-                List<InvitationOfficialActivityDataView> _ivitiesViews = _sqlSugar.SqlQueryable<InvitationOfficialActivityDataView>(sql).ToPageList(dto.PageIndex, dto.PageSize, ref totalCount);
+               var _ivitiesViews = await _sqlSugar.SqlQueryable<InvitationOfficialActivityDataView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, totalCount);
 
-                List<Grp_DelegationInfo> _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().ToList();
+                //List<Grp_DelegationInfo> _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().ToList();
 
                 foreach (var item in _ivitiesViews)
                 {
-                    string delegationNameList = "";
-                    if (!string.IsNullOrEmpty(item.Delegation))
+                    string groupNameStr = "";
+                    int[] groupIds = item.Delegation.Split(',').Select(x =>
                     {
-                        string[] DelegationName = item.Delegation.Split(',');
-                        for (int i = 0; i < DelegationName.Length; i++)
-                        {
-                            string grpId = DelegationName[i];
-                            if (!string.IsNullOrEmpty(grpId))
-                            {
-                                if (grpId.IsNumeric())
-                                {
-                                    delegationNameList += _DelegationInfos.Find(it => it.Id == int.Parse(grpId))?.TeamName ?? "Unknown" + ",";
-                                }
-                            }
-                        }
-                        if (!string.IsNullOrWhiteSpace(delegationNameList))
-                        {
-                            item.DelegationStr = delegationNameList.Substring(0, delegationNameList.Length - 1);
-                        }
+                        int id;
+                        if (int.TryParse(x, out id)) return id;
+                        else return id;
+                    }).ToArray();
+
+                    var _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => groupIds.Contains(x.Id)).ToList();
+                    foreach (var group in _DelegationInfos)
+                    {
+                        groupNameStr += $"{group.TeamName},";
+                    }
+                    if (groupNameStr.Length > 1)
+                    {
+                        groupNameStr = groupNameStr.Substring(0, groupNameStr.Length - 1);
                     }
                 }
 
@@ -1597,13 +1594,14 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
         /// <summary>
         /// 根据商邀资料Id查询信息
         /// </summary>
-        /// <param name="dto"></param>
+        /// <param name="id"></param>
         /// <returns></returns>
-        [HttpGet]
+        [HttpGet("{id}")]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> QueryInvitationOfficialActivityById(int id)
         {
             if (id < 1) return Ok(JsonView(false, "Id参数错误!"));
+
             return Ok(await _InvitationOfficialActivityDataRep.Info(id));
         }
 
@@ -1648,17 +1646,17 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
                 if (System.IO.File.Exists(filePath))
                 {
                     System.IO.File.Delete(filePath);
-
-                    //更改文件值
-                    files.Remove(fileName);
-                    var fileUpd = await _sqlSugar.Updateable<Res_InvitationOfficialActivityData>()
-                                                 .SetColumns(x => x.SndFileName == JsonConvert.SerializeObject(files))
-                                                 .Where(x => x.Id != id)
-                                                 .ExecuteCommandAsync();
                 }
+                //更改文件值
+                files.Remove(fileName);
+                var fileUpd = await _sqlSugar.Updateable<Res_InvitationOfficialActivityData>()
+                                             .SetColumns(x => x.SndFileName == JsonConvert.SerializeObject(files))
+                                             .Where(x => x.Id == id)
+                                             .ExecuteCommandAsync();
+                if (fileUpd > 0) return Ok(JsonView(true, "操作成功!"));
             }
 
-            return Ok(JsonView(true, "操作成功!"));
+            return Ok(JsonView(false, "操作失败!"));
         }
 
         /// <summary>
@@ -1670,11 +1668,9 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> DelInvitationOfficialActivity(DelBaseDto dto)
         {
-
             var res = await _InvitationOfficialActivityDataRep.SoftDeleteByIdAsync<Res_InvitationOfficialActivityData>(dto.Id.ToString(), dto.DeleteUserId);
             if (!res) return Ok(JsonView(false, "删除失败"));
 
-
             var info = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>().FirstAsync(x => x.Id == dto.Id);
             if (info == null) return Ok(JsonView(false, "该条数据不存在!"));
 
@@ -2750,7 +2746,5 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
         }
         #endregion
     }
-
-
 }
 

+ 2 - 0
OASystem/OASystem.Domain/Entities/Resource/Res_InvitationOfficialActivityData.cs

@@ -13,6 +13,8 @@ namespace OASystem.Domain.Entities.Resource
     [SugarTable("Res_InvitationOfficialActivityData")]
     public class Res_InvitationOfficialActivityData:EntityBase
     {
+        [SugarColumn(IsIgnore = true)]
+        public int RowIndex { get; set; } //行号 序号
         /// <summary>
         /// 邀请方国家
         /// </summary>

+ 150 - 82
OASystem/OASystem.Infrastructure/Repositories/Resource/InvitationOfficialActivityDataRepository.cs

@@ -31,97 +31,165 @@ namespace OASystem.Infrastructure.Repositories.Resource
         /// </summary>
         /// <param name="dto"></param>
         /// <returns></returns>
-        public async Task<Result> QueryInvitationOfficialActivityData(QueryInvitationOfficialActivityDataDto dto)
+        public async Task<JsonView> QueryInvitationOfficialActivityData(QueryInvitationOfficialActivityDataDto dto)
         {
-            Result result = new Result() { Code = -2, Msg = "未知错误" };
-            try
-            {
-                string sqlWhere = string.Empty;
-                if (!string.IsNullOrWhiteSpace(dto.Country)) { sqlWhere += string.Format(@" And i.Country like '%{0}%'", dto.Country); }
-                if (!string.IsNullOrWhiteSpace(dto.UnitName)) { sqlWhere += string.Format(@" And i.UnitName like '%{0}%'", dto.UnitName); }
-                if (!string.IsNullOrWhiteSpace(dto.Contact)) { sqlWhere += string.Format(@" And i.Contact like '%{0}%'", dto.Contact); }
-                if (!string.IsNullOrWhiteSpace(dto.Delegation)) { sqlWhere += string.Format(@" And ','+i.Delegation+',' like '%,{0},%'", dto.Delegation); }
-                if (!string.IsNullOrWhiteSpace(dto.Field)) { sqlWhere += string.Format(@" And i.Field like '%{0}%'", dto.Field); }
-                
-                if (dto.CreateUserId != 0 && !string.IsNullOrWhiteSpace(dto.CreateUserId.ToString())) { sqlWhere += string.Format(@" And i.CreateUserId={0}", dto.CreateUserId); }
-                if (!string.IsNullOrWhiteSpace(dto.StartCreateTime) && !string.IsNullOrWhiteSpace(dto.EndCreateTime))
-                {
-                    sqlWhere += string.Format(@" And i.CreateTime between '{0}' and '{1}'", dto.StartCreateTime, dto.EndCreateTime);
-                }
-                sqlWhere += string.Format(@"And Isdel={0}", 0);
+            var result = new JsonView() { Msg = "操作失败!" };
 
-                if (!string.IsNullOrEmpty(sqlWhere.Trim()))
-                {
-                    Regex r = new Regex("And");
-                    sqlWhere = r.Replace(sqlWhere, "Where", 1);
-                }
-                string sql = string.Format(@"select i.*,(select CnName from Sys_Users where Id=i.CreateUserId ) as CreateUserName from 
-                                            Res_InvitationOfficialActivityData i {0} order by CreateTime desc", sqlWhere);
-                List<InvitationOfficialActivityDataView> _ivitiesViews =  _sqlSugar.SqlQueryable<InvitationOfficialActivityDataView>(sql).ToList();
-                if (_ivitiesViews.Count != 0)
-                {
-                    List<Grp_DelegationInfo> _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().ToList();
+            //验证日期格式
+            DateTime _beginDt, _endDt;
+            var _beginDtBool = DateTime.TryParse(dto.StartCreateTime+" 00:00:00", out _beginDt);
+            var _endDtBool = DateTime.TryParse(dto.EndCreateTime + " 23:59:59", out _endDt);
 
-                    foreach (var item in _ivitiesViews)
-                    {
-                        string delegationNameList = "";
-                        string[] DelegationName = item.Delegation.Split(',');
-                        for (int i = 0; i < DelegationName.Length; i++)
-                        {
-                            //Grp_DelegationInfo _DelegationInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(a => a.Id ==int.Parse(DelegationName[i]));
-                            //if (_DelegationInfo != null) { delegationNameList += _DelegationInfo.TeamName + ","; }
+            RefAsync<int> total = 0;
+            
+            var _view = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
+                                        .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
+                                        .Where((ioa,u) => ioa.IsDel == 0)
+                                        .WhereIF(!string.IsNullOrEmpty(dto.Country), (ioa, u) => ioa.Country.Contains(dto.Country))
+                                        .WhereIF(!string.IsNullOrEmpty(dto.UnitName), (ioa, u) => ioa.UnitName.Contains(dto.UnitName))
+                                        .WhereIF(!string.IsNullOrEmpty(dto.Contact), (ioa, u) => ioa.Contact.Contains(dto.Contact))
+                                        .WhereIF(!string.IsNullOrEmpty(dto.Delegation), (ioa, u) => ioa.Delegation.Contains(dto.Delegation))
+                                        .WhereIF(!string.IsNullOrEmpty(dto.Field), (ioa, u) => ioa.Field.Contains(dto.Field))
+                                        .WhereIF(_beginDtBool && _endDtBool, (ioa, u) => ioa.CreateTime >= _beginDt && ioa.CreateTime <= _endDt)
+                                        .WhereIF(dto.CreateUserId > 0, (ioa, u) => ioa.CreateUserId == dto.CreateUserId)
+                                        .Select((ioa, u) => new { 
+                                            Row_Number = ioa.RowIndex,
+                                            ioa.Id,
+                                            ioa.Country,
+                                            ioa.City,
+                                            ioa.UnitName,
+                                            ioa.Field,
+                                            ioa.Contact,
+                                            ioa.Job,
+                                            ioa.Tel,
+                                            ioa.CreateTime,
+                                            CreateUserName = u.CnName,
+                                            DelegationStr = ioa.Delegation
+                                        })
+                                        .OrderByDescending((ioa) => ioa.CreateTime)
+                                        .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
 
-                            delegationNameList += _DelegationInfos.Find(it => it.Id == int.Parse(DelegationName[i]))?.TeamName ?? "Unknown" + ",";
-                        }
-                        if (!string.IsNullOrWhiteSpace(delegationNameList))
-                        {
-                            item.DelegationStr = delegationNameList.Substring(0, delegationNameList.Length - 1);
-                        }
-                        
-                    }
-                    if (dto.PageSize == 0 && dto.PageIndex == 0)
-                    {
-                        result = new Result() { Code = 0, Msg = "查询成功!", Data = _ivitiesViews };
-                    }
-                    else
-                    {
-                        int count = _ivitiesViews.Count;
-                        float totalPage = (float)count / dto.PageSize;//总页数
-                        if (totalPage == 0) totalPage = 1;
-                        else totalPage = (int)Math.Ceiling((double)totalPage);
 
-                        List<InvitationOfficialActivityDataView> invitations = new List<InvitationOfficialActivityDataView>();
-                        for (int i = 0; i < dto.PageSize; i++)
-                        {
-                            var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
-                            if (RowIndex < _ivitiesViews.Count)
-                            {
-                                invitations.Add(_ivitiesViews[RowIndex]);
-                            }
-                            else
-                            {
-                                break;
-                            }
-                        }
-                        ListViewBase<InvitationOfficialActivityDataView> rst = new ListViewBase<InvitationOfficialActivityDataView>();
-                        rst.DataList = invitations; 
-                        rst.DataCount = count;
-                        rst.CurrPageIndex = dto.PageIndex;
-                        rst.CurrPageSize = dto.PageSize;
-                        result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
-                    }
-                    
+            foreach (var item in _view)
+            {
+                string groupNameStr = "";
+                int[] groupIds = item.DelegationStr.Split(',').Select(x =>
+                {
+                    int id;
+                    if (int.TryParse(x, out id)) return id;
+                    else return id;
+                }).ToArray();
+
+               var _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => groupIds.Contains(x.Id)).ToList();
+                foreach (var group in _DelegationInfos)
+                {
+                    groupNameStr += $"{group.TeamName},";
                 }
-                else
+                if (groupNameStr.Length > 1)
                 {
-                    result = new Result() { Code = 0, Msg = "暂无数据!", Data = _ivitiesViews };
+                    groupNameStr= groupNameStr.Substring(0, groupNameStr.Length - 1);
                 }
             }
-            catch (Exception ex)
-            {
-                result = new Result() { Code = -2, Msg = ex.Message };
-            }
+            result.Code = StatusCodes.Status200OK;
+            result.Msg = $"操作成功!";
+            result.Data = _view;
+            result.Count = _view.Count;
+
             return result;
+
+
+
+
+
+
+            //try
+            //{
+            //    string sqlWhere = string.Empty;
+            //    if (!string.IsNullOrWhiteSpace(dto.Country)) { sqlWhere += string.Format(@" And i.Country like '%{0}%'", dto.Country); }
+            //    if (!string.IsNullOrWhiteSpace(dto.UnitName)) { sqlWhere += string.Format(@" And i.UnitName like '%{0}%'", dto.UnitName); }
+            //    if (!string.IsNullOrWhiteSpace(dto.Contact)) { sqlWhere += string.Format(@" And i.Contact like '%{0}%'", dto.Contact); }
+            //    if (!string.IsNullOrWhiteSpace(dto.Delegation)) { sqlWhere += string.Format(@" And ','+i.Delegation+',' like '%,{0},%'", dto.Delegation); }
+            //    if (!string.IsNullOrWhiteSpace(dto.Field)) { sqlWhere += string.Format(@" And i.Field like '%{0}%'", dto.Field); }
+
+            //    if (dto.CreateUserId != 0 && !string.IsNullOrWhiteSpace(dto.CreateUserId.ToString())) { sqlWhere += string.Format(@" And i.CreateUserId={0}", dto.CreateUserId); }
+            //    if (!string.IsNullOrWhiteSpace(dto.StartCreateTime) && !string.IsNullOrWhiteSpace(dto.EndCreateTime))
+            //    {
+            //        sqlWhere += string.Format(@" And i.CreateTime between '{0}' and '{1}'", dto.StartCreateTime, dto.EndCreateTime);
+            //    }
+            //    sqlWhere += string.Format(@"And Isdel={0}", 0);
+
+            //    if (!string.IsNullOrEmpty(sqlWhere.Trim()))
+            //    {
+            //        Regex r = new Regex("And");
+            //        sqlWhere = r.Replace(sqlWhere, "Where", 1);
+            //    }
+            //    string sql = string.Format(@"select i.*,(select CnName from Sys_Users where Id=i.CreateUserId ) as CreateUserName from 
+            //                                Res_InvitationOfficialActivityData i {0} order by CreateTime desc", sqlWhere);
+            //    List<InvitationOfficialActivityDataView> _ivitiesViews =  _sqlSugar.SqlQueryable<InvitationOfficialActivityDataView>(sql).ToList();
+            //    if (_ivitiesViews.Count != 0)
+            //    {
+            //        List<Grp_DelegationInfo> _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().ToList();
+
+            //        foreach (var item in _ivitiesViews)
+            //        {
+            //            string delegationNameList = "";
+            //            string[] DelegationName = item.Delegation.Split(',');
+            //            for (int i = 0; i < DelegationName.Length; i++)
+            //            {
+            //                //Grp_DelegationInfo _DelegationInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(a => a.Id ==int.Parse(DelegationName[i]));
+            //                //if (_DelegationInfo != null) { delegationNameList += _DelegationInfo.TeamName + ","; }
+
+            //                delegationNameList += _DelegationInfos.Find(it => it.Id == int.Parse(DelegationName[i]))?.TeamName ?? "Unknown" + ",";
+            //            }
+            //            if (!string.IsNullOrWhiteSpace(delegationNameList))
+            //            {
+            //                item.DelegationStr = delegationNameList.Substring(0, delegationNameList.Length - 1);
+            //            }
+
+            //        }
+            //        if (dto.PageSize == 0 && dto.PageIndex == 0)
+            //        {
+            //            result = new Result() { Code = 0, Msg = "查询成功!", Data = _ivitiesViews };
+            //        }
+            //        else
+            //        {
+            //            int count = _ivitiesViews.Count;
+            //            float totalPage = (float)count / dto.PageSize;//总页数
+            //            if (totalPage == 0) totalPage = 1;
+            //            else totalPage = (int)Math.Ceiling((double)totalPage);
+
+            //            List<InvitationOfficialActivityDataView> invitations = new List<InvitationOfficialActivityDataView>();
+            //            for (int i = 0; i < dto.PageSize; i++)
+            //            {
+            //                var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
+            //                if (RowIndex < _ivitiesViews.Count)
+            //                {
+            //                    invitations.Add(_ivitiesViews[RowIndex]);
+            //                }
+            //                else
+            //                {
+            //                    break;
+            //                }
+            //            }
+            //            ListViewBase<InvitationOfficialActivityDataView> rst = new ListViewBase<InvitationOfficialActivityDataView>();
+            //            rst.DataList = invitations; 
+            //            rst.DataCount = count;
+            //            rst.CurrPageIndex = dto.PageIndex;
+            //            rst.CurrPageSize = dto.PageSize;
+            //            result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
+            //        }
+
+            //    }
+            //    else
+            //    {
+            //        result = new Result() { Code = 0, Msg = "暂无数据!", Data = _ivitiesViews };
+            //    }
+            //}
+            //catch (Exception ex)
+            //{
+            //    result = new Result() { Code = -2, Msg = ex.Message };
+            //}
+            //return result;
         }
         /// <summary>
         /// 根据Id查询商邀资料信息
@@ -141,7 +209,7 @@ namespace OASystem.Infrastructure.Repositories.Resource
 
         public async Task<JsonView> IOA_OP(OpInvitationOfficialActivityDto dto)
         {
-            JsonView result = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败1" };
+            JsonView result = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
 
             var _info = _mapper.Map<Res_InvitationOfficialActivityData>(dto);