manage_service.go 86KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973
  1. package service
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. "XT_New/models"
  7. "github.com/jinzhu/gorm"
  8. )
  9. func GetEquitmentName(unit_type string, orgid int64) (*models.DeviceEquimentname, error) {
  10. var equimentname models.DeviceEquimentname
  11. var err error
  12. err = UserReadDB().Model(&equimentname).Where("equitment_name = ? and user_org_id = ? and status = 1", unit_type, orgid).Find(&equimentname).Error
  13. if err == gorm.ErrRecordNotFound {
  14. return nil, err
  15. }
  16. if err != nil {
  17. return nil, err
  18. }
  19. return &equimentname, nil
  20. }
  21. func CreateEquimentName(equimentname models.DeviceEquimentname) error {
  22. //err := XTWriteDB().Create(&equimentname).Error
  23. //return err
  24. err := writeUserDb.Create(&equimentname).Error
  25. return err
  26. }
  27. func GetEquitmentByBedID(bedid int64, orgid int64) (models.DeviceAddmacher, error) {
  28. addmacher := models.DeviceAddmacher{}
  29. err := UserReadDB().Model(&addmacher).Where("bed_id = ? and user_org_id = ? and status = 1", bedid, orgid).First(&addmacher).Error
  30. return addmacher, err
  31. }
  32. func CreateMacher(machers *models.DeviceAddmacher) error {
  33. //err := writeDb.Create(&machers).Error
  34. //xt := writeDb.Begin()
  35. // //fmt.Println("hhhhhhhh",xt)
  36. // //err := xt.Model(&models.DeviceAddmacher{}).Create(machers).Error
  37. // //fmt.Println("err",err)
  38. // //if err !=nil{
  39. // // xt.Rollback()
  40. // //}
  41. // //xt.Commit()
  42. // //return err
  43. err := writeUserDb.Create(&machers).Error
  44. return err
  45. }
  46. func UpdateMachine(id int64, orgid int64, addmacher *models.DeviceAddmacher) error {
  47. err := writeUserDb.Model(&addmacher).Where("id = ? AND user_org_id = ? AND status = ?", id, orgid, 1).Updates(map[string]interface{}{"serial_number": addmacher.SerialNumber, "device_type": addmacher.DeviceType, "bed_number": addmacher.BedNumber, "device_name": addmacher.DeviceName, "manufacture_factory": addmacher.ManufactureFactory, "service_manufacturer": addmacher.ServiceManufacturer, "unit_type": addmacher.UnitType, "use_section": addmacher.UseSection, "section_number": addmacher.SectionNumber, "buy_date": addmacher.BuyDate, "install_date": addmacher.InstallDate, "start_date": addmacher.StartDate, "maintenace_engineer": addmacher.MaintenaceEngineer, "telephone": addmacher.Telephone, "guarantee_date": addmacher.GuaranteeDate, "machine_status": addmacher.MachineStatus, "user_total": addmacher.UserTotal, "remarks": addmacher.Remarks, "rubbish_date": addmacher.RubbishDate, "rubbish_reason": addmacher.RubbishReason, "user_year": addmacher.UserYear, "work_time": addmacher.WorkTime, "bed_id": addmacher.BedId, "disinfection_mode": addmacher.DisinfectionMode, "revers_mode": addmacher.ReversMode, "mtime": time.Now().Unix(), "zone_id": addmacher.ZoneId}).Error
  48. return err
  49. }
  50. func GetZoneName(zoneid int64, orgid int64) (models.DeviceZone, error) {
  51. zone := models.DeviceZone{}
  52. err := XTReadDB().Where("id = ? AND org_id = ?", zoneid, orgid).Find(&zone).Error
  53. return zone, err
  54. }
  55. func UpdateTreatMode(id int64, orgid int64, treatmodes []int64) (err error) {
  56. utx := XTWriteDB().Begin()
  57. err = utx.Model(models.DeviceTreatmentmode{}).Where("machine_id = ? AND user_org_id = ?", id, orgid).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
  58. fmt.Println("错误是什么", err)
  59. if err != nil {
  60. utx.Rollback()
  61. return
  62. }
  63. if len(treatmodes) > 0 {
  64. thisSQL := "INSERT INTO xt_device_treatmentmode(machine_id,treate_mode,status,ctime,user_org_id) VALUES "
  65. insertParams := make([]string, 0)
  66. insertData := make([]interface{}, 0)
  67. for _, treatmode := range treatmodes {
  68. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  69. insertData = append(insertData, id)
  70. insertData = append(insertData, treatmode)
  71. insertData = append(insertData, 1)
  72. insertData = append(insertData, time.Now().Unix())
  73. insertData = append(insertData, orgid)
  74. }
  75. thisSQL += strings.Join(insertParams, ",")
  76. err = utx.Exec(thisSQL, insertData...).Error
  77. if err != nil {
  78. utx.Rollback()
  79. return
  80. }
  81. }
  82. utx.Commit()
  83. return
  84. }
  85. func GetAllEquimentName(orgid int64) (equit []*models.DeviceEquimentname, err error) {
  86. err = readUserDb.Model(&equit).Where("user_org_id = ? AND status = ?", orgid, 1).Group("equitment_name").Find(&equit).Error
  87. return equit, err
  88. }
  89. func GetAllDeviceMode(orgid int64) (device []*models.DeviceMode, err error) {
  90. err = readUserDb.Model(&device).Where("user_org_id = ? and status = 1", orgid).Find(&device).Error
  91. return device, err
  92. }
  93. func GetBed(equitid int64) (models.DeviceAddmacher, error) {
  94. addmacher := models.DeviceAddmacher{}
  95. err := UserReadDB().Where("id=? AND status = ?", equitid, 1).Find(&addmacher).Error
  96. return addmacher, err
  97. }
  98. func QueryPlan(orgid int64, devicetype int64, ids []int64, classids []int64, equitid int64) (*models.DevicePlan, error) {
  99. var pre models.DevicePlan
  100. var err error
  101. //for _, id := range ids {
  102. // for _, classids := range classids {
  103. // err = UserReadDB().Model(&pre).Where("user_org_id = ? AND device_type = ? AND time = ? AND classtime = ? AND equiment_id = ? AND status = 1", orgid, devicetype, id, classids, equitid).Find(&pre).Error
  104. // }
  105. //}
  106. //if err == gorm.ErrRecordNotFound {
  107. // return nil, err
  108. //}
  109. //if err != nil {
  110. // return nil, err
  111. //}
  112. //return &pre, nil
  113. if len(ids) == 1 && len(classids) == 1 {
  114. err = UserWriteDB().Model(&models.DevicePlan{}).Where("user_org_id = ? and device_type = ? and time = ? and classtime = ? and status = 1 ", orgid, devicetype, ids[0], classids[0]).Find(&pre).Error
  115. if err == gorm.ErrRecordNotFound {
  116. return nil, err
  117. }
  118. if err != nil {
  119. return nil, err
  120. }
  121. } else {
  122. err = UserWriteDB().Model(models.DevicePlan{}).Where("time IN(?) and user_org_id = ? and device_type = ? AND classtime IN(?) and status = 1", ids, orgid, devicetype, classids).Find(&pre).Error
  123. if err == gorm.ErrRecordNotFound {
  124. return nil, err
  125. }
  126. if err != nil {
  127. return nil, err
  128. }
  129. }
  130. return &pre, nil
  131. }
  132. func AddPlan(orgid int64, deviceType int64, disinfecTime string, ids []int64, classids []int64, way int64, machinedisinfectant int64, disinfectantway int64, disinfectant int64, equimentid int64, bedid int64, bed_way int64) (err error) {
  133. xt := UserWriteDB().Begin()
  134. if len(ids) > 0 {
  135. thisSQL := "INSERT INTO xt_device_plan(device_type,disinfec_time,time,classtime,way,machine_disinfectant,disinfectan_way,disinfectant,status,ctime,user_org_id,equiment_id,bed_id,bed_way) VALUES "
  136. insertParams := make([]string, 0)
  137. insertData := make([]interface{}, 0)
  138. for _, id := range ids {
  139. for _, classids := range classids {
  140. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  141. insertData = append(insertData, deviceType)
  142. insertData = append(insertData, disinfecTime)
  143. insertData = append(insertData, id)
  144. insertData = append(insertData, classids)
  145. insertData = append(insertData, way)
  146. insertData = append(insertData, machinedisinfectant)
  147. insertData = append(insertData, disinfectantway)
  148. insertData = append(insertData, disinfectant)
  149. insertData = append(insertData, 1)
  150. insertData = append(insertData, time.Now().Unix())
  151. insertData = append(insertData, orgid)
  152. insertData = append(insertData, equimentid)
  153. insertData = append(insertData, bedid)
  154. insertData = append(insertData, bed_way)
  155. }
  156. }
  157. thisSQL += strings.Join(insertParams, ",")
  158. err = xt.Exec(thisSQL, insertData...).Error
  159. if err != nil {
  160. xt.Rollback()
  161. return
  162. }
  163. }
  164. xt.Commit()
  165. return
  166. }
  167. func GetAllPlan(orgid int64) (plan []*models.DevicePlans, err error) {
  168. //db := readUserDb.Table("xt_device_plan as p").Where("p.status = 1")
  169. // //table := readUserDb.Table("xt_device_addmacher as e")
  170. // //fmt.Println("table", table)
  171. // //if orgid > 0 {
  172. // // db = db.Where("p.user_org_id = ?", orgid)
  173. // //}
  174. // //err = db.Select("p.id,p.device_type,p.disinfec_time,p.time,p.classtime,p.way,p.machine_disinfectant,p.disinfectan_way,p.disinfectant,e.unit_type").Group("p.id").Joins("Left JOIN xt_device_addmacher as e On e.id = p.device_type").Order("e.unit_type asc,p.time").Scan(&plan).Error
  175. // //return plan, err
  176. err = readUserDb.Raw("select DISTINCT p.id,p.device_type,p.disinfec_time,p.time,p.classtime,p.way,p.machine_disinfectant,p.disinfectan_way,p.disinfectant,p.equiment_id,p.bed_id,e.device_mode,p.bed_way from xt_device_plan as p left join xt_device_mode as e On e.id = p.device_type where p.user_org_id = ? and p.status = 1", orgid).Order("e.device_mode asc,p.time").Scan(&plan).Error
  177. return plan, err
  178. }
  179. func GetDeviceType(unitype string) (models.DeviceMode, error) {
  180. equimentname := models.DeviceMode{}
  181. err := UserReadDB().Where("id = ?", unitype).Find(&equimentname).Error
  182. return equimentname, err
  183. }
  184. func GetAllPlanDetail(id int64, orgid int64) (plan []*models.DevicePlans, err error) {
  185. //db := readUserDb.Table("xt_device_plan as p").Where("p.status = 1")
  186. //table := readUserDb.Table("xt_device_addmacher as e")
  187. //fmt.Println("table", table)
  188. //if orgid > 0 {
  189. // db = db.Where("p.user_org_id = ?", orgid)
  190. //}
  191. //if id > 0 {
  192. // db = db.Where("p.equiment_id = ?", id)
  193. //}
  194. //err = db.Select("p.id,p.device_type,p.disinfec_time,p.time,p.classtime,p.way,p.machine_disinfectant,p.disinfectan_way,p.disinfectant,e.unit_type").Group("p.id").Joins("Left JOIN xt_device_addmacher as e On e.id = p.equiment_id").Order("p.time asc").Scan(&plan).Error
  195. //return plan, err
  196. err = readUserDb.Raw("select DISTINCT p.id,p.device_type,p.disinfec_time,p.time,p.classtime,p.way,p.machine_disinfectant,p.disinfectan_way,p.disinfectant,p.equiment_id,p.bed_id,e.device_mode,p.bed_way from xt_device_plan as p left join xt_device_mode as e On e.id = p.device_type where p.user_org_id = ? and p.device_type = ? and p.status = 1", orgid, id).Order("p.time asc,p.classtime asc").Scan(&plan).Error
  197. return plan, err
  198. }
  199. func DeletePlan(id int64) (err error) {
  200. err = UserWriteDB().Model(&models.DevicePlan{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  201. return
  202. }
  203. func DeletePlans(orgid int64, ids []int64) (err error) {
  204. if len(ids) == 1 {
  205. err = UserWriteDB().Model(&models.DevicePlan{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  206. } else {
  207. err = UserWriteDB().Model(models.DevicePlan{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  208. }
  209. return
  210. }
  211. func GetPlanDetailById(id int64, orgid int64) (models.DevicePlanss, error) {
  212. plans := models.DevicePlanss{}
  213. db := UserReadDB().Table("xt_device_plan as x").Where("x.status = 1")
  214. table := UserReadDB().Table("xt_device_addmacher as a").Where("a.status = 1")
  215. fmt.Println("table", table)
  216. if id > 0 {
  217. db = db.Where("x.id = ?", id)
  218. }
  219. if orgid > 0 {
  220. db = db.Where("x.user_org_id = ?", orgid)
  221. }
  222. err := db.Select("x.id,x.device_type,x.disinfec_time,x.time,x.classtime,x.way,x.machine_disinfectant,x.disinfectan_way,x.disinfectant,x.status,x.user_org_id,x.equiment_id,a.unit_type").Joins("Left Join xt_device_addmacher as a ON a.id = x.equiment_id").Scan(&plans).Error
  223. return plans, err
  224. }
  225. func UpdatePlanInfo(id int64, orgid int64, plan models.DevicePlan) error {
  226. err := writeUserDb.Model(&plan).Where("id = ? AND user_org_id = ?", id, orgid).Updates(map[string]interface{}{"device_type": plan.DeviceType, "disinfec_time": plan.DisinfecTime, "time": plan.Time, "classtime": plan.Classtime, "way": plan.Way, "machine_disinfectant": plan.MachineDisinfectant, "disinfectan_way": plan.DisinfectanWay, "disinfectant": plan.Disinfectant, "mtime": time.Now().Unix()}).Error
  227. return err
  228. }
  229. func GetComprehensive(zone int64, number int64, devicetype int64, year int64, starttime int64, endtime int64, orgid int64, device_mode int64) (macher []*models.DeviceAddmachers, err error) {
  230. db := readUserDb.Table("xt_device_addmacher as a").Where("a.status = 1")
  231. table := XTReadDB().Table("xt_device_zone as x")
  232. fmt.Println(table)
  233. if orgid > 0 {
  234. db = db.Where("a.user_org_id = ?", orgid)
  235. }
  236. if zone > 0 {
  237. db = db.Where("a.zone_id = ?", zone)
  238. }
  239. if number > 0 {
  240. db = db.Where("a.bed_id = ?", number)
  241. }
  242. if devicetype > 0 {
  243. db = db.Where("a.device_type = ?", devicetype)
  244. }
  245. if device_mode > 0 {
  246. db = db.Where("a.unit_type = ?", device_mode)
  247. }
  248. if year == 1 {
  249. db = db.Where("a.user_year >= 0 AND a.user_year <= 1")
  250. }
  251. if year == 2 {
  252. db = db.Where("a.user_year >=1 AND a.user_year <= 3")
  253. }
  254. if year == 3 {
  255. db = db.Where("a.user_year >=3 AND a.user_year <= 10")
  256. }
  257. if year == 4 {
  258. db = db.Where("a.user_year >=10")
  259. }
  260. if starttime > 0 {
  261. db = db.Where("a.ctime >= ?", starttime)
  262. }
  263. if endtime > 0 {
  264. db = db.Where("a.ctime <= ?", endtime)
  265. }
  266. err = db.Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,a.zone_id,a.bed_id,x.name,m.device_mode").Joins("Left JOIN sgj_xt.xt_device_zone as x On x.id = a.zone_id").Joins("Left JOIN xt_device_mode as m on m.id = a.unit_type").Scan(&macher).Error
  267. return macher, err
  268. }
  269. func GetBedId(id int64) (models.DeviceAddmacher, error) {
  270. addmacher := models.DeviceAddmacher{}
  271. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&addmacher).Error
  272. return addmacher, err
  273. }
  274. func GetPatientInfo(bedid int64, nowtime int64, orgid int64) (schedules []*models.Schedules, err error) {
  275. db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
  276. table := XTReadDB().Table("xt_patients as x")
  277. fmt.Println("table", table)
  278. if bedid > 0 {
  279. db = db.Where("s.bed_id = ?", bedid)
  280. }
  281. if nowtime > 0 {
  282. db = db.Where("s.schedule_date = ?", nowtime)
  283. }
  284. if orgid > 0 {
  285. db = db.Where("s.user_org_id = ?", orgid)
  286. }
  287. err = db.Select("s.id,s.user_org_id,s.partition_id,s.bed_id,s.patient_id,s.schedule_date,s.schedule_type,s.schedule_week,s.mode_id,x.name").Joins("Left Join xt_patients as x On x.id = s.patient_id").Scan(&schedules).Error
  288. return schedules, err
  289. }
  290. func GetPatient(bedid int64, orgid int64, classid int64, nowtime int64) (schedules models.Schedules, err error) {
  291. db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
  292. table := XTReadDB().Table("xt_patients as x")
  293. fmt.Println("table", table)
  294. err = db.Select("s.id,s.user_org_id,s.partition_id,s.bed_id,s.patient_id,s.schedule_date,s.schedule_type,s.schedule_week,s.mode_id,x.name,x.is_infectious").Joins("Left Join xt_patients as x On x.id = s.patient_id").Where("s.bed_id = ? AND s.user_org_id = ? AND s.schedule_type = ? AND s.schedule_date = ?", bedid, orgid, classid, nowtime).Scan(&schedules).Error
  295. return schedules, err
  296. }
  297. func GetPartitionName(id int64) (models.DeviceZone, error) {
  298. zone := models.DeviceZone{}
  299. err := XTReadDB().Where("id = ? AND status = 1", id).Find(&zone).Error
  300. return zone, err
  301. }
  302. func GetPatientNumber(id int64) (models.DeviceNumber, error) {
  303. number := models.DeviceNumber{}
  304. err := XTReadDB().Where("id = ? AND status = 1", id).Find(&number).Error
  305. return number, err
  306. }
  307. func GetDialysisOrder(time int64, patientid int64, orgid int64) (models.DialysisOrder, error) {
  308. order := models.DialysisOrder{}
  309. err := XTReadDB().Where("dialysis_date = ? AND patient_id = ? AND user_org_id = ? ", time, patientid, orgid).Find(&order).Error
  310. return order, err
  311. }
  312. func GetDialysisWay(time int64, patientid int64, orgid int64) (models.DialysisPrescription, error) {
  313. prescription := models.DialysisPrescription{}
  314. err := XTReadDB().Where("record_date = ? AND patient_id = ? AND user_org_id = ?", time, patientid, orgid).Find(&prescription).Error
  315. return prescription, err
  316. }
  317. func GetDialysisTime(time int64, patientid int64, orgid int64) (models.AssessmentAfterDislysis, error) {
  318. dislysis := models.AssessmentAfterDislysis{}
  319. err := XTReadDB().Where("assessment_date = ? AND patient_id = ? AND user_org_id = ?", time, patientid, orgid).Find(&dislysis).Error
  320. return dislysis, err
  321. }
  322. func GetAllOrganization(orgid int64, appid int64) (approle []*models.App_Role, err error) {
  323. err = UserReadDB().Where("org_id = ? AND app_id = ?", orgid, appid).Find(&approle).Error
  324. return approle, err
  325. }
  326. func CreateUserInformation(information *models.DeviceInformation) error {
  327. err := writeUserDb.Create(&information).Error
  328. return err
  329. }
  330. func GetRegisterInfo(orgid int64, id int64, timenow int64) (models.DeviceInformations, error) {
  331. //information := models.DeviceInformations{}
  332. var information models.DeviceInformations
  333. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  334. table := XTReadDB().Table("xt_patients as p")
  335. fmt.Println("table", table)
  336. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  337. fmt.Print("dbs", dbs)
  338. err = db.Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,p.name,r.user_name,r.admin_user_id").Joins("Left join sgj_xt.xt_patients as p On p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Where("x.user_org_id = ? AND x.equiment_id = ? AND x.date = ?", orgid, id, timenow).Scan(&information).Error
  339. return information, err
  340. }
  341. func GetSignName(id int64, orgid int64, appid int64) (models.App_Role, error) {
  342. role := models.App_Role{}
  343. err := UserReadDB().Model(&role).Where("admin_user_id = ? AND org_id = ? AND app_id = ?", id, orgid, appid).Find(&role).Error
  344. return role, err
  345. }
  346. func GetInformationData(limit int64, page int64, orgId int64) (information []*models.DeviceInformations, total int64, err error) {
  347. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  348. table := XTReadDB().Table("xt_patients as p")
  349. fmt.Println("table", table)
  350. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  351. fmt.Println("dbs", dbs)
  352. offset := (page - 1) * limit
  353. if orgId > 0 {
  354. db = db.Where("x.user_org_id = ?", orgId)
  355. }
  356. err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Order("x.ctime desc").Offset(offset).Limit(limit).Scan(&information).Error
  357. if err != nil {
  358. return
  359. }
  360. return
  361. }
  362. func GetOrgName(orgid int64) (models.Org, error) {
  363. org := models.Org{}
  364. err := UserReadDB().Where("id= ? AND status = 1", orgid).Find(&org).Error
  365. return org, err
  366. }
  367. func GetMyMobile(id int64) (models.SgjUserAdmin, error) {
  368. admin := models.SgjUserAdmin{}
  369. err := UserReadDB().Model(&admin).Where("id=? and status = 1", id).Find(&admin).Error
  370. return admin, err
  371. }
  372. func CreateCulture(culture *models.DeviceCulture) error {
  373. err := writeUserDb.Create(&culture).Error
  374. return err
  375. }
  376. func CreateDialysate(dialysate *models.DeviceDialysate) error {
  377. err := writeUserDb.Create(&dialysate).Error
  378. return err
  379. }
  380. func CreateIon(ion *models.DeviceIon) error {
  381. err := writeUserDb.Create(&ion).Error
  382. return err
  383. }
  384. func GetAllCulture(orgId int64) (cultures []*models.DeviceCultures, err error) {
  385. db := UserReadDB().Table("xt_device_culture as x").Where("x.status = 1")
  386. table := UserReadDB().Table("sgj_user_admin_role as r")
  387. fmt.Println("table", table)
  388. if orgId > 0 {
  389. db = db.Where("x.user_org_id = ?", orgId)
  390. }
  391. err = db.Group("x.id").Select("x.id,x.speling_date,x.specimen,x.concentrate_noa,x.concentrate_nob,x.sampling_locationa,x.detection_unit,x.sampler,x.reporting_date,x.detection_result,x.bed_id,x.bed,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sampler").Scan(&cultures).Error
  392. return cultures, err
  393. }
  394. func GetAllDialysate(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  395. db := UserReadDB().Table("xt_device_dialysate as x").Where("x.status = 1")
  396. table := UserReadDB().Table("sgj_user_admin_role as r")
  397. fmt.Println("table", table)
  398. if orgId > 0 {
  399. db = db.Where("x.user_org_id = ?", orgId)
  400. }
  401. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  402. return dialysate, err
  403. }
  404. func GetAllDeviceIon(orgId int64) (ions []*models.DeviceIons, err error) {
  405. db := UserReadDB().Table("xt_device_ion as x").Where("x.status = 1")
  406. table := UserReadDB().Table("sgj_user_admin_role as r")
  407. fmt.Println("table", table)
  408. if orgId > 0 {
  409. db = db.Where("x.user_org_id = ?", orgId)
  410. }
  411. err = db.Group("x.id").Select("x.id,x.sampling_date,x.samplerc,x.detection_unit,x.concentrate_nof,x.concentrate_nog,x.date_reportc,x.actual_na,x.actual_pna,x.actual_k,x.actual_ca,x.actual_ci,x.actual_hco,x.actual_mg,x.actual_ph,x.remakes,x.bed_id,x.bed,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerc").Scan(&ions).Error
  412. return ions, err
  413. }
  414. func GetCultureById(id int64) (models.DeviceCulture, error) {
  415. culture := models.DeviceCulture{}
  416. err := UserReadDB().Model(&culture).Where("id=? AND status = 1", id).Find(&culture).Error
  417. return culture, err
  418. }
  419. func GetSampler(id int64) (models.App_Role, error) {
  420. role := models.App_Role{}
  421. err := UserReadDB().Model(&role).Where("id= ? AND status =1", id).Find(&role).Error
  422. return role, err
  423. }
  424. func UpdateCulture(id int64, orgid int64, culture *models.DeviceCulture) error {
  425. err := writeUserDb.Model(&culture).Where("id= ? AND user_org_id = ? AND status = ?", id, orgid, 1).Updates(map[string]interface{}{"speling_date": culture.SpelingDate, "specimen": culture.Specimen, "concentrate_noa": culture.ConcentrateNoa, "concentrate_nob": culture.ConcentrateNob, "sampling_locationa": culture.SamplingLocationa, "detection_unit": culture.DetectionUnit, "sampler": culture.Sampler, "reporting_date": culture.ReportingDate, "detection_result": culture.DetectionResult, "sort": culture.Sort, "pass_examination": culture.PassExamination, "modifications": culture.Modifications, "mtime": time.Now().Unix()}).Error
  426. return err
  427. }
  428. func DeleteCultrues(id int64) (err error) {
  429. err = UserWriteDB().Model(models.DeviceCulture{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  430. return
  431. }
  432. func DeleteCultrue(orgid int64, ids []int64) (err error) {
  433. if len(ids) == 1 {
  434. err = UserWriteDB().Model(&models.DeviceCulture{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  435. } else {
  436. err = UserWriteDB().Model(models.DeviceCulture{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  437. }
  438. return
  439. }
  440. func GetDialystate(id int64) (models.DeviceDialysate, error) {
  441. dialysate := models.DeviceDialysate{}
  442. err := readUserDb.Where("id= ? AND status = 1", id).Find(&dialysate).Error
  443. return dialysate, err
  444. }
  445. func Updatedialystate(id int64, orgid int64, dialysate *models.DeviceDialysate) error {
  446. err := writeUserDb.Model(&dialysate).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": dialysate.SamplingDate, "specimenb": dialysate.Specimenb, "concentrate_noc": dialysate.ConcentrateNoc, "concentrateb_nod": dialysate.ConcentratebNod, "sampling_locationb": dialysate.SamplingLocationb, "detection_unit": dialysate.DetectionUnit, "samplerb": dialysate.Samplerb, "reporting_dateb": dialysate.ReportingDateb, "detection_resultb": dialysate.DetectionResultb, "sort": dialysate.Sort, "pass_examination": dialysate.PassExamination, "modifications": dialysate.Modifications, "mtime": time.Now().Unix()}).Error
  447. return err
  448. }
  449. func DeleteDialystates(id int64) (err error) {
  450. err = UserWriteDB().Model(&models.DeviceDialysate{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  451. return
  452. }
  453. func DeleteDialystate(orgid int64, ids []int64) (err error) {
  454. if len(ids) == 1 {
  455. err = UserWriteDB().Model(&models.DeviceDialysate{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  456. } else {
  457. err = UserWriteDB().Model(models.DeviceDialysate{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  458. }
  459. return
  460. }
  461. func GetIon(id int64) (models.DeviceIon, error) {
  462. ion := models.DeviceIon{}
  463. err := UserReadDB().Model(&ion).Where("id = ? AND status = 1", id).Find(&ion).Error
  464. return ion, err
  465. }
  466. func UpdateIon(id int64, orgid int64, ion *models.DeviceIon) error {
  467. err := writeUserDb.Model(&ion).Where("id = ? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": ion.SamplingDate, "samplerc": ion.Samplerc, "detection_unit": ion.DetectionUnit, "concentrate_nof": ion.ConcentrateNof, "concentrate_nog": ion.ConcentrateNog, "date_reportc": ion.DateReportc, "actual_na": ion.ActualNa, "actual_pna": ion.ActualPna, "actual_k": ion.ActualK, "actual_ca": ion.ActualCa, "actual_ci": ion.ActualCi, "actual_hco": ion.ActualCi, "actual_mg": ion.ActualMg, "actual_ph": ion.ActualPh, "remakes": ion.Remakes, "sort": ion.Sort, "pass_examination": ion.PassExamination, "modifications": ion.Modifications, "mtime": time.Now().Unix()}).Error
  468. return err
  469. }
  470. func DeleteIons(id int64) (err error) {
  471. err = UserWriteDB().Model(&models.DeviceIon{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  472. return
  473. }
  474. func DeleteIon(orgid int64, ids []int64) (err error) {
  475. if len(ids) == 1 {
  476. err = UserWriteDB().Model(&models.DeviceIon{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  477. } else {
  478. err = UserWriteDB().Model(models.DeviceIon{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  479. }
  480. return
  481. }
  482. func GetCultureData(bedid int64, start int64, end int64, orgId int64) (cultures []*models.DeviceCultures, err error) {
  483. db := UserReadDB().Table("xt_device_culture as x").Where("x.status = 1")
  484. table := UserReadDB().Table("sgj_user_admin_role as r")
  485. fmt.Println("table", table)
  486. if orgId > 0 {
  487. db = db.Where("x.user_org_id = ?", orgId)
  488. }
  489. if bedid > 0 {
  490. db = db.Where("x.bed_id = ?", bedid)
  491. }
  492. if start > 0 {
  493. db = db.Where("x.speling_date >= ?", start)
  494. }
  495. if end > 0 {
  496. db = db.Where("x.speling_date <= ?", end)
  497. }
  498. err = db.Group("x.id").Select("x.id,x.speling_date,x.specimen,x.concentrate_noa,x.concentrate_nob,x.sampling_locationa,x.detection_unit,x.sampler,x.reporting_date,x.detection_result,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sampler").Scan(&cultures).Error
  499. return cultures, err
  500. }
  501. func GetDeviceIonData(bedid int64, start int64, end int64, orgId int64) (ions []*models.DeviceIons, err error) {
  502. db := UserReadDB().Table("xt_device_ion as x").Where("x.status = 1")
  503. table := UserReadDB().Table("sgj_user_admin_role as r")
  504. fmt.Println("table", table)
  505. if orgId > 0 {
  506. db = db.Where("x.user_org_id = ?", orgId)
  507. }
  508. if bedid > 0 {
  509. db = db.Where("x.bed_id = ?", bedid)
  510. }
  511. if start > 0 {
  512. db = db.Where("x.sampling_date >= ?", start)
  513. }
  514. if end > 0 {
  515. db = db.Where("x.sampling_date <= ?", end)
  516. }
  517. err = db.Group("x.id").Select("x.id,x.sampling_date,x.samplerc,x.detection_unit,x.concentrate_nof,x.concentrate_nog,x.date_reportc,x.actual_na,x.actual_pna,x.actual_k,x.actual_ca,x.actual_ci,x.actual_hco,x.actual_mg,x.actual_ph,x.remakes,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerc").Scan(&ions).Error
  518. return ions, err
  519. }
  520. func CreateRepair(repair *models.DeviceRepair) error {
  521. err = writeUserDb.Create(&repair).Error
  522. return err
  523. }
  524. func GetAllRepair(orgid int64, limit int64, page int64) (repair []*models.DeviceRepairs, total int64, err error) {
  525. db := UserReadDB().Table("xt_device_repair as r").Where("r.status = ?", 1)
  526. table := XTReadDB().Table("xt_device_number as x")
  527. offset := (page - 1) * limit
  528. fmt.Print("table", table)
  529. if orgid > 0 {
  530. db = db.Where("r.user_org_id = ?", orgid)
  531. }
  532. err = db.Count(&total).Select("r.id,r.guarantee_date,r.start_time,r.arrive_time,r.finish_time,r.total_distance,r.failure_stage,r.fault_description,r.cause_analysis,r.treatment_process,r.images,r.exclude,r.reason,r.ctime,r.mtime,r.status,r.user_org_id,r.bed_id,r.equitment_id,r.code_information,x.number").Joins("Left join sgj_xt.xt_device_number as x on x.id = r.bed_id").Offset(offset).Limit(limit).Scan(&repair).Error
  533. // err = UserReadDB().Where("user_org_id = ? AND status = 1", orgid).Find(&repair).Error
  534. return repair, total, err
  535. }
  536. func EditRepair(id int64) (models.DeviceRepair, error) {
  537. repair := models.DeviceRepair{}
  538. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&repair).Error
  539. return repair, err
  540. }
  541. func UpdateRepair(id int64, orgid int64, repair *models.DeviceRepair) error {
  542. err := writeUserDb.Model(&repair).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"guarantee_date": repair.GuaranteeDate, "start_time": repair.StartTime, "arrive_time": repair.ArriveTime, "finish_time": repair.FinishTime, "total_distance": repair.TotalDistance, "failure_stage": repair.FailureStage, "fault_description": repair.FaultDescription, "cause_analysis": repair.CauseAnalysis, "treatment_process": repair.TreatmentProcess, "images": repair.Images, "exclude": repair.Exclude, "reason": repair.Reason, "code_information": repair.CodeInformation, "image_name": repair.ImageName, "mtime": time.Now().Unix(), "function_accessories_inspection": repair.FunctionAccessoriesInspection, "other_information": repair.OtherInformation, "admin_user_id": repair.AdminUserId}).Error
  543. return err
  544. }
  545. func DeleteRepairs(id int64) (err error) {
  546. err = UserWriteDB().Model(models.DeviceRepair{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  547. return
  548. }
  549. func DeleteRepair(orgid int64, ids []int64) (err error) {
  550. if len(ids) == 1 {
  551. err = UserWriteDB().Model(&models.DeviceRepair{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  552. } else {
  553. err = UserWriteDB().Model(models.DeviceRepair{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  554. }
  555. return
  556. }
  557. func GetRepair(bedid int64, start int64, end int64, orgid int64) (repair []*models.DeviceRepairs, err error) {
  558. db := UserReadDB().Table("xt_device_repair as r").Where("r.status = 1")
  559. sb := UserReadDB().Table("xt_device_addmacher as x")
  560. fmt.Print("sb", sb)
  561. if orgid > 0 {
  562. db = db.Where("r.user_org_id = ?", orgid)
  563. }
  564. if bedid > 0 {
  565. db = db.Where("r.bed_id = ?", bedid)
  566. }
  567. if start > 0 {
  568. db = db.Where("r.guarantee_date >= ?", start)
  569. }
  570. if end > 0 {
  571. db = db.Where("r.guarantee_date <= ?", end)
  572. }
  573. //err = db.Model(&repair).Find(&repair).Error
  574. err = db.Select("r.id,r.guarantee_date,r.start_time,r.arrive_time,r.finish_time,r.total_distance,r.failure_stage,r.fault_description,r.cause_analysis,r.treatment_process,r.images,r.exclude,r.reason,r.ctime,r.mtime,r.status,r.user_org_id,r.bed_id,r.equitment_id,r.code_information,x.number").Joins("Left join sgj_xt.xt_device_number as x on x.id = r.bed_id").Scan(&repair).Error
  575. return repair, err
  576. }
  577. func GetUserInformation(id int64) (models.DeviceInformation, error) {
  578. information := models.DeviceInformation{}
  579. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&information).Error
  580. return information, err
  581. }
  582. func GetPatientInfoMation(patieintid int64) (models.Patients, error) {
  583. patients := models.Patients{}
  584. err := XTReadDB().Where("id = ? AND status = 1", patieintid).Find(&patients).Error
  585. return patients, err
  586. }
  587. func DeleteUserLogin(id int64) (err error) {
  588. err = UserWriteDB().Model(&models.DeviceInformation{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  589. return
  590. }
  591. func DeleteForm(orgid int64, ids []int64) (err error) {
  592. if len(ids) == 1 {
  593. err = UserWriteDB().Model(&models.DeviceInformation{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  594. } else {
  595. err = UserWriteDB().Model(models.DeviceInformation{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  596. }
  597. return
  598. }
  599. func GetLastInformationdata(eid int64, startdate int64, orgid int64) (models.DeviceInformation, error) {
  600. information := models.DeviceInformation{}
  601. err := UserReadDB().Model(&information).Where("equiment_id = ? and date = ? and user_org_id = ? and status = 1", eid, startdate, orgid).Last(&information).Error
  602. return information, err
  603. }
  604. func UpdateAddMacherBedID(id int64, orgid int64, addmacher *models.DeviceAddmacher) error {
  605. err := UserWriteDB().Model(&addmacher).Where("id=? and user_org_id = ? and status =1", id, orgid).Update(map[string]interface{}{"bed_id": addmacher.BedId, "mtime": addmacher.Mtime}).Error
  606. return err
  607. }
  608. func UpdatedZoneID(bedid int64, orgid int64, number *models.DeviceNumber) error {
  609. err := XTWriteDB().Model(&number).Where("id=? and org_id = ?", bedid, orgid).Update(map[string]interface{}{"zone_id": number.ZoneID, "mtime": time.Now().Unix()}).Error
  610. return err
  611. }
  612. func UpadateForm(id int64, orgid int64, infor *models.DeviceInformation) error {
  613. err := UserWriteDB().Model(&infor).Where("id = ? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"date": infor.Date, "class": infor.Class, "zone": infor.Zone, "bed_number": infor.BedNumber, "contagion": infor.Contagion, "dialysis_mode": infor.DialysisMode, "start_time": infor.StartTime, "end_time": infor.EndTime, "dialysis_hour": infor.DialysisHour, "hyperfiltratio": infor.Hyperfiltratio, "weight_loss": infor.WeightLoss, "warning_value": infor.WarningValue, "user_total": infor.UserTotal, "move": infor.Move, "failure_stage": infor.FailureStage, "fault_description": infor.FaultDescription, "code_information": infor.CodeInformation, "disinfect_type": infor.DisinfectType, "disinfectant_type": infor.DisinfectantType, "disinfection": infor.Disinfection, "machine_run": infor.MachineRun, "fluid_path": infor.FluidPath, "disinfectant": infor.Disinfectant, "disinfection_status": infor.DisinfectionStatus, "disinfection_residue": infor.DisinfectionResidue, "long_time": infor.LongTime, "disinfec_startime": infor.DisinfecStartime, "disinfec_endtime": infor.DisinfecEndtime, "dialysis_checked": infor.DialysisChecked, "dialysis_name": infor.DialysisName, "norms": infor.Norms, "dialysis_concentration": infor.DialysisConcentration,
  614. "germ_checked": infor.GermChecked, "germ_name": infor.GermName, "germ_number": infor.GermNumber, "clean": infor.Clean, "sign_name": infor.SignName, "bed": infor.Bed, "patient_id": infor.PatientId, "mtime": time.Now().Unix()}).Error
  615. return err
  616. }
  617. func QueryInfo(bed int64, start int64, end int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
  618. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  619. table := XTReadDB().Table("xt_patients as p")
  620. fmt.Println("table", table)
  621. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  622. fmt.Println("dbs", dbs)
  623. if orgId > 0 {
  624. db = db.Where("x.user_org_id = ?", orgId)
  625. }
  626. //if zone > 0 {
  627. // db = db.Where("x.zone = ?", zone)
  628. //}
  629. if bed > 0 {
  630. db = db.Where("x.bed_number = ?", bed)
  631. }
  632. if start > 0 {
  633. db = db.Where("x.date >= ?", start)
  634. }
  635. if end > 0 {
  636. db = db.Where("x.date <= ?", end)
  637. }
  638. offset := (page - 1) * limit
  639. err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Order("x.date desc").Offset(offset).Limit(limit).Scan(&infor).Error
  640. if err != nil {
  641. return
  642. }
  643. return
  644. }
  645. func GetPatientID(bedid int64, orgId int64, nowtime int64) (dialysis []*models.DialysisOrder, err error) {
  646. err = XTReadDB().Model(&dialysis).Where("bed_id = ? AND user_org_id = ? AND dialysis_date = ?", bedid, orgId, nowtime).Find(&dialysis).Error
  647. return dialysis, err
  648. }
  649. //func GetAllEquitType(orgId int64) (addmacher []*models.DeviceAddmacher, err error) {
  650. //
  651. // db := UserReadDB().Table("xt_device_addmacher as a").Where("a.status = 1")
  652. // if orgId > 0 {
  653. // db = db.Where("a.user_org_id = ?", orgId)
  654. // }
  655. // err = db.Group("a.unit_type").Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,a.zone_id,a.bed_id").Where("a.device_type <> 2 AND a.device_type <> 3").Scan(&addmacher).Error
  656. // return addmacher, err
  657. //}
  658. func GetAllEquitType(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
  659. //err = UserReadDB().Raw("select equitment_name,id,user_org_id,equitment_id from xt_device_equimentname where user_org_id = ? GROUP BY equitment_name ",orgid).Scan(&equiment).Error
  660. //err = UserReadDB().Raw("SELECT e.id,e.equitment_name,e.user_org_id,e.equitment_id FROM xt_device_equimentname as e LEFT JOIN xt_device_addmacher as a ON a.id = e.equitment_id WHERE a.status = 1 AND a.device_type <> 2 AND a.device_type <> 3 AND e.user_org_id = ? GROUP BY equitment_name", orgid).Scan(&equiment).Error
  661. //err = UserReadDB().Where("user_org_id = ? and status =1", orgid).Find(&equiment).Error
  662. err = UserReadDB().Raw("select x.equitment_name,x.id,x.user_org_id,x.equitment_id,x.bed_id from xt_device_equimentname as x where x.user_org_id = ? and x.status = ? GROUP BY x.equitment_name", orgid, 1).Scan(&equiment).Error
  663. return equiment, err
  664. }
  665. func GetAllEquitName(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
  666. err = UserReadDB().Raw("select id,equitment_name,status,ctime,mtime,user_org_id,equitment_id from xt_device_equimentname as e Where EXISTS (select id from xt_device_addmacher as a where a.id = e.equitment_id and a.status = 1) AND e.user_org_id = ? AND e.status = 1 ", orgid).Scan(&equiment).Error
  667. return equiment, err
  668. }
  669. func GetUserForm(id int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
  670. if orgId == 10060 {
  671. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  672. table := XTReadDB().Table("xt_patients as p")
  673. fmt.Println("table", table)
  674. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  675. fmt.Println("dbs", dbs)
  676. offset := (page - 1) * limit
  677. if id > 0 {
  678. db = db.Where("x.equiment_id = ?", id)
  679. }
  680. if orgId > 0 {
  681. db = db.Where("x.user_org_id = ?", orgId)
  682. }
  683. err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.admin_user_id,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Offset(offset).Limit(limit).Order("x.date asc").Scan(&infor).Error
  684. if err != nil {
  685. return
  686. }
  687. return
  688. } else {
  689. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  690. table := XTReadDB().Table("xt_patients as p")
  691. fmt.Println("table", table)
  692. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  693. fmt.Println("dbs", dbs)
  694. offset := (page - 1) * limit
  695. if id > 0 {
  696. db = db.Where("x.equiment_id = ?", id)
  697. }
  698. if orgId > 0 {
  699. db = db.Where("x.user_org_id = ?", orgId)
  700. }
  701. err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.admin_user_id,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Offset(offset).Limit(limit).Order("x.date desc").Scan(&infor).Error
  702. if err != nil {
  703. return
  704. }
  705. return
  706. }
  707. }
  708. func GetBedNumber(id int64, orgid int64) (models.DeviceAddmacher, error) {
  709. addmacher := models.DeviceAddmacher{}
  710. err := UserReadDB().Where("id= ? AND user_org_id = ?", id, orgid).Find(&addmacher).Error
  711. return addmacher, err
  712. }
  713. func GetNumbers(id int64, orgid int64) (models.DeviceNumber, error) {
  714. number := models.DeviceNumber{}
  715. err := XTReadDB().Where("id = ? AND org_id = ?", id, orgid).Find(&number).Error
  716. return number, err
  717. }
  718. func GetZoneForm(id int64) (models.DeviceAddmacher, error) {
  719. macher := models.DeviceAddmacher{}
  720. err := UserReadDB().Where("id=? AND status = 1", id).Find(&macher).Error
  721. return macher, err
  722. }
  723. func GetBedForm(id int64) (number []*models.DeviceNumber, err error) {
  724. err = XTReadDB().Where("zone_id = ? AND status = 1", id).Find(&number).Error
  725. return number, err
  726. }
  727. func GetTotalCount(orgid int64) (repair []*models.DeviceRepair, total int64, err error) {
  728. err = UserReadDB().Model(&repair).Where("user_org_id = ? and status = 1", orgid).Find(&repair).Count(&total).Error
  729. return repair, total, err
  730. }
  731. func GetTotalNumber(id int64, orgid int64) (total int64, err error) {
  732. var device models.DeviceInformation
  733. err = UserReadDB().Model(&device).Where("equiment_id = ? AND user_org_id = ? AND status = 1", id, orgid).Find(&device).Count(&total).Error
  734. return total, err
  735. }
  736. func GetTimeWarning(equitid int64, orgId int64) (models.DeviceInformation, error) {
  737. information := models.DeviceInformation{}
  738. err = UserReadDB().Where(" user_org_id = ? AND status = 1 AND equiment_id = ? AND (dialysis_checked = 1 or dialysis_checked = 0)", orgId, equitid).Last(&information).Error
  739. return information, err
  740. }
  741. func GetTimeLast(equitid int64, orgId int64) (models.DeviceInformation, error) {
  742. information := models.DeviceInformation{}
  743. err := UserReadDB().Model(&information).Where("equiment_id = ? AND user_org_id = ? AND status = 1 AND (germ_checked = 1 or germ_checked = 0)", equitid, orgId).Last(&information).Error
  744. return information, err
  745. }
  746. func GetTimeLastData(equitid int64, orgId int64) (models.DeviceInformation, error) {
  747. information := models.DeviceInformation{}
  748. err := UserReadDB().Model(&information).Where("equiment_id = ? AND user_org_id = ? AND status = 1 AND (clean = 1 or clean = 0)", equitid, orgId).Last(&information).Error
  749. return information, err
  750. }
  751. func GetAllpatient(orgid int64) (patients []*models.Patients, err error) {
  752. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patients).Error
  753. return patients, err
  754. }
  755. func GetAllpatientTwenty(orgid int64) (patients []*models.PatientsTwenty, err error) {
  756. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patients).Error
  757. return patients, err
  758. }
  759. func GetAllpatientThirty(orgid int64) (patients []*models.PatientsThirty, err error) {
  760. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patients).Error
  761. return patients, err
  762. }
  763. func GetAllpatientFourty(orgid int64) (patients []*models.PatientsThirty, err error) {
  764. err = XTReadDB().Where("user_org_id = ? and status = 1 and lapseto = 1", orgid).Find(&patients).Error
  765. return patients, err
  766. }
  767. func GetAllpatientFivty() (patients []*models.Patients, err error) {
  768. err = XTReadDB().Where("status = 1").Find(&patients).Error
  769. return patients, err
  770. }
  771. func GetInformation(eid int64, startdate int64, orgid int64, classtype int64) (*models.DeviceInformation, error) {
  772. var information models.DeviceInformation
  773. var err error
  774. err = UserReadDB().Model(&information).Where("equiment_id = ? and user_org_id = ? and status = ? and date = ? and class = ?", eid, orgid, 1, startdate, classtype).Find(&information).Error
  775. fmt.Print("", err)
  776. if err == gorm.ErrRecordNotFound {
  777. return nil, err
  778. }
  779. if err != nil {
  780. return nil, err
  781. }
  782. return &information, nil
  783. }
  784. func GetLastInformationById(eid int64, orgid int64) (models.DeviceInformation, error) {
  785. information := models.DeviceInformation{}
  786. err := UserReadDB().Model(&information).Where("equiment_id = ? and user_org_id = ? and status = 1", eid, orgid).Last(&information).Error
  787. return information, err
  788. }
  789. func ChangeBed(id int64, org int64) (number []*models.DeviceNumber, err error) {
  790. err = XTReadDB().Model(&number).Where("zone_id = ? AND status = 1 AND org_id = ? ", id, org).Find(&number).Error
  791. return number, err
  792. }
  793. func GetPatientDetail(id int64, orgid int64) (models.Patients, error) {
  794. patients := models.Patients{}
  795. err := XTReadDB().Where("id=? and user_org_id = ?", id, orgid).Find(&patients).Error
  796. return patients, err
  797. }
  798. func GetRemanderData(orgid int64) (remander models.DeviceRemander, err error) {
  799. err = UserReadDB().Model(&models.DeviceRemander{}).Where("user_org_id = ? and status = 1", orgid).Find(&remander).Error
  800. return
  801. }
  802. func CreateRemander(remander *models.DeviceRemander) (err error) {
  803. err = UserWriteDB().Create(&remander).Error
  804. return
  805. }
  806. func UpdateRemander(remander *models.DeviceRemander) (err error) {
  807. err = UserWriteDB().Save(&remander).Error
  808. return
  809. }
  810. func GetMode(mode string, orgid int64) (*models.DeviceMode, error) {
  811. var information models.DeviceMode
  812. var err error
  813. err = UserReadDB().Model(&information).Where("device_mode = ? and user_org_id = ? and status = ?", mode, orgid, 1).Find(&information).Error
  814. fmt.Print("", err)
  815. if err == gorm.ErrRecordNotFound {
  816. return nil, err
  817. }
  818. if err != nil {
  819. return nil, err
  820. }
  821. return &information, nil
  822. }
  823. func SaveMode(mode *models.DeviceMode) (err error) {
  824. err = UserWriteDB().Save(&mode).Error
  825. return
  826. }
  827. func GetAllMode(orgid int64) (mode []*models.DeviceMode, err error) {
  828. err = UserReadDB().Where("user_org_id = ? and status = ?", orgid, 1).Find(&mode).Error
  829. return mode, err
  830. }
  831. func GetModeById(id int64) (models.DeviceMode, error) {
  832. mode := models.DeviceMode{}
  833. err := UserReadDB().Where("id = ?", id).Find(&mode).Error
  834. return mode, err
  835. }
  836. func UpdateMode(id int64, mode models.DeviceMode) error {
  837. err := UserWriteDB().Model(&mode).Where("id=?", id).Update(map[string]interface{}{"device_mode": mode.DeviceMode, "mtime": time.Now().Unix()}).Error
  838. return err
  839. }
  840. func QueryDeviceMode(id int64, orgid int64) (*models.DeviceAddmacher, error) {
  841. addmacher := models.DeviceAddmacher{}
  842. var err error
  843. err = UserReadDB().Model(&addmacher).Where("unit_type = ? and user_org_id = ?", id, orgid).Find(&addmacher).Error
  844. if err == gorm.ErrRecordNotFound {
  845. return nil, err
  846. }
  847. if err != nil {
  848. return nil, err
  849. }
  850. return &addmacher, nil
  851. }
  852. func DeleteMode(id int64) error {
  853. err := UserWriteDB().Model(models.DeviceMode{}).Where("id=?", id).Update(map[string]interface{}{"status": 0}).Error
  854. return err
  855. }
  856. func SelectChange(id int64, orgid int64) (number []*models.DeviceNumber, err error) {
  857. //err = XTReadDB().Where("zone_id = ? and org_id = ? and status = ?", id, orgid, 1).Find(&number).Error
  858. db := XTReadDB().Table("xt_device_number as x").Where("x.status = ?", 1)
  859. err = db.Select("org_id,number,group_id,zone_id as id").Where("zone_id = ? and org_id = ?", id, orgid).Find(&number).Error
  860. return number, err
  861. }
  862. func SelectBed(id int64, orgid int64) (models.DeviceNumber, error) {
  863. number := models.DeviceNumber{}
  864. err := XTReadDB().Where("id = ? and org_id = ?", id, orgid).Find(&number).Error
  865. return number, err
  866. }
  867. func GetTimeData(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  868. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  869. //err = db.Raw("select id,date,class,zone,bed_number,patient_id,contagion,dialysis_mode,start_time,end_time,dialysis_hour,hyperfiltratio,weight_loss,warning_value,user_total,move,failure_stage,fault_description,code_information,disinfect_type,disinfectant_type,disinfection,machine_run,fluid_path,disinfectant,disinfection_status,disinfection_residue,long_time,disinfec_startime,disinfec_endtime,dialysis_checked,dialysis_name,norms,dialysis_concentration,germ_checked,germ_name,germ_number,clean,sign_name,status,ctime,mtime,user_org_id,equiment_id,bed,stime from xt_device_information where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= ? and equiment_id = ? and user_org_id = ?",timenow,equitid, orgid).Error
  870. day := time.Now().Day()
  871. oldMonth := day - 30
  872. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  873. err = UserReadDB().Model(&information).Where("date>= ? and date <= ? and equiment_id = ? and user_org_id = ? and dialysis_checked = 1 ", t.Unix(), timenow, equitid, orgid).Find(&information).Error
  874. return information, err
  875. }
  876. func GetTimeTwo(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  877. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  878. //err = db.Raw("select id,date,class,zone,bed_number,patient_id,contagion,dialysis_mode,start_time,end_time,dialysis_hour,hyperfiltratio,weight_loss,warning_value,user_total,move,failure_stage,fault_description,code_information,disinfect_type,disinfectant_type,disinfection,machine_run,fluid_path,disinfectant,disinfection_status,disinfection_residue,long_time,disinfec_startime,disinfec_endtime,dialysis_checked,dialysis_name,norms,dialysis_concentration,germ_checked,germ_name,germ_number,clean,sign_name,status,ctime,mtime,user_org_id,equiment_id,bed,stime from xt_device_information where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= ? and equiment_id = ? and user_org_id = ?",timenow,equitid, orgid).Error
  879. day := time.Now().Day()
  880. oldMonth := day - 30
  881. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  882. err = UserReadDB().Model(&information).Where("date >= ? and date<= ? and equiment_id = ? and user_org_id = ? and germ_checked = 1 ", t.Unix(), timenow, equitid, orgid).Find(&information).Error
  883. return information, err
  884. }
  885. func GetTimeThree(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  886. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  887. //err = db.Raw("select id,date,class,zone,bed_number,patient_id,contagion,dialysis_mode,start_time,end_time,dialysis_hour,hyperfiltratio,weight_loss,warning_value,user_total,move,failure_stage,fault_description,code_information,disinfect_type,disinfectant_type,disinfection,machine_run,fluid_path,disinfectant,disinfection_status,disinfection_residue,long_time,disinfec_startime,disinfec_endtime,dialysis_checked,dialysis_name,norms,dialysis_concentration,germ_checked,germ_name,germ_number,clean,sign_name,status,ctime,mtime,user_org_id,equiment_id,bed,stime from xt_device_information where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= ? and equiment_id = ? and user_org_id = ?",timenow,equitid, orgid).Error
  888. day := time.Now().Day()
  889. oldMonth := day - 30
  890. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  891. err = UserReadDB().Model(&information).Where("date >= ? and date <= ? and equiment_id = ? and user_org_id = ? and clean = 1 ", t.Unix(), timenow, equitid, orgid).Find(&information).Error
  892. return information, err
  893. }
  894. func DeleteImages(id int64) error {
  895. repair := models.DeviceRepair{}
  896. err := UserWriteDB().Model(&repair).Where("id=?", id).Update(map[string]interface{}{"images": "", "image_name": ""}).Error
  897. return err
  898. }
  899. func GetActivtyCreator(creator int64) (*models.KyActivityTable, error) {
  900. table := models.KyActivityTable{}
  901. err := UserReadDB().Model(&table).Where("admin_user_id = ? and status =1", creator).Find(&table).Error
  902. if err == gorm.ErrRecordNotFound {
  903. return nil, err
  904. }
  905. if err != nil {
  906. return nil, err
  907. }
  908. return &table, nil
  909. }
  910. func CreateTable(table *models.KyActivityTable) error {
  911. err := UserWriteDB().Model(&table).Create(&table).Error
  912. return err
  913. }
  914. func GetAdminUserRole(id int64, orgid int64) (models.SgjUserAdminRole, error) {
  915. role := models.SgjUserAdminRole{}
  916. err := UserReadDB().Where("admin_user_id = ? and org_id = ? and status = 1", id, orgid).Find(&role).Error
  917. return role, err
  918. }
  919. func GetRolePosition(id int64) (models.SgjUserRole, error) {
  920. role := models.SgjUserRole{}
  921. err := UserReadDB().Where("id = ? And status =1", id).Find(&role).Error
  922. return role, err
  923. }
  924. func GetMobile(id int64) (models.SgjUserAdmin, error) {
  925. admin := models.SgjUserAdmin{}
  926. err := UserReadDB().Where("id=? and status = 1", id).Find(&admin).Error
  927. return admin, err
  928. }
  929. func GetOrgs(id int64) (roles []*models.SgjUserAdminRole, err error) {
  930. db := UserReadDB().Table("sgj_user_admin_role as s").Where("s.status = 1")
  931. err = db.Group("s.org_id").Select("s.admin_user_id,s.org_id,s.app_id,s.role_id,s.user_name,s.avatar,s.user_type,s.user_title,s.intro,s.user_title_name,s.role_ids,s.message,s.sex,s.birthday,x.org_name,x.org_logo,x.creator,x.id").Where("s.admin_user_id = ?", id).Joins("left join sgj_user_org as x on x.id = s.org_id").Scan(&roles).Error
  932. return roles, err
  933. }
  934. func GetUserMachTotalCount(orgid int64) (vm []*models.VmDeviceInformation, err error) {
  935. err = UserReadDB().Raw("SELECT x.bed_number,count(*) as total FROM xt_device_information as x WHERE user_org_id = ? and `status` = 1 GROUP BY x.bed_number ", orgid).Scan(&vm).Error
  936. return vm, err
  937. }
  938. func GetUserTotalByMacher(id int64) (models.DeviceAddmacher, error) {
  939. addmacher := models.DeviceAddmacher{}
  940. err := UserReadDB().Model(&addmacher).Where("id=? and status = 1", id).Find(&addmacher).Error
  941. return addmacher, err
  942. }
  943. func GetUserTotalCount(orgid int64, bedid int64) (vm []*models.VmDeviceInformation, err error) {
  944. err = UserReadDB().Raw("SELECT x.bed_number,count(*) as total FROM xt_device_information as x WHERE user_org_id = ? and `status` = 1 and bed_number= ? GROUP BY x.bed_number ", orgid, bedid).Scan(&vm).Error
  945. return vm, err
  946. }
  947. func GetUserTotal(orgid int64, id int64) (models.DeviceAddmacher, error) {
  948. addmacher := models.DeviceAddmacher{}
  949. err := UserReadDB().Model(&addmacher).Where("user_org_id = ? and bed_id = ? and status = 1", orgid, id).Find(&addmacher).Error
  950. return addmacher, err
  951. }
  952. func GetDisInfectionTime(orgid int64, unitype int64, scheduletype int64, scheduleweek int64) (*models.DevicePlan, error) {
  953. plan := models.DevicePlan{}
  954. err = UserReadDB().Model(&plan).Where("user_org_id = ? and device_type = ? and classtime = ? and time = ? and status = 1", orgid, unitype, scheduletype, scheduleweek).Find(&plan).Error
  955. if err == gorm.ErrRecordNotFound {
  956. return nil, err
  957. }
  958. if err != nil {
  959. return nil, err
  960. }
  961. return &plan, nil
  962. }
  963. func GetUnitType(bedid int64, orgid int64) (models.DeviceAddmacher, error) {
  964. addmacher := models.DeviceAddmacher{}
  965. err := UserReadDB().Model(&addmacher).Where("bed_id = ? and user_org_id = ? and status = 1", bedid, orgid).Find(&addmacher).Error
  966. return addmacher, err
  967. }
  968. func GetLaseDeviceInfomation(orgid int64, bedid int64, date int64, scheduletype int64) (*models.DeviceInformation, error) {
  969. information := models.DeviceInformation{}
  970. err := UserReadDB().Model(&information).Where("bed_number = ? and user_org_id =? and status = 1 and date = ? and class = ? ", bedid, orgid, date, scheduletype).Find(&information).Error
  971. if err == gorm.ErrRecordNotFound {
  972. return nil, err
  973. }
  974. if err != nil {
  975. return nil, err
  976. }
  977. return &information, nil
  978. }
  979. func GetLaseDeviceInfomationTwo(orgid int64, bedid int64, scheduletype int64) (models.DeviceInformation, error) {
  980. information := models.DeviceInformation{}
  981. err = UserReadDB().Model(&information).Where("bed_number= ? and user_org_id = ? and status = 1 and class = ?", bedid, orgid, scheduletype).Last(&information).Error
  982. return information, err
  983. }
  984. func GetAssessmentAfterDissDataTwo(patientid int64, orgID int64, timenow int64) (models.XtAssessmentAfterDislysis, error) {
  985. dislysis := models.XtAssessmentAfterDislysis{}
  986. err := XTReadDB().Where("patient_id = ? AND user_org_id = ? AND assessment_date = ?", patientid, orgID, timenow).Find(&dislysis).Error
  987. return dislysis, err
  988. }
  989. func GetEquimentIDTwo(bedId int64, orgID int64) (models.DeviceAddmacher, error) {
  990. addmacher := models.DeviceAddmacher{}
  991. err := readUserDb.Model(&addmacher).Where("bed_id = ? AND user_org_id = ? AND status = ?", bedId, orgID, 1).Find(&addmacher).Error
  992. return addmacher, err
  993. }
  994. func GetDisinfectionTwo(equitType int64, enquitType int64, orgID int64) (*models.DevicePlan, error) {
  995. var plan models.DevicePlan
  996. var err error
  997. err = readUserDb.Model(&plan).Where("device_type = ? AND classtime = ? AND user_org_id = ? AND status = 1", equitType, enquitType, orgID).Find(&plan).Error
  998. if err == gorm.ErrRecordNotFound {
  999. return nil, err
  1000. }
  1001. if err != nil {
  1002. return nil, err
  1003. }
  1004. return &plan, nil
  1005. }
  1006. func GetInforTwo(patientid int64, timenow int64, orgid int64, class int64) (*models.DeviceInformation, error) {
  1007. var pre models.DeviceInformation
  1008. var err error
  1009. err = readUserDb.Model(&pre).Where("patient_id = ? AND date = ? AND user_org_id = ? AND class = ? AND status = 1", patientid, timenow, orgid, class).Find(&pre).Error
  1010. if err == gorm.ErrRecordNotFound {
  1011. return nil, err
  1012. }
  1013. if err != nil {
  1014. return nil, err
  1015. }
  1016. return &pre, nil
  1017. }
  1018. func GetPatientOrderInfo(schduledate int64, patientid int64, orgid int64) (models.XtDialysisOrder, error) {
  1019. order := models.XtDialysisOrder{}
  1020. err := XTReadDB().Model(&order).Where("dialysis_date = ? and patient_id = ? and user_org_id = ? and status = 1", schduledate, patientid, orgid).Find(&order).Error
  1021. return order, err
  1022. }
  1023. func DeleteInformation(patient_id int64, schedule_date int64, user_org_id int64) (models.DeviceInformation, error) {
  1024. information := models.DeviceInformation{}
  1025. err := UserWriteDB().Model(&information).Where("patient_id =? and date =? and user_org_id = ? and status=1", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
  1026. return information, err
  1027. }
  1028. func CreateInformationTwo(information *models.DeviceInformation) error {
  1029. err := UserWriteDB().Create(&information).Error
  1030. return err
  1031. }
  1032. func UpdateInformation(information *models.DeviceInformation, scheduledate int64, bedid int64, scheduletype int64) error {
  1033. err := UserWriteDB().Model(&information).Where("date = ? and bed_number = ? and class = ?", scheduledate, bedid, scheduletype).Updates(map[string]interface{}{"long_time": information.LongTime, "disinfec_startime": information.DisinfecStartime, "disinfec_endtime": information.DisinfecEndtime, "bed_number": information.BedNumber, "zone": information.Zone}).Error
  1034. return err
  1035. }
  1036. func DeleteEquit(id int64) (models.DeviceAddmacher, error) {
  1037. addmacher := models.DeviceAddmacher{}
  1038. err := UserWriteDB().Model(&addmacher).Where("id=?", id).Updates(map[string]interface{}{"status": 0}).Error
  1039. return addmacher, err
  1040. }
  1041. func GetDeviceInfomation(orgid int64, scheduledate int64) (information []*models.DeviceInformation, err error) {
  1042. err = UserReadDB().Model(&information).Where("user_org_id = ? and date = ? and status =1", orgid, scheduledate).Find(&information).Error
  1043. return information, err
  1044. }
  1045. func CreateOxygenates(oxygenates *models.XtDeviceOxygenates) error {
  1046. err := UserWriteDB().Create(&oxygenates).Error
  1047. return err
  1048. }
  1049. func CreateHadWater(hadwater *models.XtDeviceHadwater) error {
  1050. err := UserWriteDB().Create(&hadwater).Error
  1051. return err
  1052. }
  1053. func CreateWater(water *models.XtDeviceWater) error {
  1054. err := UserWriteDB().Create(&water).Error
  1055. return err
  1056. }
  1057. func CreateDevicePh(ph *models.XtDevicePh) error {
  1058. err := UserWriteDB().Create(&ph).Error
  1059. return err
  1060. }
  1061. func GetAllDeviceOxygenates(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1062. db := UserReadDB().Table("xt_device_oxygenates as x").Where("x.status = 1")
  1063. table := UserReadDB().Table("sgj_user_admin_role as r")
  1064. fmt.Println("table", table)
  1065. if orgId > 0 {
  1066. db = db.Where("x.user_org_id = ?", orgId)
  1067. }
  1068. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1069. return dialysate, err
  1070. }
  1071. func GetAllHadWater(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1072. db := UserReadDB().Table("xt_device_hadwater as x").Where("x.status = 1")
  1073. table := UserReadDB().Table("sgj_user_admin_role as r")
  1074. fmt.Println("table", table)
  1075. if orgId > 0 {
  1076. db = db.Where("x.user_org_id = ?", orgId)
  1077. }
  1078. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1079. return dialysate, err
  1080. }
  1081. func GetDeviceWater(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1082. db := UserReadDB().Table("xt_device_water as x").Where("x.status = 1")
  1083. table := UserReadDB().Table("sgj_user_admin_role as r")
  1084. fmt.Println("table", table)
  1085. if orgId > 0 {
  1086. db = db.Where("x.user_org_id = ?", orgId)
  1087. }
  1088. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1089. return dialysate, err
  1090. }
  1091. func GetDevicePH(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1092. db := UserReadDB().Table("xt_device_ph as x").Where("x.status = 1")
  1093. table := UserReadDB().Table("sgj_user_admin_role as r")
  1094. fmt.Println("table", table)
  1095. if orgId > 0 {
  1096. db = db.Where("x.user_org_id = ?", orgId)
  1097. }
  1098. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,x.sort,x.pass_examination,x.modifications,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1099. return dialysate, err
  1100. }
  1101. func GetDialysateData(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1102. db := UserReadDB().Table("xt_device_dialysate as x").Where("x.status = 1")
  1103. table := UserReadDB().Table("sgj_user_admin_role as r")
  1104. fmt.Println("table", table)
  1105. if orgId > 0 {
  1106. db = db.Where("x.user_org_id = ?", orgId)
  1107. }
  1108. if bedid > 0 {
  1109. db = db.Where("x.bed_id = ?", bedid)
  1110. }
  1111. if start > 0 {
  1112. db = db.Where("x.sampling_date >= ?", start)
  1113. }
  1114. if end > 0 {
  1115. db = db.Where("x.sampling_date <= ?", end)
  1116. }
  1117. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1118. return dialysate, err
  1119. }
  1120. func GetOxygenates(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1121. db := UserReadDB().Table("xt_device_oxygenates as x").Where("x.status = 1")
  1122. table := UserReadDB().Table("sgj_user_admin_role as r")
  1123. fmt.Println("table", table)
  1124. if orgId > 0 {
  1125. db = db.Where("x.user_org_id = ?", orgId)
  1126. }
  1127. if bedid > 0 {
  1128. db = db.Where("x.bed_id = ?", bedid)
  1129. }
  1130. if start > 0 {
  1131. db = db.Where("x.sampling_date >= ?", start)
  1132. }
  1133. if end > 0 {
  1134. db = db.Where("x.sampling_date <= ?", end)
  1135. }
  1136. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1137. return dialysate, err
  1138. }
  1139. func GetHardWater(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1140. db := UserReadDB().Table("xt_device_hadwater as x").Where("x.status = 1")
  1141. table := UserReadDB().Table("sgj_user_admin_role as r")
  1142. fmt.Println("table", table)
  1143. if orgId > 0 {
  1144. db = db.Where("x.user_org_id = ?", orgId)
  1145. }
  1146. if bedid > 0 {
  1147. db = db.Where("x.bed_id = ?", bedid)
  1148. }
  1149. if start > 0 {
  1150. db = db.Where("x.sampling_date >= ?", start)
  1151. }
  1152. if end > 0 {
  1153. db = db.Where("x.sampling_date <= ?", end)
  1154. }
  1155. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1156. return dialysate, err
  1157. }
  1158. func GetWater(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1159. db := UserReadDB().Table("xt_device_water as x").Where("x.status = 1")
  1160. table := UserReadDB().Table("sgj_user_admin_role as r")
  1161. fmt.Println("table", table)
  1162. if orgId > 0 {
  1163. db = db.Where("x.user_org_id = ?", orgId)
  1164. }
  1165. if bedid > 0 {
  1166. db = db.Where("x.bed_id = ?", bedid)
  1167. }
  1168. if start > 0 {
  1169. db = db.Where("x.sampling_date >= ?", start)
  1170. }
  1171. if end > 0 {
  1172. db = db.Where("x.sampling_date <= ?", end)
  1173. }
  1174. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1175. return dialysate, err
  1176. }
  1177. func GetDevicePh(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1178. db := UserReadDB().Table("xt_device_ph as x").Where("x.status = 1")
  1179. table := UserReadDB().Table("sgj_user_admin_role as r")
  1180. fmt.Println("table", table)
  1181. if orgId > 0 {
  1182. db = db.Where("x.user_org_id = ?", orgId)
  1183. }
  1184. if bedid > 0 {
  1185. db = db.Where("x.bed_id = ?", bedid)
  1186. }
  1187. if start > 0 {
  1188. db = db.Where("x.sampling_date >= ?", start)
  1189. }
  1190. if end > 0 {
  1191. db = db.Where("x.sampling_date <= ?", end)
  1192. }
  1193. err = db.Group("x.id").Select("x.id,x.sampling_date,x.specimenb,x.concentrate_noc,x.concentrateb_nod,x.sampling_locationb,x.detection_unit,x.samplerb,x.reporting_dateb,x.detection_resultb,x.bed_id,x.bed,r.user_name").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.samplerb").Scan(&dialysate).Error
  1194. return dialysate, err
  1195. }
  1196. func GetOxygenatesById(id int64) (models.XtDeviceOxygenates, error) {
  1197. oxygenates := models.XtDeviceOxygenates{}
  1198. err := UserReadDB().Model(&oxygenates).Where("id = ? and status = 1", id).Find(&oxygenates).Error
  1199. return oxygenates, err
  1200. }
  1201. func UpdateOxygenates(id int64, orgid int64, dialysate *models.XtDeviceOxygenates) error {
  1202. err := writeUserDb.Model(&dialysate).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": dialysate.SamplingDate, "specimenb": dialysate.Specimenb, "concentrate_noc": dialysate.ConcentrateNoc, "concentrateb_nod": dialysate.ConcentratebNod, "sampling_locationb": dialysate.SamplingLocationb, "detection_unit": dialysate.DetectionUnit, "samplerb": dialysate.Samplerb, "reporting_dateb": dialysate.ReportingDateb, "detection_resultb": dialysate.DetectionResultb, "sort": dialysate.Sort, "pass_examination": dialysate.PassExamination, "modifications": dialysate.Modifications, "mtime": time.Now().Unix()}).Error
  1203. return err
  1204. }
  1205. func GetHardWaterById(id int64) (models.XtDeviceHadwater, error) {
  1206. hadwater := models.XtDeviceHadwater{}
  1207. err := UserReadDB().Model(&hadwater).Where("id = ? and status = 1", id).Find(&hadwater).Error
  1208. return hadwater, err
  1209. }
  1210. func GetWaterById(id int64) (models.XtDeviceWater, error) {
  1211. water := models.XtDeviceWater{}
  1212. err := UserReadDB().Model(&water).Where("id=? and status =1", id).Find(&water).Error
  1213. return water, err
  1214. }
  1215. func GetDevicePhById(id int64) (models.XtDevicePh, error) {
  1216. devicePh := models.XtDevicePh{}
  1217. err := UserReadDB().Model(&devicePh).Where("id = ? and status =1", id).Find(&devicePh).Error
  1218. return devicePh, err
  1219. }
  1220. func CreateAerialDetection(detection *models.XtAerialDetection) error {
  1221. err := XTWriteDB().Create(&detection).Error
  1222. return err
  1223. }
  1224. func GetAirList(limit int64, page int64, orgid int64) (airlist []*models.XtAerialDetection, total int64, err error) {
  1225. offset := (page - 1) * limit
  1226. err = XTReadDB().Model(&airlist).Where("user_org_id = ? and status =1", orgid).Count(&total).Limit(limit).Offset(offset).Order("created_time desc").Find(&airlist).Error
  1227. return airlist, total, err
  1228. }
  1229. func GetAirDisinfectDetail(id int64) (models.XtAerialDetection, error) {
  1230. detection := models.XtAerialDetection{}
  1231. err := XTReadDB().Model(&detection).Where("id = ? and status = 1", id).Find(&detection).Error
  1232. return detection, err
  1233. }
  1234. func UpdateAeriaDetection(detection *models.XtAerialDetection, id int64) error {
  1235. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"start_time": detection.StartTime, "created_time": detection.CreatedTime, "class": detection.Class, "disinfection_methods": detection.DisinfectionMethods, "disinfection_fluid": detection.DisinfectionFluid, "sort": detection.Sort, "creator": detection.Creator, "detection_time": detection.DetectionTime, "detection_result": detection.DetectionResult, "upload_time": detection.UploadTime, "check_out": detection.CheckOut, "modifications": detection.Modifications}).Error
  1236. return err
  1237. }
  1238. func DeleteAirDisinfect(id int64) error {
  1239. detection := models.XtAerialDetection{}
  1240. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1241. return err
  1242. }
  1243. func SaveBodyDetection(detection *models.XtBodyDetection) error {
  1244. err := XTWriteDB().Create(&detection).Error
  1245. return err
  1246. }
  1247. func GetBodyList(limit int64, page int64, orgid int64) (body []*models.XtBodyDetection, total int64, err error) {
  1248. offset := (page - 1) * limit
  1249. err = XTReadDB().Model(&body).Where("user_org_id = ? and status =1", orgid).Count(&total).Limit(limit).Offset(offset).Order("created_time desc").Find(&body).Error
  1250. return body, total, err
  1251. }
  1252. func GetBodyDisinfectDetail(id int64) (models.XtBodyDetection, error) {
  1253. detection := models.XtBodyDetection{}
  1254. err := XTReadDB().Model(&detection).Where("id = ? and status = 1", id).Find(&detection).Error
  1255. return detection, err
  1256. }
  1257. func UpdateBodyDetection(detection *models.XtBodyDetection, id int64) error {
  1258. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"start_time": detection.StartTime, "created_time": detection.CreatedTime, "class": detection.Class, "disinfection_methods": detection.DisinfectionMethods, "disinfection_fluid": detection.DisinfectionFluid, "sort": detection.Sort, "creator": detection.Creator, "detection_time": detection.DetectionTime, "detection_result": detection.DetectionResult, "upload_time": detection.UploadTime, "check_out": detection.CheckOut, "modifications": detection.Modifications}).Error
  1259. return err
  1260. }
  1261. func DeleteBodyDisInfect(id int64) error {
  1262. detection := models.XtBodyDetection{}
  1263. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1264. return err
  1265. }
  1266. func UpdateHadWater(id int64, orgid int64, hadwater *models.XtDeviceHadwater) error {
  1267. err := writeUserDb.Model(&hadwater).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": hadwater.SamplingDate, "specimenb": hadwater.Specimenb, "concentrate_noc": hadwater.ConcentrateNoc, "concentrateb_nod": hadwater.ConcentratebNod, "sampling_locationb": hadwater.SamplingLocationb, "detection_unit": hadwater.DetectionUnit, "samplerb": hadwater.Samplerb, "reporting_dateb": hadwater.ReportingDateb, "detection_resultb": hadwater.DetectionResultb, "sort": hadwater.Sort, "pass_examination": hadwater.PassExamination, "modifications": hadwater.Modifications, "mtime": time.Now().Unix()}).Error
  1268. return err
  1269. }
  1270. func UpdateDeviceWater(id int64, orgid int64, hadwater *models.XtDeviceWater) error {
  1271. err := writeUserDb.Model(&hadwater).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": hadwater.SamplingDate, "specimenb": hadwater.Specimenb, "concentrate_noc": hadwater.ConcentrateNoc, "concentrateb_nod": hadwater.ConcentratebNod, "sampling_locationb": hadwater.SamplingLocationb, "detection_unit": hadwater.DetectionUnit, "samplerb": hadwater.Samplerb, "reporting_dateb": hadwater.ReportingDateb, "detection_resultb": hadwater.DetectionResultb, "sort": hadwater.Sort, "pass_examination": hadwater.PassExamination, "modifications": hadwater.Modifications, "mtime": time.Now().Unix()}).Error
  1272. return err
  1273. }
  1274. func UpdateDivicePh(id int64, orgid int64, hadwater *models.XtDevicePh) error {
  1275. err := writeUserDb.Model(&hadwater).Where("id=? AND user_org_id = ? AND status = 1", id, orgid).Updates(map[string]interface{}{"sampling_date": hadwater.SamplingDate, "specimenb": hadwater.Specimenb, "concentrate_noc": hadwater.ConcentrateNoc, "concentrateb_nod": hadwater.ConcentratebNod, "sampling_locationb": hadwater.SamplingLocationb, "detection_unit": hadwater.DetectionUnit, "samplerb": hadwater.Samplerb, "reporting_dateb": hadwater.ReportingDateb, "detection_resultb": hadwater.DetectionResultb, "sort": hadwater.Sort, "pass_examination": hadwater.PassExamination, "modifications": hadwater.Modifications, "mtime": time.Now().Unix()}).Error
  1276. return err
  1277. }
  1278. func DeleteOxygenates(id int64) error {
  1279. oxygenates := models.XtDeviceOxygenates{}
  1280. err := writeUserDb.Model(&oxygenates).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
  1281. return err
  1282. }
  1283. func DeleteHadWater(id int64) error {
  1284. hadwater := models.XtDeviceHadwater{}
  1285. err := writeUserDb.Model(&hadwater).Where("id =?", id).Updates(map[string]interface{}{"status": 0}).Error
  1286. return err
  1287. }
  1288. func DeleteWater(id int64) error {
  1289. water := models.XtDeviceWater{}
  1290. err := writeUserDb.Model(&water).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
  1291. return err
  1292. }
  1293. func DeleteDevicePh(id int64) error {
  1294. ph := models.XtDevicePh{}
  1295. err := writeUserDb.Model(&ph).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
  1296. return err
  1297. }
  1298. func CretaDeviceWater(water models.XtDialysisDeviceWater) error {
  1299. err := XTWriteDB().Create(&water).Error
  1300. return err
  1301. }
  1302. func SaveDeviceWater(water models.XtDialysisDeviceWater) error {
  1303. err := XTWriteDB().Save(&water).Error
  1304. return err
  1305. }
  1306. func GetWaterFormList(equitment_id, start_timeunix, endtimeunix, limit, page, orgId int64) (water []*models.XtDialysisDeviceWater, total int64, err error) {
  1307. offset := (page - 1) * limit
  1308. db := XTReadDB().Model(&water).Where("status =1")
  1309. if equitment_id > 0 {
  1310. db = db.Where("equiment_id= ?", equitment_id)
  1311. }
  1312. if start_timeunix > 0 {
  1313. db = db.Where("record_date>=?", start_timeunix)
  1314. }
  1315. if endtimeunix > 0 {
  1316. db = db.Where("record_date<=?", endtimeunix)
  1317. }
  1318. if orgId > 0 {
  1319. db = db.Where("user_org_id = ?", orgId)
  1320. }
  1321. err = db.Count(&total).Limit(limit).Offset(offset).Order("record_date desc").Find(&water).Error
  1322. return water, total, err
  1323. }
  1324. func DelelteDialysisWater(id int64) error {
  1325. err := XTWriteDB().Model(&models.XtDialysisDeviceWater{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  1326. return err
  1327. }
  1328. func GetDialysisWaterDetail(id int64) (models.XtDialysisDeviceWater, error) {
  1329. water := models.XtDialysisDeviceWater{}
  1330. err := XTReadDB().Where("id = ? and status = 1", id).Find(&water).Error
  1331. return water, err
  1332. }
  1333. func DeleteBatchDialysisWater(orgid int64, ids []int64) (err error) {
  1334. if len(ids) == 1 {
  1335. err = XTWriteDB().Model(&models.XtDialysisDeviceWater{}).Where("id=? and user_org_id = ?", ids[0], orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  1336. } else {
  1337. err = XTWriteDB().Model(models.XtDialysisDeviceWater{}).Where("id IN(?) and user_org_id = ?", ids, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  1338. }
  1339. return
  1340. }
  1341. func CreateNewAirDisinfect(disinfect models.XtNewAriDisinfect) error {
  1342. err := XTWriteDB().Create(&disinfect).Error
  1343. return err
  1344. }
  1345. func GetNewAirDisinfectList(limit int64, page int64, start_time int64, end_time int64, user_org_id int64, storey string) (list []*models.XtNewAriDisinfect, total int64, err error) {
  1346. offset := (page - 1) * limit
  1347. db := XTReadDB().Model(&list).Where("status =1")
  1348. if start_time > 0 {
  1349. db = db.Where("record_date >= ?", start_time)
  1350. }
  1351. if end_time > 0 {
  1352. db = db.Where("record_date <= ?", end_time)
  1353. }
  1354. if user_org_id > 0 {
  1355. db = db.Where("user_org_id = ?", user_org_id)
  1356. }
  1357. if len(storey) > 0 {
  1358. db = db.Where("storey =?", storey)
  1359. }
  1360. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1361. return list, total, err
  1362. }
  1363. func GetNewAirWayDisinfectList(limit int64, page int64, start_time int64, end_time int64, user_org_id int64) (list []*models.XtNewAriDisinfectWay, total int64, err error) {
  1364. offset := (page - 1) * limit
  1365. db := XTReadDB().Model(&list).Where("status =1")
  1366. if start_time > 0 {
  1367. db = db.Where("record_date >= ?", start_time)
  1368. }
  1369. if end_time > 0 {
  1370. db = db.Where("record_date <= ?", end_time)
  1371. }
  1372. if user_org_id > 0 {
  1373. db = db.Where("user_org_id = ?", user_org_id)
  1374. }
  1375. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1376. return list, total, err
  1377. }
  1378. func GetNewAirDisinfectByIdList(id int64) (models.XtNewAriDisinfect, error) {
  1379. disinfect := models.XtNewAriDisinfect{}
  1380. err := XTReadDB().Where("id = ? and status= 1", id).Find(&disinfect).Error
  1381. return disinfect, err
  1382. }
  1383. func SaveNewAriDisinfect(disinfect models.XtNewAriDisinfect) error {
  1384. err := XTWriteDB().Save(&disinfect).Error
  1385. return err
  1386. }
  1387. func DeleteNewAirDisInfect(id int64) error {
  1388. err := XTWriteDB().Model(&models.XtNewAriDisinfect{}).Where("id= ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1389. return err
  1390. }
  1391. func CreateObjectDisInfect(disinfect models.XtNewObjectDisinfect) error {
  1392. err := XTWriteDB().Create(&disinfect).Error
  1393. return err
  1394. }
  1395. func CreateNewAirWayDisinfectOne(disinfect models.XtNewAriDisinfectWay) error {
  1396. err := XTWriteDB().Create(&disinfect).Error
  1397. return err
  1398. }
  1399. func CreateNewAirWayDisinfect(disinfect models.XtNewAriDisinfectWay) error {
  1400. err := XTWriteDB().Save(&disinfect).Error
  1401. return err
  1402. }
  1403. func GetObjectTableDisinfectList(limit int64, page int64, start_time int64, end_time int64, user_org_id int64, storey string) (list []*models.XtNewObjectDisinfect, total int64, err error) {
  1404. offset := (page - 1) * limit
  1405. db := XTReadDB().Model(&list).Where("status =1")
  1406. if start_time > 0 {
  1407. db = db.Where("record_date >= ?", start_time)
  1408. }
  1409. if end_time > 0 {
  1410. db = db.Where("record_date <= ?", end_time)
  1411. }
  1412. if user_org_id > 0 {
  1413. db = db.Where("user_org_id = ?", user_org_id)
  1414. }
  1415. if len(storey) > 0 {
  1416. db = db.Where("storey =?", storey)
  1417. }
  1418. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1419. return list, total, err
  1420. }
  1421. func GetObjectAbleDisInfectWayList(limit int64, page int64, start_time int64, end_time int64, user_org_id int64) (list []*models.XtNewObjectDisinfectWay, total int64, err error) {
  1422. offset := (page - 1) * limit
  1423. db := XTReadDB().Model(&list).Where("status =1")
  1424. if start_time > 0 {
  1425. db = db.Where("record_date >= ?", start_time)
  1426. }
  1427. if end_time > 0 {
  1428. db = db.Where("record_date <= ?", end_time)
  1429. }
  1430. if user_org_id > 0 {
  1431. db = db.Where("user_org_id = ?", user_org_id)
  1432. }
  1433. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1434. return list, total, err
  1435. }
  1436. func GetObjectTableDisinfectByList(id int64) (models.XtNewObjectDisinfect, error) {
  1437. disinfect := models.XtNewObjectDisinfect{}
  1438. err := XTReadDB().Where("id=? and status =1", id).Find(&disinfect).Error
  1439. return disinfect, err
  1440. }
  1441. func UpdateObjectTableDisinfect(disinfect models.XtNewObjectDisinfect) error {
  1442. err := XTWriteDB().Save(&disinfect).Error
  1443. return err
  1444. }
  1445. func DeleteObjectTableDisinfect(id int64) error {
  1446. err := XTWriteDB().Model(&models.XtNewObjectDisinfect{}).Where("id=? and status= 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1447. return err
  1448. }
  1449. func GetAirDisInfectionLongTime(user_org_id int64, storey string) (list []*models.XtNewAriDisinfect, err error) {
  1450. db := XTReadDB().Model(&list).Where("status =1")
  1451. if user_org_id > 0 {
  1452. db = db.Where("user_org_id =?", user_org_id)
  1453. }
  1454. if len(storey) > 0 {
  1455. db = db.Where("storey =?", storey)
  1456. }
  1457. err = db.Order("id desc").First(&list).Error
  1458. return
  1459. }
  1460. func GetAirDisinfectWayLongTime(user_org_id int64, department string) (list []*models.XtNewAriDisinfectWay, err error) {
  1461. err = XTReadDB().Where("user_org_id = ? and status = 1 and department= ?", user_org_id, department).Order("id desc").First(&list).Error
  1462. return
  1463. }
  1464. func GetObjectDisInfectionLongTime(user_org_id int64) (list []*models.XtNewObjectDisinfect, err error) {
  1465. err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&list).Error
  1466. return
  1467. }
  1468. func GetDialysisOrderPatient(org_id int64) (order []*models.XtDialysisOrder, err error) {
  1469. err = XTReadDB().Where("user_org_id = ? and dialysis_date>=? and dialysis_date<=? and status =1", org_id, 1669824000, 1672416000).Find(&order).Error
  1470. return order, err
  1471. }
  1472. func CreateObjectRegistration(registration models.XtDialysisRegistration) error {
  1473. err := XTWriteDB().Create(&registration).Error
  1474. return err
  1475. }
  1476. func GetRegistrationDisinfectList(limit int64, page int64, start_time int64, end_time int64, user_org_id int64) (list []*models.XtDialysisRegistration, total int64, err error) {
  1477. offset := (page - 1) * limit
  1478. db := XTReadDB().Model(&list).Where("status =1")
  1479. if start_time > 0 {
  1480. db = db.Where("record_date >= ?", start_time)
  1481. }
  1482. if end_time > 0 {
  1483. db = db.Where("record_date <= ?", end_time)
  1484. }
  1485. if user_org_id > 0 {
  1486. db = db.Where("user_org_id = ?", user_org_id)
  1487. }
  1488. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&list).Error
  1489. return list, total, err
  1490. }
  1491. func GetObjectRegistrationByIdList(id int64) (models.XtDialysisRegistration, error) {
  1492. registration := models.XtDialysisRegistration{}
  1493. err := XTReadDB().Where("id = ? and status=1", id).Find(&registration).Error
  1494. return registration, err
  1495. }
  1496. func UpdateObjectRegistration(registration models.XtDialysisRegistration) error {
  1497. err := XTWriteDB().Save(&registration).Error
  1498. return err
  1499. }
  1500. func DeleteObjectTregistration(id int64) error {
  1501. err := XTWriteDB().Model(&models.XtDialysisRegistration{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1502. return err
  1503. }
  1504. func GetRegistGoodInforList(user_org_id int64) (good []*models.GoodInformationFourty, err error) {
  1505. err = XTReadDB().Where("org_id = ? and status =1", user_org_id).Find(&good).Error
  1506. return good, err
  1507. }
  1508. func GetRegistNumber(sys_record_time int64, good_id int64, user_org_id int64) (infor []*models.WarehouseOutInfoNight, err error) {
  1509. err = XTReadDB().Where("sys_record_time = ? and good_id = ? and org_id = ? and status =1 and is_sys=1", sys_record_time, good_id, user_org_id).Find(&infor).Error
  1510. return infor, err
  1511. }
  1512. func GetAirDisInfectSetting(orgid int64) (models.XtDeviceAirSetting, error) {
  1513. setting := models.XtDeviceAirSetting{}
  1514. err := XTReadDB().Where("user_org_id =? and status=1", orgid).Find(&setting).Error
  1515. return setting, err
  1516. }
  1517. func SaveSetAirDisInfect(setting models.XtDeviceAirSetting) error {
  1518. err := XTWriteDB().Save(&setting).Error
  1519. return err
  1520. }
  1521. func GetNewAirWayDisinfectByIdList(id int64) (models.XtNewAriDisinfectWay, error) {
  1522. disinfectWay := models.XtNewAriDisinfectWay{}
  1523. err := XTReadDB().Where("id = ? and status =1", id).Find(&disinfectWay).Error
  1524. return disinfectWay, err
  1525. }
  1526. func DeleteNewAirWayDisinfect(id int64) error {
  1527. err := XTWriteDB().Model(models.XtNewAriDisinfectWay{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  1528. return err
  1529. }
  1530. func GetObjectTableDisinfect(user_org_id int64) (models.XtDeviceObjctSet, error) {
  1531. objctSet := models.XtDeviceObjctSet{}
  1532. err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&objctSet).Error
  1533. return objctSet, err
  1534. }
  1535. func SaveSetObjectDisinfect(objectSet models.XtDeviceObjctSet) error {
  1536. err := XTWriteDB().Save(&objectSet).Error
  1537. return err
  1538. }
  1539. func CreateNewObjectWayDisInfect(way models.XtNewObjectDisinfectWay) error {
  1540. err := XTWriteDB().Create(&way).Error
  1541. return err
  1542. }
  1543. func GetObjectAbledDisInfectWayById(id int64) (models.XtNewObjectDisinfectWay, error) {
  1544. objway := models.XtNewObjectDisinfectWay{}
  1545. err := XTReadDB().Where("id=? and status=1", id).Find(&objway).Error
  1546. return objway, err
  1547. }
  1548. func SaveobjectDisinfect(way models.XtNewObjectDisinfectWay) error {
  1549. err := XTWriteDB().Save(&way).Error
  1550. return err
  1551. }
  1552. func DeleteObjectAbleWayDisinfect(id int64) error {
  1553. err := XTWriteDB().Model(models.XtNewObjectDisinfectWay{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  1554. return err
  1555. }