|
|
@@ -1 +1,144 @@
|
|
|
package test
|
|
|
+
|
|
|
+import (
|
|
|
+ conter "dashoo.cn/genepoint_srv/controllers/converse"
|
|
|
+ converse "dashoo.cn/genepoint_srv/business/converseService"
|
|
|
+ "dashoo.cn/utils"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+
|
|
|
+ "strings"
|
|
|
+ "testing"
|
|
|
+)
|
|
|
+
|
|
|
+const UNEXECUTED = 0
|
|
|
+const SENT = 1
|
|
|
+const ACCEPT = 2
|
|
|
+const ACTIVE = 3
|
|
|
+const FAILED = 4
|
|
|
+const SUCCESS = 5
|
|
|
+const RUNNING = 6
|
|
|
+const REJECT = 7
|
|
|
+
|
|
|
+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) {
|
|
|
+
|
|
|
+ // 初始化数据库连接
|
|
|
+ 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 res converse.ResponseEntity
|
|
|
+ json.Unmarshal([]byte(paymentData), &res)
|
|
|
+
|
|
|
+ fmt.Println("res:",res)
|
|
|
+
|
|
|
+ var message []byte
|
|
|
+
|
|
|
+ message,_ = json.Marshal(&paymentData)
|
|
|
+ fmt.Println("paymentData;",paymentData)
|
|
|
+ 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 == "abnormal_end" {
|
|
|
+ if isEnd {
|
|
|
+ fmt.Println("----------修改失败状态----------")
|
|
|
+ //保存异常信息
|
|
|
+ controller.SaveExcepMsg(res, taskId)
|
|
|
+ err = controller.StatusModify(FAILED, taskId)
|
|
|
+ }
|
|
|
+ svc := converse.GetConverseService(utils.DBE)
|
|
|
+ svc.ModifySampleStatusByApplyMainInfo(taskId, resp, res)
|
|
|
+ //this.SamplePartsStatusModify(res)
|
|
|
+ } 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 result == 300 && taskType == "reject" {
|
|
|
+ fmt.Println("----------修改失败状态----------")
|
|
|
+ //保存异常信息
|
|
|
+ controller.SaveExcepMsg(res, taskId)
|
|
|
+ err = controller.StatusModify(REJECT, taskId)
|
|
|
+ //this.SampleAllStatusModify(res,REJECT)
|
|
|
+ svc := converse.GetConverseService(utils.DBE)
|
|
|
+ svc.ModifySampleAllRejectStatus(res)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|