|
|
@@ -1,15 +1,17 @@
|
|
|
package test
|
|
|
|
|
|
import (
|
|
|
- conter "dashoo.cn/genepoint_srv/controllers/converse"
|
|
|
- converse "dashoo.cn/genepoint_srv/business/converseService"
|
|
|
- "dashoo.cn/utils"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
- "time"
|
|
|
-
|
|
|
"strings"
|
|
|
"testing"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "github.com/robfig/cron"
|
|
|
+
|
|
|
+ converse "dashoo.cn/genepoint_srv/business/converseService"
|
|
|
+ conter "dashoo.cn/genepoint_srv/controllers/converse"
|
|
|
+ "dashoo.cn/utils"
|
|
|
)
|
|
|
|
|
|
const UNEXECUTED = 0
|
|
|
@@ -25,23 +27,42 @@ const SAMPLE_STATUS_OUT = 5
|
|
|
const SAMPLE_STATUS_IN = 2
|
|
|
const TASK_TUBE_STORING = 1
|
|
|
const TASK_TUBE_RETREIVING = 2
|
|
|
-func Test_Trim(t *testing.T) {
|
|
|
+
|
|
|
+func test_Time(t *testing.T) {
|
|
|
+
|
|
|
+ cron := cron.New()
|
|
|
+ // 定时规则:每隔10秒执行一次
|
|
|
+ tick := "*/2 * * * * ?"
|
|
|
+ err := cron.AddFunc(tick, func() {
|
|
|
+ fmt.Println(time.Now())
|
|
|
+ cron.Stop()
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ cron.Start()
|
|
|
+
|
|
|
+ time.Sleep(time.Second * 10)
|
|
|
+ cron.Stop()
|
|
|
+}
|
|
|
+
|
|
|
+func test_Trim(t *testing.T) {
|
|
|
|
|
|
// 初始化数据库连接
|
|
|
utils.LoadConfig("../../conf/app.conf")
|
|
|
// Initialize data.
|
|
|
utils.InitDb()
|
|
|
|
|
|
-
|
|
|
// 定义请求报文
|
|
|
-// var paymentData =`{"response":"tube_retrieving",
|
|
|
-//"result":200,"time":"2020-12-16T08:59:00Z",
|
|
|
-//"data":{"type":"accept","task_id":"559126787905298400_1608109140",
|
|
|
-//"taskMsg":[{"cu":10,"model":"whole_rack","total":1,
|
|
|
-//"list":[{"index":1,"rack":101,"rack_id":"GA00000623","tube":201,"tube_number":1}]},
|
|
|
-//{"cu":11,"model":"whole_rack","total":1,
|
|
|
-//"list":[{"index":1,"rack":101,"rack_id":"B20200803000508","tube":201,"tube_number":1}]}]}}`
|
|
|
- var paymentData =` {
|
|
|
+ // var paymentData =`{"response":"tube_retrieving",
|
|
|
+ //"result":200,"time":"2020-12-16T08:59:00Z",
|
|
|
+ //"data":{"type":"accept","task_id":"559126787905298400_1608109140",
|
|
|
+ //"taskMsg":[{"cu":10,"model":"whole_rack","total":1,
|
|
|
+ //"list":[{"index":1,"rack":101,"rack_id":"GA00000623","tube":201,"tube_number":1}]},
|
|
|
+ //{"cu":11,"model":"whole_rack","total":1,
|
|
|
+ //"list":[{"index":1,"rack":101,"rack_id":"B20200803000508","tube":201,"tube_number":1}]}]}}`
|
|
|
+ var paymentData = ` {
|
|
|
"response":"tube_retrieving",
|
|
|
"result":200,
|
|
|
"time":"2018-09-15T13:45:32Z",
|
|
|
@@ -101,236 +122,222 @@ func Test_Trim(t *testing.T) {
|
|
|
]
|
|
|
}
|
|
|
}`
|
|
|
-//var paymentData1 =` {
|
|
|
-//"response":"rack_storing",
|
|
|
-//"result":200,
|
|
|
-//"time":"2018-09-15T13:45:32Z",
|
|
|
-//"data":{
|
|
|
-//"type":"end",
|
|
|
-//"task_id":"426466061139845100_1608100330",
|
|
|
-//"is_end":false,
|
|
|
-//"execution_time":52,
|
|
|
-//"exceptions":[
|
|
|
-//{
|
|
|
-//"cu":2,
|
|
|
-//"codes":[
|
|
|
-//30305
|
|
|
-//]
|
|
|
-//}
|
|
|
-//],
|
|
|
-//"actual_data":[
|
|
|
-//{
|
|
|
-//"rack":101,
|
|
|
-//"tube":201,
|
|
|
-//"rack_id":"B20201215000208",
|
|
|
-//"target":{
|
|
|
-//"cu":1,
|
|
|
-//"ltu":1,
|
|
|
-//"group":1,
|
|
|
-//"unit":1,
|
|
|
-//"pos":1
|
|
|
-//},
|
|
|
-//"tubes":[
|
|
|
-//{
|
|
|
-//"no":1,
|
|
|
-//"id":"562431137612308481",
|
|
|
-//"exception":30305
|
|
|
-//},
|
|
|
-//{
|
|
|
-//"no":2,
|
|
|
-//"id":"562431137612308482",
|
|
|
-//"exception":30305
|
|
|
-//},
|
|
|
-//{
|
|
|
-//"no":4,
|
|
|
-//"id":"562431137612308483",
|
|
|
-//"exception":0
|
|
|
-//},
|
|
|
-//{
|
|
|
-//"no":7,
|
|
|
-//"id":"562431137612308484",
|
|
|
-//"exception":0
|
|
|
-//},
|
|
|
-//{
|
|
|
-//"no":5,
|
|
|
-//"id":"562431137612308485",
|
|
|
-//"exception":0
|
|
|
-//}
|
|
|
-//]
|
|
|
-//}
|
|
|
-//]
|
|
|
-//}
|
|
|
-//}`
|
|
|
-//var paymentData2 =` {
|
|
|
-//"response":"rack_storing",
|
|
|
-//"result":200,
|
|
|
-//"time":"2018-09-15T13:45:32Z",
|
|
|
-//"data":{
|
|
|
-//"type":"end",
|
|
|
-//"task_id":"426466061139845100_1608100330",
|
|
|
-//"is_end":true,
|
|
|
-//"execution_time":52,
|
|
|
-//"exceptions":[
|
|
|
-//{
|
|
|
-//"cu":3,
|
|
|
-//"codes":[
|
|
|
-//30305
|
|
|
-//]
|
|
|
-//}
|
|
|
-//],
|
|
|
-//"actual_data":[
|
|
|
-//{
|
|
|
-//"rack":101,
|
|
|
-//"tube":201,
|
|
|
-//"rack_id":"B20201215000209",
|
|
|
-//"target":{
|
|
|
-//"cu":1,
|
|
|
-//"ltu":1,
|
|
|
-//"group":1,
|
|
|
-//"unit":1,
|
|
|
-//"pos":1
|
|
|
-//},
|
|
|
-//"tubes":[
|
|
|
-//{
|
|
|
-//"no":2,
|
|
|
-//"id":"5624311376123084811",
|
|
|
-//"exception":30305
|
|
|
-//},
|
|
|
-//{
|
|
|
-//"no":8,
|
|
|
-//"id":"5624311376123084822",
|
|
|
-//"exception":30305
|
|
|
-//},
|
|
|
-//{
|
|
|
-//"no":16,
|
|
|
-//"id":"5624311376123084833",
|
|
|
-//"exception":0
|
|
|
-//},
|
|
|
-//{
|
|
|
-//"no":11,
|
|
|
-//"id":"5624311376123084844",
|
|
|
-//"exception":0
|
|
|
-//},
|
|
|
-//{
|
|
|
-//"no":12,
|
|
|
-//"id":"5624311376123084855",
|
|
|
-//"exception":0
|
|
|
-//}
|
|
|
-//]
|
|
|
-//}
|
|
|
-//]
|
|
|
-//}
|
|
|
-//}`
|
|
|
-
|
|
|
-var str [1]string
|
|
|
-
|
|
|
-str[0] =paymentData
|
|
|
-//str[1] =paymentData1
|
|
|
-//str[2] =paymentData2
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-for i:=range str{
|
|
|
- fmt.Println("当前时间1",time.Now())
|
|
|
- time.Sleep(10000)
|
|
|
- fmt.Println("当前时间2",time.Now())
|
|
|
-
|
|
|
-
|
|
|
- // 报文转换为本系统可读
|
|
|
- var res converse.ResponseEntity
|
|
|
- json.Unmarshal([]byte(str[i]), &res)
|
|
|
-
|
|
|
- fmt.Println("res:",res)
|
|
|
-
|
|
|
- var message []byte
|
|
|
-
|
|
|
- message,_ = json.Marshal(&str[i])
|
|
|
- fmt.Println("paymentData;",str[i])
|
|
|
- json.Unmarshal(message, &res)
|
|
|
-
|
|
|
- fmt.Println("message:",message)
|
|
|
- fmt.Println("res:",res)
|
|
|
-
|
|
|
- // 获取请求参数
|
|
|
- resp := res.Response
|
|
|
- result := res.Result
|
|
|
- taskId := strings.Split(res.Data.Task_id,"_")[0]
|
|
|
- isEnd := res.Data.Is_end
|
|
|
- taskType := res.Data.Type
|
|
|
-
|
|
|
- fmt.Println("resp:",resp)
|
|
|
- fmt.Println("result:",result)
|
|
|
- fmt.Println("taskId:",taskId)
|
|
|
- fmt.Println("isEnd:",isEnd)
|
|
|
- fmt.Println("taskType:",taskType)
|
|
|
-
|
|
|
-
|
|
|
- //调试临时用, 把设备信息打印忽略
|
|
|
- //if resp != "report_data" {
|
|
|
- // log.Println("res:",&res)
|
|
|
+ //var paymentData1 =` {
|
|
|
+ //"response":"rack_storing",
|
|
|
+ //"result":200,
|
|
|
+ //"time":"2018-09-15T13:45:32Z",
|
|
|
+ //"data":{
|
|
|
+ //"type":"end",
|
|
|
+ //"task_id":"426466061139845100_1608100330",
|
|
|
+ //"is_end":false,
|
|
|
+ //"execution_time":52,
|
|
|
+ //"exceptions":[
|
|
|
+ //{
|
|
|
+ //"cu":2,
|
|
|
+ //"codes":[
|
|
|
+ //30305
|
|
|
+ //]
|
|
|
//}
|
|
|
- //response := res.Response
|
|
|
-
|
|
|
- //处理设备状态数据
|
|
|
- /*if response == "report_data" {
|
|
|
- converseService.RecordDeviceData(res.Data.List)
|
|
|
- }*/
|
|
|
-
|
|
|
- controller := conter.ConverseController{}
|
|
|
-
|
|
|
- var err error
|
|
|
- //如果正常响应且任务执行成功则修改任务状态为成功
|
|
|
- if result == 200 {
|
|
|
- if taskType == "end" || taskType == "abnormal_end" {
|
|
|
- fmt.Println(">>>>>>>>>>任务[" + taskId + "]结束(" + taskType + ")处理(是否全部结束:" + utils.ToStr(isEnd) + ")>>>>>>>>>>")
|
|
|
-
|
|
|
- // 所有入库单下子任务已完成,根据样本申请状态(有一个不为成功则更新为失败状态)更新申请单,任务状态
|
|
|
- if isEnd {
|
|
|
- err = controller.StatusModifyWithDetail(taskId)
|
|
|
- }
|
|
|
- //若非正常结束,保存异常信息
|
|
|
- if taskType == "abnormal_end" {
|
|
|
- controller.SaveExcepMsg(res, taskId)
|
|
|
- }
|
|
|
- //处理任务下申请
|
|
|
- svc := converse.GetConverseService(utils.DBE)
|
|
|
- svc.ModifySampleStatusByApplyMainInfo(taskId, resp, res)
|
|
|
- //this.SampleAllStatusModify(res,SUCCESS)
|
|
|
- } else if taskType == "task_activate" {
|
|
|
- fmt.Println(">>>>>>>>>>修改激活状态>>>>>>>>>>")
|
|
|
- if res.Data.Status == 3 {
|
|
|
- err = controller.StatusModify(REJECT, taskId)
|
|
|
- } else {
|
|
|
- err = controller.StatusModify(ACTIVE, taskId)
|
|
|
+ //],
|
|
|
+ //"actual_data":[
|
|
|
+ //{
|
|
|
+ //"rack":101,
|
|
|
+ //"tube":201,
|
|
|
+ //"rack_id":"B20201215000208",
|
|
|
+ //"target":{
|
|
|
+ //"cu":1,
|
|
|
+ //"ltu":1,
|
|
|
+ //"group":1,
|
|
|
+ //"unit":1,
|
|
|
+ //"pos":1
|
|
|
+ //},
|
|
|
+ //"tubes":[
|
|
|
+ //{
|
|
|
+ //"no":1,
|
|
|
+ //"id":"562431137612308481",
|
|
|
+ //"exception":30305
|
|
|
+ //},
|
|
|
+ //{
|
|
|
+ //"no":2,
|
|
|
+ //"id":"562431137612308482",
|
|
|
+ //"exception":30305
|
|
|
+ //},
|
|
|
+ //{
|
|
|
+ //"no":4,
|
|
|
+ //"id":"562431137612308483",
|
|
|
+ //"exception":0
|
|
|
+ //},
|
|
|
+ //{
|
|
|
+ //"no":7,
|
|
|
+ //"id":"562431137612308484",
|
|
|
+ //"exception":0
|
|
|
+ //},
|
|
|
+ //{
|
|
|
+ //"no":5,
|
|
|
+ //"id":"562431137612308485",
|
|
|
+ //"exception":0
|
|
|
+ //}
|
|
|
+ //]
|
|
|
+ //}
|
|
|
+ //]
|
|
|
+ //}
|
|
|
+ //}`
|
|
|
+ //var paymentData2 =` {
|
|
|
+ //"response":"rack_storing",
|
|
|
+ //"result":200,
|
|
|
+ //"time":"2018-09-15T13:45:32Z",
|
|
|
+ //"data":{
|
|
|
+ //"type":"end",
|
|
|
+ //"task_id":"426466061139845100_1608100330",
|
|
|
+ //"is_end":true,
|
|
|
+ //"execution_time":52,
|
|
|
+ //"exceptions":[
|
|
|
+ //{
|
|
|
+ //"cu":3,
|
|
|
+ //"codes":[
|
|
|
+ //30305
|
|
|
+ //]
|
|
|
+ //}
|
|
|
+ //],
|
|
|
+ //"actual_data":[
|
|
|
+ //{
|
|
|
+ //"rack":101,
|
|
|
+ //"tube":201,
|
|
|
+ //"rack_id":"B20201215000209",
|
|
|
+ //"target":{
|
|
|
+ //"cu":1,
|
|
|
+ //"ltu":1,
|
|
|
+ //"group":1,
|
|
|
+ //"unit":1,
|
|
|
+ //"pos":1
|
|
|
+ //},
|
|
|
+ //"tubes":[
|
|
|
+ //{
|
|
|
+ //"no":2,
|
|
|
+ //"id":"5624311376123084811",
|
|
|
+ //"exception":30305
|
|
|
+ //},
|
|
|
+ //{
|
|
|
+ //"no":8,
|
|
|
+ //"id":"5624311376123084822",
|
|
|
+ //"exception":30305
|
|
|
+ //},
|
|
|
+ //{
|
|
|
+ //"no":16,
|
|
|
+ //"id":"5624311376123084833",
|
|
|
+ //"exception":0
|
|
|
+ //},
|
|
|
+ //{
|
|
|
+ //"no":11,
|
|
|
+ //"id":"5624311376123084844",
|
|
|
+ //"exception":0
|
|
|
+ //},
|
|
|
+ //{
|
|
|
+ //"no":12,
|
|
|
+ //"id":"5624311376123084855",
|
|
|
+ //"exception":0
|
|
|
+ //}
|
|
|
+ //]
|
|
|
+ //}
|
|
|
+ //]
|
|
|
+ //}
|
|
|
+ //}`
|
|
|
+
|
|
|
+ var str [1]string
|
|
|
+
|
|
|
+ str[0] = paymentData
|
|
|
+ //str[1] =paymentData1
|
|
|
+ //str[2] =paymentData2
|
|
|
+
|
|
|
+ for i := range str {
|
|
|
+ fmt.Println("当前时间1", time.Now())
|
|
|
+ time.Sleep(10000)
|
|
|
+ fmt.Println("当前时间2", time.Now())
|
|
|
+
|
|
|
+ // 报文转换为本系统可读
|
|
|
+ var res converse.ResponseEntity
|
|
|
+ json.Unmarshal([]byte(str[i]), &res)
|
|
|
+
|
|
|
+ fmt.Println("res:", res)
|
|
|
+
|
|
|
+ var message []byte
|
|
|
+
|
|
|
+ message, _ = json.Marshal(&str[i])
|
|
|
+ fmt.Println("paymentData;", str[i])
|
|
|
+ json.Unmarshal(message, &res)
|
|
|
+
|
|
|
+ fmt.Println("message:", message)
|
|
|
+ fmt.Println("res:", res)
|
|
|
+
|
|
|
+ // 获取请求参数
|
|
|
+ resp := res.Response
|
|
|
+ result := res.Result
|
|
|
+ taskId := strings.Split(res.Data.Task_id, "_")[0]
|
|
|
+ isEnd := res.Data.Is_end
|
|
|
+ taskType := res.Data.Type
|
|
|
+
|
|
|
+ fmt.Println("resp:", resp)
|
|
|
+ fmt.Println("result:", result)
|
|
|
+ fmt.Println("taskId:", taskId)
|
|
|
+ fmt.Println("isEnd:", isEnd)
|
|
|
+ fmt.Println("taskType:", taskType)
|
|
|
+
|
|
|
+ //调试临时用, 把设备信息打印忽略
|
|
|
+ //if resp != "report_data" {
|
|
|
+ // log.Println("res:",&res)
|
|
|
+ //}
|
|
|
+ //response := res.Response
|
|
|
+
|
|
|
+ //处理设备状态数据
|
|
|
+ /*if response == "report_data" {
|
|
|
+ converseService.RecordDeviceData(res.Data.List)
|
|
|
+ }*/
|
|
|
+
|
|
|
+ controller := conter.ConverseController{}
|
|
|
+
|
|
|
+ var err error
|
|
|
+ //如果正常响应且任务执行成功则修改任务状态为成功
|
|
|
+ if result == 200 {
|
|
|
+ if taskType == "end" || taskType == "abnormal_end" {
|
|
|
+ fmt.Println(">>>>>>>>>>任务[" + taskId + "]结束(" + taskType + ")处理(是否全部结束:" + utils.ToStr(isEnd) + ")>>>>>>>>>>")
|
|
|
+
|
|
|
+ // 所有入库单下子任务已完成,根据样本申请状态(有一个不为成功则更新为失败状态)更新申请单,任务状态
|
|
|
+ if isEnd {
|
|
|
+ err = controller.StatusModifyWithDetail(taskId)
|
|
|
+ }
|
|
|
+ //若非正常结束,保存异常信息
|
|
|
+ if taskType == "abnormal_end" {
|
|
|
+ controller.SaveExcepMsg(res, taskId)
|
|
|
+ }
|
|
|
+ //处理任务下申请
|
|
|
+ svc := converse.GetConverseService(utils.DBE)
|
|
|
+ svc.ModifySampleStatusByApplyMainInfo(taskId, resp, res)
|
|
|
+ //this.SampleAllStatusModify(res,SUCCESS)
|
|
|
+ } else if taskType == "task_activate" {
|
|
|
+ fmt.Println(">>>>>>>>>>修改激活状态>>>>>>>>>>")
|
|
|
+ if res.Data.Status == 3 {
|
|
|
+ err = controller.StatusModify(REJECT, taskId)
|
|
|
+ } else {
|
|
|
+ err = controller.StatusModify(ACTIVE, taskId)
|
|
|
+ }
|
|
|
+ } else if taskType == "accept" {
|
|
|
+ fmt.Println(">>>>>>>>>>修改接受状态>>>>>>>>>>")
|
|
|
+ err = controller.StatusModify(ACCEPT, taskId)
|
|
|
+ } else if taskType == "running" {
|
|
|
+ fmt.Println(">>>>>>>>>>修改执行中状态>>>>>>>>>>")
|
|
|
+ err = controller.StatusModify(RUNNING, taskId)
|
|
|
}
|
|
|
- } else if taskType == "accept" {
|
|
|
- fmt.Println(">>>>>>>>>>修改接受状态>>>>>>>>>>")
|
|
|
- err = controller.StatusModify(ACCEPT, taskId)
|
|
|
- } else if taskType == "running" {
|
|
|
- fmt.Println(">>>>>>>>>>修改执行中状态>>>>>>>>>>")
|
|
|
- err = controller.StatusModify(RUNNING, taskId)
|
|
|
+ } else if result == 300 && taskType == "reject" {
|
|
|
+ fmt.Println("----------任务[" + taskId + "]任务拒绝----------")
|
|
|
+ //保存异常信息
|
|
|
+ controller.SaveExcepMsg(res, taskId)
|
|
|
+ err = controller.StatusModify(REJECT, taskId)
|
|
|
}
|
|
|
- } else if result == 300 && taskType == "reject" {
|
|
|
- fmt.Println("----------任务[" + taskId + "]任务拒绝----------")
|
|
|
- //保存异常信息
|
|
|
- controller.SaveExcepMsg(res, taskId)
|
|
|
- err = controller.StatusModify(REJECT, taskId)
|
|
|
- }
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- }
|
|
|
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|