feature: init high_opt_loss

main
Leo 1 year ago
parent d71be599b8
commit b74c01e08a

@ -28,7 +28,7 @@ var engSysCmd = &cobra.Command{
}
func run(c *config.Config) {
j, _ := filekit.ReadString("testo.json")
j, _ := filekit.ReadString("test1.json")
data := gjson.Get(j, "data").Array()
for _, v := range data {
name := v.Get("name").String()
@ -36,8 +36,8 @@ func run(c *config.Config) {
if name == c.Step && process == c.Process {
logkit.Info("***现在开始处理***:" + gjson.Get(v.String(), "tasktitle").String())
_ = commonkit.RecoverFuncWrapper(func() {
//service.ReqAccConfirm(v.Get("processInstanceId").String(), v.Get("id").String())
service.ReqWithdrawAssign(v.Get("processInstanceId").String())
service.ReqAccConfirm(v.Get("processInstanceId").String(), v.Get("id").String())
//service.ReqWithdrawAssign(v.Get("processInstanceId").String())
//service.ReqAccDelivery(v.Get("processInstanceId").String(), v.Get("id").String())
})
time.Sleep(1 * time.Second)

@ -1,8 +1,10 @@
package cmd
import (
"cu-helper/high-opt-loss/common"
"cu-helper/high-opt-loss/service"
"github.com/mizuki1412/go-core-kit/init/initkit"
"github.com/mizuki1412/go-core-kit/service/logkit"
"github.com/spf13/cobra"
)
@ -16,8 +18,9 @@ var highOpticalLossCmd = &cobra.Command{
Short: "Generate a High Optical Loss Report",
Run: func(cmd *cobra.Command, args []string) {
initkit.BindFlags(cmd)
service.ReqGetHighOptLossList("1")
m := service.ReqGetHighOptLossList("2")
logkit.Info("拿到大光衰数据,开始生成...")
common.GenExcelFile(m)
},
}

@ -0,0 +1,80 @@
package common
import (
"cu-helper/high-opt-loss/service"
"fmt"
"github.com/mizuki1412/go-core-kit/service/logkit"
"github.com/spf13/cast"
"github.com/xuri/excelize/v2"
"strconv"
)
func GenExcelFile(m map[string]*service.HighOptLoss) {
// Open the Excel file
f, err := excelize.OpenFile("/Users/leo/Documents/大光衰通报模板.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/大光衰通报模板.xlsx"); err != nil {
fmt.Println(err)
}
logkit.Info("生成结束...")
}

@ -2,18 +2,28 @@ package service
import (
"cu-helper/high-opt-loss/model"
"fmt"
"github.com/go-resty/resty/v2"
"github.com/mizuki1412/go-core-kit/class/exception"
"github.com/tidwall/gjson"
"time"
)
//获取光衰数据列表
func ReqGetHighOptLossList(receiveFlag string) {
type HighOptLoss struct {
Count int
CountFlag int //1绿色,2黄色,3红色
DurationOverSeven int
DurationOverSevenFlag int //1绿色,2黄色,3红色
DurationOverFifteen int
DurationOverFifteenFlag int //1绿色,2黄色,3红色
Book int
BookFlag int //1绿色,2黄色,3红色
}
func ReqGetHighOptLossList(receiveFlag string) map[string]*HighOptLoss {
h := model.NewHeader()
header := h.GenReqParam()
fmt.Println(header)
f := model.NewGetHighOptLossList(receiveFlag)
form := f.GenReqParam()
client := resty.New().SetRetryCount(5).SetRetryWaitTime(10 * time.Second)
@ -22,5 +32,24 @@ func ReqGetHighOptLossList(receiveFlag string) {
if err != nil {
panic(exception.New(err.Error()))
}
fmt.Println(resp.String())
//handle光衰数据
data := gjson.Get(resp.String(), "list").Array()
m := make(map[string]*HighOptLoss)
for _, v := range data {
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
}

Loading…
Cancel
Save