Parcourir la source

Merge branch 'master' of http://git.shengws.com/csx/XT_New

csx il y a 4 ans
Parent
révision
12ad8c0941

+ 253 - 15
controllers/new_mobile_api_controllers/new_dialysis_api_controller.go Voir le fichier

@@ -603,9 +603,9 @@ func (this *NewDialysisApiController) GetDoctorAdvices() {
603 603
 	limit, _ := this.GetInt64("limit")
604 604
 	page, _ := this.GetInt64("page")
605 605
 	fmt.Println("病人ID", newPatientInfo.BloodId)
606
-	advice, total, err := service.GetNewDoctorAdvice(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
607
-	one, t, date, err := service.GetNewDoctorAdviceOne(newPatientInfo.BloodId, page, orgid)
608
-	fmt.Print(one, t, date, err)
606
+	advice, _, err := service.GetNewDoctorAdvice(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
607
+	one, total, err := service.GetNewDoctorAdviceOne(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
608
+	fmt.Println("err------------------------", err)
609 609
 	if err != nil {
610 610
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
611 611
 		return
@@ -1563,8 +1563,8 @@ func (this *NewDialysisApiController) GetInspection() {
1563 1563
 
1564 1564
 func (this *NewDialysisApiController) GetMyInformation() {
1565 1565
 	id, _ := this.GetInt64("id")
1566
-	fmt.Println("id--------------", id)
1567 1566
 	roleInfo, err := service.GetPosition(id)
1567
+
1568 1568
 	if err != nil {
1569 1569
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1570 1570
 		return
@@ -1739,8 +1739,8 @@ func (this *NewDialysisApiController) SaveBirthday() {
1739 1739
 
1740 1740
 func (this *NewDialysisApiController) GetOrgName() {
1741 1741
 
1742
-	orgid := this.GetMobileAdminUserInfo().Org.Id
1743
-	name, err := service.GetOrgName(orgid)
1742
+	id, _ := this.GetInt64("id")
1743
+	name, err := service.GetOrgName(id)
1744 1744
 	if err != nil {
1745 1745
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1746 1746
 		return
@@ -1938,18 +1938,48 @@ func (this *NewDialysisApiController) GetAllNumber() {
1938 1938
 func (this *NewDialysisApiController) DeleteBed() {
1939 1939
 	id, _ := this.GetInt64("id")
1940 1940
 	fmt.Println("id", id)
1941
-	err := service.DeleteBed(id)
1942
-	fmt.Println("删除失败", err)
1943
-	returnData := make(map[string]interface{}, 0)
1944
-	returnData["msg"] = "删除失败"
1945
-	this.ServeSuccessJSON(returnData)
1946
-	return
1941
+	nowDateTime := time.Now()
1942
+	nowDate := nowDateTime.Format("2006-01-02")
1943
+	nowDate += " 00:00:00"
1944
+	timeLayout := "2006-01-02"
1945
+	loc, _ := time.LoadLocation("Local")
1946
+	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
1947
+	fmt.Println(theTime.Unix())
1948
+	adminInfo := this.GetMobileAdminUserInfo()
1949
+	orgid := adminInfo.Org.Id
1950
+	_, errcode := service.GetSchedu(id, theTime.Unix(), orgid)
1951
+	fmt.Println("errcode", errcode)
1952
+	if errcode == gorm.ErrRecordNotFound {
1953
+		err := service.DeleteBed(id)
1954
+		fmt.Println("删除失败", err)
1955
+		returnData := make(map[string]interface{}, 0)
1956
+		returnData["msg"] = "删除失败"
1957
+		this.ServeSuccessJSON(returnData)
1958
+		return
1959
+	} else if errcode == nil {
1960
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1961
+		return
1962
+	}
1963
+
1947 1964
 }
1948 1965
 
1949 1966
 func (this *NewDialysisApiController) LoginOut() {
1950 1967
 
1951 1968
 	this.DelSession("mobile_admin_user_info")
1952 1969
 	this.Ctx.SetCookie("token_cookie", "")
1970
+	id, _ := this.GetInt64("id")
1971
+	fmt.Println("id------------------------------------------", id)
1972
+	loginLog := models.SgjUserAdminLoginLog{
1973
+		AdminUserId: id,
1974
+		OrgId:       0,
1975
+		AppId:       0,
1976
+		Ip:          utils.GetIP(this.Ctx.Request),
1977
+		OperateType: 2,
1978
+		AppType:     0,
1979
+		Ctime:       time.Now().Unix(),
1980
+	}
1981
+	err := service.CreateLoginLod(&loginLog)
1982
+	fmt.Println("err--------", err)
1953 1983
 	returnData := make(map[string]interface{}, 0)
1954 1984
 	returnData["msg"] = "删除失败"
1955 1985
 	this.ServeSuccessJSON(returnData)
@@ -2036,15 +2066,223 @@ func (this *NewDialysisApiController) GetMyOrganazition() {
2036 2066
 }
2037 2067
 
2038 2068
 func (this *NewDialysisApiController) GetOrgInformation() {
2069
+	id, _ := this.GetInt64("id")
2070
+	information, err := service.GetOrgInformation(id)
2071
+	name, err := service.GetShortName(information.OrgType)
2072
+	typeName, err := service.GetTypeName(name.Pid)
2073
+	//获取省
2074
+	province, err := service.GetOrgProvince(information.Province)
2075
+	cityes, err := service.GetOrgProvince(information.City)
2076
+	district, err := service.GetOrgProvince(information.District)
2077
+	fmt.Print("err", err)
2078
+	//if err != nil {
2079
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2080
+	//	return
2081
+	//}
2082
+	this.ServeSuccessJSON(map[string]interface{}{
2083
+		"information": information,
2084
+		"name":        name,
2085
+		"typeName":    typeName,
2086
+		"province":    province,
2087
+		"city":        cityes,
2088
+		"district":    district,
2089
+	})
2090
+}
2091
+
2092
+func (this *NewDialysisApiController) GetAllOrgType() {
2093
+
2094
+	orgType, _ := service.GetAllOrgType()
2095
+	returnData := make(map[string]interface{}, 0)
2096
+	returnData["orgType"] = orgType
2097
+	this.ServeSuccessJSON(returnData)
2098
+}
2099
+
2100
+func (this *NewDialysisApiController) EditOrg() {
2101
+	id, _ := this.GetInt64("id")
2102
+	fmt.Println("id", id)
2103
+	name := this.GetString("org_name")
2104
+	fmt.Println("name", name)
2105
+	provinceName := this.GetString("provinces_name")
2106
+	fmt.Println("provinceName", provinceName)
2107
+	cityName := this.GetString("city_name")
2108
+	fmt.Println("cityName", cityName)
2109
+	districtName := this.GetString("district_name")
2110
+	fmt.Println("districtName", districtName)
2111
+	address := this.GetString("address")
2112
+	fmt.Println("address", address)
2113
+	org_type := this.GetString("org_type")
2114
+	fmt.Println("org_type", org_type)
2115
+	contactName := this.GetString("contact_name")
2116
+	fmt.Println("contactName", contactName)
2117
+	orgPhone := this.GetString("telephone")
2118
+	fmt.Println("orgPhone", orgPhone)
2119
+	provinceID := 0
2120
+	cityID := 0
2121
+	districtID := 0
2122
+	province, getProvinceErr := service.GetProvinceWithName(provinceName)
2123
+	if getProvinceErr != nil {
2124
+		utils.ErrorLog("查询省名失败:%v", getProvinceErr)
2125
+		this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2126
+		this.ServeJSON()
2127
+		return
2128
+	} else if province != nil {
2129
+		provinceID = int(province.ID)
2130
+		city, getCityErr := service.GetCityWithName(province.ID, cityName)
2131
+		if getCityErr != nil {
2132
+			utils.ErrorLog("查询城市名失败:%v", getCityErr)
2133
+			this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2134
+			this.ServeJSON()
2135
+			return
2136
+		} else if city != nil {
2137
+			cityID = int(city.ID)
2138
+			district, getDistrictErr := service.GetDistrictWithName(city.ID, districtName)
2139
+			if getDistrictErr != nil {
2140
+				utils.ErrorLog("查询区县名失败:%v", getDistrictErr)
2141
+				this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2142
+				this.ServeJSON()
2143
+				return
2144
+			} else if district != nil {
2145
+				districtID = int(district.ID)
2146
+			}
2147
+		}
2148
+	}
2149
+
2150
+	orgType := service.GetOrgTypeByName(org_type)
2151
+	fmt.Println(provinceID, cityID, districtID)
2152
+	org := models.SgjUserOrg{
2153
+		OrgName:      name,
2154
+		OrgShortName: name,
2155
+		Province:     int64(provinceID),
2156
+		City:         int64(cityID),
2157
+		District:     int64(districtID),
2158
+		Address:      address,
2159
+		OrgType:      orgType.ID,
2160
+		Telephone:    orgPhone,
2161
+		ContactName:  contactName,
2162
+	}
2163
+
2164
+	fmt.Println("org", org)
2165
+	err := service.UpdateOrg(id, org)
2166
+	if err != nil {
2167
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2168
+		return
2169
+	}
2170
+	this.ServeSuccessJSON(map[string]interface{}{
2171
+		"org": org,
2172
+	})
2173
+}
2174
+
2175
+func (this *NewDialysisApiController) GetMyInforName() {
2176
+
2177
+	id, _ := this.GetInt64("id")
2178
+	Rolename, err := service.GetMyInfoName(id)
2179
+	Username, err := service.GetAdminName(Rolename.AdminUserId)
2180
+	if err != nil {
2181
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2182
+		return
2183
+	}
2184
+	this.ServeSuccessJSON(map[string]interface{}{
2185
+		"Rolename": Rolename,
2186
+		"Username": Username,
2187
+	})
2188
+}
2039 2189
 
2190
+func (this *NewDialysisApiController) GetPartionDetail() {
2191
+	id, _ := this.GetInt64("id")
2192
+	partionDetail, err := service.GetPartionDetail(id)
2193
+	if err != nil {
2194
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2195
+		return
2196
+	}
2197
+	this.ServeSuccessJSON(map[string]interface{}{
2198
+		"partionDetail": partionDetail,
2199
+	})
2200
+}
2201
+
2202
+func (this *NewDialysisApiController) UpdatePartition() {
2203
+	id, _ := this.GetInt64("id")
2204
+	name := this.GetString("name")
2205
+	zoneType, _ := this.GetInt64("type")
2206
+	strInt64 := strconv.FormatInt(zoneType, 10)
2207
+	typeid, _ := strconv.Atoi(strInt64)
2208
+	zone := models.DeviceZone{
2209
+		Name: name,
2210
+		Type: typeid,
2211
+	}
2212
+	err := service.UpdatePartition(id, &zone)
2213
+	if err != nil {
2214
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2215
+		return
2216
+	}
2217
+	this.ServeSuccessJSON(map[string]interface{}{
2218
+		"zone": zone,
2219
+	})
2220
+}
2221
+
2222
+func (this *NewDialysisApiController) GetGroupDetail() {
2223
+	id, _ := this.GetInt64("id")
2224
+	groupDetail, err := service.GetGroupDetail(id)
2225
+	if err != nil {
2226
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2227
+		return
2228
+	}
2229
+	this.ServeSuccessJSON(map[string]interface{}{
2230
+		"groupDetail": groupDetail,
2231
+	})
2232
+
2233
+}
2234
+
2235
+func (this *NewDialysisApiController) UpdateGroup() {
2236
+	id, _ := this.GetInt64("id")
2237
+	name := this.GetString("name")
2238
+	group := models.DeviceGroup{Name: name}
2239
+	err := service.UpdateGroup(id, &group)
2240
+	if err != nil {
2241
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2242
+		return
2243
+	}
2244
+	this.ServeSuccessJSON(map[string]interface{}{
2245
+		"group": group,
2246
+	})
2247
+}
2248
+
2249
+func (this *NewDialysisApiController) GetBedDetail() {
2040 2250
 	adminUser := this.GetMobileAdminUserInfo()
2041
-	id := adminUser.Org.Id
2042
-	information, err := service.GetOrgInformation(id)
2251
+	orgid := adminUser.Org.Id
2252
+	id, _ := this.GetInt64("id")
2253
+	zone, _ := service.GetAllZoneOne(orgid)
2254
+	group, err := service.GetAllGroupOne(orgid)
2255
+	bedDetail, err := service.GetBedDetail(id)
2043 2256
 	if err != nil {
2044 2257
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2045 2258
 		return
2046 2259
 	}
2047 2260
 	this.ServeSuccessJSON(map[string]interface{}{
2048
-		"information": information,
2261
+		"zone":      zone,
2262
+		"group":     group,
2263
+		"bedDetail": bedDetail,
2264
+	})
2265
+}
2266
+
2267
+func (this *NewDialysisApiController) UpdatedBed() {
2268
+	id, _ := this.GetInt64("id")
2269
+	name := this.GetString("name")
2270
+	fmt.Println("name", name)
2271
+	zone, _ := this.GetInt64("zone")
2272
+	fmt.Println("zone", zone)
2273
+	group, _ := this.GetInt64("group")
2274
+	fmt.Println("group", group)
2275
+	number := models.DeviceNumber{
2276
+		Number:  name,
2277
+		ZoneID:  zone,
2278
+		GroupID: group,
2279
+	}
2280
+	err := service.UpdatedBed(id, &number)
2281
+	if err != nil {
2282
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2283
+		return
2284
+	}
2285
+	this.ServeSuccessJSON(map[string]interface{}{
2286
+		"number": number,
2049 2287
 	})
2050 2288
 }

+ 9 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go Voir le fichier

@@ -132,4 +132,13 @@ func NewMobileAPIControllersRegisterRouters() {
132 132
 	beego.Router("/m/api/patient/getallorganization", &NewDialysisApiController{}, "Get:GetAllOrganization")
133 133
 	beego.Router("/m/api/patient/getmyorganazition", &NewDialysisApiController{}, "Get:GetMyOrganazition")
134 134
 	beego.Router("/m/api/org/getorginformation", &NewDialysisApiController{}, "Get:GetOrgInformation")
135
+	beego.Router("/m/api/patient/getallorgtype", &NewDialysisApiController{}, "Get:GetAllOrgType")
136
+	beego.Router("/m/api/patient/editorg", &NewDialysisApiController{}, "Get:EditOrg")
137
+	beego.Router("/m/api/patient/getmyinforname", &NewDialysisApiController{}, "Get:GetMyInforName")
138
+	beego.Router("/m/api/patient/getpartiondetail", &NewDialysisApiController{}, "Get:GetPartionDetail")
139
+	beego.Router("/m/api/patient/updatepartition", &NewDialysisApiController{}, "Get:UpdatePartition")
140
+	beego.Router("/m/api/patient/getgroupdetail", &NewDialysisApiController{}, "Get:GetGroupDetail")
141
+	beego.Router("/m/api/patient/updategroup", &NewDialysisApiController{}, "Get:UpdateGroup")
142
+	beego.Router("/m/api/patient/getbeddetail", &NewDialysisApiController{}, "Get:GetBedDetail")
143
+	beego.Router("/m/api/patient/updatebed", &NewDialysisApiController{}, "Get:UpdatedBed")
135 144
 }

+ 32 - 0
models/org_models.go Voir le fichier

@@ -150,3 +150,35 @@ type SgjUserOrg struct {
150 150
 func (SgjUserOrg) TableName() string {
151 151
 	return "sgj_user_org"
152 152
 }
153
+
154
+type SgjUserDistrict struct {
155
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
156
+	Name      string `gorm:"column:name" json:"name" form:"name"`
157
+	Level     int64  `gorm:"column:level" json:"level" form:"level"`
158
+	Upid      int64  `gorm:"column:upid" json:"upid" form:"upid"`
159
+	Path      string `gorm:"column:path" json:"path" form:"path"`
160
+	Namepath  string `gorm:"column:namepath" json:"namepath" form:"namepath"`
161
+	Initial   string `gorm:"column:initial" json:"initial" form:"initial"`
162
+	Longitude string `gorm:"column:longitude" json:"longitude" form:"longitude"`
163
+	Latitude  string `gorm:"column:latitude" json:"latitude" form:"latitude"`
164
+	Adcode    int64  `gorm:"column:adcode" json:"adcode" form:"adcode"`
165
+}
166
+
167
+func (SgjUserDistrict) TableName() string {
168
+	return "sgj_user_district"
169
+}
170
+
171
+type SgjUserOrgType struct {
172
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
173
+	Name        string `gorm:"column:name" json:"name" form:"name"`
174
+	ShortName   string `gorm:"column:short_name" json:"short_name" form:"short_name"`
175
+	Pid         int64  `gorm:"column:pid" json:"pid" form:"pid"`
176
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
177
+	CreatedTime int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
178
+	UpdatedTime int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
179
+	SortNo      int64  `gorm:"column:sort_no" json:"sort_no" form:"sort_no"`
180
+}
181
+
182
+func (SgjUserOrgType) TableName() string {
183
+	return "sgj_user_org_type"
184
+}

+ 16 - 0
models/patient_models.go Voir le fichier

@@ -797,3 +797,19 @@ func (XtPatients) TableName() string {
797 797
 
798 798
 	return "xt_patients"
799 799
 }
800
+
801
+type SgjUserAdminLoginLog struct {
802
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
803
+	AdminUserId int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
804
+	OrgId       int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
805
+	AppId       int64  `gorm:"column:app_id" json:"app_id" form:"app_id"`
806
+	Ip          string `gorm:"column:ip" json:"ip" form:"ip"`
807
+	OperateType int64  `gorm:"column:operate_type" json:"operate_type" form:"operate_type"`
808
+	AppType     int64  `gorm:"column:app_type" json:"app_type" form:"app_type"`
809
+	Ctime       int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
810
+}
811
+
812
+func (SgjUserAdminLoginLog) TableName() string {
813
+
814
+	return "sgj_user_admin_login_log"
815
+}

+ 127 - 34
service/patientmanage_service.go Voir le fichier

@@ -495,7 +495,7 @@ func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int
495 495
 		db = db.Where("x.start_time>=?", start)
496 496
 	}
497 497
 	if end > 0 {
498
-		db = db.Where("start_time<=?", end)
498
+		db = db.Where("x.start_time<=?", end)
499 499
 	}
500 500
 	//offset := (page - 1) * limit
501 501
 	err = db.Group("x.id").Count(&total).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&doctoradvice).Error
@@ -504,39 +504,32 @@ func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int
504 504
 
505 505
 }
506 506
 
507
-func GetNewDoctorAdviceOne(patientID int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvice, total int64, date int64, err error) {
508
-
509
-	var advicesCount models.UserDoctorAdvicesCount
510
-
511
-	err = XTReadDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status =1", patientID, orgID).Select("count(distinct record_date) as count,patient_id").Scan(&advicesCount).Error
512
-
513
-	if err != nil {
514
-		return
507
+func GetNewDoctorAdviceOne(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvice, total int64, err error) {
508
+	fmt.Println("advicetype------------------------------", advice_type)
509
+	db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
510
+	table := UserReadDB().Table("sgj_user_admin_role as r")
511
+	fmt.Println("table", table)
512
+	if orgID > 0 {
513
+		db = db.Where("x.user_org_id=?", orgID)
515 514
 	}
516
-	total = advicesCount.Count
517
-	if total == 0 || page > total {
518
-		return
515
+	if patientID > 0 {
516
+		db = db.Where("x.patient_id = ?", patientID)
519 517
 	}
520
-
521
-	var Id models.AdviceDate
522
-
523
-	err = XTReadDB().Model(models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Select("record_date").Group("record_date").Order("created_time desc").Offset(page - 1).Limit(10).Scan(&Id).Error
524
-	if err != nil {
525
-		return
518
+	if advice_type > 0 {
519
+		db = db.Where("x.advice_type = ?", advice_type)
520
+	} else if advice_type == 0 {
521
+		db = db.Where("x.advice_type in (?)", []int{1, 3})
526 522
 	}
527
-
528
-	if Id.RecordDate == 0 {
529
-		return
523
+	if start > 0 {
524
+		db = db.Where("x.start_time>=?", start)
530 525
 	}
531
-
532
-	date = Id.RecordDate
533
-	fmt.Println("结构是==============", Id.RecordDate)
534
-	doctoradvice, err = GetAdvices(orgID, patientID, Id.RecordDate)
535
-	if err != nil {
536
-		return
526
+	if end > 0 {
527
+		db = db.Where("x.start_time<=?", end)
537 528
 	}
529
+	offset := (page - 1) * limit
530
+	err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&doctoradvice).Error
531
+	fmt.Print("错误是什么", err)
538 532
 	return
539
-
540 533
 }
541 534
 
542 535
 func GetDryWeight(patientid int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (dryWeight []*models.XtPatientDryweight, total int64, err error) {
@@ -889,14 +882,14 @@ func GetAllDoctorTwo(orgid int64, appid int64) (appRole []*models.SgjUserAdminRo
889 882
 func GetDoctorAdviceDetail(id int64, orgid int64) (advices []*models.DoctorAdvices, err error) {
890 883
 
891 884
 	db := XTReadDB().Table("xt_doctor_advice as x")
892
-	err = db.Order("x.id desc").Select("x.id,x.user_org_id,x.patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,x.single_dose,x.single_dose_unit,x.prescribing_number,x.prescribing_number_unit,x.delivery_way,x.execution_frequency,x.advice_doctor,x.status,x.created_time,x.updated_time,x.advice_affirm,x.remark,x.stop_time,x.stop_reason,x.stop_doctor,x.stop_state,x.parent_id,x.execution_time,x.execution_staff,x.execution_state,x.checker,x.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,s.name").Joins("left join xt_patients as s on s.id=x.patient_id").Where("x.groupno = ? and x.status = 1 and x.user_org_id = ?", id, orgid).Scan(&advices).Error
885
+	err = db.Order("x.id desc").Select("x.id,x.user_org_id,x.patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,x.single_dose,x.single_dose_unit,x.prescribing_number,x.prescribing_number_unit,x.delivery_way,x.execution_frequency,x.advice_doctor,x.status,x.created_time,x.updated_time,x.advice_affirm,x.remark,x.stop_time,x.stop_reason,x.stop_doctor,x.stop_state,x.parent_id,x.execution_time,x.execution_staff,x.execution_state,x.checker,x.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,s.name").Joins("left join xt_patients as s on s.id=x.patient_id").Where("x.start_time = ? and x.status = 1 and x.user_org_id = ?", id, orgid).Scan(&advices).Error
893 886
 
894 887
 	return advices, err
895 888
 }
896 889
 
897 890
 func DeleteManagement(groupid int64, orgid int64) error {
898 891
 
899
-	err := XTWriteDB().Model(models.DoctorAdvice{}).Where("groupno=? and user_org_id = ?", groupid, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
892
+	err := XTWriteDB().Model(models.DoctorAdvice{}).Where("start_time =? and user_org_id = ?", groupid, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
900 893
 	return err
901 894
 }
902 895
 
@@ -908,7 +901,7 @@ func DeleteChild(id int64) error {
908 901
 
909 902
 func DeletePatient(id int64) error {
910 903
 
911
-	err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id=? and parent_id = ?", id, id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
904
+	err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id=? or parent_id = ?", id, id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
912 905
 	return err
913 906
 }
914 907
 
@@ -1064,7 +1057,7 @@ func GetAllZone(orgid int64, page int64, limit int64) (zone []*models.DeviceZone
1064 1057
 		db = db.Where("x.org_id = ?", orgid)
1065 1058
 	}
1066 1059
 	offset := (page - 1) * limit
1067
-	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.type,n.number").Joins("left join xt_device_number as n on n.zone_id = x.id").Scan(&zone).Error
1060
+	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.type,n.number").Joins("left join xt_device_number as n on n.zone_id = x.id AND n.status = 1").Scan(&zone).Error
1068 1061
 	return zone, total, err
1069 1062
 }
1070 1063
 
@@ -1087,7 +1080,7 @@ func GetAllGroup(orgid int64, page int64, limit int64) (group []*models.DeviceGr
1087 1080
 		db = db.Where("x.org_id = ?", orgid)
1088 1081
 	}
1089 1082
 	offset := (page - 1) * limit
1090
-	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.status,x.ctime,x.mtime,n.number").Joins("left join xt_device_number as n on n.group_id = x.id").Scan(&group).Error
1083
+	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.status,x.ctime,x.mtime,n.number").Joins("left join xt_device_number as n on n.group_id = x.id And n.status = 1").Scan(&group).Error
1091 1084
 	return group, total, err
1092 1085
 }
1093 1086
 
@@ -1121,11 +1114,24 @@ func GetAllNumber(page int64, limit int64, orgid int64) (number []*models.Device
1121 1114
 		db = db.Where("x.org_id = ?", orgid)
1122 1115
 	}
1123 1116
 	offset := (page - 1) * limit
1124
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.number,x.group_id,x.zone_id,x.status").Find(&number).Error
1117
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime asc").Select("x.id,x.org_id,x.number,x.group_id,x.zone_id,x.status").Find(&number).Error
1125 1118
 
1126 1119
 	return number, total, err
1127 1120
 }
1128 1121
 
1122
+func GetSchedu(bedid int64, thetime int64, orgid int64) (*models.XtSchedule, error) {
1123
+	schedule := models.XtSchedule{}
1124
+	err := XTReadDB().Model(&schedule).Where("bed_id = ? and schedule_date = ? and user_org_id = ? and status = 1", bedid, thetime, orgid).Find(&schedule).Error
1125
+	if err == gorm.ErrRecordNotFound {
1126
+		return nil, err
1127
+	}
1128
+	if err != nil {
1129
+		return nil, err
1130
+	}
1131
+	return &schedule, nil
1132
+
1133
+}
1134
+
1129 1135
 func DeleteBed(id int64) error {
1130 1136
 	err := XTWriteDB().Model(models.DeviceNumber{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "ctime": time.Now().Unix()}).Error
1131 1137
 	return err
@@ -1178,3 +1184,90 @@ func GetOrgInformation(id int64) (models.SgjUserOrg, error) {
1178 1184
 	err := UserReadDB().Where("id=? and status = 1", id).Find(&org).Error
1179 1185
 	return org, err
1180 1186
 }
1187
+
1188
+func GetShortName(orgtype int64) (models.SgjUserOrgType, error) {
1189
+
1190
+	orgType := models.SgjUserOrgType{}
1191
+	err := UserReadDB().Model(&orgType).Where("id=? and status = 1", orgtype).Find(&orgType).Error
1192
+	return orgType, err
1193
+}
1194
+
1195
+func GetTypeName(id int64) (models.SgjUserOrgType, error) {
1196
+	orgType := models.SgjUserOrgType{}
1197
+	err := UserReadDB().Model(&orgType).Where("id=? and status = 1", id).Find(&orgType).Error
1198
+	return orgType, err
1199
+}
1200
+
1201
+func GetOrgProvince(id int64) (models.SgjUserDistrict, error) {
1202
+
1203
+	district := models.SgjUserDistrict{}
1204
+	err := UserReadDB().Model(&district).Where("id=?", id).Find(&district).Error
1205
+	return district, err
1206
+}
1207
+
1208
+func GetAllOrgType() (orgType []*models.SgjUserOrgType, err error) {
1209
+
1210
+	err = UserReadDB().Model(&models.SgjUserOrgType{}).Where("status= ? AND id = ? OR id = ? OR id = ? OR id = ? OR id = ? OR id = ?", 1, 1, 7, 12, 16, 21, 26).Find(&orgType).Error
1211
+	return
1212
+}
1213
+
1214
+func UpdateOrg(id int64, org models.SgjUserOrg) error {
1215
+
1216
+	err := UserWriteDB().Model(&org).Where("id = ?", id).Update(map[string]interface{}{"org_name": org.OrgName, "org_short_name": org.OrgShortName, "province": org.Province, "city": org.City, "district": org.District, "address": org.Address, "org_type": org.OrgType, "telephone": org.Telephone, "contact_name": org.ContactName, "mtime": time.Now().Unix()}).Error
1217
+	return err
1218
+}
1219
+
1220
+func GetMyInfoName(id int64) (models.SgjUserAdminRole, error) {
1221
+	role := models.SgjUserAdminRole{}
1222
+	err := UserReadDB().Model(&role).Where("id=? and status = 1", id).Find(&role).Error
1223
+	return role, err
1224
+}
1225
+
1226
+func GetAdminName(id int64) (models.AdminUser, error) {
1227
+	user := models.AdminUser{}
1228
+	err := UserReadDB().Model(&user).Where("id=? and status =1", id).Find(&user).Error
1229
+	return user, err
1230
+}
1231
+
1232
+func GetPartionDetail(id int64) (models.DeviceZone, error) {
1233
+
1234
+	zone := models.DeviceZone{}
1235
+	err := XTReadDB().Model(&zone).Where("id=? and status = 1", id).Find(&zone).Error
1236
+	return zone, err
1237
+}
1238
+
1239
+func UpdatePartition(id int64, zone *models.DeviceZone) error {
1240
+
1241
+	err := XTWriteDB().Model(&zone).Where("id=?", id).Update(map[string]interface{}{"name": zone.Name, "type": zone.Type, "mtime": time.Now().Unix()}).Error
1242
+	return err
1243
+}
1244
+
1245
+func GetGroupDetail(id int64) (models.DeviceGroup, error) {
1246
+	group := models.DeviceGroup{}
1247
+	err := XTReadDB().Model(&group).Where("id=? and status = 1", id).Find(&group).Error
1248
+	return group, err
1249
+}
1250
+
1251
+func UpdateGroup(id int64, group *models.DeviceGroup) error {
1252
+
1253
+	err := XTWriteDB().Model(&group).Where("id=?", id).Update(map[string]interface{}{"name": group.Name, "mtime": time.Now().Unix()}).Error
1254
+	return err
1255
+}
1256
+
1257
+func GetBedDetail(id int64) (models.DeviceNumber, error) {
1258
+	number := models.DeviceNumber{}
1259
+	err := XTReadDB().Model(&number).Where("id=? and status =1", id).Find(&number).Error
1260
+	return number, err
1261
+}
1262
+
1263
+func UpdatedBed(id int64, number *models.DeviceNumber) error {
1264
+
1265
+	err = XTWriteDB().Model(&number).Where("id=?", id).Update(map[string]interface{}{"number": number.Number, "zone_id": number.ZoneID, "group_id": number.GroupID, "mtime": time.Now().Unix()}).Error
1266
+	return err
1267
+}
1268
+
1269
+func CreateLoginLod(log *models.SgjUserAdminLoginLog) error {
1270
+
1271
+	err := UserWriteDB().Model(&log).Create(&log).Error
1272
+	return err
1273
+}