软测单独项目
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.
 
 
 
 
 
 

566 lines
24 KiB

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Spire.Xls;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
namespace FangYar.WebUI.ashx
{
/// <summary>
/// OaLeaveHandler 的摘要说明
/// </summary>
public class TTaskHandler : IHttpHandler
{
private FangYar.BLL.TRAIN.T_TRAININGTASK bll = new BLL.TRAIN.T_TRAININGTASK();
private FangYar.BLL.TRAIN.T_SUBJECT subject_bll = new BLL.TRAIN.T_SUBJECT();
private FangYar.BLL.TRAIN.T_TRAININGSCORE score_bll = new BLL.TRAIN.T_TRAININGSCORE();
public void ProcessRequest(HttpContext context)
{
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "训练任务操作请求", "");
context.Response.ContentType = "text/plain";
string action = context.Request.Params["Action"];
string returnstr = "";
switch (action)
{
case "TTaskList":
returnstr = GetttaskList(context);
break;
case "Add":
returnstr = Addttask(context);
break;
case "Edit":
returnstr = Editttask(context);
break;
case "Del":
returnstr = Delttask(context);
break;
case "GetSubject":
returnstr = GetSubject(context);
break;
case "GetPlan":
returnstr = GetPlan(context);
break;
case "GetScoreListByTaskID":
returnstr = GetScoreListByTaskID(context);
break;
case "GetScoreListByTaskIDAndSubjectID":
returnstr = GetScoreListByTaskIDAndSubjectID(context);
break;
case "AddScore":
returnstr = AddScore(context);
break;
case "EditScore":
returnstr = EditScore(context);
break;
}
context.Response.Write(returnstr);
}
//查询
private string GetttaskList(HttpContext context)
{
string returnstr = "";
try
{
string OrgId = context.Request.Params["OrgId"];
string keyword = context.Request.Params["keywords"];
string treeID = context.Request.Params["treeID"];
string page = context.Request.Params["page"];
string limit = context.Request.Params["limit"];
string is_content = context.Request.Params["is_content"];
int pageIndex = 1;
int pageSize = 10;
int startIndex = 0;
int endIndex = 10;
if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); }
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
startIndex = (pageIndex - 1) * pageSize;
endIndex = pageSize;
string where = "1=1";
if (!string.IsNullOrEmpty(treeID) && treeID != OrgId)
{
if (is_content == "1")
{
where += " and org_id in ( select o.org_id from fire_org o,(select get_Org_child_list('" + treeID + "') cids ) s where find_in_set(org_id,cids)) ";
}
else
{
where += " and ORG_ID = '" + treeID + "'";
}
}
else
{
if (is_content == "1")
{
where += " and org_id in ( select o.org_id from fire_org o,(select get_Org_child_list('" + OrgId + "') cids ) s where find_in_set(org_id,cids)) ";
}
else
{
where += " and ORG_ID = '" + OrgId + "'";
}
}
if (!string.IsNullOrEmpty(keyword))
{
where += " and NAME like '%" + keyword + "%'";
}
returnstr = "{\"code\":0,\"msg\":\"\",";
int count = bll.GetRecordCount(where);
returnstr += "\"count\":" + count + ",\"data\":";
if (count == 0)
{
returnstr += "[]";
}
else
{
DataTable dt = bll.GetListByPage(where, "TRAINIGDATE desc", startIndex, endIndex).Tables[0];
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
}
returnstr += "}";
}
catch (Exception e)
{
returnstr = "{\"code\":0,\"" + e.Message + "\":\"error\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "训练任务操作请求", "查询异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "训练任务操作请求", "查询");
return returnstr;
}
//添加
private string Addttask(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string name = context.Request.Params["name"];
string PLANID = context.Request.Params["PLANID"];
string SUBJECTCONTENT = context.Request.Params["SUBJECTCONTENT"];
string SUBJECTCONTENT_NAME = context.Request.Params["SUBJECTCONTENT_NAME"];
string ISDISTINGUISHGENDER = context.Request.Params["ISDISTINGUISHGENDER"];
string TRAININGPERSON = context.Request.Params["TRAININGPERSON"];
string TRAININGPERSON_NAME = context.Request.Params["TRAININGPERSON_NAME"];
string TRAINIGDATE = context.Request.Params["TRAINIGDATE"];
string LEADTRAINING = context.Request.Params["LEADTRAINING"];
string org_id = context.Request.Params["org_id"];
string org_name = context.Request.Params["org_name"];
string LEADTRAINING_NAME = context.Request.Params["LEADTRAINING_NAME"];
string STATE = context.Request.Params["STATE"];
FangYar.Model.TRAIN.T_TRAININGTASK model = new Model.TRAIN.T_TRAININGTASK();
model.ID = Guid.NewGuid().ToString("N");
model.NAME = name;
model.PLANID = PLANID;
model.SUBJECTCONTENT = SUBJECTCONTENT;
model.ISDISTINGUISHGENDER = ISDISTINGUISHGENDER;
model.TRAININGPERSON = TRAININGPERSON;
model.ORG_ID = org_id;
model.ORG_NAME = org_name;
model.SUBJECTCONTENT_NAME = SUBJECTCONTENT_NAME;
model.TRAININGPERSON_NAME = TRAININGPERSON_NAME;
model.TRAINIGDATE = TRAINIGDATE;
model.LEADTRAINING = LEADTRAINING;
model.LEADTRAINING_NAME = LEADTRAINING_NAME;
model.STATE = STATE;
if (bll.Add(model))
{
msg = "添加成功!";
code = 1;
}
else { msg = "添加失败!"; }
}
catch (Exception e)
{
msg = e.Message;
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "训练任务操作请求", "添加");
return returnstr;
}
//修改
private string Editttask(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string id = context.Request.Params["ID"];
string name = context.Request.Params["name"];
string PLANID = context.Request.Params["PLANID"];
string SUBJECTCONTENT = context.Request.Params["SUBJECTCONTENT"];
string SUBJECTCONTENT_NAME = context.Request.Params["SUBJECTCONTENT_NAME"];
string ISDISTINGUISHGENDER = context.Request.Params["ISDISTINGUISHGENDER"];
string TRAININGPERSON = context.Request.Params["TRAININGPERSON"];
string TRAININGPERSON_NAME = context.Request.Params["TRAININGPERSON_NAME"];
string TRAINIGDATE = context.Request.Params["TRAINIGDATE"];
string LEADTRAINING = context.Request.Params["LEADTRAINING"];
string org_id = context.Request.Params["org_id"];
string org_name = context.Request.Params["org_name"];
string LEADTRAINING_NAME = context.Request.Params["LEADTRAINING_NAME"];
string STATE = context.Request.Params["STATE"];
FangYar.Model.TRAIN.T_TRAININGTASK model = new Model.TRAIN.T_TRAININGTASK();
model.ID = id;
model.NAME = name;
model.PLANID = PLANID;
model.SUBJECTCONTENT = SUBJECTCONTENT;
model.ISDISTINGUISHGENDER = ISDISTINGUISHGENDER;
model.TRAININGPERSON = TRAININGPERSON;
model.ORG_ID = org_id;
model.ORG_NAME = org_name;
model.SUBJECTCONTENT_NAME = SUBJECTCONTENT_NAME;
model.TRAININGPERSON_NAME = TRAININGPERSON_NAME;
model.TRAINIGDATE = TRAINIGDATE;
model.LEADTRAINING = LEADTRAINING;
model.LEADTRAINING_NAME = LEADTRAINING_NAME;
model.STATE = STATE;
if (bll.Update(model))
{
msg = "修改成功!";
code = 1;
}
else { msg = "修改失败!"; }
}
catch (Exception e)
{
msg = e.Message;
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "训练任务操作请求", "修改异常:" + e);
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "训练任务操作请求", "修改");
return returnstr;
}
//删除
private string Delttask(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string id = context.Request.Params["id"];
if (bll.Delete(id))
{
msg = "删除成功!";
code = 1;
}
else
{
msg = "删除失败!";
}
}
catch (Exception e)
{
msg = e.Message;
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "训练任务操作请求", "删除异常:" + e);
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "训练任务操作请求", "删除");
return returnstr;
}
//查询科目
private string GetSubject(HttpContext context)
{
string returnstr = "";
try
{
string OrgId = context.Request.Params["OrgId"];
returnstr = "{\"code\":1,\"成功\":\"error\",\"count\":0,\"data\":";
DataTable dt = subject_bll.GetList(" ORG_ID = '" + OrgId + "'").Tables[0];
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
returnstr += "}";
}
catch (Exception e)
{
returnstr = "{\"code\":0,\"" + e.Message + "\":\"error\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "训练任务操作请求", "查询科目异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "训练任务操作请求", "查询科目");
return returnstr;
}
//查询计划
private string GetPlan(HttpContext context)
{
string returnstr = "";
try
{
FangYar.BLL.TRAIN.T_TRAININGPLAN plan_bll = new BLL.TRAIN.T_TRAININGPLAN();
string OrgId = context.Request.Params["OrgId"];
returnstr = "{\"code\":1,\"成功\":\"error\",\"count\":0,\"data\":";
DataTable dt = plan_bll.GetList(" ORG_ID = '" + OrgId + "'").Tables[0];
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
returnstr += "}";
}
catch (Exception e)
{
returnstr = "{\"code\":0,\"" + e.Message + "\":\"error\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "训练任务操作请求", "查询计划异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "训练任务操作请求", "查询计划");
return returnstr;
}
//根据任务ID获取
private string GetScoreListByTaskID(HttpContext context)
{
string returnstr = "";
try
{
string TaskId = context.Request.Params["TaskId"];
FangYar.BLL.TRAIN.T_TRAININGSCORE score_bll = new BLL.TRAIN.T_TRAININGSCORE();
DataTable dt = score_bll.GetScoreListByTaskID(TaskId);
returnstr = "{\"code\":1,\"data\":";
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
returnstr += "}";
}
catch (Exception e)
{
returnstr = "{\"code\":-1,\"" + e.Message + "\":\"error\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "训练任务操作请求", "根据任务ID获取异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "训练任务操作请求", "根据任务ID获取");
return returnstr;
}
//根据任务ID、科目ID获取成绩列表
private string GetScoreListByTaskIDAndSubjectID(HttpContext context)
{
string returnstr = "";
try
{
string TaskId = context.Request.Params["TaskId"];
string SubjectId = context.Request.Params["SubjectId"];
FangYar.BLL.TRAIN.T_TRAININGSCORE score_bll = new BLL.TRAIN.T_TRAININGSCORE();
DataTable dt = score_bll.GetScoreListByTaskIDAndSubjectID(TaskId, SubjectId);
returnstr = "{\"code\":1,\"data\":";
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
returnstr += "}";
}
catch (Exception e)
{
returnstr = "{\"code\":-1,\"" + e.Message + "\":\"error\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "训练任务操作请求", "根据任务ID、科目ID获取成绩列表异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "训练任务操作请求", "根据任务ID、科目ID获取成绩列表");
return returnstr;
}
//添加成绩
private string AddScore(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string data = context.Request.Params["data"];
string taskid = "";
List<FangYar.Model.OA.CommonSql> ht = new List<FangYar.Model.OA.CommonSql>();
JObject jsonobj = JsonConvert.DeserializeObject<JObject>(data);
foreach (JObject obj in jsonobj.Value<JArray>("data0"))
{
FangYar.Model.TRAIN.T_TRAININGSCORE scoremodel = new Model.TRAIN.T_TRAININGSCORE();
scoremodel.ID = Guid.NewGuid().ToString("N");
scoremodel.USERS_UID = obj["uuid"].ToString();
scoremodel.USERS_NAME = obj["name"].ToString();
scoremodel.SUBJECTID = obj["subjectid"].ToString();
scoremodel.SUBJECTNAME = obj["subjectname"].ToString();
scoremodel.TRAINIGDATE = obj["traintime"].ToString();
scoremodel.TASKID = obj["taskid"].ToString();
scoremodel.TASKNAME = obj["taskname"].ToString();
scoremodel.RESULT = obj["result"].ToString();
scoremodel.ACHIEVEMENT = decimal.Parse(obj["achievement"].ToString() != "" ? obj["achievement"].ToString() : "0");
scoremodel.REPORTPERSONID = obj["reportuid"].ToString();
scoremodel.REPORTPERSONNAME = obj["reportname"].ToString();
scoremodel.REPORTTIME = DateTime.Now;
//scoremodel.REMARK = obj["remark"].ToString();
scoremodel.ORG_ID = obj["orgid"].ToString();
scoremodel.ORG_NAME = obj["orgname"].ToString();
taskid = scoremodel.TASKID;
FangYar.Model.OA.CommonSql scoreModel = score_bll.getInsertScoreSql(scoremodel);
ht.Add(scoreModel);
}
string filesurl = "";
int k = 0;
foreach (JObject obj in jsonobj.Value<JArray>("datax"))
{
if (k == 0)
{
filesurl += obj["fileurl"].ToString();
}
else
{
filesurl += "," + obj["fileurl"].ToString();
}
k++;
}
FangYar.Model.OA.CommonSql taskModel = bll.getUpdateTaskSql(taskid, filesurl);
ht.Add(taskModel);
if (FangYar.Common.MySqlHelper.ExecuteSqlTranBool(ht))
{
code = 1;
msg = "操作成功";
}
else
{
code = 0;
msg = "操作失败";
}
}
catch (Exception e)
{
msg = e.Message;
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "训练任务操作请求", "添加成绩异常:" + e);
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "训练任务操作请求", "添加成绩");
return returnstr;
}
//修改成绩
private string EditScore(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
try
{
string data = context.Request.Params["data"];
string task_id = context.Request.Params["task_id"];
List<FangYar.Model.OA.CommonSql> ht = new List<FangYar.Model.OA.CommonSql>();
FangYar.Model.OA.CommonSql deleteModel = score_bll.getDeleteScoreSql(task_id);
ht.Add(deleteModel);
JObject jsonobj = JsonConvert.DeserializeObject<JObject>(data);
foreach (JObject obj in jsonobj.Value<JArray>("data0"))
{
FangYar.Model.TRAIN.T_TRAININGSCORE scoremodel = new Model.TRAIN.T_TRAININGSCORE();
scoremodel.ID = Guid.NewGuid().ToString("N");
scoremodel.USERS_UID = obj["uuid"].ToString();
scoremodel.USERS_NAME = obj["name"].ToString();
scoremodel.SUBJECTID = obj["subjectid"].ToString();
scoremodel.SUBJECTNAME = obj["subjectname"].ToString();
scoremodel.TRAINIGDATE = obj["traintime"].ToString();
scoremodel.TASKID = obj["taskid"].ToString();
scoremodel.TASKNAME = obj["taskname"].ToString();
scoremodel.RESULT = obj["result"].ToString();
scoremodel.ACHIEVEMENT = decimal.Parse(obj["achievement"].ToString() != "" ? obj["achievement"].ToString() : "0");
scoremodel.REPORTPERSONID = obj["reportuid"].ToString();
scoremodel.REPORTPERSONNAME = obj["reportname"].ToString();
scoremodel.REPORTTIME = DateTime.Now;
//scoremodel.REMARK = obj["remark"].ToString();
scoremodel.ORG_ID = obj["orgid"].ToString();
scoremodel.ORG_NAME = obj["orgname"].ToString();
FangYar.Model.OA.CommonSql scoreModel = score_bll.getInsertScoreSql(scoremodel);
ht.Add(scoreModel);
}
string filesurl = "";
int k = 0;
foreach (JObject obj in jsonobj.Value<JArray>("datax"))
{
if (k == 0)
{
filesurl += obj["fileurl"].ToString();
}
else
{
filesurl += "," + obj["fileurl"].ToString();
}
k++;
}
FangYar.Model.OA.CommonSql taskModel = bll.getUpdateTaskSql(task_id, filesurl);
ht.Add(taskModel);
if (FangYar.Common.MySqlHelper.ExecuteSqlTranBool(ht))
{
code = 1;
msg = "操作成功";
}
else
{
code = 0;
msg = "操作失败";
}
}
catch (Exception e)
{
msg = e.Message;
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "训练任务操作请求", "修改成绩异常:" + e);
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "训练任务操作请求", "修改成绩");
return returnstr;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}