Browse Source

fix: 混合表格复制条件格式配置

hsun 2 weeks ago
parent
commit
8b0aa41a4d

+ 15 - 0
models/data_manage/excel/excel_info_rule_mapping.go

@@ -76,3 +76,18 @@ func DeleteExcelRuleMappingById(id int) (err error) {
 	err = global.DbMap[utils.DbNameIndex].Exec(sql, id).Error
 	return
 }
+
+func (e *ExcelInfoRuleMapping) CreateMulti(items []*ExcelInfoRuleMapping) (err error) {
+	if len(items) == 0 {
+		return
+	}
+	err = global.DbMap[utils.DbNameIndex].CreateInBatches(items, utils.MultiAddNum).Error
+	return
+}
+
+// GetExcelRuleMappingsByExcelInfoId 根据excelInfoId获取规则映射信息
+func GetExcelRuleMappingsByExcelInfoId(id int) (items []*ExcelInfoRuleMapping, err error) {
+	sql := `SELECT * FROM excel_info_rule_mapping WHERE excel_info_id = ? ORDER BY create_time ASC`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, id).Find(&items).Error
+	return
+}

+ 17 - 0
services/data/excel/excel_op.go

@@ -222,6 +222,23 @@ func Copy(oldExcelInfo *excelModel.ExcelInfo, excelClassifyId int, excelName str
 			errMsg = "保存失败"
 		}
 
+		// 混合表格-条件格式配置
+		excelRules, e := excelModel.GetExcelRuleMappingsByExcelInfoId(oldExcelInfo.ExcelInfoId)
+		if e != nil {
+			err = fmt.Errorf("获取条件格式配置失败, %v", e)
+			return
+		}
+		if len(excelRules) > 0 {
+			for _, v := range excelRules {
+				v.ExcelInfoRuleMappingId = 0
+				v.ExcelInfoId = excelInfo.ExcelInfoId
+			}
+			mappingOb := new(excelModel.ExcelInfoRuleMapping)
+			if e = mappingOb.CreateMulti(excelRules); e != nil {
+				err = fmt.Errorf("复制条件格式配置失败, %v", e)
+				return
+			}
+		}
 		return
 	}