|
@@ -6,7 +6,14 @@ import (
|
6
|
6
|
"XT_New/models"
|
7
|
7
|
"XT_New/service"
|
8
|
8
|
"XT_New/utils"
|
|
9
|
+ "bytes"
|
|
10
|
+ "encoding/json"
|
9
|
11
|
"github.com/astaxie/beego"
|
|
12
|
+ "log"
|
|
13
|
+ "os"
|
|
14
|
+ "path"
|
|
15
|
+ "regexp"
|
|
16
|
+ "runtime"
|
10
|
17
|
"time"
|
11
|
18
|
)
|
12
|
19
|
|
|
@@ -123,13 +130,13 @@ func (this *MobileRegistController) CreateOrg() {
|
123
|
130
|
return
|
124
|
131
|
}
|
125
|
132
|
|
126
|
|
- name := this.GetString("name")
|
|
133
|
+ name := this.GetString("org_name")
|
127
|
134
|
shortName := name
|
128
|
|
- provinceName := this.GetString("province")
|
129
|
|
- cityName := this.GetString("city")
|
130
|
|
- districtName := this.GetString("district")
|
|
135
|
+ provinceName := this.GetString("provinces_name")
|
|
136
|
+ cityName := this.GetString("city_name")
|
|
137
|
+ districtName := this.GetString("district_name")
|
131
|
138
|
address := this.GetString("address")
|
132
|
|
- category, _ := this.GetInt64("category")
|
|
139
|
+ org_type := this.GetString("org_type")
|
133
|
140
|
contactName := this.GetString("contact_name")
|
134
|
141
|
|
135
|
142
|
//openXT, _ := this.GetBool("open_xt")
|
|
@@ -142,12 +149,12 @@ func (this *MobileRegistController) CreateOrg() {
|
142
|
149
|
openSCRM := false
|
143
|
150
|
openMall := false
|
144
|
151
|
|
145
|
|
- if len(name) == 0 || len(shortName) == 0 || len(contactName) == 0 || len(address) == 0 || len(provinceName) <= 0 || len(cityName) <= 0 || len(districtName) <= 0 || category <= 0 {
|
|
152
|
+ if len(name) == 0 || len(shortName) == 0 || len(contactName) == 0 || len(address) == 0 || len(provinceName) <= 0 || len(cityName) <= 0 || len(districtName) <= 0 || len(org_type) <= 0 {
|
146
|
153
|
this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
147
|
154
|
this.ServeJSON()
|
148
|
155
|
return
|
149
|
156
|
}
|
150
|
|
- orgPhone := this.GetString("org_phone")
|
|
157
|
+ orgPhone := this.GetString("telephone")
|
151
|
158
|
|
152
|
159
|
if len(orgPhone) > 0 {
|
153
|
160
|
if utils.PhoneRegexp().MatchString(orgPhone) == false {
|
|
@@ -189,6 +196,8 @@ func (this *MobileRegistController) CreateOrg() {
|
189
|
196
|
}
|
190
|
197
|
}
|
191
|
198
|
|
|
199
|
+ orgType := service.GetOrgTypeByName(org_type)
|
|
200
|
+
|
192
|
201
|
org := models.Org{
|
193
|
202
|
Creator: adminUser.Id,
|
194
|
203
|
OrgName: name,
|
|
@@ -197,7 +206,7 @@ func (this *MobileRegistController) CreateOrg() {
|
197
|
206
|
City: int64(cityID),
|
198
|
207
|
District: int64(districtID),
|
199
|
208
|
Address: address,
|
200
|
|
- OrgType: category,
|
|
209
|
+ OrgType: orgType.ID,
|
201
|
210
|
Telephone: orgPhone,
|
202
|
211
|
ContactName: contactName,
|
203
|
212
|
Claim: 1,
|
|
@@ -207,9 +216,115 @@ func (this *MobileRegistController) CreateOrg() {
|
207
|
216
|
ModifyTime: time.Now().Unix(),
|
208
|
217
|
}
|
209
|
218
|
|
210
|
|
- //创建机构,创建应用,创建显示配置, 创建打印模版
|
211
|
|
-
|
212
|
219
|
createErr := service.CreateOrg(&org, adminUser.Mobile, openXT, openCDM, openSCRM, openMall) // 创建机构以及所有类型的 app,如果有新类型的平台,则需要在这个方法里面把创建这一新类型的 app 的代码加上
|
|
220
|
+ var ids []int64
|
|
221
|
+
|
|
222
|
+ //数据初始化
|
|
223
|
+ //创建两个虚拟病人
|
|
224
|
+ patients := LoadConfig("./patient.json").patients
|
|
225
|
+ for _, item := range patients {
|
|
226
|
+ item.UserOrgId = org.Id
|
|
227
|
+ item.CreatedTime = time.Now().Unix()
|
|
228
|
+ item.UpdatedTime = time.Now().Unix()
|
|
229
|
+ item.Status = 1
|
|
230
|
+ service.CreateVMOrgPatient(item)
|
|
231
|
+ ids = append(ids, item.ID)
|
|
232
|
+ }
|
|
233
|
+
|
|
234
|
+ //创建1个分组
|
|
235
|
+ vmGroup := &models.VMDeviceGroup{
|
|
236
|
+ OrgId: org.Id,
|
|
237
|
+ Name: "测试分组1",
|
|
238
|
+ Status: 1,
|
|
239
|
+ Ctime: time.Now().Unix(),
|
|
240
|
+ Mtime: time.Now().Unix(),
|
|
241
|
+ }
|
|
242
|
+
|
|
243
|
+ service.CreateVMGroup(vmGroup)
|
|
244
|
+
|
|
245
|
+ //创建两个虚拟分区
|
|
246
|
+ vmZone1 := &models.VMDeviceZone{
|
|
247
|
+ OrgId: org.Id,
|
|
248
|
+ Name: "分区1",
|
|
249
|
+ Type: 1,
|
|
250
|
+ Status: 1,
|
|
251
|
+ Ctime: time.Now().Unix(),
|
|
252
|
+ Mtime: time.Now().Unix(),
|
|
253
|
+ }
|
|
254
|
+ service.CreateVMZone(vmZone1)
|
|
255
|
+
|
|
256
|
+ vmZone2 := &models.VMDeviceZone{
|
|
257
|
+ OrgId: org.Id,
|
|
258
|
+ Name: "分区2",
|
|
259
|
+ Type: 2,
|
|
260
|
+ Status: 1,
|
|
261
|
+ Ctime: time.Now().Unix(),
|
|
262
|
+ Mtime: time.Now().Unix(),
|
|
263
|
+ }
|
|
264
|
+ service.CreateVMZone(vmZone2)
|
|
265
|
+
|
|
266
|
+ //创建4个虚拟床位
|
|
267
|
+ vmDeviceNumber1 := &models.VMDeviceNumber{
|
|
268
|
+ OrgId: org.Id,
|
|
269
|
+ Number: "1",
|
|
270
|
+ GroupId: vmGroup.ID,
|
|
271
|
+ ZoneId: vmZone1.ID,
|
|
272
|
+ Status: 1,
|
|
273
|
+ Ctime: time.Now().Unix(),
|
|
274
|
+ Mtime: time.Now().Unix(),
|
|
275
|
+ }
|
|
276
|
+ service.CreateVMDeviceNumber(vmDeviceNumber1)
|
|
277
|
+
|
|
278
|
+ vmDeviceNumber2 := &models.VMDeviceNumber{
|
|
279
|
+ OrgId: org.Id,
|
|
280
|
+ Number: "2",
|
|
281
|
+ GroupId: vmGroup.ID,
|
|
282
|
+ ZoneId: vmZone2.ID,
|
|
283
|
+ Status: 1,
|
|
284
|
+ Ctime: time.Now().Unix(),
|
|
285
|
+ Mtime: time.Now().Unix(),
|
|
286
|
+ }
|
|
287
|
+ service.CreateVMDeviceNumber(vmDeviceNumber2)
|
|
288
|
+
|
|
289
|
+ //创建两个虚拟病人排班
|
|
290
|
+ stime, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
|
|
291
|
+ for index, id := range ids {
|
|
292
|
+ if index == 0 {
|
|
293
|
+ sch := &models.VMSchedule{
|
|
294
|
+ UserOrgId: org.Id,
|
|
295
|
+ PartitionId: vmZone1.ID,
|
|
296
|
+ BedId: vmDeviceNumber1.ID,
|
|
297
|
+ PatientId: id,
|
|
298
|
+ ScheduleDate: stime.Unix(),
|
|
299
|
+ ScheduleType: 1,
|
|
300
|
+ ScheduleWeek: int64(time.Now().Weekday()),
|
|
301
|
+ ModeId: 1,
|
|
302
|
+ Status: 1,
|
|
303
|
+ CreatedTime: time.Now().Unix(),
|
|
304
|
+ UpdatedTime: time.Now().Unix(),
|
|
305
|
+ }
|
|
306
|
+ service.CreateVMSch(sch)
|
|
307
|
+ }
|
|
308
|
+
|
|
309
|
+ if index == 1 {
|
|
310
|
+
|
|
311
|
+ sch := &models.VMSchedule{
|
|
312
|
+ UserOrgId: org.Id,
|
|
313
|
+ PartitionId: vmZone2.ID,
|
|
314
|
+ BedId: vmDeviceNumber2.ID,
|
|
315
|
+ PatientId: id,
|
|
316
|
+ ScheduleDate: stime.Unix(),
|
|
317
|
+ ScheduleType: 1,
|
|
318
|
+ ScheduleWeek: int64(time.Now().Weekday()),
|
|
319
|
+ ModeId: 1,
|
|
320
|
+ Status: 1,
|
|
321
|
+ CreatedTime: time.Now().Unix(),
|
|
322
|
+ UpdatedTime: time.Now().Unix(),
|
|
323
|
+ }
|
|
324
|
+ service.CreateVMSch(sch)
|
|
325
|
+ }
|
|
326
|
+ }
|
|
327
|
+
|
213
|
328
|
if createErr != nil {
|
214
|
329
|
utils.ErrorLog("mobile=%v的超级管理员创建机构失败:%v", adminUser.Mobile, createErr)
|
215
|
330
|
this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
|
|
@@ -243,16 +358,8 @@ func (this *MobileRegistController) Login() {
|
243
|
358
|
this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
244
|
359
|
this.ServeJSON()
|
245
|
360
|
} else {
|
246
|
|
- type MobileAdminUserInfo struct {
|
247
|
|
- AdminUser *models.AdminUser
|
248
|
|
- Org *models.Org
|
249
|
|
- App *models.OrgApp
|
250
|
|
- AppRole *models.App_Role
|
251
|
|
- Subscibe *models.ServeSubscibe
|
252
|
|
- TemplateInfo *models.GobalTemplate
|
253
|
|
- }
|
254
|
361
|
|
255
|
|
- mobileAdminUserInfo := &MobileAdminUserInfo{
|
|
362
|
+ mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
|
256
|
363
|
AdminUser: adminUser,
|
257
|
364
|
Org: nil,
|
258
|
365
|
App: nil,
|
|
@@ -286,3 +393,59 @@ func (this *MobileRegistController) Login() {
|
286
|
393
|
}
|
287
|
394
|
|
288
|
395
|
}
|
|
396
|
+
|
|
397
|
+type Config struct {
|
|
398
|
+ patients []*models.VMOrgPatients "json:patients"
|
|
399
|
+}
|
|
400
|
+
|
|
401
|
+func LoadConfig(dataFile string) *Config {
|
|
402
|
+ var config Config
|
|
403
|
+ _, filename, _, _ := runtime.Caller(1)
|
|
404
|
+ datapath := path.Join(path.Dir(filename), dataFile)
|
|
405
|
+ config_file, err := os.Open(datapath)
|
|
406
|
+ if err != nil {
|
|
407
|
+ emit("Failed to open config file '%s': %s\n", datapath, err)
|
|
408
|
+ return &config
|
|
409
|
+ }
|
|
410
|
+
|
|
411
|
+ fi, _ := config_file.Stat()
|
|
412
|
+
|
|
413
|
+ buffer := make([]byte, fi.Size())
|
|
414
|
+ _, err = config_file.Read(buffer)
|
|
415
|
+
|
|
416
|
+ buffer, err = StripComments(buffer) //去掉注释
|
|
417
|
+ if err != nil {
|
|
418
|
+ emit("Failed to strip comments from json: %s\n", err)
|
|
419
|
+ return &config
|
|
420
|
+ }
|
|
421
|
+
|
|
422
|
+ buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
|
|
423
|
+ err = json.Unmarshal(buffer, &config) //解析json格式数据
|
|
424
|
+ if err != nil {
|
|
425
|
+ emit("Failed unmarshalling json: %s\n", err)
|
|
426
|
+ return &config
|
|
427
|
+ }
|
|
428
|
+ return &config
|
|
429
|
+}
|
|
430
|
+
|
|
431
|
+func emit(msgfmt string, args ...interface{}) {
|
|
432
|
+ log.Printf(msgfmt, args...)
|
|
433
|
+}
|
|
434
|
+
|
|
435
|
+func StripComments(data []byte) ([]byte, error) {
|
|
436
|
+ data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
|
|
437
|
+ lines := bytes.Split(data, []byte("\n")) //split to muli lines
|
|
438
|
+ filtered := make([][]byte, 0)
|
|
439
|
+
|
|
440
|
+ for _, line := range lines {
|
|
441
|
+ match, err := regexp.Match(`^\s*#`, line)
|
|
442
|
+ if err != nil {
|
|
443
|
+ return nil, err
|
|
444
|
+ }
|
|
445
|
+ if !match {
|
|
446
|
+ filtered = append(filtered, line)
|
|
447
|
+ }
|
|
448
|
+ }
|
|
449
|
+
|
|
450
|
+ return bytes.Join(filtered, []byte("\n")), nil
|
|
451
|
+}
|