123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- 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 GasCylinderController struct {
- api.Api
- }
- // GetPage 获取钢瓶档案列表
- // @Summary 获取钢瓶档案列表
- // @Description 获取钢瓶档案列表
- // @Tags 钢瓶档案
- // @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.GasCylinder}} "{"code": 200, "data": [...]}"
- // @Router /api/dispatch-cost [get]
- // @Security Bearer
- func (e GasCylinderController) GetPage(c *gin.Context) {
- s := service.GasCylinder{}
- req := dto.GasCylinderGetPageReq{}
- 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.GasCylinder, 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.GasCylinder} "{"code": 200, "data": [...]}"
- // @Router /api/goods/{id} [get]
- // @Security Bearer
- func (e GasCylinderController) Get(c *gin.Context) {
- s := service.GasCylinder{}
- req := dto.GasCylinderGetReq{}
- 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.ProvGasCylinder
- p := actions.GetPermissionFromContext(c)
- //数据权限检查
- err = s.Get(&req, &object, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(object, "查询成功")
- }
- // GetByUid 通过高频编码获取钢瓶信息
- // @Summary 通过高频编码获取钢瓶信息
- // @Description 通过高频编码获取钢瓶信息
- // @Tags 钢瓶档案
- // @Param chipUid path string true "高频编码"
- // @Success 200 {object} response.Response{data=model.GasCylinder} "{"code": 200, "data": [...]}"
- // @Router /api/goods/{id} [get]
- // @Security Bearer
- func (e GasCylinderController) GetByUid(c *gin.Context) {
- s := service.GasCylinder{}
- operationLogSvc := service.OperationLog{}
- req := dto.GasCylinderGetByUidReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, nil).
- MakeService(&s.Service).
- MakeService(&operationLogSvc.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var gasCylinder model.ProvGasCylinder
- p := actions.GetPermissionFromContext(c)
- //数据权限检查
- err = s.GetByUid(&req, &gasCylinder, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- operationLogList := make([]model.OperationLog, 0)
- err = operationLogSvc.ListByUid(gasCylinder.InnerCode, &operationLogList)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(map[string]interface{}{
- "gasCylinder": gasCylinder,
- "operationLog": operationLogList,
- }, "查询成功")
- }
- // Mock 模拟气瓶数据
- // @Summary 模拟气瓶数据
- // @Description 模拟气瓶数据
- // @Tags 钢瓶档案
- // @Param data body dto.GasCylinderMockReq true "data"
- // @Success 200 {object} response.Response{data=model.GasCylinder} "{"code": 200, "data": [...]}"
- // @Router /api/goods/{id} [get]
- // @Security Bearer
- func (e GasCylinderController) Mock(c *gin.Context) {
- s := service.GasCylinder{}
- req := dto.GasCylinderMockReq{}
- 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.Mock(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(nil, "生成成功")
- }
|