package controller import ( "errors" "gas-cylinder-api/app/admin/model" "gas-cylinder-api/app/admin/service" "gas-cylinder-api/app/admin/service/dto" "gas-cylinder-api/common/actions" "gas-cylinder-api/common/global" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "gogs.baozhida.cn/zoie/OAuth-core/api" "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user" _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response" ) type GasCylinderAllotController struct { api.Api } // GetPage 获取调拨信息列表 // @Summary 获取调拨信息列表 // @Description 获取调拨信息列表 // @Tags 调拨信息 // @Param name query string false "调拨信息名称" // @Success 200 {object} response.Response{data=response.Page{list=[]model.GasCylinderAllot}} "{"code": 200, "data": [...]}" // @Router /api/dispatch-cost [get] // @Security Bearer func (e GasCylinderAllotController) GetPage(c *gin.Context) { s := service.GasCylinderAllot{} req := dto.GasCylinderAllotGetPageReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.Query). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } //数据权限检查 p := actions.GetPermissionFromContext(c) list := make([]model.GasCylinderAllot, 0) var count int64 err = s.GetPage(&req, &list, &count, p) if err != nil { e.Error(500, err, err.Error()) return } e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") } // Get 通过id获取调拨信息 // @Summary 通过id获取调拨信息 // @Description 通过id获取调拨信息 // @Tags 调拨信息 // @Param id path string true "调拨信息id" // @Success 200 {object} response.Response{data=model.GasCylinderAllot} "{"code": 200, "data": [...]}" // @Router /api/dispatch-cost/{id} [get] // @Security Bearer func (e GasCylinderAllotController) Get(c *gin.Context) { s := service.GasCylinderAllot{} req := dto.GasCylinderAllotGetReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, nil). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } var object model.GasCylinderAllot p := actions.GetPermissionFromContext(c) //数据权限检查 err = s.Get(&req, &object, p) if err != nil { e.Error(500, err, err.Error()) return } e.OK(object, "查询成功") } // GetByOptType 通过id获取调拨信息 // @Summary 通过id获取调拨信息 // @Description 通过id获取调拨信息 // @Tags 调拨信息 // @Param optType path string true "操作流程id" // @Success 200 {object} response.Response{data=model.GasCylinderAllot} "{"code": 200, "data": [...]}" // @Router /api/dispatch-cost/{id} [get] // @Security Bearer func (e GasCylinderAllotController) GetByOptType(c *gin.Context) { s := service.GasCylinderAllot{} req := dto.GasCylinderAllotGetByOptTypeReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, nil). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } var object model.GasCylinderAllot p := actions.GetPermissionFromContext(c) //数据权限检查 err = s.GetByOptType(&req, &object, p) if err != nil { e.Error(500, err, err.Error()) return } e.OK(object, "查询成功") } // Insert 添加调拨信息 // @Summary 添加调拨信息 // @Description 添加调拨信息 // @Tags 调拨信息 // @Accept application/json // @Product application/json // @Param data body dto.GasCylinderAllotInsertReq true "data" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/dispatch-cost [post] // @Security Bearer func (e GasCylinderAllotController) Insert(c *gin.Context) { s := service.GasCylinderAllot{} userSvc := service.SysUser{} req := dto.GasCylinderAllotInsertReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON). MakeService(&s.Service). MakeService(&userSvc.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } p := actions.GetPermissionFromContext(c) var userObj model.SysUser err = userSvc.Get(&dto.SysUserGetReq{Id: user.GetUserId(c)}, nil, &userObj) if err != nil { e.Error(500, err, err.Error()) return } // 送气员 if userObj.ProvUser.UserType == 3 && userObj.ProvUser.Isorders == 0 { if !global.CheckElementExists(req.OptType, []string{"21", "35", "md" + model.GasCylinderStatusScrap, "md" + model.GasCylinderStatusExtended}) { err = errors.New("该调拨码不支持操作!") e.Error(500, err, err.Error()) return } } // 门店 if userObj.ProvUser.UserType == 3 && userObj.ProvUser.Isorders == 1 { if !global.CheckElementExists(req.OptType, []string{"11", "25", "033", "sj" + model.GasCylinderStatusScrap, "sj" + model.GasCylinderStatusExtended}) { err = errors.New("该调拨码不支持操作!") e.Error(500, err, err.Error()) return } } // 司机 if userObj.ProvUser.UserType == 4 { if !global.CheckElementExists(req.OptType, []string{"31", "13", "016", "md" + model.GasCylinderStatusScrap, "md" + model.GasCylinderStatusExtended, "qz" + model.GasCylinderStatusScrap, "qz" + model.GasCylinderStatusExtended}) { err = errors.New("该调拨码不支持操作!") e.Error(500, err, err.Error()) return } } // 气站 if userObj.ProvUser.UserType == 5 { if !global.CheckElementExists(req.OptType, []string{"17", "sj" + model.GasCylinderStatusScrap, "sj" + model.GasCylinderStatusExtended}) { err = errors.New("该调拨码不支持操作!") e.Error(500, err, err.Error()) return } } // 设置创建人 req.SetCreateBy(user.GetUserId(c)) req.SetDeptId(p.DeptId) err = s.Insert(&req) if err != nil { e.Error(500, err, err.Error()) return } e.OK(req.GetId(), "调拨成功") } // Update 修改调拨信息 // @Summary 修改调拨信息 // @Description 修改调拨信息 // @Tags 调拨信息 // @Accept application/json // @Product application/json // @Param data body dto.GasCylinderAllotUpdateReq true "body" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/dispatch-cost [put] // @Security Bearer func (e GasCylinderAllotController) Update(c *gin.Context) { s := service.GasCylinderAllot{} req := dto.GasCylinderAllotUpdateReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } p := actions.GetPermissionFromContext(c) req.SetUpdateBy(user.GetUserId(c)) err = s.Update(&req, p) if err != nil { e.Error(500, err, err.Error()) return } e.OK(req.GetId(), "更新成功") } // Delete 删除调拨信息 // @Summary 删除调拨信息 // @Description 删除调拨信息 // @Tags 调拨信息 // @Accept application/json // @Product application/json // @Param data body dto.GasCylinderAllotDeleteReq true "body" // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /api/dispatch-cost [delete] // @Security Bearer func (e GasCylinderAllotController) Delete(c *gin.Context) { s := service.GasCylinderAllot{} req := dto.GasCylinderAllotDeleteReq{} userSvc := service.SysUser{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON, nil). MakeService(&s.Service). MakeService(&userSvc.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } //数据权限检查 p := actions.GetPermissionFromContext(c) err = s.Remove(&req, p) if err != nil { e.Error(500, err, err.Error()) return } e.OK(req.GetId(), "删除成功") } // Cancel 取消调拨 // @Summary 取消调拨 // @Description 取消调拨 // @Tags 调拨信息 // @Accept application/json // @Product application/json // @Param data body dto.GasCylinderAllotUpdateReq true "body" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/dispatch-cost [put] // @Security Bearer func (e GasCylinderAllotController) Cancel(c *gin.Context) { s := service.GasCylinderAllot{} req := dto.GasCylinderAllotCancelReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } p := actions.GetPermissionFromContext(c) req.SetUpdateBy(user.GetUserId(c)) err = s.Cancel(&req, p) if err != nil { e.Error(500, err, err.Error()) return } e.OK(req.GetId(), "取消成功") } // Submit 提交调拨信息 // @Summary 提交调拨信息 // @Description 提交调拨信息 // @Tags 调拨信息 // @Accept application/json // @Product application/json // @Param data body dto.GasCylinderAllotUpdateReq true "body" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/dispatch-cost [put] // @Security Bearer func (e GasCylinderAllotController) Submit(c *gin.Context) { s := service.GasCylinderAllot{} req := dto.GasCylinderAllotSubmitReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } p := actions.GetPermissionFromContext(c) req.SetUpdateBy(user.GetUserId(c)) err = s.Submit(&req, p) if err != nil { e.Error(500, err, err.Error()) return } e.OK(req.GetId(), "提交成功") }