VisaProcessRepository.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.ViewModels.Groups;
  6. using OASystem.Infrastructure.Tools;
  7. namespace OASystem.Infrastructure.Repositories.Groups
  8. {
  9. /// <summary>
  10. /// 签证流程步骤仓储
  11. /// </summary>
  12. public class VisaProcessRepository : BaseRepository<Grp_VisaProcessSteps, Grp_VisaProcessSteps>
  13. {
  14. private readonly IMapper _mapper;
  15. public VisaProcessRepository(SqlSugarClient sqlSugar, IMapper mapper)
  16. : base(sqlSugar)
  17. {
  18. _mapper = mapper;
  19. }
  20. /// <summary>
  21. /// 创建签证流程步骤
  22. /// </summary>
  23. /// <param name="groupId"></param>
  24. /// <param name="createUderId"></param>
  25. /// <returns></returns>
  26. public async Task<Result> Create(int createUderId,int groupId)
  27. {
  28. //团组有效验证
  29. var groupIsValid = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  30. .Where(g => g.Id == groupId && g.IsDel == 0)
  31. .AnyAsync();
  32. if (!groupIsValid)
  33. {
  34. return new Result(400, "团组无效,无法创建签证流程步骤。");
  35. }
  36. var existingSteps = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
  37. .Where(s => s.GroupId == groupId && s.IsDel == 0)
  38. .AnyAsync();
  39. if (existingSteps)
  40. {
  41. return new Result(400, "该团组的签证流程步骤已存在,无法重复创建。");
  42. }
  43. var steps = Grp_VisaProcessSteps.StepsInit(groupId, createUderId);
  44. var add = await _sqlSugar.Insertable(steps).ExecuteCommandAsync();
  45. if (add < 1) return new Result(400, "签证流程步骤创建失败。");
  46. return new Result(200,"Success");
  47. }
  48. /// <summary>
  49. /// 签证流程 Info
  50. /// </summary>
  51. /// <param name="dto"></param>
  52. /// <param name="createUderId"></param>
  53. /// <returns></returns>
  54. public async Task<Result> Info(VisaProcessInfoByGroupIdDto dto)
  55. {
  56. //团组有效验证
  57. //var groupIsValid = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  58. // .Where(g => g.Id == dto.GroupId && g.IsDel == 0)
  59. // .AnyAsync();
  60. //if (!groupIsValid)
  61. //{
  62. // return new Result(400, "团组无效,无法查询签证流程步骤。");
  63. //}
  64. var query = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
  65. .Where(s => s.GroupId == dto.GroupId && s.IsDel == 0)
  66. .OrderBy(s => s.Step)
  67. .ToListAsync();
  68. var infos = query.Select(s => new
  69. {
  70. s.Id,
  71. s.GroupId,
  72. s.Step,
  73. s.DataType,
  74. s.TypedValue,
  75. //s.StoreVal,
  76. s.IsCompleted,
  77. s.AttachUrl,
  78. s.TypedFileNameValue,
  79. s.Remark
  80. }).ToList();
  81. string msg = "Success";
  82. //如果不存在,则返回默认数据
  83. if (infos == null || infos.Count < 1)
  84. {
  85. infos = Grp_VisaProcessSteps.StepsInit(dto.GroupId, 208).Select(s => new {
  86. s.Id,
  87. s.GroupId,
  88. s.Step,
  89. s.DataType,
  90. s.TypedValue,
  91. //s.StoreVal,
  92. s.IsCompleted,
  93. s.AttachUrl,
  94. s.TypedFileNameValue,
  95. s.Remark
  96. }).ToList();
  97. msg = "签证流程步骤信息不存在,展示默认数据。";
  98. }
  99. //数据按照类型处理
  100. var datas = new List<object>();
  101. var view = new VisaProcessStepsInfoView();
  102. foreach (var item in infos)
  103. {
  104. if (item.DataType == "string")
  105. {
  106. var info = new VisaProcessStepsInfoByStringView
  107. {
  108. Id = item.Id,
  109. GroupId = item.GroupId,
  110. Step = item.Step,
  111. DataType = item.DataType,
  112. TypedValue = item.TypedValue == null ? "" : item.TypedValue.ToString(),
  113. //StoreVal = item.StoreVal,
  114. IsCompleted = item.IsCompleted,
  115. AttachUrl = item.TypedFileNameValue,
  116. Remark = item.Remark
  117. };
  118. if (item.Step == 1) view.Step1 = info;
  119. else if (item.Step == 2) view.Step2 = info;
  120. else if (item.Step == 3) view.Step3 = info;
  121. else if (item.Step == 4) view.Step4 = info;
  122. else if (item.Step == 5) view.Step5 = info;
  123. else if (item.Step == 8) view.Step8 = info;
  124. datas.Add(info);
  125. }
  126. else if (item.DataType == "bool")
  127. {
  128. bool boolVal = false;
  129. if (item.TypedValue != null)
  130. {
  131. boolVal = (bool)item.TypedValue;
  132. }
  133. var info = new VisaProcessStepsInfoByBoolView
  134. {
  135. Id = item.Id,
  136. GroupId = item.GroupId,
  137. Step = item.Step,
  138. DataType = item.DataType,
  139. TypedValue = boolVal,
  140. IsCompleted = item.IsCompleted,
  141. AttachUrl = item.TypedFileNameValue,
  142. Remark = item.Remark
  143. };
  144. if (item.Step == 6) view.Step6 = info;
  145. datas.Add(info);
  146. }
  147. else if (item.DataType == "string[]")
  148. {
  149. var listVal = new List<string>();
  150. var contnet = new VisaProcessSteps7Content() { IsSelected = false };
  151. if (item.TypedValue != null)
  152. {
  153. listVal = item.TypedValue switch
  154. {
  155. List<string> stringList => stringList,
  156. IEnumerable<string> stringEnumerable => stringEnumerable.ToList(),
  157. string str => new List<string> { str },
  158. IEnumerable<object> objectEnumerable => objectEnumerable.Select(x => x?.ToString() ?? "").ToList(),
  159. _ => new List<string> { item.TypedValue.ToString() ?? "" }
  160. };
  161. if (listVal != null && listVal.Count > 0)
  162. {
  163. contnet.IsSelected = bool.TryParse(CommonFun.GetValueOrDefault(listVal,0), out _);
  164. contnet.ProjectedDate = CommonFun.GetValueOrDefault(listVal, 1);
  165. }
  166. }
  167. var info = new VisaProcessStepsInfoByListView
  168. {
  169. Id = item.Id,
  170. GroupId = item.GroupId,
  171. Step = item.Step,
  172. DataType = item.DataType,
  173. TypedValue = contnet,
  174. IsCompleted = item.IsCompleted,
  175. AttachUrl = item.TypedFileNameValue,
  176. Remark = item.Remark
  177. };
  178. if (item.Step == 7) view.Step7 = info;
  179. datas.Add(info);
  180. }
  181. }
  182. return new Result(200, msg, view);
  183. }
  184. /// <summary>
  185. /// 修改签证流程步骤
  186. /// </summary>
  187. /// <param name="groupId"></param>
  188. /// <param name="createUderId"></param>
  189. /// <returns></returns>
  190. public async Task<Result> Update(Grp_VisaProcessSteps info)
  191. {
  192. var update = await _sqlSugar.Updateable<Grp_VisaProcessSteps>()
  193. .SetColumns(s => new Grp_VisaProcessSteps
  194. {
  195. StoreVal = info.StoreVal,
  196. //AttachUrl = info.AttachUrl,
  197. //IsCompleted = info.IsCompleted,
  198. LastUpdateUserId = info.LastUpdateUserId,
  199. LastUpdateTime = DateTime.Now,
  200. Remark = info.Remark
  201. })
  202. .Where(s => s.Id == info.Id && s.IsDel == 0)
  203. .ExecuteCommandAsync();
  204. if (update < 1) return new Result(400, "更新失败!");
  205. return new Result(200, "Success");
  206. }
  207. /// <summary>
  208. /// 批量修改top4Steps
  209. /// </summary>
  210. /// <param name="infos"></param>
  211. /// <returns></returns>
  212. public async Task<Result> UpdateBatchTop4Step(int groupId,int currUserId)
  213. {
  214. var steps = new List<int>() {
  215. 1, //签证启动日
  216. 2, //分配工作
  217. 3, //送外办时间
  218. 4, //预计出签时间
  219. };
  220. var visaSteps = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
  221. .Where(s => s.GroupId == groupId && s.IsDel == 0 && steps.Contains(s.Step))
  222. .ToListAsync();
  223. if (visaSteps.Count < 1) return new Result(400, "签证流程信息不存在。");
  224. //倒推表信息
  225. var invertedInfo = await _sqlSugar.Queryable<Grp_InvertedList>()
  226. .Where(i => i.DiId == groupId && i.IsDel == 0)
  227. .FirstAsync();
  228. if (invertedInfo == null) return new Result(400, "倒推表信息不存在。");
  229. //设置操作人和时间
  230. foreach (var item in visaSteps)
  231. {
  232. //默认确认完成
  233. item.IsCompleted = true;
  234. item.LastUpdateUserId = currUserId;
  235. item.LastUpdateTime = DateTime.Now;
  236. }
  237. //step=1 设置启动日值
  238. visaSteps.FirstOrDefault(x => x.Step == 1).TypedValue = DateTime.Now.ToString("yyyy-MM-dd");
  239. //step=2 分配工作
  240. visaSteps.FirstOrDefault(x => x.Step == 2).TypedValue = invertedInfo.IssueApprovalDt;
  241. //step=3 送外办时间
  242. visaSteps.FirstOrDefault(x => x.Step == 3).TypedValue = invertedInfo.SendVisaDt;
  243. //step=4 预计出签时间
  244. visaSteps.FirstOrDefault(x => x.Step == 4).TypedValue = invertedInfo.IssueVisaDt;
  245. var update = await _sqlSugar.Updateable(visaSteps)
  246. .UpdateColumns(it => new { it.StoreVal, it.LastUpdateUserId,it.LastUpdateTime })
  247. .ExecuteCommandAsync();
  248. if (update < 1) return new Result(400, "更新失败!");
  249. return new Result(200, "Success");
  250. }
  251. /// <summary>
  252. /// 设置已完成的步骤
  253. /// </summary>
  254. /// <param name="groupId"></param>
  255. /// <returns></returns>
  256. public async Task<Result> SetCompleted(int id,int currUserId)
  257. {
  258. //步骤信息验证
  259. var stepInfo = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
  260. .Where(s => s.Id == id && s.IsDel == 0 && s.IsCompleted)
  261. .FirstAsync();
  262. if (stepInfo != null) return new Result(400, "步骤信息已完成,无法重复设置。");
  263. var update = await _sqlSugar.Updateable<Grp_VisaProcessSteps>()
  264. .SetColumns(s => new Grp_VisaProcessSteps
  265. {
  266. IsCompleted = true,
  267. LastUpdateUserId = currUserId,
  268. LastUpdateTime = DateTime.Now
  269. })
  270. .Where(s => s.Id == id && s.IsDel == 0 && !s.IsCompleted)
  271. .ExecuteCommandAsync();
  272. if (update < 1) return new Result(400, "状态设置失败!");
  273. return new Result(200, "Success");
  274. }
  275. }
  276. }