CompetitionAPI_dotnet/CompetitionAPI/Controllers/ExamController.cs

1058 lines
43 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 Competition.Common.Util;
using Competition.Mysql.Model;
using CompetitionAPI.Util;
using Maticsoft.DBUtility;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NPOI.OpenXml4Net.OPC.Internal;
using NPOI.OpenXmlFormats.Shared;
using System.Diagnostics;
using System.Globalization;
using System.Transactions;
namespace CompetitionAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ExamController : BaseHandlerController
{
//Competition.Mysql.BLL.app_power_plan bll = new Competition.Mysql.BLL.app_power_plan();
Competition.Mysql.BLL.app_client_collect bll_client_collect = new Competition.Mysql.BLL.app_client_collect();
Competition.Mysql.BLL.app_exam_cache bll = new Competition.Mysql.BLL.app_exam_cache();
Competition.Mysql.BLL.app_data_cache bll_data_cache = new Competition.Mysql.BLL.app_data_cache();
Competition.Mysql.BLL.app_exam_answer bll_exam_answer = new Competition.Mysql.BLL.app_exam_answer();
private readonly ILogger<ExamController> _logger;
private readonly IWebHostEnvironment _env;
public ExamController(IHttpContextAccessor IHttpContextAccessor, IWebHostEnvironment env, IConfiguration iconfiguration, ILogger<ExamController> logger)
{
Configuration = iconfiguration;
_env = env;
_logger = logger;
context = IHttpContextAccessor.HttpContext!;
CrossDomain();
}
//[Authorize]
/// <summary>
/// 查询所有信息
/// </summary>
[Route("All")]
public JsonResult QueryALL()
{
/*
client_id varchar(50) 客户收资id,
power_unit varchar(255) 供电单位,
user_name varchar(255) 用电户名称,
contact_man varchar(255) 联系人,
contact_mobile varchar(255) 联系方式,
user_no varchar(50) 用户编号,
address varchar(255) 用电地址,
id_card varchar(50) 证件号码,
need_type varchar(255) 需求类型,
user_type varchar(255) 用电户分类,
power_voltage_client varchar(255) 供电电压(现场勘察),
city_type varchar(255) 城乡类别(特殊边远地区、农村、城市),
use_power_type varchar(255) 用电类别(乡村居民生活用电,城镇居民生活用电),
temp_power_flag varchar(255) 临时用电标志,
apply_capacity varchar(255) 申请容量,
is_start_power varchar(255) 是否可供电,
verify_capacity varchar(255) 核定合计用电容量,
is_new_point varchar(255) 是否新增接入点,
is_config_project varchar(255) 是否有配套工程,
has_project_flag varchar(255) 有工程标志,
zhuangong_flag varchar(255) 转供标志,
if_jiakong varchar(255) 是否架空,
fuhe_nature varchar(255) 负荷性质,
check_man varchar(255) 勘察人员,
check_date varchar(255) 勘察日期,
is_fee_control varchar(255) 是否费控用户,
check_idea varchar(255) 勘察意见,
power_type varchar(255) 电源类型,
power_nature varchar(255) 电源性质,
power_phase varchar(255) 电源相数,
power_voltage_powerplan varchar(255) 供电电压(电源方案),
in_line_type varchar(255) 进线方式,
protect_type varchar(255) 保护方式,
power_capacity varchar(255) 供电容量,
station_line_taiqu varchar(255) 变电站/线路/台区,
in_line_no varchar(255) 进线杆号/电缆分支箱,
property_split varchar(255) 产权分界点,
measure_name varchar(255) 计量点名称,
measure_type varchar(255) 计量点分类,
measure_nature varchar(255) 计量点性质,
measure_way varchar(255) 计量方式,
main_use varchar(255) 主用途类型,
inline_type_measure varchar(255) 接线方式(计量点),
voltage_level varchar(255) 电压等级,
is_fill_meter varchar(255) 是否装表,
device_type varchar(255) 计量装置分类,
measure_capacity varchar(255) 计量点容量,
own_side varchar(255) 计量点所属侧,
power_factor_type varchar(255) 参与功率因数计算方式,
shop_attrtype varchar(255) 市场化属性,
price_calc_way varchar(255) 电量计算方式,
rate_reduce_flag varchar(255) 定比扣减标志,
exec_price varchar(255) 执行电价,
is_stop_power varchar(255) 是否可停电,
price_type varchar(255) 定价策略类型,
fee_compute_type varchar(255) 基本电费计算方式,
power_factor_checktype varchar(255) 功率因素考核方式,
fee_hangye_type varchar(255) 电价行业类别,
fee varchar(255) 电价,
is_peak_flag varchar(255) 是否执行峰谷标志,
power_factor_stand varchar(255) 功率因数标准,
accept_type varchar(255) 受电点类型,
accept_name varchar(255) 受电点名称,
power_count varchar(255) 电源数目,
have_self_power varchar(255) 有无自备电源,
meter_category varchar(255) 类别,
meter_type varchar(255) 类型,
active_power_level varchar(255) 有功准确度等级,
power_current varchar(255) 电流,
power_voltage_meter varchar(255) 电压(电能表),
inline_type_meter varchar(255) 接线方式,
refer_flag varchar(255) 参考表标志,
indicator_type varchar(255) 电能表示数类型,
transform_plan varchar(255) 互感器方案
*/
var check = new Competition.Mysql.Model.app_exam_cache();
check.power_nature = "电源性质";
check.power_type = "电源类型";
check.power_capacity = "供电容量";
//check.power_voltage = "供电电压";
check.in_line_type = "进线方式";
check.power_phase = "电源相数";
check.protect_type = "保护方式";
///check.relay_protect_type = "继电保护类型";
check.property_split = "产权分界点";
check.in_line_no = "进线杆号/电缆分支箱";
//check.power_remark = "电源备注";
//check.station_info = "站线台信息";
var obj = new
{
power_nature = "电源性质",
power_type = "电源类型",
power_capacity = "供电容量",
in_line_type = "进线方式",
power_phase = "电源相数",
protect_type = "保护方式",
property_split = "产权分界点",
in_line_no = "进线杆号/电缆分支箱",
};
var json = JsonConvert.SerializeObject(obj);
//var user_id = "3201732844279466";
//var exam_code = "01";
//DetailToal dt = new DetailToal();
//compute(user_id, exam_code, dt);
var list = bll.GetModelList("");
var result = GetResult(true, list);
return result;
}
/*
using System;
using System.Threading.Tasks;
public class Example {
public static void Main() {
Parallel.Invoke(
() => MethodA(),
() => MethodB()
);
}
private static void MethodA() {
// 执行一些工作
Console.WriteLine("Method A finished.");
}
private static void MethodB() {
// 执行一些工作
Console.WriteLine("Method B finished.");
}
}
*/
//[Authorize]
/// <summary>
/// 查询试卷答案
/// </summary>
[Route("QueryAnswer")]
public JsonResult QueryAnswer()
{
JsonResult ret;
var exam_code = GetValue("exam_code");
if (string.IsNullOrEmpty(exam_code))
{
ret = GetResult(false, "试卷编码exam_code不能为空");
return ret;
}
var answer = bll_exam_answer.GetModelList(string.Format(" exam_code = '{0}'", exam_code)).FirstOrDefault();
if (null == answer)
{
ret = GetResult(false, "试卷答案不存在,试卷编码:" + exam_code);
return ret;
}
var result = GetResult(true, answer);
return result;
}
//[Authorize]
/// <summary>
/// 查询用户考试结果
/// </summary>
[Route("QueryResult")]
public JsonResult QueryResult()
{
JsonResult ret;
var user_id = GetValue("user_id");
if (string.IsNullOrEmpty(user_id))
{
ret = GetResult(false, "user_id不能为空");
return ret;
}
var exam_code = GetValue("exam_code");
if (string.IsNullOrEmpty(exam_code))
{
ret = GetResult(false, "试卷编码exam_code不能为空");
return ret;
}
var cache = bll.GetModelList("user_id='" + user_id + "' and exam_code='" + exam_code + "'").FirstOrDefault();
if (null == cache)
{
ret = GetResult(false, "用户考试记录不存在");
return ret;
}
var answer = bll_exam_answer.GetModelList(string.Format(" exam_code = '{0}'", exam_code)).FirstOrDefault();
if (null == answer)
{
ret = GetResult(false, "试卷答案不存在,试卷编码:" + exam_code);
return ret;
}
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
DetailToal dt = new DetailToal();
/*
Parallel.Invoke(
() => compute_Check(cache, answer, dt),
() => compute_Power_Station(cache, answer, dt)
);
*/
compute_Check(cache, answer, dt);
compute_Power_Station(cache, answer, dt);
compute_Measure(cache, answer, dt);
compute_price_type_accept_type(cache, answer, dt);
double success_lv = (double)dt.CountSuccess / dt.CountTotal;
double success_rate = Math.Round(success_lv, 2) * 100;
dt.SuccessRate = success_rate;
double fail_lv = (double)dt.CountFail / dt.CountTotal;
double fail_rate = Math.Round(fail_lv, 2) * 100;
dt.FailRate = fail_rate;
stopwatch.Stop();
Console.WriteLine("Time elapsed: {0} ms", stopwatch.ElapsedMilliseconds);
Console.WriteLine("Time elapsed: {0} s", stopwatch.Elapsed.TotalSeconds);
var result = GetResult(true, dt);
return result;
}
/// <summary>
/// 现场勘察
/// </summary>
/// <param name="cache"></param>
/// <param name="r"></param>
/// <param name="dt"></param>
private void compute_Check(Competition.Mysql.Model.app_exam_cache cache, Competition.Mysql.Model.app_exam_answer r, DetailToal dt)
{
/*
`power_unit` '供电单位',
`user_name` '用电户名称',
`contact_man` '联系人',
`contact_mobile` '联系方式',
`user_no` '用户编号',
`taiqu_no` '台区编号',
`address` '用电地址',
`id_card` '证件号码',
`need_type` '需求类型',
`user_type` '用电户分类',
`power_voltage_client` '供电电压(现场勘察)',
`city_type` '城乡类别(特殊边远地区、农村、城市)',
`use_power_type` '用电类别(乡村居民生活用电,城镇居民生活用电)',
*/
//compare("供电单位", "power_unit", cache.power_unit, r.power_unit, dt);
//compare("用电户名称", "user_name", cache.user_name, r.user_name, dt);
//compare("联系人", "contact_man", cache.contact_man, r.contact_man, dt);
//compare("联系方式", "contact_mobile", cache.contact_mobile, r.contact_mobile, dt);
//compare("用户编号", "user_no", cache.user_no, r.user_no, dt);
//无台区编号
//======compare("台区编号", "taiqu_no", cache.taiqu_no, r.taiqu_no, dt);
compare("用电地址", "address", cache.address, r.address, dt);
//compare("证件号码", "id_card", cache.id_card, r.id_card, dt);
compare("需求类型", "need_type", cache.need_type, r.need_type, dt);
compare("用电户分类", "user_type", cache.user_type, r.user_type, dt);
compare("供电电压(现场勘察)", "power_voltage_client", cache.power_voltage_client, r.power_voltage_client, dt);
compare("城乡类别", "city_type", cache.city_type, r.city_type, dt);
string[] use_power_type_array_code = new string[] { "01", "02", "03", "04", "05", "06", "07", "08" };
if (use_power_type_array_code.Contains(cache.exam_code))
{
compare("用电类别", "use_power_type", cache.use_power_type, r.use_power_type, dt);
}
/*
`temp_power_flag` '临时用电标志',
`apply_capacity` '申请容量',
`is_start_power` '是否可供电',
`verify_capacity` '核定合计用电容量',
`is_new_point` '是否新增接入点',
`is_config_project` '是否有配套工程',
`has_project_flag` '有工程标志',
`zhuangong_flag` '转供标志',
`if_jiakong` '是否架空',
`fuhe_nature` '负荷性质',
`check_man` '勘察人员',
`check_date` '勘察日期',
`is_fee_control` '是否费控用户',
`check_idea` '勘察意见',
*/
compare("临时用电标志", "temp_power_flag", cache.temp_power_flag, r.temp_power_flag, dt);
compare("申请容量", "apply_capacity", cache.apply_capacity, r.apply_capacity, dt);
compare("是否可供电", "is_start_power", cache.is_start_power, r.is_start_power, dt);
compare("核定合计用电容量", "verify_capacity", cache.verify_capacity, r.verify_capacity, dt);
compare("是否新增接入点", "is_new_point", cache.is_new_point, r.is_new_point, dt);
compare("是否有配套工程", "is_config_project", cache.is_config_project, r.is_config_project, dt);
//compare("有工程标志", "has_project_flag", cache.has_project_flag, r.has_project_flag, dt);
compare("转供标志", "zhuangong_flag", cache.zhuangong_flag, r.zhuangong_flag, dt);
compare("是否架空", "if_jiakong", cache.if_jiakong, r.if_jiakong, dt);
compare("负荷性质", "fuhe_nature", cache.fuhe_nature, r.fuhe_nature, dt);
compare("勘察人员", "check_man", cache.check_man, r.check_man, dt);
//compare("勘察日期", "check_date", cache.check_date, r.check_date, dt);
Console.WriteLine($"check_date user:{cache.check_date} , answer:{r.check_date}");
compare_date("勘察日期", "check_date", cache.check_date, r.check_date, dt);
compare("是否费控用户", "is_fee_control", cache.is_fee_control, r.is_fee_control, dt);
//compare("勘察意见", "check_idea", cache.check_idea, r.check_idea, dt);
}
private void compare_date()
{
//check_date": "2024.11.01",
string[] formats = { "yyyy-MM-dd", "dd/MM/yyyy", "MM/dd/yyyy", "MMddyyyy" };
//string dateToParse = "2023-05-15";
//string dateToParse = "12/31/2024";
string dateToParse = "12312024";
string message = $@"Description: This is a multi-line string with interpolated values.
";
var check_time = "2024.11.01";
var s1 = DateTime.TryParse(check_time, out DateTime dt_check_time);
if (DateTime.TryParseExact(dateToParse, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate))
{
string back = $"time:{check_time},Parsed Date: {parsedDate.Date.ToString("yyyy-MM-dd")},msg:{message}";
Console.WriteLine($"Parsed Date: {back}");
}
else
{
Console.WriteLine("Failed to parse the date.");
}
}
/// <summary>
/// 电源方案-站线台信息
/// </summary>
/// <param name="cache"></param>
/// <param name="r"></param>
/// <param name="dt"></param>
private void compute_Power_Station(Competition.Mysql.Model.app_exam_cache cache, Competition.Mysql.Model.app_exam_answer r, DetailToal dt)
{
/*
power_type varchar(255) 电源类型,
power_nature varchar(255) 电源性质,
power_phase varchar(255) 电源相数,
power_voltage_powerplan varchar(255) 供电电压(电源方案),
in_line_type varchar(255) 进线方式,
protect_type varchar(255) 保护方式,
power_capacity varchar(255) 供电容量,
station_line_taiqu varchar(255) 变电站/线路/台区,
in_line_no varchar(255) 进线杆号/电缆分支箱,
property_split varchar(255) 产权分界点,
*/
compare("电源类型", "power_type", cache.power_type, r.power_type, dt);
compare("电源性质", "power_nature", cache.power_nature, r.power_nature, dt);
compare("电源相数", "power_phase", cache.power_phase, r.power_phase, dt);
compare("供电电压(电源方案)", "power_voltage_powerplan", cache.power_voltage_powerplan, r.power_voltage_powerplan, dt);
compare("进线方式", "in_line_type", cache.in_line_type, r.in_line_type, dt);
compare("保护方式", "protect_type", cache.protect_type, r.protect_type, dt);
compare("供电容量", "power_capacity", cache.power_capacity, r.power_capacity, dt);
compare(" 变电站/线路/台区", "station_line_taiqu", cache.station_line_taiqu, r.station_line_taiqu, dt);
//compare("进线杆号/电缆分支箱", "in_line_no", cache.in_line_no, r.in_line_no, dt);
compare("产权分界点", "property_split", cache.property_split, r.property_split, dt);
}
/// <summary>
/// 计量点
/// </summary>
/// <param name="cache"></param>
/// <param name="r"></param>
/// <param name="dt"></param>
private void compute_Measure(Competition.Mysql.Model.app_exam_cache cache, Competition.Mysql.Model.app_exam_answer r, DetailToal dt)
{
/*
measure_name varchar(255) 计量点名称,
measure_type varchar(255) 计量点分类,
measure_nature varchar(255) 计量点性质,
measure_way varchar(255) 计量方式,
main_use varchar(255) 主用途类型,
inline_type_measure varchar(255) 接线方式(计量点),
voltage_level varchar(255) 电压等级,
is_fill_meter varchar(255) 是否装表,
device_type varchar(255) 计量装置分类,
measure_capacity varchar(255) 计量点容量,
own_side varchar(255) 计量点所属侧,
power_factor_type varchar(255) 参与功率因数计算方式,
shop_attrtype varchar(255) 市场化属性,
price_calc_way varchar(255) 电量计算方式,
rate_reduce_flag varchar(255) 定比扣减标志,
exec_price varchar(255) 执行电价,
is_stop_power varchar(255) 是否可停电,
*/
//compare("计量点名称", "measure_name", cache.measure_name, r.measure_name, dt);
compare("计量点分类", "measure_type", cache.measure_type, r.measure_type, dt);
compare("计量点性质", "measure_nature", cache.measure_nature, r.measure_nature, dt);
compare("计量方式", "measure_way", cache.measure_way, r.measure_way, dt);
compare("主用途类型", "main_use", cache.main_use, r.main_use, dt);
compare("接线方式(计量点)", "inline_type_measure", cache.inline_type_measure, r.inline_type_measure, dt);
compare("电压等级", "voltage_level", cache.voltage_level, r.voltage_level, dt);
compare("是否装表", "is_fill_meter", cache.is_fill_meter, r.is_fill_meter, dt);
compare("计量装置分类", "device_type", cache.device_type, r.device_type, dt);
compare("计量点容量", "measure_capacity", cache.measure_capacity, r.measure_capacity, dt);
compare("计量点所属侧", "own_side", cache.own_side, r.own_side, dt);
compare("参与功率因数计算方式", "power_factor_type", cache.power_factor_type, r.power_factor_type, dt);
string[] shop_attrtype_array_code = new string[] { "01", "02", "03", "04", "05", "06", "07", "08" };
if (shop_attrtype_array_code.Contains(cache.exam_code))
{
compare("市场化属性", "shop_attrtype", cache.shop_attrtype, r.shop_attrtype, dt);
}
compare("电量计算方式", "price_calc_way", cache.price_calc_way, r.price_calc_way, dt);
compare("定比扣减标志", "rate_reduce_flag", cache.rate_reduce_flag, r.rate_reduce_flag, dt);
compare("执行电价", "exec_price", cache.exec_price, r.exec_price, dt);
compare("是否可停电", "is_stop_power", cache.is_stop_power, r.is_stop_power, dt);
}
/// <summary>
/// 定价策略-受电点类型
/// </summary>
/// <param name="cache"></param>
/// <param name="r"></param>
/// <param name="dt"></param>
private void compute_price_type_accept_type(Competition.Mysql.Model.app_exam_cache cache, Competition.Mysql.Model.app_exam_answer r, DetailToal dt)
{
/*
price_type varchar(255) 定价策略类型,
fee_compute_type varchar(255) 基本电费计算方式,
power_factor_checktype varchar(255) 功率因素考核方式,
fee_hangye_type varchar(255) 电价行业类别,
fee varchar(255) 电价,
is_peak_flag varchar(255) 是否执行峰谷标志,
power_factor_stand varchar(255) 功率因数标准,
accept_type varchar(255) 受电点类型,
accept_name varchar(255) 受电点名称,
power_count varchar(255) 电源数目,
have_self_power varchar(255) 有无自备电源,
meter_category varchar(255) 类别,
meter_type varchar(255) 类型,
active_power_level varchar(255) 有功准确度等级,
power_current varchar(255) 电流,
power_voltage_meter varchar(255) 电压(电能表),
inline_type_meter varchar(255) 接线方式,
refer_flag varchar(255) 参考表标志,
indicator_type varchar(255) 电能表示数类型,
transform_plan varchar(255) 互感器方案
*/
compare("定价策略类型", "price_type", cache.price_type, r.price_type, dt);
compare("基本电费计算方式", "fee_compute_type", cache.fee_compute_type, r.fee_compute_type, dt);
compare("功率因素考核方式", "power_factor_checktype", cache.power_factor_checktype, r.power_factor_checktype, dt);
compare("电价行业类别", "fee_hangye_type", cache.fee_hangye_type, r.fee_hangye_type, dt);
compare("电价", "fee", cache.fee, r.fee, dt);
compare("是否执行峰谷标志", "is_peak_flag", cache.is_peak_flag, r.is_peak_flag, dt);
compare("功率因数标准", "power_factor_stand", cache.power_factor_stand, r.power_factor_stand, dt);
compare("受电点类型", "accept_type", cache.accept_type, r.accept_type, dt);
//compare("受电点名称", "accept_name", cache.accept_name, r.accept_name, dt);
compare("电源数目", "power_count", cache.power_count, r.power_count, dt);
compare("有无自备电源", "have_self_power", cache.have_self_power, r.have_self_power, dt);
compare("类别", "meter_category", cache.meter_category, r.meter_category, dt);
compare("类型", "meter_type", cache.meter_type, r.meter_type, dt);
compare("有功准确度等级", "active_power_level", cache.active_power_level, r.active_power_level, dt);
compare("电流", "power_current", cache.power_current, r.power_current, dt);
compare("电压(电能表)", "power_voltage_meter", cache.power_voltage_meter, r.power_voltage_meter, dt);
compare("接线方式", "inline_type_meter", cache.inline_type_meter, r.inline_type_meter, dt);
compare("参考表标志", "refer_flag", cache.refer_flag, r.refer_flag, dt);
compare("电能表示数类型", "indicator_type", cache.indicator_type, r.indicator_type, dt);
compare("互感器方案", "transform_plan", cache.transform_plan, r.transform_plan, dt);
}
void compare(string item_dsc, string item_field, string item_user_, string item_answer_, DetailToal dt)
{
string item_user = item_user_.Trim();
string item_answer = item_answer_.Trim();
dt.CountTotal++;
if (string.IsNullOrEmpty(item_user) && string.IsNullOrEmpty(item_answer))
{
dt.CountSuccess++;
DetailError right = new DetailError();
right.Field = item_field;
right.Dsc = item_dsc;
right.Answer = item_answer_;
right.User = item_user_;
string msg = string.Format(" {0}({1}) 正确值:{2},用户值:{3}", item_dsc, item_field, item_answer, item_user);
right.Msg = msg;
dt.ListRight.Add(right);
return;
}
if (item_user == item_answer)
{
dt.CountSuccess++;
DetailError right = new DetailError();
right.Field = item_field;
right.Dsc = item_dsc;
right.Answer = item_answer_;
right.User = item_user_;
string msg = string.Format(" {0}({1}) 正确值:{2},用户值:{3}", item_dsc, item_field, item_answer, item_user);
right.Msg = msg;
dt.ListRight.Add(right);
return;
}
dt.CountFail++;
DetailError error = new DetailError();
error.Field = item_field;
error.Dsc = item_dsc;
error.Answer = item_answer_;
error.User = item_user_;
string msg_fail = string.Format(" {0}({1}) 正确值:{2},错误值:{3}", item_dsc, item_field, item_answer, item_user);
error.Msg = msg_fail;
dt.ListError.Add(error);
}
void compare_date(string item_dsc, string item_field, string item_user_, string item_answer_, DetailToal dt)
{
string item_user = item_user_.Trim();
string item_answer = item_answer_.Trim();
dt.CountTotal++;
if (string.IsNullOrEmpty(item_user) && string.IsNullOrEmpty(item_answer))
{
dt.CountSuccess++;
DetailError right = new DetailError();
right.Field = item_field;
right.Dsc = item_dsc;
right.Answer = item_answer_;
right.User = item_user_;
string msg = string.Format(" {0}({1}) 正确值:{2},用户值:{3}", item_dsc, item_field, item_answer, item_user);
right.Msg = msg;
dt.ListRight.Add(right);
return;
}
if (item_user == item_answer)
{
dt.CountSuccess++;
DetailError right = new DetailError();
right.Field = item_field;
right.Dsc = item_dsc;
right.Answer = item_answer_;
right.User = item_user_;
string msg = string.Format(" {0}({1}) 正确值:{2},用户值:{3}", item_dsc, item_field, item_answer, item_user);
right.Msg = msg;
dt.ListRight.Add(right);
return;
}
else
{
string[] formats = { "yyyy-MM-dd", "dd/MM/yyyy", "MM/dd/yyyy", "yyyy.MM.dd" };
string dateToParse = item_user_.Trim();
if (DateTime.TryParseExact(dateToParse, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate))
{
var value_user = parsedDate.ToString("yyyy-MM-dd");
if (value_user == item_answer)
{
dt.CountSuccess++;
DetailError right = new DetailError();
right.Field = item_field;
right.Dsc = item_dsc;
right.Answer = item_answer_;
right.User = item_user_;
string msg = string.Format(" {0}({1}) 正确值:{2},用户值:{3}", item_dsc, item_field, item_answer, item_user);
right.Msg = msg;
dt.ListRight.Add(right);
return;
}
}
}
dt.CountFail++;
DetailError error = new DetailError();
error.Field = item_field;
error.Dsc = item_dsc;
error.Answer = item_answer_;
error.User = item_user_;
string msg_fail = string.Format(" {0}({1}) 正确值:{2},错误值:{3}", item_dsc, item_field, item_answer, item_user);
error.Msg = msg_fail;
dt.ListError.Add(error);
}
public class DetailToal
{
/// <summary>
/// 总数目
/// </summary>
public int CountTotal { get; set; }
/// <summary>
/// 正确数目
/// </summary>
public int CountSuccess { get; set; }
/// <summary>
/// 错误数目
/// </summary>
public int CountFail { get; set; }
/// <summary>
/// 错误项列表
/// </summary>
public List<DetailError> ListError = new List<DetailError>();
/// <summary>
/// 正确项列表
/// </summary>
public List<DetailError> ListRight = new List<DetailError>();
/// <summary>
/// 正确率(%)
/// </summary>
public double SuccessRate { get; set; }
/// <summary>
/// 错误率(%)
/// </summary>
public double FailRate { get; set; }
}
public class DetailError
{
/// <summary>
/// 字段
/// </summary>
public string Field { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Dsc { get; set; }
/// <summary>
/// 答案值
/// </summary>
public string Answer { get; set; }
/// <summary>
/// 用户值
/// </summary>
public string User { get; set; }
/// <summary>
/// 消息
/// </summary>
public string Msg { get; set; }
}
//[Authorize]
/// <summary>
/// 查询用户考试信息
/// </summary>
[Route("Query")]
public JsonResult QueryByClient()
{
JsonResult ret;
var user_id = GetValue("user_id");
if (string.IsNullOrEmpty(user_id))
{
ret = GetResult(false, "user_id不能为空");
return ret;
}
var exam_code = GetValue("exam_code");
if (string.IsNullOrEmpty(exam_code))
{
ret = GetResult(false, "试卷编码exam_code不能为空");
return ret;
}
var model = bll.GetModelList("user_id='" + user_id + "' and exam_code='" + exam_code + "'").FirstOrDefault();
if (null == model)
{
var result = GetResult(false, "记录不存在");
return result;
}
else
{
var result = GetResult(true, model, "");
return result;
}
}
//[Authorize]
/// <summary>
/// 查询用户考试信息
/// </summary>
[Route("Time")]
public JsonResult QueryTime()
{
//compare_date();
var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var msg = $@"user:{Configuration["Config:user_id"]}, {Configuration["Config:name"]}
,conn1: {Configuration["ConnectionStrings:ConnectionString"]}
,conn2: {PubConstant.ConnectionString}";
Console.WriteLine("Time:" + time+","+ msg);
_logger.Log(LogLevel.Information, msg);
var result = GetResult(true, time, msg);
return result;
}
#region
//[Authorize]
[HttpPost]
[Route("Edit")]
public JsonResult AddUpdate()
{
try
{
JsonResult ret;
var user_id = GetValue("user_id");
if (string.IsNullOrEmpty(user_id))
{
ret = GetResult(false, "用户id:user_id不能为空");
return ret;
}
var exam_code = GetValue("exam_code");
if (string.IsNullOrEmpty(exam_code))
{
ret = GetResult(false, "试卷编码exam_code不能为空");
return ret;
}
/*
var client = bll_client_collect.GetModel(client_id);
if (null == client)
{
ret = GetResult(false, "客户收资材料不能为空client_id:" + client_id);
return ret;
}
*/
var data = GetValue("data");
if (string.IsNullOrEmpty(data))
{
ret = GetResult(false, "data不能为空");
return ret;
}
var model = new Competition.Mysql.Model.app_exam_cache();
try
{
model = JsonConvert.DeserializeObject<Competition.Mysql.Model.app_exam_cache>(data)!;
}
catch (Exception ex)
{
ret = GetResult(false, "data转换错误" + ex.Message);
return ret;
}
var exist_model = bll.GetModelList("user_id='" + user_id + "' and exam_code='" + exam_code + "'").OrderByDescending(s => s.id).FirstOrDefault();
if (null == exist_model)
{
model.id = Tool.GetId();
model.user_id = user_id;
model.exam_code = exam_code;
model.create_time = DateTime.Now;
if (bll.Add(model))
{
return GetResult(true, model, "添加成功");
}
else
{
return GetResult(false, "添加失败");
}
}
else
{
model.id = exist_model.id;
model.user_id = user_id;
model.exam_code = exam_code;
model.create_time = DateTime.Now;
if (bll.Update(model))
{
return GetResult(true, model, "修改成功");
}
else
{
return GetResult(false, "修改失败");
}
}
}
catch (Exception ex)
{
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
return GetResult(false, "发生错误,请联系管理员");
}
}
#endregion
#region app手机端缓存
/// <summary>
/// 获取手机app缓存
/// </summary>
/// <param name="context"></param>
[Route("QueryCache")]
public JsonResult QueryDatacache()
{
var ret = string.Empty;
string wh = " 1=1";
var user_id = GetValue("user_id");
if (!string.IsNullOrEmpty(user_id))
{
wh += string.Format(" and user_id='{0}' ", user_id);
}
var type = GetValue("type");
if (string.IsNullOrEmpty(type))
{
var result = GetResult(false, "type参数不能为空");
return result;
}
if (!string.IsNullOrEmpty(type))
{
wh += string.Format(" and type='{0}' ", type);
}
var batch_id = GetValue("batch_id");
if (!string.IsNullOrEmpty(batch_id))
{
wh += string.Format(" and batch_id='{0}' ", batch_id);
}
var type_sub = GetValue("type_sub");
if (!string.IsNullOrEmpty(type_sub))
{
wh += string.Format(" and type_sub='{0}' ", type_sub);
}
var page = GetValue("page");
if (!string.IsNullOrEmpty(page))
{
wh += string.Format(" and page='{0}' ", page);
}
var str_step = GetValue("step");
if (int.TryParse(str_step, out int step))
{
wh += string.Format(" and step={0} ", step);
}
//var cache = bll_data_cache.GetModelList(wh).OrderByDescending(s => s.id).FirstOrDefault();
/*
if (null == cache)
{
var result = GetResult(false, "缓存不存在");
return result;
}
else
{
var result = GetResult(true, cache);
return result;
}
*/
var cacheList = bll_data_cache.GetModelList(wh).OrderByDescending(s => s.id).ToList();
var resultBack = GetResult(true, cacheList);
return resultBack;
}
/// <summary>
/// 添加手机app缓存
/// </summary>
[Route("AddCache")]
public JsonResult AddDatacache()
{
JsonResult ret;
var user_id = GetValue("user_id");
/*
if (string.IsNullOrEmpty(user_id) || user_id == "undefined")
{
ret = GetResult(false, "user_id参数不能为空");
context.Response.Write(ret);
context.Response.End();
}
*/
var batch_id = GetValue("batch_id");
var type = GetValue("type");
if (string.IsNullOrEmpty(type))
{
ret = GetResult(false, "type参数不能为空");
return ret;
}
var data = GetValue("data");
if (string.IsNullOrEmpty(data))
{
ret = GetResult(false, "data参数不能为空");
return ret;
}
var page = GetValue("page");
var type_sub = GetValue("type_sub");
var str_step = GetValue("step");
/*
var obj = new Competition.Mysql.Model.app_data_cache();
obj.id = Tool.GetId();
obj.user_id = user_id;
obj.batch_id = batch_id;
obj.data_json = data;
obj.type = type;
obj.type_sub = type_sub;
obj.page = page;
if (int.TryParse(str_step, out int step))
{
obj.step = step;
}
obj.create_time = DateTime.Now;
obj.update_time = DateTime.Now;
bool add_flag = bll_data_cache.Add(obj);
if (add_flag)
{
var result = GetResult(true, obj, "添加缓存成功");
return result;
}
else
{
var result = GetResult(false, "添加缓存失败");
return result;
}
*/
#region
var acquisition = bll_data_cache.GetModelList(string.Format(" user_id='{0}' and type='{1}' ", user_id, type)).FirstOrDefault();
if (null != acquisition) //修改缓存
{
acquisition.data_json = data;
acquisition.update_time = DateTime.Now;
bool update_flag = bll_data_cache.Update(acquisition);
if (update_flag)
{
var result = GetResult(true, "", "修改缓存成功");
return result;
}
else
{
var result = GetResult(false, "修改缓存失败");
return result;
}
}
else //添加缓存
{
var obj = new Competition.Mysql.Model.app_data_cache();
obj.id = Tool.GetId();
obj.user_id = user_id;
obj.batch_id = batch_id;
obj.type = type;
obj.type_sub = type_sub;
obj.page = page;
if (int.TryParse(str_step, out int step))
{
obj.step = step;
}
obj.data_json = data;
obj.create_time = DateTime.Now;
bool add_flag = bll_data_cache.Add(obj);
if (add_flag)
{
var result = GetResult(true, "", "添加缓存成功");
return result;
}
else
{
var result = GetResult(false, "添加缓存失败");
return result;
}
}
#endregion
}
#endregion
}
}