123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- using Cksoft.Data;
- using Cksoft.Data.Repository;
- using DllEapDal;
- using DllEapEntity;
- using DllEapEntity.Dtos;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace DllEapBll.Controllers
- {
- /// <summary>
- /// 日志
- /// </summary>
- [Route("eap/api/[controller]/[action]")]
- [ApiController]
- [Authorize]
- public class LogController : ControllerBase
- {
- private readonly string conn = "eapslave";
- private IConfiguration configuration;
- /// <summary>
- ///
- /// </summary>
- /// <param name="configuration"></param>
- public LogController(IConfiguration configuration)
- {
- this.configuration = configuration;
- }
- /// <summary>
- /// 获取日志列表
- /// </summary>
- /// <param name="sort"></param>
- /// <param name="platform"></param>
- /// <param name="actionstr"></param>
- /// <param name="message"></param>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="opeatorCode"></param>
- /// <param name="filter"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="sortFiled"></param>
- /// <param name="sortOrder"></param>
- /// <returns></returns>
- [HttpGet]
- public async Task<LayuiModel<EapLogDto>> GetLogList(string sort,
- int? platform, string actionstr, string message, DateTime? startTime, DateTime? endTime,
- string opeatorCode, string filter,
- int pageIndex = 1, int pageSize = 10, string sortFiled = "OperatingTime", string sortOrder = "ASC")
- {
- if (configuration["LogDbType"] == null || configuration["LogDbType"] == "Mysql")
- {
- sortFiled = "RecTime";
- if (!string.IsNullOrEmpty(sort))
- {
- var arr = sort.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- if (arr != null && arr.Length > 0)
- {
- sortFiled = arr[0];
- sortOrder = arr[1];
- }
- }
- if (string.IsNullOrEmpty(sortFiled) || sortFiled.ToString().ToLower() == "null")
- sort = "id";
- if (sortOrder == "ascend")
- sortOrder = "asc";
- else
- {
- sortOrder = "desc";
- }
- IEnumerable<Log> list = null;
- filter = filter ?? " ";
- using (IDatabase db = DbFactory.Base(conn))
- {
- var dal = new LogDal(db);
- int start = (pageIndex - 1) * pageSize + 1;
- string errorinfo = string.Empty;
- list = dal.GetLogList(start, pageSize, filter, sortFiled, sortOrder, ref errorinfo);
- var count = dal.GetLogCount(filter);
- var responseData = new LayuiModel<EapLogDto>()
- {
- code = 0,
- count = count,
- data = list.Select(c => new EapLogDto
- {
- Action = c.Action,
- Application = c.PlatformName,
- ApplicationId = c.Platform,
- CallSite = string.Empty,
- Category = c.Category,
- Controller = c.Module,
- Id = c.Id.ToString(),
- Levels = c.LogLevel,
- Message = c.Message,
- OperatingTime = c.RecTime,
- Reccode = c.RecCode,
- Requesturl = c.Action
- }),
- msg = ""
- };
- return responseData;
- }
- }
- else
- {
- if (!string.IsNullOrEmpty(sort))
- {
- var arr = sort.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- if (arr != null && arr.Length > 0)
- {
- sortFiled = arr[0];
- sortOrder = arr[1];
- }
- }
- if (string.IsNullOrEmpty(sortFiled) || sortFiled.ToString().ToLower() == "null")
- sort = "OperatingTime";
- if (sortOrder == "ascend")
- sortOrder = "asc";
- else
- {
- sortOrder = "desc";
- }
- var dal = new EapLogDal(configuration);
- int skip = (pageIndex - 1) * pageSize;
- return await dal.GetLogList(skip, pageSize, sortFiled, sortOrder, platform, actionstr,
- message, startTime, endTime, opeatorCode);
- }
- }
- /// <summary>
- /// 日志详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<EapLogDto> GetSingle(string id)
- {
- var log = new EapLogDto();
- if (configuration["LogDbType"] == null || configuration["LogDbType"] == "Mysql")
- {
- using (IDatabase db = DbFactory.Base(conn))
- {
- var dal = new LogDal(db);
- var data = dal.Get(Convert.ToInt32(id));
- log.Id = data.Id.ToString();
- log.Action = data.Action;
- log.Application = data.PlatformName;
- log.ApplicationId = data.Platform;
- log.Category = data.Category;
- log.Controller = data.Module;
- log.Levels = data.LogLevel;
- log.Message = data.Message;
- log.OperatingTime = data.RecTime;
- log.Reccode = data.RecCode;
- log.RecName = data.RecName;
- }
- }
- else
- {
- var logDal = new EapLogDal(configuration);
- log = await logDal.Get(id);
- }
- return log;
- }
- /// <summary>
- /// 机台日志
- /// </summary>
- /// <param name="maccode"></param>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <returns></returns>
- [HttpGet]
- public LayuiModel<string> ReadMachineLog(string maccode, string startTime, string endTime)
- {
- var responseData = new LayuiModel<string>()
- {
- code = 0,
- msg = ""
- };
- string errorinfo = string.Empty;
- List<string> vs = null;
- using (IDatabase db = DbFactory.Base(conn))
- {
- var dal = new LogDal(db);
- vs = dal.ReadLogList(maccode, startTime, endTime, ref errorinfo);
- }
- responseData.data = vs;
- responseData.msg = errorinfo;
- return responseData;
- }
- }
- }
|