From 447e367842d331dc4ad17068fddac6bc349b13b8 Mon Sep 17 00:00:00 2001 From: goder-zhang Date: Sat, 7 Mar 2026 10:43:08 +0000 Subject: [PATCH] fix prod --- aicss.ingress | 38 +++++++++++++++++++++++++++++ aicss_k8s/test/deployment.yaml | 42 +++++++++++++++++++++++++++++++++ aicss_k8s/test/docker_build.sh | 21 +++++++++++++++++ aicss_k8s/test/ingress.yaml | 42 +++++++++++++++++++++++++++++++++ aicss_k8s/test/svc.yaml | 14 +++++++++++ config/config_test.yaml | 6 +++++ controller/message.go | 25 ++++++++++---------- controller/visitor.go | 3 +++ docker_build_test.sh | 21 +++++++++++++++++ models/visitors.go | 10 ++++++++ static/templates/chat_main.html | 2 +- static/templates/chat_page.html | 2 +- 12 files changed, 211 insertions(+), 15 deletions(-) create mode 100644 aicss.ingress create mode 100644 aicss_k8s/test/deployment.yaml create mode 100644 aicss_k8s/test/docker_build.sh create mode 100644 aicss_k8s/test/ingress.yaml create mode 100644 aicss_k8s/test/svc.yaml create mode 100644 config/config_test.yaml create mode 100644 docker_build_test.sh diff --git a/aicss.ingress b/aicss.ingress new file mode 100644 index 0000000..ef0b085 --- /dev/null +++ b/aicss.ingress @@ -0,0 +1,38 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + alb.ingress.kubernetes.io/group.name: xpink-testapi + alb.ingress.kubernetes.io/healthcheck-path: / + alb.ingress.kubernetes.io/scheme: internet-facing + alb.ingress.kubernetes.io/target-type: ip + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{"alb.ingress.kubernetes.io/group.name":"xpink-testapi","alb.ingress.kubernetes.io/healthcheck-path":"/","alb.ingress.kubernetes.io/scheme":"internet-facing","alb.ingress.kubernetes.io/target-type":"ip"},"name":"aicss","namespace":"xpink"},"spec":{"ingressClassName":"alb","rules":[{"host":"aicss.bressx-test.com","http":{"paths":[{"backend":{"service":{"name":"aicss-svc","port":{"number":8081}}},"path":"/","pathType":"Prefix"}]}}]}} + creationTimestamp: "2026-02-09T12:32:12Z" + finalizers: + - group.ingress.k8s.aws/xpink-testapi + generation: 1 + name: aicss + namespace: xpink + resourceVersion: "2083488" + uid: c624fc3b-17be-484f-8f1c-8d9e22efea6f +spec: + ingressClassName: alb + rules: + - host: aicss.bressx-test.com + http: + paths: + - backend: + service: + name: aicss-svc + port: + number: 8081 + path: / + pathType: Prefix +status: + loadBalancer: + ingress: + - hostname: k8s-xpinktestapi-1624c23a1c-1329557297.ap-southeast-1.elb.amazonaws.com + ports: + - port: 80 + protocol: "" diff --git a/aicss_k8s/test/deployment.yaml b/aicss_k8s/test/deployment.yaml new file mode 100644 index 0000000..d1fadd3 --- /dev/null +++ b/aicss_k8s/test/deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: aicss-s + namespace: xpink + labels: + app: aicss-s +spec: + replicas: 1 + selector: + matchLabels: + app: aicss-s + template: + metadata: + labels: + app: aicss-s + spec: + containers: + - name: aicss-s + image: 322814420330.dkr.ecr.ap-southeast-1.amazonaws.com/xpink/aicss_service:test + imagePullPolicy: Always + lifecycle: + preStop: + exec: + command: + - /bin/sh + - -c + - sleep 15 + resources: + limits: + cpu: 1000m + memory: 512Mi + requests: + cpu: 10m + memory: 10Mi + env: + - name: IS_TEST + value: "true" + - name: AICSS_ENV + value: "test" + imagePullSecrets: + - name: coding diff --git a/aicss_k8s/test/docker_build.sh b/aicss_k8s/test/docker_build.sh new file mode 100644 index 0000000..30cf5a1 --- /dev/null +++ b/aicss_k8s/test/docker_build.sh @@ -0,0 +1,21 @@ +#!/bin/bash +RUN_NAME=aicss_service +DOCKER_TAG=test +set -e + +go mod tidy + +# 优化编译标志 +BUILD_FLAGS=( + "-trimpath" # 移除文件系统路径,减少二进制大小 + "-ldflags=-s -w" # 移除符号表和调试信息,减少内存使用 +) + +# 使用优化的编译标志 +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build "${BUILD_FLAGS[@]}" -o output/bin/${RUN_NAME} gofly.go + +echo 'build go success' + +docker build -t 322814420330.dkr.ecr.ap-southeast-1.amazonaws.com/xpink/${RUN_NAME}:${DOCKER_TAG} -f Dockerfile . + +docker push 322814420330.dkr.ecr.ap-southeast-1.amazonaws.com/xpink/${RUN_NAME}:${DOCKER_TAG} diff --git a/aicss_k8s/test/ingress.yaml b/aicss_k8s/test/ingress.yaml new file mode 100644 index 0000000..e143299 --- /dev/null +++ b/aicss_k8s/test/ingress.yaml @@ -0,0 +1,42 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: 2048-ingress + namespace: xpink + annotations: + #alb.ingress.kubernetes.io/subnets: vpc-0b996d24feae0e2d5 + alb.ingress.kubernetes.io/scheme: internet-facing +spec: + ingressClassName: alb + rules: + - host: bressx-test.la + http: + paths: + - path: /api + pathType: ImplementationSpecific + backend: + service: + name: hertz-s + port: + number: 8889 + - path: /admin + pathType: ImplementationSpecific + backend: + service: + name: hertz-s + port: + number: 8887 + - path: /callback + pathType: ImplementationSpecific + backend: + service: + name: hertz-s + port: + number: 8888 + - path: /ws + pathType: ImplementationSpecific + backend: + service: + name: hertz-s + port: + number: 8891 diff --git a/aicss_k8s/test/svc.yaml b/aicss_k8s/test/svc.yaml new file mode 100644 index 0000000..55f816f --- /dev/null +++ b/aicss_k8s/test/svc.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: aicss-svc + namespace: xpink # 如果不是 default,请改成你的 namespace +spec: + type: ClusterIP + selector: + app: aicss-s + ports: + - name: http + port: 80 # 对外提供的端口 + targetPort: 8081 # 容器内部监听的端口 + protocol: TCP diff --git a/config/config_test.yaml b/config/config_test.yaml new file mode 100644 index 0000000..7995354 --- /dev/null +++ b/config/config_test.yaml @@ -0,0 +1,6 @@ +mysql_service: + server: goder2.cpccmm68qb1d.ap-southeast-1.rds.amazonaws.com + port: 3306 + database: aicss_db + username: admin + password: vH2GkUxz2398GmDTy^C diff --git a/controller/message.go b/controller/message.go index 72e75c6..fbe8ffa 100644 --- a/controller/message.go +++ b/controller/message.go @@ -135,19 +135,18 @@ func SendMessageV2(c *gin.Context) { } if ws.AIAnswerAvailable(guest) { // AI回答 - ret, err := AIChat(kefuInfo.Name, vistorInfo.VisitorId, content, guest.Conn) - if err == nil { - guest.AIAnswerCycle++ - models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, ret, "kefu") - ws.VisitorMessage(vistorInfo.VisitorId, ret, kefuInfo) - c.JSON(200, gin.H{ - "code": 200, - "msg": "ok", - }) - return - } - - logger.Errorf("ai chat failed err:%v,visitorID:%s,content:%s", err, vistorInfo.VisitorId, content) + go func() { + logger.Debugf("start call ai chat") + ret, err := AIChat(kefuInfo.Name, vistorInfo.VisitorId, content, guest.Conn) + if err == nil { + guest.AIAnswerCycle++ + models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, ret, "kefu") + ws.VisitorMessage(vistorInfo.VisitorId, ret, kefuInfo) + return + } else { + logger.Errorf("ai chat failed err:%v,visitorID:%s,content:%s", err, vistorInfo.VisitorId, content) + } + }() } else if guest.AIAnswerCycle == ws.MaxAIAnswerCycleTimes { guest.AIAnswerCycle++ cot := "ai次数用完将进入人工坐席。。。" diff --git a/controller/visitor.go b/controller/visitor.go index 959dc4c..116beff 100644 --- a/controller/visitor.go +++ b/controller/visitor.go @@ -189,6 +189,9 @@ func GetVisitors(c *gin.Context) { kefuId, _ := c.Get("kefu_name") vistors := models.FindVisitorsByKefuId(uint(page), uint(pagesize), kefuId.(string)) count := models.CountVisitorsByKefuId(kefuId.(string)) + for i := range vistors { + vistors[i].Name = models.CalcVisitorName(vistors[i]) + } c.JSON(200, gin.H{ "code": 200, "msg": "ok", diff --git a/docker_build_test.sh b/docker_build_test.sh new file mode 100644 index 0000000..30cf5a1 --- /dev/null +++ b/docker_build_test.sh @@ -0,0 +1,21 @@ +#!/bin/bash +RUN_NAME=aicss_service +DOCKER_TAG=test +set -e + +go mod tidy + +# 优化编译标志 +BUILD_FLAGS=( + "-trimpath" # 移除文件系统路径,减少二进制大小 + "-ldflags=-s -w" # 移除符号表和调试信息,减少内存使用 +) + +# 使用优化的编译标志 +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build "${BUILD_FLAGS[@]}" -o output/bin/${RUN_NAME} gofly.go + +echo 'build go success' + +docker build -t 322814420330.dkr.ecr.ap-southeast-1.amazonaws.com/xpink/${RUN_NAME}:${DOCKER_TAG} -f Dockerfile . + +docker push 322814420330.dkr.ecr.ap-southeast-1.amazonaws.com/xpink/${RUN_NAME}:${DOCKER_TAG} diff --git a/models/visitors.go b/models/visitors.go index 58bd33d..a59c09f 100644 --- a/models/visitors.go +++ b/models/visitors.go @@ -1,6 +1,8 @@ package models import ( + "fmt" + "strings" "time" ) @@ -132,3 +134,11 @@ func CountVisitorsEveryDay(toId string) []EveryDayNum { toId).Scan(&results) return results } + +func CalcVisitorName(visitor Visitor) string { + var isGuest = strings.Contains(visitor.VisitorId, "-") + if isGuest { + return fmt.Sprintf("游客 | %s ", visitor.VisitorId) + } + return fmt.Sprintf("用户 | %s ", visitor.VisitorId) +} diff --git a/static/templates/chat_main.html b/static/templates/chat_main.html index 9d7bc94..660d4cd 100644 --- a/static/templates/chat_main.html +++ b/static/templates/chat_main.html @@ -784,7 +784,7 @@ pagesize: 20, visitor_id: _this.currentGuest, } - $.get("/2/messagesPages",params,function(res){ + $.get("/ai-css/2/messagesPages",params,function(res){ let msgList=res.result.list; let existKeys={}; for(let i=0;i<_this.msgList.length;i++){ diff --git a/static/templates/chat_page.html b/static/templates/chat_page.html index 516d854..4179961 100644 --- a/static/templates/chat_page.html +++ b/static/templates/chat_page.html @@ -478,7 +478,7 @@ pagesize: 20, visitor_id: _this.visitor.visitor_id, } - $.get("/2/messagesPages",params,function(res){ + $.get("/ai-css/2/messagesPages",params,function(res){ let msgList=res.result.list; let existKeys={}; for(let i=0;i<_this.msgList.length;i++){