ice_raft.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. package controller
  2. import (
  3. "cold-delivery/app/admin/model"
  4. "cold-delivery/app/admin/service"
  5. "cold-delivery/app/admin/service/dto"
  6. "cold-delivery/common/actions"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/beego/beego/v2/core/logs"
  10. "github.com/gin-gonic/gin"
  11. "github.com/gin-gonic/gin/binding"
  12. "github.com/xuri/excelize/v2"
  13. "gogs.baozhida.cn/zoie/OAuth-core/api"
  14. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
  15. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  16. "net/url"
  17. "os"
  18. "time"
  19. )
  20. type IceRaftController struct {
  21. api.Api
  22. }
  23. // GetPage 获取冰排列表
  24. // @Summary 获取冰排列表
  25. // @Description 获取冰排列表
  26. // @Tags 冰排
  27. // @Param name query string false "冰排名称"
  28. // @Param pageSize query int false "页条数"
  29. // @Param page query int false "页码"
  30. // @Success 200 {object} response.Response{data=response.Page{list=[]model.IceRaft}} "{"code": 200, "data": [...]}"
  31. // @Router /api/ice-raft [get]
  32. // @Security Bearer
  33. func (e IceRaftController) GetPage(c *gin.Context) {
  34. s := service.IceRaft{}
  35. req := dto.IceRaftGetPageReq{}
  36. err := e.MakeContext(c).
  37. MakeOrm().
  38. Bind(&req, binding.Query).
  39. MakeService(&s.Service).
  40. Errors
  41. if err != nil {
  42. e.Logger.Error(err)
  43. e.Error(500, err, err.Error())
  44. return
  45. }
  46. //数据权限检查
  47. p := actions.GetPermissionFromContext(c)
  48. list := make([]model.IceRaft, 0)
  49. var count int64
  50. err = s.GetPage(&req, &list, &count, p)
  51. if err != nil {
  52. e.Error(500, err, err.Error())
  53. return
  54. }
  55. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  56. }
  57. func (e IceRaftController) GetPageByCoolerBoxId(c *gin.Context) {
  58. s := service.IceRaft{}
  59. req := dto.GetPageByCoolerBoxIdReq{}
  60. err := e.MakeContext(c).
  61. MakeOrm().
  62. Bind(&req, binding.Query).
  63. MakeService(&s.Service).
  64. Errors
  65. if err != nil {
  66. e.Logger.Error(err)
  67. e.Error(500, err, err.Error())
  68. return
  69. }
  70. //数据权限检查
  71. p := actions.GetPermissionFromContext(c)
  72. list := make([]string, 0)
  73. err = s.GetPageByCoolerBoxId(req.CoolerBoxId, &list, p)
  74. if err != nil {
  75. e.Error(500, err, err.Error())
  76. return
  77. }
  78. e.OK(list, "查询成功")
  79. }
  80. // GetNewestRecordPage 获取冰排记录列表
  81. // @Summary 获取冰排列表
  82. // @Description 获取冰排列表
  83. // @Tags 冰排
  84. // @Param name query string false "冰排名称"
  85. // @Param pageSize query int false "页条数"
  86. // @Param page query int false "页码"
  87. // @Success 200 {object} response.Response{data=response.Page{list=[]model.IceRaft}} "{"code": 200, "data": [...]}"
  88. // @Router /api/ice-raft [get]
  89. // @Security Bearer
  90. func (e IceRaftController) GetNewestRecordPage(c *gin.Context) {
  91. s := service.IceRaft{}
  92. req := dto.IceRaftGetNewestRecordPageReq{}
  93. err := e.MakeContext(c).
  94. MakeOrm().
  95. Bind(&req, binding.Query).
  96. MakeService(&s.Service).
  97. Errors
  98. if err != nil {
  99. e.Logger.Error(err)
  100. e.Error(500, err, err.Error())
  101. return
  102. }
  103. //数据权限检查
  104. p := actions.GetPermissionFromContext(c)
  105. list := make([]model.IceRaft, 0)
  106. var count int64
  107. err = s.GetRecordPage(&req, &list, &count, p)
  108. if err != nil {
  109. e.Error(500, err, err.Error())
  110. return
  111. }
  112. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  113. }
  114. func (e IceRaftController) GetNewestRecordPageSSE(c *gin.Context) {
  115. s := service.IceRaft{}
  116. req := dto.IceRaftGetNewestRecordPageReq{}
  117. err := e.MakeContext(c).
  118. MakeOrm().
  119. Bind(&req, binding.Query).
  120. MakeService(&s.Service).
  121. Errors
  122. if err != nil {
  123. e.Logger.Error(err)
  124. e.Error(500, err, err.Error())
  125. return
  126. }
  127. //数据权限检查
  128. p := actions.GetPermissionFromContext(c)
  129. list := make([]model.IceRaft, 0)
  130. var count int64
  131. // Set the response header to indicate SSE content type
  132. c.Header("Content-Type", "text/event-stream")
  133. c.Header("Cache-Control", "no-cache")
  134. c.Header("Connection", "keep-alive")
  135. // Create a channel to send events to the client
  136. println("Client connected")
  137. // Listen for client close and remove the client from the list
  138. notify := c.Writer.CloseNotify()
  139. go func() {
  140. <-notify
  141. fmt.Println("Client disconnected")
  142. }()
  143. type Page struct {
  144. Count int `json:"count"` //总数
  145. Page int `json:"page"` //页码
  146. PageSize int `json:"pageSize"` //页条数
  147. List interface{} `json:"list"`
  148. }
  149. type Response struct {
  150. RequestId string `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
  151. Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
  152. Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
  153. Status string `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"`
  154. Data Page `json:"data"`
  155. }
  156. // Continuously send data to the client
  157. for {
  158. err = s.GetRecordPage(&req, &list, &count, p)
  159. if err != nil {
  160. e.Error(500, err, err.Error())
  161. return
  162. }
  163. var response Response
  164. var page Page
  165. response.Code = 200
  166. response.Msg = "查询成功"
  167. response.Msg = "查询成功"
  168. page.Count = int(count)
  169. page.Page = req.GetPageIndex()
  170. page.PageSize = req.GetPageSize()
  171. page.List = list
  172. response.Data = page
  173. //data := <-eventChan
  174. res, _ := json.Marshal(&response)
  175. fmt.Fprintf(c.Writer, "data: %s\n\n", string(res))
  176. c.Writer.Flush()
  177. time.Sleep(10 * time.Second)
  178. }
  179. }
  180. // Get 通过id获取冰排
  181. // @Summary 通过id获取冰排
  182. // @Description 通过id获取冰排
  183. // @Tags 冰排
  184. // @Param id path string true "冰排id"
  185. // @Success 200 {object} response.Response{data=model.IceRaft} "{"code": 200, "data": [...]}"
  186. // @Router /api/ice-raft/{id} [get]
  187. // @Security Bearer
  188. func (e IceRaftController) Get(c *gin.Context) {
  189. s := service.IceRaft{}
  190. req := dto.IceRaftGetReq{}
  191. err := e.MakeContext(c).
  192. MakeOrm().
  193. Bind(&req, nil).
  194. MakeService(&s.Service).
  195. Errors
  196. if err != nil {
  197. e.Logger.Error(err)
  198. e.Error(500, err, err.Error())
  199. return
  200. }
  201. var object model.IceRaft
  202. p := actions.GetPermissionFromContext(c)
  203. //数据权限检查
  204. err = s.Get(&req, &object, p)
  205. if err != nil {
  206. e.Error(500, err, err.Error())
  207. return
  208. }
  209. e.OK(object, "查询成功")
  210. }
  211. // GetByCode 通过code获取冰排
  212. // @Summary 通过code获取冰排
  213. // @Description 通过code获取冰排
  214. // @Tags 冰排
  215. // @Param id path string true "冰排id"
  216. // @Success 200 {object} response.Response{data=model.IceRaft} "{"code": 200, "data": [...]}"
  217. // @Router /api/ice-raft/code/{code} [get]
  218. // @Security Bearer
  219. func (e IceRaftController) GetByCode(c *gin.Context) {
  220. s := service.IceRaft{}
  221. req := dto.IceRaftGetByCodeReq{}
  222. err := e.MakeContext(c).
  223. MakeOrm().
  224. Bind(&req, nil).
  225. MakeService(&s.Service).
  226. Errors
  227. if err != nil {
  228. e.Logger.Error(err)
  229. e.Error(500, err, err.Error())
  230. return
  231. }
  232. var object model.IceRaft
  233. p := actions.GetPermissionFromContext(c)
  234. //数据权限检查
  235. err = s.GetByCode(&req, &object, p)
  236. if err != nil {
  237. e.Error(500, err, err.Error())
  238. return
  239. }
  240. e.OK(object, "查询成功")
  241. }
  242. // Insert 添加冰排
  243. // @Summary 添加冰排
  244. // @Description 添加冰排
  245. // @Tags 冰排
  246. // @Accept application/json
  247. // @Product application/json
  248. // @Param data body dto.IceRaftInsertReq true "data"
  249. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  250. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  251. // @Router /api/ice-raft [post]
  252. // @Security Bearer
  253. func (e IceRaftController) Insert(c *gin.Context) {
  254. s := service.IceRaft{}
  255. req := dto.IceRaftInsertReq{}
  256. err := e.MakeContext(c).
  257. MakeOrm().
  258. Bind(&req, binding.JSON).
  259. MakeService(&s.Service).
  260. Errors
  261. if err != nil {
  262. e.Logger.Error(err)
  263. e.Error(500, err, err.Error())
  264. return
  265. }
  266. p := actions.GetPermissionFromContext(c)
  267. // 设置创建人
  268. req.SetCreateBy(user.GetUserId(c))
  269. req.SetDeptId(p.DeptId)
  270. err = s.Insert(&req)
  271. if err != nil {
  272. e.Error(500, err, err.Error())
  273. return
  274. }
  275. e.OK(req.GetId(), "添加成功")
  276. }
  277. // Update 修改冰排
  278. // @Summary 修改冰排
  279. // @Description 修改冰排
  280. // @Tags 冰排
  281. // @Accept application/json
  282. // @Product application/json
  283. // @Param data body dto.IceRaftUpdateReq true "body"
  284. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  285. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  286. // @Router /api/ice-raft [put]
  287. // @Security Bearer
  288. func (e IceRaftController) Update(c *gin.Context) {
  289. s := service.IceRaft{}
  290. req := dto.IceRaftUpdateReq{}
  291. err := e.MakeContext(c).
  292. MakeOrm().
  293. Bind(&req).
  294. MakeService(&s.Service).
  295. Errors
  296. if err != nil {
  297. e.Logger.Error(err)
  298. e.Error(500, err, err.Error())
  299. return
  300. }
  301. p := actions.GetPermissionFromContext(c)
  302. req.SetUpdateBy(user.GetUserId(c))
  303. err = s.Update(&req, p)
  304. if err != nil {
  305. e.Error(500, err, err.Error())
  306. return
  307. }
  308. e.OK(req.GetId(), "修改成功")
  309. }
  310. // Delete 删除冰排
  311. // @Summary 删除冰排
  312. // @Description 删除冰排
  313. // @Tags 冰排
  314. // @Accept application/json
  315. // @Product application/json
  316. // @Param data body dto.IceRaftDeleteReq true "body"
  317. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  318. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  319. // @Router /api/ice-raft [delete]
  320. // @Security Bearer
  321. func (e IceRaftController) Delete(c *gin.Context) {
  322. s := service.IceRaft{}
  323. req := dto.IceRaftDeleteReq{}
  324. err := e.MakeContext(c).
  325. MakeOrm().
  326. Bind(&req, binding.JSON, nil).
  327. MakeService(&s.Service).
  328. Errors
  329. if err != nil {
  330. e.Logger.Error(err)
  331. e.Error(500, err, err.Error())
  332. return
  333. }
  334. //数据权限检查
  335. p := actions.GetPermissionFromContext(c)
  336. err = s.Remove(&req, p)
  337. if err != nil {
  338. e.Error(500, err, err.Error())
  339. return
  340. }
  341. e.OK(req.GetId(), "删除成功")
  342. }
  343. // InStorage 冰排入库
  344. // @Summary 冰排入库
  345. // @Description 冰排入库
  346. // @Tags 冰排
  347. // @Accept application/json
  348. // @Product application/json
  349. // @Param data body dto.IceRaftInStorageReq true "body"
  350. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  351. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  352. // @Router /api/ice-raft [delete]
  353. // @Security Bearer
  354. func (e IceRaftController) InStorage(c *gin.Context) {
  355. s := service.IceRaft{}
  356. req := dto.IceRaftInStorageReq{}
  357. err := e.MakeContext(c).
  358. MakeOrm().
  359. Bind(&req, binding.JSON, nil).
  360. MakeService(&s.Service).
  361. Errors
  362. if err != nil {
  363. e.Logger.Error(err)
  364. e.Error(500, err, err.Error())
  365. return
  366. }
  367. //数据权限检查
  368. p := actions.GetPermissionFromContext(c)
  369. err = s.InStorage(&req, p)
  370. if err != nil {
  371. e.Error(500, err, err.Error())
  372. return
  373. }
  374. e.OK(nil, "入库成功")
  375. }
  376. // OutStorage 冰排出库
  377. // @Summary 冰排出库
  378. // @Description 冰排出库
  379. // @Tags 冰排
  380. // @Accept application/json
  381. // @Product application/json
  382. // @Param data body dto.IceRaftOutStorageReq true "body"
  383. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  384. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  385. // @Router /api/ice-raft [delete]
  386. // @Security Bearer
  387. func (e IceRaftController) OutStorage(c *gin.Context) {
  388. s := service.IceRaft{}
  389. req := dto.IceRaftOutStorageReq{}
  390. err := e.MakeContext(c).
  391. MakeOrm().
  392. Bind(&req, binding.JSON, nil).
  393. MakeService(&s.Service).
  394. Errors
  395. if err != nil {
  396. e.Logger.Error(err)
  397. e.Error(500, err, err.Error())
  398. return
  399. }
  400. //数据权限检查
  401. p := actions.GetPermissionFromContext(c)
  402. err = s.OutStorage(&req, p)
  403. if err != nil {
  404. e.Error(500, err, err.Error())
  405. return
  406. }
  407. e.OK(nil, "出库成功")
  408. }
  409. // IsOutStorage 判断冰排出库
  410. // @Summary 判断冰排出库
  411. // @Description 判断冰排出库
  412. // @Tags 冰排
  413. // @Accept application/json
  414. // @Product application/json
  415. // @Param data body dto.IceRaftOutStorageReq true "body"
  416. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  417. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  418. // @Router /api/isoutstorage [post]
  419. // @Security Bearer
  420. func (e IceRaftController) IsOutStorage(c *gin.Context) {
  421. s := service.IceRaft{}
  422. req := dto.IceOutStorageReq{}
  423. err := e.MakeContext(c).
  424. MakeOrm().
  425. Bind(&req, binding.JSON, nil).
  426. MakeService(&s.Service).
  427. Errors
  428. if err != nil {
  429. e.Logger.Error(err)
  430. e.Error(500, err, err.Error())
  431. return
  432. }
  433. //数据权限检查
  434. p := actions.GetPermissionFromContext(c)
  435. err, str := s.IsOutStorage(&req, p)
  436. if err != nil {
  437. e.Error(500, err, err.Error())
  438. return
  439. }
  440. e.OK(nil, str)
  441. }
  442. type IceRaftRecordController struct {
  443. api.Api
  444. }
  445. // GetPage 获取冰排历史记记录列表
  446. // @Summary 获取冰排列表
  447. // @Description 获取冰排列表
  448. // @Tags 冰排
  449. // @Param name query string false "冰排名称"
  450. // @Param pageSize query int false "页条数"
  451. // @Param page query int false "页码"
  452. // @Success 200 {object} response.Response{data=response.Page{list=[]model.IceRaft}} "{"code": 200, "data": [...]}"
  453. // @Router /api/ice-raft [get]
  454. // @Security Bearer
  455. func (e IceRaftRecordController) GetPage(c *gin.Context) {
  456. s := service.IceRaftRecord{}
  457. req := dto.IceRaftRecordGetPageReq{}
  458. err := e.MakeContext(c).
  459. MakeOrm().
  460. Bind(&req, binding.Query).
  461. MakeService(&s.Service).
  462. Errors
  463. if err != nil {
  464. e.Logger.Error(err)
  465. e.Error(500, err, err.Error())
  466. return
  467. }
  468. //数据权限检查
  469. p := actions.GetPermissionFromContext(c)
  470. list := make([]model.IceRaftRecord, 0)
  471. var count int64
  472. err = s.GetPage(&req, &list, &count, p)
  473. if err != nil {
  474. e.Error(500, err, err.Error())
  475. return
  476. }
  477. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  478. }
  479. // Update 修改冰排出入库历史记录
  480. // @Summary 修改冰排出入库历史记录
  481. // @Description 修改冰排出入库历史记录
  482. // @Tags 冰排
  483. // @Accept application/json
  484. // @Product application/json
  485. // @Param data body dto.IceRaftUpdateReq true "body"
  486. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  487. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  488. // @Router /api/ice-raft [put]
  489. // @Security Bearer
  490. func (e IceRaftRecordController) Update(c *gin.Context) {
  491. s := service.IceRaftRecord{}
  492. req := dto.IceRaftRecordUpdateReq{}
  493. err := e.MakeContext(c).
  494. MakeOrm().
  495. Bind(&req).
  496. MakeService(&s.Service).
  497. Errors
  498. if err != nil {
  499. e.Logger.Error(err)
  500. e.Error(500, err, err.Error())
  501. return
  502. }
  503. p := actions.GetPermissionFromContext(c)
  504. req.SetUpdateBy(user.GetUserId(c))
  505. err = s.Update(&req, p)
  506. if err != nil {
  507. e.Error(500, err, err.Error())
  508. return
  509. }
  510. e.OK(req.GetId(), "修改成功")
  511. }
  512. // Delete 删除冰排出入库历史记录
  513. // @Summary 删除冰排出入库历史记录
  514. // @Description 删除冰排出入库历史记录
  515. // @Tags 冰排
  516. // @Accept application/json
  517. // @Product application/json
  518. // @Param data body dto.IceRaftDeleteReq true "body"
  519. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  520. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  521. // @Router /api/ice-raft [delete]
  522. // @Security Bearer
  523. func (e IceRaftRecordController) Delete(c *gin.Context) {
  524. s := service.IceRaftRecord{}
  525. req := dto.IceRaftRecordDeleteReq{}
  526. err := e.MakeContext(c).
  527. MakeOrm().
  528. Bind(&req, binding.JSON, nil).
  529. MakeService(&s.Service).
  530. Errors
  531. if err != nil {
  532. e.Logger.Error(err)
  533. e.Error(500, err, err.Error())
  534. return
  535. }
  536. //数据权限检查
  537. p := actions.GetPermissionFromContext(c)
  538. err = s.Remove(&req, p)
  539. if err != nil {
  540. e.Error(500, err, err.Error())
  541. return
  542. }
  543. e.OK(req.GetId(), "删除成功")
  544. }
  545. // EndForCold 保温箱冰排结束适冷
  546. // @Summary 保温箱冰排结束适冷
  547. // @Description 保温箱冰排结束适冷
  548. // @Tags 冰排
  549. // @Accept application/json
  550. // @Product application/json
  551. // @Param data body dto.IceRaftRecordEedReq true "body"
  552. // @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
  553. // @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
  554. // @Router /api/end-for-cold [post]
  555. // @Security Bearer
  556. func (e IceRaftRecordController) EndForCold(c *gin.Context) {
  557. s := service.IceRaftRecord{}
  558. req := dto.IceRaftRecordEedReq{}
  559. err := e.MakeContext(c).
  560. MakeOrm().
  561. Bind(&req, binding.JSON, nil).
  562. MakeService(&s.Service).
  563. Errors
  564. if err != nil {
  565. e.Logger.Error(err)
  566. e.Error(500, err, err.Error())
  567. return
  568. }
  569. //数据权限检查
  570. p := actions.GetPermissionFromContext(c)
  571. err = s.EndForCold(&req, p)
  572. if err != nil {
  573. e.Error(500, err, err.Error())
  574. return
  575. }
  576. e.OK(req.Id, "提交成功")
  577. }
  578. // StartForCold 冰排开始释冷
  579. // @Summary 冰排开始释冷
  580. // @Description 冰排开始释冷
  581. // @Tags 冰排
  582. // @Accept application/json
  583. // @Product application/json
  584. // @Param data body dto.IceRaftRecordEedReq true "body"
  585. // @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
  586. // @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
  587. // @Router /api/start-for-cold [post]
  588. // @Security Bearer
  589. func (e IceRaftRecordController) StartForCold(c *gin.Context) {
  590. s := service.IceRaftRecord{}
  591. req := dto.IceStartbleForColfTimReq{}
  592. err := e.MakeContext(c).
  593. MakeOrm().
  594. Bind(&req, binding.JSON, nil).
  595. MakeService(&s.Service).
  596. Errors
  597. if err != nil {
  598. e.Logger.Error(err)
  599. e.Error(500, err, err.Error())
  600. return
  601. }
  602. //数据权限检查
  603. p := actions.GetPermissionFromContext(c)
  604. err = s.StartForCold(&req, p)
  605. if err != nil {
  606. e.Error(500, err, err.Error())
  607. return
  608. }
  609. e.OK(req, "提交成功")
  610. }
  611. // IceRaftRecordRecording 冰排使用记录
  612. // @Summary 冰排使用记录
  613. // @Description 冰排使用记录
  614. // @Tags 冰排
  615. // @Accept application/json
  616. // @Product application/json
  617. // @Param data body dto.IceRaftRecordEedReq true "body"
  618. // @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
  619. // @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
  620. // @Router /api/recording [get]
  621. // @Security Bearer
  622. func (e IceRaftRecordController) IceRaftRecordRecording(c *gin.Context) {
  623. s := service.IceRaft{}
  624. req := dto.IceRaftRecordRecording{}
  625. err := e.MakeContext(c).
  626. MakeOrm().
  627. Bind(&req, binding.Query).
  628. MakeService(&s.Service).
  629. Errors
  630. if err != nil {
  631. e.Logger.Error(err)
  632. e.Error(500, err, err.Error())
  633. return
  634. }
  635. //数据权限检查
  636. p := actions.GetPermissionFromContext(c)
  637. list := make([]model.IceRaftRecord, 0)
  638. var count int64
  639. err = s.IceRaftRecordRecording(&req, &list, &count, p)
  640. if err != nil {
  641. e.Error(500, err, err.Error())
  642. return
  643. }
  644. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  645. }
  646. // ExportExecl 导出冰排使用记录
  647. // @Summary 导出冰排使用记录
  648. // @Description 导出冰排使用记录
  649. // @Tags 冰排
  650. // @Accept application/json
  651. // @Product application/json
  652. // @Param data body dto.IceRaftRecordEedReq true "body"
  653. // @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
  654. // @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
  655. // @Router /api/export-execl [get]
  656. // @Security Bearer
  657. func (e IceRaftRecordController) ExportExecl(c *gin.Context) {
  658. s := service.IceRaft{}
  659. req := dto.IceRaftRecordRecording{}
  660. err := e.MakeContext(c).
  661. MakeOrm().
  662. Bind(&req, binding.Query).
  663. MakeService(&s.Service).
  664. Errors
  665. if err != nil {
  666. e.Logger.Error(err)
  667. e.Error(500, err, err.Error())
  668. return
  669. }
  670. //数据权限检查
  671. p := actions.GetPermissionFromContext(c)
  672. list := make([]model.IceRaftRecord, 0)
  673. var count int64
  674. req.Page = 1
  675. req.PageSize = 9999
  676. err = s.IceRaftRecordRecording(&req, &list, &count, p)
  677. if err != nil {
  678. e.Error(500, err, err.Error())
  679. return
  680. }
  681. f := excelize.NewFile() // 设置单元格的值
  682. //获取当前登录用户信息,查询是否有权限
  683. err, sysUser := service.GetUserProfile(e.Orm, p.UserId)
  684. if err != nil {
  685. e.Error(500, err, "获取用户信息失败")
  686. return
  687. }
  688. if sysUser.Dept.IsIceReleaseCold {
  689. // 这里设置表头ÒÒ
  690. f.SetCellValue("Sheet1", "A1", "序号")
  691. f.SetCellValue("Sheet1", "B1", "冰排编号")
  692. f.SetCellValue("Sheet1", "C1", "预冷日期")
  693. f.SetCellValue("Sheet1", "D1", "预冷时间")
  694. f.SetCellValue("Sheet1", "E1", "预冷温度")
  695. f.SetCellValue("Sheet1", "F1", "预冷地点")
  696. f.SetCellValue("Sheet1", "G1", "操作人员")
  697. f.SetCellValue("Sheet1", "H1", "使用日期")
  698. f.SetCellValue("Sheet1", "I1", "使用时间")
  699. f.SetCellValue("Sheet1", "J1", "操作人员")
  700. f.SetCellValue("Sheet1", "K1", "备注")
  701. // 设置列宽
  702. f.SetColWidth("Sheet1", "A", "A", 6)
  703. f.SetColWidth("Sheet1", "B", "B", 8)
  704. f.SetColWidth("Sheet1", "C", "C", 14)
  705. f.SetColWidth("Sheet1", "D", "D", 14)
  706. f.SetColWidth("Sheet1", "E", "E", 30)
  707. f.SetColWidth("Sheet1", "F", "F", 14)
  708. f.SetColWidth("Sheet1", "G", "G", 14)
  709. f.SetColWidth("Sheet1", "H", "H", 30)
  710. f.SetColWidth("Sheet1", "I", "J", 15)
  711. f.SetColWidth("Sheet1", "K", "K", 30)
  712. line := 1
  713. // 循环写入数据
  714. for i, v := range list {
  715. line++
  716. start, _ := time.Parse("2006-01-02 15:04:05", v.IceUseTime.String())
  717. end, _ := time.Parse("2006-01-02 15:04:05", v.StartIceColdTime.String())
  718. sub := start.Sub(end).String()
  719. parse, _ := time.Parse("2006-01-02 15:04:05", v.UpdatedAt.String())
  720. s2 := parse.Sub(end).String()
  721. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  722. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.Code)
  723. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.StartIceColdTime)
  724. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), sub)
  725. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.SuitableForCold)
  726. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.IceColdAddress)
  727. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.IceColdUsers)
  728. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.IceUseTime)
  729. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), s2)
  730. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.IceUseUsers)
  731. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), "")
  732. }
  733. } else {
  734. // 这里设置表头ÒÒ
  735. f.SetCellValue("Sheet1", "A1", "序号")
  736. f.SetCellValue("Sheet1", "B1", "冰排编号")
  737. f.SetCellValue("Sheet1", "C1", "操作人员")
  738. f.SetCellValue("Sheet1", "D1", "使用日期")
  739. f.SetCellValue("Sheet1", "E1", "使用时间")
  740. f.SetCellValue("Sheet1", "F1", "操作人员")
  741. f.SetCellValue("Sheet1", "G1", "备注")
  742. // 设置列宽
  743. f.SetColWidth("Sheet1", "A", "A", 6)
  744. f.SetColWidth("Sheet1", "B", "B", 8)
  745. f.SetColWidth("Sheet1", "C", "C", 14)
  746. f.SetColWidth("Sheet1", "D", "D", 30)
  747. f.SetColWidth("Sheet1", "E", "E", 15)
  748. f.SetColWidth("Sheet1", "F", "F", 30)
  749. f.SetColWidth("Sheet1", "G", "G", 30)
  750. line := 1
  751. // 循环写入数据
  752. for i, v := range list {
  753. line++
  754. start, _ := time.Parse("2006-01-02 15:04:05", v.IceUseTime.String())
  755. parse, _ := time.Parse("2006-01-02 15:04:05", v.UpdatedAt.String())
  756. s2 := parse.Sub(start).String()
  757. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  758. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.Code)
  759. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.IceColdUsers)
  760. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.IceUseTime)
  761. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), s2)
  762. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.IceUseUsers)
  763. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), "")
  764. }
  765. }
  766. timeStr := time.Now().Format("20060102150405")
  767. filePath := "ofile/" + "冰排使用记录表" + timeStr + ".xlsx"
  768. // 保存文件
  769. if err = f.SaveAs(filePath); err != nil {
  770. logs.Error("文件失败:", err)
  771. }
  772. defer func() {
  773. os.Remove(filePath)
  774. }()
  775. c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
  776. // PathEscape 函数对中文做处理
  777. c.Header("Content-Disposition", "attachment; filename="+url.PathEscape("冰排使用记录表"+timeStr+".xlsx"))
  778. c.Header("Content-Transfer-Encoding", "binary")
  779. c.File(filePath)
  780. }