123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- package controller
- import (
- "cold-logistics/app/admin/model"
- "cold-logistics/app/admin/service"
- "cold-logistics/app/admin/service/dto"
- "cold-logistics/common/actions"
- "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 WarehouseController struct {
- api.Api
- }
- // GetPage 获取仓库列表
- // @Summary 获取仓库列表
- // @Description 获取仓库列表
- // @Tags 仓库
- // @Param name query string false "仓库名称"
- // @Param sn query string false "仓库关联sn"
- // @Param status query string false "状态:1-停用 2-启用"
- // @Param isBind query bool false "是否绑定仓管"
- // @Param pageSize query int false "页条数"
- // @Param page query int false "页码"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.Warehouse}} "{"code": 200, "data": [...]}"
- // @Router /api/warehouse [get]
- // @Security Bearer
- func (e WarehouseController) GetPage(c *gin.Context) {
- s := service.Warehouse{}
- req := dto.WarehouseGetPageReq{}
- 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.Warehouse, 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.Warehouse} "{"code": 200, "data": [...]}"
- // @Router /api/warehouse/{id} [get]
- // @Security Bearer
- func (e WarehouseController) Get(c *gin.Context) {
- s := service.Warehouse{}
- req := dto.WarehouseGetReq{}
- 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.Warehouse
- p := actions.GetPermissionFromContext(c)
- //数据权限检查
- err = s.Get(&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.WarehouseInsertReq true "data"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/warehouse [post]
- // @Security Bearer
- func (e WarehouseController) Insert(c *gin.Context) {
- s := service.Warehouse{}
- req := dto.WarehouseInsertReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- p := actions.GetPermissionFromContext(c)
- // 设置创建人
- req.SetCreateBy(user.GetUserId(c))
- req.SetDeptId(p.DeptId)
- err = s.Insert(&req, p)
- 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.WarehouseUpdateReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
- // @Router /api/warehouse [put]
- // @Security Bearer
- func (e WarehouseController) Update(c *gin.Context) {
- s := service.Warehouse{}
- req := dto.WarehouseUpdateReq{}
- 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.WarehouseDeleteReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
- // @Router /api/warehouse [delete]
- // @Security Bearer
- func (e WarehouseController) Delete(c *gin.Context) {
- s := service.Warehouse{}
- req := dto.WarehouseDeleteReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON, nil).
- MakeService(&s.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(), "删除成功")
- }
- // BatchInsert 批量添加仓库
- // @Summary 批量添加仓库
- // @Description 批量添加仓库
- // @Tags 仓库
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.WarehouseBatchInsertReq true "data"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/warehouse/import [post]
- // @Security Bearer
- func (e WarehouseController) BatchInsert(c *gin.Context) {
- s := service.Warehouse{}
- req := dto.WarehouseBatchInsertReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- p := actions.GetPermissionFromContext(c)
- // 设置创建人
- req.SetCreateBy(user.GetUserId(c))
- req.SetDeptId(p.DeptId)
- err = s.BatchInsert(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(nil, "添加成功")
- }
|