dev
Administrator 2024-05-20 01:00:09 +08:00
parent 9b88c718d9
commit 4198afe015
18 changed files with 324 additions and 231 deletions

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM centos:7
USER root
ENV TZ=Asia/Shanghai
COPY aiweek /usr/local/bin/ \
./option/option.yaml /conf/
RUN chmod +x /usr/local/bin/aiweek && mkdir /data /conf
ENTRYPOINT ["aiweek"]
CMD ["--livemode=false"]

View File

@ -1,6 +1,7 @@
package aichat
import (
"aiweek/option"
"bytes"
"fmt"
"github.com/tidwall/gjson"
@ -15,23 +16,18 @@ type KimiResp string
type AiReq struct {
token string
body string
url string
}
const token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyLWNlbnRlciIsImV4cCI6MTcyMzYyMTk1NywiaWF0IjoxNzE1ODQ1OTU3LCJqdGkiOiJjcDJybWg5a3FxNGxraGNqbTVtZyIsInR5cCI6InJlZnJlc2giLCJzdWIiOiJjbzU4anJxbG5sOTZlanF1czVnMCIsInNwYWNlX2lkIjoiY281OGpycWxubDk2ZWpxdXM1ZmciLCJhYnN0cmFjdF91c2VyX2lkIjoiY281OGpycWxubDk2ZWpxdXM1ZjAifQ.WNq2OH5egQKlnnuM4ygY2MjjmgsjhEOwHJdV7oQA66_mrHgGKluilcBuMZ5dMpClpAOnVY6wJ021dYHajzuInQ"
func NewAiReq(url string) *AiReq {
body := fmt.Sprintf("{\"model\":\"kimi\",\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"file\",\"file_url\":{\"url\":\"%s\"}},{\"type\":\"text\",\"text\":\"帮忙分析下工单中的错别字告诉我对应的工单id\"}]}],\"use_search\":false}", url)
return &AiReq{
token: token,
token: option.MODEL_TOKEN,
body: body,
url: url,
}
}
func (a *AiReq) StartChat(kimiUrl string) KimiResp {
func (a *AiReq) StartChat(url string) KimiResp {
// 定义 POST 请求的 URL
url := kimiUrl
// 创建一个带有 JSON 负载的 POST 请求
payload := []byte(a.body) // 根据需要修改 JSON 负载
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
@ -53,6 +49,7 @@ func (a *AiReq) StartChat(kimiUrl string) KimiResp {
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
log.Println(KimiResp(body))
return KimiResp(body)
}
@ -60,11 +57,5 @@ func (k KimiResp) PrepareWechatBody() string {
wechatBody := gjson.Get(string(k), "choices.#.message.content").String()
r := strings.NewReplacer("\\n", "\n", "\\", "", "[", "", "]", "", "\"", "")
wechatBody = r.Replace(wechatBody)
fmt.Println("body", wechatBody)
//wechatBody = strings.Replace(wechatBody, "\\n", "\n", -1)
//wechatBody = strings.Replace(wechatBody, "\\", "", -1)
//wechatBody = strings.Replace(wechatBody, "[", "", -1)
//wechatBody = strings.Replace(wechatBody, "]", "", -1)
//wechatBody = strings.Replace(wechatBody, "\"", "", 1)
return wechatBody
}

39
buildandrun.sh Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/bash
# 创建gopath目录
mkdir /root/go
cd /root/go
# 获取go安装包如果下载不了可以直接去浏览器下载然后上传到linux
wget https://go.dev/dl/go1.22.1.linux-amd64.tar.gz
# 解压并加入/usr/local目录
tar -C /usr/local -zxf go1.22.1.linux-amd64.tar.gz
# 导出go环境变量
PROFILE_CONTENT="
export GOROOT=/usr/local/go
export GOPATH=/root/go
export GOPROXY=https://goproxy.cn,direct
export PATH=\$PATH:$GOROOT/bin:$GOPATH/bin
"
# 检查 /etc/profile 文件是否存在
if [ -f /etc/profile ]; then
# 使用 echo 命令和 >> 操作符追加内容到 /etc/profile 文件末尾
echo "$PROFILE_CONTENT" >> /etc/profile
echo "已成功添加配置到 /etc/profile。"
else
echo "/etc/profile 文件不存在。"
fi
# 刷新环境变量
source /etc/profile
# 查看go版本检查是否安装成功
go version
cd cmd && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ../aiweek && cd ..
timestamp=$(date +%s)
docker build -t aiweek:$timestamp .
docker run -d --name aiweek -v /data:/data aiweek:$timestamp

View File

@ -3,6 +3,7 @@ package main
import (
"aiweek/aichat"
"aiweek/notifer"
"aiweek/option"
"aiweek/tools"
"aiweek/udesk/reply"
"flag"
@ -13,14 +14,11 @@ import (
"time"
)
const ToNginxFilepath = "/data/"
const kimiUrl = "http://127.0.0.1:8000/v1/chat/completions"
var liveMode bool
var operateTime = 1
func main() {
log.Println(`
fmt.Println(`
_____
_/ ____\______ ____ _____ _____ ____ __ _ _______ ____ ____
\ __\\_ __ \/ _ \ / \ \__ \ / _ \ \ \/ \/ /\__ \ / \ / ___\
@ -31,47 +29,47 @@ _/ ____\______ ____ _____ _____ ____ __ _ _______ ____ ____
flag.Parse()
if !liveMode {
log.Println("目前是定时任务模式")
log.Printf("等待任务的第%v次执行...", operateTime)
log.Printf("等待任务的第%v次执行...\n", operateTime)
// 定义任务,每周五的五点执行
gocron.Every(1).Friday().At("16:00").Do(retryJob)
gocron.Every(1).Saturday().At("16:00").Do(retryJob)
// 开始定时任务
<-gocron.Start()
} else {
log.Println("目前是即时任务模式")
job()
err := job()
if err != nil {
log.Printf("执行任务失败,错误是:%v\n", err)
return
}
}
}
func job() error {
e := reply.NewExcelObj()
replyObj, _ := e.SetReplyContent()
e.CreateNewExcel(replyObj)
e.SetAddress()
//fmt.Println("struct:", e.ExcelName, e.ExcelPath, e.ExcelAddress)
err := reply.CopyFile(e.ExcelPath, ToNginxFilepath+reply.ExcelName)
excel := reply.NewExcelObj()
excel.SetReplyContent().CreateNewExcel()
err := reply.CopyFile(excel.ExcelPath, option.VOLUMEPATH+excel.ExcelName)
if err != nil {
return err
}
err = os.Remove(e.ExcelPath)
err = os.Remove(excel.ExcelPath)
if err != nil {
return err
}
//校验文件数量超过4个删除最老的文件
fileCount, err := tools.CountFilesInDir(ToNginxFilepath)
fileCount, err := tools.CountFilesInDir(option.VOLUMEPATH)
if err != nil {
return err
}
if fileCount > 4 {
cleanFile := tools.ReadFilename(ToNginxFilepath)
err := os.Remove(ToNginxFilepath + cleanFile)
cleanFile := tools.ReadFilename(option.VOLUMEPATH)
err := os.Remove(option.VOLUMEPATH + cleanFile)
if err != nil {
return err
}
}
result := aichat.NewAiReq(e.ExcelAddress).StartChat(kimiUrl).PrepareWechatBody()
result := aichat.NewAiReq(excel.ExcelAddress).StartChat(option.MODEL_API).PrepareWechatBody()
notifer.SendWechat(result)
operateTime++
return nil
}
@ -84,7 +82,9 @@ func retryJob() {
for attempt := 0; attempt < maxRetries; attempt++ {
err := job()
if err == nil {
operateTime++
log.Println("执行成功")
log.Printf("等待第%v次任务执行\n", operateTime)
return
}
fmt.Printf("尝试 %d 次失败,错误是: %s\n", attempt+1, err)

43
createfileserver.sh Normal file
View File

@ -0,0 +1,43 @@
#!/usr/bin/bash
CONFIG_FILE="/etc/nginx/nginx.conf"
CONFIG_BLOCK=$(cat <<EOF
autoindex on; # 显示目录
autoindex_exact_size on; # 显示文件大小
autoindex_localtime on; # 显示文件时间
server {
listen 233 default_server;
listen [::]:233 default_server;
server_name _;
root /data/;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
EOF
)
yum -y install nginx
if [ ! -f "$CONFIG_FILE" ]; then
echo "配置文件不存在: $CONFIG_FILE"
exit 1
fi
sed -i 's/^user nginx;/user root;/' "$CONFIG_FILE"
if [ $? -eq 0 ]; then
echo "用户配置文件已更新。"
else
echo "更新用户配置文件失败。"
fi
sed -i '/^http\s*{/,/^}/a '"$CONFIG_BLOCK" "$NGINX_CONFIG"
if [ $? -eq 0 ]; then
echo "fileserver配置文件已更新。"
else
echo "更新fileserver配置文件失败。"
fi
nginx -s reload

View File

@ -1,8 +0,0 @@
package file
import "aiweek/tools"
func GetFileServerUrl() string {
server := tools.NewServerConfObj().ReadYaml("/conf/fileserver.yaml").Server[0]
return server
}

View File

@ -1,2 +0,0 @@
server:
- "http://43.143.245.135:233/"

View File

@ -1,6 +1,7 @@
package notifer
import (
"aiweek/option"
"encoding/json"
"fmt"
"io"
@ -9,8 +10,6 @@ import (
"strings"
)
const webhookURL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=30155eca-29d2-4e65-84bf-f31e2dac2074"
func SendWechat(repContent string) {
// 替换为你的企业微信机器人Webhook URL
jsonData, err := json.Marshal(repContent)
@ -23,7 +22,7 @@ func SendWechat(repContent string) {
repContent = fmt.Sprintf(`{"msgtype": "text", "text": {"content": %s}}`, repContent)
fmt.Println(repContent)
// 发送HTTP POST请求到企业微信机器人Webhook
resp, err := http.Post(webhookURL, "application/json", strings.NewReader(repContent))
resp, err := http.Post(option.WECHAT_WEBHOOK, "application/json", strings.NewReader(repContent))
if err != nil {
log.Printf("发送企业微信机器人失败,错误是: %v", err)
}

77
option/option.go Normal file
View File

@ -0,0 +1,77 @@
package option
import (
"gopkg.in/yaml.v2"
"io"
"log"
"os"
)
//自定义选项
type Option struct {
UDesk struct {
Filters []struct {
Filter7D string `yaml:"filter7d,omitempty"`
Filter14D string `yaml:"filter14d,omitempty"`
} `yaml:"filters"`
Macros []string `yaml:"macros"`
} `yaml:"uDesk"`
VolumePath string `yaml:"volumePath"`
FileServer struct {
Address string `yaml:"address"`
} `yaml:"fileServer"`
ModelConf struct {
API string `yaml:"api"`
Token string `yaml:"token"`
} `yaml:"modelConf"`
Wechat struct {
Webhook string `yaml:"webhook"`
} `yaml:"wechat"`
}
// 新选项对象
func newOptionObj() *Option {
return &Option{}
}
func (o *Option) readYaml(yamlFile string) *Option {
file, err := os.Open(yamlFile)
if err != nil {
log.Printf("打开yaml文件错误错误是%v", err)
return nil
}
defer file.Close()
data, err := io.ReadAll(file)
if err != nil {
log.Printf("读取yaml文件错误错误是%v", err)
return nil
}
var option Option
err = yaml.Unmarshal(data, &option)
if err != nil {
log.Printf("yaml文件内容反序列化失败错误是%v", err)
return nil
}
return &option
}
func loadALLOption() *Option {
option := newOptionObj()
option = option.readYaml("/conf/")
return option
}
var (
UDESK_FILTER7D = loadALLOption().UDesk.Filters[0].Filter7D
UDSK_FILTER14D = loadALLOption().UDesk.Filters[1].Filter14D
UDESK_MACROS = loadALLOption().UDesk.Macros
FILESERVER_ADDRESS = loadALLOption().FileServer.Address
VOLUMEPATH = loadALLOption().VolumePath
MODEL_API = loadALLOption().ModelConf.API
MODEL_TOKEN = loadALLOption().ModelConf.Token
WECHAT_WEBHOOK = loadALLOption().Wechat.Webhook
)

28
option/option.yaml Normal file
View File

@ -0,0 +1,28 @@
uDesk:
filters:
- filter7d: "16523464"
- filter14d: "16523814"
macros:
- "您好,我们的客服已尝试就此问题联系您,但尚未收到您的回复,如需进一步帮助,请您及时联系我们,谢谢。"
- "您好,您反馈的问题正在处理当中,有任何进展这边第一时间跟您同步,请您耐心等待,十分感谢。"
- "您好,您反馈的问题已分配任务给工程师,请您耐心等待,稍后工程师将尽快进行处理,感谢您的等待与理解。"
- "您好,您提出的这个问题,我们已向项目经理反馈,具体细节和进展,项目经理会与您沟通,麻烦您耐心等待,感谢您的咨询,祝您生活愉快,再见。"
- "您好,您反馈的问题这边确认下,稍后答复您,请您稍等。"
- "您好,如果确认问题解决,请您关闭工单,有其他问题,请再联系我们,感谢您的咨询与反馈,祝您生活愉快,再见。"
- "您好,您的问题,这边已经做升级处理,后端有回复这边会第一时间给您反馈,辛苦您耐心等待下,感谢您的理解。"
- "您好,您反馈的问题已经收到,这边先看下,请您稍等。"
- "您好,该问题的解决方案已反馈,烦请您验证下是否解决您的问题,如已解决,请您关闭工单,有任何问题可以随时再联系我们,感谢您的支持,祝您生活愉快,再见。"
- "您好,经过您的确认问题后已解决,工单可以关闭,如有其他问题,请您随时再联系我们,感谢您的支持,祝您生活愉快,再见!"
- "您好,经过项目经理确认,工单可以暂时关闭,有任何问题请您再联系我们,感谢您的支持,祝您生活愉快,再见!"
- "您好,您反馈的漏洞问题已收到,这边会与研发进行沟通确认,尽快给您答复,请您耐心等待,感谢您的理解!"
- "您好,您的工单我们已做升级处理,我是本次为您服务的高级工程师,您的问题我这边正在处理当中,稍后为您同步进展,请您稍等。"
- "您好非常抱歉当前工单处于排队处理状态已与您沟通XX点处理该问题感谢您的理解请您耐心等待~"
volumePath: "/data/"
fileServer:
address: "http://10.0.8.7:233/"
modelConf:
api: "http://10.0.8.7:8000/v1/chat/completions"
token: "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyLWNlbnRlciIsImV4cCI6MTcyMzYyMTk1NywiaWF0IjoxNzE1ODQ1OTU3LCJqdGkiOiJjcDJybWg5a3FxNGxraGNqbTVtZyIsInR5cCI6InJlZnJlc2giLCJzdWIiOiJjbzU4anJxbG5sOTZlanF1czVnMCIsInNwYWNlX2lkIjoiY281OGpycWxubDk2ZWpxdXM1ZmciLCJhYnN0cmFjdF91c2VyX2lkIjoiY281OGpycWxubDk2ZWpxdXM1ZjAifQ.WNq2OH5egQKlnnuM4ygY2MjjmgsjhEOwHJdV7oQA66_mrHgGKluilcBuMZ5dMpClpAOnVY6wJ021dYHajzuInQ"
wechat:
webhook: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=30155eca-29d2-4e65-84bf-f31e2dac2074"

Binary file not shown.

Binary file not shown.

View File

@ -1,82 +0,0 @@
package tools
import (
"gopkg.in/yaml.v2"
"io"
"log"
"os"
)
//自定义选项
type Option struct {
Filters []struct {
Filter7D string `yaml:"filter7d"`
Filter14D string `yaml:"filter14d"`
} `yaml:"filters"`
Macros []string `yaml:"macros"`
}
//自定义文件服务器地址
type ServerConf struct {
Server []string `yaml:"server"`
}
func NewOptionObj() *Option {
return &Option{}
}
func NewServerConfObj() *ServerConf {
return &ServerConf{}
}
func (ServerConf) ReadYaml(yamlFile string) *ServerConf {
file, err := os.Open(yamlFile)
if err != nil {
log.Printf("打开yaml文件错误错误是%v", err)
return nil
}
defer file.Close()
data, err := io.ReadAll(file)
if err != nil {
log.Printf("读取yaml文件错误错误是%v", err)
return nil
}
var serverconf ServerConf
err = yaml.Unmarshal(data, &serverconf)
if err != nil {
log.Printf("yaml文件内容反序列化失败错误是%v", err)
return nil
}
return &serverconf
}
func (Option) ReadYaml(yamlFile string) *Option {
file, err := os.Open(yamlFile)
if err != nil {
log.Printf("打开yaml文件错误错误是%v", err)
return nil
}
defer file.Close()
data, err := io.ReadAll(file)
if err != nil {
log.Printf("读取yaml文件错误错误是%v", err)
return nil
}
var option Option
err = yaml.Unmarshal(data, &option)
if err != nil {
log.Printf("yaml文件内容反序列化失败错误是%v", err)
return nil
}
return &option
}

View File

@ -1,18 +0,0 @@
filters:
- filter7d: "16523464"
- filter14d: "16523814"
macros:
- "您好,我们的客服已尝试就此问题联系您,但尚未收到您的回复,如需进一步帮助,请您及时联系我们,谢谢。"
- "您好,您反馈的问题正在处理当中,有任何进展这边第一时间跟您同步,请您耐心等待,十分感谢。"
- "您好,您反馈的问题已分配任务给工程师,请您耐心等待,稍后工程师将尽快进行处理,感谢您的等待与理解。"
- "您好,您提出的这个问题,我们已向项目经理反馈,具体细节和进展,项目经理会与您沟通,麻烦您耐心等待,感谢您的咨询,祝您生活愉快,再见。"
- "您好,您反馈的问题这边确认下,稍后答复您,请您稍等。"
- "您好,如果确认问题解决,请您关闭工单,有其他问题,请再联系我们,感谢您的咨询与反馈,祝您生活愉快,再见。"
- "您好,您的问题,这边已经做升级处理,后端有回复这边会第一时间给您反馈,辛苦您耐心等待下,感谢您的理解。"
- "您好,您反馈的问题已经收到,这边先看下,请您稍等。"
- "您好,该问题的解决方案已反馈,烦请您验证下是否解决您的问题,如已解决,请您关闭工单,有任何问题可以随时再联系我们,感谢您的支持,祝您生活愉快,再见。"
- "您好,经过您的确认问题后已解决,工单可以关闭,如有其他问题,请您随时再联系我们,感谢您的支持,祝您生活愉快,再见!"
- "您好,经过项目经理确认,工单可以暂时关闭,有任何问题请您再联系我们,感谢您的支持,祝您生活愉快,再见!"
- "您好,您反馈的漏洞问题已收到,这边会与研发进行沟通确认,尽快给您答复,请您耐心等待,感谢您的理解!"
- "您好,您的工单我们已做升级处理,我是本次为您服务的高级工程师,您的问题我这边正在处理当中,稍后为您同步进展,请您稍等。"
- "您好非常抱歉当前工单处于排队处理状态已与您沟通XX点处理该问题感谢您的理解请您耐心等待~"

View File

@ -1,6 +1,7 @@
package filter
import (
"aiweek/option"
"aiweek/tools"
"aiweek/udesk/auth"
"fmt"
@ -101,28 +102,24 @@ func Id2CloudId(id string) string {
//获取上周到上上周的工单
func GetWeeklyTicket() []string {
optionobj := tools.NewOptionObj()
Opt := optionobj.ReadYaml("/conf/udesk.yaml").Filters
sevenDayPages, err := GetUdeskTicketId(Opt[0].Filter7D)
sevenDayPages, err := GetUdeskTicketId(option.UDESK_FILTER7D)
if err != nil {
log.Printf("获取7天的工单过滤器中的page信息失败错误是%v", err)
}
fourteenDayPages, err := GetUdeskTicketId(Opt[1].Filter14D)
fourteenDayPages, err := GetUdeskTicketId(option.UDSK_FILTER14D)
if err != nil {
log.Printf("获取14天的工单过滤器中的page信息失败错误是%v", err)
}
sevenDaytTickets, err := LoopGetTicketId(sevenDayPages, Opt[0].Filter7D)
sevenDaytTickets, err := LoopGetTicketId(sevenDayPages, option.UDESK_FILTER7D)
if err != nil {
log.Printf("获取7天的工单过滤器中的ticket信息失败错误是%v", err)
}
fourteenDaytickets, err := LoopGetTicketId(fourteenDayPages, Opt[1].Filter14D)
fourteenDaytickets, err := LoopGetTicketId(fourteenDayPages, option.UDSK_FILTER14D)
if err != nil {
log.Printf("获取14天的工单过滤器中的ticket信息失败错误是%v", err)
}
fmt.Println("7天", sevenDaytTickets)
fmt.Println("14天", fourteenDaytickets)
weeklyTicket := tools.ExcludeSlice(sevenDaytTickets, fourteenDaytickets)
fmt.Println("上周到上上周的工单:", weeklyTicket)
return weeklyTicket

View File

@ -22,6 +22,14 @@ var ExcelName = "weeklyReport" + time.Now().Format("2006-01-02") + ".xlsx"
func NewExcelObj() *Excel {
return &Excel{
ExcelName: ExcelName,
ExcelPath: "",
ExcelAddress: "",
Reply: newReplyObj(),
}
}
func newReplyObj() Reply {
return Reply{
replyContent: make(map[string][]string),
}
}

View File

@ -1,14 +1,15 @@
package reply
import (
"aiweek/tools"
"aiweek/option"
"io"
"log"
"os"
)
// 加载宏
func excludeMacros() []string {
macros := tools.NewOptionObj().ReadYaml("/conf/udesk.yaml").Macros
macros := option.UDESK_MACROS
return macros
}
@ -16,6 +17,7 @@ func CopyFile(srcPath, destPath string) error {
// 打开源文件
src, err := os.Open(srcPath)
if err != nil {
log.Printf("打开源文件失败,错误是:%v", err)
return err
}
defer src.Close()
@ -23,18 +25,22 @@ func CopyFile(srcPath, destPath string) error {
// 创建目标文件(这将自动创建任何必需的目录)
dest, err := os.Create(destPath)
if err != nil {
log.Printf("创建目标文件失败,错误是:%v", err)
return err
}
defer dest.Close()
// 复制文件内容
if _, err = io.Copy(dest, src); err != nil {
log.Printf("复制文件内容失败,错误是:%v", err)
return err
}
// 确保目标文件被写入磁盘
if err := dest.Sync(); err != nil {
log.Printf("写入磁盘失败,错误是:%v", err)
return err
}
return nil
defer log.Printf("复制文件到volume目录完成错误是%v", err)
return err
}

View File

@ -1,7 +1,7 @@
package reply
import (
"aiweek/file"
"aiweek/option"
"aiweek/tools"
"aiweek/udesk/auth"
"aiweek/udesk/filter"
@ -16,37 +16,41 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"
"time"
)
//设置真正的id-content键值对。
func (r *Reply) SetReplyContent() (*Reply, error) {
func (e *Excel) SetReplyContent() *Excel {
uDeskId := filter.GetWeeklyTicket()
contentMap := make(map[string][]string)
var wg sync.WaitGroup
//计数器
j := 1
j := 0
for _, v := range uDeskId {
j++
wg.Add(1)
log.Printf("goroutie%v:开始执行\n", j)
time.Sleep(150 * time.Millisecond)
go func(v string, j int) {
defer wg.Done()
idUrl := fmt.Sprintf("https://servicecenter-alauda.udesk.cn/open_api_v1/tickets/%v/replies?", v)
repliesUrl := auth.Geturlstring(idUrl)
resp, err := http.Get(repliesUrl)
if err != nil {
// 处理错误
log.Printf("获取工单过滤器下的回复信息失败,发送请求过程,错误是:%v\n", err)
return nil, err
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
return
}
}(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
// 处理错误
log.Printf("获取工单过滤器下的回复信息失败,读取返回体过程,错误是:%v\n", err)
return nil, err
return
}
defer resp.Body.Close()
jsonData := string(body)
//*查找回复内容和配图
@ -80,25 +84,29 @@ func (r *Reply) SetReplyContent() (*Reply, error) {
repliesContentSlice = tools.AddNewlineToEachElement(repliesContentSlice)
//跳过没有回复内容的工单。
if len(repliesContentSlice) == 0 {
continue
return
}
//工单id转换为cloudid
cloudId := filter.Id2CloudId(v)
log.Printf("正在处理map中的第%v个数据,键是%v\n", j, v)
if cloudId == "" {
contentMap[v] = repliesContentSlice
log.Printf("goroutine%v:回复内容处理完成工单id(非cloudid是%v)", j, v)
} else {
contentMap[cloudId] = repliesContentSlice
log.Printf("goroutine%v:回复内容处理完成工单id(非cloudid是%v)", j, v)
}
log.Printf("第%v个数据数据处理完成\n", j)
j++
log.Printf("goroutine%v结束\n", j)
}(v, j)
}
r.replyContent = contentMap
return r, nil
wg.Wait()
e.Reply.replyContent = contentMap
return e
}
func (e *Excel) CreateNewExcel(reply *Reply) { // 示例的 map
func (e *Excel) CreateNewExcel() { // 示例的 map
// 创建一个新的 Excel 文件
f := excelize.NewFile()
@ -124,7 +132,7 @@ func (e *Excel) CreateNewExcel(reply *Reply) { // 示例的 map
//遍历 map将键和值写入 Excel 表格
row := 2
for key, value := range reply.replyContent {
for key, value := range e.Reply.replyContent {
log.Println(row, key, value)
err := f.SetCellValue("Sheet1", "A"+strconv.Itoa(row), key)
if err != nil {
@ -148,13 +156,12 @@ func (e *Excel) CreateNewExcel(reply *Reply) { // 示例的 map
}
wd, _ := os.Getwd()
relPath := filepath.Join(wd, ExcelName)
absPath, _ := filepath.Abs(relPath)
absPath, err := filepath.Abs(relPath)
if err != nil {
log.Printf("获取excel路径失败错误是:%v", err)
}
e.ExcelPath = absPath
}
func (e *Excel) SetAddress() {
url := file.GetFileServerUrl()
address := url + e.ExcelName
address := option.FILESERVER_ADDRESS + e.ExcelName
e.ExcelAddress = address
}