csny_service.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. package service
  2. import (
  3. "IC/models"
  4. "IC/utils"
  5. _ "IC/utils"
  6. "bytes"
  7. "encoding/json"
  8. _ "encoding/json"
  9. _ "encoding/xml"
  10. "fmt"
  11. _ "github.com/jinzhu/gorm"
  12. "io/ioutil"
  13. "net/http"
  14. "unicode/utf8"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. func lastThreeChars(s string) string {
  20. runeCount := 0
  21. for i := len(s); i > 0; {
  22. _, size := utf8.DecodeLastRuneInString(s[:i])
  23. i -= size
  24. runeCount++
  25. if runeCount == 3 {
  26. return s[i:]
  27. }
  28. }
  29. // 如果字符串长度少于3个字符,则返回整个字符串或空字符串
  30. if runeCount == 0 {
  31. return ""
  32. }
  33. return s
  34. }
  35. // 福建天福医院透析中心Lis同步
  36. func SyncCsnyLis() (err error) {
  37. org_id := int64(10340)
  38. //org_id_other := int64(103401)
  39. // 第一步:获取上一次同步的时间点
  40. syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
  41. var sync_time int64
  42. if syncLastInfo.ID > 0 {
  43. sync_time = syncLastInfo.SyncTime
  44. } else {
  45. sync_time = 1651334400 // 2022-05-01 00:00:00
  46. }
  47. //syncLastInfo1, _ := GetSyncTimeByOrgIDForYs(org_id_other)
  48. //var sync_time_other int64
  49. //if syncLastInfo1.ID > 0 {
  50. // sync_time_other = syncLastInfo1.SyncTime
  51. //} else {
  52. // sync_time_other = 1651334400 // 2022-05-01 00:00:00
  53. //}
  54. sync_time_temp := time.Unix(sync_time, 0)
  55. syncTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
  56. //sync_time_temp_1 := time.Unix(sync_time_other, 0)
  57. //syncTimeStr_1 := sync_time_temp_1.Format("2006-01-02 15:04:05")
  58. // 第二步:获取所有患者的病历号
  59. patientList, _ := GetPatientGzjhByOrgId(org_id)
  60. if len(patientList) > 0 {
  61. // 体检的检验数据
  62. //for _, patient := range patientList {
  63. // if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
  64. // patient_id := patient.ID
  65. // var patient_name string
  66. // length := len(patient.Name)
  67. // if length >= 3 {
  68. // utils.InfoLog("名字:%v", patient.Name)
  69. // lastThree := lastThreeChars(patient.Name)
  70. // utils.InfoLog("截取后的名字:%v", lastThree)
  71. // re := regexp.MustCompile("[0-9]+")
  72. // patient_name = re.ReplaceAllString(lastThree, "")
  73. // } else {
  74. // patient_name = patient.Name
  75. // }
  76. // result, _ := CsnyGetLabTj(patient_name, syncTimeStr_1)
  77. // utils.InfoLog("result:%v", result)
  78. // var fjtfLab LabCsnyResult
  79. // if err := json.Unmarshal([]byte(result), &fjtfLab); err != nil {
  80. // utils.ErrorLog("解析失败:%v", err)
  81. // }
  82. // fmt.Println(fjtfLab)
  83. //
  84. // if len(fjtfLab.Result) > 0 {
  85. // // 根据获取的头部lab01获取检查结果
  86. //
  87. // for _, info := range fjtfLab.Result {
  88. // lacResult, _ := CsnyGetLac(info.Lab01)
  89. // utils.InfoLog("lacResult:%v", lacResult)
  90. // var fjtfLac LacCsnyResult
  91. // if err := json.Unmarshal([]byte(lacResult), &fjtfLac); err != nil {
  92. // utils.ErrorLog("解析失败:%v", err)
  93. // }
  94. // fmt.Println(fjtfLac)
  95. // for _, cinfo := range fjtfLac.Result {
  96. // project_id := int64(0)
  97. // item_id := int64(0)
  98. // if len(cinfo.Bbx05a) > 0 {
  99. // project_id, _ = GetCsnyProjectID(org_id, cinfo.Bbx05a)
  100. // item_id, _ = GetCsnyItemID(org_id, cinfo.Bbx05a, cinfo.Bbx05, project_id)
  101. // } else {
  102. // project_id, _ = GetCsnyProjectID(org_id, cinfo.Bbx05)
  103. // item_id, _ = GetCsnyItemID(org_id, cinfo.Bbx05, cinfo.Bbx05, project_id)
  104. // }
  105. //
  106. // tx := writeMiddleDb.Begin()
  107. // var inspection models.MiddleInspection
  108. // var inspection_reference models.MiddleInspectionReference
  109. //
  110. // loc, _ := time.LoadLocation("Local")
  111. // theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Lac25, loc)
  112. // record_date := theTime.Unix()
  113. //
  114. // if record_date == 0 {
  115. // record_date = time.Now().Unix()
  116. // }
  117. //
  118. // inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
  119. // var total int
  120. // var RangeOptions string
  121. // var RangeMin string
  122. // var RangeMax string
  123. //
  124. // // // 判断检查类型
  125. // ItemType := 1
  126. // Range := strings.Split(cinfo.Lac15, "-")
  127. // if len(Range) > 1 {
  128. // RangeMin = cinfo.Lac13
  129. // RangeMax = cinfo.Lac14
  130. // ItemType = 1
  131. // } else {
  132. // ItemType = 2
  133. // RangeOptions = cinfo.Lac15
  134. // }
  135. //
  136. // err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
  137. // // if inspection_reference.ID > 0 {
  138. // // ItemType = int64(inspection_reference.RangeType)
  139. // // }
  140. //
  141. // if total <= 0 {
  142. // inspection_reference.OrgId = org_id
  143. // if len(cinfo.Bbx05a) > 0 {
  144. // inspection_reference.ProjectName = cinfo.Bbx05a
  145. // inspection_reference.Project = cinfo.Bbx05a
  146. // } else {
  147. // inspection_reference.ProjectName = cinfo.Bbx05
  148. // inspection_reference.Project = cinfo.Bbx05
  149. // }
  150. // inspection_reference.ProjectId = project_id
  151. // inspection_reference.ItemName = cinfo.Bbx05
  152. // inspection_reference.ItemId = item_id
  153. // inspection_reference.RangeType = ItemType
  154. // inspection_reference.RangeMin = RangeMin
  155. // inspection_reference.RangeMax = RangeMax
  156. // // inspection_reference.RangeValue = RangeValue
  157. // inspection_reference.RangeOptions = RangeOptions
  158. // inspection_reference.Unit = cinfo.Bdg02
  159. // inspection_reference.Status = 1
  160. // inspection_reference.CreatedTime = time.Now().Unix()
  161. // inspection_reference.UpdatedTime = time.Now().Unix()
  162. // inspection_reference.InspectDate = inspect_date
  163. // inspection_reference.UTime = inspect_date
  164. // err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  165. // if err != nil {
  166. // tx.Rollback()
  167. // }
  168. // }
  169. //
  170. // var itotal int
  171. // err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ? and status = 1", org_id, project_id, item_id, record_date, patient_id).Find(&inspection).Count(&itotal).Error
  172. // if itotal <= 0 {
  173. // inspection.PatientId = patient_id
  174. // inspection.OrgId = org_id
  175. // inspection.ProjectId = project_id
  176. // inspection.ItemName = inspection_reference.ItemName
  177. // inspection.ProjectName = inspection_reference.ProjectName
  178. // inspection.InspectType = ItemType
  179. // inspection.ItemId = item_id
  180. // inspection.InspectValue = cinfo.Lac10
  181. // inspection.InspectDate = inspect_date
  182. // inspection.RecordDate = record_date
  183. // inspection.InspectTips = cinfo.Lac11
  184. // inspection.Status = 1
  185. // inspection.CreatedTime = time.Now().Unix()
  186. // inspection.UpdatedTime = time.Now().Unix()
  187. // inspection.UTime = inspect_date
  188. // inspection.HisUserId = strconv.FormatInt(patient_id, 10)
  189. // err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  190. // if err != nil {
  191. // tx.Rollback()
  192. // }
  193. // }
  194. //
  195. // tx.Commit()
  196. //
  197. // }
  198. // }
  199. // }
  200. // } else {
  201. // continue
  202. // }
  203. //}
  204. for _, patient := range patientList {
  205. if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
  206. patient_id := patient.ID
  207. utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
  208. // utils.InfoLog("VipStr:%v", VipStr)
  209. result1, _ := CsnyGetLab(patient.IdCardNo, syncTimeStr)
  210. utils.InfoLog("result:%v", result1)
  211. var fjtfLab LabCsnyResult
  212. if err := json.Unmarshal([]byte(result1), &fjtfLab); err != nil {
  213. utils.ErrorLog("解析失败:%v", err)
  214. }
  215. fmt.Println(fjtfLab)
  216. if len(fjtfLab.Result) > 0 {
  217. // 根据获取的头部lab01获取检查结果
  218. for _, info := range fjtfLab.Result {
  219. lacResult, _ := CsnyGetLac(info.Lab01)
  220. utils.InfoLog("lacResult:%v", lacResult)
  221. var fjtfLac LacCsnyResult
  222. if err := json.Unmarshal([]byte(lacResult), &fjtfLac); err != nil {
  223. utils.ErrorLog("解析失败:%v", err)
  224. }
  225. fmt.Println(fjtfLac)
  226. for _, cinfo := range fjtfLac.Result {
  227. project_id := int64(0)
  228. item_id := int64(0)
  229. if len(cinfo.Bbx05a) > 0 {
  230. project_id, _ = GetCsnyProjectID(org_id, cinfo.Bbx05a)
  231. item_id, _ = GetCsnyItemID(org_id, cinfo.Bbx05a, cinfo.Bbx05, project_id)
  232. } else {
  233. project_id, _ = GetCsnyProjectID(org_id, cinfo.Bbx05)
  234. item_id, _ = GetCsnyItemID(org_id, cinfo.Bbx05, cinfo.Bbx05, project_id)
  235. }
  236. tx := writeMiddleDb.Begin()
  237. var inspection models.MiddleInspection
  238. var inspection_reference models.MiddleInspectionReference
  239. loc, _ := time.LoadLocation("Local")
  240. theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Lac25, loc)
  241. record_date := theTime.Unix()
  242. if record_date == 0 {
  243. record_date = time.Now().Unix()
  244. }
  245. inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
  246. var total int
  247. var RangeOptions string
  248. var RangeMin string
  249. var RangeMax string
  250. // // 判断检查类型
  251. ItemType := 1
  252. Range := strings.Split(cinfo.Lac15, "-")
  253. if len(Range) > 1 {
  254. RangeMin = cinfo.Lac13
  255. RangeMax = cinfo.Lac14
  256. ItemType = 1
  257. } else {
  258. ItemType = 2
  259. RangeOptions = cinfo.Lac15
  260. }
  261. err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
  262. // if inspection_reference.ID > 0 {
  263. // ItemType = int64(inspection_reference.RangeType)
  264. // }
  265. if total <= 0 {
  266. inspection_reference.OrgId = org_id
  267. if len(cinfo.Bbx05a) > 0 {
  268. inspection_reference.ProjectName = cinfo.Bbx05a
  269. inspection_reference.Project = cinfo.Bbx05a
  270. } else {
  271. inspection_reference.ProjectName = cinfo.Bbx05
  272. inspection_reference.Project = cinfo.Bbx05
  273. }
  274. inspection_reference.ProjectId = project_id
  275. inspection_reference.ItemName = cinfo.Bbx05
  276. inspection_reference.ItemId = item_id
  277. inspection_reference.RangeType = ItemType
  278. inspection_reference.RangeMin = RangeMin
  279. inspection_reference.RangeMax = RangeMax
  280. // inspection_reference.RangeValue = RangeValue
  281. inspection_reference.RangeOptions = RangeOptions
  282. inspection_reference.Unit = cinfo.Bdg02
  283. inspection_reference.Status = 1
  284. inspection_reference.CreatedTime = time.Now().Unix()
  285. inspection_reference.UpdatedTime = time.Now().Unix()
  286. inspection_reference.InspectDate = inspect_date
  287. inspection_reference.UTime = inspect_date
  288. err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  289. if err != nil {
  290. tx.Rollback()
  291. }
  292. }
  293. var itotal int
  294. err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ? and status = 1", org_id, project_id, item_id, record_date, patient_id).Find(&inspection).Count(&itotal).Error
  295. if itotal <= 0 {
  296. inspection.PatientId = patient_id
  297. inspection.OrgId = org_id
  298. inspection.ProjectId = project_id
  299. inspection.ItemName = inspection_reference.ItemName
  300. inspection.ProjectName = inspection_reference.ProjectName
  301. inspection.InspectType = ItemType
  302. inspection.ItemId = item_id
  303. inspection.InspectValue = cinfo.Lac10
  304. inspection.InspectDate = inspect_date
  305. inspection.RecordDate = record_date
  306. inspection.InspectTips = cinfo.Lac11
  307. inspection.Status = 1
  308. inspection.CreatedTime = time.Now().Unix()
  309. inspection.UpdatedTime = time.Now().Unix()
  310. inspection.UTime = inspect_date
  311. inspection.HisUserId = strconv.FormatInt(patient_id, 10)
  312. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  313. if err != nil {
  314. tx.Rollback()
  315. }
  316. }
  317. tx.Commit()
  318. }
  319. }
  320. }
  321. } else {
  322. continue
  323. }
  324. }
  325. }
  326. var syncInfo models.MiddleSyncInfo
  327. syncInfo.OrgId = org_id
  328. syncInfo.SyncTime = time.Now().Unix()
  329. syncInfo.SyncResultType = 1
  330. syncInfo.SyncRsultRemark = "同步成功"
  331. syncInfo.SyncTotalNum = 0
  332. syncInfo.SyncSuccessNum = 0
  333. syncInfo.SyncInfo = ""
  334. syncInfo.CreateTime = time.Now().Unix()
  335. syncInfo.UpdateTime = time.Now().Unix()
  336. cwderr := CreateSyncInfo(&syncInfo)
  337. if cwderr != nil {
  338. utils.ErrorLog("创建同步信息失败:%v", cwderr)
  339. return
  340. }
  341. //var syncInfos models.MiddleSyncInfo
  342. //syncInfos.OrgId = org_id_other
  343. //syncInfos.SyncTime = time.Now().Unix()
  344. //syncInfos.SyncResultType = 1
  345. //syncInfos.SyncRsultRemark = "同步成功"
  346. //syncInfos.SyncTotalNum = 0
  347. //syncInfos.SyncSuccessNum = 0
  348. //syncInfos.SyncInfo = ""
  349. //syncInfos.CreateTime = time.Now().Unix()
  350. //syncInfos.UpdateTime = time.Now().Unix()
  351. //
  352. //cwderrs := CreateSyncInfo(&syncInfos)
  353. //if cwderrs != nil {
  354. // utils.ErrorLog("创建同步信息失败:%v", cwderrs)
  355. // return
  356. //}
  357. SyncToCsnytx()
  358. return
  359. }
  360. type LabCsnyResult struct {
  361. Msg string `json:"msg"`
  362. Result []struct {
  363. Lab01 int64 `json:"lab01"`
  364. Lab58 string `json:"lab58"`
  365. } `json:"result"`
  366. Code string `json:"code"`
  367. }
  368. func CsnyGetLab(id_card_no string, synctime string) (string, string) {
  369. inputData := make(map[string]interface{})
  370. inputData["vaa15"] = id_card_no
  371. inputData["begintime"] = synctime
  372. var inputLog string
  373. bytesData, err := json.Marshal(inputData)
  374. inputLog = string(bytesData)
  375. fmt.Println(string(bytesData))
  376. if err != nil {
  377. fmt.Println(err.Error())
  378. return err.Error(), ""
  379. }
  380. reader := bytes.NewReader(bytesData)
  381. url := "http://58.20.58.241:9092/esb/listener/getLab1"
  382. request, err := http.NewRequest("POST", url, reader)
  383. if err != nil {
  384. fmt.Println(err.Error())
  385. return err.Error(), ""
  386. }
  387. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  388. request.Header.Set("code", "Xmrjyy")
  389. client := http.Client{}
  390. resp, err := client.Do(request)
  391. if err != nil {
  392. fmt.Println(err.Error())
  393. return err.Error(), ""
  394. }
  395. respBytes, err := ioutil.ReadAll(resp.Body)
  396. if err != nil {
  397. fmt.Println(err.Error())
  398. return err.Error(), ""
  399. }
  400. str := string(respBytes)
  401. return str, inputLog
  402. }
  403. func CsnyGetLabTj(patient_name string, synctime string) (string, string) {
  404. inputData := make(map[string]interface{})
  405. inputData["vaa05"] = patient_name
  406. inputData["begintime"] = synctime
  407. var inputLog string
  408. bytesData, err := json.Marshal(inputData)
  409. inputLog = string(bytesData)
  410. fmt.Println(string(bytesData))
  411. if err != nil {
  412. fmt.Println(err.Error())
  413. return err.Error(), ""
  414. }
  415. reader := bytes.NewReader(bytesData)
  416. url := "http://58.20.58.241:9092/esb/listener/getLab1"
  417. request, err := http.NewRequest("POST", url, reader)
  418. if err != nil {
  419. fmt.Println(err.Error())
  420. return err.Error(), ""
  421. }
  422. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  423. request.Header.Set("code", "Xmrjyy")
  424. client := http.Client{}
  425. resp, err := client.Do(request)
  426. if err != nil {
  427. fmt.Println(err.Error())
  428. return err.Error(), ""
  429. }
  430. respBytes, err := ioutil.ReadAll(resp.Body)
  431. if err != nil {
  432. fmt.Println(err.Error())
  433. return err.Error(), ""
  434. }
  435. str := string(respBytes)
  436. return str, inputLog
  437. }
  438. type LacCsnyResult struct {
  439. Msg string `json:"msg"`
  440. Result []struct {
  441. Lab01 int64 `json:"labo1"`
  442. Bbx05 string `json:"BBX05"`
  443. Bbx05a string `json:"BBX05A"`
  444. Bfc03 string `json:"BFC03"`
  445. Bdg02 string `json:"BDG02"`
  446. Lac10 string `json:"LAC10"`
  447. Lac11 string `json:"LAC11"`
  448. Lac13 string `json:"LAC13"`
  449. Lac14 string `json:"LAC14"`
  450. Lac15 string `json:"LAC15"`
  451. Lac25 string `json:"LAC25"`
  452. } `json:"result"`
  453. Code string `json:"code"`
  454. }
  455. func CsnyGetLac(lab01 int64) (string, string) {
  456. inputData := make(map[string]interface{})
  457. inputData["lab01"] = lab01
  458. var inputLog string
  459. bytesData, err := json.Marshal(inputData)
  460. inputLog = string(bytesData)
  461. fmt.Println(string(bytesData))
  462. if err != nil {
  463. fmt.Println(err.Error())
  464. return err.Error(), ""
  465. }
  466. reader := bytes.NewReader(bytesData)
  467. url := "http://58.20.58.241:9092/esb/listener/getLac1"
  468. request, err := http.NewRequest("POST", url, reader)
  469. if err != nil {
  470. fmt.Println(err.Error())
  471. return err.Error(), ""
  472. }
  473. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  474. request.Header.Set("code", "Xmrjyy")
  475. client := http.Client{}
  476. resp, err := client.Do(request)
  477. if err != nil {
  478. fmt.Println(err.Error())
  479. return err.Error(), ""
  480. }
  481. respBytes, err := ioutil.ReadAll(resp.Body)
  482. if err != nil {
  483. fmt.Println(err.Error())
  484. return err.Error(), ""
  485. }
  486. str := string(respBytes)
  487. return str, inputLog
  488. }
  489. // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
  490. func GetCsnyProjectID(org_id int64, project_name string) (project_id int64, err error) {
  491. var inspection_reference models.MiddleInspectionReference
  492. err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
  493. if inspection_reference.ID > 0 {
  494. return inspection_reference.ProjectId, err
  495. } else {
  496. err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
  497. if inspection_reference.ProjectId > 0 {
  498. return inspection_reference.ProjectId + 1, err
  499. } else {
  500. return 340001, err
  501. }
  502. }
  503. }
  504. // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
  505. func GetCsnyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
  506. var inspection_reference models.MiddleInspectionReference
  507. err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ? and item_name = ?", org_id, project_name, item_name).First(&inspection_reference).Error
  508. if inspection_reference.ID > 0 {
  509. return inspection_reference.ItemId, err
  510. } else {
  511. err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
  512. utils.InfoLog("inspection_reference: %v", inspection_reference)
  513. if inspection_reference.ItemId > 0 {
  514. return inspection_reference.ItemId + 1, err
  515. } else {
  516. return project_id*100 + 1, err
  517. }
  518. }
  519. }
  520. func SyncToCsnytx() {
  521. utils.TraceLog("检验检查同步任务开始执行")
  522. org_id := int64(10340)
  523. // 第一步:跟进org_id 去中间库查出需要同步的数据
  524. inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
  525. inspections, _ := GetSyncInspectionByOrgId(org_id)
  526. // 第二步:将数据同步到业务库
  527. if len(inspection_references) > 0 {
  528. for _, inspection_reference := range inspection_references {
  529. SyncInspectionReference(&inspection_reference)
  530. }
  531. }
  532. if len(inspections) > 0 {
  533. for _, inspection := range inspections {
  534. SyncInspection(&inspection)
  535. }
  536. }
  537. utils.SuccessLog("检验检查同步任务完成")
  538. }