/* * @description: rpc - 安全巡检 * @Author: LanJianRong * @Date: 2020-11-18 * @FilePath: \construction_management\web\api\safe_rpc_api.go */ package api import ( "fmt" "github.com/kataras/iris/v12" "go.mod/services" "go.mod/web/utils" "google.golang.org/grpc" ) type SafeRpcApi struct { //框架-web应用上下文环境 Ctx iris.Context // 需要用的service ServiceSafe services.SafeService } // @Summary 安全巡检列表 // @Tags 安全巡检 // @Description 获得列表数据 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param bidsectionId path string true "标段ID" // @Success 200 {object} viewmodels.Safe "{code:0成功,data:viewmodels.Safe,msg:}" // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}" // @Router /api/safe [get] func (c *SafeRpcApi) Get() { RpcConnect := c.Ctx.Values().Get("RpcConnect").(*grpc.ClientConn) // 1.规则验证 safeData, err := c.ServiceSafe.ValidRule(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": err}) return } bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"}) return } c.ServiceSafe.Get(bidsectionId, RpcConnect) code, msg, data := c.ServiceSafe.Get(bidsectionId) c.Ctx.JSON(iris.Map{ "code": code, "msg": msg, "data": data, }) } // @Summary 安全巡检列表 // @Tags 安全巡检 // @Description 创建新的安全巡检记录 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param bidsectionId body string true "标段ID" // @Param code body string true "编号" // @Param createTime body string true "日期" // @Param inspection body string true "检查部位" // @Param position body string true "部位" // @Success 200 {object} viewmodels.Safe "{code:0成功,msg:}" // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}" // @Router /api/safe/create [post] func (c *SafeRpcApi) PostCreate() { // 1.规则验证 safeData, err := c.ServiceSafe.ValidRule(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": err}) return } fmt.Println(safeData) bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"}) return } RpcConnect := c.Ctx.Values().Get("RpcConnect").(*grpc.ClientConn) code, msg := c.ServiceSafe.Post(bidsectionId, safeData.Position, safeData.Code, safeData.CreateTime, safeData.Inspection, RpcConnect) c.Ctx.JSON(iris.Map{ "code": code, "msg": msg, }) }