liling 1 year ago
parent
commit
ba6e9345fd

+ 30 - 0
service/controllers/taskController.go

@@ -201,6 +201,36 @@ func (c *TaskController) SetTaskActiveStop() {
 	c.ServeJSON()
 	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 /task/reset [post]
+func (c *TaskController) ReSetTaskActive() {
+	id, _ := c.GetInt("id")
+	if id == 0 {
+		c.Data["json"] = c.ResultError("任务编号不能为空!")
+		c.ServeJSON()
+		return
+	}
+	obj := new(bo.TaskMgr)
+	obj.SetUserInfo(c.GetCurrentUserInfo())
+	obj.Model = bo.T_data_task{}
+	obj.Model.Id = id
+	err := obj.SetActive(0)
+	if err != nil {
+		c.Data["json"] = c.ResultError(err.Error())
+		c.ServeJSON()
+		return
+	}
+	c.Data["json"] = c.ResultOK("", 0)
+	c.ServeJSON()
+}
+
 // @Summary 查询检测任务
 // @Summary 查询检测任务
 //	@Description  查询检测任务。支持任务名称、检测状态等过滤条件
 //	@Description  查询检测任务。支持任务名称、检测状态等过滤条件
 // 	@Tags         检测任务服务接口
 // 	@Tags         检测任务服务接口

+ 3 - 1
service/models/bo/task.go

@@ -88,6 +88,9 @@ func (c *TaskMgr) SetActive(flag int) (err error) {
 	} else {
 	} else {
 		dblog.Description = fmt.Sprintf("更新%s%s状态,操作数据:%+v", modelDesc, c.Model.Name, c.Model)
 		dblog.Description = fmt.Sprintf("更新%s%s状态,操作数据:%+v", modelDesc, c.Model.Name, c.Model)
 		dblog.Success2()
 		dblog.Success2()
+		if flag == 0 {
+			return nil
+		}
 		if flag == 1 {
 		if flag == 1 {
 			return c.start(c.Model)
 			return c.start(c.Model)
 		}
 		}
@@ -173,7 +176,6 @@ func (c *TaskMgr) stop(task T_data_task) error {
 
 
 //完成检测
 //完成检测
 func (c *TaskMgr) finish(task T_data_task) error {
 func (c *TaskMgr) finish(task T_data_task) error {
-	TaskSCD.Delete(task.ScdId)
 	db := orm.NewOrm()
 	db := orm.NewOrm()
 	_, err := db.Raw("update t_data_task_check_step set state=2,ut=now() where task_id=? and state=0", task.Id).Exec()
 	_, err := db.Raw("update t_data_task_check_step set state=2,ut=now() where task_id=? and state=0", task.Id).Exec()
 	return err
 	return err

+ 164 - 17
service/models/bo/task_report.go

@@ -1,6 +1,7 @@
 package bo
 package bo
 
 
 import (
 import (
+	"encoding/json"
 	"fmt"
 	"fmt"
 	"io/fs"
 	"io/fs"
 	"os"
 	"os"
@@ -11,6 +12,7 @@ import (
 	"strings"
 	"strings"
 
 
 	"github.com/astaxie/beego/orm"
 	"github.com/astaxie/beego/orm"
+	"github.com/tealeg/xlsx"
 )
 )
 
 
 //检测任务报告模型
 //检测任务报告模型
@@ -22,9 +24,9 @@ type T_data_task_report struct {
 	State  int    // '生成状态;1 生成中 2生成结束' ,
 	State  int    // '生成状态;1 生成中 2生成结束' ,
 	Doc    string //'下载路径' ,
 	Doc    string //'下载路径' ,
 	Cr     int    // '创建人' ,
 	Cr     int    // '创建人' ,
-	Ct     string // '创建时间' ,
+	Ct     string `orm:"-"` // '创建时间' ,
 	Ur     int    // '更新人' ,
 	Ur     int    // '更新人' ,
-	Ut     string // '更新时间'
+	Ut     string `orm:"-"` // '更新时间'
 }
 }
 
 
 //检测任务管理对象
 //检测任务管理对象
@@ -71,7 +73,7 @@ func (c *TaskReportMgr) Make() (reprid int, err error) {
 		dblog.Fail2()
 		dblog.Fail2()
 	} else {
 	} else {
 		//根据模板生成报告
 		//根据模板生成报告
-		wordpath, err := c.ToWord(taskinfo.ReportId)
+		wordpath, err := c.ToWord(taskinfo)
 		if err != nil {
 		if err != nil {
 			c.Delete()
 			c.Delete()
 			return 0, err
 			return 0, err
@@ -89,20 +91,20 @@ func (c *TaskReportMgr) List(pageno, pagesize int) ([]orm.Params, int, error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	rowset := []orm.Params{}
 	rowset := []orm.Params{}
 	sqlParams := []interface{}{}
 	sqlParams := []interface{}{}
-	sql := "select * from t_data_task_report where 1=1 "
+	sql := "select t.name,t.code,t.scd_id,a.scd_name,t1.id report_id, t1.doc,t1.state report_state from t_data_task t left join t_data_task_report t1 on t.id=t1.task_id left join t_scd_scl a on t.scd_id=a.id where t.state=2 "
 	if c.Model.TaskId > 0 {
 	if c.Model.TaskId > 0 {
-		sql = sql + " and task_id=?"
+		sql = sql + " and t.id=?"
 		sqlParams = append(sqlParams, c.Model.TaskId)
 		sqlParams = append(sqlParams, c.Model.TaskId)
 	}
 	}
 	if c.Model.Name != "" {
 	if c.Model.Name != "" {
-		sql = sql + " and name like ?"
+		sql = sql + " and t.name like ?"
 		sqlParams = append(sqlParams, "%"+c.Model.Name+"%")
 		sqlParams = append(sqlParams, "%"+c.Model.Name+"%")
 	}
 	}
 	if c.Model.Code != "" {
 	if c.Model.Code != "" {
-		sql = sql + " and code like ?"
+		sql = sql + " and t.code like ?"
 		sqlParams = append(sqlParams, "%"+c.Model.Code+"%")
 		sqlParams = append(sqlParams, "%"+c.Model.Code+"%")
 	}
 	}
-	limit := fmt.Sprintf(" order by ct desc limit %d,%d", (pageno-1)*pagesize, pagesize)
+	limit := fmt.Sprintf(" order by t.ct desc limit %d,%d", (pageno-1)*pagesize, pagesize)
 	_, err := o.Raw(sql+limit, sqlParams).Values(&rowset)
 	_, err := o.Raw(sql+limit, sqlParams).Values(&rowset)
 
 
 	total := []orm.Params{}
 	total := []orm.Params{}
@@ -157,26 +159,171 @@ func (c *TaskReportMgr) Delete() (err error) {
 		dblog.Description = fmt.Sprintf("删除%s%d失败:%s", modelDesc3, c.Model.TaskId, err.Error())
 		dblog.Description = fmt.Sprintf("删除%s%d失败:%s", modelDesc3, c.Model.TaskId, err.Error())
 		dblog.Fail2()
 		dblog.Fail2()
 	} else {
 	} else {
+		if c.Model.Doc != "" {
+			//os.RemoveAll("./" + c.Model.Doc)
+		}
 		dblog.Description = fmt.Sprintf("删除%s%d成功", modelDesc3, c.Model.TaskId)
 		dblog.Description = fmt.Sprintf("删除%s%d成功", modelDesc3, c.Model.TaskId)
 		dblog.Success2()
 		dblog.Success2()
 	}
 	}
 	return err
 	return err
 }
 }
 
 
-func (c *TaskReportMgr) ToWord(tplid int) (path string, err error) {
-	fileMgr := new(AttachmentMgr)
-	fileMgr.Model = T_sys_attachment{Id: int32(tplid)}
-	fileinfo, err := fileMgr.One()
+func (c *TaskReportMgr) ToWord(taskinfo T_data_task) (path string, err error) {
+	/*
+		fileMgr := new(AttachmentMgr)
+		fileMgr.Model = T_sys_attachment{Id: int32(taskinfo.ReportId)}
+		fileinfo, err := fileMgr.One()
+		if err != nil {
+			return "", err
+		}
+	*/
+	scdmgr := new(ScdMgr)
+	scdParse := new(ScdParse)
+	scdinfo, _ := scdmgr.One(tools.IsEmpty(taskinfo.ScdId))
+	scdName := tools.IsEmpty(scdinfo["scd_name"])
+	sdcXmlObj, _ := scdParse.GetScdXmlObjectBySCDID(tools.IsEmpty(taskinfo.ScdId))
+	reportPath := strings.Join([]string{".", "static", "download", "report"}, string(os.PathSeparator))
+	os.MkdirAll(reportPath, fs.ModePerm)
+	reportFN := reportPath + string(os.PathSeparator) + fmt.Sprintf("%s.%s", c.Model.Code, "xlsx")
+	/*
+		err = os.Rename(fileinfo.SavePath, reportFN)
+		if err != nil {
+			return "", err
+		}
+	*/
+	scdRuleResult := new(ScdNodeRule)
+	scdRuleResult.ScdID = taskinfo.ScdId
+	result, _, err := scdRuleResult.ResultList("", "", "", "", "", "", 1, 1000000)
+	if err == nil {
+		return "", err
+	}
+	//生成报告数据
+	var file *xlsx.File
+	file = xlsx.NewFile()
+	sheet_c, err := file.AddSheet("测控装置")
 	if err != nil {
 	if err != nil {
+		logger.Logger.Error(err)
 		return "", err
 		return "", err
 	}
 	}
-	reportPath := strings.Join([]string{".", "static", "download", "report"}, string(os.PathSeparator))
-	os.MkdirAll(reportPath, fs.ModePerm)
-	reportFN := reportPath + string(os.PathSeparator) + fmt.Sprintf("%s.%s", c.Model.Code, strings.Split(fileinfo.SavePath, ".")[0])
-	err = os.Rename(fileinfo.SavePath, reportFN)
+	sheet_p, err := file.AddSheet("保护装置")
 	if err != nil {
 	if err != nil {
+		logger.Logger.Error(err)
+		return "", err
+	}
+	sheet_i, err := file.AddSheet("智能终端")
+	if err != nil {
+		logger.Logger.Error(err)
+		return "", err
+	}
+	sheet_m, err := file.AddSheet("合并单元")
+	if err != nil {
+		logger.Logger.Error(err)
+		return "", err
+	}
+	sheet_other, err := file.AddSheet("schema语法和数据模板")
+	if err != nil {
+		logger.Logger.Error(err)
+		return "", err
+	}
+	c.setCaption(sheet_other, fmt.Sprintf("%-%", scdName, "语法校验结果"))
+	//生成标题行
+	c.addCellValue(sheet_other, []string{"序号", "行号", "等级", "校验结果内容", "应用标准", "标准条款"})
+	//生成报表数据
+	iedResultMap := map[string][]orm.Params{}
+	rowInd := 1
+	for _, row := range result {
+		ied_name := tools.IsEmpty(row["ied_name"])
+		if ied_name == "" {
+			//生成数据行
+			c.addCellValue(sheet_other, []string{
+				fmt.Sprintf("%d", rowInd),
+				tools.IsEmpty(row["line_no"]),
+				tools.IsEmpty(row["alart_level"]),
+				tools.IsEmpty(row["parse_result"]),
+				tools.IsEmpty(row["apply_standard"]),
+				tools.IsEmpty(row["apply_standard_no"]),
+			})
+			rowInd = rowInd + 1
+		} else {
+			iedResultMap[ied_name] = append(iedResultMap[ied_name], row)
+		}
+	}
+	crcFilePath := fmt.Sprintf(strings.Join([]string{".", "static", "upload", ""}, string(os.PathSeparator))+"%d.scd.crc", taskinfo.ScdId)
+	crctext, _ := os.ReadFile(crcFilePath)
+	crcMap := map[string]string{}
+	json.Unmarshal(crctext, &crcMap)
+	scdNodeMgr := new(ScdNode)
+	for ied_name, lst := range iedResultMap {
+		iedObj := scdNodeMgr.GetIed(sdcXmlObj, tools.IsEmpty(taskinfo.ScdId), ied_name)
+		sheetObj := new(xlsx.Sheet)
+		//生成装置标题行
+		switch strings.ToUpper(ied_name[0:1]) {
+		case "C":
+			sheetObj = sheet_c
+			c.setCaption(sheetObj, fmt.Sprintf("%s-装置(%s)校验结果", scdName, ied_name))
+			c.addCellValue(sheetObj, []string{"装置编号", "装置名称", "厂家", "型号", "类型", "校验码"})
+			c.addCellValue(sheetObj, []string{ied_name, iedObj.Desc, iedObj.Manufacturer, iedObj.Type, "测控", crcMap[ied_name]})
+			break
+		case "P":
+			sheetObj = sheet_p
+			c.setCaption(sheetObj, fmt.Sprintf("%s-装置(%s)校验结果", scdName, ied_name))
+			c.addCellValue(sheetObj, []string{"装置编号", "装置名称", "厂家", "型号", "类型", "校验码"})
+			c.addCellValue(sheetObj, []string{ied_name, iedObj.Desc, iedObj.Manufacturer, iedObj.Type, "保护装置", crcMap[ied_name]})
+			break
+		case "I":
+			sheetObj = sheet_i
+			c.setCaption(sheetObj, fmt.Sprintf("%s-装置(%s)校验结果", scdName, ied_name))
+			c.addCellValue(sheetObj, []string{"装置编号", "装置名称", "厂家", "型号", "类型", "校验码"})
+			c.addCellValue(sheetObj, []string{ied_name, iedObj.Desc, iedObj.Manufacturer, iedObj.Type, "智能终端", crcMap[ied_name]})
+			break
+		case "M":
+			sheetObj = sheet_m
+			c.setCaption(sheetObj, fmt.Sprintf("%s-装置(%s)校验结果", scdName, ied_name))
+			c.addCellValue(sheetObj, []string{"装置编号", "装置名称", "厂家", "型号", "类型", "校验码"})
+			c.addCellValue(sheetObj, []string{ied_name, iedObj.Desc, iedObj.Manufacturer, iedObj.Type, "合并单元", crcMap[ied_name]})
+			break
+		default:
+			continue
+		}
+		//装置信息行
+		c.addCellValue(sheetObj, []string{"序号", "行号", "等级", "校验结果内容", "应用标准", "标准条款"})
+		//数据行
+		rowInd := 1
+		for _, r := range lst {
+			c.addCellValue(sheetObj, []string{
+				tools.IsEmpty(rowInd),
+				tools.IsEmpty(r["line_no"]),
+				tools.IsEmpty(r["alart_level"]),
+				tools.IsEmpty(r["parse_result"]),
+				tools.IsEmpty(r["apply_standard"]),
+				tools.IsEmpty(r["apply_standard_no"]),
+			})
+			rowInd = rowInd + 1
+		}
+	}
+	err = file.Save(reportFN)
+	if err != nil {
+		logger.Logger.Error(err)
 		return "", err
 		return "", err
 	}
 	}
-	//生成报告数据
 	return reportFN[1:], err
 	return reportFN[1:], err
 }
 }
+
+func (c *TaskReportMgr) setCaption(sheet *xlsx.Sheet, caption string) *xlsx.Cell {
+	row := sheet.AddRow()
+	cell := row.AddCell()
+	cell.HMerge = 5 //合并单元格数
+	cell.Value = caption
+	style := xlsx.NewStyle()
+	style.Alignment.Horizontal = "center"
+	cell.SetStyle(style)
+	return cell
+}
+
+func (c *TaskReportMgr) addCellValue(sheet *xlsx.Sheet, vs []string) {
+	row := sheet.AddRow()
+	for _, r := range vs {
+		cell := row.AddCell()
+		cell.Value = r
+	}
+}

+ 9 - 0
service/routers/commentsRouter_controllers.go

@@ -1386,6 +1386,15 @@ func init() {
 
 
     beego.GlobalControllerRouter["scd_check_tools/controllers:TaskController"] = append(beego.GlobalControllerRouter["scd_check_tools/controllers:TaskController"],
     beego.GlobalControllerRouter["scd_check_tools/controllers:TaskController"] = append(beego.GlobalControllerRouter["scd_check_tools/controllers:TaskController"],
         beego.ControllerComments{
         beego.ControllerComments{
+            Method: "ReSetTaskActive",
+            Router: "/task/reset",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["scd_check_tools/controllers:TaskController"] = append(beego.GlobalControllerRouter["scd_check_tools/controllers:TaskController"],
+        beego.ControllerComments{
             Method: "SaveTaskInfo",
             Method: "SaveTaskInfo",
             Router: "/task/save",
             Router: "/task/save",
             AllowHTTPMethods: []string{"post"},
             AllowHTTPMethods: []string{"post"},

+ 30 - 0
service/static/swagger/swagger.json

@@ -5995,6 +5995,36 @@
                 }
                 }
             }
             }
         },
         },
+        "/task/reset": {
+            "post": {
+                "tags": [
+                    "scd_check_tools/controllersTaskController"
+                ],
+                "summary": "任务重新检测",
+                "description": "任务重新检测",
+                "parameters": [
+                    {
+                        "in": "formData",
+                        "name": "id",
+                        "description": "检测任务ID",
+                        "required": true,
+                        "type": "integer",
+                        "format": "int64"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/ResultOK"
+                        }
+                    },
+                    "500": {
+                        "description": "{object} ResultError  失败"
+                    }
+                }
+            }
+        },
         "/task/save": {
         "/task/save": {
             "post": {
             "post": {
                 "tags": [
                 "tags": [

+ 20 - 0
service/static/swagger/swagger.yml

@@ -4068,6 +4068,26 @@ paths:
             $ref: '#/definitions/ResultOK'
             $ref: '#/definitions/ResultOK'
         "500":
         "500":
           description: '{object} ResultError  失败'
           description: '{object} ResultError  失败'
+  /task/reset:
+    post:
+      tags:
+      - scd_check_tools/controllersTaskController
+      summary: 任务重新检测
+      description: 任务重新检测
+      parameters:
+      - in: formData
+        name: id
+        description: 检测任务ID
+        required: true
+        type: integer
+        format: int64
+      responses:
+        "200":
+          description: 成功
+          schema:
+            $ref: '#/definitions/ResultOK'
+        "500":
+          description: '{object} ResultError  失败'
   /task/save:
   /task/save:
     post:
     post:
       tags:
       tags:

+ 30 - 0
service/swagger/swagger.json

@@ -5995,6 +5995,36 @@
                 }
                 }
             }
             }
         },
         },
+        "/task/reset": {
+            "post": {
+                "tags": [
+                    "scd_check_tools/controllersTaskController"
+                ],
+                "summary": "任务重新检测",
+                "description": "任务重新检测",
+                "parameters": [
+                    {
+                        "in": "formData",
+                        "name": "id",
+                        "description": "检测任务ID",
+                        "required": true,
+                        "type": "integer",
+                        "format": "int64"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/ResultOK"
+                        }
+                    },
+                    "500": {
+                        "description": "{object} ResultError  失败"
+                    }
+                }
+            }
+        },
         "/task/save": {
         "/task/save": {
             "post": {
             "post": {
                 "tags": [
                 "tags": [

+ 20 - 0
service/swagger/swagger.yml

@@ -4068,6 +4068,26 @@ paths:
             $ref: '#/definitions/ResultOK'
             $ref: '#/definitions/ResultOK'
         "500":
         "500":
           description: '{object} ResultError  失败'
           description: '{object} ResultError  失败'
+  /task/reset:
+    post:
+      tags:
+      - scd_check_tools/controllersTaskController
+      summary: 任务重新检测
+      description: 任务重新检测
+      parameters:
+      - in: formData
+        name: id
+        description: 检测任务ID
+        required: true
+        type: integer
+        format: int64
+      responses:
+        "200":
+          description: 成功
+          schema:
+            $ref: '#/definitions/ResultOK'
+        "500":
+          description: '{object} ResultError  失败'
   /task/save:
   /task/save:
     post:
     post:
       tags:
       tags:

+ 11 - 0
service/test/test.go

@@ -212,3 +212,14 @@ func (t *UnitTest) Test18() {
 	testobj.Model.Id = 32
 	testobj.Model.Id = 32
 	testobj.Delete()
 	testobj.Delete()
 }
 }
+
+func (t *UnitTest) Test19() {
+	logger.Logger.Println(fmt.Sprintf("=============正在测试生成报告"))
+	appport := conf.GlobalConfig["appport"]
+	url := "http://127.0.0.1:" + appport + "/api/report/make"
+	logger.Logger.Println(fmt.Sprintf("============正在测试报告生成,请求URL:%s", url))
+	postdata := []string{"task_id=131"}
+	postdataStr := strings.Join(postdata, "&")
+	testResult, _ := tools.Post(url, postdataStr, UnitTestToken)
+	logger.Logger.Println(fmt.Sprintf("============测试结果报告生成:%+v", testResult))
+}