Преглед на файлове

开发端子导出表格生成

liling преди 1 година
родител
ревизия
af2cd3c26a
променени са 2 файла, в които са добавени 51 реда и са изтрити 6 реда
  1. 6 4
      service/models/bo/checktools_area.go
  2. 45 2
      service/models/bo/task_report.go

+ 6 - 4
service/models/bo/checktools_area.go

@@ -1431,8 +1431,10 @@ func (c *CheckAreaMgr) getIedListByVol(iedtype string, ieds map[string]orm.Param
 	return tmpLst[vollevel["hight"]], tmpLst[vollevel["middle"]], tmpLst[vollevel["low"]]
 }
 
-//测试
-func (c *CheckAreaMgr) TestAppendNode(iedname string) {
-	//t := t_scd_node_scl{NodeName: iedname}
-	//c.AppendIedNode(&t)
+func (c *CheckAreaMgr) GetCheckResult(scdid int64) ([]orm.Params, error) {
+	db := orm.NewOrm()
+	rowset := []orm.Params{}
+	sql := "select *,case error_type when 1 then '多余' when 2 then '错误' when 3 then '缺失' else '其他' end error_type_desc from t_scd_fcda_check_result where scd_id=? order by ied_name"
+	_, err := db.Raw(sql, scdid).Values(&rowset)
+	return rowset, err
 }

+ 45 - 2
service/models/bo/task_report.go

@@ -212,6 +212,11 @@ func (c *TaskReportMgr) ToWord(taskinfo T_data_task) (path string, err error) {
 	//生成报告数据
 	var file *xlsx.File
 	file = xlsx.NewFile()
+	sheet_fcda, err := file.AddSheet("虚端子关系")
+	if err != nil {
+		logger.Logger.Error(err)
+		return "", err
+	}
 	sheet_c, err := file.AddSheet("测控装置")
 	if err != nil {
 		logger.Logger.Error(err)
@@ -313,6 +318,36 @@ func (c *TaskReportMgr) ToWord(taskinfo T_data_task) (path string, err error) {
 			rowInd = rowInd + 1
 		}
 	}
+	result = nil
+	iedResultMap = nil
+	//生成端子关系检查结果
+	checkAreaRe := new(CheckAreaMgr)
+	result, err = checkAreaRe.GetCheckResult(taskinfo.ScdId)
+	if err != nil {
+		logger.Logger.Error(err)
+		return "", err
+	}
+	c.setCaption(sheet_fcda, fmt.Sprintf("%s-端子校验结果", scdName), 6)
+	lastIedName := ""
+	cellNo := 1
+	for _, row := range result {
+		nowIedName := fmt.Sprintf("%s:%s", tools.IsEmpty(row["ied_name"]), tools.IsEmpty(row["ied_desc"]))
+		if lastIedName == "" || lastIedName != nowIedName {
+			lastIedName = nowIedName
+			c.setCaption(sheet_fcda, lastIedName, 6)
+			c.addCellValue(sheet_fcda, []string{"序号", "外部IED", "发送信号", "本IED", "接收信号", "结论"})
+			cellNo = 1
+		}
+		c.addCellValue(sheet_fcda, []string{
+			fmt.Sprintf("%d", cellNo),
+			fmt.Sprintf("%s:%s", tools.IsEmpty(row["out_ied_name"]), tools.IsEmpty(row["out_ied_desc"])),
+			fmt.Sprintf("%s\n%s", tools.IsEmpty(row["out_fcda_desc"]), tools.IsEmpty(row["out_fcda_addr"])),
+			fmt.Sprintf("%s:%s", tools.IsEmpty(row["ied_name"]), tools.IsEmpty(row["ied_desc"])),
+			fmt.Sprintf("%s\n%s", tools.IsEmpty(row["fcda_desc"]), tools.IsEmpty(row["fcda_addr"])),
+			tools.IsEmpty(row["error_type_desc"]),
+		})
+		cellNo = cellNo + 1
+	}
 	err = file.Save(reportFN)
 	if err != nil {
 		logger.Logger.Error(err)
@@ -321,10 +356,14 @@ func (c *TaskReportMgr) ToWord(taskinfo T_data_task) (path string, err error) {
 	return reportFN[1:], err
 }
 
-func (c *TaskReportMgr) setCaption(sheet *xlsx.Sheet, caption string) *xlsx.Cell {
+func (c *TaskReportMgr) setCaption(sheet *xlsx.Sheet, caption string, margeNum ...int) *xlsx.Cell {
 	row := sheet.AddRow()
 	cell := row.AddCell()
-	cell.HMerge = 5 //合并单元格数
+	if len(margeNum) > 0 {
+		cell.HMerge = margeNum[0]
+	} else {
+		cell.HMerge = 5 //合并单元格数
+	}
 	cell.Value = caption
 	style := xlsx.NewStyle()
 	style.Alignment.Horizontal = "center"
@@ -337,5 +376,9 @@ func (c *TaskReportMgr) addCellValue(sheet *xlsx.Sheet, vs []string) {
 	for _, r := range vs {
 		cell := row.AddCell()
 		cell.Value = r
+		style := xlsx.NewStyle()
+		style.Alignment.Horizontal = "left"
+		style.Alignment.WrapText = true
+		cell.SetStyle(style)
 	}
 }