ice_raft.go 23 KB

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