123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- using DapperORMCore.Context.DataContext;
- using DapperORMCore.Model.BaseModel;
- using DapperORMCore.Model.CoreModel;
- using DapperORMCore.Repository.IRepositorys;
- using DapperORMCore.String.Consts;
- using DapperORMCore.String.Enums;
- using Microsoft.Extensions.Configuration;
- using NXWMS.Code;
- using NXWMS.DataAccess.Entity;
- using NXWMS.IService.NXWMS.SysSettings;
- using NXWMS.Model.AppModels.Condition.SysSettings;
- using NXWMS.Model.AppModels.Result.SysSettings;
- using NXWMS.Model.Common;
- using NXWMS.String.Enums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WestDistance.DapperORM.Repository.Repositorys;
- namespace NXWMS.Service.NXWMS.SysSettings
- {
- /// <summary>
- /// 参数服务
- /// </summary>
- [AutoInject(typeof(IOperationRecordService), InjectType.Scope)]
- public class OperationRecordService : ServiceBase, IOperationRecordService
- {
- /// <summary>
- /// 系统操作仓储中转
- /// </summary>
- private IDataRepositoryContext _dataContext;
- /// <summary>
- /// SQL节点仓储
- /// </summary>
- private ISQLNodeRepository _iSQLNodeRepository;
- /// <summary>
- /// 配置
- /// </summary>
- private IConfiguration _configuration;
- public OperationRecordService(IDataRepositoryContext dataRepositoryContext, IConfiguration configuration, ISQLNodeRepository iSQLNodeRepository)
- {
- this._dataContext = dataRepositoryContext;
- this._configuration = configuration;
- this._iSQLNodeRepository = iSQLNodeRepository;
- }
- /// <summary>
- /// 获取操作列表,支持分页
- /// </summary>
- /// <param name="info"></param>
- /// <returns></returns>
- public OperateResultInfo<PageQueryResultInfo<OperationRecordSearchResult>> GetList(OperationRecordSearchCondition info)
- {
- if (info == null)
- {
- return FailStatus(new PageQueryResultInfo<OperationRecordSearchResult> { });
- }
- if (info.OperationBeginTime == null || info.OperationEndTime == null)
- {
- return FailMessageStatus("请传递开始时间和结束时间参数!",
- new PageQueryResultInfo<OperationRecordSearchResult>());
- }
- if (info.PageIndex == 0 || info.PageSize == 0)
- {
- return FailMessageStatus("请传递分页码和分页个数!",
- new PageQueryResultInfo<OperationRecordSearchResult>());
- }
- var sqlAndBuilder = new StringBuilder();
- var sqlOrBuilder = new StringBuilder();
- var sql = $@"SELECT
- UsedFlagName = {_iSQLNodeRepository.GetEnumIntCaseString<UsedFlag>("USED_FLAG")},
- OperationUserName = (SELECT USER_NAME FROM SYS_USER C WHERE C.USER_ID=OPERATION_USER_ID),
- CreateName = (SELECT USER_NAME FROM SYS_USER A WHERE A.USER_ID=CREATE_BY),
- UpdateName = (SELECT USER_NAME FROM SYS_USER B WHERE B.USER_ID=UPDATE_BY),
- ApiOperationTypeName = CASE OPERATION_TYPE WHEN
- 'edit' then '新增'
- when 'add' then '新增'
- when 'get' then '查询'
- when 'deleted' then '逻辑删除'
- when 'remove' then '物理删除'
- when 'edit' then '编辑'
- else '其它' end,
- {info.ItemSQL} FROM WMS_LOG_OPERATION_RECORD
- WHERE 1=1 AND DEL_FLAG = 0 ";
- sqlAndBuilder = info.Id != null ?
- info.Id > 0 ?
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("LOG_OPERATION_RECORD_ID", info.Id, DBOperationString._Equal)) :
- sqlAndBuilder : sqlAndBuilder;
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationContent) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_CONTENT", info.OperationContent, DBOperationString._ContainIn));
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationType) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_TYPE", info.OperationType, DBOperationString._Equal));
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationType) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_TYPE", info.OperationType, DBOperationString._Equal));
- sqlAndBuilder = info.UserId != null ?
- info.UserId > 0 ?
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_USER_ID", info.UserId, DBOperationString._Equal)) :
- sqlAndBuilder : sqlAndBuilder;
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationObjectName) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_STATUS", info.OperationStatus, DBOperationString._Equal));
- sqlAndBuilder = string.IsNullOrWhiteSpace(info.OperationResult) ?
- sqlAndBuilder :
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_RESULT", info.OperationResult, DBOperationString._ContainIn));
- sqlAndBuilder = info.Id != null ?
- info.Id > 0 ?
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("LOG_OPERATION_RECORD_ID", info.Id, DBOperationString._Equal)) :
- sqlAndBuilder : sqlAndBuilder;
- sqlAndBuilder = info.OperationBeginTime != null ?
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_TIME", info.OperationBeginTime, DBOperationString._LargeEqual))
- : sqlAndBuilder;
- sqlAndBuilder = info.OperationEndTime != null ?
- sqlAndBuilder.Append(_iSQLNodeRepository.GetAddCondition("OPERATION_TIME", info.OperationEndTime, DBOperationString._SmallEqual))
- : sqlAndBuilder;
-
- sql = sql + (sqlAndBuilder.Length > 0 ? _iSQLNodeRepository.GetAndString(sqlAndBuilder, false) : "");
- var result = new DataRepository<OperationRecordSearchResult>(_dataContext).QueryPage(sql, "OPERATION_TIME", info.PageSize, info.PageIndex, true);
- var totalResult = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Query(sql);
- return SuccessStatus(new PageQueryResultInfo<OperationRecordSearchResult>
- {
- RowData = result,
- PageConditionInfo = info,
- TotalCount = totalResult.Count(),
- TotalPageCount = (int)Math.Ceiling((double)totalResult.Count() / info.PageSize)
- });
- }
- public OperateResultInfo Remove(OperationRecordCondition info)
- {
- var whereList = new List<FieldKeyInfo>()
- .AddFieldKeyInfo(nameof(WMS_LOG_OPERATION_RECORD.LOG_OPERATION_RECORD_ID), info.Id,
- EnumCSharpPropertyType.INT32, DBOperationString._Equal,
- info.Id != null);
- var result = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Query(whereList).FirstOrDefault();
- if (result != null)
- {
- var affectedRows = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Remove("LOG_OPERATION_RECORD_ID",
- result.LOG_OPERATION_RECORD_ID.ToString());
- return GetStatus(affectedRows);
- }
- return FailMessageStatus("未查找到数据!");
- }
- public OperateResultInfo Add(OperationRecordCondition info)
- {
- if (info == null)
- {
- return FailStatus();
- }
- var now = DateTime.Now;
- var entity = new WMS_LOG_OPERATION_RECORD
- {
- CREATE_BY = info.OperationUserId,
- CREATE_TIME = now,
- UPDATE_BY = info.OperationUserId,
- UPDATE_TIME = now,
- OPERATION_CONDITION = info.OperationCondition,
- OPERATION_CONTENT = info.OperationContent,
- OPERATION_OBJECT_NAME = info.OperationObjectName,
- OPERATION_RESULT = info.OperationResult,
- DESCRIBE = info.Describe,
- USED_FLAG = 1,
- OPERATION_STATUS = info.OperationStatus,
- OPERATION_TIME = info.OperationInTime,
- OPERATION_TYPE = info.OperationType,
- DEL_FLAG = 0,
- OPERATION_USER_ID = info.OperationUserId,
- };
- var affectedRows = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Add(entity, new string[1] { "LOG_OPERATION_RECORD_ID" });
- return GetStatus(affectedRows);
- }
- public OperateResultInfo Delete(OperationRecordCondition info)
- {
- var whereList = new List<FieldKeyInfo>()
- .AddFieldKeyInfo(nameof(WMS_LOG_OPERATION_RECORD.LOG_OPERATION_RECORD_ID), info.Id,
- EnumCSharpPropertyType.INT32, DBOperationString._Equal,
- info.Id != null);
- var result = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Query(whereList).FirstOrDefault();
- if (result != null)
- {
- var now = DateTime.Now;
- result.DEL_FLAG = 1;
- result.UPDATE_BY = info.OperationUserId;
- result.UPDATE_TIME = now;
- result.LOG_OPERATION_RECORD_ID = result.LOG_OPERATION_RECORD_ID;
- var affectedRows = new DataRepository<WMS_LOG_OPERATION_RECORD>(_dataContext).Update(result, "LOG_OPERATION_RECORD_ID");
- return SuccessStatus(affectedRows);
- }
- return FailMessageStatus("未查找到数据!");
- }
- public OperateResultInfo Edit(OperationRecordCondition info)
- {
- //操作日志编辑功能目前不添加
- return null;
- }
- }
- }
|