123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 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/jwtauth/user"
- _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
- )
- type InspectRecordController struct {
- api.Api
- }
- // GetPage 获取入户安全检查列表
- // @Summary 获取入户安全检查列表
- // @Description 获取入户安全检查列表
- // @Tags 入户安全检查
- // @Param state query int false "订单状态 状态 0-待整改 1-整改中 2-已整改 -1 合格"
- // @Param inspectStartTime query string false "检查开始时间"
- // @Param inspectEndTime query string false "检查结束时间"
- // @Param customerName query string false "客户名称"
- // @Param inspectorName query string false "检查人"
- // @Param pageSize query int false "页条数"
- // @Param page query int false "页码"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.InspectRecord}} "{"code": 200, "data": [...]}"
- // @Router /api/goods [get]
- // @Security Bearer
- func (e InspectRecordController) GetPage(c *gin.Context) {
- s := service.InspectRecord{}
- req := dto.InspectRecordGetPageReq{}
- 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.InspectRecord, 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.InspectRecord} "{"code": 200, "data": [...]}"
- // @Router /api/goods/{id} [get]
- // @Security Bearer
- func (e InspectRecordController) Get(c *gin.Context) {
- s := service.InspectRecord{}
- req := dto.InspectRecordGetReq{}
- 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.InspectRecord
- 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.InspectRecordInsertReq true "data"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/goods [post]
- // @Security Bearer
- func (e InspectRecordController) Insert(c *gin.Context) {
- s := service.InspectRecord{}
- userSvc := service.SysUser{}
- req := dto.InspectRecordInsertReq{}
- 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
- }
- // 设置创建人
- req.SetCreateBy(user.GetUserId(c))
- req.SetDeptId(user.GetDeptId(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
- }
- req.InspectorId = userObj.ProvUserId
- req.CreatorId = userObj.ProvUserId
- req.UserId = userObj.Id
- 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.InspectRecordInsertReq true "data"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/goods [post]
- // @Security Bearer
- func (e InspectRecordController) Update(c *gin.Context) {
- s := service.InspectRecord{}
- userSvc := service.SysUser{}
- req := dto.InspectRecordInsertReq{}
- 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
- }
- // 设置创建人
- req.SetCreateBy(user.GetUserId(c))
- req.SetDeptId(user.GetDeptId(c))
- err = s.Update(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "修改成功")
- }
|