waybill_task.go 7.0 KB

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