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.
410 lines
18 KiB
410 lines
18 KiB
using FangYar.Model.TRAIN;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace HardWareInteface.TrainHandle
|
|
{
|
|
|
|
/// <summary>
|
|
/// 阿里的战训设备接口
|
|
/// </summary>
|
|
public class TrainQueueTaskAl
|
|
{
|
|
public const string subjectOrg = "D8DC637B8B984848A63F82A018AFAEB0";
|
|
|
|
public static ConcurrentQueue<infoModel> infoQueue = new ConcurrentQueue<infoModel>();
|
|
|
|
private static CancellationTokenSource m_DealToken = new CancellationTokenSource();
|
|
private static Task m_DealTask = Task.Factory.StartNew(DealInfoList, m_DealToken.Token);
|
|
|
|
public static void infoQueueFun(infoModel data)
|
|
{
|
|
try
|
|
{
|
|
infoQueue.Enqueue(data); //添加
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
WriteLog(e.Message, data.LogPath);
|
|
}
|
|
WriteLog("队列长度:" + infoQueue.Count.ToString(), data.LogPath);
|
|
}
|
|
|
|
|
|
private static void DealInfoList()
|
|
{
|
|
while (!m_DealToken.IsCancellationRequested)
|
|
{
|
|
infoModel dataInfo = null;
|
|
if (infoQueue.TryDequeue(out dataInfo))
|
|
{
|
|
try
|
|
{
|
|
DealInfo(dataInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WriteLog(ex.Source + ex.StackTrace + ex.Message + "DealInfoList_Error", dataInfo.LogPath);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(100);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void DealInfo(infoModel infomodel)
|
|
{
|
|
string strLog = "";
|
|
try
|
|
{
|
|
strLog += "进入DealInfo" + "\r\n";
|
|
string TestName = matchingSubject(infomodel.TestName);
|
|
string RecordCount = infomodel.RecordCount;
|
|
string ResultInfo = infomodel.ResultInfo;
|
|
string org_id = infomodel.OrgId;
|
|
int upTrue = 0, upFalse = 0;
|
|
string taskArr = "";
|
|
|
|
#region
|
|
if (Convert.ToInt32(RecordCount) > 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];
|
|
|
|
|
|
string updateScoreSql = "update train_score set result = '" + result + "'" +
|
|
" ,reportperson_name = '" + doman + "'" +
|
|
" ,report_time = '" + time + "'" +
|
|
" ,source_type = 3" +
|
|
" where extend1 = '" + emp_num + "'";
|
|
|
|
int a = FangYar.Common.MySqlHelper.Execute(updateScoreSql);
|
|
|
|
////获取训练成绩 获取该人员的最新的一条训练成绩
|
|
//string scoreSql = "SELECT ts.id,ts.task_id FROM train_score ts left join train_task tt on ts.task_id = tt.id" +
|
|
// " WHERE ts.org_id = '" + org_id + "'" +
|
|
// " and ts.emp_id = '" + emp_num + "' and ts.subject_name = '" + TestName + "' " +
|
|
// " and (tt.state = 0 or tt.state = 1)" +
|
|
// " and (ts.result is null or result = '') and (ts.score is null or ts.score = '')" +
|
|
// " and (ts.remark is null or remark = '') ORDER BY ts.training_date DESC LIMIT 0,1";
|
|
//DataTable dt_task = FangYar.Common.MySqlHelper.Query(scoreSql).Tables[0];
|
|
|
|
//if (dt_task.Rows.Count == 0)
|
|
//{
|
|
// strLog += "获取到此人(" + name + ")的训练成绩信息为空:" + ResultInfos[i].ToString() + "\r\n";
|
|
// ScoreFlow(org_id, TestName, RecordCount, emp_num, name, result, doman, time, "2");//将成绩流水入库 1:存在任务中 2: 不存在任务
|
|
// continue;
|
|
//}
|
|
//else
|
|
//{
|
|
// strLog += "存在此人(" + name + ")的训练成绩\r\n";
|
|
// ScoreFlow(org_id, TestName, RecordCount, emp_num, name, result, doman, time, "1");//将成绩流水入库 1:存在任务中 2: 不存在任务
|
|
//}
|
|
|
|
|
|
|
|
//string scoreId = dt_task.Rows[0]["ID"].ToString();
|
|
//string taskId = dt_task.Rows[0]["TASK_ID"].ToString();
|
|
//if (!taskArr.Contains(taskId)) { taskArr += taskId + ","; }
|
|
//string updateScoreSql = "update train_score set result = '" + result + "'" +
|
|
// " ,reportperson_name = '" + doman + "'" +
|
|
// " ,report_time = '" + time + "'" +
|
|
// " ,source_type = 3" +
|
|
// " where id = '" + scoreId + "'";
|
|
|
|
//int a = FangYar.Common.MySqlHelper.Execute(updateScoreSql);
|
|
var flag = true;
|
|
if (a >= 1) {
|
|
upTrue += a;
|
|
} else {
|
|
upFalse += a;
|
|
flag = false;
|
|
}
|
|
strLog += "成绩表 extend1编号:" + emp_num + ",操作:" + flag + "\r\n";
|
|
|
|
/**
|
|
* 修改训练任务状态
|
|
* 屏蔽原因:只上报了结果未上报得分,还需要在平台进行编辑,所以不能改任务状态。
|
|
*/
|
|
//string updateTaskSql = "update train_task set state = 2" +
|
|
// " where id = '" + taskId + "'";
|
|
//int b = FangYar.Common.MySqlHelper.Execute(updateScoreSql);
|
|
//upScoreNum += b;
|
|
//flag = b >= 1 ? true : false;
|
|
//strLog += "任务ID:" + scoreId + ",操作:" + flag + "\r\n";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
strLog += "Exception 循环内部:" + e.Message + "\r\n";
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
strLog += "成功:" + upTrue + "(条),失败:" + upFalse + "(条)\r\n";
|
|
strLog += "任务ID集合:" + taskArr + "\r\n";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
strLog += "Exception:" + e.Message + "\r\n";
|
|
}
|
|
WriteLog(strLog, infomodel.LogPath);
|
|
}
|
|
|
|
////根据userId,subjectId计算得分
|
|
//private static string calculateAchievement(DataTable dt_task)
|
|
//{
|
|
// string strLog = "";
|
|
|
|
// //获取人员信息
|
|
// FangYar.Model.TBL.TBL_SYS_EMP_Model model_emp = new FangYar.Model.TBL.TBL_SYS_EMP_Model();
|
|
// FangYar.BLL.TBL.SysEmpBLL bll_emp = new FangYar.BLL.TBL.SysEmpBLL();
|
|
// model_emp = bll_emp.GetModelByUID(emp_num);
|
|
// if (model_emp == null)
|
|
// {
|
|
// strLog += "获取到人员信息为空;" + "\r\n";
|
|
// }
|
|
|
|
// 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 FangYar.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;
|
|
// }
|
|
// }
|
|
// return "";
|
|
//}
|
|
|
|
//获取匹配的系统训练科目
|
|
private static string matchingSubject(string subjectName)
|
|
{
|
|
string _subjectName = subjectName;
|
|
switch (subjectName)
|
|
{
|
|
case "俯卧撑":
|
|
_subjectName = "男子俯卧撑";
|
|
break;
|
|
case "屈腿仰卧起坐":
|
|
_subjectName = "男子屈腿仰卧起坐";
|
|
break;
|
|
case "100米负重跑":
|
|
_subjectName = "男子100米负重跑";
|
|
break;
|
|
case "单杠卷身上":
|
|
_subjectName = "男子单杠卷身上";
|
|
break;
|
|
case "双杠臂屈伸":
|
|
_subjectName = "男子双杠臂屈伸";
|
|
break;
|
|
case "绳索攀爬":
|
|
_subjectName = "男子4楼攀爬绳索";
|
|
break;
|
|
case "30米×2蛇形跑":
|
|
_subjectName = "男子30×2蛇形跑";
|
|
break;
|
|
}
|
|
return _subjectName;
|
|
}
|
|
|
|
|
|
/// <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 static void ScoreFlow(string org_id, string TestName, string RecordCount, string emp_num, string name, string result, string doman, string time, string uptype)
|
|
{
|
|
try
|
|
{
|
|
string scoreFlowId = Guid.NewGuid().ToString("N");
|
|
FangYar.Model.TRAIN.T_TRAININGSCOREFLOW model_flow = new FangYar.Model.TRAIN.T_TRAININGSCOREFLOW();
|
|
model_flow.ID = scoreFlowId;
|
|
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;
|
|
|
|
string addScoreFlowSql = "insert into train_score_flow(id,org_id,task_name,person_num,emp_code,emp_name,result,manager,up_time,up_type,extend1) values('" + scoreFlowId + "','" + org_id + "','" + TestName + "','"+ RecordCount + "','"+ emp_num + "','"+ name + "','"+ result + "','"+ doman + "','"+ time + "','"+ uptype + "','"+ DateTime.Now.ToString() + "')";
|
|
FangYar.Common.MySqlHelper.Execute(addScoreFlowSql);
|
|
|
|
try
|
|
{
|
|
FangYar.FYMQTT.MQTT mqtt = new FangYar.FYMQTT.MQTT();
|
|
mqtt.messagePublished(System.Web.HttpUtility.UrlEncode(FangYar.Common.JsonHelper.ToJson(model_flow)), "trainingscore_" + org_id);
|
|
|
|
}
|
|
catch (Exception e) { }
|
|
}
|
|
catch (Exception e) { }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 输出日志
|
|
/// </summary>
|
|
static ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim();
|
|
private static void WriteLog(string msg, string logPath)
|
|
{
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = msg, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "TrainTMQData\\" + logPath });
|
|
|
|
//try
|
|
//{
|
|
// LogWriteLock.EnterWriteLock();
|
|
|
|
// string path = AppDomain.CurrentDomain.BaseDirectory + "log\\TrainTMQData\\" + logPath + "\\数据处理\\";
|
|
// string filename = DateTime.Now.ToString("yyyyMMdd") + ".txt";
|
|
|
|
// if (Directory.Exists(path) == false)//如果不存在就创建文件夹
|
|
// {
|
|
// Directory.CreateDirectory(path);
|
|
// }
|
|
// FileInfo file = new FileInfo(path + filename);
|
|
// if (!file.Exists)
|
|
// {
|
|
// try
|
|
// {
|
|
// FileStream fs;
|
|
// fs = File.Create(path + filename);
|
|
// fs.Close();
|
|
// }
|
|
// catch
|
|
// {
|
|
|
|
// }
|
|
// }
|
|
|
|
// using (FileStream fs = new FileStream(path + filename, FileMode.Append, FileAccess.Write))
|
|
// {
|
|
// using (StreamWriter sw = new StreamWriter(fs))
|
|
// {
|
|
// sw.WriteLine("时间:" + DateTime.Now.ToString() + " 信息:" + msg);
|
|
// }
|
|
// }
|
|
//}
|
|
//catch (Exception e)
|
|
//{
|
|
|
|
//}
|
|
//finally
|
|
//{
|
|
// LogWriteLock.ExitWriteLock();
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
}
|