소스 검색

基点服务更新

xuchl 4 년 전
부모
커밋
fdc8182fb9

+ 95 - 53
src/dashoo.cn/genepoint_srv/business/converseService/converseService.go

@@ -563,22 +563,26 @@ func (this *ConverseService) ModifySampleAllRejectStatus(res ResponseEntity) err
 //}
 
 //修改样本失败状态
-func (this *ConverseService) handleSampleFailed(idsStr string, response string, parentId int) {
-	// 更新任务明细信息
-	updatesql := "UPDATE " + TABLE_APPLY_DETAIL + " SET taskstatus = '" + strconv.Itoa(FAILED) + "' WHERE barcode IN (" + idsStr + ")" + " AND parentid = '" + strconv.Itoa(parentId) + "'"
-	this.DBE.Exec(updatesql)
 
-	// 更新任务状态
-	updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(FAILED) + "' WHERE  barcode IN (" + idsStr + ")"
-	this.DBE.Exec(updTaskSql)
+
+func (this *ConverseService) handleSampleFailed(idsStr string, response string, parentId int) {
+	if (strings.Contains(response, "tube_")) {
+		// 更新任务明细信息
+		updatesql := "UPDATE " + TABLE_APPLY_DETAIL + " SET taskstatus = '" + strconv.Itoa(FAILED) + "' WHERE barcode IN (" + idsStr + ")" + " AND parentid = '" + strconv.Itoa(parentId) + "'"
+		this.DBE.Exec(updatesql)
+
+		// 更新任务状态
+		updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(FAILED) + "' WHERE  barcode IN (" + idsStr + ")"
+		this.DBE.Exec(updTaskSql)
+	}
 
 }
 
 //处理样本执行成功状态
 func (this *ConverseService) handleSampleSuccess(idsStr string, response string, applyMainId int) {
-	if strings.Contains(response, "_storing") {
+	if strings.Contains(response, "tube_storing") {
 		this.sampleRKSuccessDBModify(idsStr, applyMainId)
-	} else if strings.Contains(response, "_retrieving") {
+	} else if strings.Contains(response, "tube_retrieving") {
 		this.sampleCKSuccessDBModify(idsStr, applyMainId)
 	}
 
@@ -654,83 +658,118 @@ func (this *ConverseService) ModifySampleStatusByApplyMainInfo(entryNo string, r
 			this.UpdatePosition(Rack_id, tubes, entity, applyMain.Id)
 		}
 
-	} else if applyMain.ApplyType == TASK_TUBE_RETREIVING && strings.Contains(resp, "_storing") {
-		fmt.Println("开始入库2")
-		//lite设备 部分管子出库
-		taskType = "tube_retrieving"
-		operaIds, abnormalIds = this.getOperaSampleIdsStr(applyMain.ApplyType, applyMain.Id, resp, entity)
+	//} else if applyMain.ApplyType == TASK_TUBE_RETREIVING && strings.Contains(resp, "_storing") {
+	//	fmt.Println("开始入库2")
+	//	//lite设备 部分管子出库
+	//	taskType = "tube_retrieving"
+	//	operaIds, abnormalIds = this.getOperaSampleIdsStr(applyMain.ApplyType, applyMain.Id, resp, entity)
 	} else if applyMain.ApplyType == TASK_TUBE_RETREIVING && strings.Contains(resp, "_retrieving") /*resp == "rack_retrieving"*/ /*&& entity.Data.Is_end*/ {
-		fmt.Println("开始库3")
+		fmt.Println("开始库3")
 		//lite设备 整盒出库
 		taskType = "tube_retrieving"
-		operaIds, abnormalIds = this.getAllSampleIdsFromResEntity(entity)
+		//operaIds, abnormalIds = this.getAllSampleIdsFromResEntity(entity)
+		operaIds, abnormalIds = this.getOperaSampleIdsStr(applyMain.ApplyType, applyMain.Id, resp, entity)
 	}
-	//else {
-	//
-	//	return
-	//}
 
 	// 此处判断,如果是冻存盒整盒入库,需要更新盒子位置信息  盒  冻存盒当前的 所在的冻存架的id
 	if resp == "rack_storing" {
-		this.UpdateBoxInfo(entity)
+		fmt.Println("冻存盒入库")
+		this.UpdateBoxInfo(entity,applyMain.Id)
 	} else if resp == "rack_retrieving" {
-		fmt.Println("出库")
-		//rack_retrieving
+		fmt.Println("冻存盒出库")
 		//rack_retrieving
 		// 冻存盒出库任务完成以后,需要清空冻存盒中的冻存架信息,同时清空
-		this.UpdateBoxInfoCK(entity)
+		this.UpdateBoxInfoCK(entity,applyMain.Id)
 	}
 
-	//
-	this.handleSampleSuccess(operaIds, taskType, applyMain.Id)
-	if entity.Data.Type == "abnormal_end" {
-		this.handleSampleFailed(abnormalIds, taskType, applyMain.Id)
+	// 根据管操作 或 盒操作 判断是否执行以下更新
+	if (applyMain.ApplyType == TASK_TUBE_STORING && strings.Contains(resp, "_storing")) || (applyMain.ApplyType == TASK_TUBE_RETREIVING && strings.Contains(resp, "_retrieving")) {
+		this.handleSampleSuccess(operaIds, taskType, applyMain.Id)
+		if entity.Data.Type == "abnormal_end" {
+			this.handleSampleFailed(abnormalIds, taskType, applyMain.Id)
+		}
 	}
 }
 
 //2021/01/09 by 卢传敏
 // 根据入库返回报文,更新 冻存盒的信息盒
-func (this *ConverseService) UpdateBoxInfo(entity ResponseEntity) (err error) {
+func (this *ConverseService) UpdateBoxInfo(entity ResponseEntity,parentId int) (err error) {
 	//1.  获取当前返回的  冻存架信息,
 	var shelf Shelf
 
 	glog.Info("entity.Data.Actual_data::", entity.Data.Actual_data)
 
-	// 循环处理返回的数据,如果出现多盒存入的分批处理
+	// 判断是否存在处理成功的数据
+	if len(entity.Data.Actual_data) > 0{
+		// 循环处理返回的数据,如果出现多盒存入的分批处理
+		for i := range entity.Data.Actual_data {
 
-	for i := range entity.Data.Actual_data {
+			glog.Info("操作地  ", i, "  条数据")
 
-		glog.Info("操作地  ", i, "  条数据")
-
-		boxBarcode := entity.Data.Actual_data[i].Rack_id // 冻存盒编号
-		Cu := entity.Data.Actual_data[i].Target.Cu       // 设备编号
-		Ltu := entity.Data.Actual_data[i].Target.Ltu     //
-		Unit := entity.Data.Actual_data[i].Target.Unit
-		Pos := entity.Data.Actual_data[i].Target.Pos
-		Group := entity.Data.Actual_data[i].Target.Group
+			boxBarcode := entity.Data.Actual_data[i].Rack_id // 冻存盒编号
+			Cu := entity.Data.Actual_data[i].Target.Cu       // 设备编号
+			Ltu := entity.Data.Actual_data[i].Target.Ltu     //
+			Unit := entity.Data.Actual_data[i].Target.Unit
+			Pos := entity.Data.Actual_data[i].Target.Pos
+			Group := entity.Data.Actual_data[i].Target.Group
 
-		fmt.Println("保存返回的冻存盒位置信息:cu:", Cu, ",Ltu", Ltu, ",Unit", Unit, ",Group", Group, ",Pos", Pos)
+			fmt.Println("保存返回的冻存盒位置信息:cu:", Cu, ",Ltu", Ltu, ",Unit", Unit, ",Group", Group, ",Pos", Pos)
 
-		sql := "select b.id EquipmentId,a.id,a.XStation,a.YStation from bank_shelf a left join bank_equipment b  on a.EquipmentId = b.id  where  b.cu = '" + utils.ToStr(Cu) + "' " +
-			"and  a.Ltu = '" + utils.ToStr(Ltu) + "' and a.Unit ='" + utils.ToStr(Unit) + "' and a.Group ='" + utils.ToStr(Group) + "'"
+			sql := "select b.id EquipmentId,a.id,a.XStation,a.YStation from bank_shelf a left join bank_equipment b  on a.EquipmentId = b.id  where  b.cu = '" + utils.ToStr(Cu) + "' " +
+				"and  a.Ltu = '" + utils.ToStr(Ltu) + "' and a.Unit ='" + utils.ToStr(Unit) + "' and a.Group ='" + utils.ToStr(Group) + "'"
 
-		this.DBE.SQL(sql).Get(&shelf)
-		fmt.Println("冻存架信息:", shelf.Id, shelf.XStation, shelf.YStation)
+			this.DBE.SQL(sql).Get(&shelf)
+			fmt.Println("冻存架信息:", shelf.Id, shelf.XStation, shelf.YStation)
 
-		//  更新盒所在的冻存架的信息  计算位置信息,并更新
-		// 临时处理逻辑,默认 pos 为 盒子的  XStation
-		_, err = this.DBE.Exec("update bank_box set XStation ='" + utils.ToStr(Pos) + "',YStation =1 ,EquipmentId ='" + com.ToStr(shelf.EquipmentId) + "',shelfId =" + utils.ToStr(shelf.Id) + ",IsLocked = 0  where Barcode ='" + boxBarcode + "' ")
-		// 更新 当前冰箱冻存盒容量 信息
-		_, err = this.DBE.Exec(" update bank_currboxcapacity  set  `A" + utils.ToStr(Pos) + "`= -1 where shelfId =" + utils.ToStr(shelf.Id) + "")
+			//  更新盒所在的冻存架的信息  计算位置信息,并更新
+			// 临时处理逻辑,默认 pos 为 盒子的  XStation
+			_, err = this.DBE.Exec("update bank_box set XStation ='" + utils.ToStr(Pos) + "',YStation =1 ,EquipmentId ='" + com.ToStr(shelf.EquipmentId) + "',shelfId =" + utils.ToStr(shelf.Id) + ",IsLocked = 0  where Barcode ='" + boxBarcode + "' ")
+			// 更新 当前冰箱冻存盒容量 信息
+			_, err = this.DBE.Exec(" update bank_currboxcapacity  set  `A" + utils.ToStr(Pos) + "`= -1 where shelfId =" + utils.ToStr(shelf.Id) + "")
 
+		}
 	}
+	err = this.UpdateBoxAbnormalInfo(entity,parentId)
 	return err
 
 }
 
+func (this *ConverseService) UpdateBoxAbnormalInfo(entity ResponseEntity,parentId int) (err error) {
+	glog.Info("entity.Data.Abnormal_data::", entity.Data.Abnormal_data)
+	AbnormalRack := ""
+	// 判断是否存在处理失败的数据
+	rackEntity := entity.Data.Abnormal_data.Racks
+	if rackEntity != nil {
+		// 获取处理失败的 数据 判断失败的盒是否为空
+		if len(rackEntity) > 0 {
+			for _, v := range rackEntity {
+				// 不为空则需要将数据取出
+				AbnormalRack +=  v.Rack_id + ","
+			}
+			AbnormalRack = AbnormalRack[0 : len(AbnormalRack) -1]
+
+			// 更新盒 的任务状态
+			// 处理异常任务数据
+			updatesql := "UPDATE " + TABLE_SAMPLE_APPLY + " SET taskstatus = '" + strconv.Itoa(FAILED) + "' WHERE parentid = '" + strconv.Itoa(parentId) + "'"
+			_,err = this.DBE.Exec(updatesql)
+			if err != nil {
+				return err
+			}
+			// 更新任务状态
+			updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(FAILED) + "' WHERE  BoxBarcode IN (" + AbnormalRack + ")"
+			_,err =this.DBE.Exec(updTaskSql)
+			if err != nil {
+				return err
+			}
+			this.UpdateBoxIsLocked(utils.ToStr(parentId))
+		}
+	}
+	return err
+}
+
 //2021/01/09 by 卢传敏
 // 根据出库返回报文,更新 冻存盒的信息盒
-func (this *ConverseService) UpdateBoxInfoCK(entity ResponseEntity) (err error) {
+func (this *ConverseService) UpdateBoxInfoCK(entity ResponseEntity,parentId int) (err error) {
 	//1.  获取当前返回的  冻存架信息,
 	var shelf Shelf
 
@@ -761,6 +800,8 @@ func (this *ConverseService) UpdateBoxInfoCK(entity ResponseEntity) (err error)
 		_, err = this.DBE.Exec(" update bank_currboxcapacity  set  `A" + utils.ToStr(Pos) + "`= -2 where shelfId =" + utils.ToStr(shelf.Id) + "")
 
 	}
+
+	err = this.UpdateBoxAbnormalInfo(entity,parentId)
 	return err
 
 }
@@ -904,8 +945,8 @@ func (this *ConverseService) getOperaSampleIdsStr(applyType, parentId int, resp
 	if applyType == TASK_TUBE_RETREIVING {
 		for _, sampleId := range sampleIds {
 			//操作成功样本Id
-			for index, tubeId := range actualTubeIds {
-				if index == len(actualTubeIds)-1 && tubeId != sampleId {
+			for _, tubeId := range actualTubeIds {
+				if sampleId == tubeId {
 					operaTubeIds = append(operaTubeIds, sampleId)
 				}
 			}
@@ -919,9 +960,10 @@ func (this *ConverseService) getOperaSampleIdsStr(applyType, parentId int, resp
 			}
 		}
 	}
-
 	actualIds = "'" + strings.Join(operaTubeIds, "','") + "'"
 	abnormalIds = "'" + strings.Join(failTubeIds, ",") + "'"
+	glog.Info("处理成功数据:", actualIds)
+	glog.Info("处理失败数据:", abnormalIds)
 	return
 }
 

+ 15 - 24
src/dashoo.cn/genepoint_srv/controllers/converse/converse.go

@@ -19,6 +19,19 @@ type ConverseController struct {
 	// beego.Controller
 }
 
+//建立会话
+func (this *ConverseController) GetConnection(c *websocket.Conn) {
+	log.Println("建立会话")
+	svc := GetConverseService(utils.DBE)
+	utc := time.Now().UTC().Format(time.RFC3339)
+	req := svc.GetSessionSetupRequest(utc)
+
+	msg, _ := json.Marshal(req)
+	log.Printf("session_setup: %s", msg)
+
+	this.SendMessage(req, c)
+}
+
 // 查询样本库系统,进行接口任务处理
 func (this *ConverseController) SearchDatabase() map[string]*RequestEntity {
 	log.Println("组装请求数据报文开始---")
@@ -28,14 +41,6 @@ func (this *ConverseController) SearchDatabase() map[string]*RequestEntity {
 	// tasks := svc.GetNewTaskBasic()
 	var reqMap = make(map[string]*RequestEntity)
 
-
-
-
-
-
-
-
-
 	//依次处理每一条新任务信息
 	for _, value := range tasks {
 		var time int64 = time.Now().Unix()
@@ -48,7 +53,7 @@ func (this *ConverseController) SearchDatabase() map[string]*RequestEntity {
 			user = svc.GetOperUser(value.Task_id)
 		}
 		taskid := value.Task_id + "@" + strconv.FormatInt(time, 10)
-	//	log.Println("taskid:", taskid)
+		//	log.Println("taskid:", taskid)
 
 		//如果没有任务实体, 则创建新任务实体
 		if _, ok := reqMap[value.Task_id]; !ok {
@@ -63,25 +68,12 @@ func (this *ConverseController) SearchDatabase() map[string]*RequestEntity {
 	for _, v := range reqMap {
 		//log.Println("****************************")
 		m, _ := json.Marshal(v)
-		log.Println(string(m))
+		log.Println("组装报文成功",string(m))
 	}
 	//log.Println("组装请求数据报文:",reqMap)
 	return reqMap
 }
 
-//建立会话
-func (this *ConverseController) GetConnection(c *websocket.Conn) {
-	log.Println("建立会话")
-	svc := GetConverseService(utils.DBE)
-	utc := time.Now().UTC().Format(time.RFC3339)
-	req := svc.GetSessionSetupRequest(utc)
-
-	msg, _ := json.Marshal(req)
-	log.Printf("session_setup: %s", msg)
-
-	this.SendMessage(req, c)
-}
-
 // 发送消息给接口服务
 func (this *ConverseController) SendMessage(req *RequestEntity, conn *websocket.Conn) {
 	err := conn.WriteJSON(&req)
@@ -273,7 +265,6 @@ func (this *ConverseController) SaveExcepMsg(res ResponseEntity, taskId ,reqType
 	if totalMsg != "" {
 		svc.SaveTaskExcepMsg(totalMsg, taskId)
 		// add by 徐春林 库内整理错误信息保存
-		svc.SaveSampleExcepMsg(totalMsg, taskId)
 		if reqType == "moving" {
 			asvc.SaveArrangeExcepMsg(totalMsg, taskId)
 		} else {

+ 12 - 9
src/dashoo.cn/genepoint_srv/main.go

@@ -306,9 +306,8 @@ func ListenToSendMsg() {
 				break
 			}
 			err1 := wsConn.WriteJSON(reqEntity)
-			log.Println("write err----:", err1)
 			if err1 != nil {
-				log.Println("请求发送失败")
+				log.Println("请求发送失败",err1)
 				// 任务发送失败,,,修改任务状态,,,,提示任务执行失败
 				err1 = ctrl.StatusModify(converseService.FAILED, taskid,reqEntity.Request)
 				// 跟新异常信息
@@ -316,6 +315,7 @@ func ListenToSendMsg() {
 				svc.SaveErrInfo(totalMsg, taskid,reqEntity.Request)
 
 			} else {
+				log.Println("请求发送成功")
 				// 发送成功,修改状态
 				err1 = ctrl.StatusModify(converseService.SENT, taskid,reqEntity.Request)
 			}
@@ -426,6 +426,7 @@ func BackupDatabase() {
 	//每天0时备份数据库
 	// *    *    *    *    *   command
 	//minute   hour   day   month   week   command
+	//tick := "0 0 0 * * ?"
 	tick := "0 0 0 * * ?"
 	err = cron.AddFunc(tick, func() {
 		BackupMySqlDb("")
@@ -451,6 +452,7 @@ func BackupDatabase() {
  */
 func BackupMySqlDb(tableName string) (error,string)  {
 	//定义Cmd结构体对象指针
+	log.Println("开始备份数据库>>>>>>>>>>>>>>>>>>>")
 	var cmd *exec.Cmd
 	host := beego.AppConfig.String("db::host")
 	port := beego.AppConfig.String("db::db_port")
@@ -460,12 +462,12 @@ func BackupMySqlDb(tableName string) (error,string)  {
 	sqlPath := "/home/workservices/bank/"
 	//sqlPath := "D:/backup/"
 	//在这里如果没有传输表名,那么将会备份整个数据库,否则将只备份自己传入的表
-	if tableName == "" {
-		cmd = exec.Command("mysqldump", "--opt", "-h"+host, "-P"+port, "-u"+user, "-p"+password, databaseName)
-	} else {
-		cmd = exec.Command("mysqldump", "--opt", "-h"+host, "-P"+port, "-u"+user, "-p"+password, databaseName, tableName)
-	}
-
+	//if tableName == "" {
+		cmd = exec.Command("mysqldump", "--column-statistics=0","-h"+host, "-P"+port, "-u"+user, "-p"+password, databaseName)
+	/*} else {
+		cmd = exec.Command("mysqldump", "-h"+host, "-P"+port, "-u"+user, "-p"+password, databaseName, tableName)
+	}*/
+	// mysqldump --column-statistics=0 -h127.0.0.1 -P3307 -uroot -pDashoo#190801@ali biobank_genepoint_new > /home/workservices/bank/biobank_genepoint_new_20210413.sql
 	//StdinPipe方法返回一个在命令Start后与命令标准输入关联的管道。
 	stdout, err := cmd.StdoutPipe()
 	if err != nil {
@@ -484,7 +486,7 @@ func BackupMySqlDb(tableName string) (error,string)  {
 		return err,""
 	}
 	//获得一个当前的时间戳
-	now := time.Now().Format("20060102150405")
+	now := time.Now().Format("20060102")
 	var backupPath string
 
 	//设置我们备份文件的名字
@@ -493,6 +495,7 @@ func BackupMySqlDb(tableName string) (error,string)  {
 	} else {
 		backupPath = sqlPath+databaseName+"_"+tableName+"_"+now+".sql"
 	}
+	log.Println("定时备份数据库完成>>>>>>>>>>>>>>>>>>>",backupPath)
 	//写入文件并设置文件权限
 	err = ioutil.WriteFile(backupPath, bytes, 0644)