gas_cylinder_allot.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. package controller
  2. import (
  3. "errors"
  4. "gas-cylinder-api/app/admin/model"
  5. "gas-cylinder-api/app/admin/service"
  6. "gas-cylinder-api/app/admin/service/dto"
  7. "gas-cylinder-api/common/actions"
  8. "gas-cylinder-api/common/global"
  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 GasCylinderAllotController struct {
  16. api.Api
  17. }
  18. // GetPage 获取调拨信息列表
  19. // @Summary 获取调拨信息列表
  20. // @Description 获取调拨信息列表
  21. // @Tags 调拨信息
  22. // @Param name query string false "调拨信息名称"
  23. // @Success 200 {object} response.Response{data=response.Page{list=[]model.GasCylinderAllot}} "{"code": 200, "data": [...]}"
  24. // @Router /api/dispatch-cost [get]
  25. // @Security Bearer
  26. func (e GasCylinderAllotController) GetPage(c *gin.Context) {
  27. s := service.GasCylinderAllot{}
  28. req := dto.GasCylinderAllotGetPageReq{}
  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.GasCylinderAllot, 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.GasCylinderAllot} "{"code": 200, "data": [...]}"
  56. // @Router /api/dispatch-cost/{id} [get]
  57. // @Security Bearer
  58. func (e GasCylinderAllotController) Get(c *gin.Context) {
  59. s := service.GasCylinderAllot{}
  60. req := dto.GasCylinderAllotGetReq{}
  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.GasCylinderAllot
  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. // GetByOptType 通过id获取调拨信息
  82. // @Summary 通过id获取调拨信息
  83. // @Description 通过id获取调拨信息
  84. // @Tags 调拨信息
  85. // @Param optType path string true "操作流程id"
  86. // @Success 200 {object} response.Response{data=model.GasCylinderAllot} "{"code": 200, "data": [...]}"
  87. // @Router /api/dispatch-cost/{id} [get]
  88. // @Security Bearer
  89. func (e GasCylinderAllotController) GetByOptType(c *gin.Context) {
  90. s := service.GasCylinderAllot{}
  91. req := dto.GasCylinderAllotGetByOptTypeReq{}
  92. err := e.MakeContext(c).
  93. MakeOrm().
  94. Bind(&req, nil).
  95. MakeService(&s.Service).
  96. Errors
  97. if err != nil {
  98. e.Logger.Error(err)
  99. e.Error(500, err, err.Error())
  100. return
  101. }
  102. var object model.GasCylinderAllot
  103. p := actions.GetPermissionFromContext(c)
  104. //数据权限检查
  105. err = s.GetByOptType(&req, &object, p)
  106. if err != nil {
  107. e.Error(500, err, err.Error())
  108. return
  109. }
  110. e.OK(object, "查询成功")
  111. }
  112. // Insert 添加调拨信息
  113. // @Summary 添加调拨信息
  114. // @Description 添加调拨信息
  115. // @Tags 调拨信息
  116. // @Accept application/json
  117. // @Product application/json
  118. // @Param data body dto.GasCylinderAllotInsertReq true "data"
  119. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  120. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  121. // @Router /api/dispatch-cost [post]
  122. // @Security Bearer
  123. func (e GasCylinderAllotController) Insert(c *gin.Context) {
  124. s := service.GasCylinderAllot{}
  125. userSvc := service.SysUser{}
  126. req := dto.GasCylinderAllotInsertReq{}
  127. err := e.MakeContext(c).
  128. MakeOrm().
  129. Bind(&req, binding.JSON).
  130. MakeService(&s.Service).
  131. MakeService(&userSvc.Service).
  132. Errors
  133. if err != nil {
  134. e.Logger.Error(err)
  135. e.Error(500, err, err.Error())
  136. return
  137. }
  138. p := actions.GetPermissionFromContext(c)
  139. var userObj model.SysUser
  140. err = userSvc.Get(&dto.SysUserGetReq{Id: user.GetUserId(c)}, nil, &userObj)
  141. if err != nil {
  142. e.Error(500, err, err.Error())
  143. return
  144. }
  145. // 送气员
  146. if userObj.ProvUser.UserType == 3 && userObj.ProvUser.Isorders == 0 {
  147. if !global.CheckElementExists(req.OptType, []string{"21", "35", "md" + model.GasCylinderStatusScrap, "md" + model.GasCylinderStatusExtended}) {
  148. err = errors.New("该调拨码不支持操作!")
  149. e.Error(500, err, err.Error())
  150. return
  151. }
  152. }
  153. // 门店
  154. if userObj.ProvUser.UserType == 3 && userObj.ProvUser.Isorders == 1 {
  155. if !global.CheckElementExists(req.OptType, []string{"11", "25", "033", "sj" + model.GasCylinderStatusScrap, "sj" + model.GasCylinderStatusExtended}) {
  156. err = errors.New("该调拨码不支持操作!")
  157. e.Error(500, err, err.Error())
  158. return
  159. }
  160. }
  161. // 司机
  162. if userObj.ProvUser.UserType == 4 {
  163. if !global.CheckElementExists(req.OptType, []string{"31", "13", "016", "md" + model.GasCylinderStatusScrap, "md" + model.GasCylinderStatusExtended, "qz" + model.GasCylinderStatusScrap, "qz" + model.GasCylinderStatusExtended}) {
  164. err = errors.New("该调拨码不支持操作!")
  165. e.Error(500, err, err.Error())
  166. return
  167. }
  168. }
  169. // 气站
  170. if userObj.ProvUser.UserType == 5 {
  171. if !global.CheckElementExists(req.OptType, []string{"17", "sj" + model.GasCylinderStatusScrap, "sj" + model.GasCylinderStatusExtended}) {
  172. err = errors.New("该调拨码不支持操作!")
  173. e.Error(500, err, err.Error())
  174. return
  175. }
  176. }
  177. // 设置创建人
  178. req.SetCreateBy(user.GetUserId(c))
  179. req.SetDeptId(p.DeptId)
  180. err = s.Insert(&req)
  181. if err != nil {
  182. e.Error(500, err, err.Error())
  183. return
  184. }
  185. e.OK(req.GetId(), "调拨成功")
  186. }
  187. // Update 修改调拨信息
  188. // @Summary 修改调拨信息
  189. // @Description 修改调拨信息
  190. // @Tags 调拨信息
  191. // @Accept application/json
  192. // @Product application/json
  193. // @Param data body dto.GasCylinderAllotUpdateReq true "body"
  194. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  195. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  196. // @Router /api/dispatch-cost [put]
  197. // @Security Bearer
  198. func (e GasCylinderAllotController) Update(c *gin.Context) {
  199. s := service.GasCylinderAllot{}
  200. req := dto.GasCylinderAllotUpdateReq{}
  201. err := e.MakeContext(c).
  202. MakeOrm().
  203. Bind(&req).
  204. MakeService(&s.Service).
  205. Errors
  206. if err != nil {
  207. e.Logger.Error(err)
  208. e.Error(500, err, err.Error())
  209. return
  210. }
  211. p := actions.GetPermissionFromContext(c)
  212. req.SetUpdateBy(user.GetUserId(c))
  213. err = s.Update(&req, p)
  214. if err != nil {
  215. e.Error(500, err, err.Error())
  216. return
  217. }
  218. e.OK(req.GetId(), "更新成功")
  219. }
  220. // Delete 删除调拨信息
  221. // @Summary 删除调拨信息
  222. // @Description 删除调拨信息
  223. // @Tags 调拨信息
  224. // @Accept application/json
  225. // @Product application/json
  226. // @Param data body dto.GasCylinderAllotDeleteReq true "body"
  227. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  228. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  229. // @Router /api/dispatch-cost [delete]
  230. // @Security Bearer
  231. func (e GasCylinderAllotController) Delete(c *gin.Context) {
  232. s := service.GasCylinderAllot{}
  233. req := dto.GasCylinderAllotDeleteReq{}
  234. userSvc := service.SysUser{}
  235. err := e.MakeContext(c).
  236. MakeOrm().
  237. Bind(&req, binding.JSON, nil).
  238. MakeService(&s.Service).
  239. MakeService(&userSvc.Service).
  240. Errors
  241. if err != nil {
  242. e.Logger.Error(err)
  243. e.Error(500, err, err.Error())
  244. return
  245. }
  246. //数据权限检查
  247. p := actions.GetPermissionFromContext(c)
  248. err = s.Remove(&req, p)
  249. if err != nil {
  250. e.Error(500, err, err.Error())
  251. return
  252. }
  253. e.OK(req.GetId(), "删除成功")
  254. }
  255. // Cancel 取消调拨
  256. // @Summary 取消调拨
  257. // @Description 取消调拨
  258. // @Tags 调拨信息
  259. // @Accept application/json
  260. // @Product application/json
  261. // @Param data body dto.GasCylinderAllotUpdateReq true "body"
  262. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  263. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  264. // @Router /api/dispatch-cost [put]
  265. // @Security Bearer
  266. func (e GasCylinderAllotController) Cancel(c *gin.Context) {
  267. s := service.GasCylinderAllot{}
  268. req := dto.GasCylinderAllotCancelReq{}
  269. err := e.MakeContext(c).
  270. MakeOrm().
  271. Bind(&req).
  272. MakeService(&s.Service).
  273. Errors
  274. if err != nil {
  275. e.Logger.Error(err)
  276. e.Error(500, err, err.Error())
  277. return
  278. }
  279. p := actions.GetPermissionFromContext(c)
  280. req.SetUpdateBy(user.GetUserId(c))
  281. err = s.Cancel(&req, p)
  282. if err != nil {
  283. e.Error(500, err, err.Error())
  284. return
  285. }
  286. e.OK(req.GetId(), "取消成功")
  287. }
  288. // Submit 提交调拨信息
  289. // @Summary 提交调拨信息
  290. // @Description 提交调拨信息
  291. // @Tags 调拨信息
  292. // @Accept application/json
  293. // @Product application/json
  294. // @Param data body dto.GasCylinderAllotUpdateReq true "body"
  295. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  296. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  297. // @Router /api/dispatch-cost [put]
  298. // @Security Bearer
  299. func (e GasCylinderAllotController) Submit(c *gin.Context) {
  300. s := service.GasCylinderAllot{}
  301. req := dto.GasCylinderAllotSubmitReq{}
  302. err := e.MakeContext(c).
  303. MakeOrm().
  304. Bind(&req).
  305. MakeService(&s.Service).
  306. Errors
  307. if err != nil {
  308. e.Logger.Error(err)
  309. e.Error(500, err, err.Error())
  310. return
  311. }
  312. p := actions.GetPermissionFromContext(c)
  313. req.SetUpdateBy(user.GetUserId(c))
  314. err = s.Submit(&req, p)
  315. if err != nil {
  316. e.Error(500, err, err.Error())
  317. return
  318. }
  319. e.OK(req.GetId(), "提交成功")
  320. }