/* * @Author: lilig * @Date: 2023-10-10 15:22:58 * @LastEditors: lilifor * @LastEditTime: 2023-10-10 15:22:58 * @FilePath: \SCD\controllers\ReportController.go * @Description: * * Copyright (c) 2023 by lilig/jujutong, All Rights Reserved. */ package controllers import ( "scd_check_tools/models/bo" ) //检测报告服务 type ReportController struct { BaseController } func init() { } // @Summary 查询检测任务的报告列表 // @Description 查询检测任务的报告列表 // @Tags 检测报告服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param pageno query int true "当前页码。默认为1" // @Param pagesize query int true "每页显示数据数。默认为20" // @Param task_id formData int false "任务ID" // @Param name formData string false "任务名称。" // @Param code formData string false "任务编号。支持模糊匹配。" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /report/list [get] func (c *ReportController) GetReportList() { id, _ := c.GetInt("task_id") pi, _ := c.GetInt("pagesize", 20) po, _ := c.GetInt("pageno", 0) if po == 0 { po, _ = c.GetInt("pageindex", 0) } if po == 0 { po = 1 } obj := new(bo.TaskReportMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_task_report{TaskId: id, Name: c.GetString("name"), Code: c.GetString("code")} lst, cnt, err := obj.List(po, pi) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(lst, cnt) c.ServeJSON() } // @Summary 删除指定的检测报告 // @Description 删除指定的检测报告 // @Tags 检测报告服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int true "检测报告ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /report/delete [post] func (c *ReportController) DeleteReport() { id, _ := c.GetInt("id") if id == 0 { c.Data["json"] = c.ResultError("报告编号不能为空!") c.ServeJSON() return } obj := new(bo.TaskReportMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_task_report{} obj.Model.Id = id err := obj.Delete() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 生成指定检测任务的报告 // @Description 生成指定检测任务的报告 // @Tags 检测报告服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param task_id formData int true "任务ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /report/make [post] func (c *ReportController) MakeReport() { id, _ := c.GetInt("task_id") if id == 0 { c.Data["json"] = c.ResultError("检测任务ID不能为空") c.ServeJSON() return } obj := new(bo.TaskReportMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_task_report{TaskId: id, State: 1} reportid, err := obj.Make() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } obj.Model.Id = reportid info, _ := obj.One(id) c.Data["json"] = c.ResultOK(info, 1) c.ServeJSON() } // @Summary 创建新的检测报告模板 // @Description 创建新的检测报告模板 // @Tags 检测报告服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int false "报告模板ID。指定id值大于0时为编辑操作;否则为新增操作" // @Param name formData string true "报告模板名称" // @Param doc_id formData int true "报告模板附件ID" // @Param memo formData string false "报告模板说明" // @Param state formData int true "启用状态。1 启用 2 禁用。默认为1" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /report/tpl/save [post] func (c *ReportController) SavereportTplInfo() { id, _ := c.GetInt("id") obj := new(bo.ReportTplMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_report_tpl{Id: id} obj.Model.Name = c.GetString("name") obj.Model.Memo = c.GetString("memo") obj.Model.DocId, _ = c.GetInt("doc_id") obj.Model.State, _ = c.GetInt("state") if obj.Model.Id == 0 && obj.Model.State == 0 { obj.Model.State = 1 } if obj.Model.Name == "" { c.Data["json"] = c.ResultError("检测报告模板名称不能为空") c.ServeJSON() return } if obj.Model.DocId == 0 { c.Data["json"] = c.ResultError("检测报告附件不能为空") c.ServeJSON() return } err := obj.Save() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 删除指定的检测报告模板 // @Description 删除指定的检测报告模板 // @Tags 检测报告服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int true "检测报告模板ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /report/tpl/delete [post] func (c *ReportController) DeleteTpl() { id, _ := c.GetInt("id") if id == 0 { c.Data["json"] = c.ResultError("报告模板编号不能为空!") c.ServeJSON() return } obj := new(bo.ReportTplMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_report_tpl{} obj.Model.Id = id err := obj.Delete() if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } // @Summary 查询检测报告模板 // @Description 查询检测报告模板。支持报告模板名称、状态等过滤条件 // @Tags 检测报告服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param pageno query int true "当前页码。默认为1" // @Param pagesize query int true "每页显示数据数。默认为20" // @Param id query int false "报告模板ID" // @Param name query string false "名称" // @Param state query int false "状态。空:全部 1:启用 2:禁用" // @Success 200 {object} ResultOK 成功 // @Failure 500 {object} ResultError 失败 // @router /report/tpl/list [get] func (c *ReportController) GetreportTplList() { obj := new(bo.ReportTplMgr) obj.SetUserInfo(c.GetCurrentUserInfo()) obj.Model = bo.T_data_report_tpl{} obj.Model.Id, _ = c.GetInt("id") obj.Model.Name = c.GetString("name") obj.Model.State, _ = c.GetInt("state", 0) pi, _ := c.GetInt("pagesize", 20) po, _ := c.GetInt("pageno", 0) if po == 0 { po, _ = c.GetInt("pageindex", 0) } if po == 0 { po = 1 } lst, cnt, err := obj.List(po, pi) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(lst, cnt) c.ServeJSON() }