把当前系统所有参数转换成 字典对象, 方便业务中使用

        /// <summary>
        /// 把当前系统所有参数转换成  字典对象, 方便业务中使用
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, object> ConvertDicBySystemParam(TokenUser spCurrent, IHttpContextAccessor _accessor, IConfiguration _configuration)
        {
            spCurrent = spCurrent ?? new TokenUser();
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic[SystemParamConst.CURRENT_USER_ID] = spCurrent.UserId;
            dic[SystemParamConst.CURRENT_USER_NAME] = spCurrent.UserName;
            dic[SystemParamConst.CURRENT_TELEPHONE] = spCurrent.Telephone;
            dic[SystemParamConst.CURRENT_ROLE_ID] = spCurrent.RoleId;
            dic[SystemParamConst.CURRENT_DEP_ID] = spCurrent.DepId;
            dic[SystemParamConst.CURRENT_JOB_ID] = spCurrent.JobId;
            dic[SystemParamConst.CURRENT_AREA_CODE] = spCurrent.AreaCode;
            dic[SystemParamConst.CURRENT_MERGE_USER_ID] = spCurrent.MergeUserId;

            dic[SystemParamConst.FROM_APP_ID] = RequestPFUtil.GetFromAppIdByHeader(_accessor?.HttpContext);


            //处理二级分享
            Dictionary<string, string> dicHeads = RequestPFUtil.GetRequestHeaders(_accessor?.HttpContext, new List<string> { SystemParamConst.USER_FROM_FIRST_SHARE_ID, SystemParamConst.USER_FROM_SECOND_SHARE_ID });
            if (dicHeads.ContainsKey(SystemParamConst.USER_FROM_FIRST_SHARE_ID))
            {
                dic[SystemParamConst.USER_FROM_FIRST_SHARE_ID] = dicHeads[SystemParamConst.USER_FROM_FIRST_SHARE_ID];
            }
            else
            {
                dic[SystemParamConst.USER_FROM_FIRST_SHARE_ID] = null;
            }
            if (dicHeads.ContainsKey(SystemParamConst.USER_FROM_FIRST_SHARE_ID))
            {
                dic[SystemParamConst.USER_FROM_SECOND_SHARE_ID] = dicHeads[SystemParamConst.USER_FROM_SECOND_SHARE_ID];
            }
            else
            {
                dic[SystemParamConst.USER_FROM_SECOND_SHARE_ID] = null;
            }
            //if (!ValidateUtil.IsNullOrEmptyOrDbNull(dic[SystemParamConst.USER_FROM_SECOND_SHARE_ID]))
            //{

            //}

            //      /// <summary>
            //      /// 来至用户分享的id
            //      /// </summary>
            //public const string USER_FROM_FIRST_SHARE_ID = "userFromFirstShareId";
            ///// <summary>
            ///// 来至用户分享的二级ID
            ///// </summary>
            //public const string USER_FROM_SECOND_SHARE_ID = "userFromSecondShareId";


            DateTime dateNow = DateTime.Now;
            dic[SystemParamConst.CURRENT_DATE] = dateNow;

            dic[SystemParamConst.CURRENT_YEAR_MONTH] = string.Format("{0:yyyy-MM}", dateNow);
            dic[SystemParamConst.CURRENT_YEAR_MONTH_01] = Convert.ToDateTime(string.Format("{0:yyyy-MM-01}", dateNow)); ;


            DateTime dateDay = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd}", dateNow));
            dic[SystemParamConst.CURRENT_DAY_S] = dateDay;
            dic[SystemParamConst.CURRENT_DAY_E] = dateDay.AddDays(1).AddSeconds(-1);

            dic[SystemParamConst.CURRENT_DAY7_S] = dateDay.AddDays(-7);
            dic[SystemParamConst.CURRENT_DAY7_E] = dateDay.AddDays(1).AddSeconds(-1);


            DateTime dateWeek = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd}", dateNow));
            int dayWeek = (Convert.ToInt32(dateWeek.DayOfWeek) == 0 ? 7 : Convert.ToInt32(dateWeek.DayOfWeek));
            dateWeek = dateWeek.AddDays(-dayWeek).AddDays(1);
            dic[SystemParamConst.CURRENT_DAY_WEEK] = dayWeek;
            dic[SystemParamConst.CURRENT_WEEK_S] = dateWeek;
            dic[SystemParamConst.CURRENT_WEEK_E] = dateWeek.AddDays(7).AddSeconds(-1);
            DateTime dateMonth = Convert.ToDateTime(string.Format("{0:yyyy-MM-01}", dateNow));
            dic[SystemParamConst.CURRENT_MONTH_S] = dateMonth;
            dic[SystemParamConst.CURRENT_MONTH_E] = dateMonth.AddMonths(1).AddSeconds(-1);
            DateTime dateYear = Convert.ToDateTime(string.Format("{0:yyyy-01-01}", dateNow));
            dic[SystemParamConst.CURRENT_YEAR_S] = dateYear;
            dic[SystemParamConst.CURRENT_YEAR_E] = dateYear.AddYears(1).AddSeconds(-1);


            DateTime dateHour = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd HH:00:00}", dateNow));
            dic[SystemParamConst.CURRENT_HOUR_S] = dateHour;
            dic[SystemParamConst.CURRENT_HOUR_E] = dateHour.AddHours(1).AddSeconds(-1);


            DateTime dateMinute = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd HH:mm:59}", dateNow));
            dic[SystemParamConst.CURRENT_MINUTE5_S] = dateMinute.AddMinutes(-5).AddSeconds(-59);
            dic[SystemParamConst.CURRENT_MINUTE5_E] = dateMinute;
            dic[SystemParamConst.CURRENT_MINUTE10_S] = dateMinute.AddMinutes(-19).AddSeconds(-59);
            dic[SystemParamConst.CURRENT_MINUTE10_E] = dateMinute;
            dic[SystemParamConst.CURRENT_MINUTE15_S] = dateMinute.AddMinutes(-15).AddSeconds(-59);
            dic[SystemParamConst.CURRENT_MINUTE15_E] = dateMinute;
            dic[SystemParamConst.CURRENT_MINUTE30_S] = dateMinute.AddMinutes(-30).AddSeconds(-59);
            dic[SystemParamConst.CURRENT_MINUTE30_E] = dateMinute;
            dic[SystemParamConst.CURRENT_MINUTE45_S] = dateMinute.AddMinutes(-45).AddSeconds(-59);
            dic[SystemParamConst.CURRENT_MINUTE45_E] = dateMinute;
            dic[SystemParamConst.CURRENT_MINUTE60_S] = dateMinute.AddMinutes(-60).AddSeconds(-59);
            dic[SystemParamConst.CURRENT_MINUTE60_E] = dateMinute;




            #region 未来参数
            //    /// <summary>
            //    /// 当前月份
            //    /// </summary>
            //public const string CURRENT_MONTH = "_currentMonth";

            dic[SystemParamConst.CURRENT_MONTH] = dateNow.Month;
            ///// <summary>
            ///// 当前年
            ///// </summary>
            //public const string CURRENT_YEAR = "_currentYear";
            dic[SystemParamConst.CURRENT_YEAR] = dateNow.Year;


            ///// <summary>
            ///// 未来近1周 
            ///// </summary>
            //public const string FUTURE_WEEK01_S = "_futureWeek01S";
            dic[SystemParamConst.FUTURE_WEEK01_S] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd}", dateNow));
            ///// <summary>
            ///// 未来近1周
            ///// </summary>
            //public const string FUTURE_WEEK01_E = "_futureWeek01E";
            dic[SystemParamConst.FUTURE_WEEK01_E] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 23:59:59}", dateNow.AddDays(6)));
            ///// <summary>
            ///// 未来近1个月份 
            ///// </summary>
            //public const string FUTURE_MONTH01_S = "_futureMonth01S";
            dic[SystemParamConst.FUTURE_MONTH01_S] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd}", dateNow));
            ///// <summary>
            ///// 未来近1个月份
            ///// </summary>
            //public const string FUTURE_MONTH01_E = "_futureMonth01E";
            dic[SystemParamConst.FUTURE_MONTH01_E] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 23:59:59}", dateNow.AddMonths(1).AddDays(-1)));
            ///// <summary>
            ///// 未来近3个月份 
            ///// </summary>
            //public const string FUTURE_MONTH03_S = "_futureMonth03S";
            dic[SystemParamConst.FUTURE_MONTH03_S] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd}", dateNow));
            ///// <summary>
            ///// 未来近3个月份
            ///// </summary>
            //public const string FUTURE_MONTH03_E = "_futureMonth03E";
            dic[SystemParamConst.FUTURE_MONTH03_S] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 23:59:59}", dateNow.AddMonths(3).AddDays(-1)));
            ///// <summary>
            ///// 未来近6个月份 
            ///// </summary>
            //public const string FUTURE_MONTH06_S = "_futureMonth06S";
            dic[SystemParamConst.FUTURE_MONTH06_S] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd}", dateNow));
            ///// <summary>
            ///// 未来近6个月份
            ///// </summary>
            //public const string FUTURE_MONTH06_E = "_futureMonth06E";
            dic[SystemParamConst.FUTURE_MONTH06_E] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 23:59:59}", dateNow.AddMonths(6).AddDays(-1)));

            ///// <summary>
            ///// 未来近12个月份 
            ///// </summary>
            //public const string FUTURE_MONTH12_S = "_futureMonth12S";
            dic[SystemParamConst.FUTURE_MONTH12_S] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd}", dateNow));
            ///// <summary>
            ///// 未来近12个月份
            ///// </summary>
            //public const string FUTURE_MONTH012_E = "_futureMonth12E";

            dic[SystemParamConst.FUTURE_MONTH012_E] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 23:59:59}", dateNow.AddMonths(12).AddDays(-1)));
            #endregion

            //public const string CURRENT_HOUR_S = "_currentHourS";
            //public const string CURRENT_HOUR_E = "_currentHourE";
            //public const string CURRENT_MINUTE10_S = "_currentMinute10S";
            //public const string CURRENT_MINUTE10_E = "_currentMinute10E";
            //public const string CURRENT_MINUTE15_S = "_currentMinute15S";
            //public const string CURRENT_MINUTE15_E = "_currentMinute15E";
            //public const string CURRENT_MINUTE30_S = "_currentMinute30S";
            //public const string CURRENT_MINUTE30_E = "_currentMinute30E";
            //public const string CURRENT_MINUTE45_S = "_currentMinute45S";
            //public const string CURRENT_MINUTE45_E = "_currentMinute45E";



            dic[SystemParamConst.CURRENT_USER_DEVELOPER] = spCurrent.Developer;
            dic[SystemParamConst.FILTER_DATE_S] = "00:00:00";
            dic[SystemParamConst.FILTER_DATE_E] = "23:59:59";
            //前面带有空格
            dic["_filterDateEn"] = " 23:59:59";
            dic[SystemParamConst.FILTER_USER_ID] = new List<string>();
            var dicFilterAreaCode = RequestPFUtil.GetUrlOrFormParamValueByName(SystemParamConst.CURRENT_FILTER_AREA_CODE, _accessor?.HttpContext);
            if (!string.IsNullOrEmpty(dicFilterAreaCode))
            {
                dic[SystemParamConst.CURRENT_FILTER_AREA_CODE] = dicFilterAreaCode;
            }
            else
            {
                //设置特殊头信息 20190922 cbg
                var dicHeaders = RequestPFUtil.GetRequestHeaders(_accessor?.HttpContext, new List<string> { SystemParamConst.CURRENT_FILTER_AREA_CODE });
                if (dicHeaders != null && dicHeaders.ContainsKey(SystemParamConst.CURRENT_FILTER_AREA_CODE))
                {
                    dic[SystemParamConst.CURRENT_FILTER_AREA_CODE] = dicHeaders[SystemParamConst.CURRENT_FILTER_AREA_CODE];
                }
            }
            if (!dic.ContainsKey(SystemParamConst.CURRENT_FILTER_AREA_CODE))
            {
                dic[SystemParamConst.CURRENT_FILTER_AREA_CODE] = _configuration.GetValue<string>("default:areaCode") ?? "0";
            }


            if (dic.ContainsKey("_filterHourSpan"))
            {
                int span = Convert.ToInt32(dic["_filterHourSpan"]);
                List<DateTime> lstA = new List<DateTime>();
                DateTime dtStart = DateTime.MaxValue;
                if (span > 0)
                {
                    dtStart = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 00:00:00}", dateNow.AddHours(span)));
                    dic["_filterHourCalc"] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd HH:59:59}", dateNow.AddHours(span)));
                }
                else
                {
                    dtStart = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd HH:00:00}", dateNow.AddHours(span)));
                    dic["_filterHourCalc"] = dtStart;
                }
                for (var i = 1; i <= Math.Abs(span); i++)
                {
                    lstA.Add(dtStart.AddHours(i));
                }
                dic["_filterHourCalcA"] = lstA;
            }

            if (dic.ContainsKey("_filterDaySpan"))
            {
                int span = Convert.ToInt32(dic["_filterDaySpan"]);
                List<DateTime> lstA = new List<DateTime>();
                DateTime dtStart = DateTime.MaxValue;
                if (span > 0)
                {
                    dtStart = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 00:00:00}", dateNow.AddDays(span)));
                    dic["_filterDayCalc"] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 23:59:59}", dateNow.AddDays(span)));
                }
                else
                {
                    dtStart = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 00:00:00}", dateNow.AddDays(span)));
                    dic["_filterDayCalc"] = dtStart;
                }
                for (var i = 1; i <= Math.Abs(span); i++)
                {
                    lstA.Add(dtStart.AddDays(i));
                }
                dic["_filterDayCalcA"] = lstA;
            }


            if (dic.ContainsKey("_filterMonthSpan"))
            {
                List<DateTime> lstA = new List<DateTime>();
                int span = Convert.ToInt32(dic["_filterMonthSpan"]);
                DateTime dtStart = DateTime.MaxValue;
                if (span > 0)
                {
                    dtStart = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 00:00:00}", dateNow.AddMonths(span)));
                    dic["_filterMonthCalc"] = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 23:59:59}", dateNow.AddMonths(span)));
                }
                else
                {
                    dtStart = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 00:00:00}", dateNow.AddMonths(span)));
                    dic["_filterMonthCalc"] = dtStart;
                }
                for (var i = 1; i <= Math.Abs(span); i++)
                {
                    lstA.Add(dtStart.AddMonths(i));
                }
                dic["_filterMonthCalcA"] = lstA;
            }
            return dic;
        }
    }
}
文档更新时间: 2021-10-17 20:06   作者:admin