Browse Source

fix(bug): 基点设备数据同步
1. 基点设备同步

luchm 3 years ago
parent
commit
072c5be6db

+ 52 - 55
src/dashoo.cn/genepoint_srv/business/arrangeService/arrangeService.go

@@ -6,13 +6,14 @@
 package arrangeService
 
 import (
+	"dashoo.cn/base_common/utils"
+	. "dashoo.cn/base_common/utils/db"
 	"dashoo.cn/genepoint_srv/business/common"
-	"dashoo.cn/utils"
-	. "dashoo.cn/utils/db"
 	"encoding/json"
 	"fmt"
-	"github.com/Unknwon/com"
-	"github.com/go-xorm/xorm"
+	"github.com/gogf/gf/util/gconv"
+	"xorm.io/xorm"
+
 	"github.com/gogf/gf/os/glog"
 	"strconv"
 	"strings"
@@ -57,14 +58,14 @@ func (this *ArrangeService) GetOperUser(EntryNo string) (user string) {
  * @return
  **/
 // 修改出入库单状态
-func (this *ArrangeService) ArrangeMainStatusModify(statusCode int, entryNo,msg string) error {
+func (this *ArrangeService) ArrangeMainStatusModify(statusCode int, entryNo, msg string) error {
 	set := ""
-	if statusCode == 1 || statusCode == 2 || statusCode == 3 || statusCode == 5   {
+	if statusCode == 1 || statusCode == 2 || statusCode == 3 || statusCode == 5 {
 		set = "  ,exception='' "
-	}else{
-		if msg!=""{
-			set = "  ,exception='"+msg+"' "
-		}else{
+	} else {
+		if msg != "" {
+			set = "  ,exception='" + msg + "' "
+		} else {
 			set = "  ,exception='' "
 		}
 	}
@@ -83,7 +84,7 @@ func (this *ArrangeService) ArrangeMainStatusModify(statusCode int, entryNo,msg
  **/
 func (this *ArrangeService) ArrangeDetailStatusModify(statusCode int, entryNo string) error {
 	//获取出入库单Id
-	getId := "SELECT id FROM " + TABLE_ARRANGE_MAIN+ " WHERE entryno = '" + entryNo + "'"
+	getId := "SELECT id FROM " + TABLE_ARRANGE_MAIN + " WHERE entryno = '" + entryNo + "'"
 	var idList []Id
 	err := this.DBE.SQL(getId).Find(&idList)
 	//批量更新全部成功或失败的任务样本状态
@@ -114,7 +115,7 @@ func (this *ArrangeService) SaveArrangeExcepMsg(msg, entryNo string) error {
  * @Param
  * @return
  **/
-func (this *ArrangeService) UpdateArrangeRes (entryNo string, resp string, message []byte) error {
+func (this *ArrangeService) UpdateArrangeRes(entryNo string, resp string, message []byte) error {
 	var res ResponseEntity
 	err := json.Unmarshal(message, &res)
 	if err != nil {
@@ -124,7 +125,7 @@ func (this *ArrangeService) UpdateArrangeRes (entryNo string, resp string, messa
 	isEnd := res.Data.Is_end
 
 	// 判断是否全部成功, 更新失败的任务状态
-	this.GetAbnormalDataAndUpdate(taskId,res)
+	this.GetAbnormalDataAndUpdate(taskId, res)
 	// 先更新盒子的原位置
 	err = this.UpdateBoxInfoCK(res)
 	if err != nil {
@@ -146,7 +147,7 @@ func (this *ArrangeService) UpdateArrangeRes (entryNo string, resp string, messa
 		var tubes = value.Tubes
 		fmt.Println("样本位置信息:", tubes)
 		//新增方法 更新位置信息
-		this.UpdatePosition(taskId,Rack_id, tubes, res)
+		this.UpdatePosition(taskId, Rack_id, tubes, res)
 	}
 	if isEnd {
 		// 根据盒子中样本数量更新样本信息
@@ -156,7 +157,6 @@ func (this *ArrangeService) UpdateArrangeRes (entryNo string, resp string, messa
 	return err
 }
 
-
 /**
  * @Author 徐春林
  * @Description // 获取整理成功的 盒子信息并保存
@@ -177,8 +177,8 @@ func (this *ArrangeService) UpdateBoxInfo(entity ResponseEntity) (err error) {
 		glog.Info("操作地  ", i, "  条数据")
 
 		boxBarcode := entity.Data.Actual_data[i].RackId // 冻存盒编号
-		Cu := entity.Data.Actual_data[i].Target.Cu       // 设备编号
-		Ltu := entity.Data.Actual_data[i].Target.Ltu     //
+		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
@@ -189,25 +189,24 @@ func (this *ArrangeService) UpdateBoxInfo(entity ResponseEntity) (err error) {
 		lengSql := " select  * from bank_equipment    where  cu = '" + utils.ToStr(Cu) + "'  and    Ltu = '" + utils.ToStr(Ltu) + "'  "
 		this.DBE.SQL(lengSql).Get(&equipment)
 
-
 		sql := "select b.id EquipmentId,a.id,b.code,b.name,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.Group ='" + utils.ToStr(Group) + "'"
 
 		// 拼接冻存盒位置信息
 		position := equipment.Code + "-" + common.Boxlinename(shelf.XStation) + utils.ToStr(shelf.YStation) + "-" +
-			"" + common.Boxlinename( Pos )
+			"" + common.Boxlinename(Pos)
 
 		// 冷库设备
-		YStation:="  "
-		if equipment.Ltu  == 0    {
+		YStation := "  "
+		if equipment.Ltu == 0 {
 			sql += "  and a.Unit ='" + utils.ToStr(Unit) + "'   "
-			YStation  = " , YStation =1  "
+			YStation = " , YStation =1  "
 			position += utils.ToStr(1)
-			fmt.Println("保存返回的冻存盒位置信息:YStation1:1 ",  YStation)
-		}else{
-			YStation  = " ,   YStation =    "+ utils.ToStr(Unit)
+			fmt.Println("保存返回的冻存盒位置信息:YStation1:1 ", YStation)
+		} else {
+			YStation = " ,   YStation =    " + utils.ToStr(Unit)
 			position += utils.ToStr(utils.ToStr(Unit))
-			fmt.Println("保存返回的冻存盒位置信息:cYStation1:2 ",  YStation)
+			fmt.Println("保存返回的冻存盒位置信息:cYStation1:2 ", YStation)
 		}
 
 		this.DBE.SQL(sql).Get(&shelf)
@@ -216,8 +215,8 @@ func (this *ArrangeService) UpdateBoxInfo(entity ResponseEntity) (err error) {
 
 		//  更新盒所在的冻存架的信息  计算位置信息,并更新
 		// 临时处理逻辑,默认 pos 为 盒子的  XStation
-		_, err = this.DBE.Exec("update bank_box set XStation ='" + utils.ToStr(Pos) + "'  "+YStation+" ,EquipmentId ='" + com.ToStr(shelf.EquipmentId) + "'," +
-			" shelfId =" + utils.ToStr(shelf.Id) + ",IsLocked = 0 , position = '"+position+"'  where Barcode ='" + boxBarcode + "' ")
+		_, err = this.DBE.Exec("update bank_box set XStation = '" + utils.ToStr(Pos) + "'  " + YStation + " ,EquipmentId ='" + gconv.String(shelf.EquipmentId) + "'," +
+			" shelfId =" + utils.ToStr(shelf.Id) + ",IsLocked = 0 , position = '" + position + "'  where Barcode ='" + boxBarcode + "' ")
 		// 更新 当前冰箱冻存盒容量 信息
 		_, err = this.DBE.Exec(" update bank_currboxcapacity  set  `A" + utils.ToStr(Pos) + "`= -1 where shelfId =" + utils.ToStr(shelf.Id) + "")
 
@@ -264,7 +263,7 @@ func (this *ArrangeService) UpdateBoxInfoCK(entity ResponseEntity) (err error) {
  * @Param
  * @return
  **/
-func (this *ArrangeService) UpdatePosition(taskId,rack_id string, tubes []Tube, entity ResponseEntity) {
+func (this *ArrangeService) UpdatePosition(taskId, rack_id string, tubes []Tube, entity ResponseEntity) {
 	// 根据返回的报文中的盒子标识,获取盒子类型
 	sql := "select Id,RowNum,ColumnNum,EquipmentId,ShelfId,XStation,YStation  from bank_box where Barcode ='" + rack_id + "'"
 	var box Box
@@ -274,17 +273,17 @@ func (this *ArrangeService) UpdatePosition(taskId,rack_id string, tubes []Tube,
 	ColumnNum := box.ColumnNum
 
 	//  获取容器信息
-	equipmentsql := " select Id,Code,Name from bank_equipment where id = '"+   box.EquipmentId+"'   "
+	equipmentsql := " select Id,Code,Name from bank_equipment where id = '" + box.EquipmentId + "'   "
 	var equipmentInfo EquipmentInfo
 	this.DBE.SQL(equipmentsql).Get(&equipmentInfo)
 	//  获取架子信息
-	shelfsql := " select Id,XStation,YStation from bank_shelf where id = '"+  box.ShelfId+"'   "
+	shelfsql := " select Id,XStation,YStation from bank_shelf where id = '" + box.ShelfId + "'   "
 	var shelf Shelf
 	this.DBE.SQL(shelfsql).Get(&shelf)
 
 	glog.Info("冻存盒的行数:", RowNum, ";冻存盒的列数:", ColumnNum) //
-	glog.Info("冻存盒内管数量len(tubes) : " ,len(tubes) ) //
-	if len(tubes) >0{
+	glog.Info("冻存盒内管数量len(tubes) : ", len(tubes))       //
+	if len(tubes) > 0 {
 		for i := 0; i < len(tubes); i++ {
 			no := tubes[i].No
 			id := tubes[i].Id
@@ -303,16 +302,16 @@ func (this *ArrangeService) UpdatePosition(taskId,rack_id string, tubes []Tube,
 			glog.Info("管子在盒子中的位置坐标为:", box_y, ";", box_x)
 
 			position := equipmentInfo.Code + "-" + common.Boxlinename(shelf.YStation) + utils.ToStr(shelf.XStation) + "-" +
-				"" + common.Boxlinename(box.YStation) + utils.ToStr(box.XStation)+"-"+common.Boxlinename(box_x) + utils.ToStr(box_y)
+				"" + common.Boxlinename(box.YStation) + utils.ToStr(box.XStation) + "-" + common.Boxlinename(box_x) + utils.ToStr(box_y)
 
 			sql = "update bank_sample set BoxId = '" + utils.ToStr(box.Id) + "',Position = '" + utils.ToStr(box_y) + ";" + utils.ToStr(box_x) + "' , " +
 				"PositionInfo  =  '" + position + "'   where barcode ='" + id + "' "
 			//执行sql 更新位置和坐标信息
 			this.DBE.Exec(sql)
-			this.UpdateDetail(id, entity, rack_id,taskId)
+			this.UpdateDetail(id, entity, rack_id, taskId)
 		}
-	}else{
-		this.UpdateDetail("", entity, rack_id,taskId)
+	} else {
+		this.UpdateDetail("", entity, rack_id, taskId)
 	}
 
 }
@@ -324,7 +323,7 @@ func (this *ArrangeService) UpdatePosition(taskId,rack_id string, tubes []Tube,
  * @Param
  * @return
  **/
-func (this *ArrangeService) UpdateDetail(BarCode string, entity ResponseEntity, rack_id,taskId string) {
+func (this *ArrangeService) UpdateDetail(BarCode string, entity ResponseEntity, rack_id, taskId string) {
 
 	glog.Info("修改detail:", entity)
 	arrangeMain := this.GetArrangeMain(taskId)
@@ -338,17 +337,16 @@ func (this *ArrangeService) UpdateDetail(BarCode string, entity ResponseEntity,
 		Unit := entity.Data.Actual_data[i].Target.Unit
 		Group := entity.Data.Actual_data[i].Target.Group
 
-
 		// 判断是否是冷库,如果是冷库的话,查询容器架子信息时不需要组装 unit
 		lengSql := " select  * from bank_equipment    where  cu = '" + utils.ToStr(Cu) + "'  and    Ltu = '" + utils.ToStr(Ltu) + "'  "
 		this.DBE.SQL(lengSql).Get(&equipment)
 
-		if  entity.Response == "moving"{
+		if entity.Response == "moving" {
 			// 更内库内整理 冻存盒信息 整理结果
 			updatesql := "UPDATE bank_arrange_detail SET IsLocked = '0', taskstatus = '" + strconv.Itoa(SUCCESS) + "' WHERE barcode = '" + entity.Data.Actual_data[i].Target.Rack_id + "'" + " AND parentid = '" + strconv.Itoa(arrangeMain.Id) + "'"
 			this.DBE.Exec(updatesql)
 			// 更内库内整理 冻存盒信息 整理结果
-			updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(SUCCESS) + "' WHERE  boxbarcode = '" +  entity.Data.Actual_data[i].Target.Rack_id + "' and task_id = '"+taskId+"'"
+			updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(SUCCESS) + "' WHERE  boxbarcode = '" + entity.Data.Actual_data[i].Target.Rack_id + "' and task_id = '" + taskId + "'"
 			this.DBE.Exec(updTaskSql)
 		}
 
@@ -357,7 +355,7 @@ func (this *ArrangeService) UpdateDetail(BarCode string, entity ResponseEntity,
 			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.Group ='" + utils.ToStr(Group) + "'"
 
-			if equipment.Ltu  == 0    {
+			if equipment.Ltu == 0 {
 				sql += "  and a.Unit ='" + utils.ToStr(Unit) + "'   "
 			}
 
@@ -372,24 +370,23 @@ func (this *ArrangeService) UpdateDetail(BarCode string, entity ResponseEntity,
 			sql = "update bank_sample set EquipmentId=" + equipmentid + ",ShelfId=" + ShelfId + "    where barcode ='" + BarCode + "' "
 			this.DBE.Exec(sql)
 
-			if  entity.Response == "moving"{
+			if entity.Response == "moving" {
 				// 更内库内整理 冻存盒信息 整理结果
 				updatesql := "UPDATE bank_arrange_detail SET IsLocked = '0', taskstatus = '" + strconv.Itoa(SUCCESS) + "' WHERE barcode = '" + entity.Data.Actual_data[i].Target.Rack_id + "'" + " AND parentid = '" + strconv.Itoa(arrangeMain.Id) + "'"
 				this.DBE.Exec(updatesql)
 				// 更内库内整理 冻存盒信息 整理结果
-				updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(SUCCESS) + "' WHERE  boxbarcode = '" +  entity.Data.Actual_data[i].Target.Rack_id + "' and task_id = '"+taskId+"'"
+				updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(SUCCESS) + "' WHERE  boxbarcode = '" + entity.Data.Actual_data[i].Target.Rack_id + "' and task_id = '" + taskId + "'"
 				this.DBE.Exec(updTaskSql)
-			}else{
+			} else {
 				// 更新库内整理 样本整理结果
 				updatesql := "UPDATE bank_arrange_detail SET IsLocked = '0', taskstatus = '" + strconv.Itoa(SUCCESS) + "' WHERE barcode = '" + BarCode + "'" + " AND parentid = '" + strconv.Itoa(arrangeMain.Id) + "'"
 				this.DBE.Exec(updatesql)
 
-				updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(SUCCESS) + "' WHERE  barcode = '" + BarCode + "' and task_id = '"+taskId+"'"
+				updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(SUCCESS) + "' WHERE  barcode = '" + BarCode + "' and task_id = '" + taskId + "'"
 				this.DBE.Exec(updTaskSql)
 			}
 		}
 
-
 	}
 }
 
@@ -435,7 +432,7 @@ func (this *ArrangeService) GetAbnormalDataAndUpdate(taskId string, entity Respo
 	racks := entity.Data.Abnormal_data.Racks
 	arrangeMain := this.GetArrangeMain(taskId)
 	var shelf Shelf
-	if len(racks) > 0  {
+	if len(racks) > 0 {
 		for _, v := range racks {
 			// 根据盒编码,任务编码查询 任务信息,任务存在更新状态
 			sql := "SELECT count(*) FROM `" + TABLE_TAST + " WHERE task_id = '" + taskId + "' and BoxBarCode = '" + v.RackId + "'"
@@ -446,9 +443,9 @@ func (this *ArrangeService) GetAbnormalDataAndUpdate(taskId string, entity Respo
 			// 存在未执行成功的子任务
 			if total > 0 {
 				// 更新任务明细信息
-				updatesql := "UPDATE " + TABLE_ARRANGE_DETAIL + " SET taskstatus = '" + strconv.Itoa(FAILED) + "' WHERE BoxBarCode = '" +  v.RackId + "' AND parentid = '" + strconv.Itoa(arrangeMain.Id) + "'"
+				updatesql := "UPDATE " + TABLE_ARRANGE_DETAIL + " SET taskstatus = '" + strconv.Itoa(FAILED) + "' WHERE BoxBarCode = '" + v.RackId + "' AND parentid = '" + strconv.Itoa(arrangeMain.Id) + "'"
 				this.DBE.Exec(updatesql)
-				updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(FAILED) + "' WHERE  BoxBarCode = '" +  v.RackId + "' and task_id = '" + taskId + "'"
+				updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(FAILED) + "' WHERE  BoxBarCode = '" + v.RackId + "' and task_id = '" + taskId + "'"
 				this.DBE.Exec(updTaskSql)
 				continue
 			}
@@ -460,11 +457,11 @@ func (this *ArrangeService) GetAbnormalDataAndUpdate(taskId string, entity Respo
 
 			// 根据架编码,任务Id 查询 任务信息, 任务存在更新状态
 			// 更新任务明细信息
-			updatesql := "UPDATE " + TABLE_ARRANGE_DETAIL + " SET taskstatus = '" + strconv.Itoa(FAILED) + "' WHERE ShelfId = " +strconv.Itoa( shelf.Id)+ " AND parentid = '" + strconv.Itoa(arrangeMain.Id) + "'"
+			updatesql := "UPDATE " + TABLE_ARRANGE_DETAIL + " SET taskstatus = '" + strconv.Itoa(FAILED) + "' WHERE ShelfId = " + strconv.Itoa(shelf.Id) + " AND parentid = '" + strconv.Itoa(arrangeMain.Id) + "'"
 			this.DBE.Exec(updatesql)
 
 			// 更新任务状态
-			updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(FAILED) + "' WHERE  ShelfId = " +strconv.Itoa( shelf.Id)+ "and task_id = '" + taskId + "'"
+			updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(FAILED) + "' WHERE  ShelfId = " + strconv.Itoa(shelf.Id) + "and task_id = '" + taskId + "'"
 			this.DBE.Exec(updTaskSql)
 		}
 	}
@@ -483,7 +480,7 @@ func (this *ArrangeService) GetArrangeMain(entryNo string) Bank_Arrange_Main {
 	sql := "SELECT * FROM bank_arrange_main WHERE " + where
 	//results, err := this.DBE.Query(sql)
 	//fmt.Println(results)
-	_,err := this.DBE.SQL(sql).Get(&entity)
+	_, err := this.DBE.SQL(sql).Get(&entity)
 	fmt.Println("执行错误:", err)
 	return entity
 }
@@ -495,8 +492,8 @@ func (this *ArrangeService) GetArrangeMain(entryNo string) Bank_Arrange_Main {
  * @Param
  * @return
  **/
-func (this *ArrangeService) GetAllBox(taskId string)  {
+func (this *ArrangeService) GetAllBox(taskId string) {
 	arrangeMain := this.GetArrangeMain(taskId)
-	sql := "update bank_box a set a.IsEmpty = (case when (select count(b.Id) from bank_sample b where a.Id = b.BoxId) > 0 then 0 else 1 end) where a.EquipmentId = '"+utils.ToStr(arrangeMain.EquipmentId)+"'"
+	sql := "update bank_box a set a.IsEmpty = (case when (select count(b.Id) from bank_sample b where a.Id = b.BoxId) > 0 then 0 else 1 end) where a.EquipmentId = '" + utils.ToStr(arrangeMain.EquipmentId) + "'"
 	this.DBE.Exec(sql)
 }

+ 64 - 44
src/dashoo.cn/genepoint_srv/business/converseService/converse.go

@@ -15,7 +15,6 @@ const REJECT = 7
 const EXCEPTION = 8
 const RACKRETRIEVING = 9
 
-
 const SAMPLE_STATUS_OUT = 5
 const SAMPLE_STATUS_IN = 2
 const TASK_TUBE_STORING = 1
@@ -44,7 +43,7 @@ type RequestData struct {
 	Rack_id        string        `json:"rack_id,omitempty"`
 	Tube_id        string        `json:"tube_id,omitempty"`
 	Task_id        string        `json:"task_id,omitempty"`
-	Operation_user        string        `json:"operation_user,omitempty"`  //
+	Operation_user string        `json:"operation_user,omitempty"` //
 	Task_data      interface{}   `json:"task_data,omitempty"`
 	List           []interface{} `json:"list,omitempty"`
 	Operation_mode string        `json:"operation_mode,omitempty"`
@@ -54,8 +53,8 @@ type RequestData struct {
 	Group          int           `json:"group,omitempty"`
 	Unit           int           `json:"unit,omitempty"`
 	Pos            int           `json:"pos,omitempty"`
-	Name           string 			`json:"name"`
-	Initiator      string `json:"initiator"`
+	Name           string        `json:"name"`
+	Initiator      string        `json:"initiator"`
 }
 
 type ResponseData struct {
@@ -64,14 +63,16 @@ type ResponseData struct {
 	Key            string        `json:"key,omitempty"`
 	Task_id        string        `json:"task_id,omitempty"`
 	Task_msg       []interface{} `json:"task_msg,omitempty"`
-	Msg       	   string      `json:"msg,omitempty"`
+	Msg            string        `json:"msg,omitempty"`
 	Causes         []Cause       `json:"causes,omitempty"`
 	Is_end         bool          `json:"is_end,omitempty"`
 	Execution_time int           `json:"execution_time,omitempty"`
+	Cu             int           `json:"cu,omitempty"`
 	Exceptions     []Exception   `json:"exceptions,omitempty"`
 	Actual_data    []Single      `json:"actual_data,omitempty"`
 	Abnormal_data  Abmormal_data `json:"abnormal_data,omitempty"`
-	List           []List_Data   `json:"list,omitempty"`
+
+	List []List_Data `json:"list,omitempty"`
 }
 
 type List_Data struct {
@@ -150,6 +151,7 @@ type Tube struct {
 	S_no int    `json:"s_no,omitempty"`
 	Oper bool   `json:"oper,omitempty"`
 }
+
 // 正常入库的结构体
 type Single struct {
 	Rack       int    `json:"rack,omitempty"`
@@ -161,26 +163,25 @@ type Single struct {
 	Tubes      []Tube `json:"tubes"`
 	Exceptions []int  `json:"exceptions,omitempty"`
 }
+
 /**
  *出库的结构体    不需要   Target
  */
 type OutSingle struct {
-	Rack       int    `json:"rack,omitempty"`
-	Tube       int    `json:"tube,omitempty"`
-	Id         string `json:"id,omitempty"`
-	Rack_id    string `json:"rack_id,omitempty"`
+	Rack    int    `json:"rack,omitempty"`
+	Tube    int    `json:"tube,omitempty"`
+	Id      string `json:"id,omitempty"`
+	Rack_id string `json:"rack_id,omitempty"`
 	//Source     Source `json:"source,omitempty"`
 	//Target     Target `json:"target,omitempty"`
 	Tubes      []Tube `json:"tubes"`
 	Exceptions []int  `json:"exceptions,omitempty"`
 }
 
-
-
 type Cause struct {
-	Cu     int `json:"cu"`
-	Reason int `json:"reason"`
-	Msg string `json:"msg"`
+	Cu     int    `json:"cu"`
+	Reason int    `json:"reason"`
+	Msg    string `json:"msg"`
 }
 
 type Exception struct {
@@ -229,7 +230,7 @@ type Sample_Storage_Task struct {
 	OperaMode   string
 	Exception   string `xorm:"VARCHAR(512)"`
 	Remark      string
-	SourceBox   string   // 源盒编码
+	SourceBox   string // 源盒编码
 }
 
 type Id struct {
@@ -295,23 +296,23 @@ type Bank_Apply_Main struct {
 type Equipment struct {
 	Name string
 }
+
 // 盒子规格信息
 type Box struct {
-	EquipmentId  string // 容器id
-	ShelfId  string  // 冻存架id
-	Id  int    // 盒子id
-	ColumnNum int		// 盒子列数
-	RowNum int          //盒子行数
-	XStation   int   // 位置 X代表第几列
-	YStation   int    // 位置 Y代表第几行
+	EquipmentId string // 容器id
+	ShelfId     string // 冻存架id
+	Id          int    // 盒子id
+	ColumnNum   int    // 盒子列数
+	RowNum      int    //盒子行数
+	XStation    int    // 位置 X代表第几列
+	YStation    int    // 位置 Y代表第几行
 }
 type EquipmentInfo struct {
-	Id  int    // id
-	Code  string     // 编码
-	Name string   // 名称
+	Id   int    // id
+	Code string // 编码
+	Name string // 名称
 }
 
-
 type Bank_Equipment struct {
 	Id             int       `xorm:"not null pk autoincr INT(10)"`
 	AccCode        string    `xorm:"VARCHAR(10)"`
@@ -320,7 +321,7 @@ type Bank_Equipment struct {
 	Name           string    `xorm:"VARCHAR(255)"`
 	Brand          string    `xorm:"VARCHAR(255)"`
 	Cu             int       `xorm:"INT(2)"`
-	Ltu             int       `xorm:"INT(2)"`
+	Ltu            int       `xorm:"INT(2)"`
 	ModelVersion   string    `xorm:"VARCHAR(255)"`
 	Item           int       `xorm:"INT(10)"`
 	EncodingType   int       `xorm:"INT(10)"`
@@ -349,30 +350,49 @@ type Bank_Equipment struct {
 	RoomId         int       `xorm:"INT(11)"` // 房间ID
 }
 
-
-
-
 // 冻存架信息
 type Shelf struct {
-	EquipmentId  int // 设备id
-	Code  string   // 容器编码
-	Name  string   // 容器名称
-	Id int // 冻存架id
-	XStation   int   // 位置 X代表第几列
-	YStation   int    // 位置 Y代表第几行
+	EquipmentId int    // 设备id
+	Code        string // 容器编码
+	Name        string // 容器名称
+	Id          int    // 冻存架id
+	XStation    int    // 位置 X代表第几列
+	YStation    int    // 位置 Y代表第几行
 }
 
 // 自动库内整理结构体
 type Arrange struct {
-	Logic_id int `json:"logic_id"`
-	Position Position	`json:"position,omitempty"`
+	Logic_id int      `json:"logic_id"`
+	Position Position `json:"position,omitempty"`
 }
 
 // 整理范围结构体
 type Position struct {
-	Cu int	`json:"cu"`
-	Ltu int	`json:"ltu"`
-	Group int	`json:"group"`
-	Unit int	`json:"unit"`
-	Pos int	`json:"pos"`
+	Cu    int `json:"cu"`
+	Ltu   int `json:"ltu"`
+	Group int `json:"group"`
+	Unit  int `json:"unit"`
+	Pos   int `json:"pos"`
+}
+
+// 同步位置信息返回结构体信息
+type SamplePostion struct {
+	Response string            `json:"response"`
+	Result   int               `json:"result"`
+	Time     string            `json:"time"`
+	Data     SamplePostionData `json:"data,omitempty"`
+}
+
+type SamplePostionData struct {
+	Cu      int    `json:"cu"`
+	Ltu     int    `json:"ltu"`
+	Group   int    `json:"group"`
+	Unit    int    `json:"unit"`
+	Pos     int    `json:"pos"`
+	Rack_id string `json:"rack_id"`
+	List    []List `json:"list"`
+}
+type List struct {
+	No int    `json:"no"`
+	Id string `json:"id"`
 }

+ 281 - 97
src/dashoo.cn/genepoint_srv/business/converseService/converseService.go

@@ -5,17 +5,19 @@ import (
 	"dashoo.cn/genepoint_srv/business/arrangeService"
 	"dashoo.cn/genepoint_srv/business/common"
 	"fmt"
-	"github.com/Unknwon/com"
+	"github.com/gogf/gf/util/gconv"
+	"github.com/unknwon/com"
+
 	"github.com/gogf/gf/os/glog"
 	"log"
 	"strconv"
 	"strings"
 	"time"
 
-	"github.com/go-xorm/xorm"
+	"xorm.io/xorm"
 
-	"dashoo.cn/utils"
-	. "dashoo.cn/utils/db"
+	"dashoo.cn/base_common/utils"
+	. "dashoo.cn/base_common/utils/db"
 )
 
 const CU = 1
@@ -37,7 +39,7 @@ const STATUS_UNLOCK = "0"
 const RK_PASS = "2"
 const CK_PASS_ONHOLD = "3" //保留位置
 const CK_PASS_DONE = "4"   //已归档
-const LOGIC_ID = "0"   // 逻辑分区Id
+const LOGIC_ID = "0"       // 逻辑分区Id
 
 type ConverseService struct {
 	ServiceBase
@@ -150,7 +152,6 @@ func (this *ConverseService) GetNewTaskBasic() []Sample_Storage_Task {
 		log.Println(err)
 	}
 
-
 	return tasks
 }
 
@@ -416,29 +417,29 @@ func handleQueryTube(entity *RequestEntity, detail *Sample_Storage_Task) {
  * @Param
  * @return
  **/
-func handleArrange (entity *RequestEntity, detail *Sample_Storage_Task) {
+func handleArrange(entity *RequestEntity, detail *Sample_Storage_Task) {
 	var ones []Arrange
 
 	if entity.Data.Task_data != nil {
-		ones  = entity.Data.Task_data.([]Arrange)
+		ones = entity.Data.Task_data.([]Arrange)
 	}
 	if entity.Data.Operation_mode == "" {
 		entity.Data.Operation_mode = detail.OperaMode
 	}
 
 	position := Position{
-		Cu: detail.Cu,
-		Ltu:  detail.Ltu,
-		Group:  detail.Group,
+		Cu:    detail.Cu,
+		Ltu:   detail.Ltu,
+		Group: detail.Group,
 		Unit:  detail.Unit,
-		Pos:  detail.Pos,
+		Pos:   detail.Pos,
 	}
 	one := Arrange{
 		Logic_id: 0,
-		Position:  position,
+		Position: position,
 	}
 
-	ones = append(ones,one )
+	ones = append(ones, one)
 	entity.Data.Operation_mode = detail.OperaMode
 	entity.Data.Initiator = "genepoint"
 	entity.Data.Name = "库内整理"
@@ -449,20 +450,12 @@ func handleArrange (entity *RequestEntity, detail *Sample_Storage_Task) {
  * 卢传敏
  * 响应报文,任务执行提示
  */
-func handleTaskActivate(entity *RequestEntity, detail *Sample_Storage_Task){
+func handleTaskActivate(entity *RequestEntity, detail *Sample_Storage_Task) {
 
 }
 
-
-
-
-
-
-
-
-
 // 查询申请单详情下状态,存在一条子任务失败的情况,则整个申请单状态为失败
-func (this *ConverseService) StatusModifyWithDetail(task_id string,res ResponseEntity) error {
+func (this *ConverseService) StatusModifyWithDetail(task_id string, res ResponseEntity) error {
 	status := SUCCESS
 	// 关联查询申请详情表,申请主表中指定申请单下执行状态不为success的申请详情数量
 
@@ -485,7 +478,7 @@ func (this *ConverseService) StatusModifyWithDetail(task_id string,res ResponseE
 		status = FAILED
 	}
 
-	if res.Data.Type =="abnormal_end"{
+	if res.Data.Type == "abnormal_end" {
 		status = EXCEPTION
 	}
 
@@ -493,21 +486,17 @@ func (this *ConverseService) StatusModifyWithDetail(task_id string,res ResponseE
 	//updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(status) + "' WHERE task_id = '" + task_id + "'"
 	//_, err = this.DBE.Exec(updTaskSql)
 
-
-
-	set :=""
-	if res.Data.Type =="end" {
+	set := ""
+	if res.Data.Type == "end" {
 		set = "  ,exception='' "
 	}
 
 	// 更新申请主表状态
-	updApplySql := "UPDATE " + TABLE_SAMPLE_APPLY + " SET taskstatus = '" + strconv.Itoa(status) + "' "+set+"  WHERE entryno = '" + task_id + "'"
+	updApplySql := "UPDATE " + TABLE_SAMPLE_APPLY + " SET taskstatus = '" + strconv.Itoa(status) + "' " + set + "  WHERE entryno = '" + task_id + "'"
 	_, err := this.DBE.Exec(updApplySql)
 	return err
 }
 
-
-
 //修改任务表状态码
 func (this *ConverseService) TaskStatusModify(statusCode int, task_id string) error {
 	sql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(statusCode) + "'   WHERE task_id = '" + task_id + "'"
@@ -516,14 +505,14 @@ func (this *ConverseService) TaskStatusModify(statusCode int, task_id string) er
 }
 
 // 修改出入库单状态
-func (this *ConverseService) SampleApplyStatusModify(statusCode int, entryNo,msg string) error {
+func (this *ConverseService) SampleApplyStatusModify(statusCode int, entryNo, msg string) error {
 	set := "    "
-	if statusCode == 1 || statusCode == 2 || statusCode == 3 || statusCode == 5   {
+	if statusCode == 1 || statusCode == 2 || statusCode == 3 || statusCode == 5 {
 		set = "  ,exception='' "
-	}else{
-		if msg!=""{
-			set = "  ,exception='"+msg+"' "
-		}else{
+	} else {
+		if msg != "" {
+			set = "  ,exception='" + msg + "' "
+		} else {
 			set = "  ,exception='' "
 		}
 	}
@@ -547,8 +536,6 @@ func (this *ConverseService) SampleApplyDetailStatusModify(statusCode int, entry
 	return err
 }
 
-
-
 //任务执行驳回, 修改全部样本失败状态
 func (this *ConverseService) ModifySampleAllRejectStatus(res ResponseEntity) error {
 	//获取出入库单Id
@@ -561,12 +548,10 @@ func (this *ConverseService) ModifySampleAllRejectStatus(res ResponseEntity) err
 	return err
 }
 
-
 //修改样本失败状态
 
-
 func (this *ConverseService) handleSampleFailed(idsStr string, response string, parentId int) {
-	if (strings.Contains(response, "tube_")) {
+	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)
@@ -594,7 +579,7 @@ func (this *ConverseService) sampleRKSuccessDBModify(idsStr string, parentId int
 	// add by 徐春林  基点入库成功, 根据样本入库详情表中 更新 样本的 剩余容量
 	var list []Bank_Apply_Detail
 	// add by 徐春林 20211224 添加主单Id 作为条件
-	err := this.DBE.Where("barcode IN (" + idsStr + ")  and ParentId = '" + strconv.Itoa(parentId)+"'").Find(&list)
+	err := this.DBE.Where("barcode IN (" + idsStr + ")  and ParentId = '" + strconv.Itoa(parentId) + "'").Find(&list)
 	for _, one := range list {
 		fmt.Println("更新入库容量:", one.BarCode)
 		sql := "UPDATE " + TABLE_SAMPLE + " a SET Capacity = (SELECT Capacity from " + TABLE_APPLY_DETAIL + " b where b.BarCode = '" + one.BarCode + "' and b.ParentId = '" + strconv.Itoa(parentId) + "' ) Where barcode = '" + one.BarCode + "'"
@@ -616,12 +601,12 @@ func (this *ConverseService) sampleCKSuccessDBModify(idsStr string, parentId int
 	var onHold []string
 	var done []string
 	// add by 徐春林 20211224 添加主单Id 作为条件
-	err := this.DBE.Where("barcode IN (" + idsStr + ")   and ParentId = '" + strconv.Itoa(parentId)+"'").Find(&list)
+	err := this.DBE.Where("barcode IN (" + idsStr + ")   and ParentId = '" + strconv.Itoa(parentId) + "'").Find(&list)
 	for _, one := range list {
 		// add by   记录冻融次数
 		//beforeSql := "UPDATE "+TABLE_SAMPLE+" a SET a.FreezingNum = ( select   FreezingNum    from "+TABLE_APPLY_DETAIL+" b where b.BarCode = '"+one.BarCode+"' and b.ParentId = '"+ strconv.Itoa(parentId)+"' ) Where barcode = '"+one.BarCode+"'"
-		beforeSql := "UPDATE "+TABLE_SAMPLE+" a SET a.FreezingNum = (a.FreezingNum +1 )    Where barcode = '"+one.BarCode+"'"
-		_,err =this.DBE.Exec(beforeSql)
+		beforeSql := "UPDATE " + TABLE_SAMPLE + " a SET a.FreezingNum = (a.FreezingNum +1 )    Where barcode = '" + one.BarCode + "'"
+		_, err = this.DBE.Exec(beforeSql)
 		if strconv.Itoa(one.RecoveryId) == CK_PASS_ONHOLD {
 			// 查询样本出库详情, 更新 取出帶放回
 			onHold = append(onHold, one.BarCode)
@@ -660,7 +645,7 @@ func (this *ConverseService) ModifySampleStatusByApplyMainInfo(entryNo string, r
 	// 此处判断,如果是冻存盒整盒入库,需要更新盒子位置信息  盒  冻存盒当前的 所在的冻存架的id
 	if resp == "rack_storing" {
 		fmt.Println("冻存盒入库")
-		this.UpdateBoxInfo(entity,applyMain.Id)
+		this.UpdateBoxInfo(entity, applyMain.Id)
 	}
 
 	if applyMain.ApplyType == TASK_TUBE_STORING && strings.Contains(resp, "_storing") {
@@ -694,15 +679,15 @@ func (this *ConverseService) ModifySampleStatusByApplyMainInfo(entryNo string, r
 		//operaIds, abnormalIds = this.getAllSampleIdsFromResEntity(entity)
 		operaIds, abnormalIds = this.getOperaSampleIdsStr(applyMain.ApplyType, applyMain.Id, resp, entity)
 		// 管出库需要 更新 转运空盒 为 源盒
-		this.UpdateBoxInfoCK(entity,applyMain.Id)
+		this.UpdateBoxInfoCK(entity, applyMain.Id)
 	}
 
 	// 此处判断,如果是冻存盒整盒入库,需要更新盒子位置信息  盒  冻存盒当前的 所在的冻存架的id
-	  if resp == "rack_retrieving" {
+	if resp == "rack_retrieving" {
 		fmt.Println("冻存盒出库")
 		//rack_retrieving
 		// 冻存盒出库任务完成以后,需要清空冻存盒中的冻存架信息,同时清空
-		this.UpdateBoxInfoCK(entity,applyMain.Id)
+		this.UpdateBoxInfoCK(entity, applyMain.Id)
 	}
 
 	// 根据管操作 或 盒操作 判断是否执行以下更新
@@ -716,7 +701,7 @@ func (this *ConverseService) ModifySampleStatusByApplyMainInfo(entryNo string, r
 
 //2021/01/09 by 卢传敏
 // 根据入库返回报文,更新 冻存盒的信息盒
-func (this *ConverseService) UpdateBoxInfo(entity ResponseEntity,parentId int) (err error) {
+func (this *ConverseService) UpdateBoxInfo(entity ResponseEntity, parentId int) (err error) {
 	//1.  获取当前返回的  冻存架信息,
 	var shelf Shelf
 	var equipment Bank_Equipment
@@ -724,7 +709,7 @@ func (this *ConverseService) UpdateBoxInfo(entity ResponseEntity,parentId int) (
 	glog.Info("entity.Data.Actual_data::", entity.Data.Actual_data)
 
 	// 判断是否存在处理成功的数据
-	if len(entity.Data.Actual_data) > 0{
+	if len(entity.Data.Actual_data) > 0 {
 		// 循环处理返回的数据,如果出现多盒存入的分批处理
 		for i := range entity.Data.Actual_data {
 
@@ -739,36 +724,39 @@ func (this *ConverseService) UpdateBoxInfo(entity ResponseEntity,parentId int) (
 
 			fmt.Println("保存返回的冻存盒位置信息:cu:", Cu, ",Ltu", Ltu, ",Unit", Unit, ",Group", Group, ",Pos", Pos)
 
-
 			// 判断是否是冷库,如果是冷库的话,查询容器架子信息时不需要组装 unit
 			lengSql := " select  * from bank_equipment    where  cu = '" + utils.ToStr(Cu) + "'  and    Ltu = '" + utils.ToStr(Ltu) + "'  "
 			this.DBE.SQL(lengSql).Get(&equipment)
 
-			sql  := "select b.id EquipmentId,b.code,b.name,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) + "' " +
+			sql := "select b.id EquipmentId,b.code,b.name,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.Group ='" + utils.ToStr(Group) + "'"
 			// 冷库设备
-			YStation:="  "
-			if equipment.Ltu  == 0    {
+			YStation := "  "
+			if equipment.Ltu == 0 {
 				sql += "  and a.Unit ='" + utils.ToStr(Unit) + "'   "
-				YStation  = " , YStation =1  "
-				fmt.Println("保存返回的冻存盒位置信息:YStation1:1 ",  YStation)
-			}else{
-				YStation  = " ,   YStation =    "+ utils.ToStr(Unit)
-				fmt.Println("保存返回的冻存盒位置信息:cYStation1:2 ",  YStation)
+				YStation = " , YStation =1  "
+				fmt.Println("保存返回的冻存盒位置信息:YStation1:1 ", YStation)
+			} else {
+				YStation = " ,   YStation =    " + utils.ToStr(Unit)
+				fmt.Println("保存返回的冻存盒位置信息:cYStation1:2 ", YStation)
 			}
 
 			this.DBE.SQL(sql).Get(&shelf)
-			fmt.Println("冻存架信息:",shelf.Code,shelf.Name, shelf.Id, shelf.XStation, shelf.YStation)
+			fmt.Println("冻存架信息:", shelf.Code, shelf.Name, shelf.Id, shelf.XStation, shelf.YStation)
 
 			//  更新盒所在的冻存架的信息  计算位置信息,并更新
 			// 临时处理逻辑,默认 pos 为 盒子的  XStation
 			pos := shelf.Code + "-" + common.Boxlinename(shelf.YStation) + utils.ToStr(shelf.XStation) + "-" +
-				"" + common.Boxlinename(    Unit  ) + utils.ToStr(utils.ToStr(Pos))
+				"" + common.Boxlinename(Unit) + utils.ToStr(utils.ToStr(Pos))
 
-			possql := "update bank_box set XStation ='" + utils.ToStr(Pos) + "'  "+YStation+"," +
+			//  冻存盒入库需要先校验,当前盒子是否存在样本,如果不存在,则证明盒子为空盒,修改冻存盒状态为空盒
+			IsEmptysql := "update bank_box a set a.IsEmpty = (case when (select count(b.Id) from bank_sample b where    b.DeletionStateCode!=1 and    a.Id = b.BoxId  ) > 0 then 0 else 1 end) where a.Barcode = '" + boxBarcode + "'"
+			this.DBE.Exec(IsEmptysql)
+
+			possql := "update bank_box set XStation ='" + utils.ToStr(Pos) + "'  " + YStation + "," +
 				" EquipmentId ='" + com.ToStr(shelf.EquipmentId) + "'," +
 				" shelfId =" + utils.ToStr(shelf.Id) + ",IsLocked = 0 ," +
-				" Position  ='"+pos+"'" +
+				" Position  ='" + pos + "'" +
 				"  where Barcode ='" + boxBarcode + "' "
 			// 冷库设备
 			_, err = this.DBE.Exec(possql)
@@ -777,12 +765,12 @@ func (this *ConverseService) UpdateBoxInfo(entity ResponseEntity,parentId int) (
 
 		}
 	}
-	err = this.UpdateBoxAbnormalInfo(entity,parentId)
+	err = this.UpdateBoxAbnormalInfo(entity, parentId)
 	return err
 
 }
 
-func (this *ConverseService) UpdateBoxAbnormalInfo(entity ResponseEntity,parentId int) (err error) {
+func (this *ConverseService) UpdateBoxAbnormalInfo(entity ResponseEntity, parentId int) (err error) {
 	glog.Info("entity.Data.Abnormal_data::", entity.Data.Abnormal_data)
 	AbnormalRack := ""
 	// 判断是否存在处理失败的数据
@@ -792,20 +780,20 @@ func (this *ConverseService) UpdateBoxAbnormalInfo(entity ResponseEntity,parentI
 		if len(rackEntity) > 0 {
 			for _, v := range rackEntity {
 				// 不为空则需要将数据取出
-				AbnormalRack +=  v.Rack_id + ","
+				AbnormalRack += v.Rack_id + ","
 			}
-			AbnormalRack = AbnormalRack[0 : len(AbnormalRack) -1]
+			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)
+			_, 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)
+			_, err = this.DBE.Exec(updTaskSql)
 			if err != nil {
 				return err
 			}
@@ -817,7 +805,7 @@ func (this *ConverseService) UpdateBoxAbnormalInfo(entity ResponseEntity,parentI
 
 //2021/01/09 by 卢传敏
 // 根据出库返回报文,更新 冻存盒的信息盒
-func (this *ConverseService) UpdateBoxInfoCK(entity ResponseEntity,parentId int) (err error) {
+func (this *ConverseService) UpdateBoxInfoCK(entity ResponseEntity, parentId int) (err error) {
 	//1.  获取当前返回的  冻存架信息,
 	var shelf Shelf
 
@@ -840,19 +828,19 @@ func (this *ConverseService) UpdateBoxInfoCK(entity ResponseEntity,parentId int)
 		// 更新 当前冰箱冻存盒容量 信息
 		_, err = this.DBE.Exec(" update bank_currboxcapacity  set  `A" + utils.ToStr(Pos) + "`= -2 where shelfId =" + utils.ToStr(shelf.Id) + "")
 		updatesql := "UPDATE " + TABLE_DETAIL + " SET taskstatus = '" + strconv.Itoa(SUCCESS) + "' WHERE parentid = '" + strconv.Itoa(parentId) + "'"
-		_,err = this.DBE.Exec(updatesql)
+		_, err = this.DBE.Exec(updatesql)
 		if err != nil {
 			return err
 		}
 		// 更新任务状态
-		updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(SUCCESS) + "' WHERE  BoxBarcode = '" + boxBarcode + "' and task_id = '"+TaskId+"'"
-		_,err =this.DBE.Exec(updTaskSql)
+		updTaskSql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(SUCCESS) + "' WHERE  BoxBarcode = '" + boxBarcode + "' and task_id = '" + TaskId + "'"
+		_, err = this.DBE.Exec(updTaskSql)
 		if err != nil {
 			return err
 		}
 	}
 
-	err = this.UpdateBoxAbnormalInfo(entity,parentId)
+	err = this.UpdateBoxAbnormalInfo(entity, parentId)
 	return err
 
 }
@@ -867,9 +855,9 @@ func (this *ConverseService) UpdateBoxInfoCK(entity ResponseEntity,parentId int)
 func (this *ConverseService) UpdateBoxIsLocked(taskId string) (err error) {
 	var task Sample_Storage_Task
 
-	 sql := "SELECT id FROM " + TABLE_TAST + " WHERE taskId = '" + taskId + "'"
+	sql := "SELECT id FROM " + TABLE_TAST + " WHERE taskId = '" + taskId + "'"
 
-	 err = this.DBE.SQL(sql).Find(&task)
+	err = this.DBE.SQL(sql).Find(&task)
 
 	_, err = this.DBE.Exec("update bank_box set IsLocked = 0  where Barcode ='" + task.BoxId + "' ")
 	return err
@@ -895,24 +883,19 @@ func (this *ConverseService) UpdateDetail(BarCode string, entity ResponseEntity,
 		//当  检测到数据 与当前操作盒子的数据一直时,更新  detail   和sample 信息
 		if entity.Data.Actual_data[i].Target.Rack_id == rack_id {
 
-
-
-			fmt.Println("保存返回的冻存盒位置信息:cu:", Cu, ",Ltu", Ltu, ",Unit", Unit, ",Group", Group  )
-
+			fmt.Println("保存返回的冻存盒位置信息:cu:", Cu, ",Ltu", Ltu, ",Unit", Unit, ",Group", Group)
 
 			// 判断是否是冷库,如果是冷库的话,查询容器架子信息时不需要组装 unit
 			lengSql := " select  * from bank_equipment    where  cu = '" + utils.ToStr(Cu) + "'  and    Ltu = '" + utils.ToStr(Ltu) + "'  "
 			this.DBE.SQL(lengSql).Get(&equipment)
 
-
 			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.Group ='" + utils.ToStr(Group) + "'"
 			// 冷库设备
-			if equipment.Ltu ==0 {
+			if equipment.Ltu == 0 {
 				sql += "  and a.Unit ='" + utils.ToStr(Unit) + "' "
 			}
 
-
 			this.DBE.SQL(sql).Get(&shelf)
 			equipmentid = strconv.Itoa(shelf.EquipmentId)
 			ShelfId = strconv.Itoa(shelf.Id)
@@ -935,19 +918,18 @@ func (this *ConverseService) UpdatePosition(rack_id string, tubes []Tube, entity
 	sql := "select Id,RowNum,ColumnNum,EquipmentId,ShelfId,XStation,YStation   from bank_box where Barcode ='" + rack_id + "'"
 	var box Box
 	this.DBE.SQL(sql).Get(&box)
-	glog.Info("盒信息: ",  box)
-	glog.Info("容器Id: ", box.EquipmentId, ";字符串:", utils.ToStr( box.EquipmentId))
+	glog.Info("盒信息: ", box)
+	glog.Info("容器Id: ", box.EquipmentId, ";字符串:", utils.ToStr(box.EquipmentId))
 	// 根据盒子信息获取容器和冻存架信息, 用于更新样本孔位信息
 	//  获取容器信息
-	equipmentsql := " select Id,Code,Name from bank_equipment where id = '"+  box.EquipmentId+"'   "
+	equipmentsql := " select Id,Code,Name from bank_equipment where id = '" + box.EquipmentId + "'   "
 	var equipmentInfo EquipmentInfo
 	this.DBE.SQL(equipmentsql).Get(&equipmentInfo)
 	//  获取架子信息
-	shelfsql := " select Id,XStation,YStation from bank_shelf where id = '"+box.ShelfId+"'   "
+	shelfsql := " select Id,XStation,YStation from bank_shelf where id = '" + box.ShelfId + "'   "
 	var shelf Shelf
 	this.DBE.SQL(shelfsql).Get(&shelf)
 
-
 	RowNum := box.RowNum
 	ColumnNum := box.ColumnNum
 	glog.Info("冻存盒的行数:", RowNum, ";冻存盒的列数:", ColumnNum)
@@ -972,16 +954,15 @@ func (this *ConverseService) UpdatePosition(rack_id string, tubes []Tube, entity
 		position := equipmentInfo.Code + "-" + common.Boxlinename(shelf.YStation) + utils.ToStr(shelf.XStation) + "-" +
 			"" + common.Boxlinename(box.YStation) + utils.ToStr(box.XStation) + "-" + common.Boxlinename(box_x) + utils.ToStr(box_y)
 		sql = "update bank_sample set BoxId = '" + utils.ToStr(box.Id) + "',Position = '" + utils.ToStr(box_y) + ";" +
-			"" + utils.ToStr(box_x) + "',PositionInfo = '"+position+"'  " +
+			"" + utils.ToStr(box_x) + "',PositionInfo = '" + position + "'  " +
 			// " , unit =  '"+  utils.ToStr( entity.Data.Actual_data[i].Target.Unit)+"'" +
 			"    where barcode ='" + id + "' "
 		//执行sql 更新位置和坐标信息
 		this.DBE.Exec(sql)
 
-
 		this.UpdateDetail(id, entity, parentId, rack_id)
 		//卢传敏  新增更新盒子位置信息操作,因为新的业务处理,冻存管必须放在冻存盒中才能入库
-		this.UpdateBoxInfo(entity,parentId)
+		this.UpdateBoxInfo(entity, parentId)
 	}
 }
 
@@ -1073,8 +1054,6 @@ func (this *ConverseService) getAllSampleIdsFromResEntity(entity ResponseEntity)
 	return
 }
 
-
-
 //保存异常信息
 func (this *ConverseService) SaveTaskExcepMsg(msg, taskId string) error {
 	sql := "UPDATE " + TABLE_TAST + " SET exception = '" + msg + "' WHERE task_id = '" + taskId + "'"
@@ -1213,7 +1192,7 @@ func RecordDeviceData(list []List_Data) {
 }
 
 // 更新异常信息
-func (s *ConverseService) SaveErrInfo(err, taskid string,reqType string) {
+func (s *ConverseService) SaveErrInfo(err, taskid string, reqType string) {
 	// 任务发送失败,,,修改任务状态,,,,提示任务执行失败
 	// 请求发送失败
 
@@ -1228,3 +1207,208 @@ func (s *ConverseService) SaveErrInfo(err, taskid string,reqType string) {
 		svc.SaveSampleExcepMsg(err, taskid)
 	}
 }
+
+// 修改同步申请库单状态
+func (this *ConverseService) ApplyStatusModify(statusCode int, entryNo, msg string) error {
+	set := "    "
+	if statusCode == 1 || statusCode == 2 || statusCode == 3 || statusCode == 5 {
+		set = "  ,exception='' "
+	} else {
+		if msg != "" {
+			set = "  ,exception='" + msg + "' "
+		} else {
+			set = "  ,exception='' "
+		}
+	}
+
+	sql := "UPDATE " + "bank_synchronization_main" + " SET taskstatus = '" + strconv.Itoa(statusCode) + "' " + set + "  " +
+		" WHERE entryno = '" + entryNo + "'   "
+	_, err := this.DBE.Exec(sql)
+	return err
+}
+
+//修改任务表状态码
+func (this *ConverseService) ApplyTaskStatusModify(statusCode int, task_id, rack_id string) error {
+	sql := "UPDATE " + TABLE_TAST + " SET statuscode = '" + strconv.Itoa(statusCode) + "'   WHERE " +
+		" task_id = '" + task_id + "' and BoxBarcode = '" + rack_id + "' "
+	_, err := this.DBE.Exec(sql)
+	return err
+}
+
+// 同步更新盒子位置信息
+func (this *ConverseService) UpdateBoxPosition(res ResponseEntity) {
+
+	for k, v := range res.Data.List {
+		glog.Info("操作地  ", k, "  条数据")
+
+		boxBarcode := v.Rack_id // 冻存盒编号
+		Cu := res.Data.Cu       // 设备编号
+		Ltu := v.Ltu            //
+		Unit := v.Unit
+		Pos := v.Pos
+		Group := v.Group
+
+		fmt.Println("保存返回的冻存盒位置信息:cu:", Cu, ",Ltu", Ltu, ",Unit", Unit, ",Group", Group, ",Pos", Pos)
+		var shelf Shelf
+		var equipment Bank_Equipment
+		// 判断是否是冷库,如果是冷库的话,查询容器架子信息时不需要组装 unit
+		lengSql := " select  * from bank_equipment    where  cu = '" + utils.ToStr(res.Data.Cu) + "'  and    Ltu = '" + utils.ToStr(Ltu) + "'  "
+		this.DBE.SQL(lengSql).Get(&equipment)
+
+		sql := "select b.id EquipmentId,b.code,b.name,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.Group ='" + utils.ToStr(Group) + "'"
+		// 冷库设备
+		YStation := "  "
+		if equipment.Ltu == 0 {
+			sql += "  and a.Unit ='" + utils.ToStr(Unit) + "'   "
+			YStation = " , YStation =1  "
+			fmt.Println("保存返回的冻存盒位置信息:YStation1:1 ", YStation)
+		} else {
+			YStation = " ,   YStation =    " + utils.ToStr(Unit)
+			fmt.Println("保存返回的冻存盒位置信息:cYStation1:2 ", YStation)
+		}
+
+		this.DBE.SQL(sql).Get(&shelf)
+		fmt.Println("冻存架信息:", shelf.Code, shelf.Name, shelf.Id, shelf.XStation, shelf.YStation)
+
+		//  更新盒所在的冻存架的信息  计算位置信息,并更新
+		// 临时处理逻辑,默认 pos 为 盒子的  XStation
+		pos := shelf.Code + "-" + common.Boxlinename(shelf.YStation) + utils.ToStr(shelf.XStation) + "-" +
+			"" + common.Boxlinename(Unit) + utils.ToStr(utils.ToStr(Pos))
+
+		possql := "update bank_box set XStation ='" + utils.ToStr(Pos) + "'  " + YStation + "," +
+			" EquipmentId ='" + com.ToStr(shelf.EquipmentId) + "'," +
+			" shelfId =" + utils.ToStr(shelf.Id) + ",IsLocked = 0 ," +
+			" Position  ='" + pos + "'" +
+			"  where Barcode ='" + boxBarcode + "' "
+		// 冷库设备
+		this.DBE.Exec(possql)
+		// 更新 当前冰箱冻存盒容量 信息
+		this.DBE.Exec(" update bank_currboxcapacity  set  `A" + utils.ToStr(Pos) + "`= -1 where shelfId =" + utils.ToStr(shelf.Id) + "")
+
+	}
+
+	var task Sample_Storage_Task
+	sql := " select * from Sample_Storage_Task where   " +
+		" cu = '" + gconv.String(res.Data.Cu) + "' " + "  and   Task_type =5  and  StatusCode  =1  "
+	this.DBE.SQL(sql).Get(&task)
+
+	// 跟新任务状态
+	this.DBE.Exec(" update sample_storage_task set StatusCode =5 where   " +
+		" cu = '" + gconv.String(res.Data.Cu) + "' " + "  and   Task_type =5  and  StatusCode  =1  ")
+
+	this.ApplyStatusModify(SUCCESS, task.Task_id, "")
+
+}
+
+// 更新同步返回的位置信息
+func (this *ConverseService) UpdateSamplePosition(res SamplePostion) {
+
+	boxBarcode := res.Data.Rack_id // 冻存盒编号
+	Cu := res.Data.Cu              // 设备编号
+	Ltu := res.Data.Ltu            //
+	Unit := res.Data.Unit
+	Pos := res.Data.Pos
+	Group := res.Data.Group
+
+	fmt.Println("保存返回的冻存盒位置信息:cu:", Cu, ",Ltu", Ltu, ",Unit", Unit, ",Group", Group, ",Pos", Pos)
+	var shelf Shelf
+	var equipment Bank_Equipment
+	// 判断是否是冷库,如果是冷库的话,查询容器架子信息时不需要组装 unit
+	lengSql := " select  * from bank_equipment    where  cu = '" + utils.ToStr(res.Data.Cu) + "'  and    Ltu = '" + utils.ToStr(Ltu) + "'  "
+	this.DBE.SQL(lengSql).Get(&equipment)
+
+	sql := "select b.id EquipmentId,b.code,b.name,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.Group ='" + utils.ToStr(Group) + "'"
+	// 冷库设备
+	YStation := "  "
+	if equipment.Ltu == 0 {
+		sql += "  and a.Unit ='" + utils.ToStr(Unit) + "'   "
+		YStation = " , YStation =1  "
+		fmt.Println("保存返回的冻存盒位置信息:YStation1:1 ", YStation)
+	} else {
+		YStation = " ,   YStation =    " + utils.ToStr(Unit)
+		fmt.Println("保存返回的冻存盒位置信息:cYStation1:2 ", YStation)
+	}
+
+	this.DBE.SQL(sql).Get(&shelf)
+	fmt.Println("冻存架信息:", shelf.Code, shelf.Name, shelf.Id, shelf.XStation, shelf.YStation)
+
+	//  更新盒所在的冻存架的信息  计算位置信息,并更新
+	// 临时处理逻辑,默认 pos 为 盒子的  XStation
+	pos := shelf.Code + "-" + common.Boxlinename(shelf.YStation) + utils.ToStr(shelf.XStation) + "-" +
+		"" + common.Boxlinename(Unit) + utils.ToStr(utils.ToStr(Pos))
+
+	possql := "update bank_box set XStation ='" + utils.ToStr(Pos) + "'  " + YStation + "," +
+		" EquipmentId ='" + com.ToStr(shelf.EquipmentId) + "'," +
+		" shelfId =" + utils.ToStr(shelf.Id) + ",IsLocked = 0 ," +
+		" Position  ='" + pos + "'" +
+		"  where Barcode ='" + boxBarcode + "' "
+	// 冷库设备
+	this.DBE.Exec(possql)
+	// 更新 当前冰箱冻存盒容量 信息
+	this.DBE.Exec(" update bank_currboxcapacity  set  `A" + utils.ToStr(Pos) + "`= -1 where shelfId =" + utils.ToStr(shelf.Id) + "")
+
+	//根据返回的报文中的盒子标识,获取盒子类型
+	boxsql := "select Id,RowNum,ColumnNum,EquipmentId,ShelfId,XStation,YStation   from bank_box where Barcode ='" + res.Data.Rack_id + "'"
+	var box Box
+	this.DBE.SQL(boxsql).Get(&box)
+	glog.Info("盒信息: ", box)
+	glog.Info("容器Id: ", box.EquipmentId, ";字符串:", utils.ToStr(box.EquipmentId))
+	// 根据盒子信息获取容器和冻存架信息, 用于更新样本孔位信息
+
+	RowNum := box.RowNum
+	ColumnNum := box.ColumnNum
+	glog.Info("冻存盒的行数:", RowNum, ";冻存盒的列数:", ColumnNum)
+
+	//  因为每次只会同步一个盒子的数据,所以按照一个盒子的来
+	for _, v := range res.Data.List {
+		no := v.No
+		id := v.Id
+		glog.Info("样本在盒子中的位置:", no, ";样本条码: ", id)
+		//计算管子在盒子中的坐标
+		var box_x, box_y int
+
+		if no%ColumnNum == 0 { // 如果 取余数为0 则 证明该数是能被  10 整除的数  为该行 最后一个孔位
+			box_y = ColumnNum
+			box_x = no / ColumnNum
+		} else {
+			box_y = no % ColumnNum
+			box_x = (no / ColumnNum) + 1
+		}
+
+		glog.Info("管子在盒子中的位置坐标为:", box_y, ";", box_x)
+		//var position = utils.NumberToLetter(box_x) + utils.ToStr(box_y)
+
+		position := shelf.Code + "-" + common.Boxlinename(shelf.YStation) + utils.ToStr(shelf.XStation) + "-" +
+			"" + common.Boxlinename(box.YStation) + utils.ToStr(box.XStation) + "-" + common.Boxlinename(box_x) + utils.ToStr(box_y)
+		sql = "update bank_sample set BoxId = '" + utils.ToStr(box.Id) + "',Position = '" + utils.ToStr(box_y) + ";" +
+			"" + utils.ToStr(box_x) + "',PositionInfo = '" + position + "'  " +
+			// " , unit =  '"+  utils.ToStr( entity.Data.Actual_data[i].Target.Unit)+"'" +
+			"    where barcode ='" + id + "' "
+		//执行sql 更新位置和坐标信息
+		this.DBE.Exec(sql)
+
+	}
+
+	var task Sample_Storage_Task
+	tasksql := " select * from Sample_Storage_Task where   " +
+		" boxBarcode = '" + res.Data.Rack_id + "' " + "  and   Task_type =6  and  StatusCode  =1  "
+	this.DBE.SQL(tasksql).Get(&task)
+
+	// 跟新任务状态
+	this.DBE.Exec(" update sample_storage_task set StatusCode =5 where   " +
+		"  id = " + gconv.String(task.Id) + " ")
+
+	// 判断所有任务是否全部执行完成
+
+	count, _ := this.DBE.Table("  sample_storage_task ").Where(" task_id = '" + task.Task_id + "'").
+		Where(" StatusCode  !=5  ").Count()
+
+	glog.Info("  count   ", count)
+
+	if count == 0 {
+		this.ApplyStatusModify(SUCCESS, task.Task_id, "")
+	}
+
+}

+ 268 - 99
src/dashoo.cn/genepoint_srv/business/test/test_test.go

@@ -3,15 +3,17 @@ package test
 import (
 	"encoding/json"
 	"fmt"
+	"github.com/gogf/gf/os/glog"
+	"github.com/gogf/gf/util/gconv"
+	"log"
 	"strings"
 	"testing"
 	"time"
 
-	"github.com/robfig/cron"
-
+	"dashoo.cn/base_common/utils"
 	converse "dashoo.cn/genepoint_srv/business/converseService"
+
 	conter "dashoo.cn/genepoint_srv/controllers/converse"
-	"dashoo.cn/utils"
 )
 
 const UNEXECUTED = 0
@@ -28,45 +30,196 @@ const SAMPLE_STATUS_IN = 2
 const TASK_TUBE_STORING = 1
 const TASK_TUBE_RETREIVING = 2
 
-func Test_Time1(t *testing.T) {
+var ctrl conter.ConverseController
+
+//func Test_Time1(t *testing.T) {
+//
+//	pingTimer := time.NewTicker(5 * time.Second)
+//	for {
+//		select {
+//		case <-pingTimer.C:
+//			go func() {
+//				fmt.Println("ping msg")
+//			}()
+//		}
+//	}
+//}
+//
+//func Test_Time2(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()
+//}
 
-	pingTimer := time.NewTicker(5 * time.Second)
-	for {
-		select {
-		case <-pingTimer.C:
-			go func() {
-				fmt.Println("ping msg")
-			}()
+// 测试发送报文
+func Test_Trim4(t *testing.T) {
+	// 初始化数据库连接
+	utils.LoadConfig("../../conf/app.conf")
+	// Initialize data.
+	utils.InitDb()
+	controller := conter.ConverseController{}
+	svc := converse.GetConverseService(utils.DBE)
+
+	for i := 0; i < 2; i++ {
+		// 查询任务,生成指令
+		reqMap := controller.SearchDatabase()
+		var err error
+		if err != nil {
+			log.Println("read err:", err)
+			// 任务发送失败,,,修改任务状态,,,,提示任务执行失败
+			for taskid, reqEntity := range reqMap {
+				err = controller.StatusModifyApply(converse.FAILED, taskid, reqEntity.Request, reqEntity.Data.Rack_id, "")
+				svc.SaveErrInfo(err.Error(), taskid, reqEntity.Request)
+			}
 		}
-	}
-}
+		// 发送消息
+		for taskid, reqEntity := range reqMap {
+			log.Println("-reqMap-taskid:", taskid)
 
-func Test_Time2(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)
-	}
+			log.Println("请求发送成功")
+			// 发送成功,修改状态
+			controller.StatusModifyApply(converse.SENT, taskid, reqEntity.Request, reqEntity.Data.Rack_id, "")
 
-	cron.Start()
+		}
+	}
 
-	time.Sleep(time.Second * 10)
-	cron.Stop()
 }
 
-func test_Trim(t *testing.T) {
+func Test_Trim3(t *testing.T) {
 
 	// 初始化数据库连接
 	utils.LoadConfig("../../conf/app.conf")
 	// Initialize data.
 	utils.InitDb()
 
+	//	var paymentData = `
+	//	{
+	//    "response": "stock_rack",
+	//    "result": 200,
+	//    "time": "2018−09−15T13:45:32Z",
+	//    "data": {
+	//        "cu": 11,
+	//        "list": [
+	//            {
+	//                "ltu": 1,
+	//                "group": 1,
+	//                "unit": 1,
+	//                "pos": 1,
+	//                "rack_id": "B20220728000001"
+	//            },
+	//            {
+	//                "ltu": 1,
+	//                "group": 1,
+	//                "unit": 1,
+	//                "pos": 2,
+	//                "rack_id": "B20220728000001"
+	//            },
+	//            {
+	//                "ltu": 1,
+	//                "group": 1,
+	//                "unit": 1,
+	//                "pos": 3,
+	//                "rack_id": "B20220728000001"
+	//            }
+	//        ]
+	//    }
+	//}
+	//`
+	//
+	//
+
+	var paymentData = `
+	{
+    "response": "stock_rack_tube", 
+    "result": 200, 
+    "time": "2018−09−15T13:45:32Z", 
+    "data": {
+        "cu": 11, 
+        "ltu": 1, 
+        "group": 1, 
+        "unit": 1, 
+        "pos": 1, 
+        "rack_id": "B20220728000006", 
+        "list": [
+            {
+                "no": 1, 
+                "id": "794311203768770560"
+            }, 
+            {
+                "no": 2, 
+                "id": "794310386445721600"
+            }, 
+            {
+                "no": 6, 
+                "id": "794299845337686016"
+            }, 
+            {
+                "no": 8, 
+                "id": "794299845216051200"
+            }, 
+            {
+                "no": 9, 
+                "id": "794299845077639168"
+            }
+        ]
+    }
+}
+ 
+		
+`
+
+	var paymentData1 = `
+	{
+    "response": "stock_rack_tube", 
+    "result": 200, 
+    "time": "2018−09−15T13:45:32Z", 
+    "data": {
+        "cu": 11, 
+        "ltu": 1, 
+        "group": 1, 
+        "unit": 1, 
+        "pos": 1, 
+        "rack_id": "B20220728000005", 
+        "list": [
+            {
+                "no": 1, 
+                "id": "794299346572025856"
+            }, 
+            {
+                "no": 2, 
+                "id": "794299346395865088"
+            }, 
+            {
+                "no": 6, 
+                "id": "794299346253258752"
+            }, 
+            {
+                "no": 8, 
+                "id": "794299345930297344"
+            }, 
+            {
+                "no": 9, 
+                "id": "794299061397102592"
+            }
+        ]
+    }
+}
+ 
+	`
+
 	// 定义请求报文
 	//	var paymentData =`{"response":"tube_retrieving",
 	//"result":200,"time":"2020-12-16T08:59:00Z",
@@ -75,66 +228,66 @@ func test_Trim(t *testing.T) {
 	//"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",
-"data":{
-"type":"end",
-"task_id":"426466061139845100_1608100330",
-"is_end":true,
-"execution_time":52,
-"exceptions":[
-{
-"cu":1,
-"codes":[
-30305
-]
-}
-],
-"actual_data":[
-{
-"rack":101,
-"tube":201,
-"rack_id":"B20201221000002",
-"target":{
-"cu":1,
-"ltu":1,
-"group":1,
-"unit":1,
-"pos":1
-},
-"tubes":[
-{
-"no":1,
-"id":"559917887934963712",
-"exception":30305
-},
-{
-"no":2,
-"id":"560616560226476032",
-"exception":30305
-},
-{
-"no":6,
-"id":"560616561790951424",
-"exception":0
-},
-{
-"no":8,
-"id":"560913004158263296",
-"exception":0
-},
-{
-"no":9,
-"id":"560913305091186688",
-"exception":0
-}
-]
-}
-]
-}
-}`
+	//	var paymentData = ` {
+	//"response":"tube_retrieving",
+	//"result":200,
+	//"time":"2018-09-15T13:45:32Z",
+	//"data":{
+	//"type":"end",
+	//"task_id":"426466061139845100_1608100330",
+	//"is_end":true,
+	//"execution_time":52,
+	//"exceptions":[
+	//{
+	//"cu":1,
+	//"codes":[
+	//30305
+	//]
+	//}
+	//],
+	//"actual_data":[
+	//{
+	//"rack":101,
+	//"tube":201,
+	//"rack_id":"B20201221000002",
+	//"target":{
+	//"cu":1,
+	//"ltu":1,
+	//"group":1,
+	//"unit":1,
+	//"pos":1
+	//},
+	//"tubes":[
+	//{
+	//"no":1,
+	//"id":"559917887934963712",
+	//"exception":30305
+	//},
+	//{
+	//"no":2,
+	//"id":"560616560226476032",
+	//"exception":30305
+	//},
+	//{
+	//"no":6,
+	//"id":"560616561790951424",
+	//"exception":0
+	//},
+	//{
+	//"no":8,
+	//"id":"560913004158263296",
+	//"exception":0
+	//},
+	//{
+	//"no":9,
+	//"id":"560913305091186688",
+	//"exception":0
+	//}
+	//]
+	//}
+	//]
+	//}
+	//}`
 	//var paymentData1 =` {
 	//"response":"rack_storing",
 	//"result":200,
@@ -256,10 +409,10 @@ func test_Trim(t *testing.T) {
 	//}
 	//}`
 
-	var str [1]string
+	var str [2]string
 
 	str[0] = paymentData
-	//str[1] =paymentData1
+	str[1] = paymentData1
 	//str[2] =paymentData2
 
 	for i := range str {
@@ -316,11 +469,11 @@ func test_Trim(t *testing.T) {
 
 				// 所有入库单下子任务已完成,根据样本申请状态(有一个不为成功则更新为失败状态)更新申请单,任务状态
 				if isEnd {
-					err = controller.StatusModifyWithDetail(taskId)
+					err = controller.StatusModifyWithDetail(taskId, res)
 				}
 				//若非正常结束,保存异常信息
 				if taskType == "abnormal_end" {
-					controller.SaveExcepMsg(res, taskId)
+					controller.SaveExcepMsg(res, taskId, "")
 				}
 				//处理任务下申请
 				svc := converse.GetConverseService(utils.DBE)
@@ -329,22 +482,38 @@ func test_Trim(t *testing.T) {
 			} else if taskType == "task_activate" {
 				fmt.Println(">>>>>>>>>>修改激活状态>>>>>>>>>>")
 				if res.Data.Status == 3 {
-					err = controller.StatusModify(REJECT, taskId)
+					err = controller.StatusModify(REJECT, taskId, "", "")
 				} else {
-					err = controller.StatusModify(ACTIVE, taskId)
+					err = controller.StatusModify(ACTIVE, taskId, "", "")
 				}
 			} else if taskType == "accept" {
 				fmt.Println(">>>>>>>>>>修改接受状态>>>>>>>>>>")
-				err = controller.StatusModify(ACCEPT, taskId)
+				err = controller.StatusModify(ACCEPT, taskId, "", "")
 			} else if taskType == "running" {
 				fmt.Println(">>>>>>>>>>修改执行中状态>>>>>>>>>>")
-				err = controller.StatusModify(RUNNING, taskId)
+				err = controller.StatusModify(RUNNING, taskId, "", "")
+			}
+
+			// 设备数据同步接口,单独处理
+			if res.Response == "stock_rack" {
+				glog.Info("    entity ", res)
+				svc := converse.GetConverseService(utils.DBE)
+				svc.UpdateBoxPosition(res)
 			}
+			// 设备数据同步接口,单独处理
+			if res.Response == "stock_rack_tube" {
+				var sampres converse.SamplePostion
+				glog.Info(gconv.String(message))
+				json.Unmarshal([]byte(str[i]), &sampres)
+				svc := converse.GetConverseService(utils.DBE)
+				svc.UpdateSamplePosition(sampres)
+			}
+
 		} else if result == 300 && taskType == "reject" {
 			fmt.Println("----------任务[" + taskId + "]任务拒绝----------")
 			//保存异常信息
-			controller.SaveExcepMsg(res, taskId)
-			err = controller.StatusModify(REJECT, taskId)
+			controller.SaveExcepMsg(res, taskId, "")
+			err = controller.StatusModify(REJECT, taskId, "", "")
 		}
 
 		if err != nil {

+ 12 - 3
src/dashoo.cn/genepoint_srv/conf/app.conf

@@ -30,10 +30,19 @@ type=mysql
 #pwd=dfmgAkThwVDzJsNz
 
 # 252 测试数据库
-name=biobank_dev
+# name=biobank_dev
 #name=biobank_genepoint
-host=192.168.0.252
+# host=192.168.0.252
+# db_port=3306
+# user=root
+# pwd=Dashoo#190801@ali
+
+
+
+# 本地数据库
+name=dashoo
+host=127.0.0.1
 db_port=3306
 user=root
-pwd=Dashoo#190801@ali
+pwd=lu911003
 

+ 62 - 22
src/dashoo.cn/genepoint_srv/controllers/converse/converse.go

@@ -2,6 +2,7 @@ package converse
 
 import (
 	"encoding/json"
+	"github.com/gogf/gf/os/glog"
 	"log"
 	"strconv"
 	"strings"
@@ -10,9 +11,9 @@ import (
 	// "github.com/astaxie/beego"
 	"github.com/gorilla/websocket"
 
+	"dashoo.cn/base_common/utils"
 	arrangeService "dashoo.cn/genepoint_srv/business/arrangeService"
 	. "dashoo.cn/genepoint_srv/business/converseService"
-	"dashoo.cn/utils"
 )
 
 type ConverseController struct {
@@ -58,18 +59,17 @@ func (this *ConverseController) SearchDatabase() map[string]*RequestEntity {
 
 		//如果没有任务实体, 则创建新任务实体
 		if _, ok := reqMap[value.Task_id]; !ok {
-			entity := svc.GenerateRequestEntity(value.Task_type /*value.Task_id*/, taskid,user)
+			entity := svc.GenerateRequestEntity(value.Task_type /*value.Task_id*/, taskid, user)
 			reqMap[value.Task_id] = entity
 		}
 		//处理任务详细
 		svc.HandleTaskDetail(value.Task_type, reqMap[value.Task_id], &value)
 
-
 	}
 	for _, v := range reqMap {
 		//log.Println("****************************")
 		m, _ := json.Marshal(v)
-		log.Println("组装报文成功",string(m))
+		log.Println("组装报文成功", string(m))
 	}
 	//log.Println("组装请求数据报文:",reqMap)
 	return reqMap
@@ -84,9 +84,9 @@ func (this *ConverseController) SendMessage(req *RequestEntity, conn *websocket.
 }
 
 // 根据子任务结果修改状态,子任务中有一个失败,则整个申请单为失败状态
-func (this *ConverseController) StatusModifyWithDetail(task_id string,res ResponseEntity ) error {
+func (this *ConverseController) StatusModifyWithDetail(task_id string, res ResponseEntity) error {
 	svc := GetConverseService(utils.DBE)
-	err := svc.StatusModifyWithDetail(task_id,res)
+	err := svc.StatusModifyWithDetail(task_id, res)
 	if err != nil {
 		return err
 	}
@@ -94,7 +94,7 @@ func (this *ConverseController) StatusModifyWithDetail(task_id string,res Respon
 }
 
 // 修改任务状态码
-func (this *ConverseController) StatusModify(statusCode int, task_id string,reqType,msg string) error {
+func (this *ConverseController) StatusModify(statusCode int, task_id string, reqType, msg string) error {
 	svc := GetConverseService(utils.DBE)
 
 	asvc := arrangeService.GetArrangeService(utils.DBE)
@@ -105,7 +105,7 @@ func (this *ConverseController) StatusModify(statusCode int, task_id string,reqT
 	}
 
 	if reqType == "moving" {
-		err = asvc.ArrangeMainStatusModify(statusCode, task_id,msg)
+		err = asvc.ArrangeMainStatusModify(statusCode, task_id, msg)
 		if err != nil {
 			return err
 		}
@@ -117,7 +117,7 @@ func (this *ConverseController) StatusModify(statusCode int, task_id string,reqT
 		}
 	} else {
 		//修改出入库任务状态
-		err = svc.SampleApplyStatusModify(statusCode, task_id,msg )
+		err = svc.SampleApplyStatusModify(statusCode, task_id, msg)
 		if err != nil {
 			return err
 		}
@@ -139,6 +139,30 @@ func (this *ConverseController) StatusModify(statusCode int, task_id string,reqT
 	return nil
 }
 
+// 修改 同步任务 任务状态码
+func (this *ConverseController) StatusModifyApply(statusCode int, task_id string, reqType, Rack_id, msg string) error {
+	svc := GetConverseService(utils.DBE)
+
+	err := svc.ApplyTaskStatusModify(statusCode, task_id, Rack_id)
+
+	err = svc.ApplyStatusModify(statusCode, task_id, msg)
+	if err != nil {
+		return err
+	}
+	if statusCode != SUCCESS && statusCode != FAILED {
+		err = svc.ApplyStatusModify(statusCode, task_id, "")
+		if err != nil {
+			return err
+		}
+	}
+
+	//if statusCode == SUCCESS || statusCode == REJECT {
+	//	svc.SampleApplyDetailStatusBatchModify(statusCode,task_id)
+	//}
+
+	return nil
+}
+
 //修改部分执行成功样本状态
 //func (this *ConverseController)SamplePartsStatusModify(res ResponseEntity){
 //	svc :=  GetConverseService(utils.DBE)
@@ -190,9 +214,9 @@ func (this *ConverseController) HandleMessage(n int, message []byte) {
 				this.SaveExcepMsg(res, taskId, resp)
 			}
 			// add by 徐春林 库内整理任务需要单独处理
-			if resp == "moving"{
+			if resp == "moving" {
 				asvc := arrangeService.GetArrangeService(utils.DBE)
-				err = asvc.UpdateArrangeRes(taskId,resp,message)
+				err = asvc.UpdateArrangeRes(taskId, resp, message)
 			} else {
 				//处理任务下申请
 				svc := GetConverseService(utils.DBE)
@@ -200,25 +224,25 @@ func (this *ConverseController) HandleMessage(n int, message []byte) {
 
 				// 所有入库单下子任务已完成,根据样本申请状态(有一个不为成功则更新为失败状态)更新申请单,任务状态
 				if isEnd {
-					err = this.StatusModifyWithDetail(taskId,res)
+					err = this.StatusModifyWithDetail(taskId, res)
 				}
 			}
 			//this.SampleAllStatusModify(res,SUCCESS)
 		} else if taskType == "task_activate" {
 			log.Println(">>>>>>>>>>任务[" + taskId + "]激活>>>>>>>>>>")
 			if res.Data.Status == 3 {
-				err = this.StatusModify(REJECT, taskId,resp,res.Data.Msg)
-			} else if res.Data.Status == 6 ||   res.Data.Status == 7  {
-				err = this.StatusModify(RUNNING, taskId, resp,res.Data.Msg)
-			}else{
-				err = this.StatusModify(ACTIVE, taskId, resp,res.Data.Msg)
+				err = this.StatusModify(REJECT, taskId, resp, res.Data.Msg)
+			} else if res.Data.Status == 6 || res.Data.Status == 7 {
+				err = this.StatusModify(RUNNING, taskId, resp, res.Data.Msg)
+			} else {
+				err = this.StatusModify(ACTIVE, taskId, resp, res.Data.Msg)
 			}
 		} else if taskType == "accept" {
 			log.Println(">>>>>>>>>>任务[" + taskId + "]接受>>>>>>>>>>")
-			err = this.StatusModify(ACCEPT, taskId, resp,"")
+			err = this.StatusModify(ACCEPT, taskId, resp, "")
 		} else if taskType == "running" {
 			log.Println(">>>>>>>>>>任务[" + taskId + "]执行中>>>>>>>>>>")
-			err = this.StatusModify(RUNNING, taskId, resp,  res.Data.Msg)
+			err = this.StatusModify(RUNNING, taskId, resp, res.Data.Msg)
 		} else if taskType == "rack_retrieving" {
 			log.Println(">>>>>>>>>>任务[" + taskId + "]执行中>>>>>>>>>>")
 			err = this.StatusModify(RACKRETRIEVING, taskId, resp, res.Data.Msg)
@@ -234,11 +258,27 @@ func (this *ConverseController) HandleMessage(n int, message []byte) {
 				err = this.StatusModify(ACTIVE, taskId, resp, res.Data.Msg)
 			}
 		}
+
+		// 设备数据同步接口 - 同步冻存盒位置信息
+		if resp == "stock_rack" {
+			svc := GetConverseService(utils.DBE)
+			svc.UpdateBoxPosition(res)
+		}
+		// 设备数据同步接口 - 同步冻存管位置信息
+		if res.Response == "stock_rack_tube" {
+			var sampres SamplePostion
+			json.Unmarshal(message, &sampres)
+
+			glog.Info("    entity ", res)
+			svc := GetConverseService(utils.DBE)
+			svc.UpdateSamplePosition(sampres)
+		}
+
 	} else if result == 300 && taskType == "reject" {
 		log.Println("----------任务[" + taskId + "]任务拒绝----------")
 		//保存异常信息
 		this.SaveExcepMsg(res, taskId, resp)
-		err = this.StatusModify(REJECT, taskId, resp,res.Data.Causes[0].Msg)
+		err = this.StatusModify(REJECT, taskId, resp, res.Data.Causes[0].Msg)
 		// 判断如果为盒操作, 需要将 盒解锁, 重新执行时再上锁
 		if resp == "rack_storing" || resp == "rack_retrieving" {
 			err = this.UpdateBoxIsLocked(taskId)
@@ -249,7 +289,7 @@ func (this *ConverseController) HandleMessage(n int, message []byte) {
 		log.Println(err)
 	}
 }
-func (this *ConverseController) UpdateBoxIsLocked(taskId string) error{
+func (this *ConverseController) UpdateBoxIsLocked(taskId string) error {
 	svc := GetConverseService(utils.DBE)
 	err := svc.UpdateBoxIsLocked(taskId)
 	if err != nil {
@@ -259,7 +299,7 @@ func (this *ConverseController) UpdateBoxIsLocked(taskId string) error{
 }
 
 //保存异常信息
-func (this *ConverseController) SaveExcepMsg(res ResponseEntity, taskId ,reqType string) {
+func (this *ConverseController) SaveExcepMsg(res ResponseEntity, taskId, reqType string) {
 	svc := GetConverseService(utils.DBE)
 	//causeByte,_ := json.Marshal(res.Data.Causes)
 	//causeMsg := string(causeByte)

+ 47 - 43
src/dashoo.cn/genepoint_srv/main.go

@@ -16,9 +16,9 @@ import (
 	"github.com/gorilla/websocket"
 	"github.com/robfig/cron"
 
+	"dashoo.cn/base_common/utils"
 	"dashoo.cn/genepoint_srv/business/converseService"
 	"dashoo.cn/genepoint_srv/controllers/converse"
-	"dashoo.cn/utils"
 )
 
 //const gpServiceUrl = "ws://39.105.83.226:22225/socket"
@@ -65,7 +65,6 @@ var pingTimer = time.NewTicker(10 * time.Second)
 func main() {
 	temp = false
 
-
 	// 加载配置文件中服务器地址
 	utils.LoadConfig("conf/app.conf")
 
@@ -175,7 +174,7 @@ func connectWebSocket() bool {
 	log.Printf("connecting to %s", gpServiceUrl)
 
 	// 判断是否重复连接
-	if lockReconnect{
+	if lockReconnect {
 		return false
 	}
 
@@ -202,7 +201,6 @@ func connectWebSocket() bool {
 
 					wsConn = conn
 
-
 					/*// 设置心跳处理事件
 					wsConn.SetPingHandler(func(message string) error {
 						log.Println("ping received", message)
@@ -270,32 +268,22 @@ func ListenToReadMsg() (pid int) {
 	return
 }
 
-
-func newWithSeconds() *cron.Cron {
-	secondParser := cron.NewParser(cron.Second | cron.Minute |
-		cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
-	return cron.New(cron.WithParser(secondParser), cron.WithChain())
-}
+//func newWithSeconds() *cron.Cron {
+//	secondParser := cron.NewParser(cron.Second | cron.Minute |
+//		cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
+//	return cron.New(cron.WithParser(secondParser), cron.WithChain())
+//}
 
 // 定时查询接口任务,给基点接口发送请求
 func ListenToSendMsg() {
 	log.Println("发送消息>>>>>>>>>>>>>>>>>>>")
 
+	cron := cron.New()
 
-	cron := newWithSeconds()
 	// 定时规则:每隔10秒执行一次
-	tick := "*/10 * * * * ?"
-	_,err = cron.AddFunc(tick, func() {
-		// if temp {
-		// 	wsConn = initWebSocket()
-		// 	if wsConn != nil {
-		// 		log.Println("正在重连-------")
-		// 		defer wsConn.Close()
-		// 		ctrl.GetConnection(wsConn)
-		// 	}
-		// }
-		//判断conn是否还在  todo
-		//
+	//tick := "*/10 * * * * ?"
+	err = cron.AddFunc("@every 10s", func() {
+
 		svc := converseService.GetConverseService(utils.DBE)
 
 		// 查询任务,生成指令
@@ -304,8 +292,13 @@ func ListenToSendMsg() {
 			log.Println("read err:", err)
 			// 任务发送失败,,,修改任务状态,,,,提示任务执行失败
 			for taskid, reqEntity := range reqMap {
-				err = ctrl.StatusModify(converseService.FAILED, taskid,reqEntity.Request,"")
-				svc.SaveErrInfo(err.Error(), taskid,reqEntity.Request)
+				if reqEntity.Request == "" {
+					err = ctrl.StatusModifyApply(converseService.FAILED, taskid, reqEntity.Request, reqEntity.Data.Rack_id, "")
+				} else {
+					err = ctrl.StatusModify(converseService.FAILED, taskid, reqEntity.Request, "")
+					svc.SaveErrInfo(err.Error(), taskid, reqEntity.Request)
+				}
+
 			}
 		}
 		// 发送消息
@@ -317,23 +310,33 @@ func ListenToSendMsg() {
 			}
 			err1 := wsConn.WriteJSON(reqEntity)
 			if err1 != nil {
-				log.Println("请求发送失败",err1)
+				log.Println("请求发送失败", err1)
 				// 任务发送失败,,,修改任务状态,,,,提示任务执行失败
-				err1 = ctrl.StatusModify(converseService.FAILED, taskid,reqEntity.Request,"")
+				err1 = ctrl.StatusModify(converseService.FAILED, taskid, reqEntity.Request, "")
 				// 跟新异常信息
 				totalMsg := "请求发送失败"
-				svc.SaveErrInfo(totalMsg, taskid,reqEntity.Request)
+				svc.SaveErrInfo(totalMsg, taskid, reqEntity.Request)
 
 			} else {
 				log.Println("请求发送成功")
 				// 发送成功,修改状态
-				err1 = ctrl.StatusModify(converseService.SENT, taskid,reqEntity.Request,"")
+
+				if reqEntity.Request == "" {
+					err1 = ctrl.StatusModifyApply(converseService.SENT, taskid, reqEntity.Request, reqEntity.Data.Rack_id, "")
+
+				} else {
+					err1 = ctrl.StatusModify(converseService.SENT, taskid, reqEntity.Request, "")
+
+				}
+
 			}
 		}
 	})
+	cron.Start()
 	if err != nil {
 		log.Println(err)
 	}
+
 	if !cronstart {
 		cronstart = true
 		cron.Start()
@@ -342,6 +345,7 @@ func ListenToSendMsg() {
 		svc := converseService.GetConverseService(utils.DBE)
 		sql := " update sample_storage_task set StatusCode =4 where StatusCode =1"
 		svc.DBE.Exec(sql)
+
 	}
 }
 
@@ -351,7 +355,7 @@ func ClearSuccessfulTask() {
 	cron := cron.New()
 	//每天0时清除任务表
 	tick := "0 0 0 * * ?"
-	_,err = cron.AddFunc(tick, func() {
+	err = cron.AddFunc(tick, func() {
 		ctrl.DeleteAccomplishedTask()
 		if err != nil {
 			log.Println("read:", err)
@@ -397,7 +401,7 @@ func echo() {
 			// 更新心跳时间
 			heartTime = time.Now()
 			return err
-	})
+		})
 
 	go func() {
 		// 设定ping
@@ -406,7 +410,7 @@ func echo() {
 			case <-pingTimer.C:
 				go func() {
 					log.Println("ping msg")
-					err := wsConn.WriteControl(websocket.PingMessage, []byte("Do ping"), time.Now().Add(5 * time.Second))
+					err := wsConn.WriteControl(websocket.PingMessage, []byte("Do ping"), time.Now().Add(5*time.Second))
 					if err != nil {
 						log.Println(err)
 					}
@@ -438,7 +442,7 @@ func BackupDatabase() {
 	//minute   hour   day   month   week   command
 	//tick := "0 0 0 * * ?"
 	tick := "0 0 0 * * ?"
-	_,err = cron.AddFunc(tick, func() {
+	err = cron.AddFunc(tick, func() {
 		BackupMySqlDb("")
 		if err != nil {
 			log.Println("数据库备份失败:", err)
@@ -460,7 +464,7 @@ func BackupDatabase() {
  * @return 	backupPath
  *
  */
-func BackupMySqlDb(tableName string) (error,string)  {
+func BackupMySqlDb(tableName string) (error, string) {
 	//定义Cmd结构体对象指针
 	log.Println("开始备份数据库>>>>>>>>>>>>>>>>>>>")
 	var cmd *exec.Cmd
@@ -473,7 +477,7 @@ func BackupMySqlDb(tableName string) (error,string)  {
 	//sqlPath := "D:/backup/"
 	//在这里如果没有传输表名,那么将会备份整个数据库,否则将只备份自己传入的表
 	//if tableName == "" {
-		cmd = exec.Command("mysqldump", "--column-statistics=0","-h"+host, "-P"+port, "-u"+user, "-p"+password, databaseName)
+	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)
 	}*/
@@ -482,18 +486,18 @@ func BackupMySqlDb(tableName string) (error,string)  {
 	stdout, err := cmd.StdoutPipe()
 	if err != nil {
 		log.Println(err)
-		return err,""
+		return err, ""
 	}
 
 	if err := cmd.Start(); err != nil {
 		log.Println(err)
-		return err,""
+		return err, ""
 	}
 
 	bytes, err := ioutil.ReadAll(stdout)
 	if err != nil {
 		log.Println(err)
-		return err,""
+		return err, ""
 	}
 	//获得一个当前的时间戳
 	now := time.Now().Format("20060102")
@@ -501,17 +505,17 @@ func BackupMySqlDb(tableName string) (error,string)  {
 
 	//设置我们备份文件的名字
 	if tableName == "" {
-		backupPath = sqlPath+databaseName+"_"+now+".sql"
+		backupPath = sqlPath + databaseName + "_" + now + ".sql"
 	} else {
-		backupPath = sqlPath+databaseName+"_"+tableName+"_"+now+".sql"
+		backupPath = sqlPath + databaseName + "_" + tableName + "_" + now + ".sql"
 	}
-	log.Println("定时备份数据库完成>>>>>>>>>>>>>>>>>>>",backupPath)
+	log.Println("定时备份数据库完成>>>>>>>>>>>>>>>>>>>", backupPath)
 	//写入文件并设置文件权限
 	err = ioutil.WriteFile(backupPath, bytes, 0644)
 
 	if err != nil {
 		log.Println(err)
-		return err,""
+		return err, ""
 	}
-	return nil,backupPath
+	return nil, backupPath
 }