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.
442 lines
21 KiB
442 lines
21 KiB
using FangYar.Model.TRAIN;
|
|
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 TrainQueueTaskSn
|
|
{
|
|
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 scoreSql = "select sc.id,sc.task_id,sc.org_id,sc.emp_id,sc.subject_id,sc.unit_measuremen,sub.is_altitude from train_score sc left join train_subject sub on sc.subject_id = sub.id where sc.extend1 = '" + emp_num + "'";
|
|
DataTable scoreDt = FangYar.Common.MySqlHelper.Query(scoreSql).Tables[0];
|
|
var flag = true;
|
|
|
|
if (scoreDt.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 = scoreDt.Rows[0]["ID"].ToString();
|
|
string taskId = scoreDt.Rows[0]["TASK_ID"].ToString();
|
|
string orgId = scoreDt.Rows[0]["ORG_ID"].ToString();
|
|
string empId = scoreDt.Rows[0]["EMP_ID"].ToString();
|
|
string subjectId = scoreDt.Rows[0]["SUBJECT_ID"].ToString();
|
|
string unitMeasuremen = scoreDt.Rows[0]["UNIT_MEASUREMEN"].ToString();
|
|
string isAltitude = scoreDt.Rows[0]["IS_ALTITUDE"].ToString();
|
|
|
|
if (!taskArr.Contains(taskId)) { taskArr += taskId + ","; }
|
|
|
|
string empSql = "select e.birthday,o.altitude from tbl_sys_emp e left join fire_org o on e.org_id = o.org_id where e.id = '"+ empId + "'";
|
|
DataTable empDt = FangYar.Common.MySqlHelper.QueryTable(empSql);
|
|
|
|
if (empDt.Rows.Count > 0) //判断是否已经存入该条数据,并获取参训人基本信息
|
|
{
|
|
int scoreInt = 0;
|
|
try
|
|
{
|
|
string standardScore = "", birthday = empDt.Rows[0]["BIRTHDAY"].ToString(), altitude = empDt.Rows[0]["ALTITUDE"].ToString();
|
|
if (birthday.Contains("-"))
|
|
{
|
|
try
|
|
{
|
|
int empAge = CalculateAgeString(Convert.ToDateTime(birthday), DateTime.Now);
|
|
if (unitMeasuremen == "0")
|
|
{
|
|
if (result.Contains("\""))
|
|
{
|
|
result = result.Replace("\"", "秒");
|
|
}
|
|
if (result.Contains("'"))
|
|
{
|
|
result = result.Replace("''", "秒");
|
|
result = result.Replace("'", "分");
|
|
}
|
|
}
|
|
standardScore = standardCalculation(result, subjectId, altitude, empAge, unitMeasuremen, isAltitude);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
strLog += name + "," + TestName + "," + birthday + ";年龄计算报错!\r\n";
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(standardScore))
|
|
{
|
|
scoreInt = Convert.ToInt32(standardScore);
|
|
}
|
|
else
|
|
{
|
|
scoreInt = 0;
|
|
}
|
|
|
|
if (scoreInt <= 100 && scoreInt >= 0)
|
|
{
|
|
result = result.Replace("'", "").Trim();
|
|
string updateScoreSql = "update train_score set " +
|
|
" result = '" + result + "'" +
|
|
" ,score=" + scoreInt +
|
|
" ,reportperson_name = '" + doman + "'" +
|
|
" ,report_time = '" + time + "'" +
|
|
" ,source_type = 3" +
|
|
" where extend1 = '" + emp_num + "'";
|
|
int a = FangYar.Common.MySqlHelper.Execute(updateScoreSql);
|
|
|
|
if (a >= 1)
|
|
{
|
|
upTrue += a;
|
|
}
|
|
else
|
|
{
|
|
upFalse += a;
|
|
flag = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
strLog += name + "," + TestName + ";数据有误得分区间应为0~100!\r\n";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
strLog += name + "," + TestName + ";数据有误不是正整数!\r\n";
|
|
}
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
|
|
//获取匹配的系统训练科目
|
|
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;
|
|
}
|
|
|
|
// 计算年龄字符串(周岁)
|
|
private static 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;
|
|
|
|
}
|
|
|
|
//根据科目ID获取评分标准,并计算得分
|
|
private static string standardCalculation(string result, string subjectId, string altitude, int empAge, string unitMeasuremen, string isAltitude)
|
|
{
|
|
try
|
|
{
|
|
string orderByStr = " order by calculation_lower+0 desc", millisecond = "", altitudeLower = altitude, altitudeUpper = altitude;
|
|
if (isAltitude == "0")
|
|
{
|
|
altitudeLower = "0";
|
|
altitudeUpper = "10000";
|
|
}
|
|
if (unitMeasuremen == "0")
|
|
{
|
|
orderByStr = " order by calculation_lower+0";
|
|
|
|
string minuthTIme = string.Empty;
|
|
string secondTime = string.Empty;
|
|
string milliSeconds = string.Empty;
|
|
string resultShow = string.Empty;
|
|
|
|
int a = result.IndexOf(".");
|
|
|
|
if (a < 0)
|
|
{
|
|
result = "0." + result;
|
|
}
|
|
string[] arr2 = result.Split('.');
|
|
secondTime = string.IsNullOrWhiteSpace(arr2[0]) ? "0" : arr2[0];
|
|
milliSeconds = string.IsNullOrWhiteSpace(arr2[1]) ? "0" : arr2[1];
|
|
millisecond = (Convert.ToInt32(secondTime) * 1000 + (milliSeconds.Length == 0 ? 0 : (milliSeconds.Length == 1 ? Convert.ToInt32(milliSeconds) * 100 : (milliSeconds.Length == 2 ? Convert.ToInt32(milliSeconds) * 10 : Convert.ToInt32(milliSeconds))))).ToString();
|
|
}
|
|
|
|
string getStandardSql = "select calculation_lower,achievement_lower from train_scoring_standard where subjectid = '" + subjectId + "' and altitude_lower <= '" + altitudeLower + "' and altitude_upper >= '" + altitudeUpper + "' and age_lower <= '" + empAge + "' and age_upper >= '" + empAge + "' " + orderByStr;
|
|
DataTable getStandard = FangYar.Common.MySqlHelper.QueryTable(getStandardSql);
|
|
|
|
foreach (DataRow row in getStandard.Rows)
|
|
{
|
|
string calculationLower = row["CALCULATION_LOWER"].ToString();
|
|
string achievementLower = row["ACHIEVEMENT_LOWER"].ToString();
|
|
if (unitMeasuremen == "0")
|
|
{
|
|
//时间:速度越快得分越高
|
|
if (Convert.ToInt32(millisecond) <= Convert.ToInt32(calculationLower))
|
|
{
|
|
return achievementLower;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//次数:次数越多得分越高
|
|
if (Convert.ToInt32(result) >= Convert.ToInt32(calculationLower))
|
|
{
|
|
return achievementLower;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return "";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
// 将成绩流水入库
|
|
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();
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
}
|