package controller import ( "gas-cylinder-api/app/admin/model" "gas-cylinder-api/app/admin/service" "gas-cylinder-api/app/admin/service/dto" "gas-cylinder-api/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/response" ) type OperationLogController struct { api.Api } // GetPage 获取操作记录列表 // @Summary 获取操作记录列表 // @Description 获取操作记录列表 // @Tags 操作记录 // @Param optType query int false "气瓶流转步骤" // @Param innerCode query string false "单位内编码" // @Param pageSize query int false "页条数" // @Param page query int false "页码" // @Success 200 {object} response.Response{data=response.Page{list=[]model.OperationLog}} "{"code": 200, "data": [...]}" // @Router /api/operation-log [get] // @Security Bearer func (e OperationLogController) GetPage(c *gin.Context) { s := service.OperationLog{} req := dto.OperationLogGetPageReq{} 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.OperationLog, 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.OperationLog} "{"code": 200, "data": [...]}" // @Router /api/operation-log/{id} [get] // @Security Bearer func (e OperationLogController) Get(c *gin.Context) { s := service.OperationLog{} req := dto.OperationLogGetReq{} 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.OperationLog 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.OperationLogInsertReq true "data" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/operation-log [post] // @Security Bearer func (e OperationLogController) Insert(c *gin.Context) { s := service.OperationLog{} req := dto.OperationLogInsertReq{} 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) err = s.Insert(&req, p) if err != nil { e.Error(500, err, err.Error()) return } e.OK(req.GetId(), "创建成功") } // InsertForGasStation 添加气站操作记录 // @Summary 添加气站操作记录 // @Description 添加气站操作记录 // @Tags 操作记录 // @Accept application/json // @Product application/json // @Param data body dto.OperationLogInsertForGasStationReq true "data" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/operation-log/gas-station [post] // @Security Bearer func (e OperationLogController) InsertForGasStation(c *gin.Context) { s := service.OperationLog{} req := dto.OperationLogInsertForGasStationReq{} 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 } err = s.InsertForGasStation(&req) if err != nil { e.Error(500, err, err.Error()) return } e.OK(req.GetId(), "创建成功") }