From ee77d4f4b8e766d0218b42f82646f80ed7a0295f Mon Sep 17 00:00:00 2001 From: Leo Date: Mon, 20 Jan 2025 09:31:34 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E5=88=86=E7=A6=BB=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=85=89=E8=A1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/high_opt_loss.go | 7 +- high-opt-loss/common/excelkit.go | 74 ++++++++++++++++++- .../service/get_high_opt_loss_list.go | 41 ++++++++++ 3 files changed, 118 insertions(+), 4 deletions(-) diff --git a/cmd/high_opt_loss.go b/cmd/high_opt_loss.go index 4c838b8..c22cc02 100644 --- a/cmd/high_opt_loss.go +++ b/cmd/high_opt_loss.go @@ -18,9 +18,12 @@ var highOpticalLossCmd = &cobra.Command{ Short: "Generate a High Optical Loss Report", Run: func(cmd *cobra.Command, args []string) { initkit.BindFlags(cmd) - m := service.ReqGetHighOptLossList("2") + m1 := service.ReqGetHighOptLossList("2") logkit.Info("拿到大光衰数据,开始生成...") - common.GenExcelFile(m) + m2 := service.ReqGetHighOptLossSmallList("2") + logkit.Info("拿到小光衰数据,开始生成...") + common.GenExcelFile(m1) + common.GenExcelFileSmall(m2) }, } diff --git a/high-opt-loss/common/excelkit.go b/high-opt-loss/common/excelkit.go index 2d708c9..2015e05 100644 --- a/high-opt-loss/common/excelkit.go +++ b/high-opt-loss/common/excelkit.go @@ -11,7 +11,7 @@ import ( func GenExcelFile(m map[string]*service.HighOptLoss) { // Open the Excel file - f, err := excelize.OpenFile("/Users/leo/Documents/大光衰通报模板.xlsx") + f, err := excelize.OpenFile("/Users/leo/Documents/光衰通报/大光衰/2025/大光衰通报(1月10日).xlsx") if err != nil { fmt.Println(err) return @@ -73,7 +73,77 @@ func GenExcelFile(m map[string]*service.HighOptLoss) { } // Save the file - if err := f.SaveAs("/Users/leo/Documents/大光衰通报模板.xlsx"); err != nil { + if err := f.SaveAs("/Users/leo/Documents/光衰通报/大光衰/2025/大光衰通报(1月17日).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/光衰质差通报(1月10日).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 { + f.SetCellValue("汇总", "E"+strconv.Itoa(i), 0) + f.SetCellValue("汇总", "F"+strconv.Itoa(i), 0) + f.SetCellValue("汇总", "G"+strconv.Itoa(i), 0) + f.SetCellValue("汇总", "H"+strconv.Itoa(i), 0) + } + } + + // Calculate D4:D22 as C-E + for i := 4; i <= 22; i++ { + cCell := "C" + strconv.Itoa(i) + eCell := "E" + strconv.Itoa(i) + dCell := "D" + strconv.Itoa(i) + cValue, _ := f.GetCellValue("汇总", cCell) + eValue, _ := f.GetCellValue("汇总", eCell) + cInt, _ := strconv.Atoi(cValue) + eInt, _ := strconv.Atoi(eValue) + f.SetCellValue("汇总", dCell, cInt-eInt) + } + // Sum columns C:H and place the results in row 23 + for col := 'C'; col <= 'H'; col++ { + sumCell := string(col) + "23" + sumFormula := fmt.Sprintf("SUM(%s4:%s22)", string(col), string(col)) + f.SetCellFormula("汇总", sumCell, sumFormula) + } + + // Recalculate the sum for each cell to ensure it appears without manual intervention + for col := 'C'; col <= 'H'; col++ { + sumCell := string(col) + "23" + 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/光衰质差通报(1月17日).xlsx"); err != nil { fmt.Println(err) } logkit.Info("生成结束...") diff --git a/high-opt-loss/service/get_high_opt_loss_list.go b/high-opt-loss/service/get_high_opt_loss_list.go index 11a10ea..55e22a5 100644 --- a/high-opt-loss/service/get_high_opt_loss_list.go +++ b/high-opt-loss/service/get_high_opt_loss_list.go @@ -36,6 +36,47 @@ func ReqGetHighOptLossList(receiveFlag string) map[string]*HighOptLoss { data := gjson.Get(resp.String(), "list").Array() m := make(map[string]*HighOptLoss) for _, v := range data { + if v.Get("onuGreatLightDecline").String() == "否" { + //小光衰不处理 + continue + } + if m[v.Get("DEAL_MAN").String()] == nil { + m[v.Get("DEAL_MAN").String()] = &HighOptLoss{} + } + m[v.Get("DEAL_MAN").String()].Count++ + duration := v.Get("TIMELONGS").Int() + if duration >= 604800 { + m[v.Get("DEAL_MAN").String()].DurationOverSeven++ + } + if duration >= 1296000 { + m[v.Get("DEAL_MAN").String()].DurationOverFifteen++ + } + if v.Get("BOOK_TIME").String() != "" { + m[v.Get("DEAL_MAN").String()].Book++ + } + } + return m +} + +func ReqGetHighOptLossSmallList(receiveFlag string) map[string]*HighOptLoss { + h := model.NewHeader() + header := h.GenReqParam() + f := model.NewGetHighOptLossList(receiveFlag) + form := f.GenReqParam() + client := resty.New().SetRetryCount(5).SetRetryWaitTime(10 * time.Second) + resp, err := client.R(). + SetHeaders(header).SetFormData(form).Post("http://132.151.160.87:10010/wms-zj/gShuaiReply/gshuaiOrderReplyListAjax.do") + if err != nil { + panic(exception.New(err.Error())) + } + //handle光衰数据 + data := gjson.Get(resp.String(), "list").Array() + m := make(map[string]*HighOptLoss) + for _, v := range data { + if v.Get("onuGreatLightDecline").String() == "是" { + //大光衰不处理 + continue + } if m[v.Get("DEAL_MAN").String()] == nil { m[v.Get("DEAL_MAN").String()] = &HighOptLoss{} }