|
|
|
@ -6,6 +6,13 @@ using Tiobon.Core.IRepository.Base; |
|
|
|
|
using Tiobon.Core.Model; |
|
|
|
|
using System.Dynamic; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using AgileObjects.AgileMapper; |
|
|
|
|
using Mysqlx.Crud; |
|
|
|
|
using AgileObjects.AgileMapper.Extensions; |
|
|
|
|
using System.Data; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
using Tiobon.Core.Common.DB.Dapper; |
|
|
|
|
using MySqlX.XDevAPI.Common; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services |
|
|
|
|
{ |
|
|
|
@ -41,7 +48,7 @@ namespace Tiobon.Core.Services |
|
|
|
|
required = true, |
|
|
|
|
multipleSelect = true, |
|
|
|
|
editable = true, |
|
|
|
|
dataSource = "TBParaDetail_GhrStaff_JTFS" |
|
|
|
|
dataSource = "api/Common/GetSelect?type=Ghre_Course" |
|
|
|
|
}); |
|
|
|
|
data.Column.Add(new FromGhre_QuestionColumn() |
|
|
|
|
{ |
|
|
|
@ -96,6 +103,21 @@ namespace Tiobon.Core.Services |
|
|
|
|
{ |
|
|
|
|
var question = await base.QueryById(Id); |
|
|
|
|
data.PageData.questionType.ForEach(x => x.isActive = 0); |
|
|
|
|
data.PageData.baseData.questionNo = question.QuestionNo; |
|
|
|
|
if (!string.IsNullOrEmpty(question.CourseIds)) |
|
|
|
|
{ |
|
|
|
|
var list = question.CourseIds.Split(';'); |
|
|
|
|
list.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
data.PageData.baseData.courseID.Add(long.Parse(x)); |
|
|
|
|
} |
|
|
|
|
catch (Exception) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
var questionType = data.PageData.questionType.Where(x => x.type == question.QuestionType).FirstOrDefault(); |
|
|
|
|
if (questionType != null) |
|
|
|
|
{ |
|
|
|
@ -121,5 +143,140 @@ namespace Tiobon.Core.Services |
|
|
|
|
|
|
|
|
|
return ServiceResult<FromGhre_QuestionInput>.OprateSuccess("查询成功!", data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult<long>> InsertFrom(FromGhre_QuestionPageData insertModel) |
|
|
|
|
{ |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseId = insertModel.baseData.courseID; |
|
|
|
|
insert.CourseIds = string.Join(";", insert.CourseId.Select(x => x)); |
|
|
|
|
|
|
|
|
|
var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); |
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
|
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
|
|
|
|
|
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
QuestionNo = x.No, |
|
|
|
|
AnswerContent = x.label, |
|
|
|
|
ImageUrl = x.imageUrl, |
|
|
|
|
ImageWidthPc = x.imgWidthPc, |
|
|
|
|
ImageWidthApp = x.imgWidthApp, |
|
|
|
|
}).ToList(); |
|
|
|
|
int i = 100; |
|
|
|
|
insertAnswers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = id; |
|
|
|
|
if (questionType.detail.answer == x.QuestionNo && insert.QuestionType == "Single") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
return ServiceResult<long>.OprateSuccess("查询成功!", id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult> UpdareFrom(long Id, FromGhre_QuestionPageData editModel) |
|
|
|
|
{ |
|
|
|
|
var data = await base.QueryById(Id); |
|
|
|
|
await _ghre_QuestionAnswerServices.Delete(x => x.QuestionId == Id); |
|
|
|
|
var edit = Mapper.Map(data).ToANew<EditGhre_QuestionInput>(); |
|
|
|
|
edit.CourseId = editModel.baseData.courseID; |
|
|
|
|
edit.CourseIds = string.Join(";", edit.CourseId.Select(x => x)); |
|
|
|
|
edit.QuestionNo = ""; |
|
|
|
|
|
|
|
|
|
var questionType = editModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); |
|
|
|
|
edit.QuestionType = questionType.type; |
|
|
|
|
edit.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
edit.QuestionContent = questionType.detail.content; |
|
|
|
|
edit.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
|
|
|
|
|
await base.Update(Id, edit); |
|
|
|
|
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
QuestionNo = x.No, |
|
|
|
|
AnswerContent = x.label, |
|
|
|
|
ImageUrl = x.imageUrl, |
|
|
|
|
ImageWidthPc = x.imgWidthPc, |
|
|
|
|
ImageWidthApp = x.imgWidthApp, |
|
|
|
|
}).ToList(); |
|
|
|
|
int i = 100; |
|
|
|
|
insertAnswers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = Id; |
|
|
|
|
if (questionType.detail.answer == x.QuestionNo && edit.QuestionType == "Single") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
return ServiceResult.OprateSuccess("更新成功!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static string GenerateContinuousSequence(string prefixTemp) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
string result = string.Empty; |
|
|
|
|
string tableCode = "Ghre_Question"; |
|
|
|
|
string columnCode = "QuestionNo"; |
|
|
|
|
int length = 6; |
|
|
|
|
int tempLength = 5; |
|
|
|
|
int sequence; |
|
|
|
|
|
|
|
|
|
#region 查询 |
|
|
|
|
DbSelect dbSelect = new DbSelect(tableCode + " A", "A", null); |
|
|
|
|
dbSelect.IsInitDefaultValue = false; |
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(prefixTemp)) |
|
|
|
|
dbSelect.Select("MAX(SUBSTRING(A." + columnCode + "," + (prefixTemp.Length + 1).ToString() + "," + tempLength.ToString() + "))"); |
|
|
|
|
else |
|
|
|
|
dbSelect.Select("MAX(A." + columnCode + ")"); |
|
|
|
|
//} |
|
|
|
|
//dbSelect.Select("MAX(CONVERT(DECIMAL,SUBSTRING(A.ISSUE_NO," + (prefix.Length + dateString.Length + 1).ToString() + "," + tempLength.ToString() + ")))"); |
|
|
|
|
if (!string.IsNullOrEmpty(prefixTemp)) |
|
|
|
|
dbSelect.Where("SUBSTRING(A." + columnCode + ",1," + (prefixTemp.Length).ToString() + ")", " = ", prefixTemp); |
|
|
|
|
dbSelect.Where("LEN(A." + columnCode + ")", "=", length); |
|
|
|
|
string sql = dbSelect.GetSql(); |
|
|
|
|
string maxSequence = Convert.ToString(DbAccess.Instance.ExecuteScalar(sql)); |
|
|
|
|
#endregion |
|
|
|
|
//tempLength = tempLength - dateString.Length; |
|
|
|
|
if (string.IsNullOrEmpty(maxSequence)) |
|
|
|
|
result = prefixTemp + Convert.ToString(1).PadLeft(tempLength, '0'); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if (!string.IsNullOrEmpty(prefixTemp)) |
|
|
|
|
{ |
|
|
|
|
if (int.TryParse(maxSequence, out sequence)) |
|
|
|
|
{ |
|
|
|
|
sequence += 1; |
|
|
|
|
if (sequence.ToString().Length > tempLength) |
|
|
|
|
throw new Exception("自动生成字串长度已经超过设定长度!"); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
throw new Exception("表中的数据无法进行自动编号,请联系软件开发商!"); |
|
|
|
|
result = prefixTemp + sequence.ToString().PadLeft(tempLength, '0'); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if (int.TryParse(maxSequence, out sequence)) |
|
|
|
|
{ |
|
|
|
|
sequence += 1; |
|
|
|
|
if (sequence.ToString().Length > length) |
|
|
|
|
throw new Exception("自动生成字串长度已经超过设定长度!"); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
throw new Exception("表中的数据无法进行自动编号,请联系软件开发商!"); |
|
|
|
|
result = sequence.ToString().PadLeft(length, '0'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
catch (Exception) { throw; } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |