manage_service.go 74KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strings"
  7. "time"
  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()}).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) (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) 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. }
  155. }
  156. thisSQL += strings.Join(insertParams, ",")
  157. err = xt.Exec(thisSQL, insertData...).Error
  158. if err != nil {
  159. xt.Rollback()
  160. return
  161. }
  162. }
  163. xt.Commit()
  164. return
  165. }
  166. func GetAllPlan(orgid int64) (plan []*models.DevicePlans, err error) {
  167. //db := readUserDb.Table("xt_device_plan as p").Where("p.status = 1")
  168. // //table := readUserDb.Table("xt_device_addmacher as e")
  169. // //fmt.Println("table", table)
  170. // //if orgid > 0 {
  171. // // db = db.Where("p.user_org_id = ?", orgid)
  172. // //}
  173. // //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
  174. // //return plan, err
  175. 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 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
  176. return plan, err
  177. }
  178. func GetDeviceType(unitype string) (models.DeviceMode, error) {
  179. equimentname := models.DeviceMode{}
  180. err := UserReadDB().Where("id = ?", unitype).Find(&equimentname).Error
  181. return equimentname, err
  182. }
  183. func GetAllPlanDetail(id int64, orgid int64) (plan []*models.DevicePlans, err error) {
  184. //db := readUserDb.Table("xt_device_plan as p").Where("p.status = 1")
  185. //table := readUserDb.Table("xt_device_addmacher as e")
  186. //fmt.Println("table", table)
  187. //if orgid > 0 {
  188. // db = db.Where("p.user_org_id = ?", orgid)
  189. //}
  190. //if id > 0 {
  191. // db = db.Where("p.equiment_id = ?", id)
  192. //}
  193. //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
  194. //return plan, err
  195. 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 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
  196. return plan, err
  197. }
  198. func DeletePlan(id int64) (err error) {
  199. err = UserWriteDB().Model(&models.DevicePlan{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  200. return
  201. }
  202. func DeletePlans(orgid int64, ids []int64) (err error) {
  203. if len(ids) == 1 {
  204. 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
  205. } else {
  206. 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
  207. }
  208. return
  209. }
  210. func GetPlanDetailById(id int64, orgid int64) (models.DevicePlanss, error) {
  211. plans := models.DevicePlanss{}
  212. db := UserReadDB().Table("xt_device_plan as x").Where("x.status = 1")
  213. table := UserReadDB().Table("xt_device_addmacher as a").Where("a.status = 1")
  214. fmt.Println("table", table)
  215. if id > 0 {
  216. db = db.Where("x.id = ?", id)
  217. }
  218. if orgid > 0 {
  219. db = db.Where("x.user_org_id = ?", orgid)
  220. }
  221. 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
  222. return plans, err
  223. }
  224. func UpdatePlanInfo(id int64, orgid int64, plan models.DevicePlan) error {
  225. 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
  226. return err
  227. }
  228. func GetComprehensive(zone int64, number int64, devicetype int64, year int64, starttime int64, endtime int64, orgid int64, device_mode int64) (macher []*models.DeviceAddmachers, err error) {
  229. db := readUserDb.Table("xt_device_addmacher as a").Where("a.status = 1")
  230. table := XTReadDB().Table("xt_device_zone as x")
  231. fmt.Println(table)
  232. if orgid > 0 {
  233. db = db.Where("a.user_org_id = ?", orgid)
  234. }
  235. if zone > 0 {
  236. db = db.Where("a.zone_id = ?", zone)
  237. }
  238. if number > 0 {
  239. db = db.Where("a.bed_id = ?", number)
  240. }
  241. if devicetype > 0 {
  242. db = db.Where("a.device_type = ?", devicetype)
  243. }
  244. if device_mode > 0 {
  245. db = db.Where("a.unit_type = ?", device_mode)
  246. }
  247. if year == 1 {
  248. db = db.Where("a.user_year >= 0 AND a.user_year <= 1")
  249. }
  250. if year == 2 {
  251. db = db.Where("a.user_year >=1 AND a.user_year <= 3")
  252. }
  253. if year == 3 {
  254. db = db.Where("a.user_year >=3 AND a.user_year <= 10")
  255. }
  256. if year == 4 {
  257. db = db.Where("a.user_year >=10")
  258. }
  259. if starttime > 0 {
  260. db = db.Where("a.ctime >= ?", starttime)
  261. }
  262. if endtime > 0 {
  263. db = db.Where("a.ctime <= ?", endtime)
  264. }
  265. 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
  266. return macher, err
  267. }
  268. func GetBedId(id int64) (models.DeviceAddmacher, error) {
  269. addmacher := models.DeviceAddmacher{}
  270. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&addmacher).Error
  271. return addmacher, err
  272. }
  273. func GetPatientInfo(bedid int64, nowtime int64, orgid int64) (schedules []*models.Schedules, err error) {
  274. db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
  275. table := XTReadDB().Table("xt_patients as x")
  276. fmt.Println("table", table)
  277. if bedid > 0 {
  278. db = db.Where("s.bed_id = ?", bedid)
  279. }
  280. if nowtime > 0 {
  281. db = db.Where("s.schedule_date = ?", nowtime)
  282. }
  283. if orgid > 0 {
  284. db = db.Where("s.user_org_id = ?", orgid)
  285. }
  286. 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
  287. return schedules, err
  288. }
  289. func GetPatient(bedid int64, orgid int64, classid int64, nowtime int64) (schedules models.Schedules, err error) {
  290. db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
  291. table := XTReadDB().Table("xt_patients as x")
  292. fmt.Println("table", table)
  293. 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
  294. return schedules, err
  295. }
  296. func GetPartitionName(id int64) (models.DeviceZone, error) {
  297. zone := models.DeviceZone{}
  298. err := XTReadDB().Where("id = ? AND status = 1", id).Find(&zone).Error
  299. return zone, err
  300. }
  301. func GetPatientNumber(id int64) (models.DeviceNumber, error) {
  302. number := models.DeviceNumber{}
  303. err := XTReadDB().Where("id = ? AND status = 1", id).Find(&number).Error
  304. return number, err
  305. }
  306. func GetDialysisOrder(time int64, patientid int64, orgid int64) (models.DialysisOrder, error) {
  307. order := models.DialysisOrder{}
  308. err := XTReadDB().Where("dialysis_date = ? AND patient_id = ? AND user_org_id = ? ", time, patientid, orgid).Find(&order).Error
  309. return order, err
  310. }
  311. func GetDialysisWay(time int64, patientid int64, orgid int64) (models.DialysisPrescription, error) {
  312. prescription := models.DialysisPrescription{}
  313. err := XTReadDB().Where("record_date = ? AND patient_id = ? AND user_org_id = ?", time, patientid, orgid).Find(&prescription).Error
  314. return prescription, err
  315. }
  316. func GetDialysisTime(time int64, patientid int64, orgid int64) (models.AssessmentAfterDislysis, error) {
  317. dislysis := models.AssessmentAfterDislysis{}
  318. err := XTReadDB().Where("assessment_date = ? AND patient_id = ? AND user_org_id = ?", time, patientid, orgid).Find(&dislysis).Error
  319. return dislysis, err
  320. }
  321. func GetAllOrganization(orgid int64, appid int64) (approle []*models.App_Role, err error) {
  322. err = UserReadDB().Where("org_id = ? AND app_id = ? AND status = 1", orgid, appid).Find(&approle).Error
  323. return approle, err
  324. }
  325. func CreateUserInformation(information *models.DeviceInformation) error {
  326. err := writeUserDb.Create(&information).Error
  327. return err
  328. }
  329. func GetRegisterInfo(orgid int64, id int64, timenow int64) (models.DeviceInformations, error) {
  330. //information := models.DeviceInformations{}
  331. var information models.DeviceInformations
  332. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  333. table := XTReadDB().Table("xt_patients as p")
  334. fmt.Println("table", table)
  335. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  336. fmt.Print("dbs", dbs)
  337. 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
  338. return information, err
  339. }
  340. func GetSignName(id int64, orgid int64, appid int64) (models.App_Role, error) {
  341. role := models.App_Role{}
  342. err := UserReadDB().Model(&role).Where("admin_user_id = ? AND org_id = ? AND app_id = ?", id, orgid, appid).Find(&role).Error
  343. return role, err
  344. }
  345. func GetInformationData(limit int64, page int64, orgId int64) (information []*models.DeviceInformations, total int64, err error) {
  346. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  347. table := XTReadDB().Table("xt_patients as p")
  348. fmt.Println("table", table)
  349. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  350. fmt.Println("dbs", dbs)
  351. offset := (page - 1) * limit
  352. if orgId > 0 {
  353. db = db.Where("x.user_org_id = ?", orgId)
  354. }
  355. 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
  356. if err != nil {
  357. return
  358. }
  359. return
  360. }
  361. func GetOrgName(orgid int64) (models.Org, error) {
  362. org := models.Org{}
  363. err := UserReadDB().Where("id= ? AND status = 1", orgid).Find(&org).Error
  364. return org, err
  365. }
  366. func GetMyMobile(id int64) (models.SgjUserAdmin, error) {
  367. admin := models.SgjUserAdmin{}
  368. err := UserReadDB().Model(&admin).Where("id=? and status = 1", id).Find(&admin).Error
  369. return admin, err
  370. }
  371. func CreateCulture(culture *models.DeviceCulture) error {
  372. err := writeUserDb.Create(&culture).Error
  373. return err
  374. }
  375. func CreateDialysate(dialysate *models.DeviceDialysate) error {
  376. err := writeUserDb.Create(&dialysate).Error
  377. return err
  378. }
  379. func CreateIon(ion *models.DeviceIon) error {
  380. err := writeUserDb.Create(&ion).Error
  381. return err
  382. }
  383. func GetAllCulture(orgId int64) (cultures []*models.DeviceCultures, err error) {
  384. db := UserReadDB().Table("xt_device_culture as x").Where("x.status = 1")
  385. table := UserReadDB().Table("sgj_user_admin_role as r")
  386. fmt.Println("table", table)
  387. if orgId > 0 {
  388. db = db.Where("x.user_org_id = ?", orgId)
  389. }
  390. 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
  391. return cultures, err
  392. }
  393. func GetAllDialysate(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  394. db := UserReadDB().Table("xt_device_dialysate as x").Where("x.status = 1")
  395. table := UserReadDB().Table("sgj_user_admin_role as r")
  396. fmt.Println("table", table)
  397. if orgId > 0 {
  398. db = db.Where("x.user_org_id = ?", orgId)
  399. }
  400. 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
  401. return dialysate, err
  402. }
  403. func GetAllDeviceIon(orgId int64) (ions []*models.DeviceIons, err error) {
  404. db := UserReadDB().Table("xt_device_ion as x").Where("x.status = 1")
  405. table := UserReadDB().Table("sgj_user_admin_role as r")
  406. fmt.Println("table", table)
  407. if orgId > 0 {
  408. db = db.Where("x.user_org_id = ?", orgId)
  409. }
  410. 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
  411. return ions, err
  412. }
  413. func GetCultureById(id int64) (models.DeviceCulture, error) {
  414. culture := models.DeviceCulture{}
  415. err := UserReadDB().Model(&culture).Where("id=? AND status = 1", id).Find(&culture).Error
  416. return culture, err
  417. }
  418. func GetSampler(id int64) (models.App_Role, error) {
  419. role := models.App_Role{}
  420. err := UserReadDB().Model(&role).Where("id= ? AND status =1", id).Find(&role).Error
  421. return role, err
  422. }
  423. func UpdateCulture(id int64, orgid int64, culture *models.DeviceCulture) error {
  424. 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
  425. return err
  426. }
  427. func DeleteCultrues(id int64) (err error) {
  428. err = UserWriteDB().Model(models.DeviceCulture{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  429. return
  430. }
  431. func DeleteCultrue(orgid int64, ids []int64) (err error) {
  432. if len(ids) == 1 {
  433. 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
  434. } else {
  435. 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
  436. }
  437. return
  438. }
  439. func GetDialystate(id int64) (models.DeviceDialysate, error) {
  440. dialysate := models.DeviceDialysate{}
  441. err := readUserDb.Where("id= ? AND status = 1", id).Find(&dialysate).Error
  442. return dialysate, err
  443. }
  444. func Updatedialystate(id int64, orgid int64, dialysate *models.DeviceDialysate) error {
  445. 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
  446. return err
  447. }
  448. func DeleteDialystates(id int64) (err error) {
  449. err = UserWriteDB().Model(&models.DeviceDialysate{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  450. return
  451. }
  452. func DeleteDialystate(orgid int64, ids []int64) (err error) {
  453. if len(ids) == 1 {
  454. 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
  455. } else {
  456. 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
  457. }
  458. return
  459. }
  460. func GetIon(id int64) (models.DeviceIon, error) {
  461. ion := models.DeviceIon{}
  462. err := UserReadDB().Model(&ion).Where("id = ? AND status = 1", id).Find(&ion).Error
  463. return ion, err
  464. }
  465. func UpdateIon(id int64, orgid int64, ion *models.DeviceIon) error {
  466. 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
  467. return err
  468. }
  469. func DeleteIons(id int64) (err error) {
  470. err = UserWriteDB().Model(&models.DeviceIon{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  471. return
  472. }
  473. func DeleteIon(orgid int64, ids []int64) (err error) {
  474. if len(ids) == 1 {
  475. 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
  476. } else {
  477. 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
  478. }
  479. return
  480. }
  481. func GetCultureData(bedid int64, start int64, end int64, orgId int64) (cultures []*models.DeviceCultures, err error) {
  482. db := UserReadDB().Table("xt_device_culture as x").Where("x.status = 1")
  483. table := UserReadDB().Table("sgj_user_admin_role as r")
  484. fmt.Println("table", table)
  485. if orgId > 0 {
  486. db = db.Where("x.user_org_id = ?", orgId)
  487. }
  488. if bedid > 0 {
  489. db = db.Where("x.bed_id = ?", bedid)
  490. }
  491. if start > 0 {
  492. db = db.Where("x.speling_date >= ?", start)
  493. }
  494. if end > 0 {
  495. db = db.Where("x.speling_date <= ?", end)
  496. }
  497. 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
  498. return cultures, err
  499. }
  500. func GetDeviceIonData(bedid int64, start int64, end int64, orgId int64) (ions []*models.DeviceIons, err error) {
  501. db := UserReadDB().Table("xt_device_ion as x").Where("x.status = 1")
  502. table := UserReadDB().Table("sgj_user_admin_role as r")
  503. fmt.Println("table", table)
  504. if orgId > 0 {
  505. db = db.Where("x.user_org_id = ?", orgId)
  506. }
  507. if bedid > 0 {
  508. db = db.Where("x.bed_id = ?", bedid)
  509. }
  510. if start > 0 {
  511. db = db.Where("x.sampling_date >= ?", start)
  512. }
  513. if end > 0 {
  514. db = db.Where("x.sampling_date <= ?", end)
  515. }
  516. 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
  517. return ions, err
  518. }
  519. func CreateRepair(repair *models.DeviceRepair) error {
  520. err = writeUserDb.Create(&repair).Error
  521. return err
  522. }
  523. func GetAllRepair(orgid int64, limit int64, page int64) (repair []*models.DeviceRepairs, total int64, err error) {
  524. db := UserReadDB().Table("xt_device_repair as r").Where("r.status = ?", 1)
  525. table := XTReadDB().Table("xt_device_number as x")
  526. offset := (page - 1) * limit
  527. fmt.Print("table", table)
  528. if orgid > 0 {
  529. db = db.Where("r.user_org_id = ?", orgid)
  530. }
  531. 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
  532. // err = UserReadDB().Where("user_org_id = ? AND status = 1", orgid).Find(&repair).Error
  533. return repair, total, err
  534. }
  535. func EditRepair(id int64) (models.DeviceRepair, error) {
  536. repair := models.DeviceRepair{}
  537. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&repair).Error
  538. return repair, err
  539. }
  540. func UpdateRepair(id int64, orgid int64, repair *models.DeviceRepair) error {
  541. 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()}).Error
  542. return err
  543. }
  544. func DeleteRepairs(id int64) (err error) {
  545. err = UserWriteDB().Model(models.DeviceRepair{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  546. return
  547. }
  548. func DeleteRepair(orgid int64, ids []int64) (err error) {
  549. if len(ids) == 1 {
  550. 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
  551. } else {
  552. 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
  553. }
  554. return
  555. }
  556. func GetRepair(bedid int64, start int64, end int64, orgid int64) (repair []*models.DeviceRepairs, err error) {
  557. db := UserReadDB().Table("xt_device_repair as r").Where("r.status = 1")
  558. sb := UserReadDB().Table("xt_device_addmacher as x")
  559. fmt.Print("sb", sb)
  560. if orgid > 0 {
  561. db = db.Where("r.user_org_id = ?", orgid)
  562. }
  563. if bedid > 0 {
  564. db = db.Where("r.bed_id = ?", bedid)
  565. }
  566. if start > 0 {
  567. db = db.Where("r.guarantee_date >= ?", start)
  568. }
  569. if end > 0 {
  570. db = db.Where("r.guarantee_date <= ?", end)
  571. }
  572. //err = db.Model(&repair).Find(&repair).Error
  573. 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
  574. return repair, err
  575. }
  576. func GetUserInformation(id int64) (models.DeviceInformation, error) {
  577. information := models.DeviceInformation{}
  578. err := UserReadDB().Where("id = ? AND status = 1", id).Find(&information).Error
  579. return information, err
  580. }
  581. func GetPatientInfoMation(patieintid int64) (models.Patients, error) {
  582. patients := models.Patients{}
  583. err := XTReadDB().Where("id = ? AND status = 1", patieintid).Find(&patients).Error
  584. return patients, err
  585. }
  586. func DeleteUserLogin(id int64) (err error) {
  587. err = UserWriteDB().Model(&models.DeviceInformation{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  588. return
  589. }
  590. func DeleteForm(orgid int64, ids []int64) (err error) {
  591. if len(ids) == 1 {
  592. 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
  593. } else {
  594. 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
  595. }
  596. return
  597. }
  598. func GetLastInformationdata(eid int64, startdate int64, orgid int64) (models.DeviceInformation, error) {
  599. information := models.DeviceInformation{}
  600. err := UserReadDB().Model(&information).Where("equiment_id = ? and date = ? and user_org_id = ? and status = 1", eid, startdate, orgid).Last(&information).Error
  601. return information, err
  602. }
  603. func UpdateAddMacherBedID(id int64, orgid int64, addmacher *models.DeviceAddmacher) error {
  604. 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
  605. return err
  606. }
  607. func UpdatedZoneID(bedid int64, orgid int64, number *models.DeviceNumber) error {
  608. err := XTWriteDB().Model(&number).Where("id=? and org_id = ?", bedid, orgid).Update(map[string]interface{}{"zone_id": number.ZoneID, "mtime": time.Now().Unix()}).Error
  609. return err
  610. }
  611. func UpadateForm(id int64, orgid int64, infor *models.DeviceInformation) error {
  612. 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,
  613. "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
  614. return err
  615. }
  616. func QueryInfo(bed int64, start int64, end int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
  617. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  618. table := XTReadDB().Table("xt_patients as p")
  619. fmt.Println("table", table)
  620. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  621. fmt.Println("dbs", dbs)
  622. if orgId > 0 {
  623. db = db.Where("x.user_org_id = ?", orgId)
  624. }
  625. //if zone > 0 {
  626. // db = db.Where("x.zone = ?", zone)
  627. //}
  628. if bed > 0 {
  629. db = db.Where("x.bed_number = ?", bed)
  630. }
  631. if start > 0 {
  632. db = db.Where("x.date >= ?", start)
  633. }
  634. if end > 0 {
  635. db = db.Where("x.date <= ?", end)
  636. }
  637. offset := (page - 1) * limit
  638. 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.ctime desc").Offset(offset).Limit(limit).Scan(&infor).Error
  639. if err != nil {
  640. return
  641. }
  642. return
  643. }
  644. func GetPatientID(bedid int64, orgId int64, nowtime int64) (dialysis []*models.DialysisOrder, err error) {
  645. err = XTReadDB().Model(&dialysis).Where("bed_id = ? AND user_org_id = ? AND dialysis_date = ?", bedid, orgId, nowtime).Find(&dialysis).Error
  646. return dialysis, err
  647. }
  648. //func GetAllEquitType(orgId int64) (addmacher []*models.DeviceAddmacher, err error) {
  649. //
  650. // db := UserReadDB().Table("xt_device_addmacher as a").Where("a.status = 1")
  651. // if orgId > 0 {
  652. // db = db.Where("a.user_org_id = ?", orgId)
  653. // }
  654. // 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
  655. // return addmacher, err
  656. //}
  657. func GetAllEquitType(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
  658. //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
  659. //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
  660. //err = UserReadDB().Where("user_org_id = ? and status =1", orgid).Find(&equiment).Error
  661. 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
  662. return equiment, err
  663. }
  664. func GetAllEquitName(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
  665. 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
  666. return equiment, err
  667. }
  668. func GetUserForm(id int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
  669. if orgId == 10060 {
  670. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  671. table := XTReadDB().Table("xt_patients as p")
  672. fmt.Println("table", table)
  673. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  674. fmt.Println("dbs", dbs)
  675. offset := (page - 1) * limit
  676. if id > 0 {
  677. db = db.Where("x.equiment_id = ?", id)
  678. }
  679. if orgId > 0 {
  680. db = db.Where("x.user_org_id = ?", orgId)
  681. }
  682. 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").Offset(offset).Limit(limit).Order("x.date asc").Scan(&infor).Error
  683. if err != nil {
  684. return
  685. }
  686. return
  687. } else {
  688. db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  689. table := XTReadDB().Table("xt_patients as p")
  690. fmt.Println("table", table)
  691. dbs := UserReadDB().Table("sgj_user_admin_role as r")
  692. fmt.Println("dbs", dbs)
  693. offset := (page - 1) * limit
  694. if id > 0 {
  695. db = db.Where("x.equiment_id = ?", id)
  696. }
  697. if orgId > 0 {
  698. db = db.Where("x.user_org_id = ?", orgId)
  699. }
  700. 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").Offset(offset).Limit(limit).Order("x.date desc").Scan(&infor).Error
  701. if err != nil {
  702. return
  703. }
  704. return
  705. }
  706. }
  707. func GetBedNumber(id int64, orgid int64) (models.DeviceAddmacher, error) {
  708. addmacher := models.DeviceAddmacher{}
  709. err := UserReadDB().Where("id= ? AND user_org_id = ?", id, orgid).Find(&addmacher).Error
  710. return addmacher, err
  711. }
  712. func GetNumbers(id int64, orgid int64) (models.DeviceNumber, error) {
  713. number := models.DeviceNumber{}
  714. err := XTReadDB().Where("id = ? AND org_id = ?", id, orgid).Find(&number).Error
  715. return number, err
  716. }
  717. func GetZoneForm(id int64) (models.DeviceAddmacher, error) {
  718. macher := models.DeviceAddmacher{}
  719. err := UserReadDB().Where("id=? AND status = 1", id).Find(&macher).Error
  720. return macher, err
  721. }
  722. func GetBedForm(id int64) (number []*models.DeviceNumber, err error) {
  723. err = XTReadDB().Where("zone_id = ? AND status = 1", id).Find(&number).Error
  724. return number, err
  725. }
  726. func GetTotalCount(orgid int64) (repair []*models.DeviceRepair, total int64, err error) {
  727. err = UserReadDB().Model(&repair).Where("user_org_id = ? and status = 1", orgid).Find(&repair).Count(&total).Error
  728. return repair, total, err
  729. }
  730. func GetTotalNumber(id int64, orgid int64) (total int64, err error) {
  731. var device models.DeviceInformation
  732. err = UserReadDB().Model(&device).Where("equiment_id = ? AND user_org_id = ? AND status = 1", id, orgid).Find(&device).Count(&total).Error
  733. return total, err
  734. }
  735. func GetTimeWarning(equitid int64, orgId int64) (models.DeviceInformation, error) {
  736. //fmt.Print("equitid是什么码字--------------------------------------------------------------------",equitid)
  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 GetAllpatientThirty(orgid int64) (patients []*models.PatientsThirty, err error) {
  756. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patients).Error
  757. return patients, err
  758. }
  759. func GetInformation(eid int64, startdate int64, orgid int64, classtype int64) (*models.DeviceInformation, error) {
  760. var information models.DeviceInformation
  761. var err error
  762. 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
  763. fmt.Print("", err)
  764. if err == gorm.ErrRecordNotFound {
  765. return nil, err
  766. }
  767. if err != nil {
  768. return nil, err
  769. }
  770. return &information, nil
  771. }
  772. func ChangeBed(id int64, org int64) (number []*models.DeviceNumber, err error) {
  773. err = XTReadDB().Model(&number).Where("zone_id = ? AND status = 1 AND org_id = ? ", id, org).Find(&number).Error
  774. return number, err
  775. }
  776. func GetPatientDetail(id int64, orgid int64) (models.Patients, error) {
  777. patients := models.Patients{}
  778. err := XTReadDB().Where("id=? and user_org_id = ?", id, orgid).Find(&patients).Error
  779. return patients, err
  780. }
  781. func GetRemanderData(orgid int64) (remander models.DeviceRemander, err error) {
  782. err = UserReadDB().Model(&models.DeviceRemander{}).Where("user_org_id = ? and status = 1", orgid).Find(&remander).Error
  783. return
  784. }
  785. func CreateRemander(remander *models.DeviceRemander) (err error) {
  786. err = UserWriteDB().Create(&remander).Error
  787. return
  788. }
  789. func UpdateRemander(remander *models.DeviceRemander) (err error) {
  790. err = UserWriteDB().Save(&remander).Error
  791. return
  792. }
  793. func GetMode(mode string, orgid int64) (*models.DeviceMode, error) {
  794. var information models.DeviceMode
  795. var err error
  796. err = UserReadDB().Model(&information).Where("device_mode = ? and user_org_id = ? and status = ?", mode, orgid, 1).Find(&information).Error
  797. fmt.Print("", err)
  798. if err == gorm.ErrRecordNotFound {
  799. return nil, err
  800. }
  801. if err != nil {
  802. return nil, err
  803. }
  804. return &information, nil
  805. }
  806. func SaveMode(mode *models.DeviceMode) (err error) {
  807. err = UserWriteDB().Save(&mode).Error
  808. return
  809. }
  810. func GetAllMode(orgid int64) (mode []*models.DeviceMode, err error) {
  811. err = UserReadDB().Where("user_org_id = ? and status = ?", orgid, 1).Find(&mode).Error
  812. return mode, err
  813. }
  814. func GetModeById(id int64) (models.DeviceMode, error) {
  815. mode := models.DeviceMode{}
  816. err := UserReadDB().Where("id = ?", id).Find(&mode).Error
  817. return mode, err
  818. }
  819. func UpdateMode(id int64, mode models.DeviceMode) error {
  820. err := UserWriteDB().Model(&mode).Where("id=?", id).Update(map[string]interface{}{"device_mode": mode.DeviceMode, "mtime": time.Now().Unix()}).Error
  821. return err
  822. }
  823. func QueryDeviceMode(id int64, orgid int64) (*models.DeviceAddmacher, error) {
  824. addmacher := models.DeviceAddmacher{}
  825. var err error
  826. err = UserReadDB().Model(&addmacher).Where("unit_type = ? and user_org_id = ?", id, orgid).Find(&addmacher).Error
  827. if err == gorm.ErrRecordNotFound {
  828. return nil, err
  829. }
  830. if err != nil {
  831. return nil, err
  832. }
  833. return &addmacher, nil
  834. }
  835. func DeleteMode(id int64) error {
  836. err := UserWriteDB().Model(models.DeviceMode{}).Where("id=?", id).Update(map[string]interface{}{"status": 0}).Error
  837. return err
  838. }
  839. func SelectChange(id int64, orgid int64) (number []*models.DeviceNumber, err error) {
  840. //err = XTReadDB().Where("zone_id = ? and org_id = ? and status = ?", id, orgid, 1).Find(&number).Error
  841. db := XTReadDB().Table("xt_device_number as x").Where("x.status = ?", 1)
  842. err = db.Select("org_id,number,group_id,zone_id as id").Where("zone_id = ? and org_id = ?", id, orgid).Find(&number).Error
  843. return number, err
  844. }
  845. func SelectBed(id int64, orgid int64) (models.DeviceNumber, error) {
  846. number := models.DeviceNumber{}
  847. err := XTReadDB().Where("id = ? and org_id = ?", id, orgid).Find(&number).Error
  848. return number, err
  849. }
  850. func GetTimeData(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  851. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  852. //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
  853. day := time.Now().Day()
  854. oldMonth := day - 30
  855. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  856. 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
  857. return information, err
  858. }
  859. func GetTimeTwo(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  860. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  861. //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
  862. day := time.Now().Day()
  863. oldMonth := day - 30
  864. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  865. 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
  866. return information, err
  867. }
  868. func GetTimeThree(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
  869. //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
  870. //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
  871. day := time.Now().Day()
  872. oldMonth := day - 30
  873. t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
  874. 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
  875. return information, err
  876. }
  877. func DeleteImages(id int64) error {
  878. repair := models.DeviceRepair{}
  879. err := UserWriteDB().Model(&repair).Where("id=?", id).Update(map[string]interface{}{"images": "", "image_name": ""}).Error
  880. return err
  881. }
  882. func GetActivtyCreator(creator int64) (*models.KyActivityTable, error) {
  883. table := models.KyActivityTable{}
  884. err := UserReadDB().Model(&table).Where("admin_user_id = ? and status =1", creator).Find(&table).Error
  885. if err == gorm.ErrRecordNotFound {
  886. return nil, err
  887. }
  888. if err != nil {
  889. return nil, err
  890. }
  891. return &table, nil
  892. }
  893. func CreateTable(table *models.KyActivityTable) error {
  894. err := UserWriteDB().Model(&table).Create(&table).Error
  895. return err
  896. }
  897. func GetAdminUserRole(id int64, orgid int64) (models.SgjUserAdminRole, error) {
  898. role := models.SgjUserAdminRole{}
  899. err := UserReadDB().Where("admin_user_id = ? and org_id = ? and status = 1", id, orgid).Find(&role).Error
  900. return role, err
  901. }
  902. func GetRolePosition(id int64) (models.SgjUserRole, error) {
  903. role := models.SgjUserRole{}
  904. err := UserReadDB().Where("id = ? And status =1", id).Find(&role).Error
  905. return role, err
  906. }
  907. func GetMobile(id int64) (models.SgjUserAdmin, error) {
  908. admin := models.SgjUserAdmin{}
  909. err := UserReadDB().Where("id=? and status = 1", id).Find(&admin).Error
  910. return admin, err
  911. }
  912. func GetOrgs(id int64) (roles []*models.SgjUserAdminRole, err error) {
  913. db := UserReadDB().Table("sgj_user_admin_role as s").Where("s.status = 1")
  914. 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
  915. return roles, err
  916. }
  917. func GetUserMachTotalCount(orgid int64) (vm []*models.VmDeviceInformation, err error) {
  918. 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
  919. return vm, err
  920. }
  921. func GetUserTotalByMacher(id int64) (models.DeviceAddmacher, error) {
  922. addmacher := models.DeviceAddmacher{}
  923. err := UserReadDB().Model(&addmacher).Where("id=? and status = 1", id).Find(&addmacher).Error
  924. return addmacher, err
  925. }
  926. func GetUserTotalCount(orgid int64, bedid int64) (vm []*models.VmDeviceInformation, err error) {
  927. 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
  928. return vm, err
  929. }
  930. func GetUserTotal(orgid int64, id int64) (models.DeviceAddmacher, error) {
  931. addmacher := models.DeviceAddmacher{}
  932. err := UserReadDB().Model(&addmacher).Where("user_org_id = ? and bed_id = ? and status = 1", orgid, id).Find(&addmacher).Error
  933. return addmacher, err
  934. }
  935. func GetDisInfectionTime(orgid int64, unitype int64, scheduletype int64, scheduleweek int64) (*models.DevicePlan, error) {
  936. plan := models.DevicePlan{}
  937. 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
  938. if err == gorm.ErrRecordNotFound {
  939. return nil, err
  940. }
  941. if err != nil {
  942. return nil, err
  943. }
  944. return &plan, nil
  945. }
  946. func GetUnitType(bedid int64, orgid int64) (models.DeviceAddmacher, error) {
  947. addmacher := models.DeviceAddmacher{}
  948. err := UserReadDB().Model(&addmacher).Where("bed_id = ? and user_org_id = ? and status = 1", bedid, orgid).Find(&addmacher).Error
  949. return addmacher, err
  950. }
  951. func GetLaseDeviceInfomation(orgid int64, bedid int64, date int64, scheduletype int64) (*models.DeviceInformation, error) {
  952. information := models.DeviceInformation{}
  953. 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
  954. if err == gorm.ErrRecordNotFound {
  955. return nil, err
  956. }
  957. if err != nil {
  958. return nil, err
  959. }
  960. return &information, nil
  961. }
  962. func GetLaseDeviceInfomationTwo(orgid int64, bedid int64, scheduletype int64) (models.DeviceInformation, error) {
  963. information := models.DeviceInformation{}
  964. err = UserReadDB().Model(&information).Where("bed_number= ? and user_org_id = ? and status = 1 and class = ?", bedid, orgid, scheduletype).Last(&information).Error
  965. return information, err
  966. }
  967. func GetAssessmentAfterDissDataTwo(patientid int64, orgID int64, timenow int64) (models.XtAssessmentAfterDislysis, error) {
  968. dislysis := models.XtAssessmentAfterDislysis{}
  969. err := XTReadDB().Where("patient_id = ? AND user_org_id = ? AND assessment_date = ?", patientid, orgID, timenow).Find(&dislysis).Error
  970. return dislysis, err
  971. }
  972. func GetEquimentIDTwo(bedId int64, orgID int64) (models.DeviceAddmacher, error) {
  973. addmacher := models.DeviceAddmacher{}
  974. err := readUserDb.Model(&addmacher).Where("bed_id = ? AND user_org_id = ? AND status = ?", bedId, orgID, 1).Find(&addmacher).Error
  975. return addmacher, err
  976. }
  977. func GetDisinfectionTwo(equitType int64, enquitType int64, orgID int64) (*models.DevicePlan, error) {
  978. var plan models.DevicePlan
  979. var err error
  980. err = readUserDb.Model(&plan).Where("device_type = ? AND classtime = ? AND user_org_id = ? AND status = 1", equitType, enquitType, orgID).Find(&plan).Error
  981. if err == gorm.ErrRecordNotFound {
  982. return nil, err
  983. }
  984. if err != nil {
  985. return nil, err
  986. }
  987. return &plan, nil
  988. }
  989. func GetInforTwo(patientid int64, timenow int64, orgid int64, class int64) (*models.DeviceInformation, error) {
  990. var pre models.DeviceInformation
  991. var err error
  992. 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
  993. if err == gorm.ErrRecordNotFound {
  994. return nil, err
  995. }
  996. if err != nil {
  997. return nil, err
  998. }
  999. return &pre, nil
  1000. }
  1001. func GetPatientOrderInfo(schduledate int64, patientid int64, orgid int64) (models.XtDialysisOrder, error) {
  1002. order := models.XtDialysisOrder{}
  1003. err := XTReadDB().Model(&order).Where("dialysis_date = ? and patient_id = ? and user_org_id = ? and status = 1", schduledate, patientid, orgid).Find(&order).Error
  1004. return order, err
  1005. }
  1006. func CreateInformationTwo(information *models.DeviceInformation) error {
  1007. err := UserWriteDB().Create(&information).Error
  1008. return err
  1009. }
  1010. func UpdateInformation(information *models.DeviceInformation, scheduledate int64, bedid int64, scheduletype int64) error {
  1011. 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}).Error
  1012. return err
  1013. }
  1014. func DeleteEquit(id int64) (models.DeviceAddmacher, error) {
  1015. addmacher := models.DeviceAddmacher{}
  1016. err := UserWriteDB().Model(&addmacher).Where("id=?", id).Updates(map[string]interface{}{"status": 0}).Error
  1017. return addmacher, err
  1018. }
  1019. func GetDeviceInfomation(orgid int64, scheduledate int64) (information []*models.DeviceInformation, err error) {
  1020. err = UserReadDB().Model(&information).Where("user_org_id = ? and date = ? and status =1", orgid, scheduledate).Find(&information).Error
  1021. return information, err
  1022. }
  1023. func CreateOxygenates(oxygenates *models.XtDeviceOxygenates) error {
  1024. err := UserWriteDB().Create(&oxygenates).Error
  1025. return err
  1026. }
  1027. func CreateHadWater(hadwater *models.XtDeviceHadwater) error {
  1028. err := UserWriteDB().Create(&hadwater).Error
  1029. return err
  1030. }
  1031. func CreateWater(water *models.XtDeviceWater) error {
  1032. err := UserWriteDB().Create(&water).Error
  1033. return err
  1034. }
  1035. func CreateDevicePh(ph *models.XtDevicePh) error {
  1036. err := UserWriteDB().Create(&ph).Error
  1037. return err
  1038. }
  1039. func GetAllDeviceOxygenates(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1040. db := UserReadDB().Table("xt_device_oxygenates as x").Where("x.status = 1")
  1041. table := UserReadDB().Table("sgj_user_admin_role as r")
  1042. fmt.Println("table", table)
  1043. if orgId > 0 {
  1044. db = db.Where("x.user_org_id = ?", orgId)
  1045. }
  1046. 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
  1047. return dialysate, err
  1048. }
  1049. func GetAllHadWater(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1050. db := UserReadDB().Table("xt_device_hadwater as x").Where("x.status = 1")
  1051. table := UserReadDB().Table("sgj_user_admin_role as r")
  1052. fmt.Println("table", table)
  1053. if orgId > 0 {
  1054. db = db.Where("x.user_org_id = ?", orgId)
  1055. }
  1056. 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
  1057. return dialysate, err
  1058. }
  1059. func GetDeviceWater(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1060. db := UserReadDB().Table("xt_device_water as x").Where("x.status = 1")
  1061. table := UserReadDB().Table("sgj_user_admin_role as r")
  1062. fmt.Println("table", table)
  1063. if orgId > 0 {
  1064. db = db.Where("x.user_org_id = ?", orgId)
  1065. }
  1066. 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
  1067. return dialysate, err
  1068. }
  1069. func GetDevicePH(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1070. db := UserReadDB().Table("xt_device_ph as x").Where("x.status = 1")
  1071. table := UserReadDB().Table("sgj_user_admin_role as r")
  1072. fmt.Println("table", table)
  1073. if orgId > 0 {
  1074. db = db.Where("x.user_org_id = ?", orgId)
  1075. }
  1076. 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
  1077. return dialysate, err
  1078. }
  1079. func GetDialysateData(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1080. db := UserReadDB().Table("xt_device_dialysate as x").Where("x.status = 1")
  1081. table := UserReadDB().Table("sgj_user_admin_role as r")
  1082. fmt.Println("table", table)
  1083. if orgId > 0 {
  1084. db = db.Where("x.user_org_id = ?", orgId)
  1085. }
  1086. if bedid > 0 {
  1087. db = db.Where("x.bed_id = ?", bedid)
  1088. }
  1089. if start > 0 {
  1090. db = db.Where("x.sampling_date >= ?", start)
  1091. }
  1092. if end > 0 {
  1093. db = db.Where("x.sampling_date <= ?", end)
  1094. }
  1095. 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
  1096. return dialysate, err
  1097. }
  1098. func GetOxygenates(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1099. db := UserReadDB().Table("xt_device_oxygenates as x").Where("x.status = 1")
  1100. table := UserReadDB().Table("sgj_user_admin_role as r")
  1101. fmt.Println("table", table)
  1102. if orgId > 0 {
  1103. db = db.Where("x.user_org_id = ?", orgId)
  1104. }
  1105. if bedid > 0 {
  1106. db = db.Where("x.bed_id = ?", bedid)
  1107. }
  1108. if start > 0 {
  1109. db = db.Where("x.sampling_date >= ?", start)
  1110. }
  1111. if end > 0 {
  1112. db = db.Where("x.sampling_date <= ?", end)
  1113. }
  1114. 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
  1115. return dialysate, err
  1116. }
  1117. func GetHardWater(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1118. db := UserReadDB().Table("xt_device_hadwater as x").Where("x.status = 1")
  1119. table := UserReadDB().Table("sgj_user_admin_role as r")
  1120. fmt.Println("table", table)
  1121. if orgId > 0 {
  1122. db = db.Where("x.user_org_id = ?", orgId)
  1123. }
  1124. if bedid > 0 {
  1125. db = db.Where("x.bed_id = ?", bedid)
  1126. }
  1127. if start > 0 {
  1128. db = db.Where("x.sampling_date >= ?", start)
  1129. }
  1130. if end > 0 {
  1131. db = db.Where("x.sampling_date <= ?", end)
  1132. }
  1133. 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
  1134. return dialysate, err
  1135. }
  1136. func GetWater(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1137. db := UserReadDB().Table("xt_device_water as x").Where("x.status = 1")
  1138. table := UserReadDB().Table("sgj_user_admin_role as r")
  1139. fmt.Println("table", table)
  1140. if orgId > 0 {
  1141. db = db.Where("x.user_org_id = ?", orgId)
  1142. }
  1143. if bedid > 0 {
  1144. db = db.Where("x.bed_id = ?", bedid)
  1145. }
  1146. if start > 0 {
  1147. db = db.Where("x.sampling_date >= ?", start)
  1148. }
  1149. if end > 0 {
  1150. db = db.Where("x.sampling_date <= ?", end)
  1151. }
  1152. 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
  1153. return dialysate, err
  1154. }
  1155. func GetDevicePh(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
  1156. db := UserReadDB().Table("xt_device_ph as x").Where("x.status = 1")
  1157. table := UserReadDB().Table("sgj_user_admin_role as r")
  1158. fmt.Println("table", table)
  1159. if orgId > 0 {
  1160. db = db.Where("x.user_org_id = ?", orgId)
  1161. }
  1162. if bedid > 0 {
  1163. db = db.Where("x.bed_id = ?", bedid)
  1164. }
  1165. if start > 0 {
  1166. db = db.Where("x.sampling_date >= ?", start)
  1167. }
  1168. if end > 0 {
  1169. db = db.Where("x.sampling_date <= ?", end)
  1170. }
  1171. 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
  1172. return dialysate, err
  1173. }
  1174. func GetOxygenatesById(id int64) (models.XtDeviceOxygenates, error) {
  1175. oxygenates := models.XtDeviceOxygenates{}
  1176. err := UserReadDB().Model(&oxygenates).Where("id = ? and status = 1", id).Find(&oxygenates).Error
  1177. return oxygenates, err
  1178. }
  1179. func UpdateOxygenates(id int64, orgid int64, dialysate *models.XtDeviceOxygenates) error {
  1180. 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
  1181. return err
  1182. }
  1183. func GetHardWaterById(id int64) (models.XtDeviceHadwater, error) {
  1184. hadwater := models.XtDeviceHadwater{}
  1185. err := UserReadDB().Model(&hadwater).Where("id = ? and status = 1", id).Find(&hadwater).Error
  1186. return hadwater, err
  1187. }
  1188. func GetWaterById(id int64) (models.XtDeviceWater, error) {
  1189. water := models.XtDeviceWater{}
  1190. err := UserReadDB().Model(&water).Where("id=? and status =1", id).Find(&water).Error
  1191. return water, err
  1192. }
  1193. func GetDevicePhById(id int64) (models.XtDevicePh, error) {
  1194. devicePh := models.XtDevicePh{}
  1195. err := UserReadDB().Model(&devicePh).Where("id = ? and status =1", id).Find(&devicePh).Error
  1196. return devicePh, err
  1197. }
  1198. func CreateAerialDetection(detection *models.XtAerialDetection) error {
  1199. err := XTWriteDB().Create(&detection).Error
  1200. return err
  1201. }
  1202. func GetAirList(limit int64, page int64, orgid int64) (airlist []*models.XtAerialDetection, total int64, err error) {
  1203. offset := (page - 1) * limit
  1204. 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
  1205. return airlist, total, err
  1206. }
  1207. func GetAirDisinfectDetail(id int64) (models.XtAerialDetection, error) {
  1208. detection := models.XtAerialDetection{}
  1209. err := XTReadDB().Model(&detection).Where("id = ? and status = 1", id).Find(&detection).Error
  1210. return detection, err
  1211. }
  1212. func UpdateAeriaDetection(detection *models.XtAerialDetection, id int64) error {
  1213. 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
  1214. return err
  1215. }
  1216. func DeleteAirDisinfect(id int64) error {
  1217. detection := models.XtAerialDetection{}
  1218. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1219. return err
  1220. }
  1221. func SaveBodyDetection(detection *models.XtBodyDetection) error {
  1222. err := XTWriteDB().Create(&detection).Error
  1223. return err
  1224. }
  1225. func GetBodyList(limit int64, page int64, orgid int64) (body []*models.XtBodyDetection, total int64, err error) {
  1226. offset := (page - 1) * limit
  1227. 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
  1228. return body, total, err
  1229. }
  1230. func GetBodyDisinfectDetail(id int64) (models.XtBodyDetection, error) {
  1231. detection := models.XtBodyDetection{}
  1232. err := XTReadDB().Model(&detection).Where("id = ? and status = 1", id).Find(&detection).Error
  1233. return detection, err
  1234. }
  1235. func UpdateBodyDetection(detection *models.XtBodyDetection, id int64) error {
  1236. 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
  1237. return err
  1238. }
  1239. func DeleteBodyDisInfect(id int64) error {
  1240. detection := models.XtBodyDetection{}
  1241. err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  1242. return err
  1243. }
  1244. func UpdateHadWater(id int64, orgid int64, hadwater *models.XtDeviceHadwater) error {
  1245. 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
  1246. return err
  1247. }
  1248. func UpdateDeviceWater(id int64, orgid int64, hadwater *models.XtDeviceWater) error {
  1249. 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
  1250. return err
  1251. }
  1252. func UpdateDivicePh(id int64, orgid int64, hadwater *models.XtDevicePh) error {
  1253. 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
  1254. return err
  1255. }
  1256. func DeleteOxygenates(id int64) error {
  1257. oxygenates := models.XtDeviceOxygenates{}
  1258. err := writeUserDb.Model(&oxygenates).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
  1259. return err
  1260. }
  1261. func DeleteHadWater(id int64) error {
  1262. hadwater := models.XtDeviceHadwater{}
  1263. err := writeUserDb.Model(&hadwater).Where("id =?", id).Updates(map[string]interface{}{"status": 0}).Error
  1264. return err
  1265. }
  1266. func DeleteWater(id int64) error {
  1267. water := models.XtDeviceWater{}
  1268. err := writeUserDb.Model(&water).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
  1269. return err
  1270. }
  1271. func DeleteDevicePh(id int64) error {
  1272. ph := models.XtDevicePh{}
  1273. err := writeUserDb.Model(&ph).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
  1274. return err
  1275. }