1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954 |
- package service
-
- import (
- "XT_New/models"
- "fmt"
- "github.com/jinzhu/gorm"
- "strings"
- "time"
- )
-
- func GetEquitmentName(unit_type string, orgid int64) (*models.DeviceEquimentname, error) {
- var equimentname models.DeviceEquimentname
- var err error
- err = UserReadDB().Model(&equimentname).Where("equitment_name = ? and user_org_id = ? and status = 1", unit_type, orgid).Find(&equimentname).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &equimentname, nil
- }
-
- func CreateEquimentName(equimentname models.DeviceEquimentname) error {
-
- //err := XTWriteDB().Create(&equimentname).Error
- //return err
- err := writeUserDb.Create(&equimentname).Error
- return err
- }
-
- func GetEquitmentByBedID(bedid int64, orgid int64) (models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- err := UserReadDB().Model(&addmacher).Where("bed_id = ? and user_org_id = ? and status = 1", bedid, orgid).First(&addmacher).Error
- return addmacher, err
- }
-
- func CreateMacher(machers *models.DeviceAddmacher) error {
-
- //err := writeDb.Create(&machers).Error
- //xt := writeDb.Begin()
- // //fmt.Println("hhhhhhhh",xt)
- // //err := xt.Model(&models.DeviceAddmacher{}).Create(machers).Error
- // //fmt.Println("err",err)
- // //if err !=nil{
- // // xt.Rollback()
- // //}
- // //xt.Commit()
- // //return err
- err := writeUserDb.Create(&machers).Error
- return err
- }
-
- func UpdateMachine(id int64, orgid int64, addmacher *models.DeviceAddmacher) error {
-
- 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
-
- return err
-
- }
-
- func GetZoneName(zoneid int64, orgid int64) (models.DeviceZone, error) {
- zone := models.DeviceZone{}
- err := XTReadDB().Where("id = ? AND org_id = ?", zoneid, orgid).Find(&zone).Error
- return zone, err
- }
-
- func UpdateTreatMode(id int64, orgid int64, treatmodes []int64) (err error) {
- utx := XTWriteDB().Begin()
- 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
- fmt.Println("错误是什么", err)
- if err != nil {
- utx.Rollback()
- return
- }
- if len(treatmodes) > 0 {
- thisSQL := "INSERT INTO xt_device_treatmentmode(machine_id,treate_mode,status,ctime,user_org_id) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, treatmode := range treatmodes {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, id)
- insertData = append(insertData, treatmode)
- insertData = append(insertData, 1)
- insertData = append(insertData, time.Now().Unix())
- insertData = append(insertData, orgid)
- }
- thisSQL += strings.Join(insertParams, ",")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- return
- }
-
- func GetAllEquimentName(orgid int64) (equit []*models.DeviceEquimentname, err error) {
-
- err = readUserDb.Model(&equit).Where("user_org_id = ? AND status = ?", orgid, 1).Group("equitment_name").Find(&equit).Error
-
- return equit, err
- }
-
- func GetAllDeviceMode(orgid int64) (device []*models.DeviceMode, err error) {
-
- err = readUserDb.Model(&device).Where("user_org_id = ? and status = 1", orgid).Find(&device).Error
- return device, err
- }
-
- func GetBed(equitid int64) (models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- err := UserReadDB().Where("id=? AND status = ?", equitid, 1).Find(&addmacher).Error
- return addmacher, err
- }
-
- func QueryPlan(orgid int64, devicetype int64, ids []int64, classids []int64, equitid int64) (*models.DevicePlan, error) {
-
- var pre models.DevicePlan
- var err error
- //for _, id := range ids {
- // for _, classids := range classids {
- // 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
- // }
- //}
- //if err == gorm.ErrRecordNotFound {
- // return nil, err
- //}
- //if err != nil {
- // return nil, err
- //}
- //return &pre, nil
-
- if len(ids) == 1 && len(classids) == 1 {
- 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
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- } else {
- 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
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- }
-
- return &pre, nil
- }
-
- 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) {
- xt := UserWriteDB().Begin()
- if len(ids) > 0 {
- 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 "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, id := range ids {
- for _, classids := range classids {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, deviceType)
- insertData = append(insertData, disinfecTime)
- insertData = append(insertData, id)
- insertData = append(insertData, classids)
- insertData = append(insertData, way)
- insertData = append(insertData, machinedisinfectant)
- insertData = append(insertData, disinfectantway)
- insertData = append(insertData, disinfectant)
- insertData = append(insertData, 1)
- insertData = append(insertData, time.Now().Unix())
- insertData = append(insertData, orgid)
- insertData = append(insertData, equimentid)
- insertData = append(insertData, bedid)
- insertData = append(insertData, bed_way)
- }
- }
- thisSQL += strings.Join(insertParams, ",")
- err = xt.Exec(thisSQL, insertData...).Error
- if err != nil {
- xt.Rollback()
- return
- }
- }
- xt.Commit()
- return
- }
-
- func GetAllPlan(orgid int64) (plan []*models.DevicePlans, err error) {
-
- //db := readUserDb.Table("xt_device_plan as p").Where("p.status = 1")
- // //table := readUserDb.Table("xt_device_addmacher as e")
- // //fmt.Println("table", table)
- // //if orgid > 0 {
- // // db = db.Where("p.user_org_id = ?", orgid)
- // //}
- // //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
- // //return plan, err
-
- 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
- return plan, err
- }
-
- func GetDeviceType(unitype string) (models.DeviceMode, error) {
- equimentname := models.DeviceMode{}
- err := UserReadDB().Where("id = ?", unitype).Find(&equimentname).Error
- return equimentname, err
- }
-
- func GetAllPlanDetail(id int64, orgid int64) (plan []*models.DevicePlans, err error) {
- //db := readUserDb.Table("xt_device_plan as p").Where("p.status = 1")
- //table := readUserDb.Table("xt_device_addmacher as e")
- //fmt.Println("table", table)
- //if orgid > 0 {
- // db = db.Where("p.user_org_id = ?", orgid)
- //}
- //if id > 0 {
- // db = db.Where("p.equiment_id = ?", id)
- //}
- //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
- //return plan, err
- 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
- return plan, err
- }
-
- func DeletePlan(id int64) (err error) {
-
- err = UserWriteDB().Model(&models.DevicePlan{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func DeletePlans(orgid int64, ids []int64) (err error) {
-
- if len(ids) == 1 {
- 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
- } else {
- 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
- }
-
- return
- }
-
- func GetPlanDetailById(id int64, orgid int64) (models.DevicePlanss, error) {
- plans := models.DevicePlanss{}
- db := UserReadDB().Table("xt_device_plan as x").Where("x.status = 1")
- table := UserReadDB().Table("xt_device_addmacher as a").Where("a.status = 1")
- fmt.Println("table", table)
- if id > 0 {
- db = db.Where("x.id = ?", id)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- 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
- return plans, err
- }
-
- func UpdatePlanInfo(id int64, orgid int64, plan models.DevicePlan) error {
-
- 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
- return err
- }
-
- func GetComprehensive(zone int64, number int64, devicetype int64, year int64, starttime int64, endtime int64, orgid int64, device_mode int64) (macher []*models.DeviceAddmachers, err error) {
- db := readUserDb.Table("xt_device_addmacher as a").Where("a.status = 1")
- table := XTReadDB().Table("xt_device_zone as x")
- fmt.Println(table)
- if orgid > 0 {
- db = db.Where("a.user_org_id = ?", orgid)
- }
- if zone > 0 {
- db = db.Where("a.zone_id = ?", zone)
- }
- if number > 0 {
- db = db.Where("a.bed_id = ?", number)
- }
- if devicetype > 0 {
- db = db.Where("a.device_type = ?", devicetype)
- }
- if device_mode > 0 {
- db = db.Where("a.unit_type = ?", device_mode)
- }
- if year == 1 {
- db = db.Where("a.user_year >= 0 AND a.user_year <= 1")
- }
- if year == 2 {
- db = db.Where("a.user_year >=1 AND a.user_year <= 3")
- }
- if year == 3 {
- db = db.Where("a.user_year >=3 AND a.user_year <= 10")
- }
- if year == 4 {
- db = db.Where("a.user_year >=10")
- }
-
- if starttime > 0 {
- db = db.Where("a.ctime >= ?", starttime)
- }
- if endtime > 0 {
- db = db.Where("a.ctime <= ?", endtime)
- }
- 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
- return macher, err
- }
-
- func GetBedId(id int64) (models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- err := UserReadDB().Where("id = ? AND status = 1", id).Find(&addmacher).Error
- return addmacher, err
- }
-
- func GetPatientInfo(bedid int64, nowtime int64, orgid int64) (schedules []*models.Schedules, err error) {
-
- db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
-
- table := XTReadDB().Table("xt_patients as x")
-
- fmt.Println("table", table)
- if bedid > 0 {
- db = db.Where("s.bed_id = ?", bedid)
- }
- if nowtime > 0 {
- db = db.Where("s.schedule_date = ?", nowtime)
- }
- if orgid > 0 {
- db = db.Where("s.user_org_id = ?", orgid)
- }
-
- 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
- return schedules, err
-
- }
-
- func GetPatient(bedid int64, orgid int64, classid int64, nowtime int64) (schedules models.Schedules, err error) {
- db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
- table := XTReadDB().Table("xt_patients as x")
- fmt.Println("table", table)
- 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
- return schedules, err
- }
-
- func GetPartitionName(id int64) (models.DeviceZone, error) {
- zone := models.DeviceZone{}
- err := XTReadDB().Where("id = ? AND status = 1", id).Find(&zone).Error
-
- return zone, err
- }
-
- func GetPatientNumber(id int64) (models.DeviceNumber, error) {
- number := models.DeviceNumber{}
- err := XTReadDB().Where("id = ? AND status = 1", id).Find(&number).Error
- return number, err
- }
-
- func GetDialysisOrder(time int64, patientid int64, orgid int64) (models.DialysisOrder, error) {
- order := models.DialysisOrder{}
- err := XTReadDB().Where("dialysis_date = ? AND patient_id = ? AND user_org_id = ? ", time, patientid, orgid).Find(&order).Error
- return order, err
- }
-
- func GetDialysisWay(time int64, patientid int64, orgid int64) (models.DialysisPrescription, error) {
- prescription := models.DialysisPrescription{}
- err := XTReadDB().Where("record_date = ? AND patient_id = ? AND user_org_id = ?", time, patientid, orgid).Find(&prescription).Error
- return prescription, err
- }
-
- func GetDialysisTime(time int64, patientid int64, orgid int64) (models.AssessmentAfterDislysis, error) {
- dislysis := models.AssessmentAfterDislysis{}
- err := XTReadDB().Where("assessment_date = ? AND patient_id = ? AND user_org_id = ?", time, patientid, orgid).Find(&dislysis).Error
- return dislysis, err
- }
-
- func GetAllOrganization(orgid int64, appid int64) (approle []*models.App_Role, err error) {
- err = UserReadDB().Where("org_id = ? AND app_id = ?", orgid, appid).Find(&approle).Error
- return approle, err
- }
-
- func CreateUserInformation(information *models.DeviceInformation) error {
-
- err := writeUserDb.Create(&information).Error
- return err
- }
-
- func GetRegisterInfo(orgid int64, id int64, timenow int64) (models.DeviceInformations, error) {
- //information := models.DeviceInformations{}
- var information models.DeviceInformations
- db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_patients as p")
- fmt.Println("table", table)
- dbs := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Print("dbs", dbs)
- 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
- return information, err
- }
-
- func GetSignName(id int64, orgid int64, appid int64) (models.App_Role, error) {
- role := models.App_Role{}
- err := UserReadDB().Model(&role).Where("admin_user_id = ? AND org_id = ? AND app_id = ?", id, orgid, appid).Find(&role).Error
- return role, err
- }
-
- func GetInformationData(limit int64, page int64, orgId int64) (information []*models.DeviceInformations, total int64, err error) {
- db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_patients as p")
- fmt.Println("table", table)
- dbs := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("dbs", dbs)
- offset := (page - 1) * limit
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
- if err != nil {
-
- return
- }
- return
- }
-
- func GetOrgName(orgid int64) (models.Org, error) {
- org := models.Org{}
- err := UserReadDB().Where("id= ? AND status = 1", orgid).Find(&org).Error
- return org, err
- }
-
- func GetMyMobile(id int64) (models.SgjUserAdmin, error) {
- admin := models.SgjUserAdmin{}
- err := UserReadDB().Model(&admin).Where("id=? and status = 1", id).Find(&admin).Error
- return admin, err
- }
-
- func CreateCulture(culture *models.DeviceCulture) error {
-
- err := writeUserDb.Create(&culture).Error
- return err
- }
-
- func CreateDialysate(dialysate *models.DeviceDialysate) error {
-
- err := writeUserDb.Create(&dialysate).Error
- return err
- }
-
- func CreateIon(ion *models.DeviceIon) error {
-
- err := writeUserDb.Create(&ion).Error
- return err
- }
-
- func GetAllCulture(orgId int64) (cultures []*models.DeviceCultures, err error) {
-
- db := UserReadDB().Table("xt_device_culture as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
- return cultures, err
- }
-
- func GetAllDialysate(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_dialysate as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
-
- return dialysate, err
- }
-
- func GetAllDeviceIon(orgId int64) (ions []*models.DeviceIons, err error) {
- db := UserReadDB().Table("xt_device_ion as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
- return ions, err
- }
-
- func GetCultureById(id int64) (models.DeviceCulture, error) {
- culture := models.DeviceCulture{}
- err := UserReadDB().Model(&culture).Where("id=? AND status = 1", id).Find(&culture).Error
- return culture, err
- }
-
- func GetSampler(id int64) (models.App_Role, error) {
- role := models.App_Role{}
- err := UserReadDB().Model(&role).Where("id= ? AND status =1", id).Find(&role).Error
- return role, err
- }
-
- func UpdateCulture(id int64, orgid int64, culture *models.DeviceCulture) error {
-
- 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
- return err
- }
-
- func DeleteCultrues(id int64) (err error) {
-
- err = UserWriteDB().Model(models.DeviceCulture{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func DeleteCultrue(orgid int64, ids []int64) (err error) {
- if len(ids) == 1 {
- 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
- } else {
- 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
- }
-
- return
- }
-
- func GetDialystate(id int64) (models.DeviceDialysate, error) {
-
- dialysate := models.DeviceDialysate{}
- err := readUserDb.Where("id= ? AND status = 1", id).Find(&dialysate).Error
- return dialysate, err
- }
-
- func Updatedialystate(id int64, orgid int64, dialysate *models.DeviceDialysate) error {
-
- 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
- return err
- }
-
- func DeleteDialystates(id int64) (err error) {
-
- err = UserWriteDB().Model(&models.DeviceDialysate{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
-
- }
-
- func DeleteDialystate(orgid int64, ids []int64) (err error) {
- if len(ids) == 1 {
- 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
- } else {
- 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
- }
-
- return
- }
-
- func GetIon(id int64) (models.DeviceIon, error) {
-
- ion := models.DeviceIon{}
- err := UserReadDB().Model(&ion).Where("id = ? AND status = 1", id).Find(&ion).Error
- return ion, err
- }
-
- func UpdateIon(id int64, orgid int64, ion *models.DeviceIon) error {
-
- 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
- return err
- }
-
- func DeleteIons(id int64) (err error) {
-
- err = UserWriteDB().Model(&models.DeviceIon{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func DeleteIon(orgid int64, ids []int64) (err error) {
- if len(ids) == 1 {
- 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
- } else {
- 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
- }
-
- return
- }
-
- func GetCultureData(bedid int64, start int64, end int64, orgId int64) (cultures []*models.DeviceCultures, err error) {
- db := UserReadDB().Table("xt_device_culture as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- if bedid > 0 {
- db = db.Where("x.bed_id = ?", bedid)
- }
- if start > 0 {
- db = db.Where("x.speling_date >= ?", start)
- }
- if end > 0 {
- db = db.Where("x.speling_date <= ?", end)
- }
- 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
- return cultures, err
- }
-
- func GetDeviceIonData(bedid int64, start int64, end int64, orgId int64) (ions []*models.DeviceIons, err error) {
- db := UserReadDB().Table("xt_device_ion as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- if bedid > 0 {
- db = db.Where("x.bed_id = ?", bedid)
- }
- if start > 0 {
- db = db.Where("x.sampling_date >= ?", start)
- }
- if end > 0 {
- db = db.Where("x.sampling_date <= ?", end)
- }
- 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
- return ions, err
- }
-
- func CreateRepair(repair *models.DeviceRepair) error {
-
- err = writeUserDb.Create(&repair).Error
- return err
- }
-
- func GetAllRepair(orgid int64, limit int64, page int64) (repair []*models.DeviceRepairs, total int64, err error) {
-
- db := UserReadDB().Table("xt_device_repair as r").Where("r.status = ?", 1)
- table := XTReadDB().Table("xt_device_number as x")
- offset := (page - 1) * limit
- fmt.Print("table", table)
- if orgid > 0 {
- db = db.Where("r.user_org_id = ?", orgid)
- }
- 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
-
- // err = UserReadDB().Where("user_org_id = ? AND status = 1", orgid).Find(&repair).Error
- return repair, total, err
- }
-
- func EditRepair(id int64) (models.DeviceRepair, error) {
- repair := models.DeviceRepair{}
- err := UserReadDB().Where("id = ? AND status = 1", id).Find(&repair).Error
- return repair, err
- }
-
- func UpdateRepair(id int64, orgid int64, repair *models.DeviceRepair) error {
-
- 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
- return err
- }
-
- func DeleteRepairs(id int64) (err error) {
-
- err = UserWriteDB().Model(models.DeviceRepair{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func DeleteRepair(orgid int64, ids []int64) (err error) {
- if len(ids) == 1 {
- 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
- } else {
- 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
- }
-
- return
-
- }
-
- func GetRepair(bedid int64, start int64, end int64, orgid int64) (repair []*models.DeviceRepairs, err error) {
-
- db := UserReadDB().Table("xt_device_repair as r").Where("r.status = 1")
- sb := UserReadDB().Table("xt_device_addmacher as x")
- fmt.Print("sb", sb)
- if orgid > 0 {
- db = db.Where("r.user_org_id = ?", orgid)
- }
- if bedid > 0 {
- db = db.Where("r.bed_id = ?", bedid)
- }
-
- if start > 0 {
- db = db.Where("r.guarantee_date >= ?", start)
- }
- if end > 0 {
- db = db.Where("r.guarantee_date <= ?", end)
- }
- //err = db.Model(&repair).Find(&repair).Error
- 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
-
- return repair, err
- }
-
- func GetUserInformation(id int64) (models.DeviceInformation, error) {
- information := models.DeviceInformation{}
- err := UserReadDB().Where("id = ? AND status = 1", id).Find(&information).Error
- return information, err
- }
-
- func GetPatientInfoMation(patieintid int64) (models.Patients, error) {
- patients := models.Patients{}
- err := XTReadDB().Where("id = ? AND status = 1", patieintid).Find(&patients).Error
- return patients, err
- }
-
- func DeleteUserLogin(id int64) (err error) {
-
- err = UserWriteDB().Model(&models.DeviceInformation{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func DeleteForm(orgid int64, ids []int64) (err error) {
- if len(ids) == 1 {
- 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
- } else {
- 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
- }
-
- return
- }
-
- func GetLastInformationdata(eid int64, startdate int64, orgid int64) (models.DeviceInformation, error) {
- information := models.DeviceInformation{}
- err := UserReadDB().Model(&information).Where("equiment_id = ? and date = ? and user_org_id = ? and status = 1", eid, startdate, orgid).Last(&information).Error
- return information, err
- }
-
- func UpdateAddMacherBedID(id int64, orgid int64, addmacher *models.DeviceAddmacher) error {
-
- 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
- return err
- }
-
- func UpdatedZoneID(bedid int64, orgid int64, number *models.DeviceNumber) error {
-
- err := XTWriteDB().Model(&number).Where("id=? and org_id = ?", bedid, orgid).Update(map[string]interface{}{"zone_id": number.ZoneID, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func UpadateForm(id int64, orgid int64, infor *models.DeviceInformation) error {
-
- 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,
- "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
- return err
- }
-
- func QueryInfo(bed int64, start int64, end int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
- db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_patients as p")
- fmt.Println("table", table)
- dbs := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("dbs", dbs)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- //if zone > 0 {
- // db = db.Where("x.zone = ?", zone)
- //}
- if bed > 0 {
- db = db.Where("x.bed_number = ?", bed)
- }
- if start > 0 {
- db = db.Where("x.date >= ?", start)
- }
- if end > 0 {
- db = db.Where("x.date <= ?", end)
- }
- offset := (page - 1) * limit
-
- 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
- if err != nil {
-
- return
- }
- return
- }
-
- func GetPatientID(bedid int64, orgId int64, nowtime int64) (dialysis []*models.DialysisOrder, err error) {
-
- err = XTReadDB().Model(&dialysis).Where("bed_id = ? AND user_org_id = ? AND dialysis_date = ?", bedid, orgId, nowtime).Find(&dialysis).Error
-
- return dialysis, err
- }
-
- //func GetAllEquitType(orgId int64) (addmacher []*models.DeviceAddmacher, err error) {
- //
- // db := UserReadDB().Table("xt_device_addmacher as a").Where("a.status = 1")
- // if orgId > 0 {
- // db = db.Where("a.user_org_id = ?", orgId)
- // }
- // 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
- // return addmacher, err
- //}
-
- func GetAllEquitType(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
-
- //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
- //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
- //err = UserReadDB().Where("user_org_id = ? and status =1", orgid).Find(&equiment).Error
- 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
- return equiment, err
- }
-
- func GetAllEquitName(orgid int64) (equiment []*models.DeviceEquimentname, err error) {
- 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
- return equiment, err
- }
-
- func GetUserForm(id int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
-
- if orgId == 10060 {
- db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_patients as p")
- fmt.Println("table", table)
- dbs := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("dbs", dbs)
- offset := (page - 1) * limit
-
- if id > 0 {
- db = db.Where("x.equiment_id = ?", id)
- }
-
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
- if err != nil {
- return
- }
- return
- } else {
- db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_patients as p")
- fmt.Println("table", table)
- dbs := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("dbs", dbs)
- offset := (page - 1) * limit
-
- if id > 0 {
- db = db.Where("x.equiment_id = ?", id)
- }
-
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
- if err != nil {
- return
- }
- return
- }
-
- }
-
- func GetBedNumber(id int64, orgid int64) (models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- err := UserReadDB().Where("id= ? AND user_org_id = ?", id, orgid).Find(&addmacher).Error
-
- return addmacher, err
- }
-
- func GetNumbers(id int64, orgid int64) (models.DeviceNumber, error) {
- number := models.DeviceNumber{}
- err := XTReadDB().Where("id = ? AND org_id = ?", id, orgid).Find(&number).Error
- return number, err
- }
-
- func GetZoneForm(id int64) (models.DeviceAddmacher, error) {
- macher := models.DeviceAddmacher{}
- err := UserReadDB().Where("id=? AND status = 1", id).Find(&macher).Error
- return macher, err
- }
-
- func GetBedForm(id int64) (number []*models.DeviceNumber, err error) {
-
- err = XTReadDB().Where("zone_id = ? AND status = 1", id).Find(&number).Error
- return number, err
- }
-
- func GetTotalCount(orgid int64) (repair []*models.DeviceRepair, total int64, err error) {
- err = UserReadDB().Model(&repair).Where("user_org_id = ? and status = 1", orgid).Find(&repair).Count(&total).Error
- return repair, total, err
- }
-
- func GetTotalNumber(id int64, orgid int64) (total int64, err error) {
- var device models.DeviceInformation
- err = UserReadDB().Model(&device).Where("equiment_id = ? AND user_org_id = ? AND status = 1", id, orgid).Find(&device).Count(&total).Error
- return total, err
- }
-
- func GetTimeWarning(equitid int64, orgId int64) (models.DeviceInformation, error) {
-
- information := models.DeviceInformation{}
- 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
- return information, err
- }
-
- func GetTimeLast(equitid int64, orgId int64) (models.DeviceInformation, error) {
-
- information := models.DeviceInformation{}
- 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
- return information, err
- }
-
- func GetTimeLastData(equitid int64, orgId int64) (models.DeviceInformation, error) {
-
- information := models.DeviceInformation{}
- 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
- return information, err
- }
-
- func GetAllpatient(orgid int64) (patients []*models.Patients, err error) {
- err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patients).Error
- return patients, err
- }
-
- func GetAllpatientThirty(orgid int64) (patients []*models.PatientsThirty, err error) {
- err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patients).Error
- return patients, err
- }
-
- func GetAllpatientFourty(orgid int64) (patients []*models.PatientsThirty, err error) {
- err = XTReadDB().Where("user_org_id = ? and status = 1 and lapseto = 1", orgid).Find(&patients).Error
- return patients, err
- }
-
- func GetInformation(eid int64, startdate int64, orgid int64, classtype int64) (*models.DeviceInformation, error) {
- var information models.DeviceInformation
- var err error
- 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
- fmt.Print("", err)
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &information, nil
- }
-
- func GetLastInformationById(eid int64, orgid int64) (models.DeviceInformation, error) {
-
- information := models.DeviceInformation{}
-
- err := UserReadDB().Model(&information).Where("equiment_id = ? and user_org_id = ? and status = 1", eid, orgid).Last(&information).Error
-
- return information, err
- }
-
- func ChangeBed(id int64, org int64) (number []*models.DeviceNumber, err error) {
-
- err = XTReadDB().Model(&number).Where("zone_id = ? AND status = 1 AND org_id = ? ", id, org).Find(&number).Error
-
- return number, err
- }
-
- func GetPatientDetail(id int64, orgid int64) (models.Patients, error) {
- patients := models.Patients{}
- err := XTReadDB().Where("id=? and user_org_id = ?", id, orgid).Find(&patients).Error
- return patients, err
- }
-
- func GetRemanderData(orgid int64) (remander models.DeviceRemander, err error) {
-
- err = UserReadDB().Model(&models.DeviceRemander{}).Where("user_org_id = ? and status = 1", orgid).Find(&remander).Error
- return
- }
-
- func CreateRemander(remander *models.DeviceRemander) (err error) {
-
- err = UserWriteDB().Create(&remander).Error
- return
- }
-
- func UpdateRemander(remander *models.DeviceRemander) (err error) {
-
- err = UserWriteDB().Save(&remander).Error
- return
- }
-
- func GetMode(mode string, orgid int64) (*models.DeviceMode, error) {
- var information models.DeviceMode
- var err error
- err = UserReadDB().Model(&information).Where("device_mode = ? and user_org_id = ? and status = ?", mode, orgid, 1).Find(&information).Error
- fmt.Print("", err)
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &information, nil
- }
-
- func SaveMode(mode *models.DeviceMode) (err error) {
- err = UserWriteDB().Save(&mode).Error
- return
- }
-
- func GetAllMode(orgid int64) (mode []*models.DeviceMode, err error) {
- err = UserReadDB().Where("user_org_id = ? and status = ?", orgid, 1).Find(&mode).Error
- return mode, err
- }
-
- func GetModeById(id int64) (models.DeviceMode, error) {
- mode := models.DeviceMode{}
- err := UserReadDB().Where("id = ?", id).Find(&mode).Error
- return mode, err
- }
-
- func UpdateMode(id int64, mode models.DeviceMode) error {
-
- err := UserWriteDB().Model(&mode).Where("id=?", id).Update(map[string]interface{}{"device_mode": mode.DeviceMode, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func QueryDeviceMode(id int64, orgid int64) (*models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- var err error
- err = UserReadDB().Model(&addmacher).Where("unit_type = ? and user_org_id = ?", id, orgid).Find(&addmacher).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &addmacher, nil
- }
-
- func DeleteMode(id int64) error {
- err := UserWriteDB().Model(models.DeviceMode{}).Where("id=?", id).Update(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func SelectChange(id int64, orgid int64) (number []*models.DeviceNumber, err error) {
- //err = XTReadDB().Where("zone_id = ? and org_id = ? and status = ?", id, orgid, 1).Find(&number).Error
- db := XTReadDB().Table("xt_device_number as x").Where("x.status = ?", 1)
- err = db.Select("org_id,number,group_id,zone_id as id").Where("zone_id = ? and org_id = ?", id, orgid).Find(&number).Error
- return number, err
- }
-
- func SelectBed(id int64, orgid int64) (models.DeviceNumber, error) {
- number := models.DeviceNumber{}
- err := XTReadDB().Where("id = ? and org_id = ?", id, orgid).Find(&number).Error
- return number, err
- }
-
- func GetTimeData(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
- //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
- //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
- day := time.Now().Day()
- oldMonth := day - 30
- t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
-
- 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
- return information, err
- }
-
- func GetTimeTwo(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
- //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
- //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
- day := time.Now().Day()
- oldMonth := day - 30
- t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
- 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
- return information, err
- }
-
- func GetTimeThree(equitid int64, orgid int64, timenow int64) (information []*models.DeviceInformation, err error) {
- //db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
- //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
- day := time.Now().Day()
- oldMonth := day - 30
- t := time.Date(time.Now().Year(), time.Now().Month(), oldMonth, time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
- 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
- return information, err
- }
-
- func DeleteImages(id int64) error {
- repair := models.DeviceRepair{}
- err := UserWriteDB().Model(&repair).Where("id=?", id).Update(map[string]interface{}{"images": "", "image_name": ""}).Error
- return err
- }
-
- func GetActivtyCreator(creator int64) (*models.KyActivityTable, error) {
- table := models.KyActivityTable{}
- err := UserReadDB().Model(&table).Where("admin_user_id = ? and status =1", creator).Find(&table).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &table, nil
- }
-
- func CreateTable(table *models.KyActivityTable) error {
-
- err := UserWriteDB().Model(&table).Create(&table).Error
- return err
- }
-
- func GetAdminUserRole(id int64, orgid int64) (models.SgjUserAdminRole, error) {
- role := models.SgjUserAdminRole{}
- err := UserReadDB().Where("admin_user_id = ? and org_id = ? and status = 1", id, orgid).Find(&role).Error
- return role, err
- }
-
- func GetRolePosition(id int64) (models.SgjUserRole, error) {
- role := models.SgjUserRole{}
- err := UserReadDB().Where("id = ? And status =1", id).Find(&role).Error
- return role, err
- }
-
- func GetMobile(id int64) (models.SgjUserAdmin, error) {
- admin := models.SgjUserAdmin{}
- err := UserReadDB().Where("id=? and status = 1", id).Find(&admin).Error
- return admin, err
- }
-
- func GetOrgs(id int64) (roles []*models.SgjUserAdminRole, err error) {
-
- db := UserReadDB().Table("sgj_user_admin_role as s").Where("s.status = 1")
- 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
-
- return roles, err
- }
-
- func GetUserMachTotalCount(orgid int64) (vm []*models.VmDeviceInformation, err error) {
-
- 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
- return vm, err
- }
-
- func GetUserTotalByMacher(id int64) (models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- err := UserReadDB().Model(&addmacher).Where("id=? and status = 1", id).Find(&addmacher).Error
- return addmacher, err
- }
-
- func GetUserTotalCount(orgid int64, bedid int64) (vm []*models.VmDeviceInformation, err error) {
-
- 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
- return vm, err
-
- }
-
- func GetUserTotal(orgid int64, id int64) (models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- err := UserReadDB().Model(&addmacher).Where("user_org_id = ? and bed_id = ? and status = 1", orgid, id).Find(&addmacher).Error
- return addmacher, err
- }
-
- func GetDisInfectionTime(orgid int64, unitype int64, scheduletype int64, scheduleweek int64) (*models.DevicePlan, error) {
- plan := models.DevicePlan{}
- 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
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &plan, nil
- }
-
- func GetUnitType(bedid int64, orgid int64) (models.DeviceAddmacher, error) {
-
- addmacher := models.DeviceAddmacher{}
- err := UserReadDB().Model(&addmacher).Where("bed_id = ? and user_org_id = ? and status = 1", bedid, orgid).Find(&addmacher).Error
- return addmacher, err
- }
-
- func GetLaseDeviceInfomation(orgid int64, bedid int64, date int64, scheduletype int64) (*models.DeviceInformation, error) {
-
- information := models.DeviceInformation{}
- 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
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &information, nil
- }
-
- func GetLaseDeviceInfomationTwo(orgid int64, bedid int64, scheduletype int64) (models.DeviceInformation, error) {
- information := models.DeviceInformation{}
- err = UserReadDB().Model(&information).Where("bed_number= ? and user_org_id = ? and status = 1 and class = ?", bedid, orgid, scheduletype).Last(&information).Error
- return information, err
- }
-
- func GetAssessmentAfterDissDataTwo(patientid int64, orgID int64, timenow int64) (models.XtAssessmentAfterDislysis, error) {
- dislysis := models.XtAssessmentAfterDislysis{}
- err := XTReadDB().Where("patient_id = ? AND user_org_id = ? AND assessment_date = ?", patientid, orgID, timenow).Find(&dislysis).Error
- return dislysis, err
- }
-
- func GetEquimentIDTwo(bedId int64, orgID int64) (models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- err := readUserDb.Model(&addmacher).Where("bed_id = ? AND user_org_id = ? AND status = ?", bedId, orgID, 1).Find(&addmacher).Error
- return addmacher, err
- }
-
- func GetDisinfectionTwo(equitType int64, enquitType int64, orgID int64) (*models.DevicePlan, error) {
- var plan models.DevicePlan
- var err error
- err = readUserDb.Model(&plan).Where("device_type = ? AND classtime = ? AND user_org_id = ? AND status = 1", equitType, enquitType, orgID).Find(&plan).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &plan, nil
- }
-
- func GetInforTwo(patientid int64, timenow int64, orgid int64, class int64) (*models.DeviceInformation, error) {
- var pre models.DeviceInformation
- var err error
- 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
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &pre, nil
- }
-
- func GetPatientOrderInfo(schduledate int64, patientid int64, orgid int64) (models.XtDialysisOrder, error) {
- order := models.XtDialysisOrder{}
- err := XTReadDB().Model(&order).Where("dialysis_date = ? and patient_id = ? and user_org_id = ? and status = 1", schduledate, patientid, orgid).Find(&order).Error
- return order, err
- }
-
- func CreateInformationTwo(information *models.DeviceInformation) error {
- err := UserWriteDB().Create(&information).Error
- return err
- }
-
- func UpdateInformation(information *models.DeviceInformation, scheduledate int64, bedid int64, scheduletype int64) error {
-
- 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
- return err
- }
-
- func DeleteEquit(id int64) (models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- err := UserWriteDB().Model(&addmacher).Where("id=?", id).Updates(map[string]interface{}{"status": 0}).Error
- return addmacher, err
- }
-
- func GetDeviceInfomation(orgid int64, scheduledate int64) (information []*models.DeviceInformation, err error) {
-
- err = UserReadDB().Model(&information).Where("user_org_id = ? and date = ? and status =1", orgid, scheduledate).Find(&information).Error
- return information, err
- }
-
- func CreateOxygenates(oxygenates *models.XtDeviceOxygenates) error {
-
- err := UserWriteDB().Create(&oxygenates).Error
- return err
- }
-
- func CreateHadWater(hadwater *models.XtDeviceHadwater) error {
-
- err := UserWriteDB().Create(&hadwater).Error
- return err
- }
-
- func CreateWater(water *models.XtDeviceWater) error {
-
- err := UserWriteDB().Create(&water).Error
- return err
- }
-
- func CreateDevicePh(ph *models.XtDevicePh) error {
-
- err := UserWriteDB().Create(&ph).Error
- return err
- }
-
- func GetAllDeviceOxygenates(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_oxygenates as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
-
- return dialysate, err
- }
-
- func GetAllHadWater(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_hadwater as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
-
- return dialysate, err
- }
-
- func GetDeviceWater(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_water as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
-
- return dialysate, err
- }
-
- func GetDevicePH(orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_ph as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- 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
-
- return dialysate, err
- }
-
- func GetDialysateData(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_dialysate as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- if bedid > 0 {
- db = db.Where("x.bed_id = ?", bedid)
- }
- if start > 0 {
- db = db.Where("x.sampling_date >= ?", start)
- }
- if end > 0 {
- db = db.Where("x.sampling_date <= ?", end)
- }
-
- 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
-
- return dialysate, err
- }
-
- func GetOxygenates(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_oxygenates as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- if bedid > 0 {
- db = db.Where("x.bed_id = ?", bedid)
- }
- if start > 0 {
- db = db.Where("x.sampling_date >= ?", start)
- }
- if end > 0 {
- db = db.Where("x.sampling_date <= ?", end)
- }
-
- 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
-
- return dialysate, err
- }
-
- func GetHardWater(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_hadwater as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- if bedid > 0 {
- db = db.Where("x.bed_id = ?", bedid)
- }
- if start > 0 {
- db = db.Where("x.sampling_date >= ?", start)
- }
- if end > 0 {
- db = db.Where("x.sampling_date <= ?", end)
- }
-
- 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
-
- return dialysate, err
- }
-
- func GetWater(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_water as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- if bedid > 0 {
- db = db.Where("x.bed_id = ?", bedid)
- }
- if start > 0 {
- db = db.Where("x.sampling_date >= ?", start)
- }
- if end > 0 {
- db = db.Where("x.sampling_date <= ?", end)
- }
-
- 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
-
- return dialysate, err
- }
-
- func GetDevicePh(bedid int64, start int64, end int64, orgId int64) (dialysate []*models.DeviceDialysates, err error) {
- db := UserReadDB().Table("xt_device_ph as x").Where("x.status = 1")
- table := UserReadDB().Table("sgj_user_admin_role as r")
- fmt.Println("table", table)
- if orgId > 0 {
- db = db.Where("x.user_org_id = ?", orgId)
- }
- if bedid > 0 {
- db = db.Where("x.bed_id = ?", bedid)
- }
- if start > 0 {
- db = db.Where("x.sampling_date >= ?", start)
- }
- if end > 0 {
- db = db.Where("x.sampling_date <= ?", end)
- }
-
- 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
-
- return dialysate, err
- }
-
- func GetOxygenatesById(id int64) (models.XtDeviceOxygenates, error) {
- oxygenates := models.XtDeviceOxygenates{}
- err := UserReadDB().Model(&oxygenates).Where("id = ? and status = 1", id).Find(&oxygenates).Error
- return oxygenates, err
- }
-
- func UpdateOxygenates(id int64, orgid int64, dialysate *models.XtDeviceOxygenates) error {
- 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
- return err
- }
-
- func GetHardWaterById(id int64) (models.XtDeviceHadwater, error) {
- hadwater := models.XtDeviceHadwater{}
- err := UserReadDB().Model(&hadwater).Where("id = ? and status = 1", id).Find(&hadwater).Error
- return hadwater, err
- }
-
- func GetWaterById(id int64) (models.XtDeviceWater, error) {
-
- water := models.XtDeviceWater{}
- err := UserReadDB().Model(&water).Where("id=? and status =1", id).Find(&water).Error
- return water, err
- }
-
- func GetDevicePhById(id int64) (models.XtDevicePh, error) {
-
- devicePh := models.XtDevicePh{}
- err := UserReadDB().Model(&devicePh).Where("id = ? and status =1", id).Find(&devicePh).Error
- return devicePh, err
- }
-
- func CreateAerialDetection(detection *models.XtAerialDetection) error {
-
- err := XTWriteDB().Create(&detection).Error
- return err
- }
-
- func GetAirList(limit int64, page int64, orgid int64) (airlist []*models.XtAerialDetection, total int64, err error) {
- offset := (page - 1) * limit
- 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
- return airlist, total, err
- }
-
- func GetAirDisinfectDetail(id int64) (models.XtAerialDetection, error) {
-
- detection := models.XtAerialDetection{}
- err := XTReadDB().Model(&detection).Where("id = ? and status = 1", id).Find(&detection).Error
- return detection, err
- }
-
- func UpdateAeriaDetection(detection *models.XtAerialDetection, id int64) error {
-
- 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
- return err
- }
-
- func DeleteAirDisinfect(id int64) error {
- detection := models.XtAerialDetection{}
- err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func SaveBodyDetection(detection *models.XtBodyDetection) error {
-
- err := XTWriteDB().Create(&detection).Error
- return err
- }
-
- func GetBodyList(limit int64, page int64, orgid int64) (body []*models.XtBodyDetection, total int64, err error) {
-
- offset := (page - 1) * limit
- 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
- return body, total, err
-
- }
-
- func GetBodyDisinfectDetail(id int64) (models.XtBodyDetection, error) {
-
- detection := models.XtBodyDetection{}
- err := XTReadDB().Model(&detection).Where("id = ? and status = 1", id).Find(&detection).Error
- return detection, err
- }
-
- func UpdateBodyDetection(detection *models.XtBodyDetection, id int64) error {
-
- 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
- return err
- }
-
- func DeleteBodyDisInfect(id int64) error {
-
- detection := models.XtBodyDetection{}
- err := XTWriteDB().Model(&detection).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func UpdateHadWater(id int64, orgid int64, hadwater *models.XtDeviceHadwater) error {
-
- 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
- return err
- }
-
- func UpdateDeviceWater(id int64, orgid int64, hadwater *models.XtDeviceWater) error {
-
- 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
- return err
- }
-
- func UpdateDivicePh(id int64, orgid int64, hadwater *models.XtDevicePh) error {
- 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
- return err
- }
-
- func DeleteOxygenates(id int64) error {
- oxygenates := models.XtDeviceOxygenates{}
- err := writeUserDb.Model(&oxygenates).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func DeleteHadWater(id int64) error {
- hadwater := models.XtDeviceHadwater{}
- err := writeUserDb.Model(&hadwater).Where("id =?", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func DeleteWater(id int64) error {
-
- water := models.XtDeviceWater{}
- err := writeUserDb.Model(&water).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func DeleteDevicePh(id int64) error {
-
- ph := models.XtDevicePh{}
- err := writeUserDb.Model(&ph).Where("id = ? ", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func CretaDeviceWater(water models.XtDialysisDeviceWater) error {
-
- err := XTWriteDB().Create(&water).Error
-
- return err
- }
-
- func SaveDeviceWater(water models.XtDialysisDeviceWater) error {
-
- err := XTWriteDB().Save(&water).Error
-
- return err
- }
-
- func GetWaterFormList(equitment_id, start_timeunix, endtimeunix, limit, page, orgId int64) (water []*models.XtDialysisDeviceWater, total int64, err error) {
-
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&water).Where("status =1")
- if equitment_id > 0 {
- db = db.Where("equiment_id= ?", equitment_id)
- }
- if start_timeunix > 0 {
- db = db.Where("record_date>=?", start_timeunix)
- }
- if endtimeunix > 0 {
- db = db.Where("record_date<=?", endtimeunix)
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
- err = db.Count(&total).Limit(limit).Offset(offset).Order("record_date desc").Find(&water).Error
-
- return water, total, err
- }
-
- func DelelteDialysisWater(id int64) error {
-
- err := XTWriteDB().Model(&models.XtDialysisDeviceWater{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func GetDialysisWaterDetail(id int64) (models.XtDialysisDeviceWater, error) {
-
- water := models.XtDialysisDeviceWater{}
-
- err := XTReadDB().Where("id = ? and status = 1", id).Find(&water).Error
-
- return water, err
- }
-
- func DeleteBatchDialysisWater(orgid int64, ids []int64) (err error) {
- if len(ids) == 1 {
- 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
- } else {
- 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
- }
-
- return
- }
-
- func CreateNewAirDisinfect(disinfect models.XtNewAriDisinfect) error {
-
- err := XTWriteDB().Create(&disinfect).Error
-
- return err
- }
-
- 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) {
-
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&list).Where("status =1")
- if start_time > 0 {
- db = db.Where("record_date >= ?", start_time)
- }
- if end_time > 0 {
- db = db.Where("record_date <= ?", end_time)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- if len(storey) > 0 {
- db = db.Where("storey =?", storey)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
- return list, total, err
- }
-
- func GetNewAirWayDisinfectList(limit int64, page int64, start_time int64, end_time int64, user_org_id int64) (list []*models.XtNewAriDisinfectWay, total int64, err error) {
-
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&list).Where("status =1")
- if start_time > 0 {
- db = db.Where("record_date >= ?", start_time)
- }
- if end_time > 0 {
- db = db.Where("record_date <= ?", end_time)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
- return list, total, err
- }
-
- func GetNewAirDisinfectByIdList(id int64) (models.XtNewAriDisinfect, error) {
-
- disinfect := models.XtNewAriDisinfect{}
-
- err := XTReadDB().Where("id = ? and status= 1", id).Find(&disinfect).Error
-
- return disinfect, err
- }
-
- func SaveNewAriDisinfect(disinfect models.XtNewAriDisinfect) error {
-
- err := XTWriteDB().Save(&disinfect).Error
- return err
- }
-
- func DeleteNewAirDisInfect(id int64) error {
-
- err := XTWriteDB().Model(&models.XtNewAriDisinfect{}).Where("id= ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func CreateObjectDisInfect(disinfect models.XtNewObjectDisinfect) error {
-
- err := XTWriteDB().Create(&disinfect).Error
-
- return err
- }
-
- func CreateNewAirWayDisinfectOne(disinfect models.XtNewAriDisinfectWay) error {
-
- err := XTWriteDB().Create(&disinfect).Error
-
- return err
- }
-
- func CreateNewAirWayDisinfect(disinfect models.XtNewAriDisinfectWay) error {
-
- err := XTWriteDB().Save(&disinfect).Error
-
- return err
- }
-
- 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) {
-
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&list).Where("status =1")
- if start_time > 0 {
- db = db.Where("record_date >= ?", start_time)
- }
- if end_time > 0 {
- db = db.Where("record_date <= ?", end_time)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- if len(storey) > 0 {
- db = db.Where("storey =?", storey)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
- return list, total, err
- }
-
- func GetObjectAbleDisInfectWayList(limit int64, page int64, start_time int64, end_time int64, user_org_id int64) (list []*models.XtNewObjectDisinfectWay, total int64, err error) {
-
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&list).Where("status =1")
- if start_time > 0 {
- db = db.Where("record_date >= ?", start_time)
- }
- if end_time > 0 {
- db = db.Where("record_date <= ?", end_time)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
- return list, total, err
- }
-
- func GetObjectTableDisinfectByList(id int64) (models.XtNewObjectDisinfect, error) {
-
- disinfect := models.XtNewObjectDisinfect{}
-
- err := XTReadDB().Where("id=? and status =1", id).Find(&disinfect).Error
-
- return disinfect, err
- }
-
- func UpdateObjectTableDisinfect(disinfect models.XtNewObjectDisinfect) error {
-
- err := XTWriteDB().Save(&disinfect).Error
-
- return err
- }
-
- func DeleteObjectTableDisinfect(id int64) error {
-
- err := XTWriteDB().Model(&models.XtNewObjectDisinfect{}).Where("id=? and status= 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetAirDisInfectionLongTime(user_org_id int64, storey string) (list []*models.XtNewAriDisinfect, err error) {
-
- db := XTReadDB().Model(&list).Where("status =1")
- if user_org_id > 0 {
- db = db.Where("user_org_id =?", user_org_id)
- }
- if len(storey) > 0 {
- db = db.Where("storey =?", storey)
- }
- err = db.Order("id desc").First(&list).Error
- return
- }
-
- func GetAirDisinfectWayLongTime(user_org_id int64, department string) (list []*models.XtNewAriDisinfectWay, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and status = 1 and department= ?", user_org_id, department).Order("id desc").First(&list).Error
- return
- }
-
- func GetObjectDisInfectionLongTime(user_org_id int64) (list []*models.XtNewObjectDisinfect, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&list).Error
- return
- }
-
- func GetDialysisOrderPatient(org_id int64) (order []*models.XtDialysisOrder, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and dialysis_date>=? and dialysis_date<=? and status =1", org_id, 1669824000, 1672416000).Find(&order).Error
-
- return order, err
- }
-
- func CreateObjectRegistration(registration models.XtDialysisRegistration) error {
-
- err := XTWriteDB().Create(®istration).Error
-
- return err
- }
-
- func GetRegistrationDisinfectList(limit int64, page int64, start_time int64, end_time int64, user_org_id int64) (list []*models.XtDialysisRegistration, total int64, err error) {
-
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&list).Where("status =1")
- if start_time > 0 {
- db = db.Where("record_date >= ?", start_time)
- }
- if end_time > 0 {
- db = db.Where("record_date <= ?", end_time)
- }
- if user_org_id > 0 {
- db = db.Where("user_org_id = ?", user_org_id)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&list).Error
- return list, total, err
- }
-
- func GetObjectRegistrationByIdList(id int64) (models.XtDialysisRegistration, error) {
-
- registration := models.XtDialysisRegistration{}
- err := XTReadDB().Where("id = ? and status=1", id).Find(®istration).Error
- return registration, err
-
- }
-
- func UpdateObjectRegistration(registration models.XtDialysisRegistration) error {
-
- err := XTWriteDB().Save(®istration).Error
-
- return err
- }
-
- func DeleteObjectTregistration(id int64) error {
-
- err := XTWriteDB().Model(&models.XtDialysisRegistration{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetRegistGoodInforList(user_org_id int64) (good []*models.GoodInformationFourty, err error) {
-
- err = XTReadDB().Where("org_id = ? and status =1", user_org_id).Find(&good).Error
-
- return good, err
- }
-
- func GetRegistNumber(sys_record_time int64, good_id int64, user_org_id int64) (infor []*models.WarehouseOutInfoNight, err error) {
-
- 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
-
- return infor, err
- }
-
- func GetAirDisInfectSetting(orgid int64) (models.XtDeviceAirSetting, error) {
-
- setting := models.XtDeviceAirSetting{}
-
- err := XTReadDB().Where("user_org_id =? and status=1", orgid).Find(&setting).Error
-
- return setting, err
- }
-
- func SaveSetAirDisInfect(setting models.XtDeviceAirSetting) error {
-
- err := XTWriteDB().Save(&setting).Error
-
- return err
- }
-
- func GetNewAirWayDisinfectByIdList(id int64) (models.XtNewAriDisinfectWay, error) {
-
- disinfectWay := models.XtNewAriDisinfectWay{}
- err := XTReadDB().Where("id = ? and status =1", id).Find(&disinfectWay).Error
- return disinfectWay, err
- }
-
- func DeleteNewAirWayDisinfect(id int64) error {
-
- err := XTWriteDB().Model(models.XtNewAriDisinfectWay{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetObjectTableDisinfect(user_org_id int64) (models.XtDeviceObjctSet, error) {
-
- objctSet := models.XtDeviceObjctSet{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&objctSet).Error
- return objctSet, err
- }
-
- func SaveSetObjectDisinfect(objectSet models.XtDeviceObjctSet) error {
-
- err := XTWriteDB().Save(&objectSet).Error
-
- return err
- }
-
- func CreateNewObjectWayDisInfect(way models.XtNewObjectDisinfectWay) error {
-
- err := XTWriteDB().Create(&way).Error
- return err
- }
-
- func GetObjectAbledDisInfectWayById(id int64) (models.XtNewObjectDisinfectWay, error) {
-
- objway := models.XtNewObjectDisinfectWay{}
- err := XTReadDB().Where("id=? and status=1", id).Find(&objway).Error
- return objway, err
- }
-
- func SaveobjectDisinfect(way models.XtNewObjectDisinfectWay) error {
-
- err := XTWriteDB().Save(&way).Error
- return err
- }
-
- func DeleteObjectAbleWayDisinfect(id int64) error {
-
- err := XTWriteDB().Model(models.XtNewObjectDisinfectWay{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
|