软测单独项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

582 lines
30 KiB

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
{
/// <summary>
/// TMQTestData 的摘要说明 拉萨特勤一站
/// </summary>
public class TMQTestData : 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();
FangYar.BLL.TRAIN.T_TRAININGSCOREFLOW bll_flow = new BLL.TRAIN.T_TRAININGSCOREFLOW();
//TestName=屈腿仰卧起坐&RecordCount=1&ResultInfo=18689013358,沈万启,10,admin,2021-07-19 16:23:41;
private ConcurrentQueue<infoModel> infoQueue = new ConcurrentQueue<infoModel>();
private CancellationTokenSource m_DealToken;
private Task m_DealTask;
public void ProcessRequest(HttpContext context)
{
WriteLog("访问接口!");
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"];
WriteLog("项目名称:" + infomodel.TestName + ";人数:" + infomodel.RecordCount + ";体测数据:" + infomodel.ResultInfo);
//俯卧撑;人数:1;体测数据:17689503073,多吉,1,admin,2021-07-19 18:37:20;
//双杠直臂前移;人数:1111,"13908905515,尼玛,1,admin,2021-07-19 18:37:20";
//infomodel.TestName = "30米×2蛇形跑";
//infomodel.RecordCount = "1";
//infomodel.ResultInfo = "16689011962,苏博,0.0,admin,2021-08-21 10:40:15;";
//infomodel.TestName = "绳索攀爬";
//infomodel.RecordCount = "2";
//infomodel.ResultInfo = "15289096105,孔德超,96.9,admin,2021-08-23 11:18:07;17689517010,孔德旭,69.8,admin,2021-08-23 11:18:07;";
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)
{
string strLog = "";
try
{
strLog += "进入DealInfo" + "\r\n";
string TestName = infomodel.TestName;
string RecordCount = infomodel.RecordCount;
string ResultInfo = infomodel.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 == "双杠直臂前移" || TestName == "30米×2蛇形跑")
{
scoreWhere += " order by to_number(GENDER) ,to_number(AGE1) desc ,to_number(STASYS1)";
}
else if (TestName == "屈腿仰卧起坐" || TestName == "引体向上" || TestName == "俯卧撑" || TestName == "跳绳"
|| TestName == "单杠卷身上" || TestName == "双杠臂屈伸")
{
scoreWhere += " order by to_number(GENDER) ,to_number(AGE1) desc ,to_number(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);
if (model_emp == null)
{
strLog += "获取到人员信息为空;" + "\r\n";
}
//获取任务
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)
{
strLog += "获取到此人的训练任务信息为空:" + ResultInfos[i].ToString() + "\r\n";
ScoreFlow(org_id, TestName, RecordCount, emp_num, name, result, doman, time, "2");//将成绩流水入库 1:存在任务中 2: 不存在任务
//MQTT
continue;
}
else
{
strLog += "存在此人的训练任务";
ScoreFlow(org_id, TestName, RecordCount, emp_num, name, result, doman, time, "1");//将成绩流水入库 1:存在任务中 2: 不存在任务
}
string SUBJECTCONTENT = dt_task.Rows[0]["SUBJECTCONTENT"].ToString();
string subjectid = "";
string subjectname = "";
JArray jarray = JsonConvert.DeserializeObject<JArray>(SUBJECTCONTENT);
foreach (JObject obj in jarray.Value<JArray>())
{
if (obj["NAME"].ToString() == TestName)
{
subjectid = obj["ID"].ToString();
subjectname = obj["NAME"].ToString();
break;
}
}
strLog += "解析SUBJECTCONTENT";
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<JObject>(leaderobj);
foreach (JObject obj in leaderObj.Value<JArray>("data"))
{
REPORTPERSONID = obj["ppl_Id"].ToString();
REPORTPERSONNAME = obj["ppl_Name"].ToString();
}
strLog += "解析leaderObj";
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 == "双杠直臂前移" || TestName == "30米×2蛇形跑")
{
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 "双杠直臂前移":
case "30米×2蛇形跑":
millisecond = (Convert.ToDouble(result) * 1000).ToString(); ;
break;
default:
millisecond = "0";
break;
}
strLog += "获取成绩前";
trainscore.ACHIEVEMENT = GetScoreTime(dt, millisecond, model_emp.EMP_SEX, CalculateAgeString(Convert.ToDateTime(model_emp.BIRTHDAY), Convert.ToDateTime(time)));
strLog += "成绩:"+ trainscore.ACHIEVEMENT;
}
else if (TestName == "屈腿仰卧起坐" || TestName == "引体向上" || TestName == "俯卧撑" || TestName == "跳绳"
|| TestName == "单杠卷身上" || TestName == "双杠臂屈伸" || TestName == "双杠直臂前移")
{
strLog += "获取成绩前";
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)));
strLog += "成绩:" + trainscore.ACHIEVEMENT;
}
trainscore.REPORTPERSONID = REPORTPERSONID;
trainscore.REPORTPERSONNAME = REPORTPERSONNAME;
trainscore.REPORTTIME = Convert.ToDateTime(time);
trainscore.ORG_ID = ORG_ID;
trainscore.ORG_NAME = ORG_NAME;
strLog += "入库前";
bool flag = bll_trainscore.Add(trainscore);
strLog += "成绩入库操作 bll_trainscore flag :" + flag + "\r\n";
FangYar.Model.TRAIN.T_TRAININGTASK model_task = bll_task.GetModel(TASKID);
model_task.STATE = "1";
bool flag_updatetask = bll_task.Update(model_task);
strLog += "任务状态修改操作 flag_updatetask flag :" + flag + "\r\n";
}
}
}
catch (Exception e)
{
strLog += "Exception 循环内部:" + e.Message + "\r\n";
}
}
}
}
catch (Exception e)
{
strLog += "Exception:" + e.Message + "\r\n";
}
WriteLog(strLog);
}
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 to_number(GENDER) ,to_number(AGE1) desc ,to_number(STASYS1)";
}
else if (TestName == "屈腿仰卧起坐" || TestName == "引体向上" || TestName == "俯卧撑" || TestName == "跳绳"
|| TestName == "单杠卷身上" || TestName == "双杠臂屈伸")
{
scoreWhere += " order by to_number(GENDER) ,to_number(AGE1) desc ,to_number(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<JArray>(SUBJECTCONTENT);
foreach (JObject obj in jarray.Value<JArray>())
{
//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<JObject>(leaderobj);
foreach (JObject obj in leaderObj.Value<JArray>("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;
}
/// <summary>
/// 计算年龄字符串(周岁)
/// </summary>
/// <param name="p_FirstDateTime">第1个日期参数</param>
/// <param name="p_SecondDateTime">第2个日期参数</param>
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;
}
/// <summary>
/// 将成绩流水入库
/// </summary>
/// <param name="org_id"></param>
/// <param name="TestName"></param>
/// <param name="RecordCount"></param>
/// <param name="emp_num"></param>
/// <param name="name"></param>
/// <param name="age"></param>
/// <param name="doman"></param>
/// <param name="time"></param>
/// <param name="uptype"></param>
private void ScoreFlow(string org_id, string TestName, string RecordCount, string emp_num, string name, string result, string doman, string time, string uptype)
{
try
{
FangYar.Model.TRAIN.T_TRAININGSCOREFLOW model_flow = new Model.TRAIN.T_TRAININGSCOREFLOW();
model_flow.ID = Guid.NewGuid().ToString("N");
model_flow.ORG_ID = org_id;
model_flow.TASKNAME = TestName;
model_flow.NUMBEROFPEOPLE = RecordCount;
model_flow.EMPCODE = emp_num;
model_flow.EMPNAME = name;
model_flow.RESULT = result;
model_flow.MANAGER = doman;
model_flow.UPTIME = time;
model_flow.UPTYPE = uptype;
bll_flow.Add(model_flow);
try
{
FangYar.FYMQTT.MQTT mqtt = new FangYar.FYMQTT.MQTT();
string aaa = System.Web.HttpUtility.UrlEncode(FangYar.Common.JsonHelper.ToJson(model_flow));
mqtt.messagePublished(System.Web.HttpUtility.UrlEncode(FangYar.Common.JsonHelper.ToJson(model_flow)), "trainingscore_"+org_id);
}
catch (Exception e) { }
}
catch (Exception e) { }
}
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;
}
}
}
}