auto_create_week_schedules_service.go 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. package city
  2. import (
  3. "Data_Upload_Api/models/sz"
  4. "Data_Upload_Api/service"
  5. "XT/utils"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "github.com/jinzhu/gorm"
  9. "github.com/robfig/cron"
  10. "math"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. var createUploadDataCronJob *cron.Cron
  16. func init() {
  17. utils.InfoLog("开启定时任务")
  18. createUploadDataCronJob = cron.New()
  19. spec := "0 0 0 * * ?" // 每天凌晨0点检测数据上报情况
  20. createUploadDataCronJob.AddFunc(spec, func() {
  21. AutoSZUploadData() //深圳市数据上报
  22. })
  23. }
  24. func BeginAutoJob() {
  25. createUploadDataCronJob.Start()
  26. }
  27. func AutoSZUploadData() {
  28. //查出所有需要上传到深圳市健康数据中心的机构数据上报配置
  29. //这里暂时用上报到深圳市的方式,来处理数据,如果以后有其他城市,需要在这里对不同城市进行不同数据处理
  30. sz_province, _ := beego.AppConfig.Int64("sz_province")
  31. sz_city, _ := beego.AppConfig.Int64("sz_city")
  32. configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
  33. for _, config := range configs {
  34. //机构
  35. _, err := service.FindDataUploadOrgInfo(config.OrgId, 1)
  36. if err == gorm.ErrRecordNotFound {
  37. if GetDiffDay(config) <= 0 {
  38. //新增
  39. org, _ := service.FindOrgData(config.OrgId)
  40. hospital := &sz.TempHdHospital{
  41. HospitalId: strconv.FormatInt(org.ID, 10),
  42. InstType: strconv.FormatInt(1, 10),
  43. AuthorizedBeds: int64(len(org.DeviceNumber)),
  44. CreateTime: time.Now(),
  45. UpdateTime: time.Now(),
  46. Sjscsj: time.Now(),
  47. Xgbz: 0,
  48. }
  49. err := service.CreateOrgRecord(hospital)
  50. if err == nil {
  51. upload := &sz.DataUpload{
  52. ModuleType: 1,
  53. OrgId: org.ID,
  54. UploadDate: time.Now().Unix(),
  55. UploadStatus: 1,
  56. UploadType: 1,
  57. }
  58. err := service.CreateUploadRecord(upload)
  59. if err != nil {
  60. utils.ErrorLog("%v", err)
  61. }
  62. }
  63. }
  64. }
  65. //机构人员
  66. record, err_two := service.FindDataUploadOrgInfo(config.OrgId, 2)
  67. if err_two == gorm.ErrRecordNotFound {
  68. if GetDiffDay(config) <= 0 {
  69. var staffs []*sz.TempHdStaff
  70. roles, _ := service.FindOrgRolesData(config.OrgId, 0, 0)
  71. for _, role := range roles {
  72. var title string
  73. switch role.UserType {
  74. case 2:
  75. title = strconv.FormatInt(1, 10)
  76. break
  77. case 3:
  78. title = strconv.FormatInt(2, 10)
  79. break
  80. }
  81. staff := &sz.TempHdStaff{
  82. HospitalId: strconv.FormatInt(role.OrgId, 10),
  83. StaffId: strconv.FormatInt(role.ID, 10),
  84. StaffName: role.UserName,
  85. Position: title,
  86. PermanentType: strconv.FormatInt(1, 10),
  87. CreateTime: time.Now(),
  88. UpdateTime: time.Now(),
  89. Sjscsj: time.Now(),
  90. Xgbz: strconv.FormatInt(0, 10),
  91. }
  92. staffs = append(staffs, staff)
  93. }
  94. err := service.BatchCreateStaffRecord(staffs)
  95. if err == nil {
  96. upload := &sz.DataUpload{
  97. ModuleType: 2,
  98. OrgId: config.OrgId,
  99. UploadDate: time.Now().Unix(),
  100. UploadStatus: 1,
  101. UploadType: 1,
  102. }
  103. err := service.CreateUploadRecord(upload)
  104. if err != nil {
  105. utils.ErrorLog("%v", err)
  106. }
  107. }
  108. }
  109. } else if err_two == nil {
  110. if GetDiffDay2(config, record) <= 0 {
  111. var staffs []*sz.TempHdStaff
  112. roles, _ := service.FindOrgRolesData(record.OrgId, record.UploadDate, time.Now().Unix())
  113. for _, role := range roles {
  114. var title string
  115. switch role.UserType {
  116. case 2:
  117. title = strconv.FormatInt(1, 10)
  118. break
  119. case 3:
  120. title = strconv.FormatInt(2, 10)
  121. break
  122. }
  123. staff := &sz.TempHdStaff{
  124. HospitalId: strconv.FormatInt(role.OrgId, 10),
  125. StaffId: strconv.FormatInt(role.ID, 10),
  126. StaffName: role.UserName,
  127. Position: title,
  128. PermanentType: strconv.FormatInt(1, 10),
  129. CreateTime: time.Now(),
  130. UpdateTime: time.Now(),
  131. Sjscsj: time.Now(),
  132. Xgbz: strconv.FormatInt(0, 10),
  133. }
  134. staffs = append(staffs, staff)
  135. }
  136. err := service.BatchCreateStaffRecord(staffs)
  137. if err == nil {
  138. upload := &sz.DataUpload{
  139. ModuleType: 2,
  140. OrgId: record.OrgId,
  141. UploadDate: time.Now().Unix(),
  142. UploadStatus: 1,
  143. UploadType: 1,
  144. }
  145. err := service.CreateUploadRecord(upload)
  146. if err != nil {
  147. utils.ErrorLog("%v", err)
  148. }
  149. }
  150. }
  151. }
  152. record, err_four := service.FindDataUploadOrgInfo(config.OrgId, 4)
  153. if err_four == gorm.ErrRecordNotFound {
  154. if GetDiffDay(config) <= 0 {
  155. var hdPatients []*sz.TempHdPatient
  156. patients, _ := service.FindOrgPatientData(config.OrgId, 0, 0)
  157. for _, patient := range patients {
  158. idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
  159. idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2)) // 月
  160. idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
  161. date := strconv.Itoa(idcard_year) + "-" + strconv.Itoa(idcard_mo) + "-" + strconv.Itoa(idcard_day)
  162. local, _ := time.LoadLocation("Local")
  163. birthday, _ := time.ParseInLocation("2006-01-02", date, local)
  164. var isCKD int
  165. value := strings.Index(patient.Diagnose, "慢性肾脏病")
  166. value2 := strings.Index(patient.Diagnose, "CKD")
  167. value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
  168. if value != -1 || value2 != -1 || value3 != -1 {
  169. isCKD = 1
  170. } else {
  171. isCKD = 0
  172. }
  173. p := &sz.TempHdPatient{
  174. HospitalId: strconv.FormatInt(patient.UserOrgId, 10),
  175. PatientNk: strconv.FormatInt(patient.ID, 10),
  176. CardNo: "000000000000000000",
  177. CardType: "01",
  178. IdNo: patient.IdCardNo,
  179. IdType: "01",
  180. PatientName: patient.Name,
  181. Gender: strconv.FormatInt(patient.Gender, 10),
  182. BornDate: birthday,
  183. DiagnosisSummary: patient.Diagnose,
  184. IsCrf: strconv.Itoa(isCKD),
  185. CreatedTime: time.Now(),
  186. UpdateTime: time.Now(),
  187. Sjscsj: time.Now(),
  188. Xgbz: strconv.FormatInt(0, 10),
  189. }
  190. if patient.FirstDialysisDate != 0 {
  191. p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
  192. }
  193. if patient.HospitalFirstDialysisDate != 0 {
  194. p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
  195. }
  196. hdPatients = append(hdPatients, p)
  197. }
  198. for _, item := range hdPatients {
  199. service.XTWriteDB().Model(&sz.TempHdPatient{}).Create(item)
  200. }
  201. upload := &sz.DataUpload{
  202. ModuleType: 4,
  203. OrgId: config.OrgId,
  204. UploadDate: time.Now().Unix(),
  205. UploadStatus: 1,
  206. UploadType: 1,
  207. }
  208. err := service.CreateUploadRecord(upload)
  209. if err != nil {
  210. utils.ErrorLog("%v", err)
  211. }
  212. }
  213. } else if err_four == nil {
  214. if GetDiffDay2(config, record) <= 0 {
  215. var hdPatients []*sz.TempHdPatient
  216. patients, _ := service.FindOrgPatientData(record.OrgId, record.UploadDate, time.Now().Unix())
  217. for _, patient := range patients {
  218. idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
  219. idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2)) // 月
  220. idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
  221. date := strconv.Itoa(idcard_year) + "-" + strconv.Itoa(idcard_mo) + "-" + strconv.Itoa(idcard_day)
  222. local, _ := time.LoadLocation("Local")
  223. birthday, _ := time.ParseInLocation("2006-01-02", date, local)
  224. var isCKD int
  225. value := strings.Index(patient.Diagnose, "慢性肾脏病")
  226. value2 := strings.Index(patient.Diagnose, "CKD")
  227. value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
  228. if value != -1 || value2 != -1 || value3 != -1 {
  229. isCKD = 1
  230. } else {
  231. isCKD = 0
  232. }
  233. p := &sz.TempHdPatient{
  234. HospitalId: strconv.FormatInt(patient.UserOrgId, 10),
  235. PatientNk: strconv.FormatInt(patient.ID, 10),
  236. CardNo: "000000000000000000",
  237. CardType: "01",
  238. IdNo: patient.IdCardNo,
  239. IdType: "01",
  240. PatientName: patient.Name,
  241. Gender: strconv.FormatInt(patient.Gender, 10),
  242. BornDate: birthday,
  243. DiagnosisSummary: patient.Diagnose,
  244. IsCrf: strconv.Itoa(isCKD),
  245. CreatedTime: time.Now(),
  246. UpdateTime: time.Now(),
  247. Sjscsj: time.Now(),
  248. Xgbz: strconv.FormatInt(0, 10),
  249. }
  250. if patient.FirstDialysisDate != 0 {
  251. p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
  252. }
  253. if patient.HospitalFirstDialysisDate != 0 {
  254. p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
  255. }
  256. hdPatients = append(hdPatients, p)
  257. }
  258. for _, item := range hdPatients {
  259. service.XTReadDB().Model(&sz.TempHdPatient{}).Create(item)
  260. }
  261. upload := &sz.DataUpload{
  262. ModuleType: 4,
  263. OrgId: record.OrgId,
  264. UploadDate: time.Now().Unix(),
  265. UploadStatus: 1,
  266. UploadType: 1,
  267. }
  268. err := service.CreateUploadRecord(upload)
  269. if err != nil {
  270. utils.ErrorLog("%v", err)
  271. }
  272. }
  273. }
  274. //record, err_five := service.FindDataUploadOrgInfo(config.OrgId, 5)
  275. //if err_five == gorm.ErrRecordNotFound {
  276. // if GetDiffDay(config) <= 0 {
  277. //
  278. // var hdPatientOuts []*sz.TempHdPatientOut
  279. // patients, _ := service.FindOrgPatientOutData(config.OrgId, 0, 0)
  280. //
  281. // for _, patient := range patients {
  282. //
  283. // p := &sz.TempHdPatientOut{
  284. // Sn: strconv.FormatInt(patient.ID, 10),
  285. // HospitalId: strconv.FormatInt(patient.UserOrgId, 10),
  286. // PatientNk: strconv.FormatInt(patient.ID, 10),
  287. // SequelaeType: "99",
  288. // ExtReason: "98",
  289. // CreateTime: time.Now(),
  290. // Sjscsj: time.Now(),
  291. // Xgbz: 0,
  292. // }
  293. //
  294. // if len(patient.PatientLapseto) > 0{
  295. // p.SequelaeDate = time.Unix(patient.PatientLapseto[len(patient.PatientLapseto)].LapsetoTime, 0)
  296. // }
  297. //
  298. // hdPatientOuts = append(hdPatientOuts, p)
  299. // }
  300. //
  301. // for _, item := range hdPatientOuts {
  302. // service.XTWriteDB().Model(&sz.TempHdPatientOut{}).Create(item)
  303. // }
  304. //
  305. // upload := &sz.DataUpload{
  306. // ModuleType: 5,
  307. // OrgId: config.OrgId,
  308. // UploadDate: time.Now().Unix(),
  309. // UploadStatus: 1,
  310. // UploadType: 1,
  311. // }
  312. // err := service.CreateUploadRecord(upload)
  313. // if err != nil{
  314. // utils.ErrorLog("%v",err)
  315. // }
  316. // }
  317. //
  318. //} else if err_five == nil {
  319. // if GetDiffDay2(config,record) <= 0 {
  320. //
  321. // var hdPatientOuts []*sz.TempHdPatientOut
  322. // patients, _ := service.FindOrgPatientOutData(record.OrgId, record.UploadDate, time.Now().Unix())
  323. //
  324. // for _, patient := range patients {
  325. //
  326. // p := &sz.TempHdPatientOut{
  327. // Sn: strconv.FormatInt(patient.ID, 10),
  328. // HospitalId: strconv.FormatInt(patient.UserOrgId, 10),
  329. // PatientNk: strconv.FormatInt(patient.ID, 10),
  330. // SequelaeDate: time.Unix(patient.PatientLapseto[len(patient.PatientLapseto)].LapsetoTime, 0),
  331. // SequelaeType: "99",
  332. // ExtReason: "98",
  333. // CreateTime: time.Now(),
  334. // Sjscsj: time.Now(),
  335. // Xgbz: 0,
  336. // }
  337. //
  338. // hdPatientOuts = append(hdPatientOuts, p)
  339. // }
  340. //
  341. // for _, item := range hdPatientOuts {
  342. // service.XTWriteDB().Model(&sz.TempHdPatientOut{}).Create(item)
  343. // }
  344. //
  345. // upload := &sz.DataUpload{
  346. // ModuleType: 5,
  347. // OrgId: record.OrgId,
  348. // UploadDate: time.Now().Unix(),
  349. // UploadStatus: 1,
  350. // UploadType: 1,
  351. // }
  352. // err := service.CreateUploadRecord(upload)
  353. // if err != nil{
  354. // utils.ErrorLog("%v",err)
  355. // }
  356. // }
  357. //
  358. //}
  359. record, err_six := service.FindDataUploadOrgInfo(config.OrgId, 6)
  360. if err_six == gorm.ErrRecordNotFound {
  361. if GetDiffDay(config) <= 0 {
  362. var hdPrescription []*sz.TempHdPs
  363. prescriptions, _ := service.FindOrgDialysisPrescriptionData(config.OrgId, 0, 0)
  364. for _, item := range prescriptions {
  365. ps := &sz.TempHdPs{
  366. PrescribeId: strconv.FormatInt(item.ID, 10),
  367. HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  368. PatientNk: strconv.FormatInt(item.PatientId, 10),
  369. K: item.Kalium,
  370. Ca: item.Calcium,
  371. Na: item.Sodium,
  372. CreateTime: time.Now(),
  373. Sjscsj: time.Now(),
  374. Xgbz: 0,
  375. PrescribeTime: time.Unix(item.RecordDate, 0),
  376. }
  377. switch item.ModeId {
  378. case 1:
  379. ps.DialysisFrequency = item.AssessmentBeforeDislysis.DialysisCount
  380. ps.FrequencyUnit = 1
  381. ps.DialysisDuration = item.DialysisDuration
  382. ps.Hdf = "0"
  383. ps.Hp = "0"
  384. break
  385. case 2:
  386. ps.Hdf = "1"
  387. ps.Hp = "0"
  388. ps.HdfFrequency = item.AssessmentBeforeDislysis.DialysisCount
  389. ps.HdfFrequencyUnit = 1
  390. ps.HpDuration = item.DialysisDuration
  391. break
  392. case 4:
  393. ps.Hdf = "0"
  394. ps.Hp = "1"
  395. ps.HpFrequency = item.AssessmentBeforeDislysis.DialysisCount
  396. ps.HpFrequencyUnit = 1
  397. ps.HpDuration = item.DialysisDuration
  398. break
  399. }
  400. hdPrescription = append(hdPrescription, ps)
  401. }
  402. for _, item := range hdPrescription {
  403. service.XTWriteDB().Model(&sz.TempHdPs{}).Create(item)
  404. }
  405. upload := &sz.DataUpload{
  406. ModuleType: 6,
  407. OrgId: config.OrgId,
  408. UploadDate: time.Now().Unix(),
  409. UploadStatus: 1,
  410. UploadType: 1,
  411. }
  412. err := service.CreateUploadRecord(upload)
  413. if err != nil {
  414. utils.ErrorLog("%v", err)
  415. }
  416. }
  417. } else if err_six == nil {
  418. if GetDiffDay2(config, record) <= 0 {
  419. var hdPrescription []*sz.TempHdPs
  420. prescriptions, _ := service.FindOrgDialysisPrescriptionData(record.OrgId, record.UploadDate, time.Now().Unix())
  421. for _, item := range prescriptions {
  422. ps := &sz.TempHdPs{
  423. PrescribeId: strconv.FormatInt(item.ID, 10),
  424. HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  425. PatientNk: strconv.FormatInt(item.PatientId, 10),
  426. K: item.Kalium,
  427. Ca: item.Calcium,
  428. Na: item.Sodium,
  429. CreateTime: time.Now(),
  430. Sjscsj: time.Now(),
  431. Xgbz: 0,
  432. PrescribeTime: time.Unix(item.RecordDate, 0),
  433. }
  434. switch item.ModeId {
  435. case 1:
  436. ps.DialysisFrequency = item.AssessmentBeforeDislysis.DialysisCount
  437. ps.FrequencyUnit = 1
  438. ps.DialysisDuration = item.DialysisDuration
  439. ps.Hdf = "0"
  440. ps.Hp = "0"
  441. break
  442. case 2:
  443. ps.Hdf = "1"
  444. ps.Hp = "0"
  445. ps.HdfFrequency = item.AssessmentBeforeDislysis.DialysisCount
  446. ps.HdfFrequencyUnit = 1
  447. ps.HpDuration = item.DialysisDuration
  448. break
  449. case 4:
  450. ps.Hdf = "0"
  451. ps.Hp = "1"
  452. ps.HpFrequency = item.AssessmentBeforeDislysis.DialysisCount
  453. ps.HpFrequencyUnit = 1
  454. ps.HpDuration = item.DialysisDuration
  455. break
  456. }
  457. hdPrescription = append(hdPrescription, ps)
  458. }
  459. for _, item := range hdPrescription {
  460. service.XTWriteDB().Model(&sz.TempHdPs{}).Create(item)
  461. }
  462. upload := &sz.DataUpload{
  463. ModuleType: 6,
  464. OrgId: record.OrgId,
  465. UploadDate: time.Now().Unix(),
  466. UploadStatus: 1,
  467. UploadType: 1,
  468. }
  469. err := service.CreateUploadRecord(upload)
  470. if err != nil {
  471. utils.ErrorLog("%v", err)
  472. }
  473. }
  474. }
  475. record, err_seven := service.FindDataUploadOrgInfo(config.OrgId, 7)
  476. if err_seven == gorm.ErrRecordNotFound {
  477. if GetDiffDay(config) <= 0 {
  478. var hdPsMedicine []*sz.TempHdPsMedicine
  479. prescriptions, _ := service.FindOrgDialysisPrescriptionData(config.OrgId, 0, 0)
  480. for _, item := range prescriptions {
  481. psm := &sz.TempHdPsMedicine{
  482. Sn: strconv.FormatInt(item.ID, 10),
  483. PrescribeId: strconv.FormatInt(item.ID, 10),
  484. HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  485. MedicineTypeId: "2",
  486. CreatedTime: time.Now(),
  487. Sjscsj: time.Now(),
  488. Xgbz: 0,
  489. }
  490. switch item.Anticoagulant {
  491. case 1:
  492. psm.MedicineId = "3"
  493. break
  494. case 2:
  495. psm.MedicineId = "1"
  496. break
  497. case 3:
  498. psm.MedicineId = "2"
  499. break
  500. case 4:
  501. psm.MedicineId = "5"
  502. break
  503. case 5:
  504. psm.MedicineId = "4"
  505. break
  506. }
  507. hdPsMedicine = append(hdPsMedicine, psm)
  508. }
  509. for _, item := range hdPsMedicine {
  510. service.XTWriteDB().Model(&sz.TempHdPsMedicine{}).Create(item)
  511. }
  512. upload := &sz.DataUpload{
  513. ModuleType: 7,
  514. OrgId: config.OrgId,
  515. UploadDate: time.Now().Unix(),
  516. UploadStatus: 1,
  517. UploadType: 1,
  518. }
  519. err := service.CreateUploadRecord(upload)
  520. if err != nil {
  521. utils.ErrorLog("%v", err)
  522. }
  523. }
  524. } else if err_seven == nil {
  525. if GetDiffDay2(config, record) <= 0 {
  526. var hdPsMedicine []*sz.TempHdPsMedicine
  527. prescriptions, _ := service.FindOrgDialysisPrescriptionData(record.OrgId, record.UploadDate, time.Now().Unix())
  528. for _, item := range prescriptions {
  529. psm := &sz.TempHdPsMedicine{
  530. Sn: strconv.FormatInt(item.ID, 10),
  531. PrescribeId: strconv.FormatInt(item.ID, 10),
  532. HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  533. MedicineTypeId: "2",
  534. CreatedTime: time.Now(),
  535. Sjscsj: time.Now(),
  536. Xgbz: 0,
  537. }
  538. switch item.Anticoagulant {
  539. case 1:
  540. psm.MedicineId = "3"
  541. break
  542. case 2:
  543. psm.MedicineId = "1"
  544. break
  545. case 3:
  546. psm.MedicineId = "2"
  547. break
  548. case 4:
  549. psm.MedicineId = "5"
  550. break
  551. case 5:
  552. psm.MedicineId = "4"
  553. break
  554. }
  555. hdPsMedicine = append(hdPsMedicine, psm)
  556. }
  557. for _, item := range hdPsMedicine {
  558. service.XTWriteDB().Model(&sz.TempHdPsMedicine{}).Create(item)
  559. }
  560. upload := &sz.DataUpload{
  561. ModuleType: 7,
  562. OrgId: config.OrgId,
  563. UploadDate: time.Now().Unix(),
  564. UploadStatus: 1,
  565. UploadType: 1,
  566. }
  567. err := service.CreateUploadRecord(upload)
  568. if err != nil {
  569. utils.ErrorLog("%v", err)
  570. }
  571. }
  572. }
  573. //
  574. // //排班
  575. record, err_eight := service.FindDataUploadOrgInfo(config.OrgId, 8)
  576. if err_eight == gorm.ErrRecordNotFound {
  577. if GetDiffDay(config) <= 0 {
  578. var hdShift []*sz.TempHdShift
  579. schs, _ := service.FindOrgScheduleData(config.OrgId, 0, 0)
  580. for _, sch := range schs {
  581. shift := &sz.TempHdShift{
  582. PsId: strconv.FormatInt(sch.ID, 10),
  583. HospitalId: strconv.FormatInt(sch.UserOrgId, 10),
  584. PatientNk: strconv.FormatInt(sch.PatientId, 10),
  585. ScheduleDate: time.Unix(sch.ScheduleDate, 0),
  586. ShiftType: strconv.FormatInt(sch.ScheduleType, 10),
  587. SickbedNo: sch.DeviceNumber.Number,
  588. ScheduleStatus: "1",
  589. CreateTime: time.Now(),
  590. Sjscsj: time.Now(),
  591. Xgbz: 0,
  592. }
  593. hdShift = append(hdShift, shift)
  594. }
  595. for _, item := range hdShift {
  596. service.XTWriteDB().Model(&sz.TempHdShift{}).Create(item)
  597. }
  598. upload := &sz.DataUpload{
  599. ModuleType: 8,
  600. OrgId: config.OrgId,
  601. UploadDate: time.Now().Unix(),
  602. UploadStatus: 1,
  603. UploadType: 1,
  604. }
  605. err := service.CreateUploadRecord(upload)
  606. if err != nil {
  607. utils.ErrorLog("%v", err)
  608. }
  609. }
  610. } else if err_eight == nil {
  611. if GetDiffDay2(config, record) <= 0 {
  612. var hdShift []*sz.TempHdShift
  613. schs, _ := service.FindOrgScheduleData(record.OrgId, record.UploadDate, time.Now().Unix())
  614. for _, sch := range schs {
  615. shift := &sz.TempHdShift{
  616. PsId: strconv.FormatInt(sch.ID, 10),
  617. HospitalId: strconv.FormatInt(sch.UserOrgId, 10),
  618. PatientNk: strconv.FormatInt(sch.PatientId, 10),
  619. ScheduleDate: time.Unix(sch.ScheduleDate, 0),
  620. ShiftType: strconv.FormatInt(sch.ScheduleType, 10),
  621. SickbedNo: sch.DeviceNumber.Number,
  622. ScheduleStatus: "1",
  623. CreateTime: time.Now(),
  624. Sjscsj: time.Now(),
  625. Xgbz: 0,
  626. }
  627. hdShift = append(hdShift, shift)
  628. }
  629. for _, item := range hdShift {
  630. service.XTWriteDB().Model(&sz.TempHdShift{}).Create(item)
  631. }
  632. upload := &sz.DataUpload{
  633. ModuleType: 8,
  634. OrgId: config.OrgId,
  635. UploadDate: time.Now().Unix(),
  636. UploadStatus: 1,
  637. UploadType: 1,
  638. }
  639. err := service.CreateUploadRecord(upload)
  640. if err != nil {
  641. utils.ErrorLog("%v", err)
  642. }
  643. }
  644. }
  645. //
  646. record, err_nine := service.FindDataUploadOrgInfo(config.OrgId, 9)
  647. if err_nine == gorm.ErrRecordNotFound {
  648. if GetDiffDay(config) <= 0 {
  649. var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
  650. dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(config.OrgId, 0, 0)
  651. for _, dp := range dialysisPrescriptions {
  652. advice := &sz.TempHdDoctorsAdvice{
  653. MedicalOrDerId: strconv.FormatInt(dp.ID, 10),
  654. HospitalId: strconv.FormatInt(dp.UserOrgId, 10),
  655. DialysisId: strconv.FormatInt(dp.DialysisOrder.ID, 10),
  656. OrderType: "1",
  657. PatientNk: strconv.FormatInt(dp.PatientId, 10),
  658. DialysisDuration: dp.DialysisDurationHour*60 + dp.DialysisDurationMinute,
  659. BloodVol: int64(math.Floor(dp.BloodFlowVolume + 0/5)),
  660. CreateTime: time.Now(),
  661. Sjscsj: time.Now(),
  662. Xgbz: 0,
  663. }
  664. hdDoctorAdvices = append(hdDoctorAdvices, advice)
  665. }
  666. for _, item := range hdDoctorAdvices {
  667. service.XTWriteDB().Model(&sz.TempHdDoctorsAdvice{}).Create(item)
  668. }
  669. upload := &sz.DataUpload{
  670. ModuleType: 9,
  671. OrgId: config.OrgId,
  672. UploadDate: time.Now().Unix(),
  673. UploadStatus: 1,
  674. UploadType: 1,
  675. }
  676. err := service.CreateUploadRecord(upload)
  677. if err != nil {
  678. utils.ErrorLog("%v", err)
  679. }
  680. }
  681. } else if err_nine == nil {
  682. if GetDiffDay2(config, record) <= 0 {
  683. var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
  684. dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(record.OrgId, record.UploadDate, time.Now().Unix())
  685. for _, dp := range dialysisPrescriptions {
  686. advice := &sz.TempHdDoctorsAdvice{
  687. MedicalOrDerId: strconv.FormatInt(dp.ID, 10),
  688. HospitalId: strconv.FormatInt(dp.UserOrgId, 10),
  689. DialysisId: strconv.FormatInt(dp.DialysisOrder.ID, 10),
  690. OrderType: "1",
  691. PatientNk: strconv.FormatInt(dp.PatientId, 10),
  692. DialysisDuration: dp.DialysisDurationHour*60 + dp.DialysisDurationMinute,
  693. BloodVol: int64(math.Floor(dp.BloodFlowVolume + 0/5)),
  694. CreateTime: time.Now(),
  695. Sjscsj: time.Now(),
  696. Xgbz: 0,
  697. }
  698. hdDoctorAdvices = append(hdDoctorAdvices, advice)
  699. }
  700. for _, item := range hdDoctorAdvices {
  701. service.XTWriteDB().Model(&sz.TempHdDoctorsAdvice{}).Create(item)
  702. }
  703. upload := &sz.DataUpload{
  704. ModuleType: 9,
  705. OrgId: config.OrgId,
  706. UploadDate: time.Now().Unix(),
  707. UploadStatus: 1,
  708. UploadType: 1,
  709. }
  710. err := service.CreateUploadRecord(upload)
  711. if err != nil {
  712. utils.ErrorLog("%v", err)
  713. }
  714. }
  715. }
  716. //
  717. record, err_ten := service.FindDataUploadOrgInfo(config.OrgId, 10)
  718. fmt.Println(err_ten)
  719. fmt.Println(record)
  720. if err_ten == gorm.ErrRecordNotFound {
  721. if GetDiffDay(config) <= 0 {
  722. var hdDialysis []*sz.TempHdDialysis
  723. schs, erra := service.FindOrgDialysisData(config.OrgId, 0, 0)
  724. fmt.Println(schs)
  725. fmt.Println(erra)
  726. for _, sch := range schs {
  727. dialysis := &sz.TempHdDialysis{
  728. PsId: strconv.FormatInt(sch.ID, 10),
  729. HospitalId: strconv.FormatInt(sch.UserOrgId, 10),
  730. SickbedNo: sch.DeviceNumber.Number,
  731. DivisionId: strconv.FormatInt(sch.DeviceNumber.ZoneId, 10),
  732. Ufv: int64(math.Floor(sch.VMDialysisPrescription.Ultrafiltration + 0/5)),
  733. TotalReplace: int64(math.Floor(sch.VMDialysisPrescription.ReplacementTotal + 0/5)),
  734. BeforeWeight: sch.AssessmentBeforeDislysis.WeighingBefore,
  735. PatientNk: strconv.FormatInt(sch.PatientId, 10),
  736. CreateTime: time.Now(),
  737. Sjscsj: time.Now(),
  738. Xgbz: 0,
  739. }
  740. if sch.DialysisOrder.ID > 0 {
  741. dialysis.DialysisId = strconv.FormatInt(sch.DialysisOrder.ID, 10)
  742. dialysis.DialysisDate = time.Unix(sch.DialysisOrder.DialysisDate, 0)
  743. if sch.DialysisOrder.StartTime > 0 {
  744. dialysis.StartTime = time.Unix(sch.DialysisOrder.StartTime, 0)
  745. }
  746. if sch.DialysisOrder.EndTime > 0 {
  747. dialysis.EndTime = time.Unix(sch.DialysisOrder.EndTime, 0)
  748. }
  749. }
  750. if len(sch.MonitoringRecord) > 0 {
  751. dialysis.BeforeDbp = int64(math.Floor(sch.MonitoringRecord[0].DiastolicBloodPressure + 0/5))
  752. dialysis.BeforeSbp = int64(math.Floor(sch.MonitoringRecord[0].SystolicBloodPressure + 0/5))
  753. dialysis.AfterDbp = int64(math.Floor(sch.MonitoringRecord[len(sch.MonitoringRecord)-1].DiastolicBloodPressure + 0/5))
  754. dialysis.AfterSbp = int64(math.Floor(sch.MonitoringRecord[len(sch.MonitoringRecord)-1].SystolicBloodPressure + 0/5))
  755. }
  756. hdDialysis = append(hdDialysis, dialysis)
  757. }
  758. for _, item := range hdDialysis {
  759. service.XTWriteDB().Model(&sz.TempHdDialysis{}).Create(item)
  760. }
  761. upload := &sz.DataUpload{
  762. ModuleType: 10,
  763. OrgId: config.OrgId,
  764. UploadDate: time.Now().Unix(),
  765. UploadStatus: 1,
  766. UploadType: 1,
  767. }
  768. err := service.CreateUploadRecord(upload)
  769. if err != nil {
  770. utils.ErrorLog("%v", err)
  771. }
  772. }
  773. } else if err_ten == nil {
  774. if GetDiffDay2(config, record) <= 0 {
  775. var hdDialysis []*sz.TempHdDialysis
  776. schs, _ := service.FindOrgDialysisData(record.OrgId, record.UploadDate, time.Now().Unix())
  777. for _, sch := range schs {
  778. dialysis := &sz.TempHdDialysis{
  779. PsId: strconv.FormatInt(sch.ID, 10),
  780. HospitalId: strconv.FormatInt(sch.UserOrgId, 10),
  781. DialysisId: strconv.FormatInt(sch.DialysisOrder.ID, 10),
  782. DialysisDate: time.Unix(sch.DialysisOrder.DialysisDate, 0),
  783. SickbedNo: sch.DeviceNumber.Number,
  784. DivisionId: strconv.FormatInt(sch.DeviceNumber.ZoneId, 10),
  785. Ufv: int64(math.Floor(sch.VMDialysisPrescription.Ultrafiltration + 0/5)),
  786. TotalReplace: int64(math.Floor(sch.VMDialysisPrescription.ReplacementTotal + 0/5)),
  787. BeforeDbp: int64(math.Floor(sch.MonitoringRecord[0].DiastolicBloodPressure + 0/5)),
  788. BeforeSbp: int64(math.Floor(sch.MonitoringRecord[0].SystolicBloodPressure + 0/5)),
  789. AfterDbp: int64(math.Floor(sch.MonitoringRecord[len(sch.MonitoringRecord)].DiastolicBloodPressure + 0/5)),
  790. AfterSbp: int64(math.Floor(sch.MonitoringRecord[len(sch.MonitoringRecord)].SystolicBloodPressure + 0/5)),
  791. BeforeWeight: sch.AssessmentBeforeDislysis.WeighingBefore,
  792. StartTime: time.Unix(sch.DialysisOrder.StartTime, 0),
  793. EndTime: time.Unix(sch.DialysisOrder.EndTime, 0),
  794. PatientNk: strconv.FormatInt(sch.PatientId, 10),
  795. CreateTime: time.Now(),
  796. Sjscsj: time.Now(),
  797. Xgbz: 0,
  798. }
  799. hdDialysis = append(hdDialysis, dialysis)
  800. }
  801. for _, item := range hdDialysis {
  802. service.XTWriteDB().Model(&sz.TempHdDialysis{}).Create(item)
  803. }
  804. upload := &sz.DataUpload{
  805. ModuleType: 10,
  806. OrgId: config.OrgId,
  807. UploadDate: time.Now().Unix(),
  808. UploadStatus: 1,
  809. UploadType: 1,
  810. }
  811. err := service.CreateUploadRecord(upload)
  812. if err != nil {
  813. utils.ErrorLog("%v", err)
  814. }
  815. }
  816. }
  817. //
  818. record, err_eleven := service.FindDataUploadOrgInfo(config.OrgId, 11)
  819. if err_eleven == gorm.ErrRecordNotFound {
  820. if GetDiffDay(config) <= 0 {
  821. var hdMiddle []*sz.TempHdMiddle
  822. monitors, _ := service.FindOrgMonitorRecordData(config.OrgId, 0, 0)
  823. for _, item := range monitors {
  824. mid := &sz.TempHdMiddle{
  825. HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  826. DialysisId: strconv.FormatInt(item.DialysisOrder.ID, 10),
  827. MonitorTime: time.Unix(item.OperateTime, 0),
  828. Sbp: int64(math.Floor(item.SystolicBloodPressure + 0/5)),
  829. Dbp: int64(math.Floor(item.DiastolicBloodPressure + 0/5)),
  830. PatientNk: strconv.FormatInt(item.PatientId, 10),
  831. CreateTime: time.Now(),
  832. Sjscsj: time.Now(),
  833. Xgbz: 0,
  834. }
  835. hdMiddle = append(hdMiddle, mid)
  836. }
  837. for _, item := range hdMiddle {
  838. service.XTWriteDB().Model(&sz.TempHdMiddle{}).Create(item)
  839. }
  840. upload := &sz.DataUpload{
  841. ModuleType: 11,
  842. OrgId: config.OrgId,
  843. UploadDate: time.Now().Unix(),
  844. UploadStatus: 1,
  845. UploadType: 1,
  846. }
  847. err := service.CreateUploadRecord(upload)
  848. if err != nil {
  849. utils.ErrorLog("%v", err)
  850. }
  851. }
  852. } else if err == nil {
  853. if GetDiffDay2(config, record) <= 0 {
  854. var hdMiddle []*sz.TempHdMiddle
  855. monitors, _ := service.FindOrgMonitorRecordData(record.OrgId, record.UploadDate, time.Now().Unix())
  856. for _, item := range monitors {
  857. mid := &sz.TempHdMiddle{
  858. HospitalId: strconv.FormatInt(item.UserOrgId, 10),
  859. DialysisId: strconv.FormatInt(item.DialysisOrder.ID, 10),
  860. MonitorTime: time.Unix(item.OperateTime, 0),
  861. Sbp: int64(math.Floor(item.SystolicBloodPressure + 0/5)),
  862. Dbp: int64(math.Floor(item.DiastolicBloodPressure + 0/5)),
  863. PatientNk: strconv.FormatInt(item.PatientId, 10),
  864. CreateTime: time.Now(),
  865. Sjscsj: time.Now(),
  866. Xgbz: 0,
  867. }
  868. hdMiddle = append(hdMiddle, mid)
  869. }
  870. for _, item := range hdMiddle {
  871. service.XTWriteDB().Model(&sz.TempHdMiddle{}).Create(item)
  872. }
  873. upload := &sz.DataUpload{
  874. ModuleType: 11,
  875. OrgId: config.OrgId,
  876. UploadDate: time.Now().Unix(),
  877. UploadStatus: 1,
  878. UploadType: 1,
  879. }
  880. err := service.CreateUploadRecord(upload)
  881. if err != nil {
  882. utils.ErrorLog("%v", err)
  883. }
  884. }
  885. }
  886. //
  887. record, err_twelve := service.FindDataUploadOrgInfo(config.OrgId, 12)
  888. if err_twelve == gorm.ErrRecordNotFound {
  889. if GetDiffDay(config) <= 0 {
  890. var divisions []*sz.TempHdDivision
  891. zones, _ := service.FindOrgDeviceZoneRecordData(config.OrgId, 0, 0)
  892. for _, item := range zones {
  893. nowTime := time.Now()
  894. div := &sz.TempHdDivision{
  895. DivisionId: strconv.FormatInt(item.ID, 10),
  896. HospitalId: strconv.FormatInt(item.OrgId, 10),
  897. DevisionName: item.Name,
  898. CreateTime: nowTime,
  899. UpdateTime: nowTime,
  900. UpdateFlag: strconv.FormatInt(0, 10),
  901. Sjscsj: time.Now(),
  902. Xgbz: 0,
  903. }
  904. divisions = append(divisions, div)
  905. }
  906. for _, item := range divisions {
  907. service.XTWriteDB().Model(&sz.TempHdDivision{}).Create(item)
  908. }
  909. upload := &sz.DataUpload{
  910. ModuleType: 12,
  911. OrgId: config.OrgId,
  912. UploadDate: time.Now().Unix(),
  913. UploadStatus: 1,
  914. UploadType: 1,
  915. }
  916. err := service.CreateUploadRecord(upload)
  917. if err != nil {
  918. utils.ErrorLog("%v", err)
  919. }
  920. }
  921. } else if err_twelve == nil {
  922. if GetDiffDay2(config, record) <= 0 {
  923. var divisions []*sz.TempHdDivision
  924. zones, _ := service.FindOrgDeviceZoneRecordData(record.OrgId, record.UploadDate, time.Now().Unix())
  925. for _, item := range zones {
  926. nowTime := time.Now()
  927. div := &sz.TempHdDivision{
  928. DivisionId: strconv.FormatInt(item.ID, 10),
  929. HospitalId: strconv.FormatInt(item.OrgId, 10),
  930. DevisionName: item.Name,
  931. CreateTime: nowTime,
  932. UpdateTime: nowTime,
  933. UpdateFlag: strconv.FormatInt(0, 10),
  934. Sjscsj: time.Now(),
  935. Xgbz: 0,
  936. }
  937. divisions = append(divisions, div)
  938. }
  939. for _, item := range divisions {
  940. service.XTWriteDB().Model(&sz.TempHdDivision{}).Create(item)
  941. }
  942. upload := &sz.DataUpload{
  943. ModuleType: 12,
  944. OrgId: config.OrgId,
  945. UploadDate: time.Now().Unix(),
  946. UploadStatus: 1,
  947. UploadType: 1,
  948. }
  949. err := service.CreateUploadRecord(upload)
  950. if err != nil {
  951. utils.ErrorLog("%v", err)
  952. }
  953. }
  954. }
  955. //
  956. }
  957. }
  958. func Substr(str string, start, length int) string {
  959. rs := []rune(str)
  960. rl := len(rs)
  961. end := 0
  962. if start < 0 {
  963. start = rl - 1 + start
  964. }
  965. end = start + length
  966. if start > end {
  967. start, end = end, start
  968. }
  969. if start < 0 {
  970. start = 0
  971. }
  972. if start > rl {
  973. start = rl
  974. }
  975. if end < 0 {
  976. end = 0
  977. }
  978. if end > rl {
  979. end = rl
  980. }
  981. return string(rs[start:end])
  982. }
  983. //没有上报数据记录的时候,使用配置创建时间来计算上报时间
  984. func GetDiffDay(config *sz.DataUploadConfig) float64 {
  985. var diffDay float64
  986. switch config.TimeQuantum {
  987. case 1:
  988. tm := time.Unix(config.CreateTime, 0)
  989. dateStr := tm.Format("2006-1-2") + " 00:00:00"
  990. date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  991. year, month, day := date.Date()
  992. endTime := time.Date(year, month, day+7, 0, 0, 0, 0, time.Local)
  993. years, months, days := time.Now().Date()
  994. todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  995. diffDay = endTime.Sub(todayTime).Hours() / 24
  996. break
  997. case 2:
  998. tm := time.Unix(config.CreateTime, 0)
  999. dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1000. date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1001. year, month, day := date.Date()
  1002. endTime := time.Date(year, month, day+14, 0, 0, 0, 0, time.Local)
  1003. years, months, days := time.Now().Date()
  1004. todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1005. diffDay = endTime.Sub(todayTime).Hours() / 24
  1006. break
  1007. case 3:
  1008. tm := time.Unix(config.CreateTime, 0)
  1009. dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1010. date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1011. year, month, day := date.Date()
  1012. endTime := time.Date(year, month+1, day, 0, 0, 0, 0, time.Local)
  1013. years, months, days := time.Now().Date()
  1014. todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1015. diffDay = endTime.Sub(todayTime).Hours() / 24
  1016. break
  1017. case 4:
  1018. tm := time.Unix(config.CreateTime, 0)
  1019. dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1020. date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1021. year, month, day := date.Date()
  1022. endTime := time.Date(year, month+3, day, 0, 0, 0, 0, time.Local)
  1023. years, months, days := time.Now().Date()
  1024. todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1025. diffDay = endTime.Sub(todayTime).Hours() / 24
  1026. break
  1027. }
  1028. return diffDay
  1029. }
  1030. //有上报数据记录的时候,使用上报时间来计算下次上报时间
  1031. func GetDiffDay2(config *sz.DataUploadConfig, updateDate sz.DataUpload) float64 {
  1032. var diffDay float64
  1033. switch config.TimeQuantum {
  1034. case 1:
  1035. tm := time.Unix(updateDate.UploadDate, 0)
  1036. dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1037. date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1038. year, month, day := date.Date()
  1039. endTime := time.Date(year, month, day+7, 0, 0, 0, 0, time.Local)
  1040. years, months, days := time.Now().Date()
  1041. todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1042. diffDay = endTime.Sub(todayTime).Hours() / 24 //透析日期1年与当前天数差
  1043. break
  1044. case 2:
  1045. tm := time.Unix(updateDate.UploadDate, 0)
  1046. dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1047. date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1048. year, month, day := date.Date()
  1049. endTime := time.Date(year, month, day+14, 0, 0, 0, 0, time.Local)
  1050. years, months, days := time.Now().Date()
  1051. todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1052. diffDay = endTime.Sub(todayTime).Hours() / 24 //透析日期1年与当前天数差
  1053. break
  1054. case 3:
  1055. tm := time.Unix(updateDate.UploadDate, 0)
  1056. dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1057. date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1058. year, month, day := date.Date()
  1059. endTime := time.Date(year, month+1, day, 0, 0, 0, 0, time.Local)
  1060. years, months, days := time.Now().Date()
  1061. todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1062. diffDay = endTime.Sub(todayTime).Hours() / 24 //透析日期1年与当前天数差
  1063. break
  1064. case 4:
  1065. tm := time.Unix(updateDate.UploadDate, 0)
  1066. dateStr := tm.Format("2006-1-2") + " 00:00:00"
  1067. date, _ := time.Parse("2006-1-2 15:04:05", dateStr)
  1068. year, month, day := date.Date()
  1069. endTime := time.Date(year, month+3, day, 0, 0, 0, 0, time.Local)
  1070. years, months, days := time.Now().Date()
  1071. todayTime := time.Date(years, months, days, 0, 0, 0, 0, time.Local)
  1072. diffDay = endTime.Sub(todayTime).Hours() / 24 //透析日期1年与当前天数差
  1073. break
  1074. }
  1075. return diffDay
  1076. }