VisaProcessRepository.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. using AutoMapper;
  2. using NPOI.Util;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Groups;
  5. using OASystem.Domain.Dtos.Task;
  6. using OASystem.Domain.Entities.Groups;
  7. using OASystem.Domain.ViewModels.Groups;
  8. using OASystem.Domain.ViewModels.SmallFun;
  9. using OASystem.Infrastructure.Tools;
  10. using System.Reflection;
  11. using System.Text.Json.Serialization;
  12. namespace OASystem.Infrastructure.Repositories.Groups
  13. {
  14. /// <summary>
  15. /// 签证流程步骤仓储
  16. /// </summary>
  17. public class VisaProcessRepository : BaseRepository<Grp_VisaProcessSteps, Grp_VisaProcessSteps>
  18. {
  19. private readonly IMapper _mapper;
  20. public VisaProcessRepository(SqlSugarClient sqlSugar, IMapper mapper)
  21. : base(sqlSugar)
  22. {
  23. _mapper = mapper;
  24. }
  25. /// <summary>
  26. /// 创建签证流程步骤
  27. /// </summary>
  28. /// <param name="groupId"></param>
  29. /// <param name="createUderId"></param>
  30. /// <returns></returns>
  31. public async Task<Result> Create(int createUderId,int groupId)
  32. {
  33. //团组有效验证
  34. var groupIsValid = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  35. .Where(g => g.Id == groupId && g.IsDel == 0)
  36. .AnyAsync();
  37. if (!groupIsValid)
  38. {
  39. return new Result(400, "团组无效,无法创建签证流程步骤。");
  40. }
  41. var existingSteps = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
  42. .Where(s => s.GroupId == groupId && s.IsDel == 0)
  43. .AnyAsync();
  44. if (existingSteps)
  45. {
  46. return new Result(400, "该团组的签证流程步骤已存在,无法重复创建。");
  47. }
  48. var steps = Grp_VisaProcessSteps.StepsInit(groupId, createUderId);
  49. var add = await _sqlSugar.Insertable(steps).ExecuteCommandAsync();
  50. if (add < 1) return new Result(400, "签证流程步骤创建失败。");
  51. // 记录创建日志
  52. foreach (var step in steps)
  53. {
  54. await LogOperationAsync(null, step, "Create", createUderId);
  55. }
  56. return new Result(200,"Success");
  57. }
  58. /// <summary>
  59. /// 签证流程 Info
  60. /// </summary>
  61. /// <param name="dto"></param>
  62. /// <param name="createUderId"></param>
  63. /// <returns></returns>
  64. public async Task<Result> Info(VisaProcessInfoByGroupIdDto dto)
  65. {
  66. //团组有效验证
  67. //var groupIsValid = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  68. // .Where(g => g.Id == dto.GroupId && g.IsDel == 0)
  69. // .AnyAsync();
  70. //if (!groupIsValid)
  71. //{
  72. // return new Result(400, "团组无效,无法查询签证流程步骤。");
  73. //}
  74. var query = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
  75. .Where(s => s.GroupId == dto.GroupId && s.IsDel == 0)
  76. .OrderBy(s => s.Step)
  77. .ToListAsync();
  78. var infos = query.Select(s => new
  79. {
  80. s.Id,
  81. s.GroupId,
  82. s.Step,
  83. s.DataType,
  84. s.TypedValue,
  85. //s.StoreVal,
  86. s.IsCompleted,
  87. s.AttachUrl,
  88. s.TypedFileNameValue,
  89. s.Remark
  90. }).ToList();
  91. string msg = "Success";
  92. //如果不存在,则返回默认数据
  93. if (infos == null || infos.Count < 1)
  94. {
  95. infos = Grp_VisaProcessSteps.StepsInit(dto.GroupId, 208)
  96. .Select(s => new {
  97. s.Id,
  98. s.GroupId,
  99. s.Step,
  100. s.DataType,
  101. s.TypedValue,
  102. //s.StoreVal,
  103. s.IsCompleted,
  104. s.AttachUrl,
  105. s.TypedFileNameValue,
  106. s.Remark
  107. }).ToList();
  108. msg = "签证流程步骤信息不存在,展示默认数据。";
  109. }
  110. //数据按照类型处理
  111. var datas = new List<object>();
  112. var view = new VisaProcessStepsInfoView();
  113. foreach (var item in infos)
  114. {
  115. if (item.DataType == "string")
  116. {
  117. var info = new VisaProcessStepsInfoByStringView
  118. {
  119. Id = item.Id,
  120. GroupId = item.GroupId,
  121. Step = item.Step,
  122. DataType = item.DataType,
  123. TypedValue = item.TypedValue == null ? "" : item.TypedValue.ToString(),
  124. //StoreVal = item.StoreVal,
  125. IsCompleted = item.IsCompleted,
  126. AttachUrl = item.TypedFileNameValue,
  127. Remark = item.Remark
  128. };
  129. if (item.Step == 1) view.Step1 = info;
  130. else if (item.Step == 2) view.Step2 = info;
  131. else if (item.Step == 3) view.Step3 = info;
  132. else if (item.Step == 4) view.Step4 = info;
  133. else if (item.Step == 5) view.Step5 = info;
  134. else if (item.Step == 8) view.Step8 = info;
  135. datas.Add(info);
  136. }
  137. else if (item.DataType == "bool")
  138. {
  139. bool boolVal = false;
  140. if (item.TypedValue != null)
  141. {
  142. boolVal = (bool)item.TypedValue;
  143. }
  144. var info = new VisaProcessStepsInfoByBoolView
  145. {
  146. Id = item.Id,
  147. GroupId = item.GroupId,
  148. Step = item.Step,
  149. DataType = item.DataType,
  150. TypedValue = boolVal,
  151. IsCompleted = item.IsCompleted,
  152. AttachUrl = item.TypedFileNameValue,
  153. Remark = item.Remark
  154. };
  155. if (item.Step == 6) view.Step6 = info;
  156. datas.Add(info);
  157. }
  158. else if (item.DataType == "string[]")
  159. {
  160. var listVal = new List<string>();
  161. var contnet = new VisaProcessSteps7Content() { IsSelected = false };
  162. if (item.TypedValue != null)
  163. {
  164. listVal = item.TypedValue switch
  165. {
  166. List<string> stringList => stringList,
  167. IEnumerable<string> stringEnumerable => stringEnumerable.ToList(),
  168. string str => new List<string> { str },
  169. IEnumerable<object> objectEnumerable => objectEnumerable.Select(x => x?.ToString() ?? "").ToList(),
  170. _ => new List<string> { item.TypedValue.ToString() ?? "" }
  171. };
  172. if (listVal != null && listVal.Count > 0)
  173. {
  174. contnet.IsSelected = bool.TryParse(CommonFun.GetValueOrDefault(listVal,0), out _);
  175. contnet.ProjectedDate = CommonFun.GetValueOrDefault(listVal, 1);
  176. }
  177. }
  178. var info = new VisaProcessStepsInfoByListView
  179. {
  180. Id = item.Id,
  181. GroupId = item.GroupId,
  182. Step = item.Step,
  183. DataType = item.DataType,
  184. TypedValue = contnet,
  185. IsCompleted = item.IsCompleted,
  186. AttachUrl = item.TypedFileNameValue,
  187. Remark = item.Remark
  188. };
  189. if (item.Step == 7) view.Step7 = info;
  190. datas.Add(info);
  191. }
  192. }
  193. if (dto.PortType == 2 )
  194. {
  195. return new Result(200, msg, infos);
  196. }
  197. return new Result(200, msg, view);
  198. }
  199. /// <summary>
  200. /// 修改签证流程步骤
  201. /// </summary>
  202. /// <param name="groupId"></param>
  203. /// <param name="createUderId"></param>
  204. /// <returns></returns>
  205. public async Task<Result> Update(Grp_VisaProcessSteps info)
  206. {
  207. var step = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().FirstAsync(x => x.Id == info.Id);
  208. var before = ManualClone(step);
  209. step.StoreVal = info.StoreVal;
  210. step.LastUpdateUserId = info.LastUpdateUserId;
  211. step.LastUpdateTime = DateTime.Now;
  212. step.Remark = info.Remark;
  213. var update = await _sqlSugar.Updateable<Grp_VisaProcessSteps>(step)
  214. .Where(s => s.Id == info.Id && s.IsDel == 0)
  215. .ExecuteCommandAsync();
  216. if (update < 1) return new Result(400, "更新失败!");
  217. // 记录更新日志
  218. await LogOperationAsync(before, step, "Update", info.LastUpdateUserId);
  219. return new Result(200, "Success");
  220. }
  221. /// <summary>
  222. /// 批量修改top4Steps
  223. /// </summary>
  224. /// <param name="infos"></param>
  225. /// <returns></returns>
  226. public async Task<Result> UpdateBatchTop4Step(int groupId,int currUserId)
  227. {
  228. var steps = new List<int>() {
  229. 1, //签证启动日
  230. 2, //分配工作
  231. 3, //送外办时间
  232. 4, //预计出签时间
  233. };
  234. var visaSteps = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
  235. .Where(s => s.GroupId == groupId && s.IsDel == 0 && steps.Contains(s.Step))
  236. .ToListAsync();
  237. if (visaSteps.Count < 1) return new Result(400, "签证流程信息不存在。");
  238. //倒推表信息
  239. var invertedInfo = await _sqlSugar.Queryable<Grp_InvertedList>()
  240. .Where(i => i.DiId == groupId && i.IsDel == 0)
  241. .FirstAsync();
  242. if (invertedInfo == null) return new Result(400, "倒推表信息不存在。");
  243. //步骤更改前的值
  244. var beforeStep1 = ManualClone(visaSteps.FirstOrDefault(x => x.Step == 1));
  245. var beforeStep2 = ManualClone(visaSteps.FirstOrDefault(x => x.Step == 2));
  246. var beforeStep3 = ManualClone(visaSteps.FirstOrDefault(x => x.Step == 3));
  247. var beforeStep4 = ManualClone(visaSteps.FirstOrDefault(x => x.Step == 4));
  248. //设置操作人和时间
  249. foreach (var item in visaSteps)
  250. {
  251. //默认确认完成
  252. item.IsCompleted = true;
  253. item.LastUpdateUserId = currUserId;
  254. item.LastUpdateTime = DateTime.Now;
  255. }
  256. //step=1 设置启动日值
  257. visaSteps.FirstOrDefault(x => x.Step == 1).TypedValue = DateTime.Now.ToString("yyyy-MM-dd");
  258. //step=2 分配工作
  259. visaSteps.FirstOrDefault(x => x.Step == 2).TypedValue = invertedInfo.IssueApprovalDt;
  260. //step=3 送外办时间
  261. visaSteps.FirstOrDefault(x => x.Step == 3).TypedValue = invertedInfo.SendVisaDt;
  262. //step=4 预计出签时间
  263. visaSteps.FirstOrDefault(x => x.Step == 4).TypedValue = invertedInfo.IssueVisaDt;
  264. var update = await _sqlSugar.Updateable(visaSteps)
  265. .UpdateColumns(it => new { it.StoreVal, it.LastUpdateUserId,it.LastUpdateTime })
  266. .ExecuteCommandAsync();
  267. if (update < 1) return new Result(400, "更新失败!");
  268. //更改后的值
  269. var afterStep1 = visaSteps.FirstOrDefault(x => x.Step == 1);
  270. var afterStep2 = visaSteps.FirstOrDefault(x => x.Step == 2);
  271. var afterStep3 = visaSteps.FirstOrDefault(x => x.Step == 3);
  272. var afterStep4 = visaSteps.FirstOrDefault(x => x.Step == 4);
  273. // 记录更新日志
  274. await LogOperationAsync(beforeStep1, afterStep1, "Update", currUserId);
  275. await LogOperationAsync(beforeStep2, afterStep2, "Update", currUserId);
  276. await LogOperationAsync(beforeStep3, afterStep3, "Update", currUserId);
  277. await LogOperationAsync(beforeStep4, afterStep4, "Update", currUserId);
  278. return new Result(200, "Success");
  279. }
  280. /// <summary>
  281. /// 设置已完成的步骤
  282. /// </summary>
  283. /// <param name="id"></param>
  284. /// <param name="currUserId"></param>
  285. /// <param name="isCompleted"></param>
  286. /// <returns></returns>
  287. public async Task<Result> SetCompleted(int id, int currUserId, bool isCompleted = true)
  288. {
  289. //步骤信息验证
  290. var stepInfo = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
  291. .Where(s => s.Id == id && s.IsDel == 0)
  292. .FirstAsync();
  293. if (stepInfo == null) return new Result(400, "步骤信息不存在,无法设置。");
  294. if (stepInfo.IsCompleted) return new Result(400, "步骤信息已完成,无法重复设置。");
  295. var before = ManualClone(stepInfo);
  296. stepInfo.IsCompleted = isCompleted;
  297. stepInfo.LastUpdateUserId = currUserId;
  298. stepInfo.LastUpdateTime = DateTime.Now;
  299. var update = await _sqlSugar.Updateable<Grp_VisaProcessSteps>()
  300. .SetColumns(s => new Grp_VisaProcessSteps
  301. {
  302. IsCompleted = isCompleted,
  303. LastUpdateUserId = currUserId,
  304. LastUpdateTime = DateTime.Now
  305. })
  306. .Where(s => s.Id == id && s.IsDel == 0 && !s.IsCompleted)
  307. .ExecuteCommandAsync();
  308. if (update < 1) return new Result(400, "状态设置失败!");
  309. // 记录更新日志
  310. await LogOperationAsync(before, stepInfo, "Update", currUserId);
  311. return new Result(200, "Success");
  312. }
  313. #region 操作日志
  314. /// <summary>
  315. /// 记录签证流程步骤的操作日志
  316. /// </summary>
  317. /// <param name="before">操作前的步骤数据实体</param>
  318. /// <param name="after">操作后的步骤数据实体</param>
  319. /// <param name="opType">操作类型(Create-创建, Update-更新, Delete-删除, Complete-完成, Upload-上传附件, Download-下载文件)</param>
  320. /// <param name="operatorId">操作人用户ID</param>
  321. /// <returns>表示异步操作的任务</returns>
  322. /// <remarks>此方法会自动比较前后数据的差异,生成变更字段列表和操作描述</remarks>
  323. public async Task LogOperationAsync(Grp_VisaProcessSteps before, Grp_VisaProcessSteps after,string opType, int operatorId)
  324. {
  325. // 合并基础排除字段和额外排除字段
  326. var allExcludedFields = GetDefaultExcludedFields();
  327. var changedFields = GetChangeDetails(before, after, allExcludedFields);
  328. var log = new Grp_VisaProcessSteps_Log
  329. {
  330. StepId = after?.Id ?? before?.Id ?? 0,
  331. GroupId = after?.GroupId ?? before?.GroupId ?? 0,
  332. Step = after?.Step ?? before?.Step ?? 0,
  333. OperationType = opType,
  334. OperationDescription = GenerateOpDesc(opType, before, after, changedFields),
  335. BeforeData = before != null ? JsonSerializer.Serialize(before, new JsonSerializerOptions
  336. {
  337. ReferenceHandler = ReferenceHandler.IgnoreCycles,
  338. WriteIndented = false
  339. }) : null,
  340. AfterData = after != null ? JsonSerializer.Serialize(after, new JsonSerializerOptions
  341. {
  342. ReferenceHandler = ReferenceHandler.IgnoreCycles,
  343. WriteIndented = false
  344. }) : null,
  345. ChangedFields = string.Join(",", changedFields),
  346. CreateUserId = operatorId,
  347. };
  348. await _sqlSugar.Insertable(log).ExecuteCommandAsync();
  349. }
  350. /// <summary>
  351. /// 获取字段变更详情
  352. /// </summary>
  353. /// <param name="before">变更前</param>
  354. /// <param name="after">变更后</param>
  355. /// <param name="exclFields">排除字段</param>
  356. /// <returns>变更详情列表</returns>
  357. private List<FieldChangeDetail> GetChangeDetails(Grp_VisaProcessSteps before, Grp_VisaProcessSteps after, List<string> exclFields = null)
  358. {
  359. var changeDetails = new List<FieldChangeDetail>();
  360. var defaultExclFields = GetDefaultExcludedFields();
  361. // 合并排除字段
  362. var allExclFields = defaultExclFields;
  363. if (exclFields != null && exclFields.Any())
  364. {
  365. allExclFields = defaultExclFields.Union(exclFields).ToList();
  366. }
  367. if (before == null || after == null) return changeDetails;
  368. var properties = typeof(Grp_VisaProcessSteps).GetProperties(BindingFlags.Public | BindingFlags.Instance);
  369. foreach (var prop in properties)
  370. {
  371. // 跳过排除的字段
  372. if (allExclFields.Contains(prop.Name))
  373. {
  374. continue;
  375. }
  376. var beforeValue = prop.GetValue(before);
  377. var afterValue = prop.GetValue(after);
  378. // 处理字符串类型的特殊比较(忽略前后空格)
  379. if (prop.PropertyType == typeof(string))
  380. {
  381. var beforeString = beforeValue?.ToString()?.Trim();
  382. var afterString = afterValue?.ToString()?.Trim();
  383. if (beforeString != afterString)
  384. {
  385. changeDetails.Add(new FieldChangeDetail
  386. {
  387. FieldName = prop.Name,
  388. BeforeValue = FormatValue(beforeString),
  389. AfterValue = FormatValue(afterString)
  390. });
  391. }
  392. }
  393. else
  394. {
  395. // 其他类型使用默认比较
  396. if (!Equals(beforeValue, afterValue))
  397. {
  398. changeDetails.Add(new FieldChangeDetail
  399. {
  400. FieldName = prop.Name,
  401. BeforeValue = FormatValue(beforeValue),
  402. AfterValue = FormatValue(afterValue)
  403. });
  404. }
  405. }
  406. }
  407. return changeDetails;
  408. }
  409. /// <summary>
  410. /// 格式化值显示
  411. /// </summary>
  412. /// <param name="value">原始值</param>
  413. /// <returns>格式化后的值</returns>
  414. private static string FormatValue(object value)
  415. {
  416. if (value == null) return "null";
  417. var strValue = value.ToString();
  418. // 处理空字符串
  419. if (string.IsNullOrEmpty(strValue)) return "空";
  420. // 处理布尔值
  421. if (value is bool boolValue) return boolValue ? "是" : "否";
  422. // 处理日期时间
  423. if (value is DateTime dateTimeValue) return dateTimeValue.ToString("yyyy-MM-dd HH:mm");
  424. // 处理长文本截断
  425. if (strValue.Length > 50) return strValue.Substring(0, 47) + "...";
  426. return strValue;
  427. }
  428. /// <summary>
  429. /// 生成操作描述
  430. /// </summary>
  431. /// <param name="opType">操作类型</param>
  432. /// <param name="before">操作前</param>
  433. /// <param name="after">操作后</param>
  434. /// <param name="chgDetails">变更详情</param>
  435. /// <returns>操作描述</returns>
  436. private static string GenerateOpDesc(string opType, Grp_VisaProcessSteps before,
  437. Grp_VisaProcessSteps after, List<FieldChangeDetail> chgDetails)
  438. {
  439. if (!chgDetails.Any())
  440. {
  441. return opType switch
  442. {
  443. "Create" => $"创建步骤:团组{after.GroupId}-步骤{after.Step}",
  444. "Update" => $"更新步骤:无变更",
  445. "Complete" => $"完成步骤:团组{after.GroupId}-步骤{after.Step}",
  446. "Uncomplete" => $"取消完成:团组{after.GroupId}-步骤{after.Step}",
  447. "Delete" => $"删除步骤:团组{before.GroupId}-步骤{before.Step}",
  448. "Upload" => $"上传附件:团组{after.GroupId}-步骤{after.Step}",
  449. _ => $"{opType}:团组{after?.GroupId ?? before?.GroupId}-步骤{after?.Step ?? before?.Step}"
  450. };
  451. }
  452. var changeDesc = string.Join("; ", chgDetails.Select(x =>
  453. $"{x.FieldName} ({x.BeforeValue} -> {x.AfterValue})"));
  454. return opType switch
  455. {
  456. "Create" => $"创建步骤:团组{after.GroupId}-步骤{after.Step}",
  457. "Update" => $"更新步骤:{changeDesc}",
  458. "Complete" => $"完成步骤:团组{after.GroupId}-步骤{after.Step}",
  459. "Uncomplete" => $"取消完成:团组{after.GroupId}-步骤{after.Step}",
  460. "Delete" => $"删除步骤:团组{before.GroupId}-步骤{before.Step}",
  461. "Upload" => $"上传附件:团组{after.GroupId}-步骤{after.Step}",
  462. _ => $"{opType}:{changeDesc}"
  463. };
  464. }
  465. /// <summary>
  466. /// 字段变更详情类
  467. /// </summary>
  468. private class FieldChangeDetail
  469. {
  470. public string FieldName { get; set; }
  471. public string BeforeValue { get; set; }
  472. public string AfterValue { get; set; }
  473. }
  474. /// <summary>
  475. /// 获取默认排除的字段列表(包含系统字段和忽略字段)
  476. /// </summary>
  477. /// <returns>默认排除的字段列表</returns>
  478. private static List<string> GetDefaultExcludedFields()
  479. {
  480. var defaultExcludedFields = new List<string>
  481. {
  482. nameof(Grp_VisaProcessSteps.Id),
  483. nameof(Grp_VisaProcessSteps.CreateTime),
  484. nameof(Grp_VisaProcessSteps.CreateUserId),
  485. //nameof(Grp_VisaProcessSteps.LastUpdateTime),
  486. //nameof(Grp_VisaProcessSteps.LastUpdateUserId),
  487. // 计算字段(原本标记为 [SugarColumn(IsIgnore = true)] 的字段)
  488. "TypedFileNameValue",
  489. "TypedValue",
  490. "StringValue",
  491. "IntValue",
  492. "DecimalValue",
  493. "BooleanValue",
  494. "DateTimeValue"
  495. };
  496. return defaultExcludedFields.Distinct().ToList();
  497. }
  498. /// <summary>
  499. /// 手动创建步骤实体的副本
  500. /// </summary>
  501. /// <param name="source">源步骤实体</param>
  502. /// <returns>新的步骤实体副本</returns>
  503. private Grp_VisaProcessSteps ManualClone(Grp_VisaProcessSteps source)
  504. {
  505. if (source == null) return null;
  506. return new Grp_VisaProcessSteps
  507. {
  508. Id = source.Id,
  509. GroupId = source.GroupId,
  510. Step = source.Step,
  511. DataType = source.DataType,
  512. StoreVal = source.StoreVal,
  513. AttachUrl = source.AttachUrl,
  514. IsCompleted = source.IsCompleted,
  515. LastUpdateUserId = source.LastUpdateUserId,
  516. LastUpdateTime = source.LastUpdateTime,
  517. CreateUserId = source.CreateUserId,
  518. CreateTime = source.CreateTime
  519. // 注意:这里不拷贝计算属性(TypedValue 等),因为它们会被重新计算
  520. };
  521. }
  522. /// <summary>
  523. /// 根据步骤记录ID获取该步骤的所有操作日志
  524. /// </summary>
  525. /// <param name="stepId">步骤记录的主键ID</param>
  526. /// <returns>步骤操作日志列表,按操作时间倒序排列</returns>
  527. public async Task<List<VisaProcessStepsLogView>> GetStepLogsAsync(int stepId)
  528. {
  529. return await _sqlSugar.Queryable<Grp_VisaProcessSteps_Log>()
  530. .LeftJoin<Sys_Users>((x, y) => x.CreateUserId == y.Id)
  531. .Where((x, y) => x.StepId == stepId)
  532. .Select((x, y) => new VisaProcessStepsLogView
  533. {
  534. StepId = x.StepId,
  535. GroupId = x.GroupId,
  536. Step = x.Step,
  537. OperationType = x.OperationType,
  538. OperationDescription = x.OperationDescription,
  539. Operator = y.CnName,
  540. OperationTime = x.CreateTime,
  541. })
  542. .OrderByDescending(x => x.OperationTime)
  543. .ToListAsync();
  544. }
  545. /// <summary>
  546. /// 根据团组ID获取该团组下所有步骤的操作日志
  547. /// </summary>
  548. /// <param name="groupId">团组ID</param>
  549. /// <returns>团组步骤操作日志列表,按操作时间倒序排列</returns>
  550. public async Task<List<VisaProcessStepsLogView>> GetGroupStepLogsAsync(int groupId)
  551. {
  552. return await _sqlSugar.Queryable<Grp_VisaProcessSteps_Log>()
  553. .LeftJoin<Sys_Users>((x, y) => x.CreateUserId == y.Id)
  554. .Where((x, y) => x.GroupId == groupId)
  555. .Select((x, y) => new VisaProcessStepsLogView
  556. {
  557. StepId = x.StepId,
  558. GroupId = x.GroupId,
  559. Step = x.Step,
  560. OperationType = x.OperationType,
  561. OperationDescription = x.OperationDescription,
  562. Operator = y.CnName,
  563. OperationTime = x.CreateTime,
  564. })
  565. .OrderByDescending(x => x.OperationTime)
  566. .ToListAsync();
  567. }
  568. #endregion
  569. }
  570. }