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.
211 lines
8.1 KiB
211 lines
8.1 KiB
|
|
using Tiobon.Core.IServices;
|
|
using Tiobon.Core.Model.Models;
|
|
using Tiobon.Core.Services.BASE;
|
|
using Tiobon.Core.IRepository.Base;
|
|
using Tiobon.Core.Common.Caches;
|
|
using Newtonsoft.Json.Linq;
|
|
using Tiobon.Core.Common;
|
|
using Tiobon.Core.Model;
|
|
using Newtonsoft.Json;
|
|
using Tiobon.Core.Common.Helper;
|
|
using Org.BouncyCastle.Crypto;
|
|
using SqlSugar;
|
|
|
|
namespace Tiobon.Core.Services;
|
|
|
|
/// <summary>
|
|
/// 必选修规则 (服务)
|
|
/// </summary>
|
|
public class Ghre_StudyRuleServices : BaseServices<Ghre_StudyRule, Ghre_StudyRuleDto, InsertGhre_StudyRuleInput, EditGhre_StudyRuleInput>, IGhre_StudyRuleServices
|
|
{
|
|
private readonly IBaseRepository<Ghre_StudyRule> _dal;
|
|
private readonly IGhre_CourseServices _ghre_CourseServices;
|
|
private readonly IGhre_CourseSceneServices _ghre_CourseSceneServices;
|
|
private readonly IGhre_StudyRuleStaffServices _ghre_StudyRuleStaffServices;
|
|
public Ghre_StudyRuleServices(ICaching caching,
|
|
IGhre_CourseServices ghre_CourseServices,
|
|
IGhre_CourseSceneServices ghre_CourseSceneServices,
|
|
IGhre_StudyRuleStaffServices ghre_StudyRuleStaffServices,
|
|
IBaseRepository<Ghre_StudyRule> dal)
|
|
{
|
|
this._dal = dal;
|
|
base.BaseDal = dal;
|
|
base._caching = caching;
|
|
_ghre_CourseServices = ghre_CourseServices;
|
|
_ghre_CourseSceneServices = ghre_CourseSceneServices;
|
|
_ghre_StudyRuleStaffServices = ghre_StudyRuleStaffServices;
|
|
}
|
|
|
|
|
|
public override async Task<ServicePageResult<Ghre_StudyRuleDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(filter.orderBy))
|
|
filter.orderBy = "CreateTime1 DESC";
|
|
|
|
if (filter.pageSize == 0)
|
|
filter.pageSize = 10000;
|
|
|
|
var countSql = @$" SELECT COUNT(1) FROM Ghre_StudyRule_V";
|
|
var sql = @$" SELECT *
|
|
FROM Ghre_StudyRule_V A";
|
|
|
|
string conditions = " WHERE 1=1 ";
|
|
|
|
if (IsEnable == true)
|
|
conditions += " AND IsEnable = 1";
|
|
else if (IsEnable == false)
|
|
conditions += " AND IsEnable = 0";
|
|
|
|
if (!string.IsNullOrWhiteSpace(condition))
|
|
conditions += " AND " + condition;
|
|
|
|
|
|
if (filter.jsonParam != null)
|
|
foreach (JProperty jProperty in filter.jsonParam.Properties())
|
|
{
|
|
var name = jProperty.Name;
|
|
var value = jProperty.Value.ToString();
|
|
if (name == "page" || name == "pageSize")
|
|
continue;
|
|
if (name == "StaffId")
|
|
{
|
|
|
|
var jsonParam = JsonHelper.JsonToObj<JsonParam>(value);
|
|
var ids1 = JsonHelper.JsonToObj<List<string>>(jsonParam.columnValue.ToString());
|
|
if (ids1 is null)
|
|
continue;
|
|
string sql1 = $"SELECT DISTINCT B.Id from Ghre_StudyRuleStaff A join Ghre_StudyRule B ON A.StudyRuleId = B.ID WHERE B.IsEnable=1 AND A.StaffId IN ({string.Join(",", ids1.Select(id => "'" + id + "'"))})";
|
|
ids1 = await Db.Ado.SqlQueryAsync<string>(sql1);
|
|
switch (jsonParam.operationKey)
|
|
{
|
|
case "EqualAny"://
|
|
conditions += $" AND Id IN ({string.Join(",", ids1.Select(id => "'" + id + "'"))})";
|
|
break;
|
|
case "NotEqualAny"://
|
|
conditions += $" AND Id NOT IN ({string.Join(",", ids1.Select(id => "'" + id + "'"))})";
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
continue;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(value))
|
|
conditions = DealConditions(conditions, name, value);
|
|
}
|
|
|
|
sql += conditions;
|
|
countSql += conditions;
|
|
int total = await Db.Ado.GetIntAsync(countSql);
|
|
|
|
sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " ";
|
|
sql += ") A ) B ) C";
|
|
|
|
sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize;
|
|
|
|
var entitys = await Db.Ado.SqlQueryAsync<Ghre_StudyRuleDto>(sql);
|
|
|
|
var ids = entitys.Select(x => x.Id).ToList();
|
|
var staffs = await _ghre_StudyRuleStaffServices.Query(x => x.StudyRuleId != null && ids.Contains(x.StudyRuleId.Value));
|
|
|
|
entitys.ForEach(x =>
|
|
{
|
|
x.StaffNames = string.Join(",", staffs.Where(o => o.StudyRuleId == x.Id).Select(o => o.StaffName));
|
|
});
|
|
|
|
return new ServicePageResult<Ghre_StudyRuleDto>(filter.pageNum, total, filter.pageSize, entitys);
|
|
|
|
}
|
|
|
|
|
|
public override async Task<long> Add(InsertGhre_StudyRuleInput entity)
|
|
{
|
|
var result = await base.Add(entity);
|
|
|
|
if (entity.Staffs != null && entity.Staffs.Any())
|
|
{
|
|
var insertStaffs = entity.Staffs.Select(x => new InsertGhre_StudyRuleStaffInput
|
|
{
|
|
StaffId = x,
|
|
StudyRuleId = result
|
|
}).ToList();
|
|
await _ghre_StudyRuleStaffServices.Add(insertStaffs);
|
|
}
|
|
|
|
string sql = @"UPDATE A
|
|
SET A.StaffName = B.StaffName
|
|
FROM Ghre_StudyRuleStaff A LEFT JOIN Ghra_Staff B ON A.StaffId = B.StaffID
|
|
WHERE A.StaffName IS NULL";
|
|
await Db.Ado.ExecuteCommandAsync(sql);
|
|
|
|
await Task.Factory.StartNew(async () => await GenerateStaffStudyRecord(Db, result));
|
|
return result;
|
|
}
|
|
|
|
public override async Task<bool> Update(long Id, EditGhre_StudyRuleInput editModel)
|
|
{
|
|
var result = await base.Update(Id, editModel);
|
|
await _ghre_StudyRuleStaffServices.Delete(x => x.StudyRuleId == Id);
|
|
|
|
|
|
if (editModel.Staffs != null && editModel.Staffs.Any())
|
|
{
|
|
var insertStaffs = editModel.Staffs.Select(x => new InsertGhre_StudyRuleStaffInput
|
|
{
|
|
StaffId = x,
|
|
StudyRuleId = Id
|
|
}).ToList();
|
|
await _ghre_StudyRuleStaffServices.Add(insertStaffs);
|
|
}
|
|
|
|
string sql = @"UPDATE A
|
|
SET A.StaffName = B.StaffName
|
|
FROM Ghre_StudyRuleStaff A LEFT JOIN Ghra_Staff B ON A.StaffId = B.StaffID
|
|
WHERE A.StaffName IS NULL";
|
|
await Db.Ado.ExecuteCommandAsync(sql);
|
|
|
|
return result;
|
|
}
|
|
|
|
public override async Task<ServiceFormResult<Ghre_StudyRuleDto>> QueryForm(QueryForm body)
|
|
{
|
|
var result = await base.QueryForm(body);
|
|
|
|
if (result.result.DT_TableDataT1.Any())
|
|
{
|
|
|
|
var staffs = await _ghre_StudyRuleStaffServices.Query(x => x.StudyRuleId != null && x.StudyRuleId == result.result.DT_TableDataT1[0].Id);
|
|
|
|
var DT_TableDataT1 = result.result.DT_TableDataT1;
|
|
DT_TableDataT1.ForEach(t =>
|
|
{
|
|
t.Staffs = staffs.Where(x => x.StaffId != null).Select(x => x.StaffId.Value).ToList();
|
|
});
|
|
|
|
result.result.DT_TableDataT1 = DT_TableDataT1;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public async Task<bool> GenerateStaffStudyRecord(ISqlSugarClient Db, long ruleId)
|
|
{
|
|
var rule = await Db.Queryable<Ghre_StudyRule>().FirstAsync(x => x.Id == ruleId);
|
|
var ruleStaffs = await Db.Queryable<Ghre_StudyRuleStaff>().Where(x => x.StudyRuleId == ruleId).ToListAsync();
|
|
|
|
var ruleStaffIds = ruleStaffs.Select(x => x.StaffId).ToList();
|
|
|
|
var staffs = await Db.Queryable<Ghra_Staff>()
|
|
.WhereIF(rule.ZoneId != null, x => x.ZoneID == rule.ZoneId)
|
|
.WhereIF(rule.DeptId != null, x => x.DeptID == rule.DeptId)
|
|
.WhereIF(rule.TitleId != null, x => x.TitleID == rule.TitleId)
|
|
.WhereIF(rule.GradeId != null, x => x.GradeID == rule.GradeId)
|
|
.WhereIF(rule.JobId != null, x => x.JobID == rule.JobId)
|
|
.WhereIF(ruleStaffIds != null && ruleStaffIds.Any(), x => ruleStaffIds.Contains(x.StaffID))
|
|
.WhereIF(rule.GradeId != null, x => x.GradeID == rule.GradeId)
|
|
.ToListAsync();
|
|
|
|
return true;
|
|
}
|
|
} |