package controllers import ( "IC/enums" "IC/models" "IC/service" "IC/utils" "encoding/json" "fmt" _ "github.com/astaxie/beego" _ "github.com/jinzhu/gorm" _ "strconv" "time" ) // LisController operations for Lis type LisController struct { BaseAPIController } func (c *LisController) Schedule() { for i := 762429; i > 0; i-- { schedule,err := service.GetScheduless(int64(i)) fmt.Println(schedule.ID) if err == nil { service.UpdateSchedule(schedule.ID,schedule.Status) } } c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) SyncAdvice() { // 获取备份库里所有的医嘱信息 advices, _ := service.GetAllAdvice() for _, advice := range advices { // if index > 50 { // break // } tempAdvice := models.DoctorAdvice{ ID: advice.ID, Checker: advice.Checker, CheckTime: advice.CheckTime, CheckState: advice.CheckState, } service.SyncAdvice(&tempAdvice) } c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) FiledConfigSys() { orgs, _ := service.GetfiledConfigOrg() sysFiledConfig, _ := service.GetfiledConfigSys() if len(orgs) > 0 { for _, org := range orgs { for _, filed := range sysFiledConfig { filedConfig, _ := service.GetfiledConfigByOrgId(org.OrgId, filed.Module, filed.FiledName) if filedConfig.ID > 0 { continue } else { tempfiled := models.FiledConfig{ OrgId: org.OrgId, Module: filed.Module, FiledName: filed.FiledName, FiledNameCn: filed.FiledNameCn, IsShow: 2, } service.CreatefiledConfig(&tempfiled) } } } } c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) SyncToBase() { org_id, _ := c.GetInt64("org_id", 0) if org_id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } // 第一步:跟进org_id 去中间库查出需要同步的数据 inspection_references, _ := service.GetSyncInspectionReferenceByOrgId(org_id) inspections, _ := service.GetSyncInspectionByOrgId(org_id) // 第二步:将数据同步到业务库 if len(inspection_references) > 0 { for _, inspection_reference := range inspection_references { service.SyncInspectionReference(&inspection_reference) } } if len(inspections) > 0 { for _, inspection := range inspections { service.SyncInspection(&inspection) } } c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) GetList() { org_id, _ := c.GetInt64("org_id", 0) if org_id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } // 第一步:根据机构id获取对应机构所有病人的his_user_id patients, patientError := service.GetHisUserIdByOrgID(org_id) if patientError != nil { utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } patientStr := make([]interface{}, 0) if len(patients) > 0 { // 第二步:根据病人的his_user_id来查询上次同步时间 for _, patient := range patients { if len(patient.HisUserId) <= 0 { continue } // if patient.SelectType != 1 { // continue // } syncLastInfo, _ := service.GetSyncTimeByOrgID(org_id, patient.HisUserId) var sync_time int64 if syncLastInfo.ID > 0 { sync_time = syncLastInfo.SyncTime } else { inspectionLastInfo, _ := service.GetInspectionLastInfoByOrgID(org_id, patient.HisUserId) if inspectionLastInfo.ID > 0 { sync_time = inspectionLastInfo.CreatedTime } else { sync_time = 1609430400 } } syncTimes := time.Unix(sync_time, 0).Format("2006-01-02 15:04") utils.InfoLog("syncTimes:%v", syncTimes) // 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录 resultList, _ := service.GetListByHisUserID(patient.HisUserId, syncTimes, patient.SelectType) var syncInfo models.MiddleSyncInfo if len(resultList) > 0 { // 如果有数据,则把同步过来的详情插入一条数据到同步详情表中 syncInfo.OrgId = org_id syncInfo.HisUserId = patient.HisUserId syncInfo.SyncTime = time.Now().Unix() syncInfo.SyncResultType = 1 syncInfo.SyncRsultRemark = "同步成功" syncInfo.SyncTotalNum = int64(len(resultList)) syncInfo.SyncSuccessNum = 0 SyncInfos, _ := json.Marshal(resultList) syncInfo.SyncInfo = string(SyncInfos) syncInfo.CreateTime = time.Now().Unix() syncInfo.UpdateTime = time.Now().Unix() err := service.CreateSyncInfo(&syncInfo) if err != nil { utils.ErrorLog("创建同步信息失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else { // 如果没有数据,则插入一条数据到同步详情表中 syncInfo.OrgId = org_id syncInfo.HisUserId = patient.HisUserId syncInfo.SyncTime = time.Now().Unix() syncInfo.SyncResultType = 1 syncInfo.SyncRsultRemark = "该患者这个时间段没有任何检验检查数据" syncInfo.CreateTime = time.Now().Unix() syncInfo.UpdateTime = time.Now().Unix() err := service.CreateSyncInfo(&syncInfo) if err != nil { utils.ErrorLog("创建同步信息失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } // utils.InfoLog("同步信息详情:%v",syncInfo) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) continue } // 第四部:将同步过来的数据插入到中间库对应的表 syncSuccessNum := 0 for _, result := range resultList { utils.ErrorLog("result:%v", result) if (result.HisUserId == patient.HisUserId) || (result.PatientName == patient.HisUserId) { patientId := patient.XtPatientId if patientId > 0 { inspection_reference, inspection, _ := service.Sync(result, org_id, patientId) if inspection_reference.ID > 0 || inspection.ID > 0 { syncSuccessNum++ } } } } syncInfo.SyncSuccessNum = int64(syncSuccessNum) service.UpdateSyncInfo(&syncInfo) // patientStr = append(patientStr,patient.HisUserId) // utils.InfoLog("patientStr:%v",patientStr) } } else { var syncInfo models.MiddleSyncInfo // 如果没有数据,则插入一条数据到同步详情表中 syncInfo.OrgId = org_id syncInfo.SyncTime = time.Now().Unix() syncInfo.SyncResultType = 0 syncInfo.SyncRsultRemark = "该机构没有对应的his_user_id" syncInfo.CreateTime = time.Now().Unix() syncInfo.UpdateTime = time.Now().Unix() err := service.CreateSyncInfo(&syncInfo) if err != nil { utils.ErrorLog("创建同步信息失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } utils.InfoLog("同步信息详情:%v", syncInfo) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } utils.InfoLog("patientStr:%v", patientStr) // // 第一步:根据机构id获取上次同步时间 // syncLastInfo,_ := service.GetSyncTimeByOrgID(org_id) // var sync_time int64 // if syncLastInfo.ID > 0 { // sync_time = syncLastInfo.SyncTime // } else { // sync_time = 0 // } // syncTimes := time.Unix(sync_time,0).Format("2006-01-02 15:04") // utils.InfoLog("syncTimes:%v",syncTimes) // // 第二步:根据机构id获取对应机构所有病人的his_user_id // patients,patientError := service.GetHisUserIdByOrgID(org_id) // if patientError != nil { // utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError) // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } // patientStr:= make([]interface{},0) // if len(patients) > 0 { // for _ , patient := range patients { // patientStr = append(patientStr,patient.HisUserId) // utils.InfoLog("patientStr:%v",patientStr) // } // } else { // // 如果没有数据,则插入一条数据到同步详情表中 // syncInfo.OrgId = org_id // syncInfo.SyncTime = time.Now().Unix() // syncInfo.SyncResultType = 0 // syncInfo.SyncRsultRemark = "该机构没有对应的his_user_id" // syncInfo.CreateTime = time.Now().Unix() // syncInfo.UpdateTime = time.Now().Unix() // err := service.CreateSyncInfo(&syncInfo) // if err != nil { // utils.ErrorLog("创建同步信息失败:%v", err) // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } // utils.InfoLog("同步信息详情:%v",syncInfo) // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } // utils.InfoLog("patientStr:%v",patientStr) // // 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录 // resultList, _ := service.GetList(patientStr,syncTimes) // if len(resultList) > 0 { // // 如果有数据,则把同步过来的详情插入一条数据到同步详情表中 // syncInfo.OrgId = org_id // syncInfo.SyncTime = time.Now().Unix() // syncInfo.SyncResultType = 1 // syncInfo.SyncRsultRemark = "同步成功" // syncInfo.SyncTotalNum = int64(len(resultList)) // syncInfo.SyncSuccessNum = 0 // SyncInfos,_ := json.Marshal(resultList) // syncInfo.SyncInfo = string(SyncInfos) // syncInfo.CreateTime = time.Now().Unix() // syncInfo.UpdateTime = time.Now().Unix() // err := service.CreateSyncInfo(&syncInfo) // if err != nil { // utils.ErrorLog("创建同步信息失败:%v", err) // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } // } else { // // 如果没有数据,则插入一条数据到同步详情表中 // syncInfo.OrgId = org_id // syncInfo.SyncTime = time.Now().Unix() // syncInfo.SyncResultType = 1 // syncInfo.SyncRsultRemark = "该机构这个时间段没有任何检验检查数据" // syncInfo.CreateTime = time.Now().Unix() // syncInfo.UpdateTime = time.Now().Unix() // err := service.CreateSyncInfo(&syncInfo) // if err != nil { // utils.ErrorLog("创建同步信息失败:%v", err) // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } // // utils.InfoLog("同步信息详情:%v",syncInfo) // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } // // 第四部:将同步过来的数据插入到中间库对应的表 // syncSuccessNum := 0 // for _, result := range resultList { // patientId := int64(0) // for _ , patientInfo := range patients { // if result.HisUserId == patientInfo.HisUserId { // patientId = patientInfo.XtPatientId // break // } // } // if patientId > 0 { // inspection_reference,inspection,_ := service.Sync(result,org_id,patientId) // if (inspection_reference.ID > 0 || inspection.ID > 0 ) { // syncSuccessNum++ // } // } // } // syncInfo.SyncSuccessNum = int64(syncSuccessNum) // service.UpdateSyncInfo(&syncInfo) c.ServeSuccessJSON(map[string]interface{}{ "resultList": patients, }) return } func (c *LisController) SyncLgth() { service.SyncLisLgty() c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) SyncYstx() { service.SyncLisYstx() c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) SyncGzjhyz() { service.SyncGzjhyz() c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) SyncGzjhLis() { service.SyncGzjhLis() c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) SyncHbJldyyz() { service.SyncHbJldyyz() c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) SyncHbJldyLis() { service.SyncHbdyLis() c.ServeSuccessJSON(map[string]interface{}{ "resultList": "12345", }) return } func (c *LisController) SyncBlLis() { service.GetDataInsertDB(10138) c.ServeSuccessJSON(map[string]interface{}{ "resultList": "同步成功", }) } func (c *LisController) SyncBlResultLis() { service.GetResultDataInsertDB(10138) c.ServeSuccessJSON(map[string]interface{}{ "resultList": "同步成功", }) } //肇庆三鹤 func (c *LisController) SyncZQSHResultLis() { service.GetResultDataInsertDB(10215) c.ServeSuccessJSON(map[string]interface{}{ "resultList": "同步成功", }) }