ice_raft.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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. "math"
  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. // BindCoolerBox 冰排绑定保温箱
  449. // @Summary 冰排绑定保温箱
  450. // @Description 冰排绑定保温箱
  451. // @Tags 冰排
  452. // @Accept application/json
  453. // @Product application/json
  454. // @Param data body dto.IceRaftOutStorageReq true "body"
  455. // @Success 200 {string} string "{"code": 200, "message": "绑定成功"}"
  456. // @Success 200 {string} string "{"code": -1, "message": "绑定失败"}"
  457. // @Router /api/bindCoolerBox [post]
  458. // @Security Bearer
  459. func (e IceRaftController) BindCoolerBox(c *gin.Context) {
  460. s := service.IceRaft{}
  461. req := dto.BindCoolerBox{}
  462. err := e.MakeContext(c).
  463. MakeOrm().
  464. Bind(&req, binding.JSON, nil).
  465. MakeService(&s.Service).
  466. Errors
  467. if err != nil {
  468. e.Logger.Error(err)
  469. e.Error(500, err, err.Error())
  470. return
  471. }
  472. //数据权限检查
  473. p := actions.GetPermissionFromContext(c)
  474. err = s.BindCookerBox(&req, p)
  475. if err != nil {
  476. e.Error(500, err, err.Error())
  477. return
  478. }
  479. e.OK(nil, "绑定成功")
  480. }
  481. // GetCoolerBoxBindCieRaft 获取保温箱可绑定冰排
  482. // @Summary 获取保温箱可绑定冰排
  483. // @Description 获取保温箱可绑定冰排
  484. // @Tags 冰排
  485. // @Accept application/json
  486. // @Product application/json
  487. // @Param data body dto.IceRaftOutStorageReq true "body"
  488. // @Success 200 {string} string "{"code": 200, "message": "绑定成功"}"
  489. // @Success 200 {string} string "{"code": -1, "message": "绑定失败"}"
  490. // @Router /api/bindCoolerBox [post]
  491. // @Security Bearer
  492. func (e IceRaftController) GetCoolerBoxBindCieRaft(c *gin.Context) {
  493. s := service.IceRaft{}
  494. req := dto.GetCoolerBoxByIceRaft{}
  495. err := e.MakeContext(c).
  496. MakeOrm().
  497. Bind(&req, binding.JSON, nil).
  498. MakeService(&s.Service).
  499. Errors
  500. if err != nil {
  501. e.Logger.Error(err)
  502. e.Error(500, err, err.Error())
  503. return
  504. }
  505. //数据权限检查
  506. list := make([]string, 0)
  507. p := actions.GetPermissionFromContext(c)
  508. err = s.GetCoolerBoxBindCieRaft(&req, p, &list)
  509. if err != nil {
  510. e.Error(500, err, err.Error())
  511. return
  512. }
  513. e.OK(list, "获取成功")
  514. }
  515. // GetIceRaft 获取未入库冰排
  516. // @Summary 获取未入库冰排
  517. // @Description 获取未入库冰排
  518. // @Tags 冰排
  519. // @Accept application/json
  520. // @Product application/json
  521. // @Param data body dto.IceRaftOutStorageReq true "body"
  522. // @Success 200 {string} string "{"code": 200, "message": "绑定成功"}"
  523. // @Success 200 {string} string "{"code": -1, "message": "绑定失败"}"
  524. // @Router /api/bindCoolerBox [post]
  525. // @Security Bearer
  526. func (e IceRaftController) GetIceRaft(c *gin.Context) {
  527. s := service.IceRaft{}
  528. err := e.MakeContext(c).
  529. MakeOrm().
  530. MakeService(&s.Service).
  531. Errors
  532. if err != nil {
  533. e.Logger.Error(err)
  534. e.Error(500, err, err.Error())
  535. return
  536. }
  537. //数据权限检查
  538. list := make([]model.IceRaft, 0)
  539. p := actions.GetPermissionFromContext(c)
  540. err = s.GetCoolerIceRaft(p, &list)
  541. if err != nil {
  542. e.Error(500, err, err.Error())
  543. return
  544. }
  545. e.OK(list, "获取成功")
  546. }
  547. // UnBindCoolerBox 冰排解邦
  548. // @Summary 冰排解邦
  549. // @Description 冰排解邦
  550. // @Tags 冰排
  551. // @Accept application/json
  552. // @Product application/json
  553. // @Param data body dto.IceRaftOutStorageReq true "body"
  554. // @Success 200 {string} string "{"code": 200, "message": "绑定成功"}"
  555. // @Success 200 {string} string "{"code": -1, "message": "绑定失败"}"
  556. // @Router /api/UnbindCoolerBox [post]
  557. // @Security Bearer
  558. func (e IceRaftController) UnBindCoolerBox(c *gin.Context) {
  559. s := service.IceRaft{}
  560. req := dto.UnBindCoolerBox{}
  561. err := e.MakeContext(c).
  562. MakeOrm().
  563. Bind(&req, binding.JSON, nil).
  564. MakeService(&s.Service).
  565. Errors
  566. if err != nil {
  567. e.Logger.Error(err)
  568. e.Error(500, err, err.Error())
  569. return
  570. }
  571. //数据权限检查
  572. p := actions.GetPermissionFromContext(c)
  573. err = s.UnBindCookerBox(&req, p)
  574. if err != nil {
  575. e.Error(500, err, err.Error())
  576. return
  577. }
  578. e.OK(nil, "修改成功")
  579. }
  580. type IceRaftRecordController struct {
  581. api.Api
  582. }
  583. // GetPage 获取冰排历史记记录列表
  584. // @Summary 获取冰排列表
  585. // @Description 获取冰排列表
  586. // @Tags 冰排
  587. // @Param name query string false "冰排名称"
  588. // @Param pageSize query int false "页条数"
  589. // @Param page query int false "页码"
  590. // @Success 200 {object} response.Response{data=response.Page{list=[]model.IceRaft}} "{"code": 200, "data": [...]}"
  591. // @Router /api/ice-raft [get]
  592. // @Security Bearer
  593. func (e IceRaftRecordController) GetPage(c *gin.Context) {
  594. s := service.IceRaftRecord{}
  595. req := dto.IceRaftRecordGetPageReq{}
  596. err := e.MakeContext(c).
  597. MakeOrm().
  598. Bind(&req, binding.Query).
  599. MakeService(&s.Service).
  600. Errors
  601. if err != nil {
  602. e.Logger.Error(err)
  603. e.Error(500, err, err.Error())
  604. return
  605. }
  606. //数据权限检查
  607. p := actions.GetPermissionFromContext(c)
  608. list := make([]model.IceRaftRecord, 0)
  609. var count int64
  610. err = s.GetPage(&req, &list, &count, p)
  611. if err != nil {
  612. e.Error(500, err, err.Error())
  613. return
  614. }
  615. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  616. }
  617. // Update 修改冰排出入库历史记录
  618. // @Summary 修改冰排出入库历史记录
  619. // @Description 修改冰排出入库历史记录
  620. // @Tags 冰排
  621. // @Accept application/json
  622. // @Product application/json
  623. // @Param data body dto.IceRaftUpdateReq true "body"
  624. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  625. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  626. // @Router /api/ice-raft [put]
  627. // @Security Bearer
  628. func (e IceRaftRecordController) Update(c *gin.Context) {
  629. s := service.IceRaftRecord{}
  630. req := dto.IceRaftRecordUpdateReq{}
  631. err := e.MakeContext(c).
  632. MakeOrm().
  633. Bind(&req).
  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. p := actions.GetPermissionFromContext(c)
  642. req.SetUpdateBy(user.GetUserId(c))
  643. err = s.Update(&req, p)
  644. if err != nil {
  645. e.Error(500, err, err.Error())
  646. return
  647. }
  648. e.OK(req.GetId(), "修改成功")
  649. }
  650. // Delete 删除冰排出入库历史记录
  651. // @Summary 删除冰排出入库历史记录
  652. // @Description 删除冰排出入库历史记录
  653. // @Tags 冰排
  654. // @Accept application/json
  655. // @Product application/json
  656. // @Param data body dto.IceRaftDeleteReq true "body"
  657. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  658. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  659. // @Router /api/ice-raft [delete]
  660. // @Security Bearer
  661. func (e IceRaftRecordController) Delete(c *gin.Context) {
  662. s := service.IceRaftRecord{}
  663. req := dto.IceRaftRecordDeleteReq{}
  664. err := e.MakeContext(c).
  665. MakeOrm().
  666. Bind(&req, binding.JSON, nil).
  667. MakeService(&s.Service).
  668. Errors
  669. if err != nil {
  670. e.Logger.Error(err)
  671. e.Error(500, err, err.Error())
  672. return
  673. }
  674. //数据权限检查
  675. p := actions.GetPermissionFromContext(c)
  676. err = s.Remove(&req, p)
  677. if err != nil {
  678. e.Error(500, err, err.Error())
  679. return
  680. }
  681. e.OK(req.GetId(), "删除成功")
  682. }
  683. // EndForCold 保温箱冰排结束适冷
  684. // @Summary 保温箱冰排结束适冷
  685. // @Description 保温箱冰排结束适冷
  686. // @Tags 冰排
  687. // @Accept application/json
  688. // @Product application/json
  689. // @Param data body dto.IceRaftRecordEedReq true "body"
  690. // @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
  691. // @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
  692. // @Router /api/end-for-cold [post]
  693. // @Security Bearer
  694. func (e IceRaftRecordController) EndForCold(c *gin.Context) {
  695. s := service.IceRaftRecord{}
  696. req := dto.IceRaftRecordEedReq{}
  697. err := e.MakeContext(c).
  698. MakeOrm().
  699. Bind(&req, binding.JSON, nil).
  700. MakeService(&s.Service).
  701. Errors
  702. if err != nil {
  703. e.Logger.Error(err)
  704. e.Error(500, err, err.Error())
  705. return
  706. }
  707. //数据权限检查
  708. p := actions.GetPermissionFromContext(c)
  709. err = s.EndForCold(&req, p)
  710. if err != nil {
  711. e.Error(500, err, err.Error())
  712. return
  713. }
  714. e.OK(req.Id, "提交成功")
  715. }
  716. // StartForCold 冰排开始释冷
  717. // @Summary 冰排开始释冷
  718. // @Description 冰排开始释冷
  719. // @Tags 冰排
  720. // @Accept application/json
  721. // @Product application/json
  722. // @Param data body dto.IceRaftRecordEedReq true "body"
  723. // @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
  724. // @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
  725. // @Router /api/start-for-cold [post]
  726. // @Security Bearer
  727. func (e IceRaftRecordController) StartForCold(c *gin.Context) {
  728. s := service.IceRaftRecord{}
  729. req := dto.IceStartbleForColfTimReq{}
  730. err := e.MakeContext(c).
  731. MakeOrm().
  732. Bind(&req, binding.JSON, nil).
  733. MakeService(&s.Service).
  734. Errors
  735. if err != nil {
  736. e.Logger.Error(err)
  737. e.Error(500, err, err.Error())
  738. return
  739. }
  740. //数据权限检查
  741. p := actions.GetPermissionFromContext(c)
  742. err = s.StartForCold(&req, p)
  743. if err != nil {
  744. e.Error(500, err, err.Error())
  745. return
  746. }
  747. e.OK(req, "提交成功")
  748. }
  749. // IceRaftRecordRecording 冰排使用记录
  750. // @Summary 冰排使用记录
  751. // @Description 冰排使用记录
  752. // @Tags 冰排
  753. // @Accept application/json
  754. // @Product application/json
  755. // @Param data body dto.IceRaftRecordEedReq true "body"
  756. // @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
  757. // @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
  758. // @Router /api/recording [get]
  759. // @Security Bearer
  760. func (e IceRaftRecordController) IceRaftRecordRecording(c *gin.Context) {
  761. s := service.IceRaft{}
  762. req := dto.IceRaftRecordRecording{}
  763. err := e.MakeContext(c).
  764. MakeOrm().
  765. Bind(&req, binding.Query).
  766. MakeService(&s.Service).
  767. Errors
  768. if err != nil {
  769. e.Logger.Error(err)
  770. e.Error(500, err, err.Error())
  771. return
  772. }
  773. //数据权限检查
  774. p := actions.GetPermissionFromContext(c)
  775. list := make([]model.IceRaftRecord, 0)
  776. var count int64
  777. err = s.IceRaftRecordRecording(&req, &list, &count, p)
  778. if err != nil {
  779. e.Error(500, err, err.Error())
  780. return
  781. }
  782. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  783. }
  784. // ExportExecl 导出冰排使用记录
  785. // @Summary 导出冰排使用记录
  786. // @Description 导出冰排使用记录
  787. // @Tags 冰排
  788. // @Accept application/json
  789. // @Product application/json
  790. // @Param data body dto.IceRaftRecordEedReq true "body"
  791. // @Success 200 {string} string "{"code": 200, "message": "提交成功"}"
  792. // @Success 200 {string} string "{"code": -1, "message": "提交成功"}"
  793. // @Router /api/export-execl [get]
  794. // @Security Bearer
  795. func (e IceRaftRecordController) ExportExecl(c *gin.Context) {
  796. s := service.IceRaft{}
  797. req := dto.IceRaftRecordRecording{}
  798. err := e.MakeContext(c).
  799. MakeOrm().
  800. Bind(&req, binding.Query).
  801. MakeService(&s.Service).
  802. Errors
  803. if err != nil {
  804. e.Logger.Error(err)
  805. e.Error(500, err, err.Error())
  806. return
  807. }
  808. //数据权限检查
  809. p := actions.GetPermissionFromContext(c)
  810. list := make([]model.IceRaftRecord, 0)
  811. var count int64
  812. req.Page = 1
  813. req.PageSize = 9999
  814. err = s.IceRaftRecordRecording(&req, &list, &count, p)
  815. if err != nil {
  816. e.Error(500, err, err.Error())
  817. return
  818. }
  819. f := excelize.NewFile() // 设置单元格的值
  820. //获取当前登录用户信息,查询是否有权限
  821. err, sysUser := service.GetUserProfile(e.Orm, p.UserId)
  822. if err != nil {
  823. e.Error(500, err, "获取用户信息失败")
  824. return
  825. }
  826. if sysUser.Dept.IsIceReleaseCold {
  827. // 这里设置表头ÒÒ
  828. f.SetCellValue("Sheet1", "A1", "序号")
  829. f.SetCellValue("Sheet1", "B1", "冰排编号")
  830. f.SetCellValue("Sheet1", "C1", "入库时间")
  831. f.SetCellValue("Sheet1", "D1", "出库时间")
  832. f.SetCellValue("Sheet1", "E1", "所在位置")
  833. f.SetCellValue("Sheet1", "F1", "冷冻要求")
  834. f.SetCellValue("Sheet1", "G1", "冷冻时间")
  835. f.SetCellValue("Sheet1", "H1", "释冷日期")
  836. f.SetCellValue("Sheet1", "I1", "释冷时间(小时)")
  837. f.SetCellValue("Sheet1", "J1", "释冷温度")
  838. f.SetCellValue("Sheet1", "K1", "释冷地点")
  839. f.SetCellValue("Sheet1", "L1", "操作人员")
  840. f.SetCellValue("Sheet1", "M1", "使用日期")
  841. f.SetCellValue("Sheet1", "N1", "使用时间")
  842. f.SetCellValue("Sheet1", "O1", "使用人员")
  843. f.SetCellValue("Sheet1", "P1", "备注")
  844. // 设置列宽
  845. f.SetColWidth("Sheet1", "A", "A", 6)
  846. f.SetColWidth("Sheet1", "B", "B", 8)
  847. f.SetColWidth("Sheet1", "C", "C", 14)
  848. f.SetColWidth("Sheet1", "D", "D", 14)
  849. f.SetColWidth("Sheet1", "E", "E", 15)
  850. f.SetColWidth("Sheet1", "F", "F", 14)
  851. f.SetColWidth("Sheet1", "G", "G", 14)
  852. f.SetColWidth("Sheet1", "H", "H", 14)
  853. f.SetColWidth("Sheet1", "I", "J", 15)
  854. f.SetColWidth("Sheet1", "K", "K", 15)
  855. f.SetColWidth("Sheet1", "L", "K", 15)
  856. f.SetColWidth("Sheet1", "M", "K", 15)
  857. f.SetColWidth("Sheet1", "N", "K", 15)
  858. f.SetColWidth("Sheet1", "O", "K", 15)
  859. f.SetColWidth("Sheet1", "P", "K", 15)
  860. line := 1
  861. // 循环写入数据
  862. for i, v := range list {
  863. line++
  864. start, _ := time.Parse("2006-01-02 15:04:05", v.StartIceColdTime.String())
  865. end, _ := time.Parse("2006-01-02 15:04:05", v.EndForColdTime.String())
  866. IceColdTime := end.Sub(start)
  867. ColdTime := fmt.Sprintf("%vh%vm", math.Floor(IceColdTime.Hours()), int(IceColdTime.Minutes())%60)
  868. Updstart, _ := time.Parse("2006-01-02 15:04:05", v.ReturnDate.String())
  869. Useend, _ := time.Parse("2006-01-02 15:04:05", v.IceUseTime.String())
  870. sub := Updstart.Sub(Useend)
  871. subTime := fmt.Sprintf("%vh%vm", math.Floor(sub.Hours()), int(sub.Minutes())%60)
  872. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  873. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.IceRafts.Code)
  874. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.InStorageTime)
  875. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.OutStorageTime)
  876. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.CoolerBox.Name)
  877. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.FreezeClaim)
  878. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.FreezeDuration)
  879. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.StartIceColdTime)
  880. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), ColdTime)
  881. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.SuitableForCold)
  882. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v.IceColdAddress)
  883. f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), v.IceColdUsers)
  884. f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), v.IceUseTime)
  885. f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), subTime)
  886. f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), v.IceUseUsers)
  887. f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), "")
  888. }
  889. } else {
  890. // 这里设置表头ÒÒ
  891. f.SetCellValue("Sheet1", "A1", "序号")
  892. f.SetCellValue("Sheet1", "B1", "冰排编号")
  893. f.SetCellValue("Sheet1", "C1", "入库时间")
  894. f.SetCellValue("Sheet1", "D1", "出库时间")
  895. f.SetCellValue("Sheet1", "E1", "所在位置")
  896. f.SetCellValue("Sheet1", "F1", "冷冻要求")
  897. f.SetCellValue("Sheet1", "G1", "冷冻时间")
  898. f.SetCellValue("Sheet1", "H1", "使用日期")
  899. f.SetCellValue("Sheet1", "I1", "使用时间")
  900. f.SetCellValue("Sheet1", "J1", "使用人员")
  901. f.SetCellValue("Sheet1", "K1", "备注")
  902. // 设置列宽
  903. f.SetColWidth("Sheet1", "A", "A", 6)
  904. f.SetColWidth("Sheet1", "B", "B", 8)
  905. f.SetColWidth("Sheet1", "C", "C", 14)
  906. f.SetColWidth("Sheet1", "D", "D", 15)
  907. f.SetColWidth("Sheet1", "E", "E", 15)
  908. f.SetColWidth("Sheet1", "F", "F", 15)
  909. f.SetColWidth("Sheet1", "G", "G", 15)
  910. f.SetColWidth("Sheet1", "H", "H", 15)
  911. f.SetColWidth("Sheet1", "I", "I", 15)
  912. f.SetColWidth("Sheet1", "J", "J", 15)
  913. f.SetColWidth("Sheet1", "K", "K", 15)
  914. line := 1
  915. // 循环写入数据
  916. for i, v := range list {
  917. line++
  918. Update, _ := time.Parse("2006-01-02 15:04:05", v.ReturnDate.String())
  919. UseTime, _ := time.Parse("2006-01-02 15:04:05", v.IceUseTime.String())
  920. sub := Update.Sub(UseTime)
  921. subTime := fmt.Sprintf("%vh%vm", math.Floor(sub.Hours()), int(sub.Minutes())%60)
  922. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  923. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.IceRafts.Code)
  924. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.InStorageTime)
  925. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.OutStorageTime)
  926. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.CoolerBox.Name)
  927. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.FreezeClaim)
  928. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.FreezeDuration)
  929. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.IceUseTime)
  930. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), subTime)
  931. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.IceUseUsers)
  932. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), "")
  933. }
  934. }
  935. timeStr := time.Now().Format("20060102150405")
  936. filePath := "ofile/" + "冰排使用记录表" + timeStr + ".xlsx"
  937. // 保存文件
  938. if err = f.SaveAs(filePath); err != nil {
  939. logs.Error("文件失败:", err)
  940. }
  941. defer func() {
  942. os.Remove(filePath)
  943. }()
  944. c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
  945. // PathEscape 函数对中文做处理
  946. c.Header("Content-Disposition", "attachment; filename="+url.PathEscape("冰排使用记录表"+timeStr+".xlsx"))
  947. c.Header("Content-Transfer-Encoding", "binary")
  948. c.File(filePath)
  949. }