|
|
|
@ -3,19 +3,125 @@ package common
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"cu-helper/high-opt-loss/service"
|
|
|
|
"cu-helper/high-opt-loss/service"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/mizuki1412/go-core-kit/library/mathkit"
|
|
|
|
"github.com/mizuki1412/go-core-kit/service/logkit"
|
|
|
|
"github.com/mizuki1412/go-core-kit/service/logkit"
|
|
|
|
"github.com/spf13/cast"
|
|
|
|
"github.com/spf13/cast"
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func GenExcelFile(m map[string]*service.HighOptLoss) {
|
|
|
|
func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*service.HighOptLossHistory) {
|
|
|
|
// Open the Excel file
|
|
|
|
// Open the Excel file
|
|
|
|
f, err := excelize.OpenFile("/Users/leo/Documents/光衰通报/大光衰/2025/大光衰通报(3月3日).xlsx")
|
|
|
|
f, err := excelize.OpenFile("/Users/leo/Documents/光衰通报/光衰/2025/光衰通报(3月14日).xlsx")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
styleRed, err := f.NewStyle(&excelize.Style{
|
|
|
|
|
|
|
|
Alignment: &excelize.Alignment{
|
|
|
|
|
|
|
|
Horizontal: "center",
|
|
|
|
|
|
|
|
Vertical: "center",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Border: []excelize.Border{
|
|
|
|
|
|
|
|
{Type: "top", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "bottom", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "left", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "right", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Fill: excelize.Fill{
|
|
|
|
|
|
|
|
Type: "pattern",
|
|
|
|
|
|
|
|
Color: []string{"C00000"}, // RGB(192,0,0)
|
|
|
|
|
|
|
|
Pattern: 1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Font: &excelize.Font{
|
|
|
|
|
|
|
|
Color: "FFFFFF", // 白色
|
|
|
|
|
|
|
|
Bold: true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
styleRedFMT, err := f.NewStyle(&excelize.Style{
|
|
|
|
|
|
|
|
Alignment: &excelize.Alignment{
|
|
|
|
|
|
|
|
Horizontal: "center",
|
|
|
|
|
|
|
|
Vertical: "center",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Border: []excelize.Border{
|
|
|
|
|
|
|
|
{Type: "top", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "bottom", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "left", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "right", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Fill: excelize.Fill{
|
|
|
|
|
|
|
|
Type: "pattern",
|
|
|
|
|
|
|
|
Color: []string{"C00000"}, // RGB(192,0,0)
|
|
|
|
|
|
|
|
Pattern: 1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Font: &excelize.Font{
|
|
|
|
|
|
|
|
Color: "FFFFFF", // 白色
|
|
|
|
|
|
|
|
Bold: true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
NumFmt: 10, // 或使用自定义格式代码:"0.00%"
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
styleYellow, err := f.NewStyle(&excelize.Style{
|
|
|
|
|
|
|
|
Alignment: &excelize.Alignment{
|
|
|
|
|
|
|
|
Horizontal: "center",
|
|
|
|
|
|
|
|
Vertical: "center",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Border: []excelize.Border{
|
|
|
|
|
|
|
|
{Type: "top", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "bottom", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "left", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "right", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Fill: excelize.Fill{
|
|
|
|
|
|
|
|
Type: "pattern",
|
|
|
|
|
|
|
|
Color: []string{"FFC000"}, // RGB(255,192,0)
|
|
|
|
|
|
|
|
Pattern: 1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Font: &excelize.Font{
|
|
|
|
|
|
|
|
Bold: true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
styleGreen, err := f.NewStyle(&excelize.Style{
|
|
|
|
|
|
|
|
Alignment: &excelize.Alignment{
|
|
|
|
|
|
|
|
Horizontal: "center",
|
|
|
|
|
|
|
|
Vertical: "center",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Border: []excelize.Border{
|
|
|
|
|
|
|
|
{Type: "top", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "bottom", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "left", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "right", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Fill: excelize.Fill{
|
|
|
|
|
|
|
|
Type: "pattern",
|
|
|
|
|
|
|
|
Color: []string{"92D050"}, // RGB(146,208,80)
|
|
|
|
|
|
|
|
Pattern: 1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Font: &excelize.Font{
|
|
|
|
|
|
|
|
Bold: true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
styleGreenFMT, err := f.NewStyle(&excelize.Style{
|
|
|
|
|
|
|
|
Alignment: &excelize.Alignment{
|
|
|
|
|
|
|
|
Horizontal: "center",
|
|
|
|
|
|
|
|
Vertical: "center",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Border: []excelize.Border{
|
|
|
|
|
|
|
|
{Type: "top", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "bottom", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "left", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
{Type: "right", Style: 1, Color: "000000"},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Fill: excelize.Fill{
|
|
|
|
|
|
|
|
Type: "pattern",
|
|
|
|
|
|
|
|
Color: []string{"92D050"}, // RGB(146,208,80)
|
|
|
|
|
|
|
|
Pattern: 1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Font: &excelize.Font{
|
|
|
|
|
|
|
|
Bold: true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
NumFmt: 10, // 或使用自定义格式代码:"0.00%"
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Cut and paste data from E4:E22 to C4:C22
|
|
|
|
// Cut and paste data from E4:E22 to C4:C22
|
|
|
|
for i := 4; i <= 22; i++ {
|
|
|
|
for i := 4; i <= 22; i++ {
|
|
|
|
@ -26,90 +132,101 @@ func GenExcelFile(m map[string]*service.HighOptLoss) {
|
|
|
|
f.SetCellValue("汇总", eCell, "")
|
|
|
|
f.SetCellValue("汇总", eCell, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Populate E4:H22 with data from the map
|
|
|
|
// Populate E4:L22 with data from the map
|
|
|
|
for i := 4; i <= 22; i++ {
|
|
|
|
for i := 4; i <= 22; i++ {
|
|
|
|
bCell := "B" + strconv.Itoa(i)
|
|
|
|
bCell := "B" + strconv.Itoa(i)
|
|
|
|
key, _ := f.GetCellValue("汇总", bCell)
|
|
|
|
key, _ := f.GetCellValue("汇总", bCell)
|
|
|
|
if data, ok := m[key]; ok {
|
|
|
|
if data, ok := m1[key]; ok {
|
|
|
|
f.SetCellValue("汇总", "E"+strconv.Itoa(i), data.Count)
|
|
|
|
f.SetCellValue("汇总", "E"+strconv.Itoa(i), data.UnderCount)
|
|
|
|
|
|
|
|
if data.UnderCount == 0 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "E"+strconv.Itoa(i), "E"+strconv.Itoa(i), styleGreen)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.UnderCount > 0 && data.UnderCount <= 5 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "E"+strconv.Itoa(i), "E"+strconv.Itoa(i), styleYellow)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.UnderCount > 5 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "E"+strconv.Itoa(i), "E"+strconv.Itoa(i), styleRed)
|
|
|
|
|
|
|
|
}
|
|
|
|
f.SetCellValue("汇总", "F"+strconv.Itoa(i), data.DurationOverSeven)
|
|
|
|
f.SetCellValue("汇总", "F"+strconv.Itoa(i), data.DurationOverSeven)
|
|
|
|
|
|
|
|
if data.DurationOverSeven == 0 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "F"+strconv.Itoa(i), "F"+strconv.Itoa(i), styleGreen)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.DurationOverSeven > 0 && data.DurationOverSeven <= 5 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "F"+strconv.Itoa(i), "F"+strconv.Itoa(i), styleYellow)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.DurationOverSeven > 5 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "F"+strconv.Itoa(i), "F"+strconv.Itoa(i), styleRed)
|
|
|
|
|
|
|
|
}
|
|
|
|
f.SetCellValue("汇总", "G"+strconv.Itoa(i), data.DurationOverFifteen)
|
|
|
|
f.SetCellValue("汇总", "G"+strconv.Itoa(i), data.DurationOverFifteen)
|
|
|
|
|
|
|
|
if data.DurationOverFifteen == 0 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "G"+strconv.Itoa(i), "G"+strconv.Itoa(i), styleGreen)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.DurationOverFifteen > 0 && data.DurationOverFifteen <= 5 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "G"+strconv.Itoa(i), "G"+strconv.Itoa(i), styleYellow)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.DurationOverFifteen > 5 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "G"+strconv.Itoa(i), "G"+strconv.Itoa(i), styleRed)
|
|
|
|
|
|
|
|
}
|
|
|
|
f.SetCellValue("汇总", "H"+strconv.Itoa(i), data.Book)
|
|
|
|
f.SetCellValue("汇总", "H"+strconv.Itoa(i), data.Book)
|
|
|
|
|
|
|
|
if data.Book == 0 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "H"+strconv.Itoa(i), "H"+strconv.Itoa(i), styleRed)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.Book > 0 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "H"+strconv.Itoa(i), "H"+strconv.Itoa(i), styleGreen)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.Book == 0 && data.UnderCount == 0 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "H"+strconv.Itoa(i), "H"+strconv.Itoa(i), styleGreen)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "I"+strconv.Itoa(i), data.ApplyCount)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
f.SetCellValue("汇总", "E"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "E"+strconv.Itoa(i), 0)
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "E"+strconv.Itoa(i), "E"+strconv.Itoa(i), styleGreen)
|
|
|
|
f.SetCellValue("汇总", "F"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "F"+strconv.Itoa(i), 0)
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "F"+strconv.Itoa(i), "F"+strconv.Itoa(i), styleGreen)
|
|
|
|
f.SetCellValue("汇总", "G"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "G"+strconv.Itoa(i), 0)
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "G"+strconv.Itoa(i), "G"+strconv.Itoa(i), styleGreen)
|
|
|
|
f.SetCellValue("汇总", "H"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "H"+strconv.Itoa(i), 0)
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "H"+strconv.Itoa(i), "H"+strconv.Itoa(i), styleGreen)
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "I"+strconv.Itoa(i), 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if data, ok := m2[key]; ok {
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "J"+strconv.Itoa(i), data.Count)
|
|
|
|
// Calculate D4:D22 as C-E
|
|
|
|
if data1, ok1 := m1[key]; ok1 {
|
|
|
|
for i := 4; i <= 22; i++ {
|
|
|
|
//有归档+有在途
|
|
|
|
cCell := "C" + strconv.Itoa(i)
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), data.Count+data1.Count)
|
|
|
|
eCell := "E" + strconv.Itoa(i)
|
|
|
|
v := mathkit.FloatRound(float64(data.Count)/(float64(data.Count)+float64(data1.Count)), 4)
|
|
|
|
dCell := "D" + strconv.Itoa(i)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), v)
|
|
|
|
cValue, _ := f.GetCellValue("汇总", cCell)
|
|
|
|
if v < 0.8 {
|
|
|
|
eValue, _ := f.GetCellValue("汇总", eCell)
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleRedFMT)
|
|
|
|
cInt, _ := strconv.Atoi(cValue)
|
|
|
|
}
|
|
|
|
eInt, _ := strconv.Atoi(eValue)
|
|
|
|
if v >= 0.8 {
|
|
|
|
f.SetCellValue("汇总", dCell, cInt-eInt)
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleGreenFMT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Sum columns C:H and place the results in row 23
|
|
|
|
} else {
|
|
|
|
for col := 'C'; col <= 'H'; col++ {
|
|
|
|
//有归档+无在途
|
|
|
|
sumCell := string(col) + "23"
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), data.Count)
|
|
|
|
sumFormula := fmt.Sprintf("SUM(%s4:%s22)", string(col), string(col))
|
|
|
|
v := mathkit.FloatRound(float64(data.Count)/(float64(data.Count)), 4)
|
|
|
|
f.SetCellFormula("汇总", sumCell, sumFormula)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), v)
|
|
|
|
}
|
|
|
|
if v < 0.8 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleRedFMT)
|
|
|
|
// Recalculate the sum for each cell to ensure it appears without manual intervention
|
|
|
|
}
|
|
|
|
for col := 'C'; col <= 'H'; col++ {
|
|
|
|
if v >= 0.8 {
|
|
|
|
sumCell := string(col) + "23"
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleGreenFMT)
|
|
|
|
value, err := f.CalcCellValue("汇总", sumCell)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
}
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", sumCell, cast.ToInt(value))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save the file
|
|
|
|
|
|
|
|
if err := f.SaveAs("/Users/leo/Documents/光衰通报/大光衰/2025/大光衰通报(3月14日).xlsx"); err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
logkit.Info("生成结束...")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GenExcelFileSmall(m map[string]*service.HighOptLoss) {
|
|
|
|
|
|
|
|
// Open the Excel file
|
|
|
|
|
|
|
|
f, err := excelize.OpenFile("/Users/leo/Documents/光衰通报/小光衰/2025/光衰质差通报(3月3日).xlsx")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cut and paste data from E4:E22 to C4:C22
|
|
|
|
|
|
|
|
for i := 4; i <= 22; i++ {
|
|
|
|
|
|
|
|
eCell := "E" + strconv.Itoa(i)
|
|
|
|
|
|
|
|
cCell := "C" + strconv.Itoa(i)
|
|
|
|
|
|
|
|
value, _ := f.GetCellValue("汇总", eCell)
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", cCell, cast.ToInt(value))
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", eCell, "")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Populate E4:H22 with data from the map
|
|
|
|
|
|
|
|
for i := 4; i <= 22; i++ {
|
|
|
|
|
|
|
|
bCell := "B" + strconv.Itoa(i)
|
|
|
|
|
|
|
|
key, _ := f.GetCellValue("汇总", bCell)
|
|
|
|
|
|
|
|
if data, ok := m[key]; ok {
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "E"+strconv.Itoa(i), data.Count)
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "F"+strconv.Itoa(i), data.DurationOverSeven)
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "G"+strconv.Itoa(i), data.DurationOverFifteen)
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "H"+strconv.Itoa(i), data.Book)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
f.SetCellValue("汇总", "E"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "J"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "F"+strconv.Itoa(i), 0)
|
|
|
|
if data1, ok1 := m1[key]; ok1 {
|
|
|
|
f.SetCellValue("汇总", "G"+strconv.Itoa(i), 0)
|
|
|
|
//无归档+有在途
|
|
|
|
f.SetCellValue("汇总", "H"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), data1.Count)
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), 0)
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleRedFMT)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//无归档+无在途
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), 0)
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), 1)
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleGreenFMT)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -123,16 +240,31 @@ func GenExcelFileSmall(m map[string]*service.HighOptLoss) {
|
|
|
|
cInt, _ := strconv.Atoi(cValue)
|
|
|
|
cInt, _ := strconv.Atoi(cValue)
|
|
|
|
eInt, _ := strconv.Atoi(eValue)
|
|
|
|
eInt, _ := strconv.Atoi(eValue)
|
|
|
|
f.SetCellValue("汇总", dCell, cInt-eInt)
|
|
|
|
f.SetCellValue("汇总", dCell, cInt-eInt)
|
|
|
|
|
|
|
|
if cInt-eInt == 0 {
|
|
|
|
|
|
|
|
//本周压降为0但是当前遗留量为0
|
|
|
|
|
|
|
|
if eInt == 0 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", dCell, dCell, styleGreen)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//当前有遗留但是没压降量
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", dCell, dCell, styleYellow)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if cInt-eInt < 0 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", dCell, dCell, styleRed)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if cInt-eInt > 0 {
|
|
|
|
|
|
|
|
f.SetCellStyle("汇总", dCell, dCell, styleGreen)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Sum columns C:H and place the results in row 23
|
|
|
|
// Sum columns C:H and place the results in row 23
|
|
|
|
for col := 'C'; col <= 'H'; col++ {
|
|
|
|
for col := 'C'; col <= 'K'; col++ {
|
|
|
|
sumCell := string(col) + "23"
|
|
|
|
sumCell := string(col) + "23"
|
|
|
|
sumFormula := fmt.Sprintf("SUM(%s4:%s22)", string(col), string(col))
|
|
|
|
sumFormula := fmt.Sprintf("SUM(%s4:%s22)", string(col), string(col))
|
|
|
|
f.SetCellFormula("汇总", sumCell, sumFormula)
|
|
|
|
f.SetCellFormula("汇总", sumCell, sumFormula)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Recalculate the sum for each cell to ensure it appears without manual intervention
|
|
|
|
// Recalculate the sum for each cell to ensure it appears without manual intervention
|
|
|
|
for col := 'C'; col <= 'H'; col++ {
|
|
|
|
for col := 'C'; col <= 'K'; col++ {
|
|
|
|
sumCell := string(col) + "23"
|
|
|
|
sumCell := string(col) + "23"
|
|
|
|
value, err := f.CalcCellValue("汇总", sumCell)
|
|
|
|
value, err := f.CalcCellValue("汇总", sumCell)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
@ -141,9 +273,16 @@ func GenExcelFileSmall(m map[string]*service.HighOptLoss) {
|
|
|
|
f.SetCellValue("汇总", sumCell, cast.ToInt(value))
|
|
|
|
f.SetCellValue("汇总", sumCell, cast.ToInt(value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done, _ := f.GetCellValue("汇总", "J23")
|
|
|
|
|
|
|
|
total, _ := f.GetCellValue("汇总", "K23")
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "L23", mathkit.FloatRound(cast.ToFloat64(done)/cast.ToFloat64(total), 4))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置表头
|
|
|
|
|
|
|
|
content := fmt.Sprintf("西湖智家光衰通报:%s", time.Now().Format("1月2日"))
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "A1", content)
|
|
|
|
|
|
|
|
|
|
|
|
// Save the file
|
|
|
|
// Save the file
|
|
|
|
if err := f.SaveAs("/Users/leo/Documents/光衰通报/小光衰/2025/光衰质差通报(3月14日).xlsx"); err != nil {
|
|
|
|
if err := f.SaveAs("/Users/leo/Documents/光衰通报/光衰/2025/光衰通报(" + time.Now().Format("1月2日") + ").xlsx"); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logkit.Info("生成结束...")
|
|
|
|
logkit.Info("生成结束...")
|
|
|
|
|