role_controller.go 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542
  1. package controllers
  2. import (
  3. "fmt"
  4. "github.com/jinzhu/gorm"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "XT_New/enums"
  9. "XT_New/models"
  10. "XT_New/service"
  11. "github.com/astaxie/beego"
  12. )
  13. func RoleAPIControllerRegistRouters() {
  14. beego.Router("/api/roles", &RoleAPIController{}, "get:GetRoles")
  15. beego.Router("/api/role/create", &RoleAPIController{}, "post:CreateRole")
  16. beego.Router("/api/role/modify", &RoleAPIController{}, "post:ModifyRole")
  17. beego.Router("/api/role/setstatus", &RoleAPIController{}, "post:ModifyRoleStatus")
  18. beego.Router("/role/purview/editinit", &RoleAPIController{}, "get:EditPurviewInitData")
  19. beego.Router("/role/purview/edit", &RoleAPIController{}, "post:EditPurview")
  20. beego.Router("/api/adminmain", &RoleAPIController{}, "get:AdminMainView")
  21. beego.Router("/api/admins", &RoleAPIController{}, "get:Admins")
  22. beego.Router("/api/admin/addinit", &RoleAPIController{}, "get:AddAdminInitData")
  23. beego.Router("/api/admin/add", &RoleAPIController{}, "get:AddAdmin")
  24. beego.Router("/api/admin/editinit", &RoleAPIController{}, "get:EditAdminInitData")
  25. beego.Router("/api/admin/edit", &RoleAPIController{}, "get:EditAdmin")
  26. beego.Router("/api/admin/setstatus", &RoleAPIController{}, "post:AdminSetStatus")
  27. beego.Router("/api/admin/specialpermission/initdata", &RoleAPIController{}, "get:SpecialPermissionInitData")
  28. beego.Router("/api/admin/specialpermission/dialysisrecord/submit", &RoleAPIController{}, "post:SubmitDialysisRecordPermission")
  29. beego.Router("/api/roles/list", &RoleAPIController{}, "get:GetAllOrgRole")
  30. beego.Router("/api/staff", &RoleAPIController{}, "get:GetAllOrgUser")
  31. beego.Router("/api/role/addStaff", &RoleAPIController{}, "post:AddRoleStaff")
  32. beego.Router("/api/role/staff", &RoleAPIController{}, "get:GetRoleStaff")
  33. beego.Router("/api/role", &RoleAPIController{}, "get:GetRoleInfo")
  34. }
  35. type RoleAPIController struct {
  36. BaseAuthAPIController
  37. }
  38. // /api/roles [get]
  39. // @param page?:int
  40. func (this *RoleAPIController) GetRoles() {
  41. page, _ := this.GetInt("page")
  42. adminUserInfo := this.GetAdminUserInfo()
  43. //beego.Alert(adminUserInfo.AdminUser)
  44. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  45. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  46. // return
  47. //}
  48. if page <= 0 {
  49. page = 1
  50. }
  51. roles, total, getRoleErr := service.GetRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
  52. if getRoleErr != nil {
  53. //beego.Error("获取角色列表失败:", getRoleErr)
  54. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  55. } else {
  56. this.ServeSuccessJSON(map[string]interface{}{
  57. "roles": roles,
  58. "total_count": total,
  59. })
  60. }
  61. }
  62. // /api/role/create [post]
  63. // @param name:string
  64. // @param intro:string
  65. func (this *RoleAPIController) CreateRole() {
  66. name := this.GetString("name")
  67. intro := this.GetString("intro")
  68. if len(name) == 0 {
  69. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  70. return
  71. }
  72. adminUserInfo := this.GetAdminUserInfo()
  73. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  74. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  75. // return
  76. //}
  77. total := service.FindRoleRecordByRoleName(name, adminUserInfo.CurrentOrgId)
  78. if total > 0 {
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNameIsExist)
  80. return
  81. }
  82. role, createErr := service.CreateRole(adminUserInfo.AdminUser.Id, adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, name, intro)
  83. if createErr != nil {
  84. //beego.Error("创建角色失败:", createErr)
  85. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  86. } else {
  87. this.ServeSuccessJSON(map[string]interface{}{
  88. "id": role.Id,
  89. "name": role.RoleName,
  90. "intro": role.RoleIntro,
  91. "status": role.Status,
  92. })
  93. }
  94. }
  95. // /api/role/modify
  96. // @param role_id:int
  97. // @param name:string
  98. // @param intro:string
  99. func (this *RoleAPIController) ModifyRole() {
  100. roleID, _ := this.GetInt64("role_id")
  101. name := this.GetString("name")
  102. intro := this.GetString("intro")
  103. if roleID <= 0 || len(name) == 0 || len(intro) == 0 {
  104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  105. return
  106. }
  107. //adminUserInfo := this.GetAdminUserInfo()
  108. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  109. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  110. // return
  111. //}
  112. role, getRoleErr := service.GetRoleByRoleID(roleID)
  113. if getRoleErr != nil {
  114. //beego.Error("获取角色失败:", getRoleErr)
  115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  116. return
  117. } else if role == nil {
  118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
  119. return
  120. }
  121. role.RoleName = name
  122. role.RoleIntro = intro
  123. role.ModifyTime = time.Now().Unix()
  124. saveErr := service.ModifyRole(role)
  125. if saveErr != nil {
  126. //beego.Error("修改角色失败:", role.Id, saveErr)
  127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  128. } else {
  129. this.ServeSuccessJSON(nil)
  130. }
  131. }
  132. // /api/role/setstatus
  133. // @param role_id:int
  134. // @param enable:bool
  135. func (this *RoleAPIController) ModifyRoleStatus() {
  136. roleID, _ := this.GetInt64("role_id")
  137. enable, _ := this.GetBool("enable")
  138. if roleID <= 0 {
  139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. adminUserInfo := this.GetAdminUserInfo()
  143. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  144. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  145. // return
  146. //}
  147. role, getRoleErr := service.GetRoleByRoleID(roleID)
  148. if getRoleErr != nil {
  149. //beego.Error("获取角色失败:", getRoleErr)
  150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  151. return
  152. } else if role == nil {
  153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
  154. return
  155. }
  156. if enable == false {
  157. if count, _ := service.RoleAdminUserCountTwo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleID); count != 0 {
  158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCannotRemoveRole)
  159. return
  160. }
  161. }
  162. if enable {
  163. role.Status = 1
  164. } else {
  165. role.Status = 2
  166. }
  167. role.ModifyTime = time.Now().Unix()
  168. saveErr := service.ModifyRole(role)
  169. if saveErr != nil {
  170. //beego.Error("修改角色失败:", role.Id, saveErr)
  171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  172. } else {
  173. this.ServeSuccessJSON(nil)
  174. }
  175. }
  176. // /role/purview/editinit [get]
  177. // @param role_id:int
  178. func (this *RoleAPIController) EditPurviewInitData() {
  179. //adminUserInfo := this.GetAdminUserInfo()
  180. //if
  181. //}
  182. roleId, _ := this.GetInt64("role_id")
  183. if roleId <= 0 {
  184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  185. return
  186. }
  187. role, _ := service.GetRoleByRoleID(roleId)
  188. //purviews_xt, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(3)
  189. purviews_scrm, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(6)
  190. purviews_cdm, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(4)
  191. purviews_mall, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(7)
  192. purviews_ky_mall, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(8)
  193. purviews_func, _ := service.GetAllGeneralFuncPurviewVMsProcessed()
  194. //门诊
  195. outpatientRegistration, _, _ := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientRegistration/manage")
  196. //电子病历
  197. _, _, originEle := service.GetOtherAllGeneralPurviewVMsProcessed("/patinets/ele")
  198. //透析管理
  199. _, _, originDialysis := service.GetOtherAllGeneralPurviewVMsProcessed("/dialysis/manage")
  200. //库房管理
  201. _, _, originStock := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/manage")
  202. //配置管理
  203. //_, _, orginConfig := service.GetOtherAllGeneralPurviewVMsProcessed("/config/manage")
  204. //门诊管理
  205. _, _, outpatientRegistrationPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientRegistration/index")
  206. _, _, outpatientRegistrationPurviewTwo := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientDoctorStation")
  207. _, _, outpatientRegistrationPurviewThree := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientCharges")
  208. //透析管理
  209. _, _, originDialysisWatchPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/dialysis/watch")
  210. _, _, originWorkforcePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/workforce/patient")
  211. _, _, originSignPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/sign/lineup")
  212. _, _, originMedicalSchedulingPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/medicalScheduling/index")
  213. _, _, originQcdPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/qcd/manage")
  214. _, _, originDevicePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/device/manage")
  215. _, _, originDataUploadPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/data/upload")
  216. _, _, originConsumablesPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/consumablesManagement")
  217. _, _, originDrugsPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/drugs")
  218. _, _, originSelfPreparedMedicinePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/selfPreparedMedicineIndex")
  219. _, _, originOtherPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/other")
  220. _, _, originIntegrationPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/integration/manage")
  221. _, _, originTemplatePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/template/manage")
  222. _, _, originDictMedicinePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/dict/manage")
  223. _, _, originBedPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/bed/manage")
  224. //门诊管理
  225. subPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  226. subPurviewTreeViewModelTwo := []*service.PurviewTreeViewModel{}
  227. subPurviewTreeViewModelThree := []*service.PurviewTreeViewModel{}
  228. for _, item := range outpatientRegistrationPurview {
  229. temp := &service.PurviewTreeViewModel{
  230. ID: item.Id,
  231. PID: item.Parentid,
  232. Name: item.Name,
  233. Number: 1,
  234. }
  235. subPurviewTreeViewModel = append(subPurviewTreeViewModel, temp)
  236. }
  237. for _, item := range outpatientRegistrationPurviewTwo {
  238. temp := &service.PurviewTreeViewModel{
  239. ID: item.Id,
  240. PID: item.Parentid,
  241. Name: item.Name,
  242. Number: 1,
  243. }
  244. subPurviewTreeViewModelTwo = append(subPurviewTreeViewModelTwo, temp)
  245. }
  246. for _, item := range outpatientRegistrationPurviewThree {
  247. temp := &service.PurviewTreeViewModel{
  248. ID: item.Id,
  249. PID: item.Parentid,
  250. Name: item.Name,
  251. Number: 1,
  252. }
  253. subPurviewTreeViewModelThree = append(subPurviewTreeViewModelThree, temp)
  254. }
  255. for _, item := range outpatientRegistration {
  256. if item.Name == "门诊挂号" {
  257. item.Childs = append(item.Childs, subPurviewTreeViewModel...)
  258. }
  259. if item.Name == "门诊医生站" {
  260. item.Childs = append(item.Childs, subPurviewTreeViewModelTwo...)
  261. }
  262. if item.Name == "门诊收费" {
  263. item.Childs = append(item.Childs, subPurviewTreeViewModelThree...)
  264. }
  265. }
  266. //电子病历
  267. subElePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  268. for _, item := range originEle {
  269. temp := &service.PurviewTreeViewModel{
  270. ID: item.Id,
  271. PID: item.Parentid,
  272. Name: item.Name,
  273. Number: 1,
  274. }
  275. subElePurviewTreeViewModel = append(subElePurviewTreeViewModel, temp)
  276. }
  277. //透析管理
  278. subDialysisPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  279. for _, item := range originDialysis {
  280. temp := &service.PurviewTreeViewModel{
  281. ID: item.Id,
  282. PID: item.Parentid,
  283. Name: item.Name,
  284. Number: 1,
  285. }
  286. subDialysisPurviewTreeViewModel = append(subDialysisPurviewTreeViewModel, temp)
  287. }
  288. //库存管理
  289. subStockPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  290. for _, item := range originStock {
  291. temp := &service.PurviewTreeViewModel{
  292. ID: item.Id,
  293. PID: item.Parentid,
  294. Name: item.Name,
  295. Number: 1,
  296. }
  297. subStockPurviewTreeViewModel = append(subStockPurviewTreeViewModel, temp)
  298. }
  299. ////配置管理
  300. //subConfigPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  301. //for _, item := range orginConfig {
  302. // temp := &service.PurviewTreeViewModel{
  303. // ID: item.Id,
  304. // PID: item.Parentid,
  305. // Name: item.Name,
  306. // Number: 1,
  307. // }
  308. // subConfigPurviewTreeViewModel = append(subConfigPurviewTreeViewModel, temp)
  309. //}
  310. //
  311. //
  312. //监测管理
  313. subWatchPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  314. for _, item := range originDialysisWatchPurview {
  315. temp := &service.PurviewTreeViewModel{
  316. ID: item.Id,
  317. PID: item.Parentid,
  318. Name: item.Name,
  319. Number: 1,
  320. }
  321. subWatchPurviewTreeViewModel = append(subWatchPurviewTreeViewModel, temp)
  322. }
  323. //排班管理
  324. subWorkforcePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  325. for _, item := range originWorkforcePurview {
  326. temp := &service.PurviewTreeViewModel{
  327. ID: item.Id,
  328. PID: item.Parentid,
  329. Name: item.Name,
  330. Number: 1,
  331. }
  332. subWorkforcePurviewTreeViewModel = append(subWorkforcePurviewTreeViewModel, temp)
  333. }
  334. //签到排队
  335. subSignPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  336. for _, item := range originSignPurview {
  337. temp := &service.PurviewTreeViewModel{
  338. ID: item.Id,
  339. PID: item.Parentid,
  340. Name: item.Name,
  341. Number: 1,
  342. }
  343. subSignPurviewTreeViewModel = append(subSignPurviewTreeViewModel, temp)
  344. }
  345. //医护排班
  346. subMedicalSchedulingPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  347. for _, item := range originMedicalSchedulingPurview {
  348. temp := &service.PurviewTreeViewModel{
  349. ID: item.Id,
  350. PID: item.Parentid,
  351. Name: item.Name,
  352. Number: 1,
  353. }
  354. subMedicalSchedulingPurviewTreeViewModel = append(subMedicalSchedulingPurviewTreeViewModel, temp)
  355. }
  356. subQCDPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  357. for _, item := range originQcdPurview {
  358. temp := &service.PurviewTreeViewModel{
  359. ID: item.Id,
  360. PID: item.Parentid,
  361. Name: item.Name,
  362. Number: 1,
  363. }
  364. subQCDPurviewTreeViewModel = append(subQCDPurviewTreeViewModel, temp)
  365. }
  366. subDevicePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  367. for _, item := range originDevicePurview {
  368. temp := &service.PurviewTreeViewModel{
  369. ID: item.Id,
  370. PID: item.Parentid,
  371. Name: item.Name,
  372. Number: 1,
  373. }
  374. subDevicePurviewTreeViewModel = append(subDevicePurviewTreeViewModel, temp)
  375. }
  376. subDataUploadPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  377. for _, item := range originDataUploadPurview {
  378. temp := &service.PurviewTreeViewModel{
  379. ID: item.Id,
  380. PID: item.Parentid,
  381. Name: item.Name,
  382. Number: 1,
  383. }
  384. subDataUploadPurviewTreeViewModel = append(subDataUploadPurviewTreeViewModel, temp)
  385. }
  386. subConsumablesPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  387. for _, item := range originConsumablesPurview {
  388. temp := &service.PurviewTreeViewModel{
  389. ID: item.Id,
  390. PID: item.Parentid,
  391. Name: item.Name,
  392. Number: 1,
  393. }
  394. subConsumablesPurviewTreeViewModel = append(subConsumablesPurviewTreeViewModel, temp)
  395. }
  396. subDrugPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  397. for _, item := range originDrugsPurview {
  398. temp := &service.PurviewTreeViewModel{
  399. ID: item.Id,
  400. PID: item.Parentid,
  401. Name: item.Name,
  402. Number: 1,
  403. }
  404. subDrugPurviewTreeViewModel = append(subDrugPurviewTreeViewModel, temp)
  405. }
  406. subSelfPreparedMedicinePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  407. for _, item := range originSelfPreparedMedicinePurview {
  408. temp := &service.PurviewTreeViewModel{
  409. ID: item.Id,
  410. PID: item.Parentid,
  411. Name: item.Name,
  412. Number: 1,
  413. }
  414. subSelfPreparedMedicinePurviewTreeViewModel = append(subSelfPreparedMedicinePurviewTreeViewModel, temp)
  415. }
  416. subOtherPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  417. for _, item := range originOtherPurview {
  418. temp := &service.PurviewTreeViewModel{
  419. ID: item.Id,
  420. PID: item.Parentid,
  421. Name: item.Name,
  422. Number: 1,
  423. }
  424. subOtherPurviewTreeViewModel = append(subOtherPurviewTreeViewModel, temp)
  425. }
  426. subIntegrationPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  427. for _, item := range originIntegrationPurview {
  428. temp := &service.PurviewTreeViewModel{
  429. ID: item.Id,
  430. PID: item.Parentid,
  431. Name: item.Name,
  432. Number: 1,
  433. }
  434. subIntegrationPurviewTreeViewModel = append(subIntegrationPurviewTreeViewModel, temp)
  435. }
  436. subTemplatePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  437. for _, item := range originTemplatePurview {
  438. temp := &service.PurviewTreeViewModel{
  439. ID: item.Id,
  440. PID: item.Parentid,
  441. Name: item.Name,
  442. Number: 1,
  443. }
  444. subTemplatePurviewTreeViewModel = append(subTemplatePurviewTreeViewModel, temp)
  445. }
  446. subDictPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  447. for _, item := range originDictMedicinePurview {
  448. temp := &service.PurviewTreeViewModel{
  449. ID: item.Id,
  450. PID: item.Parentid,
  451. Name: item.Name,
  452. Number: 1,
  453. }
  454. subDictPurviewTreeViewModel = append(subDictPurviewTreeViewModel, temp)
  455. }
  456. subBedPrviewTreeViewModel := []*service.PurviewTreeViewModel{}
  457. for _, item := range originBedPurview {
  458. temp := &service.PurviewTreeViewModel{
  459. ID: item.Id,
  460. PID: item.Parentid,
  461. Name: item.Name,
  462. Number: 1,
  463. }
  464. subBedPrviewTreeViewModel = append(subBedPrviewTreeViewModel, temp)
  465. }
  466. for _, item := range subDialysisPurviewTreeViewModel {
  467. if item.Name == "透析记录" {
  468. item.Childs = append(item.Childs, purviews_func...)
  469. }
  470. if item.Name == "透析监控" {
  471. item.Childs = append(item.Childs, subWatchPurviewTreeViewModel...)
  472. }
  473. if item.Name == "患者排班" {
  474. item.Childs = append(item.Childs, subWorkforcePurviewTreeViewModel...)
  475. }
  476. if item.Name == "签到排队" {
  477. item.Childs = append(item.Childs, subSignPurviewTreeViewModel...)
  478. }
  479. if item.Name == "医护排班" {
  480. item.Childs = append(item.Childs, subMedicalSchedulingPurviewTreeViewModel...)
  481. }
  482. if item.Name == "质控管理" {
  483. item.Childs = append(item.Childs, subQCDPurviewTreeViewModel...)
  484. }
  485. if item.Name == "院感管理" {
  486. item.Childs = append(item.Childs, subDevicePurviewTreeViewModel...)
  487. }
  488. if item.Name == "质控上报" {
  489. item.Childs = append(item.Childs, subDataUploadPurviewTreeViewModel...)
  490. }
  491. }
  492. for _, item := range subStockPurviewTreeViewModel {
  493. if item.Name == "耗材管理" {
  494. item.Childs = append(item.Childs, subConsumablesPurviewTreeViewModel...)
  495. }
  496. if item.Name == "药品管理" {
  497. item.Childs = append(item.Childs, subDrugPurviewTreeViewModel...)
  498. }
  499. if item.Name == "自备药管理" {
  500. item.Childs = append(item.Childs, subSelfPreparedMedicinePurviewTreeViewModel...)
  501. }
  502. if item.Name == "其他管理" {
  503. item.Childs = append(item.Childs, subOtherPurviewTreeViewModel...)
  504. }
  505. }
  506. //for _, item := range subConfigPurviewTreeViewModel {
  507. // if item.Name == "集成管理" {
  508. // item.Childs = append(item.Childs, subIntegrationPurviewTreeViewModel...)
  509. // }
  510. // if item.Name == "模版管理" {
  511. // item.Childs = append(item.Childs, subTemplatePurviewTreeViewModel...)
  512. // }
  513. // if item.Name == "字典管理" {
  514. // item.Childs = append(item.Childs, subDictPurviewTreeViewModel...)
  515. // }
  516. // if item.Name == "床位管理" {
  517. // item.Childs = append(item.Childs, subBedPrviewTreeViewModel...)
  518. // }
  519. //
  520. //}
  521. purviews := []*service.PurviewTreeViewModel{}
  522. menzhen := &service.PurviewTreeViewModel{
  523. ID: 0,
  524. PID: 0,
  525. Name: "门诊管理",
  526. Number: 3,
  527. Childs: outpatientRegistration,
  528. }
  529. purviews = append(purviews, menzhen)
  530. dianzi := &service.PurviewTreeViewModel{
  531. ID: 0,
  532. PID: 0,
  533. Name: "电子病历",
  534. Number: 3,
  535. Childs: subElePurviewTreeViewModel,
  536. }
  537. purviews = append(purviews, dianzi)
  538. touxi := &service.PurviewTreeViewModel{
  539. ID: 0,
  540. PID: 0,
  541. Name: "透析管理",
  542. Number: 3,
  543. Childs: subDialysisPurviewTreeViewModel,
  544. }
  545. purviews = append(purviews, touxi)
  546. kufang := &service.PurviewTreeViewModel{
  547. ID: 0,
  548. PID: 0,
  549. Name: "库房管理",
  550. Number: 3,
  551. Childs: subStockPurviewTreeViewModel,
  552. }
  553. purviews = append(purviews, kufang)
  554. ky_mall := &service.PurviewTreeViewModel{
  555. ID: 0,
  556. PID: 0,
  557. Name: "酷医商城",
  558. Number: 3,
  559. Childs: purviews_ky_mall,
  560. }
  561. purviews = append(purviews, ky_mall)
  562. cdm := &service.PurviewTreeViewModel{
  563. ID: 0,
  564. PID: 0,
  565. Number: 3,
  566. Name: "慢病管理",
  567. Childs: purviews_cdm,
  568. }
  569. purviews = append(purviews, cdm)
  570. scrm := &service.PurviewTreeViewModel{
  571. ID: 0,
  572. PID: 0,
  573. Name: "营销管理",
  574. Number: 3,
  575. Childs: purviews_scrm,
  576. }
  577. purviews = append(purviews, scrm)
  578. mall := &service.PurviewTreeViewModel{
  579. ID: 0,
  580. PID: 0,
  581. Name: "分销商城",
  582. Number: 3,
  583. Childs: purviews_mall,
  584. }
  585. purviews = append(purviews, mall)
  586. //peizhi := &service.PurviewTreeViewModel{
  587. // ID: 0,
  588. // PID: 0,
  589. // Name: "配置管理",
  590. // Number: 3,
  591. // Childs: subConfigPurviewTreeViewModel,
  592. //}
  593. //purviews = append(purviews, peizhi)
  594. if getPurviewsErr != nil {
  595. //beego.Error("获取所有权限时出错:", getPurviewsErr)
  596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  597. return
  598. }
  599. rolePurviewIdStr, getRPIdsErr := service.GetRolePurviewIds(roleId)
  600. if getRPIdsErr != nil {
  601. //beego.Error("获取角色的权限时出错:", getRPIdsErr)
  602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  603. return
  604. }
  605. roleFuncPurview, getFuncRPIdsErr := service.GetRoleFuncPurview(roleId)
  606. if getFuncRPIdsErr == gorm.ErrRecordNotFound {
  607. //beego.Error("获取角色的权限时出错:", getRPIdsErr)
  608. if roleFuncPurview.ID == 0 {
  609. rolePurviewIdStr = rolePurviewIdStr
  610. } else {
  611. rolePurviewIdStr = rolePurviewIdStr + "," + roleFuncPurview.PurviewIds
  612. }
  613. } else if getFuncRPIdsErr != nil {
  614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  615. return
  616. } else {
  617. if roleFuncPurview.ID == 0 {
  618. rolePurviewIdStr = rolePurviewIdStr
  619. } else {
  620. rolePurviewIdStr = rolePurviewIdStr + "," + roleFuncPurview.PurviewIds
  621. }
  622. }
  623. this.ServeSuccessJSON(map[string]interface{}{
  624. "purviews": purviews,
  625. "role": role,
  626. "role_purview_ids": rolePurviewIdStr + "," + roleFuncPurview.PurviewIds,
  627. })
  628. }
  629. // /role/purview/edit [post]
  630. // @param role_id:int
  631. // @param purview_ids:string
  632. func (this *RoleAPIController) EditPurview() {
  633. adminUserInfo := this.GetAdminUserInfo()
  634. roleId, _ := this.GetInt64("role_id")
  635. purviewIds := this.GetString("purview_ids")
  636. funcPurviewIds := this.GetString("func_purview_ids")
  637. if roleId <= 0 {
  638. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  639. return
  640. }
  641. redis := service.RedisClient()
  642. defer redis.Close()
  643. users := service.GetAllUserRole(adminUserInfo.CurrentOrgId)
  644. for _, item := range users {
  645. key := "purviews_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + strconv.FormatInt(item.AdminUserId, 10)
  646. redis.Set(key, "", time.Second)
  647. }
  648. err := service.SaveRolePurviewIds(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId, purviewIds)
  649. err = service.SaveFuncRolePurviewIds(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId, funcPurviewIds)
  650. if err != nil {
  651. //beego.Error("设置角色的权限时出错:", err)
  652. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  653. } else {
  654. this.ServeSuccessJSON(nil)
  655. }
  656. }
  657. // func (this *RoleAPIController) doesUserHaveAccess(userID int64) bool {
  658. // adminUser, getAdminUserErr := service.GetAdminUserByUserID(userID)
  659. // if getAdminUserErr != nil {
  660. // beego.Error("获取用户信息失败:%v", getAdminUserErr)
  661. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  662. // return false
  663. // } else if adminUser == nil {
  664. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  665. // return false
  666. // } else if adminUser.Status == 2 {
  667. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUserWasForbidden)
  668. // return false
  669. // } else if adminUser.IsSuperAdmin == false {
  670. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  671. // return false
  672. // }
  673. // return true
  674. // }
  675. // func (this *RoleAPIController) isAppRoleExist(orgID int64, appID int64, userID int64) bool {
  676. // appRole, getAppRoleErr := service.GetAppRole(orgID, appID, userID)
  677. // if getAppRoleErr != nil {
  678. // beego.Error("检查用户和机构应用对应关系时失败:%v", getAppRoleErr)
  679. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  680. // return false
  681. // } else if appRole == nil {
  682. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  683. // return false
  684. // }
  685. // return true
  686. // }
  687. // /api/adminmain [get]
  688. func (this *RoleAPIController) AdminMainView() {
  689. adminUserInfo := this.GetAdminUserInfo()
  690. var isSubSuperAdmin bool = false
  691. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  692. if len(adminUserRole.RoleIds) > 0 {
  693. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  694. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  695. if adminUserInfo.AdminUser.Id != org.Creator {
  696. for _, item := range role_ids {
  697. id, _ := strconv.ParseInt(item, 10, 64)
  698. if id != 0 {
  699. role, _ := service.GetRoleByRoleID(id)
  700. if role != nil {
  701. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  702. isSubSuperAdmin = true
  703. }
  704. }
  705. }
  706. }
  707. }
  708. }
  709. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  710. viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  711. if getAdminsErr != nil {
  712. //beego.Error("获取管理员列表失败:", getAdminsErr)
  713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  714. return
  715. }
  716. this.ServeSuccessJSON(map[string]interface{}{
  717. "admins": viewModels,
  718. "org": org,
  719. "isSubSuperAdmin": isSubSuperAdmin,
  720. })
  721. }
  722. // /api/admins [get]
  723. // @param page?:int
  724. func (this *RoleAPIController) Admins() {
  725. adminUserInfo := this.GetAdminUserInfo()
  726. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  727. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  728. // return
  729. //}
  730. page, _ := this.GetInt("page")
  731. viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
  732. if getAdminsErr != nil {
  733. //beego.Error("获取管理员列表失败:", getAdminsErr)
  734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  735. } else {
  736. this.ServeSuccessJSON(map[string]interface{}{
  737. "admins": viewModels,
  738. "total_count": total,
  739. })
  740. }
  741. }
  742. // /api/admin/addinit [get]
  743. func (this *RoleAPIController) AddAdminInitData() {
  744. adminUserInfo := this.GetAdminUserInfo()
  745. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  746. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  747. // return
  748. //}
  749. var isSubSuperAdmin bool = false
  750. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  751. if len(adminUserRole.RoleIds) > 0 {
  752. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  753. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  754. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  755. if adminUserInfo.AdminUser.Id != org.Creator {
  756. for _, item := range role_ids {
  757. id, _ := strconv.ParseInt(item, 10, 64)
  758. if id != 0 {
  759. role, _ := service.GetRoleByRoleID(id)
  760. if role != nil {
  761. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  762. isSubSuperAdmin = true
  763. }
  764. }
  765. }
  766. }
  767. }
  768. }
  769. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  770. roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  771. if getRoleErr != nil {
  772. //beego.Error("获取所有角色失败:", getRoleErr)
  773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  774. return
  775. }
  776. redisClient := service.RedisClient()
  777. defer redisClient.Close()
  778. qntoken, _ := redisClient.Get("qn_token").Result()
  779. this.ServeSuccessJSON(map[string]interface{}{
  780. "roles": roles,
  781. "qntoken": qntoken,
  782. "isSubSuperAdmin": isSubSuperAdmin,
  783. "org": org,
  784. })
  785. }
  786. // /api/admin/add [post]
  787. // @param mobile:string
  788. // @param name:string
  789. // @param type:int 管理员类型:2.医生 3.护士 4.运营
  790. // @param title:int 用户职称(1.医士;2.医师;3.住院医师;4.主治医师;5.副主任医师;6.主任医师;7.护士;8.护师;9.主管护师;10.副主任护师;11.主任护师;12.运营专员;13.运营主管)
  791. // @param role:int
  792. // @param intro?:string
  793. func (this *RoleAPIController) AddAdmin() {
  794. adminUserInfo := this.GetAdminUserInfo()
  795. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  796. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  797. // return
  798. //}
  799. mobile := this.GetString("mobile")
  800. name := this.GetString("name")
  801. userType, _ := this.GetInt("type")
  802. userTitle, _ := this.GetInt("title")
  803. roleIds := this.GetString("role")
  804. user_title_name := this.GetString("user_title_name")
  805. department := this.GetString("department")
  806. department_id, _ := this.GetInt64("department_id")
  807. sex, _ := this.GetInt64("sex")
  808. age, _ := this.GetInt64("age")
  809. nation := this.GetString("nation")
  810. card_type, _ := this.GetInt64("card_type")
  811. id_card := this.GetString("id_card")
  812. education, _ := this.GetInt64("education")
  813. study_major_name := this.GetString("study_major_name")
  814. work_major_name := this.GetString("work_major_name")
  815. role_type, _ := this.GetInt64("role_type")
  816. medical_code := this.GetString("medical_code")
  817. doctor_code := this.GetString("doctor_code")
  818. licensing, _ := this.GetInt64("licensing")
  819. job_number := this.GetString("job_number")
  820. prescription_qualification_identification, _ := this.GetInt64("prescription_qualification_identification")
  821. identification_outpatients, _ := this.GetInt64("identification_outpatients")
  822. timeLayout := "2006-01-02"
  823. loc, _ := time.LoadLocation("Local")
  824. start_time := this.GetString("start_time")
  825. theStartTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  826. medical_range_code, _ := this.GetInt64("medical_range_code")
  827. medical_level, _ := this.GetInt64("medical_level")
  828. medical_type_job, _ := this.GetInt64("medical_type_job")
  829. pharmacist_registration_number := this.GetString("pharmacist_registration_number")
  830. doctor_range_code, _ := this.GetInt64("doctor_range_code")
  831. doctor_level, _ := this.GetInt64("doctor_level")
  832. doctor_type_job, _ := this.GetInt64("doctor_type_job")
  833. doctor_number := this.GetString("doctor_number")
  834. outpatient_illnessCategory := this.GetString("outpatient_illnessCategory")
  835. is_active, _ := this.GetInt64("is_active")
  836. active_status, _ := this.GetInt64("active_status")
  837. fmt.Println("active_status", active_status)
  838. if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || len(roleIds) <= 0 {
  839. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  840. return
  841. }
  842. // 判断是否已存在该手机号
  843. if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
  844. //beego.Error("查询用户是否已被添加为管理员时失败:", err)
  845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  846. return
  847. } else {
  848. if adminUser == nil { //新增账号和用户
  849. _, password, createErr := service.CreateGeneralAdminUserOne(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile, name, user_title_name, roleIds, userType, userTitle, department_id, department, sex, age, nation, card_type, id_card, education, study_major_name, work_major_name, role_type, medical_code, doctor_code, licensing, job_number, prescription_qualification_identification, identification_outpatients, theStartTime.Unix(), medical_range_code, medical_level, medical_type_job, pharmacist_registration_number, doctor_range_code, doctor_level, doctor_type_job, doctor_number, outpatient_illnessCategory, is_active, active_status)
  850. if createErr != nil {
  851. //beego.Error("创建管理员失败:", createErr)
  852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  853. return
  854. } else {
  855. sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
  856. if sendSMSErr != nil {
  857. }
  858. this.ServeSuccessJSON(nil)
  859. return
  860. }
  861. } else {
  862. total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.CurrentOrgId)
  863. if total <= 0 {
  864. //新增用户
  865. app_role := &models.App_Role{
  866. AdminUserId: adminUser.Id,
  867. OrgId: adminUserInfo.CurrentOrgId,
  868. AppId: adminUserInfo.CurrentAppId,
  869. Avatar: "",
  870. UserName: name,
  871. UserTitleName: user_title_name,
  872. Status: 1,
  873. UserType: int8(userType),
  874. UserTitle: int8(userTitle),
  875. CreateTime: time.Now().Unix(),
  876. ModifyTime: time.Now().Unix(),
  877. RoleIds: roleIds,
  878. Department: department,
  879. DepartmentId: department_id,
  880. Sex: sex,
  881. Age: age,
  882. Nation: nation,
  883. CardType: card_type,
  884. IdCard: id_card,
  885. Education: education,
  886. StudyMajorName: study_major_name,
  887. WorkMajorName: work_major_name,
  888. RoleType: role_type,
  889. MedicalCode: medical_code,
  890. DoctorCode: doctor_code,
  891. Licensing: licensing,
  892. JobNumber: job_number,
  893. PrescriptionQualificationIdentification: prescription_qualification_identification,
  894. IdentificationOutpatients: identification_outpatients,
  895. StartTime: theStartTime.Unix(),
  896. MedicalRangeCode: medical_range_code,
  897. MedicalLevel: medical_level,
  898. MedicalTypeJob: medical_type_job,
  899. PharmacistRegistrationNumber: pharmacist_registration_number,
  900. DoctorRangeCode: doctor_range_code,
  901. DoctorLevel: doctor_level,
  902. DoctorTypeJob: doctor_type_job,
  903. DoctorNumber: doctor_number,
  904. OutpatientIllnesscategory: outpatient_illnessCategory,
  905. IsActive: is_active,
  906. ActiveStatus: active_status,
  907. }
  908. err := service.CreateUserRole(app_role)
  909. if err != nil {
  910. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  911. return
  912. }
  913. this.ServeSuccessJSON(nil)
  914. } else {
  915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
  916. return
  917. }
  918. return
  919. }
  920. }
  921. }
  922. // /api/admin/editinit [get]
  923. // @param uid:int
  924. func (this *RoleAPIController) EditAdminInitData() {
  925. adminUserInfo := this.GetAdminUserInfo()
  926. admin_user_id, _ := this.GetInt64("uid")
  927. if admin_user_id <= 0 {
  928. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  929. return
  930. }
  931. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
  932. if getAppRoleErr != nil {
  933. //beego.Error("查询管理员信息时失败:", getAppRoleErr)
  934. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  935. return
  936. }
  937. if appRole == nil {
  938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  939. return
  940. }
  941. roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  942. if getRoleErr != nil {
  943. //beego.Error("获取所有角色失败:", getRoleErr)
  944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  945. return
  946. }
  947. var isSubSuperAdmin bool = false
  948. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  949. if len(adminUserRole.RoleIds) > 0 {
  950. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  951. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  952. if adminUserInfo.AdminUser.Id != org.Creator {
  953. for _, item := range role_ids {
  954. id, _ := strconv.ParseInt(item, 10, 64)
  955. if id != 0 {
  956. role, _ := service.GetRoleByRoleID(id)
  957. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  958. isSubSuperAdmin = true
  959. }
  960. }
  961. }
  962. }
  963. }
  964. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  965. redisClient := service.RedisClient()
  966. defer redisClient.Close()
  967. qntoken, _ := redisClient.Get("qn_token").Result()
  968. this.ServeSuccessJSON(map[string]interface{}{
  969. "admin": appRole,
  970. "roles": roles,
  971. "qntoken": qntoken,
  972. "isSubSuperAdmin": isSubSuperAdmin,
  973. "org": org,
  974. })
  975. }
  976. // /api/admin/edit [post]
  977. // @param uid:int
  978. // @param name:string
  979. // @param type:int
  980. // @param title:int
  981. // @param role:int
  982. // @param intro?:string
  983. func (this *RoleAPIController) EditAdmin() {
  984. adminUserInfo := this.GetAdminUserInfo()
  985. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  986. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  987. // return
  988. //}
  989. adminUserId, _ := this.GetInt64("uid")
  990. name := this.GetString("name")
  991. userType, _ := this.GetInt("type")
  992. userTitle, _ := this.GetInt("title")
  993. roleIds := this.GetString("role")
  994. intro := this.GetString("intro")
  995. user_title_name := this.GetString("user_title_name")
  996. department := this.GetString("department")
  997. department_id, _ := this.GetInt64("department_id")
  998. sort, _ := this.GetInt64("sort")
  999. age, _ := this.GetInt64("age")
  1000. nation := this.GetString("nation")
  1001. card_type, _ := this.GetInt64("card_type")
  1002. id_card := this.GetString("id_card")
  1003. education, _ := this.GetInt64("education")
  1004. study_major_name := this.GetString("study_major_name")
  1005. work_major_name := this.GetString("work_major_name")
  1006. role_type, _ := this.GetInt64("role_type")
  1007. medical_code := this.GetString("medical_code")
  1008. doctor_code := this.GetString("doctor_code")
  1009. licensing, _ := this.GetInt64("licensing")
  1010. job_number := this.GetString("job_number")
  1011. prescription_qualification_identification, _ := this.GetInt64("prescription_qualification_identification")
  1012. identification_outpatients, _ := this.GetInt64("identification_outpatients")
  1013. timeLayout := "2006-01-02"
  1014. loc, _ := time.LoadLocation("Local")
  1015. start_time := this.GetString("start_time")
  1016. fmt.Println("start_time22222222222", start_time)
  1017. theStartTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1018. medical_range_code, _ := this.GetInt64("medical_range_code")
  1019. medical_level, _ := this.GetInt64("medical_level")
  1020. medical_type_job, _ := this.GetInt64("medical_type_job")
  1021. pharmacist_registration_number := this.GetString("pharmacist_registration_number")
  1022. doctor_range_code, _ := this.GetInt64("doctor_range_code")
  1023. doctor_level, _ := this.GetInt64("doctor_level")
  1024. doctor_type_job, _ := this.GetInt64("doctor_type_job")
  1025. doctor_number := this.GetString("doctor_number")
  1026. outpatient_illnessCategory := this.GetString("outpatient_illnessCategory")
  1027. is_active, _ := this.GetInt64("is_active")
  1028. active_status, _ := this.GetInt64("active_status")
  1029. _, titleExist := models.UserTitle[userTitle]
  1030. fmt.Println(titleExist)
  1031. if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || len(roleIds) <= 0 {
  1032. fmt.Println("进来了吗")
  1033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1034. return
  1035. }
  1036. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserId)
  1037. if getAppRoleErr != nil {
  1038. //beego.Error("查询管理员信息时失败:", getAppRoleErr)
  1039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1040. return
  1041. }
  1042. if appRole == nil {
  1043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1044. return
  1045. }
  1046. appRole.Department = department
  1047. appRole.DepartmentId = department_id
  1048. appRole.UserName = name
  1049. appRole.UserType = int8(userType)
  1050. appRole.UserTitle = int8(userTitle)
  1051. appRole.RoleIds = roleIds
  1052. appRole.Intro = intro
  1053. appRole.UserTitleName = user_title_name
  1054. appRole.ModifyTime = time.Now().Unix()
  1055. appRole.Sort = sort
  1056. appRole.Age = age
  1057. appRole.Nation = nation
  1058. appRole.CardType = card_type
  1059. appRole.IdCard = id_card
  1060. appRole.Education = education
  1061. appRole.StudyMajorName = study_major_name
  1062. appRole.WorkMajorName = work_major_name
  1063. appRole.RoleType = role_type
  1064. appRole.MedicalCode = medical_code
  1065. appRole.DoctorCode = doctor_code
  1066. appRole.Licensing = licensing
  1067. appRole.JobNumber = job_number
  1068. appRole.PrescriptionQualificationIdentification = prescription_qualification_identification
  1069. appRole.IdentificationOutpatients = identification_outpatients
  1070. appRole.StartTime = theStartTime.Unix()
  1071. appRole.MedicalCode = medical_code
  1072. appRole.MedicalRangeCode = medical_range_code
  1073. appRole.MedicalLevel = medical_level
  1074. appRole.MedicalTypeJob = medical_type_job
  1075. appRole.PharmacistRegistrationNumber = pharmacist_registration_number
  1076. appRole.DoctorRangeCode = doctor_range_code
  1077. appRole.DoctorLevel = doctor_level
  1078. appRole.DoctorTypeJob = doctor_type_job
  1079. appRole.DoctorNumber = doctor_number
  1080. appRole.OutpatientIllnesscategory = outpatient_illnessCategory
  1081. appRole.IsActive = is_active
  1082. appRole.ActiveStatus = active_status
  1083. saveErr := service.SaveAppRole(appRole)
  1084. if saveErr != nil {
  1085. //beego.Error("修改App_Role失败:", saveErr)
  1086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1087. } else {
  1088. this.ServeSuccessJSON(map[string]interface{}{
  1089. "approle": appRole,
  1090. })
  1091. this.ServeSuccessJSON(nil)
  1092. }
  1093. }
  1094. // /api/admin/setstatus [post]
  1095. // @param uid:int
  1096. // @param enable:bool
  1097. func (this *RoleAPIController) AdminSetStatus() {
  1098. adminUserInfo := this.GetAdminUserInfo()
  1099. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1100. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1101. // return
  1102. //}
  1103. userID, _ := this.GetInt64("uid")
  1104. if userID <= 0 {
  1105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1106. return
  1107. }
  1108. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, userID)
  1109. if getAppRoleErr != nil {
  1110. //beego.Error("查询管理员信息失败:", getAppRoleErr)
  1111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1112. return
  1113. } else if appRole == nil {
  1114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1115. return
  1116. }
  1117. enable, _ := this.GetBool("enable")
  1118. if enable {
  1119. appRole.Status = 1
  1120. } else {
  1121. appRole.Status = 0
  1122. }
  1123. appRole.ModifyTime = time.Now().Unix()
  1124. saveErr := service.SaveAppRole(appRole)
  1125. if saveErr != nil {
  1126. //beego.Error("保存AppRole失败:", saveErr)
  1127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1128. } else {
  1129. this.ServeSuccessJSON(nil)
  1130. }
  1131. }
  1132. // /api/admin/specialpermission/initdata [get]
  1133. func (this *RoleAPIController) SpecialPermissionInitData() {
  1134. adminUserInfo := this.GetAdminUserInfo()
  1135. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1136. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1137. // return
  1138. //}
  1139. adminUsers, getAdminUsersErr := service.GetAllGeneralAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  1140. if getAdminUsersErr != nil {
  1141. this.ErrorLog("获取所有普通用户失败:%v", getAdminUsersErr)
  1142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1143. return
  1144. }
  1145. headNurses, getAllHeadNursesErr := service.GetAllValidAdminUsersWithSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1146. if getAllHeadNursesErr != nil {
  1147. this.ErrorLog("获取所有拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1149. return
  1150. }
  1151. this.ServeSuccessJSON(map[string]interface{}{
  1152. "users": adminUsers,
  1153. "head_nurses": headNurses,
  1154. })
  1155. }
  1156. // /api/admin/specialpermission/dialysisrecord/submit [post]
  1157. // @param ids:string ("1,2,5")
  1158. func (this *RoleAPIController) SubmitDialysisRecordPermission() {
  1159. adminUserInfo := this.GetAdminUserInfo()
  1160. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1161. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1162. // return
  1163. //}
  1164. idsString := this.GetString("ids")
  1165. if len(idsString) == 0 {
  1166. // 取消所有用户的护士长权限
  1167. cancelErr := service.CancelAllSpecialPermissionAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1168. if cancelErr != nil {
  1169. this.ErrorLog("取消所有用户的护士长权限失败:%v", cancelErr)
  1170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1171. return
  1172. } else {
  1173. this.ServeSuccessJSON(nil)
  1174. return
  1175. }
  1176. } else {
  1177. ids := make([]int64, 0)
  1178. idStrs := strings.Split(idsString, ",")
  1179. for _, idStr := range idStrs {
  1180. id, parseErr := strconv.Atoi(idStr)
  1181. if parseErr != nil {
  1182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1183. return
  1184. }
  1185. ids = append(ids, int64(id))
  1186. }
  1187. headNurses, getAllHeadNursesErr := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1188. if getAllHeadNursesErr != nil {
  1189. this.ErrorLog("获取所有拥有或曾拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1191. return
  1192. }
  1193. cancelList := make([]*models.AdminUserSpecialPermission, 0)
  1194. addList := make([]*models.AdminUserSpecialPermission, 0)
  1195. for _, id := range ids {
  1196. exit := false
  1197. for _, headNurse := range headNurses {
  1198. if headNurse.AdminUserID == id {
  1199. exit = true
  1200. if headNurse.Status != 1 {
  1201. headNurse.Status = 1
  1202. headNurse.ModifyTime = time.Now().Unix()
  1203. addList = append(addList, headNurse)
  1204. }
  1205. break
  1206. }
  1207. }
  1208. if exit == false {
  1209. newHeadNurse := &models.AdminUserSpecialPermission{
  1210. OrgID: adminUserInfo.CurrentOrgId,
  1211. AppID: adminUserInfo.CurrentAppId,
  1212. AdminUserID: id,
  1213. Permission: int64(models.SpecialPermissionTypeHeadNurse),
  1214. Status: 1,
  1215. CreateTime: time.Now().Unix(),
  1216. ModifyTime: time.Now().Unix(),
  1217. }
  1218. addList = append(addList, newHeadNurse)
  1219. }
  1220. }
  1221. for _, headNurse := range headNurses {
  1222. cancel := true
  1223. for _, willAdd := range addList {
  1224. if willAdd.AdminUserID == headNurse.AdminUserID {
  1225. cancel = false
  1226. break
  1227. }
  1228. }
  1229. if cancel {
  1230. headNurse.Status = 0
  1231. headNurse.ModifyTime = time.Now().Unix()
  1232. cancelList = append(cancelList, headNurse)
  1233. }
  1234. }
  1235. addErr := service.BatchSaveSpecialPermissionAdminUsers(addList)
  1236. if addErr != nil {
  1237. this.ErrorLog("授权失败:%v", addErr)
  1238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1239. return
  1240. }
  1241. cancelErr := service.BatchSaveSpecialPermissionAdminUsers(cancelList)
  1242. if cancelErr != nil {
  1243. this.ErrorLog("取消授权失败:%v", cancelErr)
  1244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1245. return
  1246. }
  1247. this.ServeSuccessJSON(nil)
  1248. }
  1249. }
  1250. func (this *RoleAPIController) GetAllOrgRole() {
  1251. adminUserInfo := this.GetAdminUserInfo()
  1252. var isSubSuperAdmin bool = false
  1253. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1254. if len(adminUserRole.RoleIds) > 0 {
  1255. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1256. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1257. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1258. if adminUserInfo.AdminUser.Id != org.Creator {
  1259. for _, item := range role_ids {
  1260. id, _ := strconv.ParseInt(item, 10, 64)
  1261. if id != 0 {
  1262. role, _ := service.GetRoleByRoleID(id)
  1263. if role != nil {
  1264. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1265. isSubSuperAdmin = true
  1266. }
  1267. }
  1268. }
  1269. }
  1270. }
  1271. }
  1272. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1273. roles, err := service.GetAllOrgValidRoles(adminUserInfo.CurrentOrgId, isSubSuperAdmin)
  1274. if err != nil {
  1275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1276. return
  1277. } else {
  1278. this.ServeSuccessJSON(map[string]interface{}{
  1279. "roles": roles,
  1280. "isSubSuperAdmin": isSubSuperAdmin,
  1281. "org": org,
  1282. })
  1283. }
  1284. }
  1285. func (this *RoleAPIController) GetAllOrgUser() {
  1286. adminUserInfo := this.GetAdminUserInfo()
  1287. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1288. var isSubSuperAdmin bool = false
  1289. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1290. if len(adminUserRole.RoleIds) > 0 {
  1291. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1292. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1293. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1294. if adminUserInfo.AdminUser.Id != org.Creator {
  1295. for _, item := range role_ids {
  1296. id, _ := strconv.ParseInt(item, 10, 64)
  1297. if id != 0 {
  1298. role, _ := service.GetRoleByRoleID(id)
  1299. if role != nil {
  1300. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1301. isSubSuperAdmin = true
  1302. }
  1303. }
  1304. }
  1305. }
  1306. }
  1307. }
  1308. viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1309. this.ServeSuccessJSON(map[string]interface{}{
  1310. "admins": viewModels,
  1311. "org": org,
  1312. "isSubSuperAdmin": isSubSuperAdmin,
  1313. })
  1314. }
  1315. func (this *RoleAPIController) AddRoleStaff() {
  1316. //adminUserInfo := this.GetMobileAdminUserInfo()
  1317. role_id, _ := this.GetInt64("id", 0)
  1318. staff_ids := this.GetString("ids")
  1319. ids := strings.Split(staff_ids, ",")
  1320. for _, item := range ids {
  1321. id, _ := strconv.ParseInt(item, 10, 64)
  1322. role, _ := service.FindAdminUserID(id)
  1323. role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
  1324. service.SaveAdminUser(&role)
  1325. }
  1326. this.ServeSuccessJSON(map[string]interface{}{
  1327. "msg": "添加成功",
  1328. })
  1329. }
  1330. func (this *RoleAPIController) GetRoleStaff() {
  1331. adminUserInfo := this.GetAdminUserInfo()
  1332. var isSubSuperAdmin bool = false
  1333. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1334. if len(adminUserRole.RoleIds) > 0 {
  1335. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1336. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1337. if adminUserInfo.AdminUser.Id != org.Creator {
  1338. for _, item := range role_ids {
  1339. id, _ := strconv.ParseInt(item, 10, 64)
  1340. if id != 0 {
  1341. role, _ := service.GetRoleByRoleID(id)
  1342. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1343. isSubSuperAdmin = true
  1344. }
  1345. }
  1346. }
  1347. }
  1348. }
  1349. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1350. viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1351. if getAdminsErr != nil {
  1352. //beego.Error("获取管理员列表失败:", getAdminsErr)
  1353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1354. return
  1355. }
  1356. this.ServeSuccessJSON(map[string]interface{}{
  1357. "admins": viewModels,
  1358. "org": org,
  1359. "isSubSuperAdmin": isSubSuperAdmin,
  1360. })
  1361. }
  1362. func (this *RoleAPIController) GetRoleInfo() {
  1363. roleId, _ := this.GetInt64("role_id")
  1364. if roleId <= 0 {
  1365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1366. return
  1367. }
  1368. role, _ := service.GetRoleByRoleID(roleId)
  1369. this.ServeSuccessJSON(map[string]interface{}{
  1370. "role": role,
  1371. })
  1372. }