|
@@ -807,11 +807,11 @@ func (c *PerformanceController) GetPerformanceDetail() {
|
|
|
}
|
|
|
|
|
|
func Cron_Percentage() {
|
|
|
-
|
|
|
+ time.Sleep(10 * time.Second) // 等待10秒,确保数据库初始化完成
|
|
|
//创建一个定时任务对象
|
|
|
c := cron.New(cron.WithSeconds())
|
|
|
- //给对象增加定时任务 - 改为每月1日凌晨0点0分执行
|
|
|
- c.AddFunc("0 0 1 * *", SyncVerifyPercentage)
|
|
|
+ //给对象增加定时任务 - 测试用:每分钟执行一次
|
|
|
+ c.AddFunc("0 0 1 * *", SyncVerifyPercentage) // 生产环境:每月1日凌晨0点0分执行
|
|
|
|
|
|
//启动定时任务
|
|
|
c.Start()
|
|
@@ -822,20 +822,23 @@ func Cron_Percentage() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-func SyncVerifyPercentage() {
|
|
|
- urls := "/openapi/task/list"
|
|
|
- signature, timestamp := lib.GenColdVerifySignature()
|
|
|
-
|
|
|
- // 构建请求数据
|
|
|
- var start_time, end_time string
|
|
|
+// VerifyTaskResponse 冷链验证任务响应结构
|
|
|
+type VerifyTaskResponse struct {
|
|
|
+ Data []Performance.VerifyTask
|
|
|
+ Code int64
|
|
|
+ Msg string
|
|
|
+}
|
|
|
|
|
|
- start_time = lib.GetFirstDayOfLastMonth() + " 00:00:00"
|
|
|
- end_time = lib.GetLastDayOfLastMonth() + " 23:59:59"
|
|
|
+// buildVerifyRequest 构建冷链验证请求并处理响应
|
|
|
+func GetTaskList(startTime, endTime, requestType string) (*VerifyTaskResponse, error) {
|
|
|
+ urls := "/openapi/task/list2"
|
|
|
+ signature, timestamp := lib.GenColdVerifySignature()
|
|
|
|
|
|
// 使用标准HTTP库替换resty
|
|
|
formData := url.Values{}
|
|
|
- formData.Set("T_reporting_pass_start_time", start_time)
|
|
|
- formData.Set("T_reporting_pass_end_time", end_time)
|
|
|
+ formData.Set("T_start_time", startTime)
|
|
|
+ formData.Set("T_end_time", endTime)
|
|
|
+ formData.Set("T_type", requestType)
|
|
|
formData.Set("X-API-KEY", lib.ColdVerify_OpenApi_Key)
|
|
|
formData.Set("X-API-SIGNATURE", signature)
|
|
|
formData.Set("X-API-TIMESTAMP", timestamp)
|
|
@@ -843,26 +846,26 @@ func SyncVerifyPercentage() {
|
|
|
// 构建完整URL
|
|
|
fullURL := conf.ColdVerify_OpenApi_Host + urls
|
|
|
|
|
|
- // 创建HTTP客户端
|
|
|
- client := &http.Client{
|
|
|
- Timeout: 30 * time.Second,
|
|
|
- }
|
|
|
-
|
|
|
// 创建POST请求
|
|
|
req, err := http.NewRequest("POST", fullURL, strings.NewReader(formData.Encode()))
|
|
|
if err != nil {
|
|
|
logs.Error("创建HTTP请求失败: %v", err)
|
|
|
- return
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
// 设置请求头
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
|
|
+ // 创建HTTP客户端
|
|
|
+ client := &http.Client{
|
|
|
+ Timeout: 30 * time.Second,
|
|
|
+ }
|
|
|
+
|
|
|
// 发送请求
|
|
|
resp, err := client.Do(req)
|
|
|
if err != nil {
|
|
|
logs.Error("请求冷链验证任务列表接口失败: %v", err)
|
|
|
- return
|
|
|
+ return nil, err
|
|
|
}
|
|
|
defer resp.Body.Close()
|
|
|
|
|
@@ -870,54 +873,87 @@ func SyncVerifyPercentage() {
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
|
if err != nil {
|
|
|
logs.Error("读取响应体失败: %v", err)
|
|
|
- return
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
// 检查响应状态码
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
logs.Error("请求冷链验证任务列表接口失败,状态码: %d", resp.StatusCode)
|
|
|
- return
|
|
|
+ return nil, fmt.Errorf("请求失败,状态码: %d", resp.StatusCode)
|
|
|
}
|
|
|
|
|
|
// 解析响应
|
|
|
- type R_JSONS struct {
|
|
|
- //必须的大写开头
|
|
|
- Data []Performance.VerifyTask
|
|
|
- Code int64
|
|
|
- Msg string
|
|
|
- }
|
|
|
- var res R_JSONS
|
|
|
+ var res VerifyTaskResponse
|
|
|
if err = json.Unmarshal(body, &res); err != nil {
|
|
|
logs.Error("解析响应数据失败: %v", err)
|
|
|
- return
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
+ return &res, nil
|
|
|
+}
|
|
|
+
|
|
|
+// processWorkloadStats 处理工作量统计逻辑
|
|
|
+func processWorkloadStats(res *VerifyTaskResponse, workType string) map[string]map[int]int {
|
|
|
pointsMap := GetPerformancePointsMap()
|
|
|
coldVerifyUUIDMap := GetColdVerifyUUIDMap()
|
|
|
|
|
|
- // 分别为报告编写人员和数据采集人员创建统计映射
|
|
|
- reportingStat := map[string]map[int]int{} // 报告编写人员统计
|
|
|
- collectionStat := map[string]map[int]int{} // 数据采集人员统计
|
|
|
+ // 创建统计映射
|
|
|
+ stat := map[string]map[int]int{}
|
|
|
|
|
|
- // 遍历所有任务,分别统计报告编写人员和数据采集人员的工作量
|
|
|
+ // 遍历所有任务,统计指定类型的工作量
|
|
|
for _, task := range res.Data {
|
|
|
verifyItem := GetPerformancePoints(Performance.DeviceTypeMap[task.T_device_type], task.T_verify_type, pointsMap)
|
|
|
if verifyItem.Id == 0 {
|
|
|
continue
|
|
|
}
|
|
|
- // 报告编写人员统计
|
|
|
- reportingUserUUID := coldVerifyUUIDMap[task.T_reporting]
|
|
|
- if reportingUserUUID != "" {
|
|
|
- updateWorkloadStat(reportingStat, reportingUserUUID, verifyItem.Id)
|
|
|
+
|
|
|
+ var userUUID string
|
|
|
+ if workType == "reporting" {
|
|
|
+ // 报告编写人员统计
|
|
|
+ userUUID = coldVerifyUUIDMap[task.T_reporting]
|
|
|
+ } else if workType == "collection" {
|
|
|
+ // 数据采集人员统计
|
|
|
+ userUUID = coldVerifyUUIDMap[task.T_collection]
|
|
|
}
|
|
|
|
|
|
- // 数据采集人员统计
|
|
|
- collectionUserUUID := coldVerifyUUIDMap[task.T_collection]
|
|
|
- if collectionUserUUID != "" {
|
|
|
- updateWorkloadStat(collectionStat, collectionUserUUID, verifyItem.Id)
|
|
|
+ if userUUID != "" {
|
|
|
+ updateWorkloadStat(stat, userUUID, verifyItem.Id)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return stat
|
|
|
+}
|
|
|
+
|
|
|
+func SyncVerifyPercentage() {
|
|
|
+ // 构建请求数据
|
|
|
+ start_time := lib.GetFirstDayOfLastMonth() + " 00:00:00"
|
|
|
+ end_time := lib.GetLastDayOfLastMonth() + " 23:59:59"
|
|
|
+
|
|
|
+ // 请求报告编写类型的数据
|
|
|
+ reportingRes, err := GetTaskList(start_time, end_time, "reporting")
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("请求报告编写任务列表失败: %v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 请求数据采集类型的数据
|
|
|
+ collectionRes, err := GetTaskList(start_time, end_time, "collection")
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("请求数据采集任务列表失败: %v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化绩效目标
|
|
|
Performance.Read_PerformanceTarget_All_Map()
|
|
|
+ userList, _ := NatsServer.Read_User_List_All()
|
|
|
+ Account.Read_User_All_Map(userList)
|
|
|
+
|
|
|
+ // 处理报告编写人员统计
|
|
|
+ reportingStat := processWorkloadStats(reportingRes, "reporting")
|
|
|
+
|
|
|
+ // 处理数据采集人员统计
|
|
|
+ collectionStat := processWorkloadStats(collectionRes, "collection")
|
|
|
+
|
|
|
// 保存统计结果到数据库
|
|
|
saveReportingStatsToDB(reportingStat, "reporting")
|
|
|
saveCollectionStatsToDB(collectionStat, "collection")
|
|
@@ -973,7 +1009,6 @@ func saveReportingStatsToDB(stat map[string]map[int]int, workType string) {
|
|
|
T_points_numerator: pointsInfo.T_points_numerator,
|
|
|
T_points_denominator: pointsInfo.T_points_denominator,
|
|
|
T_type: workType,
|
|
|
- T_remark: fmt.Sprintf("报告编写工作量统计: %d项", count),
|
|
|
}
|
|
|
pointList = append(pointList, point)
|
|
|
}
|
|
@@ -1038,7 +1073,6 @@ func saveCollectionStatsToDB(stat map[string]map[int]int, workType string) {
|
|
|
T_points_numerator: pointsInfo.T_points_numerator,
|
|
|
T_points_denominator: pointsInfo.T_points_denominator,
|
|
|
T_type: workType,
|
|
|
- T_remark: fmt.Sprintf("数据采集工作量统计: %d项", count),
|
|
|
}
|
|
|
pointList = append(pointList, point)
|
|
|
}
|