waybill.go 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. "github.com/gin-gonic/gin"
  8. "github.com/gin-gonic/gin/binding"
  9. "gogs.baozhida.cn/zoie/OAuth-core/api"
  10. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
  11. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  12. )
  13. type WaybillController struct {
  14. api.Api
  15. }
  16. // GetPage 获取运单列表
  17. // @Summary 获取运单列表
  18. // @Description 获取运单列表
  19. // @Tags 运单
  20. // @Param no query string false "运单号"
  21. // @Param pageSize query int false "页条数"
  22. // @Param page query int false "页码"
  23. // @Success 200 {object} response.Response{data=response.Page{list=[]model.Waybill}} "{"code": 200, "data": [...]}"
  24. // @Router /api/waybill [get]
  25. // @Security Bearer
  26. func (e WaybillController) GetPage(c *gin.Context) {
  27. s := service.Waybill{}
  28. req := dto.WaybillGetPageReq{}
  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. //数据权限检查
  40. p := actions.GetPermissionFromContext(c)
  41. list := make([]model.Waybill, 0)
  42. var count int64
  43. err = s.GetPage(&req, &list, &count, p)
  44. if err != nil {
  45. e.Error(500, err, err.Error())
  46. return
  47. }
  48. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  49. }
  50. // Get 通过id获取运单
  51. // @Summary 通过id获取运单
  52. // @Description 通过id获取运单
  53. // @Tags 运单
  54. // @Param id path string true "运单id"
  55. // @Success 200 {object} response.Response{data=model.Waybill} "{"code": 200, "data": [...]}"
  56. // @Router /api/warehouse/{id} [get]
  57. // @Security Bearer
  58. func (e WaybillController) Get(c *gin.Context) {
  59. s := service.Waybill{}
  60. req := dto.WaybillGetReq{}
  61. err := e.MakeContext(c).
  62. MakeOrm().
  63. Bind(&req, nil).
  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. var object model.Waybill
  72. p := actions.GetPermissionFromContext(c)
  73. //数据权限检查
  74. err = s.Get(&req, &object, p)
  75. if err != nil {
  76. e.Error(500, err, err.Error())
  77. return
  78. }
  79. e.OK(object, "查询成功")
  80. }
  81. // Insert 添加运单
  82. // @Summary 添加运单
  83. // @Description 添加运单
  84. // @Tags 运单
  85. // @Accept application/json
  86. // @Product application/json
  87. // @Param data body dto.WaybillInsertReq true "data"
  88. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  89. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  90. // @Router /api/waybill [post]
  91. // @Security Bearer
  92. func (e WaybillController) Insert(c *gin.Context) {
  93. s := service.Waybill{}
  94. req := dto.WaybillInsertReq{}
  95. err := e.MakeContext(c).
  96. MakeOrm().
  97. Bind(&req, binding.JSON).
  98. MakeService(&s.Service).
  99. Errors
  100. if err != nil {
  101. e.Logger.Error(err)
  102. e.Error(500, err, err.Error())
  103. return
  104. }
  105. p := actions.GetPermissionFromContext(c)
  106. // 设置创建人
  107. req.SetCreateBy(user.GetUserId(c))
  108. req.SetDeptId(p.DeptId)
  109. err = s.Insert(&req)
  110. if err != nil {
  111. e.Error(500, err, err.Error())
  112. return
  113. }
  114. e.OK(req.GetId(), "创建成功")
  115. }
  116. // Update 修改运单
  117. // @Summary 修改运单
  118. // @Description 修改运单
  119. // @Tags 运单
  120. // @Accept application/json
  121. // @Product application/json
  122. // @Param data body dto.WaybillUpdateReq true "body"
  123. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  124. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  125. // @Router /api/waybill [put]
  126. // @Security Bearer
  127. func (e WaybillController) Update(c *gin.Context) {
  128. s := service.Waybill{}
  129. req := dto.WaybillUpdateReq{}
  130. err := e.MakeContext(c).
  131. MakeOrm().
  132. Bind(&req).
  133. MakeService(&s.Service).
  134. Errors
  135. if err != nil {
  136. e.Logger.Error(err)
  137. e.Error(500, err, err.Error())
  138. return
  139. }
  140. p := actions.GetPermissionFromContext(c)
  141. req.SetUpdateBy(user.GetUserId(c))
  142. err = s.Update(&req, p)
  143. if err != nil {
  144. e.Error(500, err, err.Error())
  145. return
  146. }
  147. e.OK(req.GetId(), "更新成功")
  148. }
  149. // Delivery 派单
  150. // @Summary 派单
  151. // @Description 派单
  152. // @Tags 运单
  153. // @Accept application/json
  154. // @Product application/json
  155. // @Param data body dto.WaybillDeliveryReq true "body"
  156. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  157. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  158. // @Router /api/waybill [put]
  159. // @Security Bearer
  160. func (e WaybillController) Delivery(c *gin.Context) {
  161. s := service.Waybill{}
  162. req := dto.WaybillDeliveryReq{}
  163. err := e.MakeContext(c).
  164. MakeOrm().
  165. Bind(&req).
  166. MakeService(&s.Service).
  167. Errors
  168. if err != nil {
  169. e.Logger.Error(err)
  170. e.Error(500, err, err.Error())
  171. return
  172. }
  173. p := actions.GetPermissionFromContext(c)
  174. req.SetUpdateBy(user.GetUserId(c))
  175. err = s.Delivery(&req, p)
  176. if err != nil {
  177. e.Error(500, err, err.Error())
  178. return
  179. }
  180. e.OK(req.GetId(), "派单成功")
  181. }
  182. // Delete 删除运单
  183. // @Summary 删除运单
  184. // @Description 删除运单
  185. // @Tags 运单
  186. // @Accept application/json
  187. // @Product application/json
  188. // @Param data body dto.WaybillDeleteReq true "body"
  189. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  190. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  191. // @Router /api/waybill [delete]
  192. // @Security Bearer
  193. func (e WaybillController) Delete(c *gin.Context) {
  194. s := service.Waybill{}
  195. req := dto.WaybillDeleteReq{}
  196. userSvc := service.SysUser{}
  197. err := e.MakeContext(c).
  198. MakeOrm().
  199. Bind(&req, binding.JSON, nil).
  200. MakeService(&s.Service).
  201. MakeService(&userSvc.Service).
  202. Errors
  203. if err != nil {
  204. e.Logger.Error(err)
  205. e.Error(500, err, err.Error())
  206. return
  207. }
  208. //数据权限检查
  209. p := actions.GetPermissionFromContext(c)
  210. err = s.Remove(&req, p)
  211. if err != nil {
  212. e.Error(500, err, err.Error())
  213. return
  214. }
  215. e.OK(req.GetId(), "删除成功")
  216. }
  217. // WarehouseIn 入库
  218. // @Summary 入库
  219. // @Description 入库
  220. // @Tags 运单
  221. // @Accept application/json
  222. // @Product application/json
  223. // @Param data body dto.WaybillInOutReq true "body"
  224. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  225. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  226. // @Router /api/waybill/warehouse-in [post]
  227. // @Security Bearer
  228. func (e WaybillController) WarehouseIn(c *gin.Context) {
  229. s := service.Waybill{}
  230. req := dto.WaybillInOutReq{}
  231. err := e.MakeContext(c).
  232. MakeOrm().
  233. Bind(&req, binding.JSON, nil).
  234. MakeService(&s.Service).
  235. Errors
  236. if err != nil {
  237. e.Logger.Error(err)
  238. e.Error(500, err, err.Error())
  239. return
  240. }
  241. //数据权限检查
  242. p := actions.GetPermissionFromContext(c)
  243. err = s.WarehouseIn(&req, p)
  244. if err != nil {
  245. e.Error(500, err, err.Error())
  246. return
  247. }
  248. e.OK(req.WaybillNoList, "入库成功")
  249. }
  250. // WarehouseOut 出库
  251. // @Summary 出库
  252. // @Description 出库
  253. // @Tags 运单
  254. // @Accept application/json
  255. // @Product application/json
  256. // @Param data body dto.WaybillInOutReq true "body"
  257. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  258. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  259. // @Router /api/waybill/warehouse-out [post]
  260. // @Security Bearer
  261. func (e WaybillController) WarehouseOut(c *gin.Context) {
  262. s := service.Waybill{}
  263. req := dto.WaybillInOutReq{}
  264. err := e.MakeContext(c).
  265. MakeOrm().
  266. Bind(&req, binding.JSON, nil).
  267. MakeService(&s.Service).
  268. Errors
  269. if err != nil {
  270. e.Logger.Error(err)
  271. e.Error(500, err, err.Error())
  272. return
  273. }
  274. //数据权限检查
  275. p := actions.GetPermissionFromContext(c)
  276. err = s.WarehouseOut(&req, p)
  277. if err != nil {
  278. e.Error(500, err, err.Error())
  279. return
  280. }
  281. e.OK(req.WaybillNoList, "出库成功")
  282. }
  283. // CarIn 上车
  284. // @Summary 上车
  285. // @Description 上车
  286. // @Tags 运单
  287. // @Accept application/json
  288. // @Product application/json
  289. // @Param data body dto.WaybillInOutReq true "body"
  290. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  291. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  292. // @Router /api/waybill/car-in [post]
  293. // @Security Bearer
  294. func (e WaybillController) CarIn(c *gin.Context) {
  295. s := service.Waybill{}
  296. req := dto.WaybillInOutReq{}
  297. err := e.MakeContext(c).
  298. MakeOrm().
  299. Bind(&req, binding.JSON, nil).
  300. MakeService(&s.Service).
  301. Errors
  302. if err != nil {
  303. e.Logger.Error(err)
  304. e.Error(500, err, err.Error())
  305. return
  306. }
  307. //数据权限检查
  308. p := actions.GetPermissionFromContext(c)
  309. err = s.CarIn(&req, p)
  310. if err != nil {
  311. e.Error(500, err, err.Error())
  312. return
  313. }
  314. e.OK(req.WaybillNoList, "装车成功")
  315. }
  316. // CarOut 下车
  317. // @Summary 下车
  318. // @Description 下车
  319. // @Tags 运单
  320. // @Accept application/json
  321. // @Product application/json
  322. // @Param data body dto.WaybillInOutReq true "body"
  323. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  324. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  325. // @Router /api/waybill/car-out [post]
  326. // @Security Bearer
  327. func (e WaybillController) CarOut(c *gin.Context) {
  328. s := service.Waybill{}
  329. req := dto.WaybillInOutReq{}
  330. err := e.MakeContext(c).
  331. MakeOrm().
  332. Bind(&req, binding.JSON, nil).
  333. MakeService(&s.Service).
  334. Errors
  335. if err != nil {
  336. e.Logger.Error(err)
  337. e.Error(500, err, err.Error())
  338. return
  339. }
  340. //数据权限检查
  341. p := actions.GetPermissionFromContext(c)
  342. err = s.CarOut(&req, p)
  343. if err != nil {
  344. e.Error(500, err, err.Error())
  345. return
  346. }
  347. e.OK(req.WaybillNoList, "下车成功")
  348. }