waybill_task.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package controller
  2. import (
  3. "cold-logistics/app/admin/model"
  4. "cold-logistics/app/admin/service"
  5. "cold-logistics/app/admin/service/dto"
  6. "cold-logistics/common/nats/nats_server"
  7. "errors"
  8. "github.com/gin-gonic/gin"
  9. "github.com/gin-gonic/gin/binding"
  10. "gogs.baozhida.cn/zoie/OAuth-core/api"
  11. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  12. )
  13. type WaybillTaskController struct {
  14. api.Api
  15. }
  16. // GetPage 获取运单任务列表
  17. // @Summary 获取运单任务列表
  18. // @Description 获取运单任务列表
  19. // @Tags 运单任务
  20. // @Param waybillNo query string true "运单号"
  21. // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
  22. // @Router /api/waybill-task [get]
  23. // @Security Bearer
  24. func (e WaybillTaskController) GetPage(c *gin.Context) {
  25. s := service.WaybillTask{}
  26. req := dto.WaybillTaskGetPageReq{}
  27. err := e.MakeContext(c).
  28. MakeOrm().
  29. Bind(&req, binding.Query).
  30. MakeService(&s.Service).
  31. Errors
  32. if err != nil {
  33. e.Logger.Error(err)
  34. e.Error(500, err, err.Error())
  35. return
  36. }
  37. list := make([]model.WaybillTask, 0)
  38. var count int64
  39. err = s.GetPage(&req, &list, &count)
  40. if err != nil {
  41. e.Error(500, err, err.Error())
  42. return
  43. }
  44. //e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  45. e.PageOK(list, int(count), 0, 0, "查询成功")
  46. }
  47. // GetData 获取温湿度记录
  48. // @Summary 获取传感器列表
  49. // @Description 获取传感器列表
  50. // @Tags 运单任务
  51. // @Accept application/json
  52. // @Product application/json
  53. // @Param data body dto.WaybillTaskGetDataPageReq true "body"
  54. // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
  55. // @Router /api/waybill-task/data [post]
  56. // @Security Bearer
  57. func (e WaybillTaskController) GetData(c *gin.Context) {
  58. s := service.WaybillTask{}
  59. req := dto.WaybillTaskGetDataPageReq{}
  60. err := e.MakeContext(c).
  61. MakeOrm().
  62. Bind(&req, binding.JSON, nil).
  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. list := make([]nats_server.DeviceData_R, 0)
  71. var count int64
  72. list, count, err = s.GetDataPage(&req)
  73. if err != nil {
  74. e.Error(500, err, err.Error())
  75. return
  76. }
  77. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  78. }
  79. // GetPrintData 获取打印的温湿度记录
  80. // @Summary 获取打印的温湿度记录
  81. // @Description 获取打印的温湿度记录
  82. // @Tags 运单任务
  83. // @Accept application/json
  84. // @Product application/json
  85. // @Param data body dto.WaybillTaskGetDataPageReq true "body"
  86. // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
  87. // @Router /api/waybill-task/print-data [post]
  88. // @Security Bearer
  89. func (e WaybillTaskController) GetPrintData(c *gin.Context) {
  90. s := service.WaybillTask{}
  91. waybillSvc := service.Waybill{}
  92. companySvc := service.Company{}
  93. req := dto.WaybillTaskGetDataPageReq{}
  94. err := e.MakeContext(c).
  95. MakeOrm().
  96. Bind(&req, binding.JSON, nil).
  97. MakeService(&s.Service).
  98. MakeService(&companySvc.Service).
  99. MakeService(&waybillSvc.Service).
  100. Errors
  101. if err != nil {
  102. e.Logger.Error(err)
  103. e.Error(500, err, err.Error())
  104. return
  105. }
  106. var waybill model.Waybill
  107. var company model.SysDept
  108. err = waybillSvc.GetByWaybillNo(&dto.WaybillGetByWaybillPdfReq{WaybillNo: req.WaybillNo}, &waybill, nil)
  109. if err != nil {
  110. e.Error(500, err, err.Error())
  111. return
  112. }
  113. err = companySvc.Get(&dto.CompanyGetReq{Id: waybill.DeptId}, &company)
  114. if err != nil {
  115. e.Error(500, err, err.Error())
  116. return
  117. }
  118. if company.PrintIntercept == true {
  119. var qualified bool
  120. qualified, err = waybillSvc.VerifyDataQualified(req.WaybillNo)
  121. if err != nil {
  122. e.Error(500, err, err.Error())
  123. return
  124. }
  125. if !qualified {
  126. err = errors.New("数据不合格,无法打印!")
  127. // 错误码 5000 提示无法打印
  128. e.Error(5000, err, err.Error())
  129. return
  130. }
  131. }
  132. list := make([]nats_server.DeviceData_R, 0)
  133. var count int64
  134. list, count, err = s.GetPrintDataPage(&req)
  135. if err != nil {
  136. e.Error(500, err, err.Error())
  137. return
  138. }
  139. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  140. }
  141. // GetNewestData 获取最新温湿度记录
  142. // @Summary 获取最新温湿度记录
  143. // @Description 获取最新温湿度记录
  144. // @Tags 运单任务
  145. // @Accept application/json
  146. // @Product application/json
  147. // @Param data body dto.WaybillTaskGetNewestDataPageReq true "body"
  148. // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
  149. // @Router /api/waybill-task/newest-locus [post]
  150. // @Security Bearer
  151. func (e WaybillTaskController) GetNewestData(c *gin.Context) {
  152. s := service.WaybillTask{}
  153. req := dto.WaybillTaskGetNewestDataPageReq{}
  154. err := e.MakeContext(c).
  155. MakeOrm().
  156. Bind(&req, binding.JSON, nil).
  157. MakeService(&s.Service).
  158. Errors
  159. if err != nil {
  160. e.Logger.Error(err)
  161. e.Error(500, err, err.Error())
  162. return
  163. }
  164. data := nats_server.DeviceData_R{}
  165. data, err = s.GetNewestDataPage(&req)
  166. if err != nil {
  167. e.Error(500, err, err.Error())
  168. return
  169. }
  170. e.OK(data, "查询成功")
  171. }
  172. // GetLocus 获取轨迹信息
  173. // @Summary 获取轨迹信息
  174. // @Description 获取轨迹信息
  175. // @Tags 运单任务
  176. // @Accept application/json
  177. // @Product application/json
  178. // @Param waybillNo query string true "运单号"
  179. // @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillTask}} "{"code": 200, "data": [...]}"
  180. // @Router /api/waybill-task/locus [get]
  181. // @Security Bearer
  182. func (e WaybillTaskController) GetLocus(c *gin.Context) {
  183. s := service.WaybillTask{}
  184. req := dto.WaybillGetLocusReq{}
  185. err := e.MakeContext(c).
  186. MakeOrm().
  187. Bind(&req, binding.Query).
  188. MakeService(&s.Service).
  189. Errors
  190. if err != nil {
  191. e.Logger.Error(err)
  192. e.Error(500, err, err.Error())
  193. return
  194. }
  195. list := make([]nats_server.DeviceData_R2, 0)
  196. list, err = s.GetLocus(&req)
  197. if err != nil {
  198. e.Error(500, err, err.Error())
  199. return
  200. }
  201. e.OK(list, "获取轨迹信息成功")
  202. }