123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- using Newtonsoft.Json.Linq;
- using PTMedicalInsurance.Variables;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace PTMedicalInsurance.Common
- {
- public class Utils
- {
- #region 工具
-
-
-
-
-
- public static long GetTimeStamp(DateTime dateTime)
- {
- DateTime _dtStart = new DateTime(1970, 1, 1, 8, 0, 0);
-
- long timeStamp = Convert.ToInt32(dateTime.Subtract(_dtStart).TotalSeconds);
-
-
- return timeStamp;
- }
-
-
-
-
-
- public static DateTime GetDateTime(long timestamp)
- {
-
-
- DateTime dtStart = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
- DateTime targetDt = dtStart.AddMilliseconds(timestamp).AddHours(8);
- return targetDt;
- }
-
-
-
-
-
- public static void convertTimestamp(JObject joObject,string key)
- {
- if (joObject.ContainsKey(key))
- {
- Global.writeLog(string.Format("当前对象[{0}]的类型为:{1}", key, joObject.GetValue(key).Type.GetType()));
- }
-
- if (joObject.ContainsKey(key) && joObject.GetValue(key).Type.GetType() != typeof(string))
- {
- long timestamp = long.Parse(joObject.GetValue(key).ToString());
- string datetime = Utils.GetDateTime(timestamp).ToString("yyyy-MM-dd");
- joObject[key] = datetime;
- Global.writeLog(string.Format("转换后的日期为:{0}",datetime));
- }
- }
- #endregion
- #region BeanUtils
-
-
-
-
-
-
-
-
- public static T merge<T>(T entity, T addtional,bool forceCover)
- {
- if (entity == null) return addtional;
- if (addtional == null) return entity;
-
- Type mType = typeof(T);
- object result = Activator.CreateInstance(mType);
- PropertyInfo[] pi = mType.GetProperties();
- pi.ToList().ForEach((p) =>
- {
- object v1 = p.GetValue(entity);
- object v2 = p.GetValue(addtional);
- if (forceCover)
- {
- v1 = v2;
- }
- else {
- v1 = (v1 == null ? v2 : v1);
- }
- p.SetValue(result, v1);
- });
- return (T)result;
- }
-
-
-
-
-
-
-
- public static T merge<T>(T entity, T addtional)
- {
- return merge(entity, addtional, false);
- }
- private static JObject merge(JObject to, JObject from)
- {
- to.Merge(from);
- return to;
- }
-
-
-
-
-
-
-
- public static T mergeObject<T>(T to, T from)
- {
- JObject toObj = JObject.FromObject(to);
- JObject fromObj = JObject.FromObject(from);
- JObject result = merge(toObj, fromObj);
- return result.ToObject<T>();
- }
- #endregion
- #region 业务个性化
-
-
-
-
-
- public static JObject Wrapper(JObject jsonInParam)
- {
-
-
-
- return jsonInParam;
- }
-
-
-
-
-
- public static JObject removeWrapper(JObject jsonInParam)
- {
-
-
-
-
- return jsonInParam;
- }
- public static bool isOtherCityPatient()
- {
-
- string areaCode = Global.pat.insuplc_admdvs;
- if (!string.IsNullOrEmpty(areaCode) && areaCode.Length>2 && areaCode.Substring(0, 2) != "50")
- {
- return true;
- }
- return false;
- }
- public static string convertAdmDr(string admNo)
- {
-
- if (isOtherCityPatient())
- {
-
- string ret = admNo + "-" + DateTime.Now.ToString("HHmm");
-
- JObject exp = new JObject();
- exp.Add("admDr",ret);
- Global.pat.ExpContent = exp.ToString();
- return ret;
- }
- return admNo;
- }
- #endregion
- }
- }
|