diff --git a/cmd/au_sim.go b/cmd/au_sim.go deleted file mode 100644 index 92f8caa..0000000 --- a/cmd/au_sim.go +++ /dev/null @@ -1,419 +0,0 @@ -//go:build legacy_au_sim - -// Deprecated: This file is no longer used. -// Retained temporarily for rollback. -// Planned removal: 2026-06-23. -package cmd - -import ( - "encoding/base64" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "regexp" - "strings" - "time" - - "github.com/go-resty/resty/v2" - "github.com/mizuki1412/go-core-kit/class/exception" - "github.com/mizuki1412/go-core-kit/init/initkit" - "github.com/mizuki1412/go-core-kit/service/logkit" - "github.com/spf13/cobra" - "github.com/tidwall/gjson" - "github.com/xuri/excelize/v2" -) - -func init() { - rootCmd.AddCommand(auSimCmd) -} - -var ( - apiKey = "oEr6D60u6mmJRPlAHEIx8dWN" - secretKey = "r7fYVHExzsqlYO9P2kgdvs5N1WVJL8vB" - imageDir = "/Users/leo/Documents/au-ocr/image/" - ocrAPIURL = "http://127.0.0.1:5005/ocr" - outputExcelPath = "/Users/leo/Documents/au-ocr/excel/" - - nameWhiteList = []string{"德宁", "鼎斌", "海波", "何晓璇", "胡鑫", "佳欣", "佳怡", "嘉乐", "建闽", "锦城", "景浩", "君豪", "凯彬", "兰青", "李想", "林艳", "刘美云", "裴雅妮", "任子健", "润宇", "隆蝶", "石明毅", "覃彩玉", "唐鑫", "唐宇豪", "童斌", "万兴凯", "王权", "吴宇峰", "武文迪", "夏晨阳", "项乐奇", "小锐", "小颖", "晓雪", "谢俊", "欣萍", "鑫杰", "徐宁", "许慧超", "雅妮", "杨传杰", "杨帅", "杨笑笑", "杨兴俊", "叶琪婷", "宇飞", "玉梅", "张钧帅", "张奕韬", "张玉", "张原硕", "章帅", "赵林冲", "郑佳欣", "朱菲玲", "子健", "邹思惠", "徐林焱", "周志乐", "林焱", "许慧超", "嘉辉", "楚俊", "军豪", "王皓", "丁磊", "吴喻飞", "秦俊杰", "俊杰", "刘继伟", "佳朴", "王浩", "游雨婷", "娅慧", "李浪", "奇乐", "张雨珈", "婧婧", "乞慧利", "郭婧婧", "王鑫", "兴凯"} - schoolWhiteList = []string{"财经", "工商", "工业", "杭电", "计量", "金融", "经济", "经贸", "科技", "理工", "美院", "万向", "长征", "浙音", "万象", "特殊教育", "外国语", "浙大紫金港", "师范", "杭职", "杭师大", "树人", "成院", "城院", "师大", "开放", "中美院", "美院", "同济", "杭科"} - amountWhiteList = []string{"200", "100", "未充值", "50"} -) - -type ExtractedInfo struct { - Name string - School string - Phone string - Amount string -} - -var auSimCmd = &cobra.Command{ - Use: "au", - Short: "Batch processing operations of the autumn semester sim card", - Run: func(cmd *cobra.Command, args []string) { - initkit.BindFlags(cmd) - files, err := ioutil.ReadDir(imageDir) - if err != nil { - panic(exception.New(err.Error())) - } - tokenBaidu := getBaiduAccessToken() - results := []ExtractedInfo{} - for _, file := range files { - if file.IsDir() || !strings.HasSuffix(file.Name(), ".jpg") || strings.Contains(file.Name(), "thumb.jpg") || strings.Contains(file.Name(), "hd.jpg") { - continue - } - fullPath := filepath.Join(imageDir, file.Name()) - base64Str, err := imageToBase64(fullPath) - if err != nil { - panic(exception.New("转base64失败:" + err.Error())) - } - //第一次调用本地的 - ocrText := callOCR(base64Str) - logkit.Info("成功调用本地OCR") - if err != nil { - panic(exception.New("OCR请求失败:" + err.Error())) - } - info := extractInfoFromOCR(ocrText, "") - //只要返回结果中存在空值的,就再调用另外的接口 - if info.Name == "" || info.Phone == "" || info.School == "" || info.Amount == "" { - ocrTextBaidu := callOCRBaidu(base64Str, tokenBaidu) - logkit.Info("¥成功调用百度OCR") - infoBaidu := extractInfoFromOCR(ocrTextBaidu, "") - //合并 - if info.Name == "" { - info.Name = infoBaidu.Name - } - if info.Phone == "" { - info.Phone = infoBaidu.Phone - } - if info.School == "" { - info.School = infoBaidu.School - } - if info.Amount == "" { - info.Amount = infoBaidu.Amount - } - } - //号码里包含了充值的这些敏感数字,就把号码从combined删除了重新再提取一次 //TODO 本地ocr识别不到 baidu能识别到? 把infoBaidu变量移出去 - if info.Phone != "" && (strings.Contains(info.Phone, "200") || strings.Contains(info.Phone, "100") || strings.Contains(info.Phone, "50")) { - infoRedo := extractInfoFromOCR(ocrText, info.Phone) - info.Amount = infoRedo.Amount - } - if info.Phone != "" && containsBroadband(ocrText) { - newName := "broadband/" + file.Name() - newPath := filepath.Join(imageDir, newName) - os.Rename(fullPath, newPath) - info.Name = info.Name + "+宽带" - logkit.Info(info.Phone + " √√√加宽带!√√√") - } - oldPath := fullPath - newName := "" - //条件放宽到识别出号码就算成功,剩下不成功的 打?手动 - if info.Phone != "" { - logkit.Info("业务员:" + info.Name + " 学校:" + info.School + " 首充:" + info.Amount + " 号码:" + info.Phone + " 识别成功!") - newName = "success/" + fmt.Sprintf("%s%s.jpg", info.Name, info.Phone) - results = append(results, info) - } else { - logkit.Info("××× 业务员:" + info.Name + " 学校:" + info.School + " 首充:" + info.Amount + " 号码:" + info.Phone + " 识别失败!") - newName = "fail/" + file.Name() + ".error.jpg" - } - - newPath := filepath.Join(imageDir, newName) - os.Rename(oldPath, newPath) - - } - - writeExcel(results, outputExcelPath+"/"+time.Now().Format("20060102150405")+".xlsx") - }, -} - -func containsBroadband(texts []string) bool { - for _, text := range texts { - if strings.Contains(text, "宽带") { - return true - } - } - return false -} - -func imageToBase64(path string) (string, error) { - data, err := os.ReadFile(path) - if err != nil { - return "", err - } - return base64.StdEncoding.EncodeToString(data), nil -} - -func callOCR(b64 string) []string { - client := resty.New() - resp, err := client.R(). - SetHeader("Content-Type", "application/json"). - SetBody(map[string]string{ - "image": b64, - }). - Post(ocrAPIURL) - - if err != nil { - panic(exception.New(err.Error())) - } - bodyStr := string(resp.Body()) - // 快速检查 resultcode 是否为 200 - if resp.StatusCode() != 200 { - panic(exception.New(fmt.Errorf("OCR failed: %s", gjson.Get(bodyStr, "message").String()).Error())) - } - // 使用 GJSON 提取所有文本字段 - var texts []string - textResults := gjson.Get(bodyStr, "results") - - if !textResults.Exists() || !textResults.IsArray() { - panic(exception.New(fmt.Errorf("no OCR results found").Error())) - } - - textResults.ForEach(func(_, value gjson.Result) bool { - text := value.Get("text").String() - if text != "" { - texts = append(texts, text) - } - return true - }) - return texts -} - -func extractInfoFromOCR(texts []string, delPhone string) ExtractedInfo { - combined := strings.Join(texts, "") - if delPhone != "" { - combined = strings.Replace(combined, delPhone, "", -1) - } - info := ExtractedInfo{} - // 提取手机号 - re := regexp.MustCompile(`(?:XH[^\x00-\xff]|H势|势|XH).*?(\d{11})`) - match := re.FindStringSubmatch(combined) - if len(match) >= 2 { - info.Phone = match[1] - } - - // 提取业务员姓名 - for _, name := range nameWhiteList { - if strings.Contains(combined, name) { - info.Name = name - context := getContext(combined, name, 30) - logkit.Info("【上下文 " + context + "】") - // 从上下文中查找学校 - for _, school := range schoolWhiteList { - if strings.Contains(context, school) { - info.School = school - break - } - } - - // 从上下文中查找金额 - for _, amount := range amountWhiteList { - if strings.Contains(context, amount) { - info.Amount = amount - break - } - } - - break - } - } - //如果到这一步业务员的名字还没找到,那么就放弃提取业务员名字上下文去找学校,改成直接全文去找学校,然后从学校获取上下文找首充 - if info.Name == "" { - for _, school := range schoolWhiteList { - if strings.Contains(combined, school) { - info.School = school - context := getContext(combined, school, 30) - // 从上下文中查找金额 - for _, amount := range amountWhiteList { - if strings.Contains(context, amount) { - info.Amount = amount - break - } - } - break - } - } - } - //如果到这一步业务员名字找到了,业务员上下文没有学校,那么还是直接全文去找学校 - if info.Name != "" && info.School == "" { - for _, school := range schoolWhiteList { - if strings.Contains(combined, school) { - info.School = school - //如果到这里首充还是空白的,试着在学校上下文找首充 - if info.Amount == "" { - context := getContext(combined, school, 30) - // 从上下文中查找金额 - for _, amount := range amountWhiteList { - if strings.Contains(context, amount) { - info.Amount = amount - break - } - } - } - break - } - } - } - - //如果到这一步充值金额还没找到,那么可以以关键字去寻找充值金额,适用于充值100,充值200,充值50这类关键词 - if info.Amount == "" { - re2 := regexp.MustCompile(`充值[::]?\s*(100|200|50)\b`) - match2 := re2.FindStringSubmatch(combined) - if len(match2) >= 2 { - info.Amount = match2[1] - } - } - //到这里要判断一下是不是压根没充值,还是没找到再去全文正则匹配纯100、200、50 - if info.Amount == "" { - if strings.Contains(combined, "未充值") { - info.Amount = "未充值" - } - } - - //如果到这一步充值金额还没找到,再通过正则去找纯100、200、50 - /* - "100", // 匹配 - "200", // 匹配 - "50", // 匹配 - "1003", // 不匹配 - "5004", // 不匹配 - "2004", // 不匹配 - "充值200", // 匹配 - "充值2004", // 不匹配 - "abc100xyz", // 匹配 - */ - if info.Amount == "" { - re3 := regexp.MustCompile(`100|200|50`) - allMatches := re3.FindAllStringIndex(combined, -1) - for _, loc := range allMatches { - start, end := loc[0], loc[1] - beforeOK := start == 0 || (combined[start-1] < '0' || combined[start-1] > '9') - afterOK := end == len(combined) || (combined[end] < '0' || combined[end] > '9') - if beforeOK && afterOK { - info.Amount = combined[start:end] - break - } - } - } - - return info -} - -func getContext(text, keyword string, length int) string { - index := strings.Index(text, keyword) - if index == -1 { - return "" - } - start := index - length - if start < 0 { - start = 0 - } - end := index + len(keyword) + length - if end > len(text) { - end = len(text) - } - return text[start:end] -} - -func writeExcel(data []ExtractedInfo, filename string) { - f := excelize.NewFile() - sheet := "Sheet1" - f.SetSheetRow(sheet, "A1", &[]string{"学校", "业务员姓名", "手机号码", "充值金额"}) - - for i, d := range data { - if d.School == "万象" { - d.School = "万向" - } - if d.School == "外国语" { - d.School = "浙外" - } - if d.School == "浙大紫金港" { - d.School = "浙大" - } - if d.School == "师范" { - d.School = "杭师" - } - if d.School == "师大" { - d.School = "杭师" - } - if d.School == "杭师大" { - d.School = "杭师" - } - if d.School == "成院" { - d.School = "城院" - } - if d.School == "中美院" { - d.School = "美院" - } - if d.Amount == "未充值" { - d.Amount = "0" - } - if d.Amount == "" { - d.Amount = "?" - } - if d.Name == "" { - d.Name = "?" - } - if d.School == "" { - d.School = "?" - } - row := []string{d.School, d.Name, d.Phone, d.Amount} - cell, _ := excelize.CoordinatesToCellName(1, i+2) - f.SetSheetRow(sheet, cell, &row) - } - - f.SaveAs(filename) -} - -func getBaiduAccessToken() string { - client := resty.New() - url := "https://aip.baidubce.com/oauth/2.0/token" - data := map[string]string{ - "grant_type": "client_credentials", - "client_id": apiKey, - "client_secret": secretKey, - } - resp, err := client.R(). - SetHeader("Content-Type", "application/x-www-form-urlencoded"). - SetFormData(data). - Post(url) - if err != nil { - panic(exception.New("获取AccessToken失败:" + err.Error())) - } - accessToken := gjson.Get(resp.String(), "access_token").String() - return accessToken -} - -func callOCRBaidu(b64, token string) []string { - url := "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=" + token - // 构造表单数据 - payload := map[string]string{ - "image": b64, - "multidirectional_recognize": "true", - } - client := resty.New() - resp, err := client.R(). - SetHeader("Content-Type", "application/x-www-form-urlencoded"). - SetHeader("Accept", "application/json"). - SetFormData(payload). - Post(url) - if err != nil { - panic(exception.New("请求百度OCR出错:" + err.Error())) - } - - // 使用 gjson 解析结果 - result := resp.String() - var texts []string - textResults := gjson.Get(result, "words_result") - - if !textResults.Exists() || !textResults.IsArray() { - panic(exception.New(fmt.Errorf("no OCR results found").Error())) - } - textResults.ForEach(func(_, value gjson.Result) bool { - text := value.Get("words").String() - if text != "" { - texts = append(texts, text) - } - return true - }) - return texts -} diff --git a/cmd/diff_fiber_box.go b/cmd/diff_fiber_box.go deleted file mode 100644 index 417e2ea..0000000 --- a/cmd/diff_fiber_box.go +++ /dev/null @@ -1,150 +0,0 @@ -//go:build legacy_dfb - -// Deprecated: This file is no longer used. -// Retained temporarily for rollback. -// Planned removal: 2026-06-23. -package cmd - -import ( - "cu-helper/internal/deprecated/wms/cryptokit" - model2 "cu-helper/internal/deprecated/wms/model" - "strings" - "time" - - "github.com/go-resty/resty/v2" - "github.com/mizuki1412/go-core-kit/class/exception" - "github.com/mizuki1412/go-core-kit/init/initkit" - "github.com/mizuki1412/go-core-kit/library/commonkit" - "github.com/mizuki1412/go-core-kit/service/configkit" - "github.com/mizuki1412/go-core-kit/service/logkit" - "github.com/spf13/cast" - "github.com/spf13/cobra" - "github.com/tidwall/gjson" - "github.com/xuri/excelize/v2" - "golang.org/x/net/html" -) - -func init() { - rootCmd.AddCommand(dfbCmd) - defFlagsDfb(dfbCmd) -} - -var dfbCmd = &cobra.Command{ - Use: "dfb", - Short: "Batch processing operations of the difficult fiber box", - Run: func(cmd *cobra.Command, args []string) { - initkit.BindFlags(cmd) - handleDfb() - }, -} - -func defFlagsDfb(cmd *cobra.Command) { - cmd.Flags().String("wms.token", "", "*Specify the token of WMS-ZJ(装维调度系统)") - cmd.Flags().String("path", "", "*Specify the file of excel") -} - -var dfbClient = resty.New().SetRetryCount(5).SetRetryWaitTime(10 * time.Second) - -func handleDfb() { - // Open the Excel file - excelPath := configkit.GetString("path", "") - if excelPath == "" { - panic(exception.New("EXCEL文件不存在或路径错误")) - } - f, err := excelize.OpenFile(excelPath) - if err != nil { - panic(exception.New(err.Error())) - } - rows, err := f.GetRows("Sheet1") - if err != nil { - panic(exception.New(err.Error())) - } - h := model2.NewHeader() - header := h.GenReqParam() - for rowIndex, row := range rows { - if rowIndex <= 1 { - continue - } - _ = commonkit.RecoverFuncWrapper(func() { - no := row[8] //宽带编号 I列 - fo := model2.NewGetOrderQueryList(no) - form := fo.GenReqParam() - logkit.Info("***开始请求*** " + no) - resp, err := dfbClient.R(). - SetHeaders(header).SetFormData(form).Post("http://132.151.160.87:10010/wms-zj/monitor/orderQueryListAjax.do") - if err != nil { - panic(exception.New(err.Error())) - } - if resp.StatusCode() != 200 { - panic(exception.New(resp.Status())) - } - totalNumber := gjson.Get(resp.String(), "pageObj.total").Int() - if totalNumber == 0 { - logkit.Error(no + " 该条记录不存在!") - return - } - list := gjson.Get(resp.String(), "list").Array() - if list[totalNumber-1].Get("ORDER_TYPE_NAME").String() == "改用户资料" { - totalNumber-- - } - if totalNumber == 0 { - logkit.Error(no + " 该条记录不存在!") - return - } - addId := list[totalNumber-1].Get("SEVEN_ADDR_ID").String() - addName := list[totalNumber-1].Get("SEVEN_ADDR").String() - woId := cryptokit.Encrypt(list[totalNumber-1].Get("WO_ID").String()) - shardingId := list[totalNumber-1].Get("SHARDING_ID").String() - resp, err = dfbClient.R(). - SetHeaders(header).SetQueryParams(map[string]string{ - "woIde": woId, - "hisFlag": "2", - "shardingId": shardingId, - }).Get("http://132.151.160.87:10010/wms-zj/common/installOrderDetailInfoQuery.do") - qrCode, gqpName := extractGQPInfo(resp.String()) - f.SetCellValue("Sheet1", "C"+cast.ToString(rowIndex+1), addId) - f.SetCellValue("Sheet1", "D"+cast.ToString(rowIndex+1), addName) - f.SetCellValue("Sheet1", "E"+cast.ToString(rowIndex+1), qrCode) - f.SetCellValue("Sheet1", "F"+cast.ToString(rowIndex+1), gqpName) - }) - } - // Save the file - if err = f.SaveAs(excelPath); err != nil { - panic(exception.New(err.Error())) - } - logkit.Info("生成结束...") -} - -// extractGQPInfo 解析 HTML 并提取光分线盒二维码和光分线盒名称 -func extractGQPInfo(htmlStr string) (qrCode, gqpName string) { - doc, err := html.Parse(strings.NewReader(htmlStr)) - if err != nil { - panic(exception.New(err.Error())) - } - var extractData func(*html.Node, string) string - extractData = func(n *html.Node, key string) string { - if n.Type == html.ElementNode && n.Data == "td" { - // 检查当前节点的文本内容是否匹配 key - if n.FirstChild != nil && n.FirstChild.Type == html.TextNode && strings.TrimSpace(n.FirstChild.Data) == key { - // 获取同一行的第三个 里的 title 属性 - if nextTd := n.NextSibling.NextSibling; nextTd != nil { - for _, attr := range nextTd.Attr { - if attr.Key == "title" { - return attr.Val - } - } - } - } - } - // 递归遍历所有子节点 - for c := n.FirstChild; c != nil; c = c.NextSibling { - if val := extractData(c, key); val != "" { - return val - } - } - return "" - } - qrCode = extractData(doc, "光分线盒二维码") - gqpName = extractData(doc, "光分线盒名称") - return -} diff --git a/cmd/gen_con_plan.go b/cmd/gen_con_plan.go deleted file mode 100644 index 6141303..0000000 --- a/cmd/gen_con_plan.go +++ /dev/null @@ -1,286 +0,0 @@ -//go:build legacy_gco - -// Deprecated: This file is no longer used. -// Retained temporarily for rollback. -// Planned removal: 2026-06-23. -package cmd - -import ( - "fmt" - "regexp" - "strconv" - "strings" - "time" - - "github.com/mizuki1412/go-core-kit/init/initkit" - "github.com/mizuki1412/go-core-kit/service/configkit" - "github.com/spf13/cobra" - "github.com/xuri/excelize/v2" -) - -func init() { - rootCmd.AddCommand(gcpCmd) - defFlagsGcp(gcpCmd) -} - -var gcpCmd = &cobra.Command{ - Use: "gcp", - Short: "Generate construction plan", - Run: func(cmd *cobra.Command, args []string) { - initkit.BindFlags(cmd) - templatePath := configkit.GetString("gcp.template", "/Users/leo/Desktop/归档/公众扩容/在途工单通报/模板.xlsx") - filePath1 := configkit.GetString("gcp.file1", "/Users/leo/Downloads/宽带在途工单进展反馈表.xlsx") - filePath2 := configkit.GetString("gcp.file2", "/Users/leo/Downloads/扩容需求表.xlsx") - _ = ProcessExcelData(filePath1, filePath2, templatePath) - }, -} - -func defFlagsGcp(cmd *cobra.Command) { - cmd.Flags().String("gcp.template", "", "*Specify the template used to generate construction plan") - cmd.Flags().String("gcp.file1", "", "*Specify the file1 used to generate construction plan") - cmd.Flags().String("gcp.file2", "", "*Specify the file2 used to generate construction plan") -} - -// ====================== 对外入口 ====================== - -func ProcessExcelData(broadbandPath string, expansionPath string, templatePath string) error { - template, err := excelize.OpenFile(templatePath) - if err != nil { - return err - } - defer template.Close() - dateFmt := "yyyy年mm月dd日" - dateStyle, err := template.NewStyle(&excelize.Style{ - CustomNumFmt: &dateFmt, - }) - if err != nil { - return err - } - templateSheet := template.GetSheetName(0) - writeRow := 2 // 模板从第2行写 - today := time.Now() - - // ---------------- 宽带在途工单 ---------------- - if err := processBroadband(template, templateSheet, broadbandPath, &writeRow, today, dateStyle); err != nil { - return err - } - - // ---------------- 扩容需求表 ---------------- - if err := processExpansion(template, templateSheet, expansionPath, &writeRow, today, dateStyle); err != nil { - return err - } - filename := time.Now().Format("20060102") + ".xlsx" - return template.SaveAs("/Users/leo/Desktop/归档/公众扩容/在途工单通报/通报表格/" + filename) -} - -// ====================== 宽带在途 ====================== - -func processBroadband(template *excelize.File, templateSheet string, path string, writeRow *int, today time.Time, dateStyle int) error { - - f, err := excelize.OpenFile(path) - if err != nil { - return err - } - defer f.Close() - - sheet := f.GetSheetName(0) - rows, err := f.GetRows(sheet) - if err != nil { - return err - } - - reDay := regexp.MustCompile(`(\d+)`) - - for i := 1; i < len(rows); i++ { - row := rows[i] - - // A列 == 西湖 - if getCell(row, 0) != "西湖" { - continue - } - // O列 == 需建设处理 - if getCell(row, 14) != "需建设处理" { - continue - } - - // D列 → 地址 - address := getCell(row, 3) - if address == "" { - continue - } - - // H列 → 填报日期 - dateStr, err := f.GetCellValue(sheet, fmt.Sprintf("H%d", i+1)) - if err != nil || dateStr == "" { - continue - } - reportTime, err := parseExcelTime(dateStr) - if err != nil { - continue - } - // 写模板 - template.SetCellValue(templateSheet, fmt.Sprintf("A%d", *writeRow), address) - template.SetCellValue(templateSheet, fmt.Sprintf("F%d", *writeRow), reportTime) - template.SetCellStyle( - templateSheet, - fmt.Sprintf("F%d", *writeRow), - fmt.Sprintf("F%d", *writeRow), - dateStyle, - ) - // S列:X日通 - colS := getCell(row, 18) - if m := reDay.FindStringSubmatch(colS); len(m) == 2 { - days, _ := strconv.Atoi(m[1]) - - // C列:几日通 - template.SetCellValue(templateSheet, fmt.Sprintf("C%d", *writeRow), days) - - // D列:需完成日期 - finishDate := reportTime.AddDate(0, 0, days) - template.SetCellValue(templateSheet, fmt.Sprintf("D%d", *writeRow), finishDate) - template.SetCellStyle( - templateSheet, - fmt.Sprintf("D%d", *writeRow), - fmt.Sprintf("D%d", *writeRow), - dateStyle, - ) - // E列:是否超时 - if today.After(finishDate) { - template.SetCellValue(templateSheet, fmt.Sprintf("E%d", *writeRow), "是") - } else { - template.SetCellValue(templateSheet, fmt.Sprintf("E%d", *writeRow), "否") - } - } - - // G列:工单历时 - duration := int(today.Sub(reportTime).Hours() / 24) - if duration < 0 { - duration = 0 - } - template.SetCellValue(templateSheet, fmt.Sprintf("G%d", *writeRow), duration) - - *writeRow++ - } - - return nil -} - -// ====================== 扩容需求 ====================== - -func processExpansion(template *excelize.File, templateSheet string, path string, writeRow *int, today time.Time, dateStyle int) error { - - f, err := excelize.OpenFile(path) - if err != nil { - return err - } - defer f.Close() - - sheet := f.GetSheetName(0) - rows, err := f.GetRows(sheet) - if err != nil { - return err - } - - for i := 1; i < len(rows); i++ { - row := rows[i] - - // P列为空 - if strings.TrimSpace(getCell(row, 15)) != "" { - continue - } - // X列 == 1 - if getCell(row, 23) != "1" { - continue - } - - //D列 → 地址 - address := getCell(row, 3) - if address == "" { - continue - } - - // N列 → 填报日期 - dateStr, err := f.GetCellValue(sheet, fmt.Sprintf("N%d", i+1)) - if err != nil || dateStr == "" { - continue - } - - reportTime, err := parseExcelTime(dateStr) - if err != nil { - continue - } - - template.SetCellValue(templateSheet, fmt.Sprintf("A%d", *writeRow), address) - template.SetCellValue(templateSheet, fmt.Sprintf("F%d", *writeRow), reportTime) - template.SetCellStyle( - templateSheet, - fmt.Sprintf("F%d", *writeRow), - fmt.Sprintf("F%d", *writeRow), - dateStyle, - ) - // G列:工单历时 - duration := int(today.Sub(reportTime).Hours() / 24) - if duration < 0 { - duration = 0 - } - template.SetCellValue(templateSheet, fmt.Sprintf("G%d", *writeRow), duration) - - *writeRow++ - } - - return nil -} - -// ====================== 工具函数 ====================== - -func parseExcelTime(val string) (time.Time, error) { - val = strings.TrimSpace(val) - if val == "" { - return time.Time{}, fmt.Errorf("empty time") - } - - // 1️⃣ Excel 原生数值(最优先) - if f, err := strconv.ParseFloat(val, 64); err == nil { - return excelize.ExcelDateToTime(f, false) - } - - // 2️⃣ 中文日期:11月23日 / 11月23号 - reCN := regexp.MustCompile(`^(\d{1,2})月(\d{1,2})([日号])?$`) - if m := reCN.FindStringSubmatch(val); len(m) > 0 { - month, _ := strconv.Atoi(m[1]) - day, _ := strconv.Atoi(m[2]) - //todo - year := 0 - if month >= 11 { - year = 2025 // 默认用当前年 - } - year = time.Now().Year() // 默认用当前年 - return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local), nil - } - - // 3️⃣ 常见字符串格式 - layouts := []string{ - "2006-01-02", - "2006/01/02", - "2006-01-02 15:04", - "2006/01/02 15:04", - "2006-01-02 15:04:05", - "2006/01/02 15:04:05", - } - - for _, layout := range layouts { - if t, err := time.ParseInLocation(layout, val, time.Local); err == nil { - return t, nil - } - } - - return time.Time{}, fmt.Errorf("cannot parse time: %s", val) -} - -// 安全取单元格 -func getCell(row []string, idx int) string { - if idx >= len(row) { - return "" - } - return strings.TrimSpace(row[idx]) -} diff --git a/cmd/high_opt_loss.go b/cmd/high_opt_loss.go deleted file mode 100644 index bd0f50b..0000000 --- a/cmd/high_opt_loss.go +++ /dev/null @@ -1,36 +0,0 @@ -//go:build legacy_loss - -// Deprecated: This file is no longer used. -// Retained temporarily for rollback. -// Planned removal: 2026-06-23. -package cmd - -import ( - "cu-helper/internal/deprecated/wms/common" - "cu-helper/internal/deprecated/wms/service" - - "github.com/mizuki1412/go-core-kit/init/initkit" - "github.com/mizuki1412/go-core-kit/service/logkit" - "github.com/spf13/cobra" -) - -func init() { - rootCmd.AddCommand(highOpticalLossCmd) - defFlagsLoss(highOpticalLossCmd) -} - -var highOpticalLossCmd = &cobra.Command{ - Use: "loss", - Short: "Generate a High Optical Loss Report", - Run: func(cmd *cobra.Command, args []string) { - initkit.BindFlags(cmd) - m1 := service.ReqGetHighOptLossUnderList() - logkit.Info("拿到光衰数据,开始生成...") - common.GenExcelFile(m1) - }, -} - -func defFlagsLoss(cmd *cobra.Command) { - cmd.Flags().String("wms.token", "", "*Specify the token of WMS-ZJ(装维调度系统)") - cmd.Flags().String("loss.open", "", "*Specify the file of excel to open") -} diff --git a/cmd/law_plat.go b/cmd/law_plat.go deleted file mode 100644 index 804021d..0000000 --- a/cmd/law_plat.go +++ /dev/null @@ -1,113 +0,0 @@ -//go:build legacy_law - -// Deprecated: This file is no longer used. -// Retained temporarily for rollback. -// Planned removal: 2026-06-23. -package cmd - -import ( - "net/url" - "strings" - "time" - - "github.com/go-resty/resty/v2" - "github.com/mizuki1412/go-core-kit/class/exception" - "github.com/mizuki1412/go-core-kit/init/initkit" - "github.com/mizuki1412/go-core-kit/service/configkit" - "github.com/mizuki1412/go-core-kit/service/logkit" - "github.com/spf13/cast" - "github.com/spf13/cobra" - "github.com/tidwall/gjson" -) - -//法治在沃 - -func init() { - rootCmd.AddCommand(lawCmd) - defFlagsLaw(lawCmd) -} - -var lawCmd = &cobra.Command{ - Use: "law", - Short: "Batch processing operations of the law platform", - Run: func(cmd *cobra.Command, args []string) { - initkit.BindFlags(cmd) - handleLaw() - }, -} - -func defFlagsLaw(cmd *cobra.Command) { - cmd.Flags().String("cookie", "", "*Specify the cookie") -} - -var lawClient = resty.New().SetRetryCount(5).SetRetryWaitTime(10 * time.Second) - -func handleLaw() { - resp, err := lawClient.R(). - SetHeaders(map[string]string{ - "Content-type": "application/x-www-form-urlencoded; charset=UTF-8", - "Cookie": cast.ToString(configkit.Get("cookie", "")), - }).SetFormData(map[string]string{ - "pid": "0", - }).Post("http://lawplatform.unicom.local/law/tpubTreeMenu/getMenuByRole.do") - if err != nil || resp.IsError() || gjson.Get(resp.String(), "ok").Bool() != true { - panic(exception.New("获取菜单失败")) - } - data := gjson.Get(resp.String(), "data.menuList").Array() - for _, v := range data { - for _, vv := range gjson.Get(v.String(), "chirlds").Array() { - for _, vvv := range gjson.Get(vv.String(), "chirlds").Array() { - rawURL := gjson.Get(vvv.String(), "tpubTreeMenuUrl").String() - resp, err = lawClient.R(). - SetHeaders(map[string]string{ - "Content-type": "application/x-www-form-urlencoded; charset=UTF-8", - "Cookie": cast.ToString(configkit.Get("cookie", "")), - }).SetFormData(map[string]string{ - "page": "1", - "pageSize": "1000", - }).Post(getUrl(rawURL)) - if err != nil || resp.IsError() || resp.StatusCode() != 200 { - panic(exception.New("获取文章列表失败")) - } - articleData := gjson.Get(resp.String(), "data").Array() - for _, a := range articleData { - infoId := gjson.Get(a.String(), "infoId").String() - creatorTime := gjson.Get(a.String(), "creatorTime").String() - //TODO 以后每年修改这个 - if !strings.Contains(creatorTime, "2024") { - logkit.Info("非2024文章,跳过...") - continue - } - resp, err = lawClient.R(). - SetHeaders(map[string]string{ - "Content-type": "application/x-www-form-urlencoded; charset=UTF-8", - "Cookie": cast.ToString(configkit.Get("cookie", "")), - }).SetFormData(map[string]string{ - "infoId": infoId, - }).Post("http://lawplatform.unicom.local/law/tpfLike/toLike.do") - if err != nil || resp.IsError() || resp.StatusCode() != 200 { - panic(exception.New("点赞失败")) - } else { - time.Sleep(1 * time.Second) - logkit.Info("点赞成功~") - } - } - } - } - - } -} - -func getUrl(rawURL string) string { - // 解析 URL - u, err := url.Parse(rawURL) - if err != nil { - panic(exception.New("解析URL失败")) - } - // 提取查询参数 - queryParams := u.Query() - // 获取 pftype 的值 - pfType := queryParams.Get("pftype") - uri := "http://lawplatform.unicom.local/law/tpfInfoQuery/findPfInfoList.do?pftype=" + pfType + "&pfsortLevel=3&cache_id=" + cast.ToString(time.Now().UnixMilli()) - return uri -} diff --git a/cmd/test.go b/cmd/test.go index e16fb61..5f3a953 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -1,17 +1,7 @@ package cmd import ( - "fmt" - "log" - "strconv" - "time" - - "github.com/mizuki1412/go-core-kit/class/exception" - "github.com/mizuki1412/go-core-kit/service/logkit" - "github.com/spf13/cast" "github.com/spf13/cobra" - "github.com/tidwall/gjson" - "github.com/xuri/excelize/v2" ) func init() { @@ -25,138 +15,3 @@ var testCmd = &cobra.Command{ }, } - -func extractColumnsLoss() { - // 打开 Excel 文件 - f, err := excelize.OpenFile("/Users/leo/Documents/竣工与调度光衰单 (21).xlsx") - if err != nil { - log.Fatal(err) - } - - // 获取表格的所有行 - rows, err := f.GetRows("{worksheet}") // 假设表格在"{worksheet}"中 - if err != nil { - log.Fatal(err) - } - - // 创建一个二维数组来存储提取的数据 - var data []string - - // 遍历每一行,提取 A, C, BH 列的数据 - for i, row := range rows { - // 跳过表头 - if i == 0 { - continue - } - // 获取 AO 列的数据 - if len(row) > 40 { - data = append(data, row[40]) // AC列 - } - } - for i, row := range data { - resp, err := lawClient.R(). - SetHeaders(map[string]string{ - "Authorization": "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIxNTY1NzE3NTEyNCIsInVzZXJJZCI6IjE2NjUiLCJuYW1lIjoi6K646ZyW5Y2TIiwiZXhwIjoxNzYxOTE2NTAwLCJuYmYiOjE3NjE4OTg1MDB9.DBqqShxxp5dwLrKYzuKFneRnqQub5V5ocbwFSAa5DvmHww3iWWAHLRD9bPkoE20CSDqcVjOj2MjkttaT3EarYqVhPxTdXtS0rddWTZaRDiMkO5GOFRvdlb-404h2YCUtxoubM0033v9jBKF_VgjMphUo_w8VjizqzcouucBlNtE", - "Content-type": "application/json;charset=UTF-8", - "Cookie": "Admin-Token=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIxNTY1NzE3NTEyNCIsInVzZXJJZCI6IjE2NjUiLCJuYW1lIjoi6K646ZyW5Y2TIiwiZXhwIjoxNzYxOTE2NTAwLCJuYmYiOjE3NjE4OTg1MDB9.DBqqShxxp5dwLrKYzuKFneRnqQub5V5ocbwFSAa5DvmHww3iWWAHLRD9bPkoE20CSDqcVjOj2MjkttaT3EarYqVhPxTdXtS0rddWTZaRDiMkO5GOFRvdlb-404h2YCUtxoubM0033v9jBKF_VgjMphUo_w8VjizqzcouucBlNtE; sysName=%E8%AE%B8%E9%9C%96%E5%8D%93", - }).SetBody(map[string]interface{}{ - "endTime": cast.ToString(time.Now().Format("2006-01-02")), - "eqpLoid": row, - "limit": "10", - "page": 1, - "startTime": cast.ToString(time.Now().AddDate(0, 0, -4).Format("2006-01-02")), - "userName": "许霖卓", - }).Post("http://10.20.219.85:9527/api/view/onuCon/queryOnuInfoList") - if err != nil || resp.IsError() || resp.StatusCode() != 200 { - fmt.Println(err) - } else { - res := gjson.Get(resp.String(), "data.rows").Array() - if len(res) > 0 { - f.SetCellValue("{worksheet}", "AZ"+strconv.Itoa(i+2), res[0].Get("onu_rx_power").String()) - } - if len(res) > 1 { - f.SetCellValue("{worksheet}", "BA"+strconv.Itoa(i+2), res[1].Get("onu_rx_power").String()) - } - if len(res) > 2 { - f.SetCellValue("{worksheet}", "BB"+strconv.Itoa(i+2), res[2].Get("onu_rx_power").String()) - } - if len(res) > 3 { - f.SetCellValue("{worksheet}", "BC"+strconv.Itoa(i+2), res[3].Get("onu_rx_power").String()) - } - if len(res) > 4 { - f.SetCellValue("{worksheet}", "BD"+strconv.Itoa(i+2), res[4].Get("onu_rx_power").String()) - } - } - } - if err := f.SaveAs("/Users/leo/Documents/竣工与调度光衰单 (21).xlsx"); err != nil { - fmt.Println(err) - } - logkit.Info("生成结束...") -} - -func extractColumns() { - // 打开 Excel 文件 - f, err := excelize.OpenFile("/Users/leo/Documents/副本电子围栏---林斌1.16.xlsx") - if err != nil { - log.Fatal(err) - } - - // 获取表格的所有行 - rows, err := f.GetRows("李强") // 假设表格在"Sheet1"中 - if err != nil { - log.Fatal(err) - } - - // 创建一个二维数组来存储提取的数据 - var data [][]string - - // 遍历每一行,提取 A, C, BH 列的数据 - for i, row := range rows { - // 跳过表头 - if i == 0 { - continue - } - - // 获取 A, C, BH 列的数据 - var rowData []string - if len(row) > 0 { - rowData = append(rowData, row[0]) // A列 - } - if len(row) > 2 { - rowData = append(rowData, row[2]) // C列 - } - if len(row) > 28 { - rowData = append(rowData, row[28]) // AC列 - } - - // 将这一行数据添加到二维数组中 - if len(rowData) > 0 { - data = append(data, rowData) - } - } - - // 输出提取的数据 - for _, row := range data { - fmt.Println(row) - resp, err := lawClient.R(). - SetHeaders(map[string]string{ - "Authorization": "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIxNTY1NzE3NjI2OSIsInVzZXJJZCI6IjEwMTUiLCJuYW1lIjoi6a2P5beN5beNIiwiZXhwIjoxNzM3MDI1MDc1LCJuYmYiOjE3MzcwMDcwNzV9.TG-Bk0CbwzavOl1RKszTDVYrBEZUoyY8EhXAS_Q8HRkJj_CyzPj_SfAc2sJnejarxh4hfVK0FkIU6GiVPMm67OhKUQCN1FnBWspXNFihIdnsaS9WDB4o_BCI16gV5dUxEQ3TjL3Ok4vMBnzk0rPdQJmU-3DphCmo7f_AS6BM46s", - "Content-type": "application/json;charset=UTF-8", - "Cookie": "Admin-Token=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIxNTY1NzE3NjI2OSIsInVzZXJJZCI6IjEwMTUiLCJuYW1lIjoi6a2P5beN5beNIiwiZXhwIjoxNzM3MDI1MDc1LCJuYmYiOjE3MzcwMDcwNzV9.TG-Bk0CbwzavOl1RKszTDVYrBEZUoyY8EhXAS_Q8HRkJj_CyzPj_SfAc2sJnejarxh4hfVK0FkIU6GiVPMm67OhKUQCN1FnBWspXNFihIdnsaS9WDB4o_BCI16gV5dUxEQ3TjL3Ok4vMBnzk0rPdQJmU-3DphCmo7f_AS6BM46s; sysName=%E9%AD%8F%E5%B7%8D%E5%B7%8D", - }).SetBody(map[string]interface{}{ - "dzwlCode": row[2], - "dzwlId": cast.ToInt64(row[0]), - "remarks": "其他", - "sevenAddrId": row[1], - "userId": "15657176269", - "zprName": "林斌", - "zprPhone": "15657178035", - }).Post("http://10.20.219.85:9527/api/resourceView/dzwl/updDzwlZpr") - if err != nil || resp.IsError() || resp.StatusCode() != 200 { - fmt.Println(err) - panic(exception.New("失败" + row[1])) - } else { - fmt.Println("ok" + row[1] + resp.String()) - } - } -} diff --git a/internal/deprecated/wms/common/excelkit.go b/internal/deprecated/wms/common/excelkit.go deleted file mode 100644 index fff7aff..0000000 --- a/internal/deprecated/wms/common/excelkit.go +++ /dev/null @@ -1,206 +0,0 @@ -package common - -import ( - "cu-helper/internal/deprecated/wms/service" - "fmt" - "path/filepath" - "strconv" - "time" - - "github.com/mizuki1412/go-core-kit/service/configkit" - "github.com/mizuki1412/go-core-kit/service/logkit" - "github.com/spf13/cast" - "github.com/xuri/excelize/v2" -) - -func GenExcelFile(m1 map[string]*service.HighOptLossUnder) { - // Open the Excel file - open := configkit.GetString("loss.open", "") - if open == "" { - open = "/Users/leo/Documents/光衰通报/光衰/2025/光衰通报(11月5日).xlsx" - } - f, err := excelize.OpenFile(open) - if err != nil { - fmt.Println(err) - 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, - }, - }) - 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, - }, - }) - - // Cut and paste data from E4:E25 to C4:C25 - //TODO - for i := 4; i <= 25; 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:L25 with data from the map - //TODO - for i := 4; i <= 25; i++ { - bCell := "B" + strconv.Itoa(i) - key, _ := f.GetCellValue("汇总", bCell) - if data, ok := m1[key]; ok { - 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) - 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) - 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("汇总", "I"+strconv.Itoa(i), data.ApplyCount) - } else { - 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.SetCellStyle("汇总", "F"+strconv.Itoa(i), "F"+strconv.Itoa(i), styleGreen) - 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("汇总", "I"+strconv.Itoa(i), 0) - } - } - - // Calculate D4:D25 as C-E - //TODO - for i := 4; i <= 25; 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) - 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:I and place the results in row 26 - for col := 'C'; col <= 'I'; col++ { - //TODO - sumCell := string(col) + "26" - //TODO - sumFormula := fmt.Sprintf("SUM(%s4:%s25)", 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 <= 'I'; col++ { - //TODO - sumCell := string(col) + "26" - value, err := f.CalcCellValue("汇总", sumCell) - if err != nil { - fmt.Println(err) - } else { - f.SetCellValue("汇总", sumCell, cast.ToInt(value)) - } - } - //设置表头 - content := fmt.Sprintf("西湖智家光衰通报:%s", time.Now().Format("1月2日")) - f.SetCellValue("汇总", "A1", content) - - // Save the file - save := filepath.Dir(open) + "/光衰通报(" + time.Now().Format("1月2日") + ").xlsx" - if err := f.SaveAs(save); err != nil { - fmt.Println(err) - } - logkit.Info("生成结束...") -} diff --git a/internal/deprecated/wms/cryptokit/crypto.go b/internal/deprecated/wms/cryptokit/crypto.go deleted file mode 100644 index 41a6253..0000000 --- a/internal/deprecated/wms/cryptokit/crypto.go +++ /dev/null @@ -1,34 +0,0 @@ -package cryptokit - -import ( - "bytes" - "crypto/aes" - "crypto/cipher" - "encoding/base64" - - "github.com/mizuki1412/go-core-kit/class/exception" -) - -// Encrypt 实现 AES-CBC 加密(返回 Base64 编码结果) -func Encrypt(plainText string) string { - key := "1234567890123456" - iv := "1234567890123456" - block, err := aes.NewCipher([]byte(key)) - if err != nil { - panic(exception.New(err.Error())) - } - // PKCS7 填充 - paddedText := pkcs7Padding([]byte(plainText), block.BlockSize()) - // CBC 模式加密 - blockMode := cipher.NewCBCEncrypter(block, []byte(iv)) - ciphertext := make([]byte, len(paddedText)) - blockMode.CryptBlocks(ciphertext, paddedText) - // Base64 编码 - return base64.StdEncoding.EncodeToString(ciphertext) -} - -func pkcs7Padding(ciphertext []byte, blockSize int) []byte { - padding := blockSize - len(ciphertext)%blockSize - padtext := bytes.Repeat([]byte{byte(padding)}, padding) - return append(ciphertext, padtext...) -} diff --git a/internal/deprecated/wms/model/get_high_opt_loss_under_list.go b/internal/deprecated/wms/model/get_high_opt_loss_under_list.go deleted file mode 100644 index 826c3cd..0000000 --- a/internal/deprecated/wms/model/get_high_opt_loss_under_list.go +++ /dev/null @@ -1,58 +0,0 @@ -package model - -import ( - "reflect" -) - -/* -http://132.151.160.87:10010/wms-zj/gshuaiOrderQueryW/getOrderInfo.do -*/ - -/* -用途:获取光衰在途数据列表(包含施工中、人工回访、综合调度等全部未归档状态) -*/ - -type GetHighOptLossUnderList struct { - OrgId string `map:"orgId"` - BookFlag string `map:"bookFlag"` - OrderParam string `map:"orderparam"` - OrderDesc string `map:"orderDesc"` - ReceiveFlag string `map:"receiveFlag"` - Rows string `map:"rows"` - Page string `map:"page"` - QueryType string `map:"queryType"` -} - -func NewGetHighOptLossUnderList() *GetHighOptLossUnderList { - getHighOptLossUnderList := new(GetHighOptLossUnderList) - getHighOptLossUnderList.OrgId = "330106" - getHighOptLossUnderList.BookFlag = "-1" - getHighOptLossUnderList.OrderParam = "ACCEPT_TIME" - getHighOptLossUnderList.OrderDesc = "DESC" - getHighOptLossUnderList.ReceiveFlag = "0" - getHighOptLossUnderList.Rows = "10000" - getHighOptLossUnderList.Page = "1" - getHighOptLossUnderList.QueryType = "-1" - return getHighOptLossUnderList -} - -func (th *GetHighOptLossUnderList) GenReqParam() map[string]string { - return th.structToMap() -} - -func (th *GetHighOptLossUnderList) structToMap() map[string]string { - result := make(map[string]string) - t := reflect.TypeOf(*th) - v := reflect.ValueOf(*th) - for i := 0; i < t.NumField(); i++ { - field := t.Field(i) - value := v.Field(i) - // Use the tag value as the key in the map, if it exists; otherwise, use the field name. - tag := field.Tag.Get("map") - if tag == "" { - tag = field.Name - } - result[tag] = value.String() - } - return result -} diff --git a/internal/deprecated/wms/model/get_order_query_list.go b/internal/deprecated/wms/model/get_order_query_list.go deleted file mode 100644 index dcb3d06..0000000 --- a/internal/deprecated/wms/model/get_order_query_list.go +++ /dev/null @@ -1,66 +0,0 @@ -package model - -import "reflect" - -/* -http://132.151.160.87:10010/wms-zj/monitor/orderQueryListAjax.do -*/ - -/* -用途:宽带装机工单查询 -*/ - -type GetOrderQueryList struct { - Page string `map:"page"` - Rows string `map:"rows"` - OrgId string `map:"orgId"` - BusiNo string `map:"busiNo"` - BusiType string `map:"busiType"` - QueryFlag string `map:"queryFlag"` - OrdStatus string `map:"ordStatus"` - ParallelFlag string `map:"parallelFlag"` - QueryType string `map:"queryType"` - QueryValue string `map:"queryValue"` - ProdClass string `map:"prodClass"` - DelFlag string `map:"delFlag"` - IsCurrentArchive string `map:"isCurrentArchive"` //非当日报竣=2 当日报竣=1 -} - -func NewGetOrderQueryList(no string) *GetOrderQueryList { - return &GetOrderQueryList{ - Page: "1", - Rows: "10", - OrgId: "330106", //西湖=330106 萧山=330109 - BusiNo: no, - BusiType: "1", - QueryFlag: "2", - OrdStatus: "0", - ParallelFlag: "0", - QueryType: "0", - QueryValue: no, - ProdClass: "-1", - DelFlag: "-1", - IsCurrentArchive: "2", - } -} - -func (th *GetOrderQueryList) GenReqParam() map[string]string { - return th.structToMap() -} - -func (th *GetOrderQueryList) structToMap() map[string]string { - result := make(map[string]string) - t := reflect.TypeOf(*th) - v := reflect.ValueOf(*th) - for i := 0; i < t.NumField(); i++ { - field := t.Field(i) - value := v.Field(i) - // Use the tag value as the key in the map, if it exists; otherwise, use the field name. - tag := field.Tag.Get("map") - if tag == "" { - tag = field.Name - } - result[tag] = value.String() - } - return result -} diff --git a/internal/deprecated/wms/model/request_header.go b/internal/deprecated/wms/model/request_header.go deleted file mode 100644 index 0001c0f..0000000 --- a/internal/deprecated/wms/model/request_header.go +++ /dev/null @@ -1,43 +0,0 @@ -package model - -import ( - "reflect" - - "github.com/mizuki1412/go-core-kit/service/configkit" -) - -// Header WMS-ZJ通用Header -type Header struct { - ContentType string `map:"Content-Type"` - Cookie string `map:"Cookie"` - UserAgent string `map:"User-Agent"` -} - -func NewHeader() *Header { - header := new(Header) - header.ContentType = "application/x-www-form-urlencoded; charset=UTF-8" - header.Cookie = "JSESSIONID=" + configkit.GetString("wms.token", "") - header.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" - return header -} - -func (th *Header) GenReqParam() map[string]string { - return th.structToMap() -} - -func (th *Header) structToMap() map[string]string { - result := make(map[string]string) - t := reflect.TypeOf(*th) - v := reflect.ValueOf(*th) - for i := 0; i < t.NumField(); i++ { - field := t.Field(i) - value := v.Field(i) - // Use the tag value as the key in the map, if it exists; otherwise, use the field name. - tag := field.Tag.Get("map") - if tag == "" { - tag = field.Name - } - result[tag] = value.String() - } - return result -} diff --git a/internal/deprecated/wms/service/get_high_opt_loss_list.go b/internal/deprecated/wms/service/get_high_opt_loss_list.go deleted file mode 100644 index 75edb8a..0000000 --- a/internal/deprecated/wms/service/get_high_opt_loss_list.go +++ /dev/null @@ -1,61 +0,0 @@ -package service - -import ( - model2 "cu-helper/internal/deprecated/wms/model" - "time" - - "github.com/go-resty/resty/v2" - "github.com/mizuki1412/go-core-kit/class/exception" - "github.com/tidwall/gjson" -) - -//获取光衰数据列表 - -// HighOptLossUnder 在途光衰单 -type HighOptLossUnder struct { - Count int //所有在途单 - UnderCount int //施工中在途单 - ApplyCount int //人工回访在途单 - DurationOverSeven int - DurationOverFifteen int - Book int -} - -// ReqGetHighOptLossUnderList 查询在途光衰单(包含施工中、人工回访、综合调度等全部未归档状态) -func ReqGetHighOptLossUnderList() map[string]*HighOptLossUnder { - h := model2.NewHeader() - header := h.GenReqParam() - f := model2.NewGetHighOptLossUnderList() - 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())) - } - data := gjson.Get(resp.String(), "list").Array() - m := make(map[string]*HighOptLossUnder) - for _, v := range data { - if m[v.Get("DEAL_MAN").String()] == nil { - m[v.Get("DEAL_MAN").String()] = &HighOptLossUnder{} - } - m[v.Get("DEAL_MAN").String()].Count++ - if v.Get("STATUS_NAME").String() == "施工处理" { - m[v.Get("DEAL_MAN").String()].UnderCount++ - 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++ - } - } - if v.Get("STATUS_NAME").String() == "人工回访" { - m[v.Get("DEAL_MAN").String()].ApplyCount++ - } - } - return m -}