role_controller.go 51KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  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. sex, _ := this.GetInt64("sex")
  1000. age, _ := this.GetInt64("age")
  1001. nation := this.GetString("nation")
  1002. card_type, _ := this.GetInt64("card_type")
  1003. id_card := this.GetString("id_card")
  1004. education, _ := this.GetInt64("education")
  1005. study_major_name := this.GetString("study_major_name")
  1006. work_major_name := this.GetString("work_major_name")
  1007. role_type, _ := this.GetInt64("role_type")
  1008. medical_code := this.GetString("medical_code")
  1009. doctor_code := this.GetString("doctor_code")
  1010. licensing, _ := this.GetInt64("licensing")
  1011. job_number := this.GetString("job_number")
  1012. prescription_qualification_identification, _ := this.GetInt64("prescription_qualification_identification")
  1013. identification_outpatients, _ := this.GetInt64("identification_outpatients")
  1014. timeLayout := "2006-01-02"
  1015. loc, _ := time.LoadLocation("Local")
  1016. start_time := this.GetString("start_time")
  1017. fmt.Println("start_time22222222222", start_time)
  1018. theStartTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1019. medical_range_code, _ := this.GetInt64("medical_range_code")
  1020. medical_level, _ := this.GetInt64("medical_level")
  1021. medical_type_job, _ := this.GetInt64("medical_type_job")
  1022. pharmacist_registration_number := this.GetString("pharmacist_registration_number")
  1023. doctor_range_code, _ := this.GetInt64("doctor_range_code")
  1024. doctor_level, _ := this.GetInt64("doctor_level")
  1025. doctor_type_job, _ := this.GetInt64("doctor_type_job")
  1026. doctor_number := this.GetString("doctor_number")
  1027. outpatient_illnessCategory := this.GetString("outpatient_illnessCategory")
  1028. is_active, _ := this.GetInt64("is_active")
  1029. active_status, _ := this.GetInt64("active_status")
  1030. _, titleExist := models.UserTitle[userTitle]
  1031. fmt.Println(titleExist)
  1032. if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || len(roleIds) <= 0 {
  1033. fmt.Println("进来了吗")
  1034. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1035. return
  1036. }
  1037. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserId)
  1038. if getAppRoleErr != nil {
  1039. //beego.Error("查询管理员信息时失败:", getAppRoleErr)
  1040. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1041. return
  1042. }
  1043. if appRole == nil {
  1044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1045. return
  1046. }
  1047. appRole.Department = department
  1048. appRole.DepartmentId = department_id
  1049. appRole.UserName = name
  1050. appRole.UserType = int8(userType)
  1051. appRole.UserTitle = int8(userTitle)
  1052. appRole.RoleIds = roleIds
  1053. appRole.Intro = intro
  1054. appRole.UserTitleName = user_title_name
  1055. appRole.ModifyTime = time.Now().Unix()
  1056. appRole.Sort = sort
  1057. appRole.Age = age
  1058. appRole.Nation = nation
  1059. appRole.CardType = card_type
  1060. appRole.IdCard = id_card
  1061. appRole.Education = education
  1062. appRole.StudyMajorName = study_major_name
  1063. appRole.WorkMajorName = work_major_name
  1064. appRole.RoleType = role_type
  1065. appRole.MedicalCode = medical_code
  1066. appRole.DoctorCode = doctor_code
  1067. appRole.Licensing = licensing
  1068. appRole.JobNumber = job_number
  1069. appRole.PrescriptionQualificationIdentification = prescription_qualification_identification
  1070. appRole.IdentificationOutpatients = identification_outpatients
  1071. appRole.StartTime = theStartTime.Unix()
  1072. appRole.MedicalCode = medical_code
  1073. appRole.MedicalRangeCode = medical_range_code
  1074. appRole.MedicalLevel = medical_level
  1075. appRole.MedicalTypeJob = medical_type_job
  1076. appRole.PharmacistRegistrationNumber = pharmacist_registration_number
  1077. appRole.DoctorRangeCode = doctor_range_code
  1078. appRole.DoctorLevel = doctor_level
  1079. appRole.DoctorTypeJob = doctor_type_job
  1080. appRole.DoctorNumber = doctor_number
  1081. appRole.OutpatientIllnesscategory = outpatient_illnessCategory
  1082. appRole.IsActive = is_active
  1083. appRole.ActiveStatus = active_status
  1084. appRole.Sex = sex
  1085. saveErr := service.SaveAppRole(appRole)
  1086. if saveErr != nil {
  1087. //beego.Error("修改App_Role失败:", saveErr)
  1088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1089. } else {
  1090. this.ServeSuccessJSON(map[string]interface{}{
  1091. "approle": appRole,
  1092. })
  1093. this.ServeSuccessJSON(nil)
  1094. }
  1095. }
  1096. // /api/admin/setstatus [post]
  1097. // @param uid:int
  1098. // @param enable:bool
  1099. func (this *RoleAPIController) AdminSetStatus() {
  1100. adminUserInfo := this.GetAdminUserInfo()
  1101. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1102. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1103. // return
  1104. //}
  1105. userID, _ := this.GetInt64("uid")
  1106. if userID <= 0 {
  1107. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1108. return
  1109. }
  1110. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, userID)
  1111. if getAppRoleErr != nil {
  1112. //beego.Error("查询管理员信息失败:", getAppRoleErr)
  1113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1114. return
  1115. } else if appRole == nil {
  1116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1117. return
  1118. }
  1119. enable, _ := this.GetBool("enable")
  1120. if enable {
  1121. appRole.Status = 1
  1122. } else {
  1123. appRole.Status = 0
  1124. }
  1125. appRole.ModifyTime = time.Now().Unix()
  1126. saveErr := service.SaveAppRole(appRole)
  1127. if saveErr != nil {
  1128. //beego.Error("保存AppRole失败:", saveErr)
  1129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1130. } else {
  1131. this.ServeSuccessJSON(nil)
  1132. }
  1133. }
  1134. // /api/admin/specialpermission/initdata [get]
  1135. func (this *RoleAPIController) SpecialPermissionInitData() {
  1136. adminUserInfo := this.GetAdminUserInfo()
  1137. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1138. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1139. // return
  1140. //}
  1141. adminUsers, getAdminUsersErr := service.GetAllGeneralAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  1142. if getAdminUsersErr != nil {
  1143. this.ErrorLog("获取所有普通用户失败:%v", getAdminUsersErr)
  1144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1145. return
  1146. }
  1147. headNurses, getAllHeadNursesErr := service.GetAllValidAdminUsersWithSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1148. if getAllHeadNursesErr != nil {
  1149. this.ErrorLog("获取所有拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1151. return
  1152. }
  1153. this.ServeSuccessJSON(map[string]interface{}{
  1154. "users": adminUsers,
  1155. "head_nurses": headNurses,
  1156. })
  1157. }
  1158. // /api/admin/specialpermission/dialysisrecord/submit [post]
  1159. // @param ids:string ("1,2,5")
  1160. func (this *RoleAPIController) SubmitDialysisRecordPermission() {
  1161. adminUserInfo := this.GetAdminUserInfo()
  1162. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1163. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1164. // return
  1165. //}
  1166. idsString := this.GetString("ids")
  1167. if len(idsString) == 0 {
  1168. // 取消所有用户的护士长权限
  1169. cancelErr := service.CancelAllSpecialPermissionAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1170. if cancelErr != nil {
  1171. this.ErrorLog("取消所有用户的护士长权限失败:%v", cancelErr)
  1172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1173. return
  1174. } else {
  1175. this.ServeSuccessJSON(nil)
  1176. return
  1177. }
  1178. } else {
  1179. ids := make([]int64, 0)
  1180. idStrs := strings.Split(idsString, ",")
  1181. for _, idStr := range idStrs {
  1182. id, parseErr := strconv.Atoi(idStr)
  1183. if parseErr != nil {
  1184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1185. return
  1186. }
  1187. ids = append(ids, int64(id))
  1188. }
  1189. headNurses, getAllHeadNursesErr := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1190. if getAllHeadNursesErr != nil {
  1191. this.ErrorLog("获取所有拥有或曾拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. return
  1194. }
  1195. cancelList := make([]*models.AdminUserSpecialPermission, 0)
  1196. addList := make([]*models.AdminUserSpecialPermission, 0)
  1197. for _, id := range ids {
  1198. exit := false
  1199. for _, headNurse := range headNurses {
  1200. if headNurse.AdminUserID == id {
  1201. exit = true
  1202. if headNurse.Status != 1 {
  1203. headNurse.Status = 1
  1204. headNurse.ModifyTime = time.Now().Unix()
  1205. addList = append(addList, headNurse)
  1206. }
  1207. break
  1208. }
  1209. }
  1210. if exit == false {
  1211. newHeadNurse := &models.AdminUserSpecialPermission{
  1212. OrgID: adminUserInfo.CurrentOrgId,
  1213. AppID: adminUserInfo.CurrentAppId,
  1214. AdminUserID: id,
  1215. Permission: int64(models.SpecialPermissionTypeHeadNurse),
  1216. Status: 1,
  1217. CreateTime: time.Now().Unix(),
  1218. ModifyTime: time.Now().Unix(),
  1219. }
  1220. addList = append(addList, newHeadNurse)
  1221. }
  1222. }
  1223. for _, headNurse := range headNurses {
  1224. cancel := true
  1225. for _, willAdd := range addList {
  1226. if willAdd.AdminUserID == headNurse.AdminUserID {
  1227. cancel = false
  1228. break
  1229. }
  1230. }
  1231. if cancel {
  1232. headNurse.Status = 0
  1233. headNurse.ModifyTime = time.Now().Unix()
  1234. cancelList = append(cancelList, headNurse)
  1235. }
  1236. }
  1237. addErr := service.BatchSaveSpecialPermissionAdminUsers(addList)
  1238. if addErr != nil {
  1239. this.ErrorLog("授权失败:%v", addErr)
  1240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1241. return
  1242. }
  1243. cancelErr := service.BatchSaveSpecialPermissionAdminUsers(cancelList)
  1244. if cancelErr != nil {
  1245. this.ErrorLog("取消授权失败:%v", cancelErr)
  1246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1247. return
  1248. }
  1249. this.ServeSuccessJSON(nil)
  1250. }
  1251. }
  1252. func (this *RoleAPIController) GetAllOrgRole() {
  1253. adminUserInfo := this.GetAdminUserInfo()
  1254. var isSubSuperAdmin bool = false
  1255. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1256. if len(adminUserRole.RoleIds) > 0 {
  1257. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1258. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1259. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1260. if adminUserInfo.AdminUser.Id != org.Creator {
  1261. for _, item := range role_ids {
  1262. id, _ := strconv.ParseInt(item, 10, 64)
  1263. if id != 0 {
  1264. role, _ := service.GetRoleByRoleID(id)
  1265. if role != nil {
  1266. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1267. isSubSuperAdmin = true
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. }
  1274. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1275. roles, err := service.GetAllOrgValidRoles(adminUserInfo.CurrentOrgId, isSubSuperAdmin)
  1276. if err != nil {
  1277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1278. return
  1279. } else {
  1280. this.ServeSuccessJSON(map[string]interface{}{
  1281. "roles": roles,
  1282. "isSubSuperAdmin": isSubSuperAdmin,
  1283. "org": org,
  1284. })
  1285. }
  1286. }
  1287. func (this *RoleAPIController) GetAllOrgUser() {
  1288. adminUserInfo := this.GetAdminUserInfo()
  1289. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1290. var isSubSuperAdmin bool = false
  1291. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1292. if len(adminUserRole.RoleIds) > 0 {
  1293. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1294. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1295. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1296. if adminUserInfo.AdminUser.Id != org.Creator {
  1297. for _, item := range role_ids {
  1298. id, _ := strconv.ParseInt(item, 10, 64)
  1299. if id != 0 {
  1300. role, _ := service.GetRoleByRoleID(id)
  1301. if role != nil {
  1302. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1303. isSubSuperAdmin = true
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1311. this.ServeSuccessJSON(map[string]interface{}{
  1312. "admins": viewModels,
  1313. "org": org,
  1314. "isSubSuperAdmin": isSubSuperAdmin,
  1315. })
  1316. }
  1317. func (this *RoleAPIController) AddRoleStaff() {
  1318. //adminUserInfo := this.GetMobileAdminUserInfo()
  1319. role_id, _ := this.GetInt64("id", 0)
  1320. staff_ids := this.GetString("ids")
  1321. ids := strings.Split(staff_ids, ",")
  1322. for _, item := range ids {
  1323. id, _ := strconv.ParseInt(item, 10, 64)
  1324. role, _ := service.FindAdminUserID(id)
  1325. role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
  1326. service.SaveAdminUser(&role)
  1327. }
  1328. this.ServeSuccessJSON(map[string]interface{}{
  1329. "msg": "添加成功",
  1330. })
  1331. }
  1332. func (this *RoleAPIController) GetRoleStaff() {
  1333. adminUserInfo := this.GetAdminUserInfo()
  1334. var isSubSuperAdmin bool = false
  1335. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1336. if len(adminUserRole.RoleIds) > 0 {
  1337. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1338. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1339. if adminUserInfo.AdminUser.Id != org.Creator {
  1340. for _, item := range role_ids {
  1341. id, _ := strconv.ParseInt(item, 10, 64)
  1342. if id != 0 {
  1343. role, _ := service.GetRoleByRoleID(id)
  1344. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1345. isSubSuperAdmin = true
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1352. viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1353. if getAdminsErr != nil {
  1354. //beego.Error("获取管理员列表失败:", getAdminsErr)
  1355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1356. return
  1357. }
  1358. this.ServeSuccessJSON(map[string]interface{}{
  1359. "admins": viewModels,
  1360. "org": org,
  1361. "isSubSuperAdmin": isSubSuperAdmin,
  1362. })
  1363. }
  1364. func (this *RoleAPIController) GetRoleInfo() {
  1365. roleId, _ := this.GetInt64("role_id")
  1366. if roleId <= 0 {
  1367. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1368. return
  1369. }
  1370. role, _ := service.GetRoleByRoleID(roleId)
  1371. this.ServeSuccessJSON(map[string]interface{}{
  1372. "role": role,
  1373. })
  1374. }