|
|
|
@ -1,7 +1,7 @@
|
|
|
|
package common
|
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"cu-helper/high-opt-loss/service"
|
|
|
|
"cu-helper/wms/service"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"github.com/mizuki1412/go-core-kit/library/mathkit"
|
|
|
|
"github.com/mizuki1412/go-core-kit/library/mathkit"
|
|
|
|
"github.com/mizuki1412/go-core-kit/service/logkit"
|
|
|
|
"github.com/mizuki1412/go-core-kit/service/logkit"
|
|
|
|
@ -13,7 +13,7 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*service.HighOptLossHistory) {
|
|
|
|
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月14日).xlsx")
|
|
|
|
f, err := excelize.OpenFile("/Users/leo/Documents/光衰通报/光衰/2025/光衰通报(3月28日).xlsx")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
@ -177,7 +177,8 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
|
|
|
|
if data.Book == 0 && data.UnderCount == 0 {
|
|
|
|
if data.Book == 0 && data.UnderCount == 0 {
|
|
|
|
f.SetCellStyle("汇总", "H"+strconv.Itoa(i), "H"+strconv.Itoa(i), styleGreen)
|
|
|
|
f.SetCellStyle("汇总", "H"+strconv.Itoa(i), "H"+strconv.Itoa(i), styleGreen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f.SetCellValue("汇总", "I"+strconv.Itoa(i), data.ApplyCount)
|
|
|
|
f.SetCellValue("汇总", "I"+strconv.Itoa(i), data.CantCount)
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "J"+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.SetCellStyle("汇总", "E"+strconv.Itoa(i), "E"+strconv.Itoa(i), styleGreen)
|
|
|
|
@ -188,44 +189,45 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
|
|
|
|
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.SetCellStyle("汇总", "H"+strconv.Itoa(i), "H"+strconv.Itoa(i), styleGreen)
|
|
|
|
f.SetCellValue("汇总", "I"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "I"+strconv.Itoa(i), 0)
|
|
|
|
|
|
|
|
f.SetCellValue("汇总", "J"+strconv.Itoa(i), 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if data, ok := m2[key]; ok {
|
|
|
|
if data, ok := m2[key]; ok {
|
|
|
|
f.SetCellValue("汇总", "J"+strconv.Itoa(i), data.Count)
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), data.Count)
|
|
|
|
if data1, ok1 := m1[key]; ok1 {
|
|
|
|
if data1, ok1 := m1[key]; ok1 {
|
|
|
|
//有归档+有在途
|
|
|
|
//有归档+有在途
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), data.Count+data1.Count)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), data.Count+data1.Count)
|
|
|
|
v := mathkit.FloatRound(float64(data.Count)/(float64(data.Count)+float64(data1.Count)), 4)
|
|
|
|
v := mathkit.FloatRound(float64(data.Count)/(float64(data.Count)+float64(data1.Count)), 4)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), v)
|
|
|
|
f.SetCellValue("汇总", "M"+strconv.Itoa(i), v)
|
|
|
|
if v < 0.8 {
|
|
|
|
if v < 0.8 {
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleRedFMT)
|
|
|
|
f.SetCellStyle("汇总", "M"+strconv.Itoa(i), "M"+strconv.Itoa(i), styleRedFMT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v >= 0.8 {
|
|
|
|
if v >= 0.8 {
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleGreenFMT)
|
|
|
|
f.SetCellStyle("汇总", "M"+strconv.Itoa(i), "M"+strconv.Itoa(i), styleGreenFMT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//有归档+无在途
|
|
|
|
//有归档+无在途
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), data.Count)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), data.Count)
|
|
|
|
v := mathkit.FloatRound(float64(data.Count)/(float64(data.Count)), 4)
|
|
|
|
v := mathkit.FloatRound(float64(data.Count)/(float64(data.Count)), 4)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), v)
|
|
|
|
f.SetCellValue("汇总", "M"+strconv.Itoa(i), v)
|
|
|
|
if v < 0.8 {
|
|
|
|
if v < 0.8 {
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleRedFMT)
|
|
|
|
f.SetCellStyle("汇总", "M"+strconv.Itoa(i), "M"+strconv.Itoa(i), styleRedFMT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v >= 0.8 {
|
|
|
|
if v >= 0.8 {
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleGreenFMT)
|
|
|
|
f.SetCellStyle("汇总", "M"+strconv.Itoa(i), "M"+strconv.Itoa(i), styleGreenFMT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
f.SetCellValue("汇总", "J"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), 0)
|
|
|
|
if data1, ok1 := m1[key]; ok1 {
|
|
|
|
if data1, ok1 := m1[key]; ok1 {
|
|
|
|
//无归档+有在途
|
|
|
|
//无归档+有在途
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), data1.Count)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), data1.Count)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "M"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleRedFMT)
|
|
|
|
f.SetCellStyle("汇总", "M"+strconv.Itoa(i), "M"+strconv.Itoa(i), styleRedFMT)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//无归档+无在途
|
|
|
|
//无归档+无在途
|
|
|
|
f.SetCellValue("汇总", "K"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), 0)
|
|
|
|
f.SetCellValue("汇总", "L"+strconv.Itoa(i), 1)
|
|
|
|
f.SetCellValue("汇总", "M"+strconv.Itoa(i), 1)
|
|
|
|
f.SetCellStyle("汇总", "L"+strconv.Itoa(i), "L"+strconv.Itoa(i), styleGreenFMT)
|
|
|
|
f.SetCellStyle("汇总", "M"+strconv.Itoa(i), "M"+strconv.Itoa(i), styleGreenFMT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -257,14 +259,14 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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 <= 'K'; col++ {
|
|
|
|
for col := 'C'; col <= 'L'; 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 <= 'K'; col++ {
|
|
|
|
for col := 'C'; col <= 'L'; 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 {
|
|
|
|
@ -273,9 +275,9 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
|
|
|
|
f.SetCellValue("汇总", sumCell, cast.ToInt(value))
|
|
|
|
f.SetCellValue("汇总", sumCell, cast.ToInt(value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done, _ := f.GetCellValue("汇总", "J23")
|
|
|
|
done, _ := f.GetCellValue("汇总", "K23")
|
|
|
|
total, _ := f.GetCellValue("汇总", "K23")
|
|
|
|
total, _ := f.GetCellValue("汇总", "L23")
|
|
|
|
f.SetCellValue("汇总", "L23", mathkit.FloatRound(cast.ToFloat64(done)/cast.ToFloat64(total), 4))
|
|
|
|
f.SetCellValue("汇总", "M23", mathkit.FloatRound(cast.ToFloat64(done)/cast.ToFloat64(total), 4))
|
|
|
|
|
|
|
|
|
|
|
|
//设置表头
|
|
|
|
//设置表头
|
|
|
|
content := fmt.Sprintf("西湖智家光衰通报:%s", time.Now().Format("1月2日"))
|
|
|
|
content := fmt.Sprintf("西湖智家光衰通报:%s", time.Now().Format("1月2日"))
|