loging.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. package log
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. "go.uber.org/zap"
  7. "log-server/global"
  8. "log-server/model/common/response"
  9. log2 "log-server/model/log"
  10. "log-server/model/log/request"
  11. "log-server/service/log"
  12. loging2 "log-server/service/log/loging"
  13. "log-server/utils"
  14. "strconv"
  15. )
  16. type ApiLoging struct {
  17. }
  18. // @Tags loging
  19. // @Summary 添加日志
  20. // @Security ApiKeyAuth
  21. // @accept application/json
  22. // @Produce application/json
  23. // @Param data body request.AddLogRequest true "simulator_ip(模拟器ip),simulator_mac(模拟器mac地址),pc_code(租机编号),pc_mac(租机mac地址),pc_ip(租机ip),device_id(绑定的设备id),account(账号),game_id(游戏id),coding(上传编码),computer_type(电脑类型),env_code(环境编号),log_uuid(日志uuid唯一,可以时间戳加随机数。上报一轮后更换),operator(脚本开发员),account_type(账号类型),remarks(备注),report_points_data(打点数据),task_type(1新增,2活跃),script_type(1中控,2脚本)脚本类型"
  24. // @Success 200 {object} response.Response{msg=string} "添加日志"
  25. // @Router /loging/setLog [Post]
  26. func (s *ApiLoging) CreateLog(c *gin.Context) {
  27. var api request.AddLogRequest
  28. _ = c.ShouldBindJSON(&api)
  29. body, _ := json.Marshal(api)
  30. global.GVA_LOG.Info(string(body))
  31. if err := utils.Verify(api, utils.LogAddVerify); err != nil {
  32. response.FailWithMessage(err.Error(), c)
  33. return
  34. }
  35. coding := strconv.Itoa(api.Coding)
  36. if len(coding) != 7 {
  37. response.FailWithMessage("该日志码没有7位"+coding, c)
  38. return
  39. }
  40. nodeCoding := coding[:3]
  41. status := coding[5:]
  42. noLogStatus := coding[3:5]
  43. var logical log.ServiceLoging
  44. switch nodeCoding {
  45. case "410":
  46. logical = new(loging2.PullAccountLog)
  47. break
  48. case "430":
  49. logical = new(loging2.SimulatorStartLog)
  50. break
  51. case "450":
  52. logical = new(loging2.GameStartLog)
  53. break
  54. case "460":
  55. logical = new(loging2.LoginLog)
  56. break
  57. case "470":
  58. logical = new(loging2.EnterMainLog)
  59. break
  60. case "480":
  61. logical = new(loging2.FeeLog)
  62. break
  63. default:
  64. logical = new(loging2.OtherLog)
  65. break
  66. }
  67. go ServiceLogList.CreateLog(c, api, logical, status, noLogStatus)
  68. response.OkWithMessage("后台已接收数据", c)
  69. }
  70. // @Tags loging
  71. // @Summary 获取log
  72. // @Security ApiKeyAuth
  73. // @accept application/json
  74. // @Produce application/json
  75. // @Param data body request.GetLogListRequest true "获取log"
  76. // @Success 200 {object} response.Response{data=response.GetLogCodingReply} "根据id获取coding,返回包括coding详情"
  77. // @Router /loging/getLogList [post]
  78. func (s *ApiLoging) GetLogList(c *gin.Context) {
  79. var paramsInfo request.GetLogListRequest
  80. _ = c.ShouldBindJSON(&paramsInfo)
  81. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  82. response.FailWithMessage(err.Error(), c)
  83. return
  84. }
  85. list, total, err := ServiceLogList.GetCodeLogList(c, paramsInfo.Loging, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc, paramsInfo.Code)
  86. if err != nil {
  87. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  88. response.FailWithMessage("获取失败", c)
  89. } else {
  90. response.OkWithDetailed(response.PageResult{
  91. List: list,
  92. Total: total,
  93. Page: paramsInfo.Page,
  94. PageSize: paramsInfo.PageSize,
  95. }, "获取成功", c)
  96. }
  97. }
  98. // @Tags loging
  99. // @Summary 获取打点log
  100. // @Security ApiKeyAuth
  101. // @accept application/json
  102. // @Produce application/json
  103. // @Param data body request.GetLogListRequest true "获取打点log"
  104. // @Success 200 {object} response.Response{data=response.GetLogCodingReply} "获取打点log列表"
  105. // @Router /loging/getReportLogList [post]
  106. func (s *ApiLoging) GetReportPointsLogList(c *gin.Context) {
  107. var paramsInfo request.ReportPointsListRequest
  108. _ = c.ShouldBindJSON(&paramsInfo)
  109. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  110. response.FailWithMessage(err.Error(), c)
  111. return
  112. }
  113. list, total, err := ServiceReportPointsLog.GetReportPointsLogList(paramsInfo.ReportPointsLog, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  114. if err != nil {
  115. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  116. response.FailWithMessage("获取失败", c)
  117. } else {
  118. response.OkWithDetailed(response.PageResult{
  119. List: list,
  120. Total: total,
  121. Page: paramsInfo.Page,
  122. PageSize: paramsInfo.PageSize,
  123. }, "获取成功", c)
  124. }
  125. }
  126. // @Tags loging
  127. // @Summary 获取iplog
  128. // @Security ApiKeyAuth
  129. // @accept application/json
  130. // @Produce application/json
  131. // @Param data body request.IpLogListRequest true "获取iplog"
  132. // @Success 200 {object} response.Response{data=log2.IpLog} "获取iplog列表"
  133. // @Router /loging/getIpLogList [post]
  134. func (s *ApiLoging) GetIpLogList(c *gin.Context) {
  135. var paramsInfo request.IpLogListRequest
  136. _ = c.ShouldBindJSON(&paramsInfo)
  137. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  138. response.FailWithMessage(err.Error(), c)
  139. return
  140. }
  141. list, total, err := ServiceIpLog.GetIpLogList(paramsInfo.IpLogRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  142. if err != nil {
  143. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  144. response.FailWithMessage("获取失败", c)
  145. } else {
  146. response.OkWithDetailed(response.PageResult{
  147. List: list,
  148. Total: total,
  149. Page: paramsInfo.Page,
  150. PageSize: paramsInfo.PageSize,
  151. }, "获取成功", c)
  152. }
  153. }
  154. // @Tags loging
  155. // @Summary 获取某天具体ip
  156. // @Security ApiKeyAuth
  157. // @accept application/json
  158. // @Produce application/json
  159. // @Param data body log2.IpLog true "获取ip"
  160. // @Success 200 {object} response.Response{data=log2.IpResponse} "获取iplog列表"
  161. // @Router /loging/getIp [post]
  162. func (s *ApiLoging) GetIp(c *gin.Context) {
  163. var ip log2.IpLogResponse
  164. _ = c.ShouldBindJSON(&ip)
  165. if ip.GameId == 0 {
  166. response.FailWithMessage("游戏id不能为空", c)
  167. return
  168. }
  169. if ip.PcCode == "" {
  170. response.FailWithMessage("租机编号不能为空", c)
  171. return
  172. }
  173. if ip.CreateDate == "" {
  174. response.FailWithMessage("创建日期不能为空", c)
  175. return
  176. }
  177. list, total, err := ServiceIpLog.GetIp(ip)
  178. if err != nil {
  179. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  180. response.FailWithMessage("获取失败", c)
  181. } else {
  182. response.OkWithDetailed(response.PageResult{
  183. List: list,
  184. Total: total,
  185. }, "获取成功", c)
  186. }
  187. }
  188. // @Tags loging
  189. // @Summary 获取统计节点log
  190. // @Security ApiKeyAuth
  191. // @accept application/json
  192. // @Produce application/json
  193. // @Success 200 {object} response.Response{data=interface{}} "获取统计log"
  194. // @Router /loging/getNodeStatisticsLogList [post]
  195. func (s *ApiLoging) GetNodeStatisticsLogList(c *gin.Context) {
  196. var paramsInfo request.GetStatisticsLogRequest
  197. _ = c.ShouldBindJSON(&paramsInfo)
  198. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  199. response.FailWithMessage(err.Error(), c)
  200. return
  201. }
  202. list, total, err := ServiceStatisticsLog.StatisticsNodeLogList(c, paramsInfo.StatisticsLog, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  203. if err != nil {
  204. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  205. response.FailWithMessage("获取失败", c)
  206. } else {
  207. response.OkWithDetailed(response.PageResult{
  208. List: list,
  209. Total: total,
  210. Page: paramsInfo.Page,
  211. PageSize: paramsInfo.PageSize,
  212. }, "获取成功", c)
  213. }
  214. }
  215. // @Tags loging
  216. // @Summary 获取统计log
  217. // @Security ApiKeyAuth
  218. // @accept application/json
  219. // @Produce application/json
  220. // @Success 200 {object} response.Response{data=interface{}} "获取统计log"
  221. // @Router /loging/getStatisticsLogList [post]
  222. func (s *ApiLoging) GetStatisticsLogList(c *gin.Context) {
  223. var paramsInfo request.GetStatisticsLogRequest
  224. _ = c.ShouldBindJSON(&paramsInfo)
  225. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  226. response.FailWithMessage(err.Error(), c)
  227. return
  228. }
  229. list, total, err := ServiceStatisticsLog.OtherStatisticsLogList(c, paramsInfo.StatisticsLog, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc, paramsInfo.GamePortId)
  230. if err != nil {
  231. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  232. response.FailWithMessage("获取失败", c)
  233. } else {
  234. response.OkWithDetailed(response.PageResult{
  235. List: list,
  236. Total: total,
  237. Page: paramsInfo.Page,
  238. PageSize: paramsInfo.PageSize,
  239. }, "获取成功", c)
  240. }
  241. }
  242. // @Tags loging
  243. // @Summary 重置统计log
  244. // @Security ApiKeyAuth
  245. // @accept application/json
  246. // @Produce application/json
  247. // @Param data body request.GetById true "根据id重置统计log"
  248. // @Success 200 {object} response.Response{data=interface{}} "重置统计log"
  249. // @Router /loging/resetStatisticsLog [post]
  250. //func (s *ApiLoging) ResetStatisticsLog(c *gin.Context) {
  251. // var paramsInfo request.GetById
  252. // _ = c.ShouldBindJSON(&paramsInfo)
  253. // if err := utils.Verify(paramsInfo, utils.IdVerify); err != nil {
  254. // response.FailWithMessage(err.Error(), c)
  255. // return
  256. // }
  257. // current := time.Now().Format("2006-01-02")
  258. // key := current + ":" + strconv.Itoa(paramsInfo.ID) + ":reset"
  259. // i, err := global.GVA_REDIS.Exists(c, key).Result()
  260. // if err != nil {
  261. // global.GVA_LOG.Error("重置统计数据检测key失败", zap.Error(err))
  262. // response.FailWithMessage("重置失败", c)
  263. // return
  264. // }
  265. // if i != 0 {
  266. // global.GVA_LOG.Info("还在重置中", zap.Error(err))
  267. // response.FailWithMessage("在重置中", c)
  268. // return
  269. // }
  270. // go ServiceStatisticsLog.ResetStatisticsLog(c, paramsInfo.ID, current)
  271. // response.OkWithMessage("后台重置中", c)
  272. //}
  273. // @Tags loging
  274. // @Summary 获取统计电脑
  275. // @Security ApiKeyAuth
  276. // @accept application/json
  277. // @Produce application/json
  278. // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑"
  279. // @Router /loging/getComputerStatistics [post]
  280. func (s *ApiLoging) GetComputerStatistics(c *gin.Context) {
  281. var paramsInfo request.GetStatisticsComputerRequest
  282. _ = c.ShouldBindJSON(&paramsInfo)
  283. /*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  284. response.FailWithMessage(err.Error(), c)
  285. return
  286. }*/
  287. list, total, err := ServiceStatisticsLog.ComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  288. if err != nil {
  289. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  290. response.FailWithMessage("获取失败", c)
  291. } else {
  292. response.OkWithDetailed(response.PageResult{
  293. List: list,
  294. Total: total,
  295. Page: paramsInfo.Page,
  296. PageSize: paramsInfo.PageSize,
  297. }, "获取成功", c)
  298. }
  299. }
  300. // @Tags loging
  301. // @Summary 在线电脑
  302. // @Security ApiKeyAuth
  303. // @accept application/json
  304. // @Produce application/json
  305. // @Success 200 {object} response.Response{data=interface{}} "在线电脑"
  306. // @Router /loging/getOnlineComputer [post]
  307. func (s *ApiLoging) GetOnlineComputer(c *gin.Context) {
  308. var paramsInfo request.GetStatisticsComputerRequest
  309. _ = c.ShouldBindJSON(&paramsInfo)
  310. list, total, err := ServiceStatisticsLog.OnlineComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  311. if err != nil {
  312. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  313. response.FailWithMessage("获取失败", c)
  314. } else {
  315. response.OkWithDetailed(response.PageResult{
  316. List: list,
  317. Total: total,
  318. Page: paramsInfo.Page,
  319. PageSize: paramsInfo.PageSize,
  320. }, "获取成功", c)
  321. }
  322. }
  323. // @Tags loging
  324. // @Summary 获取统计电脑数量
  325. // @Security ApiKeyAuth
  326. // @accept application/json
  327. // @Produce application/json
  328. // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑数量"
  329. // @Router /loging/getComputerNum [post]
  330. func (s *ApiLoging) GetComputerNum(c *gin.Context) {
  331. var paramsInfo request.GetStatisticsComputerRequest
  332. _ = c.ShouldBindJSON(&paramsInfo)
  333. num := ServiceStatisticsLog.GetComputerNum(paramsInfo.CreateDate)
  334. response.OkWithDetailed(num, "获取成功", c)
  335. }
  336. // @Tags loging
  337. // @Summary 获取统计数据通过GameId
  338. // @Security ApiKeyAuth
  339. // @accept application/json
  340. // @Produce application/json
  341. // @Success 200 {object} response.Response{data=interface{}} "获取统计数据通过GameId"
  342. // @Router /loging/getGameIdStatistics [post]
  343. func (s *ApiLoging) GetGameIdStatistics(c *gin.Context) {
  344. var paramsInfo request.GetStatisticsComputerRequest
  345. _ = c.ShouldBindJSON(&paramsInfo)
  346. /*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  347. response.FailWithMessage(err.Error(), c)
  348. return
  349. }*/
  350. list, total, err := ServiceStatisticsLog.GameStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo)
  351. if err != nil {
  352. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  353. response.FailWithMessage("获取失败", c)
  354. } else {
  355. response.OkWithDetailed(response.PageResult{
  356. List: list,
  357. Total: total,
  358. Page: paramsInfo.Page,
  359. PageSize: paramsInfo.PageSize,
  360. }, "获取成功", c)
  361. }
  362. }
  363. // @Tags loging
  364. // @Summary 获取统计电脑数量
  365. // @Security ApiKeyAuth
  366. // @accept application/json
  367. // @Produce application/json
  368. // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑数量"
  369. // @Router /loging/computerHeartbeat [post]
  370. func (s *ApiLoging) ComputerHeartbeat(c *gin.Context) {
  371. var paramsInfo request.OnlineComputerRequest
  372. _ = c.ShouldBindJSON(&paramsInfo)
  373. if paramsInfo.PcCode == "" || paramsInfo.Operator == "" {
  374. global.GVA_LOG.Error("参数错误!")
  375. response.FailWithMessage("参数错误", c)
  376. return
  377. }
  378. num := ServiceStatisticsLog.ComputerHeartbeat(c, paramsInfo)
  379. global.GVA_LOG.Warn(fmt.Sprintf("电脑上报参数pcc_code=%s Operator=%s", paramsInfo.PcCode, paramsInfo.Operator))
  380. response.OkWithDetailed(num, "上报成功", c)
  381. }
  382. // @Tags loging
  383. // @Summary 获取统计电脑数量
  384. // @Security ApiKeyAuth
  385. // @accept application/json
  386. // @Produce application/json
  387. // @Success 200 {object} response.Response{data=interface{}} "获取统计电脑数量"
  388. // @Router /loging/test [post]
  389. func (s *ApiLoging) ComputerTest(c *gin.Context) {
  390. var paramsInfo request.OnlineComputerRequest
  391. _ = c.ShouldBindJSON(&paramsInfo)
  392. ServiceStatisticsLog.RegularCheckPc()
  393. response.OkWithDetailed("b", "上报成功", c)
  394. }
  395. // @Tags loging
  396. // @Summary 导出Excel
  397. // @Security ApiKeyAuth
  398. // @accept application/json
  399. // @Produce application/octet-stream
  400. // @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息"
  401. // @Success 200
  402. // @Router /loging/exportExcel [post]
  403. func (e *ApiLoging) ExportExcel(c *gin.Context) {
  404. var excelInfo request.ExcelInfo
  405. _ = c.ShouldBindJSON(&excelInfo)
  406. paramsInfo := excelInfo.InfoList
  407. paramsInfo.PageSize = 300
  408. paramsInfo.Page = 1
  409. list, _, err := ServiceStatisticsLog.OnlineComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  410. if err != nil {
  411. global.GVA_LOG.Error("获取电脑数据失败!", zap.Error(err))
  412. response.FailWithMessage("获取电脑数据失败", c)
  413. return
  414. }
  415. filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
  416. err = ServiceStatisticsLog.ParseInfoList2Excel(list, filePath)
  417. if err != nil {
  418. global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
  419. response.FailWithMessage("转换Excel失败", c)
  420. return
  421. }
  422. c.Writer.Header().Add("success", "true")
  423. c.File(filePath)
  424. }
  425. // @Tags loging
  426. // @Summary 修改租机使用备注信息
  427. // @Security ApiKeyAuth
  428. // @accept application/json
  429. // @Produce application/json
  430. // @Param data body log2.ComputerUseRemarks true "id, 租机编号, 使用者, 租机供应商"
  431. // @Success 200 {object} response.Response{msg=string} "修改租机使用备注信息"
  432. // @Router /computer/updatePcRemarks [post]
  433. func (s *ApiLoging) UpdatePcRemarks(c *gin.Context) {
  434. var paramsInfo log2.ComputerUseRemarks
  435. _ = c.ShouldBindJSON(&paramsInfo)
  436. if err := utils.Verify(paramsInfo, utils.PcVerify); err != nil {
  437. response.FailWithMessage(err.Error(), c)
  438. return
  439. }
  440. if paramsInfo.PcCode == "" || paramsInfo.CreateDate == "" {
  441. response.FailWithMessage("有必要的参数未添加", c)
  442. return
  443. }
  444. if err := ServiceStatisticsLog.UpdateComputerUseLog(paramsInfo); err != nil {
  445. global.GVA_LOG.Error("修改失败!", zap.Error(err))
  446. response.FailWithMessage(err.Error(), c)
  447. } else {
  448. response.OkWithMessage("修改成功", c)
  449. }
  450. }
  451. // @Tags loging
  452. // @Summary 上报扫码订单信息
  453. // @Security ApiKeyAuth
  454. // @accept application/json
  455. // @Produce application/json
  456. // @Param data body request.GetCardListRequest true "扫码订单列表"
  457. // @Success 200 {object} response.Response{data=response.GetGameTaskListReply,msg=string} "分页游戏任务列表,返回包括列表,总数,页码,每页数量"
  458. // @Router /loging/getLogScanningList [post]
  459. func (s *ApiLoging) GetLogScanningList(c *gin.Context) {
  460. var paramsInfo request.GetLogScanningCodeRequest
  461. _ = c.ShouldBindJSON(&paramsInfo)
  462. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  463. response.FailWithMessage(err.Error(), c)
  464. return
  465. }
  466. if list, total, err := ServiceStatisticsLog.GetScanningInfoList(paramsInfo.LogScanningRequest, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc); err != nil {
  467. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  468. response.FailWithMessage("获取失败"+err.Error(), c)
  469. } else {
  470. response.OkWithDetailed(response.PageResult{
  471. List: list,
  472. Total: total,
  473. Page: paramsInfo.Page,
  474. PageSize: paramsInfo.PageSize,
  475. }, "获取成功", c)
  476. }
  477. }
  478. // @Tags loging
  479. // @Summary 导出Excel
  480. // @Security ApiKeyAuth
  481. // @accept application/json
  482. // @Produce application/octet-stream
  483. // @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息"
  484. // @Success 200
  485. // @Router /loging/computerRateExport [post]
  486. func (e *ApiLoging) ComputerRateExport(c *gin.Context) {
  487. var excelInfo request.ExcelInfo
  488. _ = c.ShouldBindJSON(&excelInfo)
  489. paramsInfo := excelInfo.InfoList
  490. paramsInfo.PageSize = 300
  491. paramsInfo.Page = 1
  492. list, _, err := ServiceStatisticsLog.ComputerStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  493. if err != nil {
  494. global.GVA_LOG.Error("获取电脑数据失败!", zap.Error(err))
  495. response.FailWithMessage("获取电脑数据失败", c)
  496. return
  497. }
  498. filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
  499. err = ServiceStatisticsLog.ComputeRateList2Excel(list, filePath)
  500. if err != nil {
  501. global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
  502. response.FailWithMessage("转换Excel失败", c)
  503. return
  504. }
  505. c.Writer.Header().Add("success", "true")
  506. c.File(filePath)
  507. }
  508. // @Tags loging
  509. // @Summary 七天電腦效率
  510. // @Security ApiKeyAuth
  511. // @accept application/json
  512. // @Produce application/octet-stream
  513. // @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息"
  514. // @Success 200
  515. // @Router /loging/computerSevenRate [post]
  516. func (e *ApiLoging) ComputerSevenRate(c *gin.Context) {
  517. var paramsInfo request.GetStatisticsComputerRequest
  518. _ = c.ShouldBindJSON(&paramsInfo)
  519. paramsInfo.PageSize = 300
  520. paramsInfo.Page = 1
  521. list, _, err := ServiceStatisticsLog.ComputerSevenStatistics(c, paramsInfo.LogComputer, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  522. if err != nil {
  523. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  524. response.FailWithMessage("获取失败", c)
  525. } else {
  526. response.OkWithDetailed(response.PageResult{
  527. List: list,
  528. Total: 1,
  529. Page: paramsInfo.Page,
  530. PageSize: paramsInfo.PageSize,
  531. }, "获取成功", c)
  532. }
  533. }
  534. // @Tags loging
  535. // @Summary 设备统计接口
  536. // @Security ApiKeyAuth
  537. // @accept application/json
  538. // @Produce application/json
  539. // @Param data body request.GetDeviceStatisticsRequest true "设备统计接口"
  540. // @Success 200
  541. // @Router /loging/getDeviceStatistics [post]
  542. func (e *ApiLoging) GetDeviceStatistics(c *gin.Context) {
  543. var paramsInfo request.GetDeviceStatisticsRequest
  544. _ = c.ShouldBindJSON(&paramsInfo)
  545. list, total, err := ServiceStatisticsLog.GetDeviceStatistics(c, paramsInfo.DeviceStatistics, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  546. if err != nil {
  547. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  548. response.FailWithMessage("获取失败", c)
  549. } else {
  550. response.OkWithDetailed(response.PageResult{
  551. List: list,
  552. Total: total,
  553. Page: paramsInfo.Page,
  554. PageSize: paramsInfo.PageSize,
  555. }, "获取成功", c)
  556. }
  557. }
  558. // @Tags loging
  559. // @Summary 设备统计接口
  560. // @Security ApiKeyAuth
  561. // @accept application/json
  562. // @Produce application/json
  563. // @Param data body request.GetDeviceStatisticsRequest true "设备统计接口"
  564. // @Success 200
  565. // @Router /loging/getDeviceInfoLog [post]
  566. func (e *ApiLoging) GetDeviceInfoLog(c *gin.Context) {
  567. var paramsInfo request.GetDeviceInfoLogRequest
  568. _ = c.ShouldBindJSON(&paramsInfo)
  569. list, total, err := ServiceStatisticsLog.GetDeviceInfo(c, paramsInfo.DeviceLog, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  570. if err != nil {
  571. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  572. response.FailWithMessage("获取失败", c)
  573. } else {
  574. response.OkWithDetailed(response.PageResult{
  575. List: list,
  576. Total: total,
  577. Page: paramsInfo.Page,
  578. PageSize: paramsInfo.PageSize,
  579. }, "获取成功", c)
  580. }
  581. }
  582. // @Tags loging
  583. // @Summary 设备id异常数据
  584. // @Security ApiKeyAuth
  585. // @accept application/json
  586. // @Produce application/json
  587. // @Param data body request.GetDeviceStatisticsRequest true "设备id异常数据"
  588. // @Success 200
  589. // @Router /loging/getDeviceIdErr [post]
  590. func (e *ApiLoging) GetDeviceIdErr(c *gin.Context) {
  591. var paramsInfo request.GetDeviceIdErrRequest
  592. _ = c.ShouldBindJSON(&paramsInfo)
  593. list, total, err := ServiceStatisticsLog.GetDeviceIdErr(c, paramsInfo.ScriptDeviceErr, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  594. if err != nil {
  595. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  596. response.FailWithMessage("获取失败", c)
  597. } else {
  598. response.OkWithDetailed(response.PageResult{
  599. List: list,
  600. Total: total,
  601. Page: paramsInfo.Page,
  602. PageSize: paramsInfo.PageSize,
  603. }, "获取成功", c)
  604. }
  605. }
  606. // @Tags loging
  607. // @Summary 导出Excel
  608. // @Security ApiKeyAuth
  609. // @accept application/json
  610. // @Produce application/octet-stream
  611. // @Param data body request.GetStatisticsComputerRequest true "导出Excel文件信息"
  612. // @Success 200
  613. // @Router /loging/deviceErrRateExcel [post]
  614. func (e *ApiLoging) DeviceErrRateExcel(c *gin.Context) {
  615. var excelInfo request.ExcelDeviceErrRate
  616. _ = c.ShouldBindJSON(&excelInfo)
  617. paramsInfo := excelInfo.InfoList
  618. paramsInfo.PageSize = 1000
  619. paramsInfo.Page = 1
  620. list, _, err := ServiceStatisticsLog.GetDeviceStatistics(c, paramsInfo.DeviceStatistics, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
  621. if err != nil {
  622. global.GVA_LOG.Error("获取电脑数据失败!", zap.Error(err))
  623. response.FailWithMessage("获取电脑数据失败", c)
  624. return
  625. }
  626. filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
  627. err = ServiceStatisticsLog.DeviceErrRateExcel(list, filePath)
  628. if err != nil {
  629. global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
  630. response.FailWithMessage("转换Excel失败", c)
  631. return
  632. }
  633. c.Writer.Header().Add("success", "true")
  634. c.File(filePath)
  635. }
  636. // @Tags loging
  637. // @Summary 设备异常数据接口
  638. // @Security ApiKeyAuth
  639. // @accept application/json
  640. // @Produce application/json
  641. // @Param data body log2.DeviceLog true "设备异常数据接口"
  642. // @Success 200
  643. // @Router /loging/getErrDeviceLog [post]
  644. func (e *ApiLoging) GetErrDeviceLog(c *gin.Context) {
  645. var paramsInfo log2.DeviceLog
  646. _ = c.ShouldBindJSON(&paramsInfo)
  647. list, err := ServiceStatisticsLog.GetDeviceContrastInfo(c, paramsInfo)
  648. if err != nil {
  649. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  650. response.FailWithMessage("获取失败", c)
  651. } else {
  652. response.OkWithDetailed(response.PageResult{
  653. List: list,
  654. }, "获取成功", c)
  655. }
  656. }