update: loss

main
Leo 3 months ago
parent 29f6981e54
commit 9e61b448fb

@ -27,6 +27,5 @@ var highOpticalLossCmd = &cobra.Command{
func defFlagsLoss(cmd *cobra.Command) { func defFlagsLoss(cmd *cobra.Command) {
cmd.Flags().String("wms.token", "", "*Specify the token of WMS-ZJ(装维调度系统)") cmd.Flags().String("wms.token", "", "*Specify the token of WMS-ZJ(装维调度系统)")
//cmd.Flags().String(config.WechatApi, "", "微信推送api") cmd.Flags().String("loss.open", "", "*Specify the file of excel to open")
//cmd.Flags().String(config.WechatToken, "", "微信推送服务token")
} }

@ -4,16 +4,22 @@ import (
"cu-helper/wms/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/configkit"
"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"
"path/filepath"
"strconv" "strconv"
"time" "time"
) )
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/光衰通报(5月30日).xlsx") open := configkit.GetString("loss.open", "")
if open == "" {
open = "/Users/leo/Documents/光衰通报/光衰/2025/光衰通报(11月5日).xlsx"
}
f, err := excelize.OpenFile(open)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
@ -123,9 +129,9 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
NumFmt: 10, // 或使用自定义格式代码:"0.00%" NumFmt: 10, // 或使用自定义格式代码:"0.00%"
}) })
// Cut and paste data from E4:E23 to C4:C23 // Cut and paste data from E4:E25 to C4:C25
//TODO //TODO
for i := 4; i <= 23; i++ { for i := 4; i <= 25; i++ {
eCell := "E" + strconv.Itoa(i) eCell := "E" + strconv.Itoa(i)
cCell := "C" + strconv.Itoa(i) cCell := "C" + strconv.Itoa(i)
value, _ := f.GetCellValue("汇总", eCell) value, _ := f.GetCellValue("汇总", eCell)
@ -133,9 +139,9 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
f.SetCellValue("汇总", eCell, "") f.SetCellValue("汇总", eCell, "")
} }
// Populate E4:L23 with data from the map // Populate E4:L25 with data from the map
//TODO //TODO
for i := 4; i <= 23; i++ { for i := 4; i <= 25; i++ {
bCell := "B" + strconv.Itoa(i) bCell := "B" + strconv.Itoa(i)
key, _ := f.GetCellValue("汇总", bCell) key, _ := f.GetCellValue("汇总", bCell)
if data, ok := m1[key]; ok { if data, ok := m1[key]; ok {
@ -234,9 +240,9 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
} }
} }
// Calculate D4:D23 as C-E // Calculate D4:D25 as C-E
//TODO //TODO
for i := 4; i <= 23; i++ { for i := 4; i <= 25; i++ {
cCell := "C" + strconv.Itoa(i) cCell := "C" + strconv.Itoa(i)
eCell := "E" + strconv.Itoa(i) eCell := "E" + strconv.Itoa(i)
dCell := "D" + strconv.Itoa(i) dCell := "D" + strconv.Itoa(i)
@ -261,19 +267,19 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
f.SetCellStyle("汇总", dCell, dCell, styleGreen) f.SetCellStyle("汇总", dCell, dCell, styleGreen)
} }
} }
// Sum columns C:H and place the results in row 24 // Sum columns C:H and place the results in row 26
for col := 'C'; col <= 'L'; col++ { for col := 'C'; col <= 'L'; col++ {
//TODO //TODO
sumCell := string(col) + "24" sumCell := string(col) + "26"
//TODO //TODO
sumFormula := fmt.Sprintf("SUM(%s4:%s23)", string(col), string(col)) sumFormula := fmt.Sprintf("SUM(%s4:%s25)", 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 <= 'L'; col++ { for col := 'C'; col <= 'L'; col++ {
//TODO //TODO
sumCell := string(col) + "24" sumCell := string(col) + "26"
value, err := f.CalcCellValue("汇总", sumCell) value, err := f.CalcCellValue("汇总", sumCell)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -282,16 +288,17 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
} }
} }
//TODO 3行 //TODO 3行
done, _ := f.GetCellValue("汇总", "K24") done, _ := f.GetCellValue("汇总", "K26")
total, _ := f.GetCellValue("汇总", "L24") total, _ := f.GetCellValue("汇总", "L26")
f.SetCellValue("汇总", "M24", mathkit.FloatRound(cast.ToFloat64(done)/cast.ToFloat64(total), 4)) f.SetCellValue("汇总", "M26", 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日"))
f.SetCellValue("汇总", "A1", content) f.SetCellValue("汇总", "A1", content)
// Save the file // Save the file
if err := f.SaveAs("/Users/leo/Documents/光衰通报/光衰/2025/光衰通报(" + time.Now().Format("1月2日") + ").xlsx"); err != nil { save := filepath.Dir(open) + "/光衰通报(" + time.Now().Format("1月2日") + ").xlsx"
if err := f.SaveAs(save); err != nil {
fmt.Println(err) fmt.Println(err)
} }
logkit.Info("生成结束...") logkit.Info("生成结束...")

@ -30,7 +30,7 @@ func NewGetOrderQueryList(no string) *GetOrderQueryList {
return &GetOrderQueryList{ return &GetOrderQueryList{
Page: "1", Page: "1",
Rows: "10", Rows: "10",
OrgId: "330106", //西湖 OrgId: "330106", //西湖=330106 萧山=330109
BusiNo: no, BusiNo: no,
BusiType: "1", BusiType: "1",
QueryFlag: "2", QueryFlag: "2",

@ -46,18 +46,28 @@ func ReqGetHighOptLossUnderList() map[string]*HighOptLossUnder {
m[v.Get("DEAL_MAN").String()].Count++ m[v.Get("DEAL_MAN").String()].Count++
if v.Get("STATUS").String() == "施工处理" { if v.Get("STATUS").String() == "施工处理" {
m[v.Get("DEAL_MAN").String()].UnderCount++ m[v.Get("DEAL_MAN").String()].UnderCount++
if v.Get("REPLY_TYPE").String() == "不可处理" { if v.Get("REPLY_TYPE").String() == "不可处理" || v.Get("REPLY_TYPE").String() == "不可整治" {
m[v.Get("DEAL_MAN").String()].CantCount++ m[v.Get("DEAL_MAN").String()].CantCount++
m[v.Get("DEAL_MAN").String()].UnderCount--
} }
duration := v.Get("TIMELONGS").Int() duration := v.Get("TIMELONGS").Int()
if duration >= 604800 { if duration >= 604800 {
m[v.Get("DEAL_MAN").String()].DurationOverSeven++ m[v.Get("DEAL_MAN").String()].DurationOverSeven++
if v.Get("REPLY_TYPE").String() == "不可处理" || v.Get("REPLY_TYPE").String() == "不可整治" {
m[v.Get("DEAL_MAN").String()].DurationOverSeven--
}
} }
if duration >= 1296000 { if duration >= 1296000 {
m[v.Get("DEAL_MAN").String()].DurationOverFifteen++ m[v.Get("DEAL_MAN").String()].DurationOverFifteen++
if v.Get("REPLY_TYPE").String() == "不可处理" || v.Get("REPLY_TYPE").String() == "不可整治" {
m[v.Get("DEAL_MAN").String()].DurationOverFifteen--
}
} }
if v.Get("BOOK_TIME").String() != "" { if v.Get("BOOK_TIME").String() != "" {
m[v.Get("DEAL_MAN").String()].Book++ m[v.Get("DEAL_MAN").String()].Book++
if v.Get("REPLY_TYPE").String() == "不可处理" || v.Get("REPLY_TYPE").String() == "不可整治" {
m[v.Get("DEAL_MAN").String()].Book--
}
} }
} }
if v.Get("STATUS").String() == "人工回访" { if v.Get("STATUS").String() == "人工回访" {

Loading…
Cancel
Save