| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- using Newtonsoft.Json.Linq;
- using PTMedicalInsurance.Variables;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace PTMedicalInsurance.Common
- {
- public class Utils
- {
- #region 工具
-
-
-
-
- public static string GetTradeNo()
- {
- return Global.inf.hospitalNO + DateTime.Now.ToString("yyyyMMddHHmmssffff");
- }
-
-
-
-
-
- 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 string GetDateTimeNow()
- {
- return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- }
- public static string ConvertLongToDate(string strValue)
- {
- DateTime dateTime = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(strValue)).DateTime;
- return dateTime.ToString("yyyy-MM-dd");
- }
- public static string ConvertShortDate(string strValue)
- {
- if (!strValue.Contains("-") && strValue.Length >= 8)
- {
- return strValue.Substring(0, 4) + "-" + strValue.Substring(4, 2) + "-" + strValue.Substring(6, 2);
- }
- return strValue.Length > 10 ? strValue.Substring(0, 10) : strValue;
- }
- public static string ConvertNoSplitDate(string strValue)
- {
- strValue = strValue.Replace("-", "");
- if (strValue.Length > 8)
- {
- strValue = strValue.Substring(0, 8);
- }
- return strValue;
- }
-
-
-
-
-
- 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)
- {
- dynamic request = new JObject();
- request.arg0 = jsonInParam;
- return request;
- }
-
-
-
-
-
- public static JObject removeWrapper(JObject jsonInParam)
- {
- if (jsonInParam.ContainsKey("arg0"))
- {
- return (JObject)jsonInParam.GetValue("arg0");
- }
- 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
- public static string MockData(bool requestFlag, string tradeNo)
- {
- string dataFile = Global.curEvt.path + "/config/mock/" + (requestFlag ? "request" : "response") + "/" + tradeNo + ".json";
-
- if (File.Exists(dataFile))
- {
- return File.ReadAllText(dataFile);
- }
- else
- {
- Global.writeLog("配置文件不存在:" + dataFile);
- }
- return "";
- }
-
-
-
-
-
- public static void ExpandData(string key, object value)
- {
- string expand = Global.pat.ExpContent;
- JObject obj = new JObject();
- if (!string.IsNullOrEmpty(expand))
- {
- obj = JObject.Parse(expand);
- }
- if (!obj.ContainsKey(key))
- {
- obj.Add(key, value?.ToString());
- }
- else
- {
- obj[key] = value?.ToString();
- }
- Global.pat.ExpContent = obj.ToString();
- }
-
-
-
-
- public static string GetInsuCode()
- {
- if (string.IsNullOrEmpty(Global.pat.insuplc_admdvs))
- {
- Global.pat.insuplc_admdvs = Global.inf.areaCode;
- }
- return Global.pat.insuplc_admdvs;
- }
-
-
-
-
- public static string GetInsuOrgCode()
- {
- return Global.inf.hospitalNO;
- }
- public static bool Confirm(string title)
- {
- if (MessageBox.Show(title, "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
- {
- return false;
- }
- return true;
- }
- }
- }
|