206 lines
8.6 KiB
C#
206 lines
8.6 KiB
C#
using APT.BaseData.Domain.Entities;
|
|
using APT.BaseData.Domain.Entities.FM;
|
|
using APT.BaseData.Domain.Enums;
|
|
using APT.BaseData.Domain.Enums.PF;
|
|
using APT.BaseData.Domain.IServices;
|
|
using APT.BaseData.Domain.IServices.FM;
|
|
using APT.Infrastructure.Api;
|
|
using APT.Infrastructure.Core;
|
|
using APT.MS.Domain.Entities.SC;
|
|
using APT.MS.Domain.Entities.SE;
|
|
using APT.MS.Domain.Enums;
|
|
using InfluxData.Net.InfluxDb.Models.Responses;
|
|
using MySqlX.XDevAPI.Common;
|
|
using NPOI.SS.Formula.Functions;
|
|
using Org.BouncyCastle.Utilities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace APT.BaseData.Services.DomainServices
|
|
{
|
|
/// <summary>
|
|
/// 获取会议Model T_SE_NEW_USERS
|
|
/// </summary>
|
|
public class SENewUserService : CommonService, ISENewUserService
|
|
{
|
|
IFMNotificationTaskService NotificationTaskService { get; set; }
|
|
public SENewUserService(IRepository repository, IFMNotificationTaskService notificationTaskService)
|
|
: base(repository)
|
|
{
|
|
NotificationTaskService = notificationTaskService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取试题 三级安全教育
|
|
/// </summary>
|
|
/// <param name="ORG_ID"></param>
|
|
/// <param name="RECORD_ID"></param>
|
|
/// <param name="USER_ID"></param>
|
|
/// <param name="eduCard"></param>
|
|
/// <param name="config"></param>
|
|
/// <param name="modelText"></param>
|
|
/// <param name="ListPapers"></param>
|
|
/// <param name="sendNotice"></param>
|
|
/// <param name="Msg"></param>
|
|
/// <param name="TEXT_TIMES"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public bool GetText(Guid ORG_ID, Guid RECORD_ID, Guid USER_ID, T_SE_NEW_USERS eduCard, T_SE_SECONFIG config, ref T_SE_NEW_USER_DETAIL_TEXT modelText, ref List<T_SE_NEW_USER_DETAIL_PAPER> ListPapers, ref T_FM_NOTIFICATION_TASK sendNotice, ref string Msg, int TEXT_TIMES = 1)
|
|
{
|
|
List<T_FM_NOTIFICATION_TASK> sendNotices = new List<T_FM_NOTIFICATION_TASK>();
|
|
if (config == null)
|
|
{
|
|
config = GetEntity<T_SE_SECONFIG>(t => true);
|
|
}
|
|
var SCount = 1;
|
|
var MCount = 1;
|
|
var CCount = 1;
|
|
if (config != null)
|
|
{
|
|
if (config.M_TEST_COUNT > 0 || config.S_TEST_COUNT > 0 || config.C_TEST_COUNT > 0)
|
|
{
|
|
//王永文 只要有配置 就获取
|
|
MCount = config.M_TEST_COUNT;
|
|
SCount = config.S_TEST_COUNT;
|
|
CCount = config.C_TEST_COUNT;
|
|
}
|
|
else
|
|
{
|
|
//保持原来的版本
|
|
if (config.M_TEST_COUNT > 0)
|
|
{
|
|
MCount = config.M_TEST_COUNT;
|
|
}
|
|
if (config.S_TEST_COUNT > 0)
|
|
{
|
|
SCount = config.S_TEST_COUNT;
|
|
}
|
|
if (config.C_TEST_COUNT > 0)
|
|
{
|
|
CCount = config.C_TEST_COUNT;
|
|
}
|
|
}
|
|
}
|
|
var testidlist = new List<Guid>();
|
|
var testFilter = new BaseFilter(ORG_ID);
|
|
testFilter.Include = new string[] { "Nav_Points" };
|
|
var currStatus = eduCard.TRAIN_STATUS;
|
|
IEnumerable<T_SE_TEST_ENUM_POINT> pointS = new List<T_SE_TEST_ENUM_POINT>();
|
|
string PointName = "";
|
|
if (eduCard.TRAIN_STATUS == SEThreeLevelSafeTrainType.公司级)
|
|
{
|
|
PointName = "三级安全教育-公司级";
|
|
}
|
|
else if (eduCard.TRAIN_STATUS == SEThreeLevelSafeTrainType.部门级)
|
|
{
|
|
PointName = "三级安全教育-部门级";
|
|
}
|
|
else if (eduCard.TRAIN_STATUS == SEThreeLevelSafeTrainType.班组级)
|
|
{
|
|
PointName = "三级安全教育-班组级";
|
|
}
|
|
pointS = GetEntities<T_SE_TEST_ENUM_POINT>(t => t.NAME == PointName, new BaseFilter(ORG_ID));
|
|
if (pointS == null || pointS.Count() < 1)
|
|
{
|
|
throw new Exception("未找到试题知识点【" + PointName + "】的配置信息,配置路径:系统管理 > 安全教育培训配置 > 知识点类型。");
|
|
}
|
|
var pointIDS = pointS.Select(t => t.ID).ToList();
|
|
var allTests = GetEntities<T_SE_TEST>(st => st.Nav_Points.Any(pt => pointIDS.Contains((Guid)pt.POINT_ID)), testFilter).ToList();
|
|
foreach (var testPoint in pointIDS)
|
|
{
|
|
var havepoint = allTests.Where(st => st.Nav_Points.Any(pt => pt.POINT_ID == testPoint));
|
|
if (havepoint.Count() < 1)
|
|
{
|
|
var noPoint = GetEntity<T_SE_TEST_ENUM_POINT>(testPoint);
|
|
Msg += noPoint.NAME + ",";
|
|
}
|
|
}
|
|
if (Msg != "")
|
|
{
|
|
Msg = "知识点 " + Msg + " 没有题目!";
|
|
return false;
|
|
}
|
|
var SCurrentCount = allTests.Count(t => t.TYPE == SETestTypeEnum.单选题);
|
|
var MCurrentCount = allTests.Count(t => t.TYPE == SETestTypeEnum.多选题);
|
|
var CCurrentCount = allTests.Count(t => t.TYPE == SETestTypeEnum.是非题);
|
|
Msg = "";
|
|
if (SCurrentCount < SCount)
|
|
{
|
|
Msg += "题库中题目数量不足!";
|
|
Msg += "单选题还需" + (SCount - SCurrentCount) + "题\n";
|
|
}
|
|
if (MCurrentCount < MCount)
|
|
{
|
|
Msg += "题库中题目数量不足!";
|
|
Msg += "多选题还需" + (MCount - MCurrentCount) + "题\n";
|
|
}
|
|
if (CCurrentCount < CCount)
|
|
{
|
|
Msg += "题库中题目数量不足!";
|
|
Msg += "是非题还需" + (CCount - CCurrentCount) + "题\n";
|
|
}
|
|
|
|
if (Msg != "")
|
|
{
|
|
Msg = "知识点 " + Msg + " 没有题目!";
|
|
return false;
|
|
}
|
|
CreateTestList(allTests, testidlist, pointIDS, (int)SETestTypeEnum.是非题, CCount);
|
|
CreateTestList(allTests, testidlist, pointIDS, (int)SETestTypeEnum.单选题, SCount);
|
|
CreateTestList(allTests, testidlist, pointIDS, (int)SETestTypeEnum.多选题, MCount);
|
|
|
|
if (testidlist.Count == 0 || testidlist.Count < (SCount + MCount + CCount))
|
|
{
|
|
Msg = "当前题库数据不足,未能正常生成试卷! 知识点:" + PointName + "是非题:" + CCount + "题,单选题:" + SCount + "题,多选题:" + MCount + "题!";
|
|
return false;
|
|
}
|
|
|
|
modelText = new T_SE_NEW_USER_DETAIL_TEXT();
|
|
Guid TEXT_ID = Guid.NewGuid();
|
|
modelText.RECORD_ID = RECORD_ID;
|
|
modelText.ID = TEXT_ID;
|
|
modelText.ORG_ID = ORG_ID;
|
|
modelText.USER_ID = USER_ID;
|
|
modelText.TEXT_TIMES = TEXT_TIMES;
|
|
if (ListPapers == null)
|
|
{
|
|
ListPapers = new List<T_SE_NEW_USER_DETAIL_PAPER>();
|
|
}
|
|
List<T_SE_NEW_USER_DETAIL_PAPER> temp = new List<T_SE_NEW_USER_DETAIL_PAPER>();
|
|
testidlist.ForEach(testid =>
|
|
{
|
|
var p = new T_SE_NEW_USER_DETAIL_PAPER
|
|
{
|
|
RECORD_ID = RECORD_ID,
|
|
ID = Guid.NewGuid(),
|
|
ORG_ID = ORG_ID,
|
|
TEXT_ID = TEXT_ID,
|
|
USER_ID = USER_ID,
|
|
TEST_ID = testid,
|
|
ANSWER = 0,
|
|
};
|
|
temp.Add(p);
|
|
});
|
|
ListPapers = temp;
|
|
string userNAME = GetEntity<T_FM_USER>(USER_ID).NAME;
|
|
sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("三级安全教育在线答题-" + eduCard.TRAIN_STATUS.GetDescription(), modelText.ID, modelText.ORG_ID, USER_ID, userNAME, DateTime.Now, DateTime.Now.AddHours(12), 1, "SE061_PAPERPAGE");
|
|
return true;
|
|
}
|
|
|
|
private void CreateTestList(List<T_SE_TEST> allTests, List<Guid> ret, List<Guid> contentFilter, int type, int count)
|
|
{
|
|
var tests = allTests.Where(st =>
|
|
st.Nav_Points.Any(pt => contentFilter.Contains(pt.POINT_ID.Value)) &&
|
|
st.TYPE == (SETestTypeEnum)type).OrderBy(t => Guid.NewGuid()).Take(count); ;
|
|
if (tests != null)
|
|
{
|
|
ret.AddRange(tests.Select(it => it.ID));
|
|
}
|
|
}
|
|
}
|
|
}
|