123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- /*
- * @description: rpc - 质量巡检
- * @Author: LanJianRong
- * @Date: 2020-11-18
- * @FilePath: \construction_management\web\api\quality_api.go
- */
- package api
- import (
- "fmt"
- "time"
- "github.com/kataras/iris/v12"
- "go.mod/conf"
- "go.mod/models"
- "go.mod/services"
- "go.mod/web/utils"
- )
- type QualityApi struct {
- //框架-web应用上下文环境
- Ctx iris.Context
- // 需要用的service
- ServiceQuality services.QualityService
- }
- // @Summary 质量巡检列表
- // @Tags 质量巡检
- // @Description 获得列表数据
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param bidsectionId path string true "标段ID"
- // @Param pageNo path int true "页码" eg:1
- // @Param pageSize path int true "页数" eg:15
- // @Success 200 {object} viewmodels.Quality "{code:0成功,data:viewmodels.Quality,msg:}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/quality [get]
- func (c *QualityApi) Get() {
- // 1.规则验证
- qualityData, err := c.ServiceQuality.ValidRule(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- pid, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
- return
- }
- bidsectionId, err := utils.GetDecryptId(qualityData.BidsectionId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- return
- }
- QualityData, total := c.ServiceQuality.Get(bidsectionId, pid, qualityData.PageNo, qualityData.PageSize)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "请求成功",
- "data": QualityData,
- "total": total,
- })
- }
- // @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.Quality "{code:0成功,msg:}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/quality [post]
- func (c *QualityApi) Post() {
- // 1.规则验证
- qualityData, err := c.ServiceQuality.ValidRule(c.Ctx)
- // fmt.Println("-------------------------------", err)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- bidsectionId, err := utils.GetDecryptId(qualityData.BidsectionId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- return
- }
- data := models.CmQuality{}
- data.BidsectionId = bidsectionId
- data.Code = qualityData.Code
- data.Inspection = qualityData.Inspection
- data.Times = 1
- uid, err := utils.GetProjectAccountId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "未登录或账号失效,请重新登录"})
- return
- }
- data.Uid = uid
- createTime, err := time.Parse(conf.SysTimeform, qualityData.CreateTime)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "日期转换异常,请检查参数"})
- return
- }
- // fmt.Println(createTime)
- data.CreateTime = createTime
- err = c.ServiceQuality.Post(data)
- if err != nil {
- c.Ctx.JSON(iris.Map{
- "code": -1,
- "msg": fmt.Sprintf("%s", err),
- })
- return
- }
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "插入成功",
- })
- }
- // @Summary 删除记录
- // @Tags 质量巡检
- // @Description 删除质量巡检记录
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string true "质量巡检ID"
- // @Success 200 {object} viewmodels.Quality "{code:0成功,msg:}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/quality [delete]
- func (c *QualityApi) Delete() {
- queryId := c.Ctx.URLParam("id")
- if queryId == "" {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "id不存在"})
- return
- }
- id, err := utils.GetDecryptId(queryId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- return
- }
- err = c.ServiceQuality.Del(id)
- if err != nil {
- c.Ctx.JSON(iris.Map{
- "code": -1,
- "msg": fmt.Sprintf("%s", err),
- })
- return
- }
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "删除成功",
- })
- }
- // @Summary 获取质量巡检详情
- // @Tags 质量巡检
- // @Description 获得质量巡检详情页面数据
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id path string true "巡检ID"
- // @Success 200 {object} viewmodels.QualityDetail "{code:0成功,data:viewmodels.QualityDetail,msg:}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/quality/detail [get]
- func (c *QualityApi) GetDetail() {
- // 1.规则验证
- qualityData, err := c.ServiceQuality.ValidRule(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- id, err := utils.GetDecryptId(qualityData.Id)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadForm转换异常,请检查参数"})
- return
- }
- pid, _ := utils.GetProjectId(c.Ctx)
- quality := c.ServiceQuality.GetDetail(id, pid)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "请求成功",
- "data": quality,
- })
- }
- // @Summary 质量概述
- // @Tags 质量巡检
- // @Description 质量概述
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param bidsectionId path string true "标段ID"
- // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
- // @Router /api/quality/survey [get]
- func (c *QualityApi) GetSurvey() {
- // sectionData := viewmodels.Quality{}
- // err := c.Ctx.ReadForm(§ionData)
- // if err != nil {
- // c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- // return
- // }
- // err = sectionData.ValidateBidsectionId()
- // if err != nil {
- // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- // return
- // }
- // 标段ID
- // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
- // if err != nil {
- // c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- // return
- // }
- // 项目ID
- // projectId, err := utils.GetProjectId(c.Ctx)
- // if err != nil {
- // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- // return
- // }
- // QualityData := c.ServiceQuality.GetSurvey(projectId, bidsectionId)
- // c.Ctx.JSON(iris.Map{
- // "code": 0,
- // "msg": "",
- // "data": QualityData,
- // })
- }
|