Browse Source

update:优化openapi配置文件

zoie 1 tháng trước cách đây
mục cha
commit
06f8381b2f

+ 0 - 1
README.md

@@ -11,7 +11,6 @@
 #### 导入线上库
 
 go env -w GOPRIVATE=https://gogs.baozhida.cn
-git config --global url."admin@gogs.baozhida.cn:23".insteadOf "https://gogs.baozhida.cn"
 
 #### 导入本地库
 

+ 31 - 8
app/admin/controller/weian.go

@@ -4,6 +4,7 @@ import (
 	"cold-delivery/app/admin/model"
 	"cold-delivery/app/admin/service"
 	"cold-delivery/app/admin/service/dto"
+	cDto "cold-delivery/common/dto"
 	"cold-delivery/common/nats/nats_server"
 	"cold-delivery/conf"
 	"encoding/json"
@@ -12,6 +13,7 @@ import (
 	"github.com/go-resty/resty/v2"
 	"gogs.baozhida.cn/zoie/OAuth-core/api"
 	_ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
+	"time"
 )
 
 type WeianController struct {
@@ -111,16 +113,37 @@ func (e WeianController) GetWaybillData(c *gin.Context) {
 	}
 
 	var ids []int
-	for _, r := range task.DeviceSensorList {
-		ids = append(ids, r.T_id)
+	for _, ds := range task.DeviceSensorList {
+		ids = append(ids, ds.T_id)
+	}
+	startTime := task.StartTime.String()
+	endTime := task.EndTime.String()
+	if len(req.StartTime) > 0 {
+		_, err = time.Parse("2006-01-02 15:04:05", req.StartTime)
+		if err != nil {
+			e.Error(500, err, "开始时间格式不正确")
+			return
+		}
+		startTime = req.StartTime
+	}
+	if len(req.EndTime) > 0 {
+		_, err = time.Parse("2006-01-02 15:04:05", req.EndTime)
+		if err != nil {
+			e.Error(500, err, "结束时间格式不正确")
+			return
+		}
+		endTime = req.EndTime
 	}
 	dataReq := dto.WaybillTaskGetDataPageReq{
-		Pagination: req.Pagination,
-		WaybillNo:  task.WaybillNo,
-		TaskId:     task.Id,
-		T_ids:      ids,
-		StartTime:  task.StartTime.String(),
-		EndTime:    task.EndTime.String(),
+		Pagination: cDto.Pagination{
+			Page:     req.GetPageIndex(),
+			PageSize: req.GetPageSize(),
+		},
+		WaybillNo: task.WaybillNo,
+		TaskId:    task.Id,
+		T_ids:     ids,
+		StartTime: startTime,
+		EndTime:   endTime,
 	}
 	list, count, err := s.GetDataPage(&dataReq)
 	if err != nil {

+ 2 - 0
app/admin/service/dto/weian.go

@@ -15,6 +15,8 @@ type WeianGetWaybillNoReq struct {
 type WeianGetWaybillDataReq struct {
 	dto.Pagination `search:"-"`
 	WaybillNo      string `form:"waybillNo" search:"type:contains;column:waybill_no;table:waybill_task" vd:"len($)>0;msg:'订单编号不能为空'"` // 运单编号-必填
+	StartTime      string `form:"startTime"`
+	EndTime        string `form:"endTime"`
 }
 
 func (m *WeianGetWaybillDataReq) GetNeedSearch() interface{} {

+ 6 - 8
app/admin/service/waybill_task.go

@@ -76,12 +76,12 @@ func (e *WaybillTask) Get(c *dto.WeianGetWaybillDataReq, task *model.WaybillTask
 	}
 
 	err = e.Orm.Model(&data).
-		Where("waybill_no = ?", c.WaybillNo).
+		Where("waybill_no = ?", waybill.WaybillNo).
 		Preload("CoolerBox").
 		First(task).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
-		return global.GetFailedErr
+		return errors.New("获取运单任务信息失败")
 	}
 	// 获取公司秘钥
 	var company model.SysDept
@@ -211,7 +211,7 @@ func (e *WaybillTask) GetLocus(c *dto.WaybillGetLocusReq) ([]nats_server.DeviceD
 	var taskList []model.WaybillTask
 	locusList := make([]nats_server.DeviceData_R2, 0)
 
-	err = e.Orm.Model(&waybill).Where("waybill_no = ?", c.WaybillNo).First(&waybill).Error
+	err = e.Orm.Model(&waybill).Where("waybill_no = ? or order_no = ?", c.WaybillNo, c.WaybillNo).First(&waybill).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
 		return locusList, errors.New("获取运单信息失败")
@@ -225,13 +225,11 @@ func (e *WaybillTask) GetLocus(c *dto.WaybillGetLocusReq) ([]nats_server.DeviceD
 	}
 
 	err = e.Orm.Model(&data).
-		Scopes(
-			cDto.MakeCondition(c.GetNeedSearch()),
-		).
+		Where("waybill_no = ?", waybill.WaybillNo).
 		Find(&taskList).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
-		return locusList, global.GetFailedErr
+		return locusList, errors.New("获取运单任务信息失败")
 	}
 
 	for i := 0; i < len(taskList); i++ {
@@ -242,7 +240,7 @@ func (e *WaybillTask) GetLocus(c *dto.WaybillGetLocusReq) ([]nats_server.DeviceD
 			dataList, _, err := nats_server.Cold_ReadDeviceDataListBy_T_snidForLocus(T_snid, taskList[i].StartTime.String(), taskList[i].EndTime.String(), 0, 9999)
 			if err != nil {
 				e.Log.Errorf("nats 获取轨迹信息失败: %s", err)
-				return locusList, global.GetFailedErr
+				return locusList, errors.New("获取运单轨迹信息失败")
 			}
 
 			// 倒序

+ 3 - 6
common/middleware/openapi.go

@@ -1,6 +1,7 @@
 package middleware
 
 import (
+	"cold-delivery/conf"
 	"crypto/hmac"
 	"crypto/sha256"
 	"encoding/hex"
@@ -16,18 +17,14 @@ const apiKeyHeader = "X-API-KEY"
 const apiSignatureHeader = "X-API-SIGNATURE"
 const apiTimestampHeader = "X-API-TIMESTAMP"
 
-// 这些 API Key 和 Secret 应该存储在安全的存储中,例如数据库或配置文件
-var validAPIKeys = map[string]string{
-	"01HsBYiG": "A8CDJ1GQW4XNB3SZY7PKT92R6LQV8FW5",
-}
 
 // 验证签名是否有效
 func isValidSignature(apiKey, signature, timestamp string) bool {
 	// 使用提供的 API Key 查找对应的 API Secret
-	secret, ok := validAPIKeys[apiKey]
-	if !ok {
+	if apiKey != conf.ExtConfig.OpenApi.ApiKey {
 		return false
 	}
+	secret := conf.ExtConfig.OpenApi.Secret
 
 	// 计算签名,签名内容是 "apiKey + timestamp"
 	message := apiKey + timestamp

+ 6 - 0
conf/extend.go

@@ -17,6 +17,7 @@ type Extend struct {
 	Amap    Amap    `yaml:"amap"`
 	Apk     Apk     `yaml:"apk"`
 	Weian   Weian   `yaml:"weian"`
+	OpenApi OpenApi `yaml:"openapi"`
 }
 
 type SubMail struct {
@@ -53,3 +54,8 @@ type Apk struct {
 type Weian struct {
 	OrderInfoUrl string `json:"orderInfoUrl"`
 }
+
+type OpenApi struct {
+	ApiKey string `json:"apiKey"`
+	Secret string `json:"secret"`
+}

+ 68 - 0
conf/setting_test.yml

@@ -0,0 +1,68 @@
+settings:
+  application:
+    # dev开发环境 test测试环境 prod线上环境
+    mode: dev
+    # 服务器ip,默认使用 0.0.0.0
+    host: 0.0.0.0
+    # 服务名称
+    name: cold-delivery
+    # 端口号
+    port: 6280 # 服务端口号
+    readtimeout: 1
+    writertimeout: 2
+    # 数据权限功能开关
+    enabledp: true
+  logger:
+    # 日志存放路径
+    path: temp/logs
+    # 日志输出,file:文件,default:命令行,其他:命令行
+    stdout: 'default' #控制台日志,启用后,不输出到文件
+    # 日志等级, trace, debug, info, warn, error, fatal
+    level: trace
+    # 文件最多保存多少天
+    maxdays: 1
+    # 数据库日志开关
+    enableddb: true
+  jwt:
+    # token 密钥,生产环境时及的修改
+    secret: JA6WD#*SwAR7
+    # token 过期时间 单位:秒
+    timeout: 3600
+  database:
+    # 数据库类型 mysql
+    driver: mysql
+    # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms
+    source: cold-delivery:SRxDd5TK3xtPTKxw@tcp(192.168.11.77:3306)/cold-delivery?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
+  cache:
+    redis:
+      addr: 192.168.11.77:6379
+      password:
+      db: 4
+    # key存在即可
+    memory: ''
+  extend:
+    subMail:
+      appid: "97173"
+      signature: "f639a60e41ee0554921d89884f5ff87e"
+    qiniu:
+      endpoint: "https://coldoss.coldbaozhida.com/"
+      accessKeyID: "-8ezB_d-8-eUFTMvhOGbGzgeQRPeKQnaQ3DBcUxo"
+      accessKeySecret: "KFhkYxTAJ2ZPN3ZS3euTsfWk8-C92rKgkhAMkDRN"
+      bucketName: "coldoss"
+    applet:
+      appid: "wx7d2f59a537c6ffdd"
+      appSecret: "b6ae826c8c64dd246e8bd8c281c33bde"
+      tokenExpire: 30
+      waybillUrl: "https://coldlogistics.coldbaozhida.com/newInquiry?waybillNo="
+    nats:
+      url: "127.0.0.1:43422"
+    amap:
+      key: "c3dbf424f12240b2de8ace32893c1aa2"
+    apk:
+      path: "/Users/zoie/work/bzd_project/cold-delivery/ofile"
+    weian:
+      orderInfoUrl: "http://127.0.0.1:4523/m2/4530431-0-default/215455750"
+    openapi:
+      apiKey: "01HsBYiG"
+      secret: "A8CDJ1GQW4XNB3SZY7PKT92R6LQV8FW5"
+

+ 13 - 12
conf/settings.yml

@@ -1,13 +1,13 @@
 settings:
   application:
     # dev开发环境 test测试环境 prod线上环境
-    mode: test
+    mode: prod
     # 服务器ip,默认使用 0.0.0.0
     host: 0.0.0.0
     # 服务名称
     name: cold-delivery
     # 端口号
-    port: 8200 # 服务端口号
+    port: 6280 # 服务端口号
     readtimeout: 1
     writertimeout: 2
     # 数据权限功能开关
@@ -16,7 +16,7 @@ settings:
     # 日志存放路径
     path: temp/logs
     # 日志输出,file:文件,default:命令行,其他:命令行
-    stdout: '' #控制台日志,启用后,不输出到文件
+    stdout: 'default' #控制台日志,启用后,不输出到文件
     # 日志等级, trace, debug, info, warn, error, fatal
     level: trace
     # 数据库日志开关
@@ -30,27 +30,25 @@ settings:
     # 数据库类型 mysql
     driver: mysql
     # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms
-#    source: godown:Fp8stPSZ!W3@#G@tcp(192.168.0.88:3306)/godown?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
-    source: gas_cylinder:PtwLf5LLhP8w7Xi5@tcp(192.168.11.77:3306)/gas_cylinder?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
-    host: localhost:6400
+    source: cold:yjwyEckZS7rE5H!@tcp(127.0.0.1:40306)/cold_delivery?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
+  #    host: localhost:8080
+  #    host: 192.168.31.163:8080
   cache:
     redis:
-#      addr: 192.168.0.33:6379
-      addr: 192.168.11.77:6379
+      addr: 127.0.0.1:43379
       password:
-      db: 4
+      db: 11
     # key存在即可
     memory: ''
   extend:
     subMail:
       appid: "97173"
       signature: "f639a60e41ee0554921d89884f5ff87e"
-      waybillUrl: "https://coldlogistics.coldbaozhida.com/newInquiry?waybillNo="
     qiniu:
-      endpoint: "https://bzdcdn.baozhida.cn/"
+      endpoint: "https://coldoss.coldbaozhida.com/"
       accessKeyID: "-8ezB_d-8-eUFTMvhOGbGzgeQRPeKQnaQ3DBcUxo"
       accessKeySecret: "KFhkYxTAJ2ZPN3ZS3euTsfWk8-C92rKgkhAMkDRN"
-      bucketName: "bzdcdn"
+      bucketName: "coldoss"
     applet:
       appid: "wx7d2f59a537c6ffdd"
       appSecret: "b6ae826c8c64dd246e8bd8c281c33bde"
@@ -64,3 +62,6 @@ settings:
       path: "/Users/zoie/work/bzd_project/cold-delivery/ofile"
     weian:
       orderInfoUrl: "http://127.0.0.1:4523/m2/4530431-0-default/215455750"
+    openapi:
+      apiKey: "01HsBYiG"
+      secret: "A8CDJ1GQW4XNB3SZY7PKT92R6LQV8FW5"

+ 0 - 2
setting.yml

@@ -33,8 +33,6 @@ settings:
     driver: mysql
     # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms
     source: cold-delivery:SRxDd5TK3xtPTKxw@tcp(192.168.11.77:3306)/cold-delivery?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
-  #    host: localhost:8080
-  #    host: 192.168.31.163:8080
   cache:
     redis:
       addr: 192.168.11.77:6379