dev
parent
9b88c718d9
commit
4198afe015
|
@ -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"]
|
|
@ -1,6 +1,7 @@
|
||||||
package aichat
|
package aichat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"aiweek/option"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
@ -15,23 +16,18 @@ type KimiResp string
|
||||||
type AiReq struct {
|
type AiReq struct {
|
||||||
token string
|
token string
|
||||||
body string
|
body string
|
||||||
url string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyLWNlbnRlciIsImV4cCI6MTcyMzYyMTk1NywiaWF0IjoxNzE1ODQ1OTU3LCJqdGkiOiJjcDJybWg5a3FxNGxraGNqbTVtZyIsInR5cCI6InJlZnJlc2giLCJzdWIiOiJjbzU4anJxbG5sOTZlanF1czVnMCIsInNwYWNlX2lkIjoiY281OGpycWxubDk2ZWpxdXM1ZmciLCJhYnN0cmFjdF91c2VyX2lkIjoiY281OGpycWxubDk2ZWpxdXM1ZjAifQ.WNq2OH5egQKlnnuM4ygY2MjjmgsjhEOwHJdV7oQA66_mrHgGKluilcBuMZ5dMpClpAOnVY6wJ021dYHajzuInQ"
|
|
||||||
|
|
||||||
func NewAiReq(url string) *AiReq {
|
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)
|
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{
|
return &AiReq{
|
||||||
token: token,
|
token: option.MODEL_TOKEN,
|
||||||
body: body,
|
body: body,
|
||||||
url: url,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AiReq) StartChat(kimiUrl string) KimiResp {
|
func (a *AiReq) StartChat(url string) KimiResp {
|
||||||
// 定义 POST 请求的 URL
|
// 定义 POST 请求的 URL
|
||||||
url := kimiUrl
|
|
||||||
// 创建一个带有 JSON 负载的 POST 请求
|
// 创建一个带有 JSON 负载的 POST 请求
|
||||||
payload := []byte(a.body) // 根据需要修改 JSON 负载
|
payload := []byte(a.body) // 根据需要修改 JSON 负载
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
|
||||||
|
@ -53,6 +49,7 @@ func (a *AiReq) StartChat(kimiUrl string) KimiResp {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
log.Println(KimiResp(body))
|
||||||
return KimiResp(body)
|
return KimiResp(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,11 +57,5 @@ func (k KimiResp) PrepareWechatBody() string {
|
||||||
wechatBody := gjson.Get(string(k), "choices.#.message.content").String()
|
wechatBody := gjson.Get(string(k), "choices.#.message.content").String()
|
||||||
r := strings.NewReplacer("\\n", "\n", "\\", "", "[", "", "]", "", "\"", "")
|
r := strings.NewReplacer("\\n", "\n", "\\", "", "[", "", "]", "", "\"", "")
|
||||||
wechatBody = r.Replace(wechatBody)
|
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
|
return wechatBody
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"aiweek/aichat"
|
"aiweek/aichat"
|
||||||
"aiweek/notifer"
|
"aiweek/notifer"
|
||||||
|
"aiweek/option"
|
||||||
"aiweek/tools"
|
"aiweek/tools"
|
||||||
"aiweek/udesk/reply"
|
"aiweek/udesk/reply"
|
||||||
"flag"
|
"flag"
|
||||||
|
@ -13,14 +14,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ToNginxFilepath = "/data/"
|
|
||||||
const kimiUrl = "http://127.0.0.1:8000/v1/chat/completions"
|
|
||||||
|
|
||||||
var liveMode bool
|
var liveMode bool
|
||||||
var operateTime = 1
|
var operateTime = 1
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println(`
|
fmt.Println(`
|
||||||
_____
|
_____
|
||||||
_/ ____\______ ____ _____ _____ ____ __ _ _______ ____ ____
|
_/ ____\______ ____ _____ _____ ____ __ _ _______ ____ ____
|
||||||
\ __\\_ __ \/ _ \ / \ \__ \ / _ \ \ \/ \/ /\__ \ / \ / ___\
|
\ __\\_ __ \/ _ \ / \ \__ \ / _ \ \ \/ \/ /\__ \ / \ / ___\
|
||||||
|
@ -31,47 +29,47 @@ _/ ____\______ ____ _____ _____ ____ __ _ _______ ____ ____
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if !liveMode {
|
if !liveMode {
|
||||||
log.Println("目前是定时任务模式")
|
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()
|
<-gocron.Start()
|
||||||
} else {
|
} else {
|
||||||
log.Println("目前是即时任务模式")
|
log.Println("目前是即时任务模式")
|
||||||
job()
|
err := job()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("执行任务失败,错误是:%v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func job() error {
|
func job() error {
|
||||||
e := reply.NewExcelObj()
|
excel := reply.NewExcelObj()
|
||||||
replyObj, _ := e.SetReplyContent()
|
excel.SetReplyContent().CreateNewExcel()
|
||||||
e.CreateNewExcel(replyObj)
|
err := reply.CopyFile(excel.ExcelPath, option.VOLUMEPATH+excel.ExcelName)
|
||||||
e.SetAddress()
|
|
||||||
//fmt.Println("struct:", e.ExcelName, e.ExcelPath, e.ExcelAddress)
|
|
||||||
err := reply.CopyFile(e.ExcelPath, ToNginxFilepath+reply.ExcelName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = os.Remove(e.ExcelPath)
|
err = os.Remove(excel.ExcelPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//校验文件数量,超过4个删除最老的文件
|
//校验文件数量,超过4个删除最老的文件
|
||||||
fileCount, err := tools.CountFilesInDir(ToNginxFilepath)
|
fileCount, err := tools.CountFilesInDir(option.VOLUMEPATH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if fileCount > 4 {
|
if fileCount > 4 {
|
||||||
cleanFile := tools.ReadFilename(ToNginxFilepath)
|
cleanFile := tools.ReadFilename(option.VOLUMEPATH)
|
||||||
err := os.Remove(ToNginxFilepath + cleanFile)
|
err := os.Remove(option.VOLUMEPATH + cleanFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result := aichat.NewAiReq(e.ExcelAddress).StartChat(kimiUrl).PrepareWechatBody()
|
result := aichat.NewAiReq(excel.ExcelAddress).StartChat(option.MODEL_API).PrepareWechatBody()
|
||||||
notifer.SendWechat(result)
|
notifer.SendWechat(result)
|
||||||
operateTime++
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +82,9 @@ func retryJob() {
|
||||||
for attempt := 0; attempt < maxRetries; attempt++ {
|
for attempt := 0; attempt < maxRetries; attempt++ {
|
||||||
err := job()
|
err := job()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
operateTime++
|
||||||
log.Println("执行成功")
|
log.Println("执行成功")
|
||||||
|
log.Printf("等待第%v次任务执行\n", operateTime)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("尝试 %d 次失败,错误是: %s\n", attempt+1, err)
|
fmt.Printf("尝试 %d 次失败,错误是: %s\n", attempt+1, err)
|
|
@ -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
|
|
@ -1,8 +0,0 @@
|
||||||
package file
|
|
||||||
|
|
||||||
import "aiweek/tools"
|
|
||||||
|
|
||||||
func GetFileServerUrl() string {
|
|
||||||
server := tools.NewServerConfObj().ReadYaml("/conf/fileserver.yaml").Server[0]
|
|
||||||
return server
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
server:
|
|
||||||
- "http://43.143.245.135:233/"
|
|
|
@ -1,6 +1,7 @@
|
||||||
package notifer
|
package notifer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"aiweek/option"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -9,8 +10,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const webhookURL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=30155eca-29d2-4e65-84bf-f31e2dac2074"
|
|
||||||
|
|
||||||
func SendWechat(repContent string) {
|
func SendWechat(repContent string) {
|
||||||
// 替换为你的企业微信机器人Webhook URL
|
// 替换为你的企业微信机器人Webhook URL
|
||||||
jsonData, err := json.Marshal(repContent)
|
jsonData, err := json.Marshal(repContent)
|
||||||
|
@ -23,7 +22,7 @@ func SendWechat(repContent string) {
|
||||||
repContent = fmt.Sprintf(`{"msgtype": "text", "text": {"content": %s}}`, repContent)
|
repContent = fmt.Sprintf(`{"msgtype": "text", "text": {"content": %s}}`, repContent)
|
||||||
fmt.Println(repContent)
|
fmt.Println(repContent)
|
||||||
// 发送HTTP POST请求到企业微信机器人Webhook
|
// 发送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 {
|
if err != nil {
|
||||||
log.Printf("发送企业微信机器人失败,错误是: %v", err)
|
log.Printf("发送企业微信机器人失败,错误是: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
)
|
|
@ -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.
|
@ -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
|
|
||||||
}
|
|
18
udesk.yaml
18
udesk.yaml
|
@ -1,18 +0,0 @@
|
||||||
filters:
|
|
||||||
- filter7d: "16523464"
|
|
||||||
- filter14d: "16523814"
|
|
||||||
macros:
|
|
||||||
- "您好,我们的客服已尝试就此问题联系您,但尚未收到您的回复,如需进一步帮助,请您及时联系我们,谢谢。"
|
|
||||||
- "您好,您反馈的问题正在处理当中,有任何进展这边第一时间跟您同步,请您耐心等待,十分感谢。"
|
|
||||||
- "您好,您反馈的问题已分配任务给工程师,请您耐心等待,稍后工程师将尽快进行处理,感谢您的等待与理解。"
|
|
||||||
- "您好,您提出的这个问题,我们已向项目经理反馈,具体细节和进展,项目经理会与您沟通,麻烦您耐心等待,感谢您的咨询,祝您生活愉快,再见。"
|
|
||||||
- "您好,您反馈的问题这边确认下,稍后答复您,请您稍等。"
|
|
||||||
- "您好,如果确认问题解决,请您关闭工单,有其他问题,请再联系我们,感谢您的咨询与反馈,祝您生活愉快,再见。"
|
|
||||||
- "您好,您的问题,这边已经做升级处理,后端有回复这边会第一时间给您反馈,辛苦您耐心等待下,感谢您的理解。"
|
|
||||||
- "您好,您反馈的问题已经收到,这边先看下,请您稍等。"
|
|
||||||
- "您好,该问题的解决方案已反馈,烦请您验证下是否解决您的问题,如已解决,请您关闭工单,有任何问题可以随时再联系我们,感谢您的支持,祝您生活愉快,再见。"
|
|
||||||
- "您好,经过您的确认问题后已解决,工单可以关闭,如有其他问题,请您随时再联系我们,感谢您的支持,祝您生活愉快,再见!"
|
|
||||||
- "您好,经过项目经理确认,工单可以暂时关闭,有任何问题请您再联系我们,感谢您的支持,祝您生活愉快,再见!"
|
|
||||||
- "您好,您反馈的漏洞问题已收到,这边会与研发进行沟通确认,尽快给您答复,请您耐心等待,感谢您的理解!"
|
|
||||||
- "您好,您的工单我们已做升级处理,我是本次为您服务的高级工程师,您的问题我这边正在处理当中,稍后为您同步进展,请您稍等。"
|
|
||||||
- "您好,非常抱歉,当前工单处于排队处理状态,已与您沟通XX点处理该问题,感谢您的理解,请您耐心等待~"
|
|
|
@ -1,6 +1,7 @@
|
||||||
package filter
|
package filter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"aiweek/option"
|
||||||
"aiweek/tools"
|
"aiweek/tools"
|
||||||
"aiweek/udesk/auth"
|
"aiweek/udesk/auth"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -101,28 +102,24 @@ func Id2CloudId(id string) string {
|
||||||
//获取上周到上上周的工单
|
//获取上周到上上周的工单
|
||||||
|
|
||||||
func GetWeeklyTicket() []string {
|
func GetWeeklyTicket() []string {
|
||||||
optionobj := tools.NewOptionObj()
|
sevenDayPages, err := GetUdeskTicketId(option.UDESK_FILTER7D)
|
||||||
Opt := optionobj.ReadYaml("/conf/udesk.yaml").Filters
|
|
||||||
sevenDayPages, err := GetUdeskTicketId(Opt[0].Filter7D)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("获取7天的工单过滤器中的page信息失败!错误是%v", err)
|
log.Printf("获取7天的工单过滤器中的page信息失败!错误是%v", err)
|
||||||
}
|
}
|
||||||
fourteenDayPages, err := GetUdeskTicketId(Opt[1].Filter14D)
|
fourteenDayPages, err := GetUdeskTicketId(option.UDSK_FILTER14D)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("获取14天的工单过滤器中的page信息失败!错误是%v", err)
|
log.Printf("获取14天的工单过滤器中的page信息失败!错误是%v", err)
|
||||||
}
|
}
|
||||||
sevenDaytTickets, err := LoopGetTicketId(sevenDayPages, Opt[0].Filter7D)
|
sevenDaytTickets, err := LoopGetTicketId(sevenDayPages, option.UDESK_FILTER7D)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("获取7天的工单过滤器中的ticket信息失败!错误是%v", err)
|
log.Printf("获取7天的工单过滤器中的ticket信息失败!错误是%v", err)
|
||||||
}
|
}
|
||||||
fourteenDaytickets, err := LoopGetTicketId(fourteenDayPages, Opt[1].Filter14D)
|
fourteenDaytickets, err := LoopGetTicketId(fourteenDayPages, option.UDSK_FILTER14D)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("获取14天的工单过滤器中的ticket信息失败!错误是%v", err)
|
log.Printf("获取14天的工单过滤器中的ticket信息失败!错误是%v", err)
|
||||||
}
|
}
|
||||||
fmt.Println("7天", sevenDaytTickets)
|
fmt.Println("7天", sevenDaytTickets)
|
||||||
fmt.Println("14天", fourteenDaytickets)
|
fmt.Println("14天", fourteenDaytickets)
|
||||||
|
|
||||||
weeklyTicket := tools.ExcludeSlice(sevenDaytTickets, fourteenDaytickets)
|
weeklyTicket := tools.ExcludeSlice(sevenDaytTickets, fourteenDaytickets)
|
||||||
fmt.Println("上周到上上周的工单:", weeklyTicket)
|
fmt.Println("上周到上上周的工单:", weeklyTicket)
|
||||||
return weeklyTicket
|
return weeklyTicket
|
||||||
|
|
|
@ -22,6 +22,14 @@ var ExcelName = "weeklyReport" + time.Now().Format("2006-01-02") + ".xlsx"
|
||||||
func NewExcelObj() *Excel {
|
func NewExcelObj() *Excel {
|
||||||
return &Excel{
|
return &Excel{
|
||||||
ExcelName: ExcelName,
|
ExcelName: ExcelName,
|
||||||
|
ExcelPath: "",
|
||||||
ExcelAddress: "",
|
ExcelAddress: "",
|
||||||
|
Reply: newReplyObj(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newReplyObj() Reply {
|
||||||
|
return Reply{
|
||||||
|
replyContent: make(map[string][]string),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package reply
|
package reply
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"aiweek/tools"
|
"aiweek/option"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 加载宏
|
// 加载宏
|
||||||
func excludeMacros() []string {
|
func excludeMacros() []string {
|
||||||
macros := tools.NewOptionObj().ReadYaml("/conf/udesk.yaml").Macros
|
macros := option.UDESK_MACROS
|
||||||
return macros
|
return macros
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ func CopyFile(srcPath, destPath string) error {
|
||||||
// 打开源文件
|
// 打开源文件
|
||||||
src, err := os.Open(srcPath)
|
src, err := os.Open(srcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("打开源文件失败,错误是:%v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer src.Close()
|
defer src.Close()
|
||||||
|
@ -23,18 +25,22 @@ func CopyFile(srcPath, destPath string) error {
|
||||||
// 创建目标文件(这将自动创建任何必需的目录)
|
// 创建目标文件(这将自动创建任何必需的目录)
|
||||||
dest, err := os.Create(destPath)
|
dest, err := os.Create(destPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("创建目标文件失败,错误是:%v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer dest.Close()
|
defer dest.Close()
|
||||||
|
|
||||||
// 复制文件内容
|
// 复制文件内容
|
||||||
if _, err = io.Copy(dest, src); err != nil {
|
if _, err = io.Copy(dest, src); err != nil {
|
||||||
|
log.Printf("复制文件内容失败,错误是:%v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保目标文件被写入磁盘
|
// 确保目标文件被写入磁盘
|
||||||
if err := dest.Sync(); err != nil {
|
if err := dest.Sync(); err != nil {
|
||||||
|
log.Printf("写入磁盘失败,错误是:%v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
defer log.Printf("复制文件到volume目录完成!错误是:%v", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package reply
|
package reply
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"aiweek/file"
|
"aiweek/option"
|
||||||
"aiweek/tools"
|
"aiweek/tools"
|
||||||
"aiweek/udesk/auth"
|
"aiweek/udesk/auth"
|
||||||
"aiweek/udesk/filter"
|
"aiweek/udesk/filter"
|
||||||
|
@ -16,37 +16,41 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//设置真正的id-content键值对。
|
//设置真正的id-content键值对。
|
||||||
|
|
||||||
func (r *Reply) SetReplyContent() (*Reply, error) {
|
func (e *Excel) SetReplyContent() *Excel {
|
||||||
uDeskId := filter.GetWeeklyTicket()
|
uDeskId := filter.GetWeeklyTicket()
|
||||||
contentMap := make(map[string][]string)
|
contentMap := make(map[string][]string)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
//计数器
|
//计数器
|
||||||
j := 1
|
j := 0
|
||||||
for _, v := range uDeskId {
|
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)
|
idUrl := fmt.Sprintf("https://servicecenter-alauda.udesk.cn/open_api_v1/tickets/%v/replies?", v)
|
||||||
repliesUrl := auth.Geturlstring(idUrl)
|
repliesUrl := auth.Geturlstring(idUrl)
|
||||||
resp, err := http.Get(repliesUrl)
|
resp, err := http.Get(repliesUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 处理错误
|
// 处理错误
|
||||||
log.Printf("获取工单过滤器下的回复信息失败,发送请求过程,错误是:%v\n", err)
|
log.Printf("获取工单过滤器下的回复信息失败,发送请求过程,错误是:%v\n", err)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer func(Body io.ReadCloser) {
|
|
||||||
err := Body.Close()
|
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}(resp.Body)
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 处理错误
|
// 处理错误
|
||||||
log.Printf("获取工单过滤器下的回复信息失败,读取返回体过程,错误是:%v\n", err)
|
log.Printf("获取工单过滤器下的回复信息失败,读取返回体过程,错误是:%v\n", err)
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
jsonData := string(body)
|
jsonData := string(body)
|
||||||
|
|
||||||
//*查找回复内容和配图
|
//*查找回复内容和配图
|
||||||
|
@ -80,25 +84,29 @@ func (r *Reply) SetReplyContent() (*Reply, error) {
|
||||||
repliesContentSlice = tools.AddNewlineToEachElement(repliesContentSlice)
|
repliesContentSlice = tools.AddNewlineToEachElement(repliesContentSlice)
|
||||||
//跳过没有回复内容的工单。
|
//跳过没有回复内容的工单。
|
||||||
if len(repliesContentSlice) == 0 {
|
if len(repliesContentSlice) == 0 {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//工单id转换为cloudid
|
//工单id转换为cloudid
|
||||||
cloudId := filter.Id2CloudId(v)
|
cloudId := filter.Id2CloudId(v)
|
||||||
log.Printf("正在处理map中的第%v个数据,键是%v\n", j, v)
|
|
||||||
if cloudId == "" {
|
if cloudId == "" {
|
||||||
contentMap[v] = repliesContentSlice
|
contentMap[v] = repliesContentSlice
|
||||||
|
log.Printf("goroutine%v:回复内容处理完成,工单id(非cloudid是%v)", j, v)
|
||||||
} else {
|
} else {
|
||||||
contentMap[cloudId] = repliesContentSlice
|
contentMap[cloudId] = repliesContentSlice
|
||||||
}
|
log.Printf("goroutine%v:回复内容处理完成,工单id(非cloudid是%v)", j, v)
|
||||||
log.Printf("第%v个数据数据处理完成\n", j)
|
|
||||||
j++
|
|
||||||
}
|
|
||||||
r.replyContent = contentMap
|
|
||||||
return r, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Excel) CreateNewExcel(reply *Reply) { // 示例的 map
|
log.Printf("goroutine%v结束\n", j)
|
||||||
|
}(v, j)
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
e.Reply.replyContent = contentMap
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Excel) CreateNewExcel() { // 示例的 map
|
||||||
|
|
||||||
// 创建一个新的 Excel 文件
|
// 创建一个新的 Excel 文件
|
||||||
f := excelize.NewFile()
|
f := excelize.NewFile()
|
||||||
|
@ -124,7 +132,7 @@ func (e *Excel) CreateNewExcel(reply *Reply) { // 示例的 map
|
||||||
|
|
||||||
//遍历 map,将键和值写入 Excel 表格
|
//遍历 map,将键和值写入 Excel 表格
|
||||||
row := 2
|
row := 2
|
||||||
for key, value := range reply.replyContent {
|
for key, value := range e.Reply.replyContent {
|
||||||
log.Println(row, key, value)
|
log.Println(row, key, value)
|
||||||
err := f.SetCellValue("Sheet1", "A"+strconv.Itoa(row), key)
|
err := f.SetCellValue("Sheet1", "A"+strconv.Itoa(row), key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -148,13 +156,12 @@ func (e *Excel) CreateNewExcel(reply *Reply) { // 示例的 map
|
||||||
}
|
}
|
||||||
wd, _ := os.Getwd()
|
wd, _ := os.Getwd()
|
||||||
relPath := filepath.Join(wd, ExcelName)
|
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
|
e.ExcelPath = absPath
|
||||||
|
address := option.FILESERVER_ADDRESS + e.ExcelName
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Excel) SetAddress() {
|
|
||||||
url := file.GetFileServerUrl()
|
|
||||||
address := url + e.ExcelName
|
|
||||||
e.ExcelAddress = address
|
e.ExcelAddress = address
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue