sso

org_controller.go 38KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. package controllers
  2. import (
  3. "SSO/enums"
  4. "SSO/models"
  5. "SSO/service"
  6. "SSO/utils"
  7. "bytes"
  8. "encoding/json"
  9. "fmt"
  10. "log"
  11. "os"
  12. "path"
  13. "regexp"
  14. "runtime"
  15. "strconv"
  16. "time"
  17. "github.com/astaxie/beego"
  18. )
  19. type OrgController struct {
  20. BaseController
  21. }
  22. // /org/create [get]
  23. func (this *OrgController) Create() {
  24. adminUserObj := this.GetSession("admin_user")
  25. if adminUserObj == nil {
  26. this.Redirect302(beego.URLFor("LoginController.PwdLogin"))
  27. return
  28. }
  29. adminUser := adminUserObj.(*models.AdminUser)
  30. if !adminUser.IsSuperAdmin {
  31. utils.ErrorLog("用户%v不是超级管理员,没有权限创建机构,应跳转到错误页", adminUser.Mobile)
  32. this.Redirect302(beego.URLFor("OrgController.CreateAppHint"))
  33. return
  34. }
  35. if didCreateOrg, checkCreateOrgErr := service.DidAdminUserCreateOrg(adminUser.Id); checkCreateOrgErr != nil {
  36. utils.ErrorLog("检查id = %v的用户是否创建了机构时出错:%v", adminUser.Id, checkCreateOrgErr)
  37. // this.Redirect302(beego.URLFor("LoginController.PwdLogin"))
  38. this.Abort("404")
  39. return
  40. } else {
  41. if didCreateOrg {
  42. // if didCreateApp, checkCreateAppErr := service.DidAdminUserOrgCreateApp(adminUser.Id); checkCreateAppErr != nil {
  43. // utils.ErrorLog("检查id = %v的用户是否创建了应用时出错:%v", adminUser.Id, checkCreateAppErr)
  44. // this.Redirect302(beego.URLFor("LoginController.Login"))
  45. // return
  46. // } else {
  47. // if didCreateApp {
  48. // // 前往该去的地方 LoginController.getRedirectURL()
  49. // }
  50. // }
  51. utils.ErrorLog("id = %v 的用户已创建机构,接下来应当前往应用页或者前往错误页", adminUser.Id)
  52. this.Redirect302(beego.URLFor("LoginController.CreateApp"))
  53. return
  54. }
  55. }
  56. cats, getCatErr := service.GetOrgCategoriesByPid(0)
  57. if getCatErr != nil {
  58. utils.ErrorLog("获取机构类型失败:%v", getCatErr)
  59. this.Abort("404")
  60. return
  61. }
  62. this.Data["categories"] = cats
  63. this.Data["avatar"] = "/static/images/userData.png"
  64. this.Data["user_name"] = adminUser.Mobile
  65. this.Data["province"] = service.GetAllProvince()
  66. this.Data["illness"], _ = service.GetIllness()
  67. this.SetTpl("new_main/create_org.html")
  68. }
  69. // /org/create/submit [post]
  70. // @param name:string
  71. // @param short_name:string 已和 name 同步,不需要传了
  72. // @param intro?:string
  73. // @param logo?:string
  74. // @param province:int
  75. // @param city:int
  76. // @param district:int
  77. // @param address:string
  78. // @param ill?:string ("病种1,病种2")
  79. // @param category:int
  80. // @param contact_name:string
  81. // @param org_phone?:string
  82. // @param business_week?:string
  83. // @param business_time?:string
  84. // @param business_state?:int
  85. // @param org_pics?:string (url1@@url2@@url3)
  86. // @param open_xt?:bool 是否开启血透系统
  87. // @param open_cdm?:bool 是否开启慢病系统
  88. // @param open_scrm?:bool 是否开启SCRM
  89. // @param open_mall?:bool 是否开启Mall
  90. func (this *OrgController) CreateSubmit() {
  91. adminUserObj := this.GetSession("admin_user")
  92. if adminUserObj == nil {
  93. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeLoginTimeout)
  94. this.ServeJSON()
  95. return
  96. }
  97. adminUser := adminUserObj.(*models.AdminUser)
  98. if !adminUser.IsSuperAdmin {
  99. utils.ErrorLog("用户%v不是超级管理员,没有权限创建机构", adminUser.Mobile)
  100. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  101. this.ServeJSON()
  102. return
  103. }
  104. if didCreateOrg, checkCreateOrgErr := service.DidAdminUserCreateOrg(adminUser.Id); checkCreateOrgErr != nil {
  105. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  106. this.ServeJSON()
  107. return
  108. } else if didCreateOrg {
  109. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateOrg)
  110. this.ServeJSON()
  111. return
  112. }
  113. name := this.GetString("name")
  114. shortName := name // this.GetString("short_name")
  115. intro := this.GetString("intro")
  116. logo := this.GetString("logo")
  117. province, _ := this.GetInt("province", 0)
  118. city, _ := this.GetInt("city", 0)
  119. district, _ := this.GetInt("district", 0)
  120. address := this.GetString("address")
  121. ill := this.GetString("ill")
  122. category, _ := this.GetInt64("category")
  123. contactName := this.GetString("contact_name")
  124. openXT, _ := this.GetBool("open_xt")
  125. openCDM, _ := this.GetBool("open_cdm")
  126. openSCRM, _ := this.GetBool("open_scrm")
  127. openMall, _ := this.GetBool("open_mall")
  128. user_name := this.GetString("user_name")
  129. if len(name) == 0 || len(shortName) == 0 || len(contactName) == 0 || len(address) == 0 || province <= 0 || city <= 0 || district <= 0 || category <= 0 || (!openXT && !openCDM && !openSCRM && !openMall) {
  130. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  131. this.ServeJSON()
  132. return
  133. }
  134. orgPhone := this.GetString("org_phone")
  135. businessWeek := this.GetString("business_week")
  136. businessTime := this.GetString("business_time")
  137. businessState, _ := this.GetInt64("business_state")
  138. orgPics := this.GetString("org_pics")
  139. if len(orgPhone) > 0 {
  140. if utils.CellPhoneRegexp().MatchString(orgPhone) == false {
  141. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. this.ServeJSON()
  143. return
  144. }
  145. }
  146. if businessState != 0 && businessState != 1 {
  147. businessState = 0
  148. }
  149. org := models.Org{
  150. Creator: adminUser.Id,
  151. OrgName: name,
  152. OrgShortName: shortName,
  153. OrgIntroduction: intro,
  154. OrgLogo: logo,
  155. Province: province,
  156. City: city,
  157. District: district,
  158. Address: address,
  159. Illness: ill,
  160. OrgType: category,
  161. OperatingState: businessState,
  162. Telephone: orgPhone,
  163. ContactName: contactName,
  164. BusinessWeek: businessWeek,
  165. BusinessTime: businessTime,
  166. Gallery: orgPics,
  167. Claim: 1,
  168. Evaluate: 5,
  169. Status: 1,
  170. CreateTime: time.Now().Unix(),
  171. ModifyTime: time.Now().Unix(),
  172. }
  173. fmt.Print("user_name ------------------------------------------------------------------", user_name)
  174. createErr := service.CreateOrg(&org, user_name, openXT, openCDM, openSCRM, openMall) // 创建机构以及所有类型的 app,如果有新类型的平台,则需要在这个方法里面把创建这一新类型的 app 的代码加上
  175. if createErr != nil {
  176. utils.ErrorLog("mobile=%v的超级管理员创建机构失败:%v", adminUser.Mobile, createErr)
  177. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  178. this.ServeJSON()
  179. } else {
  180. //初始化病人和排班相关数据
  181. InitPatientAndSchedule(&org)
  182. //初始化透析方案
  183. InitSystemPrescrption(&org)
  184. //初始化医嘱模版
  185. //InitAdviceTemplate(org)
  186. //初始化角色和权限
  187. InitRoleAndPurviews(&org)
  188. //初始化设备管理org
  189. InitEquitMentInformation(&org)
  190. //初始化显示配置和打印模版
  191. InitShowConfig(&org)
  192. redirectURL := beego.AppConfig.String("submodule_domain_dialysis_manage")
  193. //} else if openCDM {
  194. // redirectURL = beego.AppConfig.String("submodule_domain_cdm_manage")
  195. //} else if openSCRM {
  196. // redirectURL = beego.AppConfig.String("submodule_domain_patient_manage")
  197. //} else if openMall {
  198. // redirectURL = beego.AppConfig.String("submodule_domain_mall_manage")
  199. //}
  200. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  201. "url": redirectURL,
  202. })
  203. this.ServeJSON()
  204. }
  205. }
  206. // /org/app/create [get] 19.06.04 之前的管理应用逻辑,已弃用
  207. func (this *OrgController) CreateApp() {
  208. // this.Abort("404")
  209. // return
  210. adminUserObj := this.GetSession("admin_user")
  211. if adminUserObj == nil {
  212. this.Redirect302(beego.URLFor("LoginController.PwdLogin"))
  213. return
  214. }
  215. adminUser := adminUserObj.(*models.AdminUser)
  216. if !adminUser.IsSuperAdmin {
  217. utils.ErrorLog("用户%v不是超级管理员,没有权限创建应用,应跳转到错误页", adminUser.Mobile)
  218. this.Redirect302(beego.URLFor("OrgController.CreateAppHint"))
  219. return
  220. }
  221. org, getOrgErr := service.GetOrgWithAdminUserID(adminUser.Id)
  222. if getOrgErr != nil {
  223. utils.ErrorLog("获取id = %v的用户创建的机构时出错:%v", adminUser.Id, getOrgErr)
  224. // this.Redirect302(beego.URLFor("LoginController.PwdLogin"))
  225. this.Abort("404")
  226. return
  227. } else {
  228. if org == nil {
  229. this.Redirect302(beego.URLFor("OrgController.Create"))
  230. return
  231. } else {
  232. _, getAppsErr := service.GetOrgApps(adminUser.Id, org.Id)
  233. if getAppsErr != nil {
  234. utils.ErrorLog("获取id = %v的用户创建的机构下已创建的应用时出错:%v", adminUser.Id, getOrgErr)
  235. // this.Redirect302(beego.URLFor("LoginController.PwdLogin"))
  236. this.Abort("404")
  237. return
  238. } else {
  239. this.Data["avatar"] = org.OrgLogo //"/static/images/userData.png"
  240. this.Data["user_name"] = org.OrgShortName //adminUser.Mobile
  241. // 已创建的应用的信息
  242. //did_patient_manage_create := false
  243. //did_dialysis_manage_create := false
  244. //did_cdm_manage_create := false
  245. //did_mall_manage_create := false
  246. //for _, app := range apps {
  247. // if app.AppType == 1 {
  248. // did_patient_manage_create = true
  249. // } else if app.AppType == 3 {
  250. // did_dialysis_manage_create = true
  251. // } else if app.AppType == 4 {
  252. // did_cdm_manage_create = true
  253. // } else if app.AppType == 5 {
  254. // did_mall_manage_create = true
  255. // }
  256. //}
  257. //// 自动创建所有应用
  258. //if did_patient_manage_create == false {
  259. // err := service.CreateOrgApp(adminUser.Id, org.Id, 1, true)
  260. // if err != nil {
  261. // utils.ErrorLog("自动创建酷医聚客应用失败:%v", err)
  262. // this.Abort("404")
  263. // return
  264. // }
  265. //}
  266. //if did_dialysis_manage_create == false {
  267. // err := service.CreateOrgApp(adminUser.Id, org.Id, 3, true)
  268. // if err != nil {
  269. // utils.ErrorLog("自动创建透析管理应用失败:%v", err)
  270. // this.Abort("404")
  271. // return
  272. // }
  273. //}
  274. //if did_cdm_manage_create == false {
  275. // err := service.CreateOrgApp(adminUser.Id, org.Id, 4, true)
  276. // if err != nil {
  277. // utils.ErrorLog("自动创建慢病管理应用失败:%v", err)
  278. // this.Abort("404")
  279. // return
  280. // }
  281. //}
  282. //if did_mall_manage_create == false {
  283. // err := service.CreateOrgApp(adminUser.Id, org.Id, 5, true)
  284. // if err != nil {
  285. // utils.ErrorLog("自动创建微商城应用失败:%v", err)
  286. // this.Abort("404")
  287. // return
  288. // }
  289. //}
  290. this.Data["submodule_domain_patient_manage"] = beego.AppConfig.String("submodule_domain_patient_manage")
  291. this.Data["submodule_domain_dialysis_manage"] = beego.AppConfig.String("submodule_domain_dialysis_manage")
  292. this.Data["submodule_domain_cdm_manage"] = beego.AppConfig.String("submodule_domain_cdm_manage")
  293. this.Data["submodule_domain_mall_manage"] = beego.AppConfig.String("submodule_domain_mall_manage")
  294. this.SetTpl("new_main/manage_app.html")
  295. }
  296. }
  297. }
  298. }
  299. // /org/admin/apps [get]
  300. // @param org:int
  301. //func (this *OrgController) ViewApps() {
  302. // adminUserObj := this.GetSession("admin_user")
  303. // if adminUserObj == nil {
  304. // this.Redirect302(beego.URLFor("LoginController.PwdLogin"))
  305. // return
  306. // }
  307. // adminUser := adminUserObj.(*models.AdminUser)
  308. // orgID, _ := this.GetInt("org")
  309. // if orgID <= 0 {
  310. // this.Abort("404")
  311. // return
  312. // }
  313. // org, getOrgErr := service.GetOrgById(orgID)
  314. // if getOrgErr != nil {
  315. // utils.ErrorLog("获取id = %v的用户创建的机构时出错:%v", adminUser.Id, getOrgErr)
  316. // this.Abort("404")
  317. // return
  318. // } else {
  319. // if org == nil {
  320. // if adminUser.IsSuperAdmin == true {
  321. // this.Redirect302(beego.URLFor("OrgController.Create"))
  322. // } else {
  323. // this.Abort("404")
  324. // }
  325. // return
  326. // } else {
  327. // this.Data["avatar"] = org.OrgLogo
  328. // this.Data["user_name"] = org.OrgShortName
  329. // this.Data["is_super_admin"] = adminUser.IsSuperAdmin
  330. // this.Data["org_id"] = org.Id
  331. //
  332. // apps, getAppsErr := service.GetAdminUserAllOrgApp(adminUser.Id, org.Id)
  333. // if getAppsErr != nil {
  334. // utils.ErrorLog("获取 id = %v,org_id = %v 的用户有权限的应用时出错:%v", adminUser.Id, org.Id, getOrgErr)
  335. // this.Abort("404")
  336. // return
  337. // }
  338. // this.Data["scrm_role_exist"] = false
  339. // this.Data["xt_role_exist"] = false
  340. // this.Data["cdm_role_exist"] = false
  341. // this.Data["mall_role_exist"] = false
  342. // for _, app := range apps {
  343. // if app.AppType == 1 && app.OpenStatus == 1 {
  344. // this.Data["scrm_role_exist"] = true
  345. // }
  346. // if app.AppType == 3 && app.OpenStatus == 1 {
  347. // this.Data["xt_role_exist"] = true
  348. // }
  349. // if app.AppType == 4 && app.OpenStatus == 1 {
  350. // this.Data["cdm_role_exist"] = true
  351. // }
  352. // if app.AppType == 5 && app.OpenStatus == 1 {
  353. // this.Data["mall_role_exist"] = true
  354. // }
  355. // }
  356. //
  357. // this.Data["submodule_domain_patient_manage"] = beego.AppConfig.String("submodule_domain_patient_manage")
  358. // this.Data["submodule_domain_dialysis_manage"] = beego.AppConfig.String("submodule_domain_dialysis_manage")
  359. // this.Data["submodule_domain_cdm_manage"] = beego.AppConfig.String("submodule_domain_cdm_manage")
  360. // this.Data["submodule_domain_mall_manage"] = beego.AppConfig.String("submodule_domain_mall_manage")
  361. // this.SetTpl("new_main/manage_app.html")
  362. // }
  363. // }
  364. //}
  365. // /app/open [post]
  366. // @param type:int
  367. func (this *OrgController) OpenAppSubmit() {
  368. adminUserObj := this.GetSession("admin_user")
  369. if adminUserObj == nil {
  370. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeLoginTimeout)
  371. this.ServeJSON()
  372. return
  373. }
  374. adminUser := adminUserObj.(*models.AdminUser)
  375. if !adminUser.IsSuperAdmin {
  376. utils.ErrorLog("用户%v不是超级管理员,没有权限启用应用", adminUser.Mobile)
  377. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  378. this.ServeJSON()
  379. return
  380. }
  381. appType, _ := this.GetInt("type")
  382. if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
  383. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  384. this.ServeJSON()
  385. return
  386. }
  387. org, getOrgErr := service.GetOrgWithAdminUserID(adminUser.Id)
  388. if getOrgErr != nil {
  389. utils.ErrorLog("获取id = %v的用户创建的机构时出错:%v", adminUser.Id, getOrgErr)
  390. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  391. this.ServeJSON()
  392. return
  393. } else {
  394. if org == nil {
  395. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMissingOrg)
  396. this.ServeJSON()
  397. return
  398. } else {
  399. app, getAppErr := service.GetOrgAppWithType(adminUser.Id, org.Id, appType)
  400. if getAppErr != nil {
  401. utils.ErrorLog("获取 id=%v 的用户的类型为%v的应用时失败:%v", adminUser.Id, appType)
  402. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  403. this.ServeJSON()
  404. return
  405. }
  406. if app == nil {
  407. createAppErr := service.CreateOrgApp(adminUser.Id, org.Id, appType, true)
  408. if createAppErr != nil {
  409. utils.ErrorLog("id=%v的超级管理员创建类型为%v的应用时失败:%v", adminUser.Id, appType, createAppErr)
  410. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  411. this.ServeJSON()
  412. } else {
  413. this.Data["json"] = enums.MakeSuccessResponseJSON(nil)
  414. this.ServeJSON()
  415. }
  416. } else {
  417. if app.OpenStatus != 1 {
  418. app.OpenStatus = 1
  419. app.ModifyTime = time.Now().Unix()
  420. updateErr := service.SaveOrgApp(app)
  421. if updateErr != nil {
  422. utils.ErrorLog("id=%v的超级管理员开启类型为%v的应用时失败:%v", adminUser.Id, appType, updateErr)
  423. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  424. this.ServeJSON()
  425. return
  426. }
  427. }
  428. this.Data["json"] = enums.MakeSuccessResponseJSON(nil)
  429. this.ServeJSON()
  430. }
  431. }
  432. }
  433. }
  434. // /org/app/create/submit [post] 已废弃
  435. // @param app_type:int
  436. func (this *OrgController) CreateAppSubmit() {
  437. adminUserObj := this.GetSession("admin_user")
  438. if adminUserObj == nil {
  439. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeLoginTimeout)
  440. this.ServeJSON()
  441. return
  442. }
  443. adminUser := adminUserObj.(*models.AdminUser)
  444. if !adminUser.IsSuperAdmin {
  445. utils.ErrorLog("用户%v不是超级管理员,没有权限创建机构", adminUser.Mobile)
  446. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  447. this.ServeJSON()
  448. return
  449. }
  450. appType, _ := this.GetInt("app_type", 0)
  451. // if appType != 1 && appType != 3 && appType != 5 {
  452. // this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  453. // this.ServeJSON()
  454. // return
  455. // }
  456. if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
  457. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  458. this.ServeJSON()
  459. return
  460. }
  461. org, getOrgErr := service.GetOrgWithAdminUserID(adminUser.Id)
  462. if getOrgErr != nil {
  463. utils.ErrorLog("获取id = %v的用户创建的机构时出错:%v", adminUser.Id, getOrgErr)
  464. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  465. this.ServeJSON()
  466. return
  467. } else {
  468. if org == nil {
  469. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMissingOrg)
  470. this.ServeJSON()
  471. return
  472. } else {
  473. if didCreate, checkErr := service.DidOrgDidCreateAppWithType(org.Id, appType); checkErr != nil {
  474. utils.ErrorLog("检查id = %v的用户是否创建了类型为%v的应用时出错:%v", adminUser.Id, appType, checkErr)
  475. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  476. this.ServeJSON()
  477. return
  478. } else {
  479. if didCreate {
  480. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateApp)
  481. this.ServeJSON()
  482. return
  483. }
  484. }
  485. // 创建应用
  486. if createErr := service.CreateOrgApp(adminUser.Id, org.Id, appType, false); createErr != nil {
  487. utils.ErrorLog("id=%v的超级管理员创建类型为%v的应用时失败:%v", adminUser.Id, appType, createErr)
  488. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  489. this.ServeJSON()
  490. } else {
  491. this.Data["json"] = enums.MakeSuccessResponseJSON(nil)
  492. this.ServeJSON()
  493. }
  494. }
  495. }
  496. }
  497. type OrgCategoryController struct {
  498. BaseController
  499. }
  500. // /get_org_cat [get]
  501. // @param pid?:int
  502. func (this *OrgCategoryController) GetOrgCategories() {
  503. pid, _ := this.GetInt64("pid")
  504. if pid < 0 {
  505. pid = 0
  506. }
  507. cats, getCatErr := service.GetOrgCategoriesByPid(pid)
  508. if getCatErr != nil {
  509. utils.ErrorLog("获取机构类型失败:%v", getCatErr)
  510. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  511. this.ServeJSON()
  512. return
  513. } else {
  514. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  515. "list": cats,
  516. })
  517. this.ServeJSON()
  518. return
  519. }
  520. }
  521. // /create_app_hint [get]
  522. func (this *OrgController) CreateAppHint() {
  523. this.SetTpl("error/create_app_hint.html")
  524. }
  525. //func InitAdviceTemplate(org *models.Org) {
  526. //
  527. // //初始化医嘱模版
  528. // adviceInit := &models.AdviceInit{
  529. // UserOrgId: org.Id,
  530. // CreateTime: time.Now().Unix(),
  531. // UpdateTime: time.Now().Unix(),
  532. // Status: 1,
  533. // IsInit: 1,
  534. // }
  535. //
  536. // adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
  537. // for _, item := range adviceParentTemplate {
  538. // parentTemplate := &models.DoctorAdviceParentTemplate{
  539. // OrgId: org.Id,
  540. // Name: item.Name,
  541. // Status: 1,
  542. // CreatedTime: time.Now().Unix(),
  543. // UpdatedTime: time.Now().Unix(),
  544. // AdviceType: item.AdviceType,
  545. // }
  546. //
  547. // createErr := service.CreateDoctorParentTemplate(parentTemplate)
  548. // fmt.Println(parentTemplate.ID)
  549. // if createErr == nil {
  550. // for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
  551. // adviceTeplate := &models.DoctorAdviceTemplate{
  552. // OrgId: org.Id,
  553. // AdviceName: adviceTemplateItem.AdviceName,
  554. // AdviceDesc: adviceTemplateItem.AdviceDesc,
  555. // SingleDose: adviceTemplateItem.SingleDose,
  556. // SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
  557. // PrescribingNumber: adviceTemplateItem.PrescribingNumber,
  558. // PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
  559. // DeliveryWay: adviceTemplateItem.DeliveryWay,
  560. // ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
  561. // AdviceDoctor: adviceTemplateItem.AdviceDoctor,
  562. // Status: 1,
  563. // CreatedTime: time.Now().Unix(),
  564. // UpdatedTime: time.Now().Unix(),
  565. // TemplateId: parentTemplate.ID,
  566. // DrugSpec: adviceTemplateItem.DrugSpec,
  567. // DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
  568. // ParentId: adviceTemplateItem.ParentId,
  569. // AdviceType: adviceTemplateItem.AdviceType,
  570. // DayCount: adviceTemplateItem.DayCount,
  571. // WeekDays: adviceTemplateItem.WeekDays,
  572. // FrequencyType: adviceTemplateItem.FrequencyType,
  573. // }
  574. // createErr := service.CreateDoctorTemplate(adviceTeplate)
  575. //
  576. // if createErr == nil {
  577. // for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
  578. // adviceTeplate := &models.DoctorAdviceTemplate{
  579. // OrgId: org.Id,
  580. // AdviceName: childItem.AdviceName,
  581. // AdviceDesc: childItem.AdviceDesc,
  582. // SingleDose: childItem.SingleDose,
  583. // SingleDoseUnit: childItem.SingleDoseUnit,
  584. // PrescribingNumber: childItem.PrescribingNumber,
  585. // PrescribingNumberUnit: childItem.PrescribingNumberUnit,
  586. // DeliveryWay: childItem.DeliveryWay,
  587. // ExecutionFrequency: childItem.ExecutionFrequency,
  588. // AdviceDoctor: childItem.AdviceDoctor,
  589. // Status: 1,
  590. // CreatedTime: time.Now().Unix(),
  591. // UpdatedTime: time.Now().Unix(),
  592. // TemplateId: parentTemplate.ID,
  593. // DrugSpec: childItem.DrugSpec,
  594. // DrugSpecUnit: childItem.DrugSpecUnit,
  595. // ParentId: adviceTeplate.ID,
  596. // AdviceType: childItem.AdviceType,
  597. // DayCount: childItem.DayCount,
  598. // WeekDays: childItem.WeekDays,
  599. // FrequencyType: childItem.FrequencyType,
  600. // }
  601. // service.CreateDoctorTemplate(adviceTeplate)
  602. // }
  603. // }
  604. // }
  605. // }
  606. // }
  607. // service.CreateAdviceInitConfig(adviceInit)
  608. //
  609. //}
  610. func InitSystemPrescrption(org *models.Org) {
  611. //初始化透析方案
  612. prescriptions := LoadPrescriptionConfig("./system_dialysis_prescription.json").Prescription
  613. for _, item := range prescriptions {
  614. item.UserOrgId = int64(org.Id)
  615. item.CreatedTime = time.Now().Unix()
  616. item.UpdatedTime = time.Now().Unix()
  617. service.CreateVMPrescription(item)
  618. }
  619. }
  620. func InitPatientAndSchedule(org *models.Org) {
  621. var ids []int64
  622. //数据初始化
  623. //创建两个虚拟病人
  624. patients := LoadPatientConfig("./patient.json").Patients
  625. for _, item := range patients {
  626. item.UserOrgId = int64(org.Id)
  627. item.CreatedTime = time.Now().Unix()
  628. item.UpdatedTime = time.Now().Unix()
  629. item.Status = 1
  630. service.CreateVMOrgPatient(item)
  631. ids = append(ids, item.ID)
  632. }
  633. //创建两个血透的虚拟病人到新表
  634. fmt.Print("patients", patients)
  635. for _, it := range patients {
  636. patientsNew := models.XtPatientsNew{
  637. UserOrgId: int64(org.Id),
  638. CreatedTime: time.Now().Unix(),
  639. UpdatedTime: time.Now().Unix(),
  640. Status: 1,
  641. BloodId: it.ID,
  642. BloodPatients: 1,
  643. Name: it.Name,
  644. Avatar: it.Avatar,
  645. PatientType: it.PatientType,
  646. Source: it.Source,
  647. Lapseto: it.Lapseto,
  648. Gender: it.Gender,
  649. Nation: it.Nation,
  650. NativePlace: it.NativePlace,
  651. MaritalStatus: it.MaritalStatus,
  652. IdCardNo: it.IdCardNo,
  653. Birthday: it.Birthday,
  654. ReimbursementWayId: it.ReimbursementWayId,
  655. HealthCareNo: it.HealthCareNo,
  656. Phone: it.Phone,
  657. HomeAddress: it.HomeAddress,
  658. WorkUnit: it.WorkUnit,
  659. UnitAddress: it.UnitAddress,
  660. Children: it.Children,
  661. IsHospitalFirstDialysis: it.IsHospitalFirstDialysis,
  662. FirstDialysisDate: it.FirstDialysisDate,
  663. BindingState: it.BindingState,
  664. PatientComplains: it.PatientComplains,
  665. PresentHistory: it.PresentHistory,
  666. PastHistory: it.PastHistory,
  667. Temperature: it.Temperature,
  668. Pulse: it.Pulse,
  669. Respiratory: it.Respiratory,
  670. Age: it.Age,
  671. IsOpenRemind: it.IsOpenRemind,
  672. TellPhone: it.TellPhone,
  673. FirstTreatmentDate: it.FirstTreatmentDate,
  674. ContactName: it.ContactName,
  675. }
  676. service.CreateVMOrgNewPatient(&patientsNew)
  677. }
  678. //创建1个分组
  679. vmGroup := &models.VMDeviceGroup{
  680. OrgId: int64(org.Id),
  681. Name: "护理一组",
  682. Status: 1,
  683. Ctime: time.Now().Unix(),
  684. Mtime: time.Now().Unix(),
  685. }
  686. service.CreateVMGroup(vmGroup)
  687. //创建两个虚拟分区
  688. vmZone1 := &models.VMDeviceZone{
  689. OrgId: int64(org.Id),
  690. Name: "A区",
  691. Type: 1,
  692. Status: 1,
  693. Ctime: time.Now().Unix(),
  694. Mtime: time.Now().Unix(),
  695. }
  696. service.CreateVMZone(vmZone1)
  697. vmZone2 := &models.VMDeviceZone{
  698. OrgId: int64(org.Id),
  699. Name: "B区",
  700. Type: 2,
  701. Status: 1,
  702. Ctime: time.Now().Unix(),
  703. Mtime: time.Now().Unix(),
  704. }
  705. service.CreateVMZone(vmZone2)
  706. //创建2个虚拟床位
  707. vmDeviceNumber1 := &models.VMDeviceNumber{
  708. OrgId: int64(org.Id),
  709. Number: "1号床",
  710. GroupId: vmGroup.ID,
  711. ZoneId: vmZone1.ID,
  712. Status: 1,
  713. Ctime: time.Now().Unix(),
  714. Mtime: time.Now().Unix(),
  715. }
  716. service.CreateVMDeviceNumber(vmDeviceNumber1)
  717. vmDeviceNumber2 := &models.VMDeviceNumber{
  718. OrgId: int64(org.Id),
  719. Number: "2号床",
  720. GroupId: vmGroup.ID,
  721. ZoneId: vmZone2.ID,
  722. Status: 1,
  723. Ctime: time.Now().Unix(),
  724. Mtime: time.Now().Unix(),
  725. }
  726. service.CreateVMDeviceNumber(vmDeviceNumber2)
  727. var dates []int64
  728. mondayDate := GetDateOfWeek(1)
  729. tuesdayDate := GetDateOfWeek(2)
  730. wednesdayDate := GetDateOfWeek(3)
  731. thursdayDate := GetDateOfWeek(4)
  732. fridayDate := GetDateOfWeek(5)
  733. saturdayDate := GetDateOfWeek(6)
  734. sundayDate := GetDateOfWeek(7)
  735. dates = append(dates, mondayDate)
  736. dates = append(dates, tuesdayDate)
  737. dates = append(dates, wednesdayDate)
  738. dates = append(dates, thursdayDate)
  739. dates = append(dates, fridayDate)
  740. dates = append(dates, saturdayDate)
  741. dates = append(dates, sundayDate)
  742. //创建两个虚拟病人本周的排班
  743. //stime, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  744. for week_type, date := range dates {
  745. for index, id := range ids {
  746. if index == 0 {
  747. sch := &models.VMSchedule{
  748. UserOrgId: int64(org.Id),
  749. PartitionId: vmZone1.ID,
  750. BedId: vmDeviceNumber1.ID,
  751. PatientId: id,
  752. ScheduleDate: date,
  753. ScheduleType: 1,
  754. ScheduleWeek: int64(week_type + 1),
  755. ModeId: 1,
  756. Status: 1,
  757. CreatedTime: time.Now().Unix(),
  758. UpdatedTime: time.Now().Unix(),
  759. }
  760. service.CreateVMSch(sch)
  761. }
  762. if index == 1 {
  763. sch := &models.VMSchedule{
  764. UserOrgId: int64(org.Id),
  765. PartitionId: vmZone2.ID,
  766. BedId: vmDeviceNumber2.ID,
  767. PatientId: id,
  768. ScheduleDate: date,
  769. ScheduleType: 2,
  770. ScheduleWeek: int64(week_type + 1),
  771. ModeId: 1,
  772. Status: 1,
  773. CreatedTime: time.Now().Unix(),
  774. UpdatedTime: time.Now().Unix(),
  775. }
  776. service.CreateVMSch(sch)
  777. }
  778. }
  779. }
  780. //创建单周模版
  781. //1.创建模版模式
  782. mode := &models.VMPatientScheduleTemplateMode{
  783. OrgId: int64(org.Id),
  784. Mode: 1,
  785. ExecuteTimes: 0,
  786. Status: 1,
  787. Ctime: time.Now().Unix(),
  788. Mtime: time.Now().Unix(),
  789. }
  790. service.CreateVMSchMode(mode)
  791. //2.创建模版id
  792. templaeIdOne := &models.VMPatientScheduleTemplateId{
  793. OrgId: int64(org.Id),
  794. Status: 1,
  795. Ctime: time.Now().Unix(),
  796. Mtime: time.Now().Unix(),
  797. }
  798. service.CreateVMSchTemplateId(templaeIdOne)
  799. templaeIdTwo := &models.VMPatientScheduleTemplateId{
  800. OrgId: int64(org.Id),
  801. Status: 1,
  802. Ctime: time.Now().Unix(),
  803. Mtime: time.Now().Unix(),
  804. }
  805. service.CreateVMSchTemplateId(templaeIdTwo)
  806. //3.创建单周排班模版
  807. items := LoadSchTemplateConfig("./schedule_template.json").Item
  808. for _, item := range items {
  809. if item.TimeType == 1 {
  810. item.OrgId = int64(org.Id)
  811. item.TemplateId = templaeIdOne.ID
  812. item.DeviceNumberId = vmDeviceNumber1.ID
  813. item.PatientId = ids[0]
  814. item.Status = 1
  815. item.Ctime = time.Now().Unix()
  816. item.Mtime = time.Now().Unix()
  817. } else if item.TimeType == 2 {
  818. item.OrgId = int64(org.Id)
  819. item.TemplateId = templaeIdOne.ID
  820. item.DeviceNumberId = vmDeviceNumber2.ID
  821. item.PatientId = ids[1]
  822. item.Status = 1
  823. item.Ctime = time.Now().Unix()
  824. item.Mtime = time.Now().Unix()
  825. }
  826. service.CreateVMSchTemplate(item)
  827. }
  828. }
  829. func InitRoleAndPurviews(org *models.Org) {
  830. roles := LoadRoleConfig("./role.json").Roles
  831. app, _ := service.GetOrgApp(org.Id, 3)
  832. for _, item := range roles {
  833. role := &models.Role{
  834. RoleName: item.RoleName,
  835. RoleIntro: item.RoleIntroduction,
  836. Creator: 0,
  837. OrgId: org.Id,
  838. AppId: app.Id,
  839. IsSuperAdmin: false,
  840. Status: 1,
  841. CreateTime: time.Now().Unix(),
  842. ModifyTime: time.Now().Unix(),
  843. Number: item.Number,
  844. IsSystem: item.IsSystem,
  845. }
  846. err := service.CreateOrgRole(role)
  847. if err == nil {
  848. purview := &models.RolePurview{
  849. RoleId: role.Id,
  850. OrgId: org.Id,
  851. AppId: role.AppId,
  852. PurviewIds: item.PurviewIds,
  853. Status: 1,
  854. CreateTime: time.Now().Unix(),
  855. ModifyTime: time.Now().Unix(),
  856. }
  857. func_purview := &models.SgjUserRoleFuncPurview{
  858. RoleId: int64(role.Id),
  859. OrgId: int64(org.Id),
  860. AppId: int64(role.AppId),
  861. PurviewIds: item.FuncIds,
  862. Status: 1,
  863. Ctime: time.Now().Unix(),
  864. Mtime: time.Now().Unix(),
  865. }
  866. service.CreateRolePurview(purview)
  867. service.CreateFuncRolePurview(func_purview)
  868. }
  869. }
  870. }
  871. type RoleConfig struct {
  872. Roles []*models.VMUserRoleAndPurview "json:roles"
  873. }
  874. type PatientConfig struct {
  875. Patients []*models.VMOrgPatients "json:patients"
  876. }
  877. type SchTemplateConfig struct {
  878. Item []*models.VMPatientScheduleTemplateItem "json:item"
  879. }
  880. type PrescriptionConfig struct {
  881. Prescription []*models.SystemPrescription "json:prescription"
  882. }
  883. func LoadRoleConfig(dataFile string) *RoleConfig {
  884. var config RoleConfig
  885. _, filename, _, _ := runtime.Caller(1)
  886. datapath := path.Join(path.Dir(filename), dataFile)
  887. config_file, err := os.Open(datapath)
  888. if err != nil {
  889. emit("Failed to open config file '%s': %s\n", datapath, err)
  890. return &config
  891. }
  892. fi, _ := config_file.Stat()
  893. buffer := make([]byte, fi.Size())
  894. _, err = config_file.Read(buffer)
  895. buffer, err = StripComments(buffer) //去掉注释
  896. if err != nil {
  897. emit("Failed to strip comments from json: %s\n", err)
  898. return &config
  899. }
  900. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  901. err = json.Unmarshal(buffer, &config) //解析json格式数据
  902. if err != nil {
  903. emit("Failed unmarshalling json: %s\n", err)
  904. return &config
  905. }
  906. return &config
  907. }
  908. func LoadPatientConfig(dataFile string) *PatientConfig {
  909. var config PatientConfig
  910. _, filename, _, _ := runtime.Caller(1)
  911. datapath := path.Join(path.Dir(filename), dataFile)
  912. config_file, err := os.Open(datapath)
  913. if err != nil {
  914. emit("Failed to open config file '%s': %s\n", datapath, err)
  915. return &config
  916. }
  917. fi, _ := config_file.Stat()
  918. buffer := make([]byte, fi.Size())
  919. _, err = config_file.Read(buffer)
  920. buffer, err = StripComments(buffer) //去掉注释
  921. if err != nil {
  922. emit("Failed to strip comments from json: %s\n", err)
  923. return &config
  924. }
  925. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  926. err = json.Unmarshal(buffer, &config) //解析json格式数据
  927. if err != nil {
  928. emit("Failed unmarshalling json: %s\n", err)
  929. return &config
  930. }
  931. return &config
  932. }
  933. func LoadSchTemplateConfig(dataFile string) *SchTemplateConfig {
  934. var config SchTemplateConfig
  935. _, filename, _, _ := runtime.Caller(1)
  936. datapath := path.Join(path.Dir(filename), dataFile)
  937. config_file, err := os.Open(datapath)
  938. if err != nil {
  939. emit("Failed to open config file '%s': %s\n", datapath, err)
  940. return &config
  941. }
  942. fi, _ := config_file.Stat()
  943. buffer := make([]byte, fi.Size())
  944. _, err = config_file.Read(buffer)
  945. buffer, err = StripComments(buffer) //去掉注释
  946. if err != nil {
  947. emit("Failed to strip comments from json: %s\n", err)
  948. return &config
  949. }
  950. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  951. err = json.Unmarshal(buffer, &config) //解析json格式数据
  952. if err != nil {
  953. emit("Failed unmarshalling json: %s\n", err)
  954. return &config
  955. }
  956. return &config
  957. }
  958. func LoadPrescriptionConfig(dataFile string) *PrescriptionConfig {
  959. var config PrescriptionConfig
  960. _, filename, _, _ := runtime.Caller(1)
  961. datapath := path.Join(path.Dir(filename), dataFile)
  962. config_file, err := os.Open(datapath)
  963. if err != nil {
  964. emit("Failed to open config file '%s': %s\n", datapath, err)
  965. return &config
  966. }
  967. fi, _ := config_file.Stat()
  968. buffer := make([]byte, fi.Size())
  969. _, err = config_file.Read(buffer)
  970. buffer, err = StripComments(buffer) //去掉注释
  971. if err != nil {
  972. emit("Failed to strip comments from json: %s\n", err)
  973. return &config
  974. }
  975. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  976. err = json.Unmarshal(buffer, &config) //解析json格式数据
  977. if err != nil {
  978. emit("Failed unmarshalling json: %s\n", err)
  979. return &config
  980. }
  981. return &config
  982. }
  983. func emit(msgfmt string, args ...interface{}) {
  984. log.Printf(msgfmt, args...)
  985. }
  986. func StripComments(data []byte) ([]byte, error) {
  987. data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
  988. lines := bytes.Split(data, []byte("\n")) //split to muli lines
  989. filtered := make([][]byte, 0)
  990. for _, line := range lines {
  991. match, err := regexp.Match(`^\s*#`, line)
  992. if err != nil {
  993. return nil, err
  994. }
  995. if !match {
  996. filtered = append(filtered, line)
  997. }
  998. }
  999. return bytes.Join(filtered, []byte("\n")), nil
  1000. }
  1001. func GetDateOfWeek(week_type int) (weekMonday int64) {
  1002. thisTime := time.Now()
  1003. weekDay := int(thisTime.Weekday())
  1004. if weekDay == 0 {
  1005. weekDay = 7
  1006. }
  1007. weekEnd := 7 - weekDay
  1008. weekStart := weekEnd - 6
  1009. weekTitle := make([]string, 0)
  1010. days := make([]string, 0)
  1011. for index := weekStart; index <= weekEnd; index++ {
  1012. theDay := thisTime.AddDate(0, 0, index)
  1013. indexYear, indexMonthTime, indexDay := theDay.Date()
  1014. indexMonth := int(indexMonthTime)
  1015. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1016. weekTitle = append(weekTitle, indexWeek)
  1017. days = append(days, theDay.Format("2006-01-02"))
  1018. }
  1019. var targetDayStr string
  1020. switch week_type {
  1021. case 1:
  1022. targetDayStr = days[0]
  1023. break
  1024. case 2:
  1025. targetDayStr = days[1]
  1026. break
  1027. case 3:
  1028. targetDayStr = days[2]
  1029. break
  1030. case 4:
  1031. targetDayStr = days[3]
  1032. break
  1033. case 5:
  1034. targetDayStr = days[4]
  1035. break
  1036. case 6:
  1037. targetDayStr = days[5]
  1038. break
  1039. case 7:
  1040. targetDayStr = days[6]
  1041. break
  1042. }
  1043. targetDay, _ := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  1044. return targetDay.Unix()
  1045. }
  1046. func InitEquitMentInformation(org *models.Org) {
  1047. //添加设备型号
  1048. mode := models.VMDeviceMode{
  1049. DeviceMode: "5008S",
  1050. Status: 1,
  1051. UserOrgId: int64(org.Id),
  1052. Ctime: time.Now().Unix(),
  1053. Mtime: time.Now().Unix(),
  1054. }
  1055. service.CreatedDeviceMode(&mode)
  1056. deviceMode := models.VMDeviceMode{
  1057. DeviceMode: "4008S",
  1058. Status: 1,
  1059. UserOrgId: int64(org.Id),
  1060. Ctime: time.Now().Unix(),
  1061. Mtime: time.Now().Unix(),
  1062. }
  1063. service.CreatedDeviceMode(&deviceMode)
  1064. firstDeviceMode, _ := service.GetFirstDeviceMode(int64(org.Id))
  1065. //获取机构下对应的第一数据
  1066. number, _ := service.GetFirstBedNumber(int64(org.Id))
  1067. //添加设备
  1068. deviceAddmacher := models.VmDeviceAddmacher{
  1069. SerialNumber: "8VSAHE13",
  1070. DeviceType: 1,
  1071. BedId: number.ID,
  1072. DeviceName: "费森尤斯",
  1073. UnitType: firstDeviceMode.ID,
  1074. MachineStatus: 1,
  1075. Status: 1,
  1076. UserOrgId: int64(org.Id),
  1077. Ctime: time.Now().Unix(),
  1078. }
  1079. service.CreateDeviceAddMacher(&deviceAddmacher)
  1080. macher, _ := service.GetLastMacher(int64(org.Id))
  1081. fmt.Print(macher.ID)
  1082. treatmentmode := models.VmDeviceTreatmentmode{
  1083. MachineId: macher.ID,
  1084. Status: 1,
  1085. Ctime: time.Now().Unix(),
  1086. Mtime: time.Now().Unix(),
  1087. UserOrgId: int64(org.Id),
  1088. TreateMode: 1,
  1089. }
  1090. service.CreatedTreateMode(&treatmentmode)
  1091. treatmentmodeone := models.VmDeviceTreatmentmode{
  1092. MachineId: macher.ID,
  1093. Status: 1,
  1094. Ctime: time.Now().Unix(),
  1095. Mtime: time.Now().Unix(),
  1096. UserOrgId: int64(org.Id),
  1097. TreateMode: 2,
  1098. }
  1099. service.CreatedTreateMode(&treatmentmodeone)
  1100. treatmentmodetwo := models.VmDeviceTreatmentmode{
  1101. MachineId: macher.ID,
  1102. Status: 1,
  1103. Ctime: time.Now().Unix(),
  1104. Mtime: time.Now().Unix(),
  1105. UserOrgId: int64(org.Id),
  1106. TreateMode: 3,
  1107. }
  1108. service.CreatedTreateMode(&treatmentmodetwo)
  1109. treatmentmodethree := models.VmDeviceTreatmentmode{
  1110. MachineId: macher.ID,
  1111. Status: 1,
  1112. Ctime: time.Now().Unix(),
  1113. Mtime: time.Now().Unix(),
  1114. UserOrgId: int64(org.Id),
  1115. TreateMode: 4,
  1116. }
  1117. service.CreatedTreateMode(&treatmentmodethree)
  1118. treatmentmodefour := models.VmDeviceTreatmentmode{
  1119. MachineId: macher.ID,
  1120. Status: 1,
  1121. Ctime: time.Now().Unix(),
  1122. Mtime: time.Now().Unix(),
  1123. UserOrgId: int64(org.Id),
  1124. TreateMode: 5,
  1125. }
  1126. service.CreatedTreateMode(&treatmentmodefour)
  1127. treatmentmodefive := models.VmDeviceTreatmentmode{
  1128. MachineId: macher.ID,
  1129. Status: 1,
  1130. Ctime: time.Now().Unix(),
  1131. Mtime: time.Now().Unix(),
  1132. UserOrgId: int64(org.Id),
  1133. TreateMode: 12,
  1134. }
  1135. service.CreatedTreateMode(&treatmentmodefive)
  1136. }
  1137. func InitShowConfig(org *models.Org) {
  1138. service.BatchInsertFiledSystemConfig(int64(org.Id))
  1139. template := &models.VMGobalTemplate{
  1140. Status: 1,
  1141. Ctime: time.Now().Unix(),
  1142. Mtime: time.Now().Unix(),
  1143. OrgId: int64(org.Id),
  1144. TemplateId: 2,
  1145. }
  1146. service.CreateVMPrintTemplate(template)
  1147. }