OperationRecordService.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using DapperORMCore.Context.DataContext;
  2. using DapperORMCore.Model.BaseModel;
  3. using DapperORMCore.Model.CoreModel;
  4. using DapperORMCore.Repository.IRepositorys;
  5. using DapperORMCore.String.Consts;
  6. using DapperORMCore.String.Enums;
  7. using Microsoft.Extensions.Configuration;
  8. using NXWMS.Code;
  9. using NXWMS.DataAccess.Entity;
  10. using NXWMS.IService.NXWMS.SysSettings;
  11. using NXWMS.Model.AppModels.Condition.SysSettings;
  12. using NXWMS.Model.AppModels.Result.SysSettings;
  13. using NXWMS.Model.Common;
  14. using NXWMS.String.Enums;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using WestDistance.DapperORM.Repository.Repositorys;
  21. namespace NXWMS.Service.NXWMS.SysSettings
  22. {
  23. /// <summary>
  24. /// 参数服务
  25. /// </summary>
  26. [AutoInject(typeof(IOperationRecordService), InjectType.Scope)]
  27. public class OperationRecordService : ServiceBase, IOperationRecordService
  28. {
  29. /// <summary>
  30. /// 系统操作仓储中转
  31. /// </summary>
  32. private IDataRepositoryContext _dataContext;
  33. /// <summary>
  34. /// SQL节点仓储
  35. /// </summary>
  36. private ISQLNodeRepository _iSQLNodeRepository;
  37. /// <summary>
  38. /// 配置
  39. /// </summary>
  40. private IConfiguration _configuration;
  41. public OperationRecordService(IDataRepositoryContext dataRepositoryContext, IConfiguration configuration, ISQLNodeRepository iSQLNodeRepository)
  42. {
  43. this._dataContext = dataRepositoryContext;
  44. this._configuration = configuration;
  45. this._iSQLNodeRepository = iSQLNodeRepository;
  46. }
  47. /// <summary>
  48. /// 获取操作列表,支持分页
  49. /// </summary>
  50. /// <param name="info"></param>
  51. /// <returns></returns>
  52. public OperateResultInfo<PageQueryResultInfo<OperationRecordSearchResult>> GetList(OperationRecordSearchCondition info)
  53. {
  54. if (info == null)
  55. {
  56. return FailStatus(new PageQueryResultInfo<OperationRecordSearchResult> { });
  57. }
  58. if (info.OperationBeginTime == null || info.OperationEndTime == null)
  59. {
  60. return FailMessageStatus("请传递开始时间和结束时间参数!",
  61. new PageQueryResultInfo<OperationRecordSearchResult>());
  62. }
  63. if (info.PageIndex == 0 || info.PageSize == 0)
  64. {
  65. return FailMessageStatus("请传递分页码和分页个数!",
  66. new PageQueryResultInfo<OperationRecordSearchResult>());
  67. }
  68. var sqlAndBuilder = new StringBuilder();
  69. var sqlOrBuilder = new StringBuilder();
  70. var sql = $@"SELECT
  71. UsedFlagName = {_iSQLNodeRepository.GetEnumIntCaseString<UsedFlag>("USED_FLAG")},
  72. OperationUserName = (SELECT USER_NAME FROM SYS_USER C WHERE C.USER_ID=OPERATION_USER_ID),
  73. CreateName = (SELECT USER_NAME FROM SYS_USER A WHERE A.USER_ID=CREATE_BY),
  74. UpdateName = (SELECT USER_NAME FROM SYS_USER B WHERE B.USER_ID=UPDATE_BY),
  75. ApiOperationTypeName = CASE OPERATION_TYPE WHEN
  76. 'edit' then '新增'
  77. when 'add' then '新增'
  78. when 'get' then '查询'
  79. when 'deleted' then '逻辑删除'
  80. when 'remove' then '物理删除'
  81. when 'edit' then '编辑'
  82. else '其它' end,
  83. {info.ItemSQL} FROM WMS_LOG_OPERATION_RECORD
  84. WHERE 1=1 AND DEL_FLAG = 0 ";
  85. sqlAndBuilder = info.Id != null ?
  86. info.Id > 0 ?
  87. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("LOG_OPERATION_RECORD_ID", info.Id, DBOperationString._Equal)) :
  88. sqlAndBuilder : sqlAndBuilder;
  89. sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationContent) ?
  90. sqlAndBuilder :
  91. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_CONTENT", info.OperationContent, DBOperationString._ContainIn));
  92. sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationType) ?
  93. sqlAndBuilder :
  94. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_TYPE", info.OperationType, DBOperationString._Equal));
  95. sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationType) ?
  96. sqlAndBuilder :
  97. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_TYPE", info.OperationType, DBOperationString._Equal));
  98. sqlAndBuilder = info.UserId != null ?
  99. info.UserId > 0 ?
  100. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_USER_ID", info.UserId, DBOperationString._Equal)) :
  101. sqlAndBuilder : sqlAndBuilder;
  102. sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationObjectName) ?
  103. sqlAndBuilder :
  104. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_STATUS", info.OperationStatus, DBOperationString._Equal));
  105. sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationResult) ?
  106. sqlAndBuilder :
  107. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_RESULT", info.OperationResult, DBOperationString._ContainIn));
  108. sqlAndBuilder = info.Id != null ?
  109. info.Id > 0 ?
  110. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("LOG_OPERATION_RECORD_ID", info.Id, DBOperationString._Equal)) :
  111. sqlAndBuilder : sqlAndBuilder;
  112. sqlAndBuilder = info.OperationBeginTime != null ?
  113. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_TIME", info.OperationBeginTime, DBOperationString._LargeEqual))
  114. : sqlAndBuilder;
  115. sqlAndBuilder = info.OperationEndTime != null ?
  116. sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_TIME", info.OperationEndTime, DBOperationString._SmallEqual))
  117. : sqlAndBuilder;
  118. sql = sql + (sqlAndBuilder.Length > 0 ? _iSQLNodeRepository.GetAndString(sqlAndBuilder, false) : "");
  119. var result = new DataRepository<OperationRecordSearchResult>(_dataContext).QueryPage(sql, "OPERATION_TIME", info.PageSize, info.PageIndex, true);
  120. var totalResult = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Query(sql);
  121. return SuccessStatus(new PageQueryResultInfo<OperationRecordSearchResult>
  122. {
  123. RowData = result,
  124. PageConditionInfo = info,
  125. TotalCount = totalResult.Count(),
  126. TotalPageCount = (int)Math.Ceiling((double)totalResult.Count() / info.PageSize)
  127. });
  128. }
  129. public OperateResultInfo Remove(OperationRecordCondition info)
  130. {
  131. var whereList = new List<FieldKeyInfo>()
  132. .AddFieldKeyInfo(nameof(WMS_LOG_OPERATION_RECORD.LOG_OPERATION_RECORD_ID), info.Id,
  133. EnumCSharpPropertyType.INT32, DBOperationString._Equal,
  134. info.Id != null);
  135. var result = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Query(whereList).FirstOrDefault();
  136. if (result != null)
  137. {
  138. var affectedRows = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Remove("LOG_OPERATION_RECORD_ID",
  139. result.LOG_OPERATION_RECORD_ID.ToString());
  140. return GetStatus(affectedRows);
  141. }
  142. return FailMessageStatus("未查找到数据!");
  143. }
  144. public OperateResultInfo Add(OperationRecordCondition info)
  145. {
  146. if (info == null)
  147. {
  148. return FailStatus();
  149. }
  150. var now = DateTime.Now;
  151. var entity = new WMS_LOG_OPERATION_RECORD
  152. {
  153. CREATE_BY = info.OperationUserId,
  154. CREATE_TIME = now,
  155. UPDATE_BY = info.OperationUserId,
  156. UPDATE_TIME = now,
  157. OPERATION_CONDITION = info.OperationCondition,
  158. OPERATION_CONTENT = info.OperationContent,
  159. OPERATION_OBJECT_NAME = info.OperationObjectName,
  160. OPERATION_RESULT = info.OperationResult,
  161. DESCRIBE = info.Describe,
  162. USED_FLAG = 1,
  163. OPERATION_STATUS = info.OperationStatus,
  164. OPERATION_TIME = info.OperationInTime,
  165. OPERATION_TYPE = info.OperationType,
  166. DEL_FLAG = 0,
  167. OPERATION_USER_ID = info.OperationUserId,
  168. };
  169. var affectedRows = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Add(entity, new string[1] { "LOG_OPERATION_RECORD_ID" });
  170. return GetStatus(affectedRows);
  171. }
  172. public OperateResultInfo Delete(OperationRecordCondition info)
  173. {
  174. var whereList = new List<FieldKeyInfo>()
  175. .AddFieldKeyInfo(nameof(WMS_LOG_OPERATION_RECORD.LOG_OPERATION_RECORD_ID), info.Id,
  176. EnumCSharpPropertyType.INT32, DBOperationString._Equal,
  177. info.Id != null);
  178. var result = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Query(whereList).FirstOrDefault();
  179. if (result != null)
  180. {
  181. var now = DateTime.Now;
  182. result.DEL_FLAG = 1;
  183. result.UPDATE_BY = info.OperationUserId;
  184. result.UPDATE_TIME = now;
  185. result.LOG_OPERATION_RECORD_ID = result.LOG_OPERATION_RECORD_ID;
  186. var affectedRows = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Update(result, "LOG_OPERATION_RECORD_ID");
  187. return SuccessStatus(affectedRows);
  188. }
  189. return FailMessageStatus("未查找到数据!");
  190. }
  191. public OperateResultInfo Edit(OperationRecordCondition info)
  192. {
  193. //操作日志编辑功能目前不添加
  194. return null;
  195. }
  196. }
  197. }