| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419 |
- package converseService
- import (
- "crypto/md5"
- "dashoo.cn/genepoint_srv/business/arrangeService"
- "dashoo.cn/genepoint_srv/business/common"
- "fmt"
- "github.com/gogf/gf/os/gtime"
- "github.com/gogf/gf/util/gconv"
- "github.com/unknwon/com"
- "github.com/gogf/gf/os/glog"
- "log"
- "strconv"
- "strings"
- "time"
- "xorm.io/xorm"
- "dashoo.cn/base_common/utils"
- . "dashoo.cn/base_common/utils/db"
- )
- const CU = 1
- const EE = 1
- const POS = 1
- const LTU = 1
- const GROUP = 1
- const TABLE_TAST = "sample_storage_task"
- const TABLE_SAMPLE_APPLY = "bank_apply_main"
- const TABLE_DETAIL = "bank_apply_detail"
- const TABLE_SHELF = "bank_shelf"
- const TABLE_BOX = "bank_box"
- const TABLE_EQUIPMENT = "bank_equipment"
- const TABLE_DEVICE_DATA = "GenePoint_Device_Report_Data"
- const TABLE_SAMPLE = "bank_sample"
- const TABLE_APPLY_DETAIL = "bank_apply_detail"
- const STATUS_LOCKED = "1"
- const STATUS_UNLOCK = "0"
- const RK_PASS = "2"
- const CK_PASS_ONHOLD = "3" //保留位置
- const CK_PASS_DONE = "4" //已归档
- const LOGIC_ID = "0" // 逻辑分区Id
- type ConverseService struct {
- ServiceBase
- }
- type ConverseSessionService struct {
- SessionBase
- }
- func GetConverseService(xormEngine *xorm.Engine) *ConverseService {
- s := new(ConverseService)
- s.DBE = xormEngine
- return s
- }
- func GetConverseSessionService(session *xorm.Session) *ConverseSessionService {
- s := new(ConverseSessionService)
- s.Session = session
- return s
- }
- //建立会话
- func (this *ConverseService) GetSessionSetupRequest(utc string) *RequestEntity {
- var request = "session_setup"
- var reqData RequestData
- reqData.Key = this.GetKeyBaseOnTime(utc)
- reqData.Client = "lims"
- var entity = this.GetRequestEntity(request, utc, reqData)
- return entity
- }
- //生成请求报文
- func (this *ConverseService) GetRequestEntity(request string, utc string, data RequestData) *RequestEntity {
- var entity RequestEntity
- entity.Request = request
- entity.Time = utc
- entity.Data = data
- return &entity
- }
- // 获取身份验证key
- // key的信息按照生物样本存储系统分配的私钥字符串+请求报文中的time字段的值进行MD5加密
- func (this *ConverseService) GetKeyBaseOnTime(utc string) string {
- privateKey, _ := utils.Cfg.GetValue("key", "privateKey")
- log.Println("身份验证Key", privateKey)
- //privateKey := "ZGlzdHJp23Yn4V06b3I6OGQ5NjllZWY2ZWNhZDNjMjlhM2E2MjkyODBlNjg2Y2YwYzNmNWQ1YTg2YWZmM2Nh3MTIwMjB3454jOTIzYWRjNmM5M4g"
- unencoded := privateKey + utc
- byte := md5.Sum([]byte(unencoded))
- encode := fmt.Sprintf("%x", byte)
- resultKey := strings.ToUpper(encode)
- return resultKey
- }
- //查询库存冻存盒信息
- func (this *ConverseService) CheckStockRackInfo(cu int, rack_id string, utc string) *RequestEntity {
- var request = "stock_rack"
- var data RequestData
- data.Rack_id = rack_id
- data.Cu = cu
- entity := this.GetRequestEntity(request, utc, data)
- return entity
- }
- //查询库存冻存管信息
- func (this *ConverseService) CheckStockTubeInfo(cu int, rack_id, tube_id, utc string) *RequestEntity {
- var request = "stock_rack_tube"
- var data RequestData
- data.Rack_id = rack_id
- data.Tube_id = tube_id
- data.Cu = cu
- entity := this.GetRequestEntity(request, utc, data)
- return entity
- }
- //任务撤销
- func (this *ConverseService) CancelTast(utc string, task_id string) *RequestEntity {
- var request = "task_change"
- var data RequestData
- data.Task_id = task_id
- data.Status = 1
- entity := this.GetRequestEntity(request, utc, data)
- return entity
- }
- //扫描新任务
- func (this *ConverseService) ScanNewTaskDetail() []Sample_Storage_Task {
- var tasks []Sample_Storage_Task
- where := "statuscode = 0"
- this.GetEntitysByWhere(TABLE_TAST, where, &tasks)
- return tasks
- }
- // 获取申请单创建人
- func (this *ConverseService) GetOperUser(EntryNo string) (user string) {
- // 获取当前任务的操作人
- sql := " select a.UserName from base_user a left join bank_apply_main b on a.id = b.CreateUserId where b.EntryNo ='" + EntryNo + "' "
- this.DBE.SQL(sql).Get(&user)
- return user
- }
- //新任务数量
- func (this *ConverseService) GetNewTaskBasic() []Sample_Storage_Task {
- //var count64 int64
- var tasks []Sample_Storage_Task
- //sql := "SELECT COUNT(DISTINCT(task_id)) FROM sample_storage_task WHERE status = 0"
- sql := "SELECT task_id, task_type, statuscode FROM " + TABLE_TAST + " GROUP BY task_id, task_type HAVING statuscode = 0"
- err := this.DBE.SQL(sql).Find(&tasks)
- if err != nil {
- log.Println(err)
- }
- return tasks
- }
- ////冻存管位置格式转换
- //func TransPositionToNo(boxType int, position string) int{
- // co := strings.Split(position,";")
- // x, _ := strconv.Atoi(co[0])
- // y, _ := strconv.Atoi(co[1])
- // var no int
- // switch boxType {
- // case 101,102,103:
- // no = (y-1)*14+x
- // break
- // case 0 :
- // no = (y-1)*10+x
- // }
- // return no
- //}
- // 生成请求实体,根据任务类型获取requestName
- func (this *ConverseService) GenerateRequestEntity(taskType int, task_id, user string) *RequestEntity {
- var requestName string
- switch taskType {
- case 1:
- requestName = "rack_storing"
- break
- case 2:
- requestName = "rack_retrieving"
- break
- case 3, 8:
- requestName = "tube_storing"
- break
- case 4:
- requestName = "tube_retrieving"
- break
- case 5:
- requestName = "stock_rack"
- break
- case 6:
- requestName = "stock_rack_tube"
- break
- case 7:
- requestName = "task_change"
- break
- case 9:
- // add by 徐春林 添加库内整理任务
- requestName = "moving"
- }
- utc := time.Now().UTC().Format(time.RFC3339)
- var data RequestData
- if requestName != "stock_rack" && requestName != "stock_rack_tube" {
- data.Task_id = task_id
- data.Type = "begin"
- // 自动化设备 必须要穿 Operation_user 用户信息
- data.Operation_user = user
- // 半自动化设备,不需要传 Operation_user 用户信息
- //data.Operation_user = ""
- }
- entity := this.GetRequestEntity(requestName, utc, data)
- return entity
- }
- // 按类型进行任务处理
- func (this *ConverseService) HandleTaskDetail(taskType int, entity *RequestEntity, detail *Sample_Storage_Task) {
- switch taskType {
- case 1: //冻存盒 入库
- handleRackStore(entity, detail)
- break
- case 2: //冻存盒出库
- handleRackRetrieve(entity, detail)
- break
- case 3, 8: //冻存管入库
- handleTubeStore(entity, detail)
- break
- case 4: // 冻存管出库
- handleTubeRetrieve(entity, detail)
- break
- case 5: // 获取设备库存情况及冻存盒信息
- handleQueryRack(entity, detail)
- break
- case 6: // 根据冻存盒编号查询冻存管信息
- handleQueryTube(entity, detail)
- break
- case 7: // 任务变更通知
- handleTaskChange(entity, detail)
- break
- case 9: // add by 徐春林 添加库内整理任务 手动库内整理
- handleArrange(entity, detail)
- }
- }
- //处理冻存盒入库任务信息
- func handleRackStore(entity *RequestEntity, detail *Sample_Storage_Task) {
- var ones = make([]Single, 0)
- var exist bool
- if entity.Data.Task_data != nil {
- ones = entity.Data.Task_data.([]Single)
- for idx, value := range ones {
- if value.Target.Cu == detail.Cu && value.Target.Unit == detail.Unit && value.Target.Pos == detail.Pos && value.Target.Ltu == detail.Ltu && value.Target.Group == detail.Group && value.Rack_id == detail.BoxBarcode {
- var tube Tube
- tube.Id = detail.BarCode
- ones[idx].Tubes = append(ones[idx].Tubes, tube)
- exist = true
- }
- }
- }
- if !exist {
- var one Single
- one.Rack = detail.BoxType
- one.Tube = detail.TubeType
- one.Rack_id = detail.BoxBarcode
- //one.Source.Cu = CU
- one.Source.Cu = detail.Cu
- one.Source.Ee = EE
- one.Source.Pos = POS
- //one.Target.Cu = CU
- one.Target.Cu = detail.Cu
- one.Target.Unit = detail.Unit
- one.Target.Pos = detail.Pos
- one.Target.Ltu = detail.Ltu
- //one.Target.Group = 1
- one.Target.Group = detail.Group
- if detail.BarCode != "" {
- var tube Tube
- tube.Id = detail.BarCode
- one.Tubes = append(one.Tubes, tube)
- } else {
- one.Tubes = make([]Tube, 0) //tubes不能为空, 否则Genepoint系统报错
- }
- ones = append(ones, one)
- }
- entity.Data.Task_data = ones
- }
- //处理冻存盒出库任务信息
- func handleRackRetrieve(entity *RequestEntity, detail *Sample_Storage_Task) {
- var ones []Single
- var one Single
- one.Tubes = make([]Tube, 0) //tubes不能为空, 否则Genepoint系统报错
- if entity.Data.Task_data != nil {
- // ones = make([]Single, 0)
- //}else{
- ones = entity.Data.Task_data.([]Single)
- }
- one.Rack_id = detail.BoxBarcode
- one.Target.Cu = detail.Cu //todo
- one.Target.Ee = EE
- one.Target.Pos = POS
- ones = append(ones, one)
- entity.Data.Task_data = ones
- }
- //处理冻存管入库任务信息
- func handleTubeStore(entity *RequestEntity, detail *Sample_Storage_Task) {
- var ones []Single
- var exist bool
- if entity.Data.Operation_mode == "" {
- entity.Data.Operation_mode = detail.OperaMode
- }
- // 盒子存在追加样本
- if entity.Data.Task_data != nil {
- ones = entity.Data.Task_data.([]Single)
- for idx, value := range ones {
- // 若目标盒一致,则追加样本
- isSampleTarget := value.Target.Cu == detail.Cu && value.Target.Ltu == detail.Ltu && value.Target.Group == detail.Group && value.Target.Unit == detail.Unit && value.Target.Pos == detail.Pos && value.Target.Rack_id == detail.BoxBarcode
- if isSampleTarget {
- var tube Tube
- if detail.OperaMode != "auto" {
- //tube.T_no = TransPositionToNo(detail.BoxType,detail.Position)
- //实际采用,暂时注释掉
- tube.T_no = detail.No
- }
- tube.Id = detail.BarCode
- ones[idx].Tubes = append(ones[idx].Tubes, tube)
- //value.Tubes = append(value.Tubes,tube)
- exist = true
- goto label
- }
- }
- }
- // 盒子不存在新加盒子及管信息
- if !exist {
- var one Single
- //one.Rack = 101 // 测试临时使用
- //one.Tube = 201 // 测试临时使用
- one.Rack = detail.BoxType // 样本库系统,没有添加该字段信息逻辑,临时注释
- one.Tube = detail.TubeType // 样本库系统,没有添加该字段信息逻辑,临时注释
- one.Rack_id = detail.SourceBox // 此处需要添加源盒编码 SourceBox
- //one.Source.Cu = CU // 测试临时使用
- one.Source.Cu = detail.Cu
- one.Source.Ee = EE
- one.Source.Pos = POS
- var tube Tube
- if detail.OperaMode != "auto" {
- one.Target.Cu = detail.Cu
- one.Target.Ltu = detail.Ltu
- one.Target.Group = detail.Group
- one.Target.Unit = detail.Unit
- one.Target.Pos = detail.Pos
- one.Target.Rack_id = detail.BoxBarcode
- //tube.T_no = TransPositionToNo(detail.BoxType,detail.Position)
- tube.T_no = detail.No //实际采用,暂时注释掉
- }
- tube.Id = detail.BarCode
- one.Tubes = append(one.Tubes, tube)
- ones = append(ones, one)
- }
- label:
- entity.Data.Task_data = ones
- }
- //处理冻存管出库任务信息
- func handleTubeRetrieve(entity *RequestEntity, detail *Sample_Storage_Task) {
- var one OutSingle
- //var exist bool
- if entity.Data.Task_data != nil {
- one = entity.Data.Task_data.(OutSingle)
- //exist = true
- }
- //if !exist {
- // //one.Target.Cu = CU
- // one.Target.Cu = detail.Cu
- // one.Target.Ee = EE
- // one.Target.Pos = POS
- //}
- var tube Tube
- tube.Id = detail.BarCode
- one.Tubes = append(one.Tubes, tube)
- entity.Data.Task_data = one
- }
- //任务撤销
- func handleTaskChange(entity *RequestEntity, detail *Sample_Storage_Task) {
- entity.Data.Status = detail.Status
- }
- //查询冻存盒库存信息
- func handleQueryRack(entity *RequestEntity, detail *Sample_Storage_Task) {
- entity.Data.Cu = detail.Cu
- entity.Data.Rack_id = detail.BoxBarcode
- }
- //查询冻存管库存信息
- func handleQueryTube(entity *RequestEntity, detail *Sample_Storage_Task) {
- entity.Data.Rack_id = detail.BoxBarcode
- entity.Data.Tube_id = detail.BarCode
- }
- /**
- * @Author 徐春林
- * @Description // 手动选择位置 库内整理
- * @Date 20:01 2021/3/29
- * @Param
- * @return
- **/
- func handleArrange(entity *RequestEntity, detail *Sample_Storage_Task) {
- var ones []Arrange
- if entity.Data.Task_data != nil {
- 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,
- Unit: detail.Unit,
- Pos: detail.Pos,
- }
- one := Arrange{
- Logic_id: 0,
- Position: position,
- }
- ones = append(ones, one)
- entity.Data.Operation_mode = detail.OperaMode
- entity.Data.Initiator = "genepoint"
- entity.Data.Name = "库内整理"
- entity.Data.Task_data = ones
- }
- /**
- * 卢传敏
- * 响应报文,任务执行提示
- */
- func handleTaskActivate(entity *RequestEntity, detail *Sample_Storage_Task) {
- }
- // 查询申请单详情下状态,存在一条子任务失败的情况,则整个申请单状态为失败
- func (this *ConverseService) StatusModifyWithDetail(task_id string, res ResponseEntity) error {
- status := SUCCESS
- // 关联查询申请详情表,申请主表中指定申请单下执行状态不为success的申请详情数量
- sql := "SELECT count(*) FROM `" + TABLE_APPLY_DETAIL + "` a JOIN `" + TABLE_SAMPLE_APPLY + "` b ON a.parentid = b.Id WHERE (b.entryno = '" + task_id + "' and a.taskstatus <> " + strconv.Itoa(SUCCESS) + ")"
- //total, err := this.DBE.Table(TABLE_APPLY_DETAIL ).Join("", TABLE_SAMPLE_APPLY ,"a.parentid = b.Id").Where(" a.parentid = b.Id and b.entryno = '" + task_id + "' and a.taskstatus <> " + strconv.Itoa(SUCCESS)).Count()
- //if err != nil && err != sql.ErrNoRows {
- // return err
- //}
- var total int
- //_, err := this.DBE.Exec(sql)
- this.DBE.SQL(sql).Get(&total)
- //total ,_ := result.RowsAffected()
- fmt.Println("数量:", total)
- // 存在未执行成功的子任务
- if total > 0 {
- status = FAILED
- }
- if res.Data.Type == "abnormal_end" {
- status = EXCEPTION
- }
- // 更新任务状态
- //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 = " ,exception='' "
- }
- // 更新申请主表状态
- 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 + "'"
- _, err := this.DBE.Exec(sql)
- return err
- }
- // 修改出入库单状态
- func (this *ConverseService) SampleApplyStatusModify(statusCode int, entryNo, msg string) error {
- set := " "
- if statusCode == 1 || statusCode == 2 || statusCode == 3 || statusCode == 5 {
- set = " ,exception='' "
- if statusCode == 5 {
- // 任务执行成功以后,需要记录执行时间
- set = " ,exception='', ExecutionTime = " + gconv.String(gtime.Now()) + ", ModifiedOn = " + gconv.String(gtime.Now())
- }
- } else {
- if msg != "" {
- set = " ,exception='" + msg + "' "
- } else {
- set = " ,exception='' "
- }
- }
- sql := "UPDATE " + TABLE_SAMPLE_APPLY + " SET taskstatus = '" + strconv.Itoa(statusCode) + "' " + set + " WHERE entryno = '" + entryNo + "'"
- _, err := this.DBE.Exec(sql)
- return err
- }
- //2020/12/18新增 根据当前任务报文返回状态批量更新当前任务下所有的样本状态
- func (this *ConverseService) SampleApplyDetailStatusModify(statusCode int, entryNo string) error {
- //获取出入库单Id
- getId := "SELECT id FROM " + TABLE_SAMPLE_APPLY + " WHERE entryno = '" + entryNo + "'"
- var idList []Id
- err := this.DBE.SQL(getId).Find(&idList)
- //批量更新全部成功或失败的任务样本状态
- sql := "UPDATE " + TABLE_APPLY_DETAIL + " SET taskstatus = '" + strconv.Itoa(statusCode) + "' WHERE parentid = '" + strconv.Itoa(idList[0].Id) + "' and taskstatus !=5"
- _, err = this.DBE.Exec(sql)
- return err
- }
- //任务执行驳回, 修改全部样本失败状态
- func (this *ConverseService) ModifySampleAllRejectStatus(res ResponseEntity) error {
- //获取出入库单Id
- getId := "SELECT id FROM " + TABLE_SAMPLE_APPLY + " WHERE entryno = '" + res.Data.Task_id + "'"
- var idList []Id
- err := this.DBE.SQL(getId).Find(&idList)
- //批量更新全部成功或失败的任务样本状态
- sql := "UPDATE " + TABLE_APPLY_DETAIL + " SET taskstatus = '" + strconv.Itoa(REJECT) + "' WHERE parentid = '" + strconv.Itoa(idList[0].Id) + "'"
- _, err = this.DBE.Exec(sql)
- return err
- }
- //修改样本失败状态
- 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, "tube_storing") {
- this.sampleRKSuccessDBModify(idsStr, applyMainId)
- } else if strings.Contains(response, "tube_retrieving") {
- this.sampleCKSuccessDBModify(idsStr, applyMainId)
- }
- }
- //入库成功, 修改样本数据库状态信息
- func (this *ConverseService) sampleRKSuccessDBModify(idsStr string, parentId int) error {
- fmt.Println("开始更新样本入库信息, 包括更新容量,状态, 锁定状态")
- // 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)
- 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 + "'"
- _, err = this.DBE.Exec(sql)
- }
- updatesql := "UPDATE " + TABLE_APPLY_DETAIL + " SET IsLocked = '" + STATUS_UNLOCK + "', taskstatus = '" + strconv.Itoa(SUCCESS) + "' WHERE barcode IN (" + idsStr + ")" + " AND parentid = '" + strconv.Itoa(parentId) + "'"
- // 更新样本状态解锁,原盒子id置为0
- updatesql2 := "UPDATE " + TABLE_SAMPLE + " SET IsLocked = '" + STATUS_UNLOCK + "', IState = '" + RK_PASS + "',SourceBoxId = 0 WHERE barcode IN (" + idsStr + ")"
- //更新每个样本的孔位信息
- _, err = this.DBE.Exec(updatesql)
- _, err = this.DBE.Exec(updatesql2)
- return err
- }
- //出库成功, 修改样本数据库状态信息
- func (this *ConverseService) sampleCKSuccessDBModify(idsStr string, parentId int) error {
- var list []Bank_Apply_Detail
- var onHold []string
- var done []string
- // add by 徐春林 20211224 添加主单Id 作为条件
- 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)
- if strconv.Itoa(one.RecoveryId) == CK_PASS_ONHOLD {
- // 查询样本出库详情, 更新 取出帶放回
- onHold = append(onHold, one.BarCode)
- } else if strconv.Itoa(one.RecoveryId) == CK_PASS_DONE {
- // 查询样本出库详情, 更新 取出归档
- done = append(done, one.BarCode)
- }
- }
- // 基点出库取出待放回, 清空样本位置信息, 但是状态保留为 取出待放回
- // sql := "UPDATE " + TABLE_SAMPLE + " SET istate = '" + CK_PASS_ONHOLD + "', islocked = '" + STATUS_UNLOCK + "' WHERE barcode IN ('" + strings.Join(onHold, "','") + "')"
- sql := "UPDATE " + TABLE_SAMPLE + " SET istate = '" + CK_PASS_ONHOLD + "', islocked = '" + STATUS_UNLOCK + "',equipmentid = '0', shelfid = '0',boxid= '0', position = '', positioninfo = '' WHERE barcode IN ('" + strings.Join(onHold, "','") + "')"
- sql2 := "UPDATE " + TABLE_SAMPLE + " SET istate = '" + CK_PASS_DONE + "', islocked = '" + STATUS_UNLOCK + "', equipmentid = '0', shelfid = '0',boxid= '0', position = '', positioninfo = '' WHERE barcode IN ('" + strings.Join(done, "','") + "')"
- sql3 := "UPDATE " + TABLE_APPLY_DETAIL + " SET IsLocked = '" + STATUS_UNLOCK + "', taskstatus = '" + strconv.Itoa(SUCCESS) + "' WHERE barcode IN (" + idsStr + ")" + " AND parentid = '" + strconv.Itoa(parentId) + "'"
- _, err = this.DBE.Exec(sql)
- _, err = this.DBE.Exec(sql2)
- _, err = this.DBE.Exec(sql3)
- return err
- }
- //获取出入库单信息
- func (this *ConverseService) GetApplyMain(entryNo string) Bank_Apply_Main {
- where := "entryNo = '" + entryNo + "'"
- var entity Bank_Apply_Main
- this.GetEntity(&entity, where)
- return entity
- }
- //根据出入库单信息判断任务信息, 并修改样本状态
- func (this *ConverseService) ModifySampleStatusByApplyMainInfo(entryNo string, resp string, entity ResponseEntity) {
- applyMain := this.GetApplyMain(entryNo)
- fmt.Println("resp:", resp)
- var operaIds, abnormalIds, taskType string
- // 此处判断,如果是冻存盒整盒入库,需要更新盒子位置信息 盒 冻存盒当前的 所在的冻存架的id
- if resp == "rack_storing" {
- fmt.Println("冻存盒入库")
- this.UpdateBoxInfo(entity, applyMain.Id)
- }
- if applyMain.ApplyType == TASK_TUBE_STORING && strings.Contains(resp, "_storing") {
- fmt.Println("开始入库1", entity)
- taskType = "tube_storing" // 冻存管入库
- // 获取返回报文中成功的样本 和失败的样本
- operaIds, abnormalIds = this.getOperaSampleIdsStr(applyMain.ApplyType, applyMain.Id, resp, entity)
- for _, value := range entity.Data.Actual_data {
- //获取报文中的 盒子信息
- var Rack_id string = value.Target.Rack_id
- fmt.Println("冻存盒盒子编号:", Rack_id)
- // 获取报文中的 位置信息和 样本编码
- var tubes = value.Tubes
- fmt.Println("样本位置信息:", tubes)
- //新增方法 更新位置信息
- 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, "_retrieving") /*resp == "rack_retrieving"*/ /*&& entity.Data.Is_end*/ {
- fmt.Println("开始出库3")
- //lite设备 整盒出库
- taskType = "tube_retrieving"
- //operaIds, abnormalIds = this.getAllSampleIdsFromResEntity(entity)
- operaIds, abnormalIds = this.getOperaSampleIdsStr(applyMain.ApplyType, applyMain.Id, resp, entity)
- // 管出库需要 更新 转运空盒 为 源盒
- this.UpdateBoxInfoCK(entity, applyMain.Id)
- }
- // 此处判断,如果是冻存盒整盒入库,需要更新盒子位置信息 盒 冻存盒当前的 所在的冻存架的id
- if resp == "rack_retrieving" {
- fmt.Println("冻存盒出库")
- //rack_retrieving
- // 冻存盒出库任务完成以后,需要清空冻存盒中的冻存架信息,同时清空
- this.UpdateBoxInfoCK(entity, 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, parentId int) (err error) {
- //1. 获取当前返回的 冻存架信息,
- var shelf Shelf
- var equipment Bank_Equipment
- glog.Info("entity.Data.Actual_data::", entity.Data.Actual_data)
- // 判断是否存在处理成功的数据
- if len(entity.Data.Actual_data) > 0 {
- // 循环处理返回的数据,如果出现多盒存入的分批处理
- for i := range entity.Data.Actual_data {
- 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
- 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) + "' " +
- "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))
- // 冻存盒入库需要先校验,当前盒子是否存在样本,如果不存在,则证明盒子为空盒,修改冻存盒状态为空盒
- 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 + "'" +
- " where Barcode ='" + boxBarcode + "' "
- // 冷库设备
- _, err = this.DBE.Exec(possql)
- // 更新 当前冰箱冻存盒容量 信息
- _, 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, parentId int) (err error) {
- //1. 获取当前返回的 冻存架信息,
- var shelf Shelf
- // 循环处理返回的数据,如果出现多盒存入的分批处理
- for i := range entity.Data.Actual_data {
- TaskId := entity.Data.Task_id
- boxBarcode := entity.Data.Actual_data[i].Rack_id // 冻存盒编号
- Pos := entity.Data.Actual_data[i].Target.Pos
- sql := " select shelfId , EquipmentId from bank_box where code = '" + boxBarcode + "'"
- this.DBE.SQL(sql).Get(&shelf)
- fmt.Println("冻存架信息:", shelf.Id, shelf.XStation, shelf.YStation)
- // 更新盒所在的冻存架的信息 计算位置信息,并更新
- // 临时处理逻辑,默认 pos 为 盒子的 XStation
- _, err = this.DBE.Exec("update bank_box set EquipmentId=null,shelfId=null,XStation =null,YStation =null,IsLocked = 0,Position =null where Barcode ='" + boxBarcode + "' ")
- // 更新 当前冰箱冻存盒容量 信息
- _, 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)
- 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)
- if err != nil {
- return err
- }
- }
- err = this.UpdateBoxAbnormalInfo(entity, parentId)
- return err
- }
- /**
- * @Author 徐春林
- * @Description // 盒任务执行失败 , 更新 盒锁定状态为 解锁
- * @Date 19:17 2021/3/22
- * @Param
- * @return
- **/
- func (this *ConverseService) UpdateBoxIsLocked(taskId string) (err error) {
- var task Sample_Storage_Task
- sql := "SELECT id FROM " + TABLE_TAST + " WHERE taskId = '" + taskId + "'"
- err = this.DBE.SQL(sql).Find(&task)
- _, err = this.DBE.Exec("update bank_box set IsLocked = 0 where Barcode ='" + task.BoxId + "' ")
- return err
- }
- /**
- 修改detail 信息
- */
- func (this *ConverseService) UpdateDetail(BarCode string, entity ResponseEntity, parentId int, rack_id string) {
- glog.Info("修改detail:", entity)
- var shelf Shelf
- var equipment Bank_Equipment
- var equipmentid string
- var ShelfId string
- for i := range entity.Data.Actual_data {
- Cu := entity.Data.Actual_data[i].Target.Cu // 设备编号
- Ltu := entity.Data.Actual_data[i].Target.Ltu //
- Unit := entity.Data.Actual_data[i].Target.Unit
- Group := entity.Data.Actual_data[i].Target.Group
- //当 检测到数据 与当前操作盒子的数据一直时,更新 detail 和sample 信息
- if entity.Data.Actual_data[i].Target.Rack_id == rack_id {
- 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 {
- sql += " and a.Unit ='" + utils.ToStr(Unit) + "' "
- }
- this.DBE.SQL(sql).Get(&shelf)
- equipmentid = strconv.Itoa(shelf.EquipmentId)
- ShelfId = strconv.Itoa(shelf.Id)
- sql = "Update bank_apply_detail Set EquipmentId=" + equipmentid + ",ShelfId=" + ShelfId + " where BarCode='" + BarCode + "' and ParentId=" + strconv.Itoa(parentId)
- this.DBE.Exec(sql)
- sql = "update bank_sample set EquipmentId=" + equipmentid + ",ShelfId=" + ShelfId + " where barcode ='" + BarCode + "' "
- this.DBE.Exec(sql)
- }
- }
- }
- // 20201026 卢传敏新增根据返回报文,更新位置信息
- /**
- * rack_id 盒子编号
- * tubes 报文中返回的 位置和样本条码
- */
- func (this *ConverseService) UpdatePosition(rack_id string, tubes []Tube, entity ResponseEntity, parentId int) {
- // 根据返回的报文中的盒子标识,获取盒子类型
- 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))
- // 根据盒子信息获取容器和冻存架信息, 用于更新样本孔位信息
- // 获取容器信息
- 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 + "' "
- var shelf Shelf
- this.DBE.SQL(shelfsql).Get(&shelf)
- RowNum := box.RowNum
- ColumnNum := box.ColumnNum
- glog.Info("冻存盒的行数:", RowNum, ";冻存盒的列数:", ColumnNum)
- for i := 0; i < len(tubes); i++ {
- no := tubes[i].No
- id := tubes[i].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 := 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 + "' " +
- // " , 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)
- }
- }
- //获取当前操作样本的id, 正常和异常的
- func (this *ConverseService) getOperaSampleIdsStr(applyType, parentId int, resp string, entity ResponseEntity) (actualIds string, abnormalIds string) {
- //获取出入库单中所有样本信息
- var list []Bank_Apply_Detail
- where := " parentid = '" + strconv.Itoa(parentId) + "'"
- this.GetEntitysByWhere(TABLE_DETAIL, where, &list)
- var sampleIds []string
- for _, detail := range list {
- sampleIds = append(sampleIds, detail.BarCode)
- }
- //获取反馈报文中的所有成功样本Id列表
- var actualTubeIds []string
- for _, single := range entity.Data.Actual_data {
- for _, tube := range single.Tubes {
- actualTubeIds = append(actualTubeIds, tube.Id)
- }
- }
- //获取反馈报文中的所有异常样本Id列表
- var abnormalTubeIds []string
- for _, single := range entity.Data.Abnormal_data.Tubes {
- abnormalTubeIds = append(abnormalTubeIds, single.Id)
- }
- var operaTubeIds []string
- var failTubeIds []string
- if applyType == TASK_TUBE_STORING {
- for _, sampleId := range sampleIds {
- //操作成功样本Id
- for _, tubeId := range actualTubeIds {
- if sampleId == tubeId {
- operaTubeIds = append(operaTubeIds, tubeId)
- break
- }
- }
- //操作失败样本Id
- for _, tubeId := range abnormalTubeIds {
- if sampleId == tubeId {
- failTubeIds = append(failTubeIds, tubeId)
- break
- }
- }
- }
- }
- if applyType == TASK_TUBE_RETREIVING {
- for _, sampleId := range sampleIds {
- //操作成功样本Id
- for _, tubeId := range actualTubeIds {
- if sampleId == tubeId {
- operaTubeIds = append(operaTubeIds, sampleId)
- }
- }
- //操作失败样本Id
- for _, tubeId := range abnormalTubeIds {
- if sampleId == tubeId {
- failTubeIds = append(failTubeIds, tubeId)
- break
- }
- }
- }
- }
- actualIds = "'" + strings.Join(operaTubeIds, "','") + "'"
- abnormalIds = "'" + strings.Join(failTubeIds, ",") + "'"
- glog.Info("处理成功数据:", actualIds)
- glog.Info("处理失败数据:", abnormalIds)
- return
- }
- //当任务为rack_retrieving 且 end 时, 获取所有样本Ids
- func (this *ConverseService) getAllSampleIdsFromResEntity(entity ResponseEntity) (actualIds string, abnormalIds string) {
- //获取反馈报文中的所有成功样本Id列表
- var actualTubeIds []string
- for _, single := range entity.Data.Actual_data {
- for _, tube := range single.Tubes {
- actualTubeIds = append(actualTubeIds, tube.Id)
- }
- }
- actualIds = "'" + strings.Join(actualTubeIds, "','") + "'"
- abnormalIds = ""
- return
- }
- //保存异常信息
- func (this *ConverseService) SaveTaskExcepMsg(msg, taskId string) error {
- sql := "UPDATE " + TABLE_TAST + " SET exception = '" + msg + "' WHERE task_id = '" + taskId + "'"
- _, err := this.DBE.Exec(sql)
- return err
- }
- //保存异常信息
- func (this *ConverseService) SaveSampleExcepMsg(msg, entryNo string) error {
- sql := "UPDATE " + TABLE_SAMPLE_APPLY + " SET exception = '" + msg + "' WHERE entryno = '" + entryNo + "'"
- _, err := this.DBE.Exec(sql)
- return err
- }
- //根据条件删除数据,不记录日志
- func (this *ConverseService) DeleteEntityBytbl(tablename string, where string) (err error) {
- if where == "" {
- where = "1=2"
- }
- sql := `delete from ` + tablename + ` where ` + where
- _, err = this.DBE.Exec(sql)
- return
- }
- //样本库分表
- func (s *ConverseSessionService) InsertEntityBytbl(tablename string, entity interface{}) (affected int64, err error) {
- affected, err = s.Session.Table(tablename).Insert(entity)
- LogError(err)
- return
- }
- //获取设备名称
- func (s *ConverseService) GetEquipmentName(cu int) string {
- sql := "SELECT name from " + TABLE_EQUIPMENT + " where cu = '" + strconv.Itoa(cu) + "'"
- var entity Equipment
- s.DBE.SQL(sql).Get(&entity)
- return entity.Name
- }
- //异常信息转换
- func (s *ConverseService) HandleCauses(causes []Cause) string {
- var exceptInfo string
- for _, cause := range causes {
- eName := s.GetEquipmentName(cause.Cu)
- exceptInfo += s.GetReason(cause, eName)
- }
- return exceptInfo
- }
- //根据异常码获取异常原因
- func (s *ConverseService) GetReason(cause Cause, equipmentName string) string {
- var reasonStr string
- switch cause.Reason {
- case 1:
- reasonStr = "存储位不够;"
- break
- case 2:
- reasonStr = "单次任务涉及的冻存盒数量超出限制;"
- break
- case 3:
- reasonStr = "指定的位置已经被占用或者位置不正确,无法存入;"
- break
- case 4:
- reasonStr = "没有权限对指定位置进行操作;"
- break
- case 5:
- reasonStr = "指定的编号不正确,无法完成操作;"
- break
- case 6:
- reasonStr = "报文数据不完整,缺少冻存管数据;"
- break
- case 7:
- reasonStr = "相同的冻存盒位置只允许有一组报文数据;"
- break
- case 8:
- reasonStr = "半自动设备在不配置转运机器人的情况下,一个存管任务只允许操作一台设备;"
- default:
- reasonStr = cause.Msg
- }
- if cause.Cu != 0 {
- //reasonStr = strconv.Itoa(cause.Cu)+"号设备, " + equipmentName + "," + reasonStr
- reasonStr = "设备: " + equipmentName + "," + reasonStr
- }
- return reasonStr
- }
- //处理Exceptions异常信息
- func (s *ConverseService) HandleExceptions(excepts []Exception) string {
- var exceptStr string
- for _, except := range excepts {
- eName := s.GetEquipmentName(except.Cu)
- for _, code := range except.Codes {
- //var tempStr = string(except.Cu)+"号设备," + eName + ","
- var tempStr = "设备: " + eName + ","
- switch code {
- case 40200:
- tempStr += "移动盒子过程中设备故障,动作失败;"
- break
- case 40201:
- tempStr += "移动盒子过程中目标位置不为空,动作取消;"
- break
- case 40202:
- tempStr += "移动盒子过程中起始位置为空,动作取消;"
- break
- case 40300:
- tempStr += "移动管子过程中设备故障,动作失败;"
- break
- case 40301:
- tempStr = "移动管子过程中目标位置不为空,动作取消;"
- break
- case 40302:
- tempStr = "移动管子过程中起始位置为空,动作取消;"
- }
- exceptStr += tempStr
- }
- }
- return exceptStr
- }
- //处理返回设备状态数据, 并存储到数据表里
- func RecordDeviceData(list []List_Data) {
- t := time.Now()
- var data []GenePoint_Device_Report_Data
- for _, one := range list {
- var piece GenePoint_Device_Report_Data
- piece.Cu = one.Cu
- piece.Addr = one.Addr
- piece.Type = one.Type
- piece.Value = one.Value
- piece.RecordTime = t
- data = append(data, piece)
- }
- svc := GetConverseService(utils.DBE)
- svc.InsertEntity(data)
- }
- // 更新异常信息
- func (s *ConverseService) SaveErrInfo(err, taskid string, reqType string) {
- // 任务发送失败,,,修改任务状态,,,,提示任务执行失败
- // 请求发送失败
- svc := GetConverseService(utils.DBE)
- // add by 徐春林 库内整理错误信息保存
- asvc := arrangeService.GetArrangeService(utils.DBE)
- svc.SaveTaskExcepMsg(err, taskid)
- if reqType == "moving" {
- asvc.SaveArrangeExcepMsg(err, taskid)
- } else {
- 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, "")
- }
- }
|