gyhlw_dotnet/网站项目/VRS/Handler/SubjectResult.ashx.cs

357 lines
17 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace VRS.Handler
{
/// <summary>
/// 科目成绩写入接口
/// http://192.168.1.105:8001/Handler/SubjectResult.ashx?subjectid=10002&loginname=xy1001&totalresult=27&content=备注&mode=0&time=2020-1-1
///subjectid:科目id
///loginname:登录账号
///totalresult:成绩
///mode:考核类型 0 测验(实习)1 考试
///content:备注内容
///time:考核时间
/// </summary>
public class SubjectResult : BasePage, IHttpHandler
{
DataService.BLL.admin_user bll_user = new DataService.BLL.admin_user();
DataService.BLL.pro_subject bll_subject = new DataService.BLL.pro_subject();
DataService.BLL.admin_log log = new DataService.BLL.admin_log();
DataService.BLL.pro_result pro_result = new DataService.BLL.pro_result();
DataService.BLL.pro_result_detail pro_result_detail = new DataService.BLL.pro_result_detail();
DataService.BLL.pro_subject_proc bll_subject_proc = new DataService.BLL.pro_subject_proc();
DataService.BLL.pro_flow bll_pro_flow = new DataService.BLL.pro_flow();
DataService.BLL.pro_fault bll_fault = new DataService.BLL.pro_fault();
DataService.BLL.pro_exam_batch bll_batch = new DataService.BLL.pro_exam_batch();
DataService.BLL.pro_subject_batch_user bll_subject_batch_user = new DataService.BLL.pro_subject_batch_user();
DataService.BLL.pro_fault_batch_user bll_fault_batch_user = new DataService.BLL.pro_fault_batch_user();
public override void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string subject_id = context.Request.Params["subjectid"];//科目id
string login_name = context.Request.Params["loginname"];//登录账号
string total_result = context.Request.Params["totalresult"]; //成绩
//string mode = context.Request.Params["mode"]; // 考核类型 0 测验(实习)1 考试
string content = context.Request.Params["content"]; //考试内容
string fault_code = context.Request.Params["fault_code"]; //备注内容
var user = bll_user.GetModelByJobNumber(login_name);
if (null == user)
{
context.Response.Write(GetJsonWithCode(APICode.Fail, "登录账号:" + login_name + ",的学员不存在!"));
context.Response.End();
}
var model_subject = bll_subject.GetModel(subject_id);
if (null == model_subject)
{
log.write_user_log(user, "学员姓名:" + user.real_name + ",学员学号:" + login_name + ",提交科目成绩,科目不存在," + "科目id:" + subject_id);
context.Response.Write(GetJsonWithCode(APICode.Fail, "科目不存在:" + "科目id:" + subject_id));
context.Response.End();
}
log.write_user_log(user, "科目名称:" + model_subject.subject_name + "科目id:" + subject_id + ",学员账号:" + login_name + ",成绩:" + total_result + ",内容:" + content);
bool state = false;
var model = new DataService.Model.pro_result();
var batch = bll_batch.GetModelList(" state =1 ").FirstOrDefault();
if (null == batch)
{
log.write_user_log(user, "学员姓名:" + user.real_name + ",学员学号:" + login_name + ",科目考试批次不存在或未启用!科目:"+ model_subject.subject_name);
context.Response.Write(GetJsonWithCode(APICode.Fail, "学员姓名:" + user.real_name + ",学员学号:" + login_name + ",科目考试批次不存在或未启用!"));
context.Response.End();
}
//故障科目
if (subject_id == "10003")
{
var exist_fault_batch_user = bll_fault_batch_user.GetModelList(" login_name = '" + login_name + "' and batch_id = '" + batch.batch_id + "'").FirstOrDefault();
if (null == exist_fault_batch_user)
{
log.write_user_log(user, "学员姓名:" + user.real_name + ",学员学号:" + login_name +"批次id"+ batch.batch_id+",批次名称:" + batch.batch_name + ",该批次未配置科目:"+model_subject.subject_name);
context.Response.Write(GetJsonWithCode(APICode.Fail, "学员姓名:" + user.real_name + ",学员学号:" + login_name + ",该批次未配置科目!"));
context.Response.End();
}
fault_code = exist_fault_batch_user.fault_code;
}
else //其他科目
{
var exist_subject_batch_user = bll_subject_batch_user.GetModelList(" login_name='" + login_name + "' and batch_id='" + batch.batch_id + "' and subject_id='" + subject_id + "'").FirstOrDefault();
if (null == exist_subject_batch_user)
{
log.write_user_log(user, "学员姓名:" + user.real_name + ",学员学号:" + login_name + "批次id" + batch.batch_id + ",批次名称:" + batch.batch_name + ",该批次未配置科目:" + model_subject.subject_name);
context.Response.Write(GetJsonWithCode(APICode.Fail, "学员姓名:" + user.real_name + ",学员学号:" + login_name + ",该批次未配置科目!"));
context.Response.End();
}
}
var fault_list = bll_fault.GetModelList(" fault_code='" + fault_code + "' ");
var result = pro_result.GetModelList(" user_id='" + user.user_id + "' and batch_id='" + batch.batch_id + "' and subject_id='" + subject_id + "'").FirstOrDefault();
if (null != result)
{
var fault_desc = "";
if (!string.IsNullOrEmpty(fault_code))
{
fault_desc = ",故障点编码:" + fault_code;
}
log.write_user_log(user, "学员姓名:" + user.real_name + ",学员学号:" + login_name + ",科目考试已经考过试!科目名称:" + result.subject_name + "科目id" + result.subject_id + ",得分:" + result.total_result + fault_desc);
context.Response.Write(GetJsonWithCode(APICode.Fail, "学员姓名:" + user.real_name + ",学员学号:" + login_name + ",科目考试已经考过试!"));
context.Response.End();
}
if (!string.IsNullOrWhiteSpace(subject_id) && !string.IsNullOrWhiteSpace(login_name))
{
try
{
DataService.BLL.pro_result bll = new DataService.BLL.pro_result();
var config = GetSystemConfig(System.Configuration.ConfigurationManager.AppSettings["SystemName"].ToString());
model.result_id = GetNewId();
var dt_time = DateTime.Now;
model.examine_time = dt_time;
model.subject_id = subject_id;
model.subject_name = model_subject.subject_name;
model.login_name = user.login_name;
model.real_name = user.real_name;
if (null != batch)
{
model.batch_id = batch.batch_id;
model.batch_name = batch.batch_name;
model.sjms = batch.sjms;
}
if (fault_list.Count > 0)
{
model.fault_code = fault_list[0].fault_code;
model.fault_name = fault_list[0].fault_name;
}
int examine_type = 1;
//int.TryParse(mode, out examine_type);
//detail_id, result_id, step, score, result, r1, r2, r3
//15:拆解软波导,5$14:拆解双工器,5$17:拆解天线头,5
var array = content.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries);
decimal total_score = 0;
List<string> list_pass_tips = new List<string>();
#region
foreach (var item in array)
{
var sub_array = item.Split(',');
var tip_array = sub_array[0].Split(':');
var detail = new DataService.Model.pro_result_detail();
detail.detail_id = GetNewId();
detail.result_id = model.result_id;
detail.step = int.Parse(tip_array[0]);
detail.tip = tip_array[1];
detail.examine_time = dt_time;
detail.subject_id = subject_id;
detail.subject_name = model_subject.subject_name;
detail.user_id = user.user_id;
detail.login_name = user.login_name;
detail.real_name = user.real_name;
if (fault_list.Count > 0)
{
detail.fault_code = fault_list[0].fault_code;
detail.fault_name = fault_list[0].fault_name;
}
if (null != batch)
{
detail.batch_id = batch.batch_id;
detail.batch_name = batch.batch_name;
detail.sjms = batch.sjms;
}
list_pass_tips.Add(tip_array[1]);
//detail.score = int.Parse(sub_array[1]);
detail.score = get_score(subject_id, tip_array[1], fault_code);
if (detail.score <= 0)
{
var fault_desc = "";
if (!string.IsNullOrEmpty(fault_code))
{
fault_desc = ",故障点编码:" + fault_code;
}
log.write_user_log(user, "学员姓名:" + user.real_name + ",学员学号:" + login_name + "科目id" + model_subject.subject_id + ",科目名称:" + model_subject.subject_name + "。步骤提示(tip)" + tip_array[1] + ",该步骤没有配置得分 " + fault_desc);
}
total_score += detail.score;
pro_result_detail.Add(detail);
}
#endregion
//添加没有得分的步骤
if (string.IsNullOrEmpty(fault_code))
{
add_fail_tips(batch, user, subject_id, model_subject.subject_name, model.result_id, list_pass_tips, fault_list, dt_time, config);
}
else
{
add_fault_fail_tips(batch, user, subject_id, model_subject.subject_name, model.result_id, list_pass_tips, fault_list, dt_time, config, fault_code);
}
model.examine_type = examine_type;
model.user_id = user.user_id;
model.practice_content = content;
model.exam_year = DateTime.Now.Year;
model.exam_month = DateTime.Now.Month;
//int score = 0;
//int.TryParse(total_result, out score);
//model.total_result = score;
model.total_result = total_score;
var flag = bll.Add(model);
}
catch (Exception ex)
{
log.write_user_log(user, "Error科目名称" + model_subject.subject_name + "科目id:" + subject_id + ",学员账号:" + login_name + ",成绩:" + total_result + ",内容:" + content + ",错误:" + ex.Message);
context.Response.Write(GetJsonWithCode(APICode.Fail, ex.ToString()));
context.Response.End();
}
state = true;
context.Response.Write(GetJsonWithCode(APICode.Success, model));
context.Response.End();
}
if (!state)
{
context.Response.Write(GetJsonWithCode(APICode.Fail, ""));
context.Response.End();
}
}
public decimal get_score(string subject_id, string tip, string fault_code)
{
if (string.IsNullOrEmpty(fault_code))
{
var list = bll_subject_proc.GetModelList(" tip='" + tip + "' and subject_id='" + subject_id + "' ");
if (list.Count > 0)
{
return list[0].score;
}
}
else
{
var list = bll_subject_proc.GetModelList(" tip='" + tip + "' and subject_id='" + subject_id + "' and fault_code='" + fault_code + "'");
if (list.Count > 0)
{
return list[0].score;
}
}
return 0;
}
public void add_fail_tips(DataService.Model.pro_exam_batch batch, DataService.Model.admin_user user, string subject_id, string subject_name, string result_id, List<string> list_pass_tips, List<DataService.Model.pro_fault> fault_list, DateTime examine_time, DataService.Model.admin_config config)
{
var list = bll_pro_flow.GetModelList(" subject_id='" + subject_id + "' ").OrderBy(s => s.step).ToList();
var array = list_pass_tips.ToArray();
var fail_list = list.Where(s => !array.Contains(s.tip)).ToList();
foreach (var item in fail_list)
{
var detail = new DataService.Model.pro_result_detail();
detail.subject_id = subject_id;
detail.subject_name = subject_name;
detail.detail_id = GetNewId();
detail.result_id = result_id;
detail.step = item.step;
detail.tip = item.tip;
detail.score = 0;
detail.user_id = user.user_id;
detail.login_name = user.login_name;
detail.real_name = user.real_name;
detail.examine_time = examine_time;
if (fault_list.Count > 0)
{
detail.fault_code = fault_list[0].fault_code;
detail.fault_name = fault_list[0].fault_name;
}
if (null != batch)
{
detail.batch_id = batch.batch_id;
detail.batch_name = batch.batch_name;
detail.sjms = batch.sjms;
}
pro_result_detail.Add(detail);
}
}
/// <summary>
/// 添加故障失败步骤
/// </summary>
/// <param name="user"></param>
/// <param name="subject_id"></param>
/// <param name="subject_name"></param>
/// <param name="result_id"></param>
/// <param name="list_pass_tips"></param>
/// <param name="fault_list"></param>
/// <param name="examine_time"></param>
/// <param name="config"></param>
/// <param name="fault_code"></param>
public void add_fault_fail_tips(DataService.Model.pro_exam_batch batch, DataService.Model.admin_user user, string subject_id, string subject_name, string result_id, List<string> list_pass_tips, List<DataService.Model.pro_fault> fault_list, DateTime examine_time, DataService.Model.admin_config config, string fault_code)
{
var list = bll_subject_proc.GetModelList(" subject_id='" + subject_id + "' " + " and fault_code='" + fault_code + "' ").OrderBy(s => s.step).ToList();
var array = list_pass_tips.ToArray();
var fail_list = list.Where(s => !array.Contains(s.tip)).ToList();
foreach (var item in fail_list)
{
var detail = new DataService.Model.pro_result_detail();
detail.subject_id = subject_id;
detail.subject_name = subject_name;
detail.detail_id = GetNewId();
detail.result_id = result_id;
detail.step = item.step;
detail.tip = item.tip;
detail.score = 0;
detail.user_id = user.user_id;
detail.login_name = user.login_name;
detail.real_name = user.real_name;
detail.examine_time = examine_time;
if (fault_list.Count > 0)
{
detail.fault_code = fault_list[0].fault_code;
detail.fault_name = fault_list[0].fault_name;
}
if (null != batch)
{
detail.batch_id = batch.batch_id;
detail.batch_name = batch.batch_name;
detail.sjms = batch.sjms;
}
pro_result_detail.Add(detail);
}
}
public new bool IsReusable
{
get
{
return false;
}
}
}
}