using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Reflection; using System.Collections; using System.IO; using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Configuration; using System.Data; using System.Threading.Tasks; using System.Threading; using System.Collections.Concurrent; namespace FangYar.WebUI.Handle { /// /// TMQTestData 的摘要说明 拉萨特勤一站 /// public class LSTQYZTMQTrainData : IHttpHandler { string org_id = "021933cc9b11441c920a431eeffe60c2"; FangYar.BLL.TRAIN.T_TRAININGSCORE bll_trainscore = new BLL.TRAIN.T_TRAININGSCORE(); FangYar.BLL.TRAIN.T_SUBJECTGRADESTANDARD bll_standard = new BLL.TRAIN.T_SUBJECTGRADESTANDARD(); FangYar.BLL.TBL.SysEmpBLL bll_emp = new BLL.TBL.SysEmpBLL(); FangYar.BLL.TRAIN.T_TRAININGTASK bll_task = new BLL.TRAIN.T_TRAININGTASK(); //TestName=俯卧撑&RecordCount=1&ResultInfo=210000333,杨213,30,admin01,2017-12-27 09:14:22; private ConcurrentQueue infoQueue = new ConcurrentQueue(); private CancellationTokenSource m_DealToken; private Task m_DealTask; public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string returnstr = "1"; //returnstr = GetInfo(context); infoModel infomodel = new infoModel(); infomodel.TestName = context.Request.Params["TestName"]; infomodel.RecordCount = context.Request.Params["RecordCount"]; infomodel.ResultInfo = context.Request.Params["ResultInfo"]; infoQueue.Enqueue(infomodel); //添加 m_DealToken = new CancellationTokenSource(); m_DealTask = Task.Factory.StartNew(DealInfoList, m_DealToken.Token); context.Response.Write(returnstr); } public class infoModel { public string TestName { get; set; } public string RecordCount { get; set; } public string ResultInfo { get; set; } } infoModel infomodel; private void DealInfoList() { while (!m_DealToken.IsCancellationRequested) { if (infoQueue.TryDequeue(out infomodel)) { try { DealInfo(infomodel); } catch (Exception ex) { WriteLog(ex.Source + ex.StackTrace + ex.Message + "DealInfoList_Error"); } } else { Thread.Sleep(100); } } } private void DealInfo(infoModel infomodel) { try { WriteLog("进入!"); string TestName = infomodel.TestName; string RecordCount = infomodel.RecordCount; string ResultInfo = infomodel.ResultInfo; WriteLog("项目名称:" + TestName + ";人数:" + RecordCount + ";体测数据:" + ResultInfo); if (Convert.ToInt32(RecordCount) > 0) { //获取成绩标准 string scoreWhere = " SUBJECTNAME = '" + TestName + "' and ORG_ID = '" + org_id + "'"; if (TestName == "3000米跑" || TestName == "蛇形跑" || TestName == "屈臂悬垂" || TestName == "5000米负重跑" || TestName == "400米救人疏散物资" || TestName == "100米负重跑" || TestName == "60米肩梯跑" || TestName == "负重上10楼" || TestName == "搬运重物折返" || TestName == "绳索攀爬" || TestName == "双杠直臂前移") { scoreWhere += " order by (GENDER) ,(AGE1) desc ,(STASYS1)"; } else if (TestName == "屈腿仰卧起坐" || TestName == "引体向上" || TestName == "俯卧撑" || TestName == "跳绳" || TestName == "单杠卷身上" || TestName == "双杠臂屈伸") { scoreWhere += " order by (GENDER) ,(AGE1) desc ,(STASYS1) desc"; } DataTable dt = bll_standard.GetList(scoreWhere).Tables[0]; string[] ResultInfos = ResultInfo.Split(';'); for (int i = 0; i < ResultInfos.Length; i++) { try { if (!string.IsNullOrEmpty(ResultInfos[i])) { string[] ResultArry = ResultInfos[i].ToString().Split(','); string emp_num = ResultArry[0]; string name = ResultArry[1]; string result = ResultArry[2]; string doman = ResultArry[3]; string time = ResultArry[4]; //获取人员信息 FangYar.Model.TBL.TBL_SYS_EMP_Model model_emp = new Model.TBL.TBL_SYS_EMP_Model(); model_emp = bll_emp.GetModelByUID(emp_num); //获取任务 string taskWhere = " subjectcontent_name like '%" + TestName + "%' and org_id ='" + org_id + "' and trainingperson_name like '%" + name + "%'"; DataTable dt_task = bll_task.GetListFirst(taskWhere).Tables[0]; if (dt_task.Rows.Count == 0) { WriteLog("Exception : dt_task 为空,此人没有任务:" + ResultInfos[i].ToString()); continue; } string SUBJECTCONTENT = dt_task.Rows[0]["SUBJECTCONTENT"].ToString(); string subjectid = ""; string subjectname = ""; JArray jarray = JsonConvert.DeserializeObject(SUBJECTCONTENT); foreach (JObject obj in jarray.Value()) { if (obj["NAME"].ToString() == TestName) { subjectid = obj["ID"].ToString(); subjectname = obj["NAME"].ToString(); break; } } string TRAINIGDATE = dt_task.Rows[0]["TRAINIGDATE"].ToString(); string TASKID = dt_task.Rows[0]["ID"].ToString(); string TASKNAME = dt_task.Rows[0]["NAME"].ToString(); string ORG_ID = dt_task.Rows[0]["ORG_ID"].ToString(); string ORG_NAME = dt_task.Rows[0]["ORG_NAME"].ToString(); //{"data":[{"ppl_Id":"18609986119","ppl_Name":"颜龙","ppl_Sex":"0","ppl_Age":"36"}]} string REPORTPERSONID = "", REPORTPERSONNAME = ""; string leaderobj = dt_task.Rows[0]["LEADTRAINING"].ToString(); JObject leaderObj = JsonConvert.DeserializeObject(leaderobj); foreach (JObject obj in leaderObj.Value("data")) { REPORTPERSONID = obj["ppl_Id"].ToString(); REPORTPERSONNAME = obj["ppl_Name"].ToString(); } if (model_emp != null) { FangYar.Model.TRAIN.T_TRAININGSCORE trainscore = new Model.TRAIN.T_TRAININGSCORE(); trainscore.ID = Guid.NewGuid().ToString("N"); trainscore.USERS_UID = emp_num; trainscore.USERS_NAME = name; trainscore.SUBJECTID = subjectid; trainscore.SUBJECTNAME = subjectname; trainscore.TRAINIGDATE = TRAINIGDATE; trainscore.TASKID = TASKID; trainscore.TASKNAME = TASKNAME; trainscore.RESULT = result; if (TestName == "3000米跑" || TestName == "蛇形跑" || TestName == "屈臂悬垂" || TestName == "5000米负重跑" || TestName == "400米救人疏散物资" || TestName == "100米负重跑" || TestName == "60米肩梯跑" || TestName == "负重上10楼" || TestName == "搬运重物折返" || TestName == "绳索攀爬" || TestName == "双杠直臂前移") { string millisecond = ""; switch (TestName) { case "3000米跑": case "屈臂悬垂": case "5000米负重跑": case "400米救人疏散物资": case "负重上10楼": case "搬运重物折返": string a = result.Split('\'')[0]; string b = result.Split('\'')[1].Split('"')[0]; millisecond = (Convert.ToInt32(a) * 60 * 1000 + Convert.ToInt32(b) * 1000).ToString(); break; case "蛇形跑": case "100米负重跑": case "60米肩梯跑": case "绳索攀爬": case "双杠直臂前移": millisecond = (Convert.ToInt32(result) * 1000).ToString(); ; break; default: millisecond = "0"; break; } trainscore.ACHIEVEMENT = GetScoreTime(dt, millisecond, model_emp.EMP_SEX, CalculateAgeString(Convert.ToDateTime(model_emp.BIRTHDAY), Convert.ToDateTime(time))); } else if (TestName == "屈腿仰卧起坐" || TestName == "引体向上" || TestName == "俯卧撑" || TestName == "跳绳" || TestName == "单杠卷身上" || TestName == "双杠臂屈伸") { DateTime t1 = Convert.ToDateTime(model_emp.BIRTHDAY); DateTime t2 = Convert.ToDateTime(time); trainscore.ACHIEVEMENT = GetScoreFrequency(dt, result, model_emp.EMP_SEX, CalculateAgeString(Convert.ToDateTime(model_emp.BIRTHDAY), Convert.ToDateTime(time))); } trainscore.REPORTPERSONID = REPORTPERSONID; trainscore.REPORTPERSONNAME = REPORTPERSONNAME; trainscore.REPORTTIME = Convert.ToDateTime(time); trainscore.ORG_ID = ORG_ID; trainscore.ORG_NAME = ORG_NAME; bool flag = bll_trainscore.Add(trainscore); WriteLog("flag :" + flag); FangYar.Model.TRAIN.T_TRAININGTASK model_task = bll_task.GetModel(TASKID); model_task.STATE = "2"; bool flag_updatetask = bll_task.Update(model_task); WriteLog("flag_updatetask :" + flag_updatetask); } } } catch (Exception e) { WriteLog("Exception 循环内部:" + e.Message); } } } } catch (Exception e) { WriteLog("Exception :" + e.Message); } } private string GetInfo(HttpContext context) { try { WriteLog("进入!"); string TestName = context.Request.Params["TestName"]; string RecordCount = context.Request.Params["RecordCount"]; string ResultInfo = context.Request.Params["ResultInfo"]; WriteLog("项目名称:" + TestName + ";人数:" + RecordCount + ";体测数据:" + ResultInfo); if (Convert.ToInt32(RecordCount) > 0) { //获取成绩标准 string scoreWhere = " SUBJECTNAME = '" + TestName + "' and ORG_ID = '" + org_id + "'"; if (TestName == "3000米跑" || TestName == "蛇形跑" || TestName == "屈臂悬垂" || TestName == "5000米负重跑" || TestName == "400米救人疏散物资" || TestName == "100米负重跑" || TestName == "60米肩梯跑" || TestName == "负重上10楼" || TestName == "搬运重物折返" || TestName == "绳索攀爬" || TestName == "双杠直臂前移") { scoreWhere += " order by (GENDER) ,(AGE1) desc ,(STASYS1)"; } else if (TestName == "屈腿仰卧起坐" || TestName == "引体向上" || TestName == "俯卧撑" || TestName == "跳绳" || TestName == "单杠卷身上" || TestName == "双杠臂屈伸") { scoreWhere += " order by (GENDER) ,(AGE1) desc ,(STASYS1) desc"; } DataTable dt = bll_standard.GetList(scoreWhere).Tables[0]; string[] ResultInfos = ResultInfo.Split(';'); for (int i = 0; i < ResultInfos.Length; i++) { if (!string.IsNullOrEmpty(ResultInfos[i])) { string[] ResultArry = ResultInfos[i].ToString().Split(','); string emp_num = ResultArry[0]; string name = ResultArry[1]; string result = ResultArry[2]; string doman = ResultArry[3]; string time = ResultArry[4]; //获取人员信息 FangYar.Model.TBL.TBL_SYS_EMP_Model model_emp = new Model.TBL.TBL_SYS_EMP_Model(); model_emp = bll_emp.GetModelByUID(emp_num); //获取任务 string taskWhere = " subjectcontent_name like '%" + TestName + "%' and org_id ='" + org_id + "' and trainingperson_name like '%" + name + "%'"; DataTable dt_task = bll_task.GetListFirst(taskWhere).Tables[0]; string SUBJECTCONTENT = dt_task.Rows[0]["SUBJECTCONTENT"].ToString(); string subjectid = ""; string subjectname = ""; JArray jarray = JsonConvert.DeserializeObject(SUBJECTCONTENT); foreach (JObject obj in jarray.Value()) { //string a = obj["NAME"].ToString(); //string b = obj["ID"].ToString(); if (obj["NAME"].ToString() == TestName) { subjectid = obj["ID"].ToString(); subjectname = obj["NAME"].ToString(); break; } } string TRAINIGDATE = dt_task.Rows[0]["TRAINIGDATE"].ToString(); string TASKID = dt_task.Rows[0]["ID"].ToString(); string TASKNAME = dt_task.Rows[0]["NAME"].ToString(); string ORG_ID = dt_task.Rows[0]["ORG_ID"].ToString(); string ORG_NAME = dt_task.Rows[0]["ORG_NAME"].ToString(); //{"data":[{"ppl_Id":"18609986119","ppl_Name":"颜龙","ppl_Sex":"0","ppl_Age":"36"}]} string REPORTPERSONID = "", REPORTPERSONNAME = ""; string leaderobj = dt_task.Rows[0]["LEADTRAINING"].ToString(); JObject leaderObj = JsonConvert.DeserializeObject(leaderobj); foreach (JObject obj in leaderObj.Value("data")) { REPORTPERSONID = obj["ppl_Id"].ToString(); REPORTPERSONNAME = obj["ppl_Name"].ToString(); } if (model_emp != null) { FangYar.Model.TRAIN.T_TRAININGSCORE trainscore = new Model.TRAIN.T_TRAININGSCORE(); trainscore.ID = Guid.NewGuid().ToString("N"); trainscore.USERS_UID = emp_num; trainscore.USERS_NAME = name; trainscore.SUBJECTID = subjectid; trainscore.SUBJECTNAME = subjectname; trainscore.TRAINIGDATE = TRAINIGDATE; trainscore.TASKID = TASKID; trainscore.TASKNAME = TASKNAME; trainscore.RESULT = result; if (TestName == "3000米跑" || TestName == "蛇形跑" || TestName == "屈臂悬垂" || TestName == "5000米负重跑" || TestName == "400米救人疏散物资" || TestName == "100米负重跑" || TestName == "60米肩梯跑" || TestName == "负重上10楼" || TestName == "搬运重物折返" || TestName == "绳索攀爬" || TestName == "双杠直臂前移") { trainscore.ACHIEVEMENT = GetScoreTime(dt, result, model_emp.EMP_SEX, CalculateAgeString(Convert.ToDateTime(model_emp.BIRTHDAY), Convert.ToDateTime(time))); } else if (TestName == "屈腿仰卧起坐" || TestName == "引体向上" || TestName == "俯卧撑" || TestName == "跳绳" || TestName == "单杠卷身上" || TestName == "双杠臂屈伸") { DateTime t1 = Convert.ToDateTime(model_emp.BIRTHDAY); DateTime t2 = Convert.ToDateTime(time); trainscore.ACHIEVEMENT = GetScoreFrequency(dt, result, model_emp.EMP_SEX, CalculateAgeString(Convert.ToDateTime(model_emp.BIRTHDAY), Convert.ToDateTime(time))); } trainscore.REPORTPERSONID = REPORTPERSONID; trainscore.REPORTPERSONNAME = REPORTPERSONNAME; trainscore.REPORTTIME = Convert.ToDateTime(time); trainscore.ORG_ID = ORG_ID; trainscore.ORG_NAME = ORG_NAME; bool flag = bll_trainscore.Add(trainscore); WriteLog("flag :" + flag); FangYar.Model.TRAIN.T_TRAININGTASK model_task = bll_task.GetModel(TASKID); model_task.STATE = "2"; bool flag_updatetask = bll_task.Update(model_task); WriteLog("flag_updatetask :" + flag_updatetask); } } } } } catch (Exception e) { WriteLog("Exception :" + e.Message); } return "1"; } //时间获取分数 private int GetScoreTime(DataTable dt, string result, string sex, int age) { sex = sex == "男" ? "0" : "1"; int returnInt = 0; for (var y = 0; y < dt.Rows.Count; y++) { if (sex == dt.Rows[y]["GENDER"].ToString() && Convert.ToInt32(result) <= Convert.ToInt32(dt.Rows[y]["STASYS1"].ToString()) && Convert.ToInt32(age) >= Convert.ToInt32(dt.Rows[y]["AGE1"].ToString())) { returnInt = Convert.ToInt32(dt.Rows[y]["ACHIEVEMENT1"].ToString()); break; } else { continue; } } return returnInt; } //次数获取分数 private int GetScoreFrequency(DataTable dt, string result, string sex, int age) { sex = sex == "男" ? "0" : "1"; int returnInt = 0; for (var y = 0; y < dt.Rows.Count; y++) { if (sex == dt.Rows[y]["GENDER"].ToString() && Convert.ToInt32(result) >= Convert.ToInt32(dt.Rows[y]["STASYS1"].ToString()) && Convert.ToInt32(age) >= Convert.ToInt32(dt.Rows[y]["AGE1"].ToString())) { returnInt = Convert.ToInt32(dt.Rows[y]["ACHIEVEMENT1"].ToString()); break; } else { continue; } } return returnInt; } /// /// 计算年龄字符串(周岁) /// /// 第1个日期参数 /// 第2个日期参数 private int CalculateAgeString(DateTime p_FirstDateTime, System.DateTime p_SecondDateTime) { //判断时间段是否为正。若为负,调换两个时间点的位置。 if (System.DateTime.Compare(p_FirstDateTime, p_SecondDateTime) > 0) { System.DateTime stmpDateTime = p_FirstDateTime; p_FirstDateTime = p_SecondDateTime; p_SecondDateTime = stmpDateTime; } //定义:年、月、日 int year, month, day; //计算:天 day = p_SecondDateTime.Day - p_FirstDateTime.Day; if (day < 0) { day += System.DateTime.DaysInMonth(p_FirstDateTime.Year, p_FirstDateTime.Month); p_FirstDateTime = p_FirstDateTime.AddMonths(1); } //计算:月 month = p_SecondDateTime.Month - p_FirstDateTime.Month; if (month < 0) { month += 12; p_FirstDateTime = p_FirstDateTime.AddYears(1); } //计算:年 year = p_SecondDateTime.Year - p_FirstDateTime.Year; //返回格式化后的结果 return year; } private void WriteLog(string msg) { FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = msg, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "TMQTestData" }); //string path = AppDomain.CurrentDomain.BaseDirectory + "log\\TMQTestData\\"; //string filename = DateTime.Now.ToString("yyyyMMdd") + ".txt"; //if (Directory.Exists(path) == false)//如果不存在就创建文件夹 //{ // Directory.CreateDirectory(path); //} //FileInfo file = new FileInfo(path + filename); //if (!file.Exists) //{ // FileStream fs; // fs = File.Create(path + filename); // fs.Close(); //} //using (FileStream fs = new FileStream(path + filename, FileMode.Append, FileAccess.Write)) //{ // using (StreamWriter sw = new StreamWriter(fs)) // { // sw.WriteLine("时间:" + DateTime.Now.ToString() + " 信息:" + msg); // } //} } public bool IsReusable { get { return false; } } } }