role_controller.go 43KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  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{}, "post:AddAdmin")
  24. beego.Router("/api/admin/editinit", &RoleAPIController{}, "get:EditAdminInitData")
  25. beego.Router("/api/admin/edit", &RoleAPIController{}, "post: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. //透析管理
  207. _, _, originDialysisWatchPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/dialysis/watch")
  208. _, _, originWorkforcePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/workforce/patient")
  209. _, _, originSignPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/sign/lineup")
  210. _, _, originMedicalSchedulingPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/medicalScheduling/index")
  211. _, _, originQcdPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/qcd/manage")
  212. _, _, originDevicePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/device/manage")
  213. _, _, originDataUploadPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/data/upload")
  214. _, _, originConsumablesPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/consumablesManagement")
  215. _, _, originDrugsPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/drugs")
  216. _, _, originSelfPreparedMedicinePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/selfPreparedMedicineIndex")
  217. _, _, originOtherPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/other")
  218. _, _, originIntegrationPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/integration/manage")
  219. _, _, originTemplatePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/template/manage")
  220. _, _, originDictMedicinePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/dict/manage")
  221. _, _, originBedPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/bed/manage")
  222. //门诊管理
  223. subPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  224. for _, item := range outpatientRegistrationPurview {
  225. temp := &service.PurviewTreeViewModel{
  226. ID: item.Id,
  227. PID: item.Parentid,
  228. Name: item.Name,
  229. Number: 1,
  230. }
  231. subPurviewTreeViewModel = append(subPurviewTreeViewModel, temp)
  232. }
  233. for _, item := range outpatientRegistration {
  234. if item.Name == "门诊挂号" {
  235. item.Childs = append(item.Childs, subPurviewTreeViewModel...)
  236. }
  237. }
  238. //电子病历
  239. subElePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  240. for _, item := range originEle {
  241. temp := &service.PurviewTreeViewModel{
  242. ID: item.Id,
  243. PID: item.Parentid,
  244. Name: item.Name,
  245. Number: 1,
  246. }
  247. subElePurviewTreeViewModel = append(subElePurviewTreeViewModel, temp)
  248. }
  249. //透析管理
  250. subDialysisPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  251. for _, item := range originDialysis {
  252. temp := &service.PurviewTreeViewModel{
  253. ID: item.Id,
  254. PID: item.Parentid,
  255. Name: item.Name,
  256. Number: 1,
  257. }
  258. subDialysisPurviewTreeViewModel = append(subDialysisPurviewTreeViewModel, temp)
  259. }
  260. //库存管理
  261. subStockPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  262. for _, item := range originStock {
  263. temp := &service.PurviewTreeViewModel{
  264. ID: item.Id,
  265. PID: item.Parentid,
  266. Name: item.Name,
  267. Number: 1,
  268. }
  269. subStockPurviewTreeViewModel = append(subStockPurviewTreeViewModel, temp)
  270. }
  271. ////配置管理
  272. //subConfigPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  273. //for _, item := range orginConfig {
  274. // temp := &service.PurviewTreeViewModel{
  275. // ID: item.Id,
  276. // PID: item.Parentid,
  277. // Name: item.Name,
  278. // Number: 1,
  279. // }
  280. // subConfigPurviewTreeViewModel = append(subConfigPurviewTreeViewModel, temp)
  281. //}
  282. //
  283. //
  284. //监测管理
  285. subWatchPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  286. for _, item := range originDialysisWatchPurview {
  287. temp := &service.PurviewTreeViewModel{
  288. ID: item.Id,
  289. PID: item.Parentid,
  290. Name: item.Name,
  291. Number: 1,
  292. }
  293. subWatchPurviewTreeViewModel = append(subWatchPurviewTreeViewModel, temp)
  294. }
  295. //排班管理
  296. subWorkforcePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  297. for _, item := range originWorkforcePurview {
  298. temp := &service.PurviewTreeViewModel{
  299. ID: item.Id,
  300. PID: item.Parentid,
  301. Name: item.Name,
  302. Number: 1,
  303. }
  304. subWorkforcePurviewTreeViewModel = append(subWorkforcePurviewTreeViewModel, temp)
  305. }
  306. //签到排队
  307. subSignPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  308. for _, item := range originSignPurview {
  309. temp := &service.PurviewTreeViewModel{
  310. ID: item.Id,
  311. PID: item.Parentid,
  312. Name: item.Name,
  313. Number: 1,
  314. }
  315. subSignPurviewTreeViewModel = append(subSignPurviewTreeViewModel, temp)
  316. }
  317. //医护排班
  318. subMedicalSchedulingPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  319. for _, item := range originMedicalSchedulingPurview {
  320. temp := &service.PurviewTreeViewModel{
  321. ID: item.Id,
  322. PID: item.Parentid,
  323. Name: item.Name,
  324. Number: 1,
  325. }
  326. subMedicalSchedulingPurviewTreeViewModel = append(subMedicalSchedulingPurviewTreeViewModel, temp)
  327. }
  328. subQCDPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  329. for _, item := range originQcdPurview {
  330. temp := &service.PurviewTreeViewModel{
  331. ID: item.Id,
  332. PID: item.Parentid,
  333. Name: item.Name,
  334. Number: 1,
  335. }
  336. subQCDPurviewTreeViewModel = append(subQCDPurviewTreeViewModel, temp)
  337. }
  338. subDevicePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  339. for _, item := range originDevicePurview {
  340. temp := &service.PurviewTreeViewModel{
  341. ID: item.Id,
  342. PID: item.Parentid,
  343. Name: item.Name,
  344. Number: 1,
  345. }
  346. subDevicePurviewTreeViewModel = append(subDevicePurviewTreeViewModel, temp)
  347. }
  348. subDataUploadPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  349. for _, item := range originDataUploadPurview {
  350. temp := &service.PurviewTreeViewModel{
  351. ID: item.Id,
  352. PID: item.Parentid,
  353. Name: item.Name,
  354. Number: 1,
  355. }
  356. subDataUploadPurviewTreeViewModel = append(subDataUploadPurviewTreeViewModel, temp)
  357. }
  358. subConsumablesPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  359. for _, item := range originConsumablesPurview {
  360. temp := &service.PurviewTreeViewModel{
  361. ID: item.Id,
  362. PID: item.Parentid,
  363. Name: item.Name,
  364. Number: 1,
  365. }
  366. subConsumablesPurviewTreeViewModel = append(subConsumablesPurviewTreeViewModel, temp)
  367. }
  368. subDrugPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  369. for _, item := range originDrugsPurview {
  370. temp := &service.PurviewTreeViewModel{
  371. ID: item.Id,
  372. PID: item.Parentid,
  373. Name: item.Name,
  374. Number: 1,
  375. }
  376. subDrugPurviewTreeViewModel = append(subDrugPurviewTreeViewModel, temp)
  377. }
  378. subSelfPreparedMedicinePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  379. for _, item := range originSelfPreparedMedicinePurview {
  380. temp := &service.PurviewTreeViewModel{
  381. ID: item.Id,
  382. PID: item.Parentid,
  383. Name: item.Name,
  384. Number: 1,
  385. }
  386. subSelfPreparedMedicinePurviewTreeViewModel = append(subSelfPreparedMedicinePurviewTreeViewModel, temp)
  387. }
  388. subOtherPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  389. for _, item := range originOtherPurview {
  390. temp := &service.PurviewTreeViewModel{
  391. ID: item.Id,
  392. PID: item.Parentid,
  393. Name: item.Name,
  394. Number: 1,
  395. }
  396. subOtherPurviewTreeViewModel = append(subOtherPurviewTreeViewModel, temp)
  397. }
  398. subIntegrationPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  399. for _, item := range originIntegrationPurview {
  400. temp := &service.PurviewTreeViewModel{
  401. ID: item.Id,
  402. PID: item.Parentid,
  403. Name: item.Name,
  404. Number: 1,
  405. }
  406. subIntegrationPurviewTreeViewModel = append(subIntegrationPurviewTreeViewModel, temp)
  407. }
  408. subTemplatePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  409. for _, item := range originTemplatePurview {
  410. temp := &service.PurviewTreeViewModel{
  411. ID: item.Id,
  412. PID: item.Parentid,
  413. Name: item.Name,
  414. Number: 1,
  415. }
  416. subTemplatePurviewTreeViewModel = append(subTemplatePurviewTreeViewModel, temp)
  417. }
  418. subDictPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  419. for _, item := range originDictMedicinePurview {
  420. temp := &service.PurviewTreeViewModel{
  421. ID: item.Id,
  422. PID: item.Parentid,
  423. Name: item.Name,
  424. Number: 1,
  425. }
  426. subDictPurviewTreeViewModel = append(subDictPurviewTreeViewModel, temp)
  427. }
  428. subBedPrviewTreeViewModel := []*service.PurviewTreeViewModel{}
  429. for _, item := range originBedPurview {
  430. temp := &service.PurviewTreeViewModel{
  431. ID: item.Id,
  432. PID: item.Parentid,
  433. Name: item.Name,
  434. Number: 1,
  435. }
  436. subBedPrviewTreeViewModel = append(subBedPrviewTreeViewModel, temp)
  437. }
  438. for _, item := range subDialysisPurviewTreeViewModel {
  439. if item.Name == "透析记录" {
  440. item.Childs = append(item.Childs, purviews_func...)
  441. }
  442. if item.Name == "透析监控" {
  443. item.Childs = append(item.Childs, subWatchPurviewTreeViewModel...)
  444. }
  445. if item.Name == "患者排班" {
  446. item.Childs = append(item.Childs, subWorkforcePurviewTreeViewModel...)
  447. }
  448. if item.Name == "签到排队" {
  449. item.Childs = append(item.Childs, subSignPurviewTreeViewModel...)
  450. }
  451. if item.Name == "医护排班" {
  452. item.Childs = append(item.Childs, subMedicalSchedulingPurviewTreeViewModel...)
  453. }
  454. if item.Name == "质控管理" {
  455. item.Childs = append(item.Childs, subQCDPurviewTreeViewModel...)
  456. }
  457. if item.Name == "院感管理" {
  458. item.Childs = append(item.Childs, subDevicePurviewTreeViewModel...)
  459. }
  460. if item.Name == "质控上报" {
  461. item.Childs = append(item.Childs, subDataUploadPurviewTreeViewModel...)
  462. }
  463. }
  464. for _, item := range subStockPurviewTreeViewModel {
  465. if item.Name == "耗材管理" {
  466. item.Childs = append(item.Childs, subConsumablesPurviewTreeViewModel...)
  467. }
  468. if item.Name == "药品管理" {
  469. item.Childs = append(item.Childs, subDrugPurviewTreeViewModel...)
  470. }
  471. if item.Name == "自备药管理" {
  472. item.Childs = append(item.Childs, subSelfPreparedMedicinePurviewTreeViewModel...)
  473. }
  474. if item.Name == "其他管理" {
  475. item.Childs = append(item.Childs, subOtherPurviewTreeViewModel...)
  476. }
  477. }
  478. //for _, item := range subConfigPurviewTreeViewModel {
  479. // if item.Name == "集成管理" {
  480. // item.Childs = append(item.Childs, subIntegrationPurviewTreeViewModel...)
  481. // }
  482. // if item.Name == "模版管理" {
  483. // item.Childs = append(item.Childs, subTemplatePurviewTreeViewModel...)
  484. // }
  485. // if item.Name == "字典管理" {
  486. // item.Childs = append(item.Childs, subDictPurviewTreeViewModel...)
  487. // }
  488. // if item.Name == "床位管理" {
  489. // item.Childs = append(item.Childs, subBedPrviewTreeViewModel...)
  490. // }
  491. //
  492. //}
  493. purviews := []*service.PurviewTreeViewModel{}
  494. menzhen := &service.PurviewTreeViewModel{
  495. ID: 0,
  496. PID: 0,
  497. Name: "门诊管理",
  498. Number: 3,
  499. Childs: outpatientRegistration,
  500. }
  501. purviews = append(purviews, menzhen)
  502. dianzi := &service.PurviewTreeViewModel{
  503. ID: 0,
  504. PID: 0,
  505. Name: "电子病历",
  506. Number: 3,
  507. Childs: subElePurviewTreeViewModel,
  508. }
  509. purviews = append(purviews, dianzi)
  510. touxi := &service.PurviewTreeViewModel{
  511. ID: 0,
  512. PID: 0,
  513. Name: "透析管理",
  514. Number: 3,
  515. Childs: subDialysisPurviewTreeViewModel,
  516. }
  517. purviews = append(purviews, touxi)
  518. kufang := &service.PurviewTreeViewModel{
  519. ID: 0,
  520. PID: 0,
  521. Name: "库房管理",
  522. Number: 3,
  523. Childs: subStockPurviewTreeViewModel,
  524. }
  525. purviews = append(purviews, kufang)
  526. ky_mall := &service.PurviewTreeViewModel{
  527. ID: 0,
  528. PID: 0,
  529. Name: "酷医商城",
  530. Number: 3,
  531. Childs: purviews_ky_mall,
  532. }
  533. purviews = append(purviews, ky_mall)
  534. cdm := &service.PurviewTreeViewModel{
  535. ID: 0,
  536. PID: 0,
  537. Number: 3,
  538. Name: "慢病管理",
  539. Childs: purviews_cdm,
  540. }
  541. purviews = append(purviews, cdm)
  542. scrm := &service.PurviewTreeViewModel{
  543. ID: 0,
  544. PID: 0,
  545. Name: "营销管理",
  546. Number: 3,
  547. Childs: purviews_scrm,
  548. }
  549. purviews = append(purviews, scrm)
  550. mall := &service.PurviewTreeViewModel{
  551. ID: 0,
  552. PID: 0,
  553. Name: "分销商城",
  554. Number: 3,
  555. Childs: purviews_mall,
  556. }
  557. purviews = append(purviews, mall)
  558. //peizhi := &service.PurviewTreeViewModel{
  559. // ID: 0,
  560. // PID: 0,
  561. // Name: "配置管理",
  562. // Number: 3,
  563. // Childs: subConfigPurviewTreeViewModel,
  564. //}
  565. //purviews = append(purviews, peizhi)
  566. if getPurviewsErr != nil {
  567. //beego.Error("获取所有权限时出错:", getPurviewsErr)
  568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  569. return
  570. }
  571. rolePurviewIdStr, getRPIdsErr := service.GetRolePurviewIds(roleId)
  572. if getRPIdsErr != nil {
  573. //beego.Error("获取角色的权限时出错:", getRPIdsErr)
  574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  575. return
  576. }
  577. roleFuncPurview, getFuncRPIdsErr := service.GetRoleFuncPurview(roleId)
  578. if getFuncRPIdsErr == gorm.ErrRecordNotFound {
  579. //beego.Error("获取角色的权限时出错:", getRPIdsErr)
  580. if roleFuncPurview.ID == 0 {
  581. rolePurviewIdStr = rolePurviewIdStr
  582. } else {
  583. rolePurviewIdStr = rolePurviewIdStr + "," + roleFuncPurview.PurviewIds
  584. }
  585. } else if getFuncRPIdsErr != nil {
  586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  587. return
  588. } else {
  589. if roleFuncPurview.ID == 0 {
  590. rolePurviewIdStr = rolePurviewIdStr
  591. } else {
  592. rolePurviewIdStr = rolePurviewIdStr + "," + roleFuncPurview.PurviewIds
  593. }
  594. }
  595. this.ServeSuccessJSON(map[string]interface{}{
  596. "purviews": purviews,
  597. "role": role,
  598. "role_purview_ids": rolePurviewIdStr + "," + roleFuncPurview.PurviewIds,
  599. })
  600. }
  601. // /role/purview/edit [post]
  602. // @param role_id:int
  603. // @param purview_ids:string
  604. func (this *RoleAPIController) EditPurview() {
  605. adminUserInfo := this.GetAdminUserInfo()
  606. roleId, _ := this.GetInt64("role_id")
  607. purviewIds := this.GetString("purview_ids")
  608. funcPurviewIds := this.GetString("func_purview_ids")
  609. if roleId <= 0 {
  610. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  611. return
  612. }
  613. redis := service.RedisClient()
  614. defer redis.Close()
  615. users := service.GetAllUserRole(adminUserInfo.CurrentOrgId)
  616. for _, item := range users {
  617. key := "purviews_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + strconv.FormatInt(item.AdminUserId, 10)
  618. redis.Set(key, "", time.Second)
  619. }
  620. err := service.SaveRolePurviewIds(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId, purviewIds)
  621. err = service.SaveFuncRolePurviewIds(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId, funcPurviewIds)
  622. if err != nil {
  623. //beego.Error("设置角色的权限时出错:", err)
  624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  625. } else {
  626. this.ServeSuccessJSON(nil)
  627. }
  628. }
  629. // func (this *RoleAPIController) doesUserHaveAccess(userID int64) bool {
  630. // adminUser, getAdminUserErr := service.GetAdminUserByUserID(userID)
  631. // if getAdminUserErr != nil {
  632. // beego.Error("获取用户信息失败:%v", getAdminUserErr)
  633. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  634. // return false
  635. // } else if adminUser == nil {
  636. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  637. // return false
  638. // } else if adminUser.Status == 2 {
  639. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUserWasForbidden)
  640. // return false
  641. // } else if adminUser.IsSuperAdmin == false {
  642. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  643. // return false
  644. // }
  645. // return true
  646. // }
  647. // func (this *RoleAPIController) isAppRoleExist(orgID int64, appID int64, userID int64) bool {
  648. // appRole, getAppRoleErr := service.GetAppRole(orgID, appID, userID)
  649. // if getAppRoleErr != nil {
  650. // beego.Error("检查用户和机构应用对应关系时失败:%v", getAppRoleErr)
  651. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  652. // return false
  653. // } else if appRole == nil {
  654. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  655. // return false
  656. // }
  657. // return true
  658. // }
  659. // /api/adminmain [get]
  660. func (this *RoleAPIController) AdminMainView() {
  661. adminUserInfo := this.GetAdminUserInfo()
  662. var isSubSuperAdmin bool = false
  663. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  664. if len(adminUserRole.RoleIds) > 0 {
  665. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  666. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  667. if adminUserInfo.AdminUser.Id != org.Creator {
  668. for _, item := range role_ids {
  669. id, _ := strconv.ParseInt(item, 10, 64)
  670. if id != 0 {
  671. role, _ := service.GetRoleByRoleID(id)
  672. if role != nil {
  673. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  674. isSubSuperAdmin = true
  675. }
  676. }
  677. }
  678. }
  679. }
  680. }
  681. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  682. viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  683. if getAdminsErr != nil {
  684. //beego.Error("获取管理员列表失败:", getAdminsErr)
  685. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  686. return
  687. }
  688. this.ServeSuccessJSON(map[string]interface{}{
  689. "admins": viewModels,
  690. "org": org,
  691. "isSubSuperAdmin": isSubSuperAdmin,
  692. })
  693. }
  694. // /api/admins [get]
  695. // @param page?:int
  696. func (this *RoleAPIController) Admins() {
  697. adminUserInfo := this.GetAdminUserInfo()
  698. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  699. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  700. // return
  701. //}
  702. page, _ := this.GetInt("page")
  703. viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
  704. if getAdminsErr != nil {
  705. //beego.Error("获取管理员列表失败:", getAdminsErr)
  706. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  707. } else {
  708. this.ServeSuccessJSON(map[string]interface{}{
  709. "admins": viewModels,
  710. "total_count": total,
  711. })
  712. }
  713. }
  714. // /api/admin/addinit [get]
  715. func (this *RoleAPIController) AddAdminInitData() {
  716. adminUserInfo := this.GetAdminUserInfo()
  717. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  718. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  719. // return
  720. //}
  721. var isSubSuperAdmin bool = false
  722. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  723. if len(adminUserRole.RoleIds) > 0 {
  724. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  725. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  726. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  727. if adminUserInfo.AdminUser.Id != org.Creator {
  728. for _, item := range role_ids {
  729. id, _ := strconv.ParseInt(item, 10, 64)
  730. if id != 0 {
  731. role, _ := service.GetRoleByRoleID(id)
  732. if role != nil {
  733. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  734. isSubSuperAdmin = true
  735. }
  736. }
  737. }
  738. }
  739. }
  740. }
  741. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  742. roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  743. if getRoleErr != nil {
  744. //beego.Error("获取所有角色失败:", getRoleErr)
  745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  746. return
  747. }
  748. redisClient := service.RedisClient()
  749. defer redisClient.Close()
  750. qntoken, _ := redisClient.Get("qn_token").Result()
  751. this.ServeSuccessJSON(map[string]interface{}{
  752. "roles": roles,
  753. "qntoken": qntoken,
  754. "isSubSuperAdmin": isSubSuperAdmin,
  755. "org": org,
  756. })
  757. }
  758. // /api/admin/add [post]
  759. // @param mobile:string
  760. // @param name:string
  761. // @param type:int 管理员类型:2.医生 3.护士 4.运营
  762. // @param title:int 用户职称(1.医士;2.医师;3.住院医师;4.主治医师;5.副主任医师;6.主任医师;7.护士;8.护师;9.主管护师;10.副主任护师;11.主任护师;12.运营专员;13.运营主管)
  763. // @param role:int
  764. // @param intro?:string
  765. func (this *RoleAPIController) AddAdmin() {
  766. adminUserInfo := this.GetAdminUserInfo()
  767. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  768. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  769. // return
  770. //}
  771. mobile := this.GetString("mobile")
  772. name := this.GetString("name")
  773. userType, _ := this.GetInt("type")
  774. userTitle, _ := this.GetInt("title")
  775. roleIds := this.GetString("role")
  776. user_title_name := this.GetString("user_title_name")
  777. department := this.GetString("department")
  778. department_id, _ := this.GetInt64("department_id")
  779. fmt.Println("deparment-------", department, department_id)
  780. if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || len(roleIds) <= 0 {
  781. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  782. return
  783. }
  784. // 判断是否已存在该手机号
  785. if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
  786. //beego.Error("查询用户是否已被添加为管理员时失败:", err)
  787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  788. return
  789. } else {
  790. if adminUser == nil { //新增账号和用户
  791. _, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile, name, user_title_name, roleIds, userType, userTitle)
  792. if createErr != nil {
  793. //beego.Error("创建管理员失败:", createErr)
  794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  795. return
  796. } else {
  797. sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
  798. if sendSMSErr != nil {
  799. }
  800. this.ServeSuccessJSON(nil)
  801. return
  802. }
  803. } else {
  804. total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.CurrentOrgId)
  805. if total <= 0 {
  806. //新增用户
  807. app_role := &models.App_Role{
  808. AdminUserId: adminUser.Id,
  809. OrgId: adminUserInfo.CurrentOrgId,
  810. AppId: adminUserInfo.CurrentAppId,
  811. Avatar: "",
  812. UserName: name,
  813. UserTitleName: user_title_name,
  814. Status: 1,
  815. UserType: int8(userType),
  816. UserTitle: int8(userTitle),
  817. CreateTime: time.Now().Unix(),
  818. ModifyTime: time.Now().Unix(),
  819. RoleIds: roleIds,
  820. Department: department,
  821. DepartmentId: department_id,
  822. }
  823. err := service.CreateUserRole(app_role)
  824. if err != nil {
  825. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  826. return
  827. }
  828. this.ServeSuccessJSON(nil)
  829. } else {
  830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
  831. return
  832. }
  833. return
  834. }
  835. }
  836. }
  837. // /api/admin/editinit [get]
  838. // @param uid:int
  839. func (this *RoleAPIController) EditAdminInitData() {
  840. adminUserInfo := this.GetAdminUserInfo()
  841. admin_user_id, _ := this.GetInt64("uid")
  842. if admin_user_id <= 0 {
  843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  844. return
  845. }
  846. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
  847. if getAppRoleErr != nil {
  848. //beego.Error("查询管理员信息时失败:", getAppRoleErr)
  849. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  850. return
  851. }
  852. if appRole == nil {
  853. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  854. return
  855. }
  856. roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  857. if getRoleErr != nil {
  858. //beego.Error("获取所有角色失败:", getRoleErr)
  859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  860. return
  861. }
  862. var isSubSuperAdmin bool = false
  863. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  864. if len(adminUserRole.RoleIds) > 0 {
  865. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  866. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  867. if adminUserInfo.AdminUser.Id != org.Creator {
  868. for _, item := range role_ids {
  869. id, _ := strconv.ParseInt(item, 10, 64)
  870. if id != 0 {
  871. role, _ := service.GetRoleByRoleID(id)
  872. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  873. isSubSuperAdmin = true
  874. }
  875. }
  876. }
  877. }
  878. }
  879. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  880. redisClient := service.RedisClient()
  881. defer redisClient.Close()
  882. qntoken, _ := redisClient.Get("qn_token").Result()
  883. this.ServeSuccessJSON(map[string]interface{}{
  884. "admin": appRole,
  885. "roles": roles,
  886. "qntoken": qntoken,
  887. "isSubSuperAdmin": isSubSuperAdmin,
  888. "org": org,
  889. })
  890. }
  891. // /api/admin/edit [post]
  892. // @param uid:int
  893. // @param name:string
  894. // @param type:int
  895. // @param title:int
  896. // @param role:int
  897. // @param intro?:string
  898. func (this *RoleAPIController) EditAdmin() {
  899. adminUserInfo := this.GetAdminUserInfo()
  900. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  901. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  902. // return
  903. //}
  904. adminUserId, _ := this.GetInt64("uid")
  905. name := this.GetString("name")
  906. userType, _ := this.GetInt("type")
  907. userTitle, _ := this.GetInt("title")
  908. roleIds := this.GetString("role")
  909. intro := this.GetString("intro")
  910. user_title_name := this.GetString("user_title_name")
  911. department := this.GetString("department")
  912. department_id, _ := this.GetInt64("department_id")
  913. sort, _ := this.GetInt64("sort")
  914. _, titleExist := models.UserTitle[userTitle]
  915. if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || len(roleIds) <= 0 {
  916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  917. return
  918. }
  919. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserId)
  920. if getAppRoleErr != nil {
  921. //beego.Error("查询管理员信息时失败:", getAppRoleErr)
  922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  923. return
  924. }
  925. if appRole == nil {
  926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  927. return
  928. }
  929. appRole.UserName = name
  930. appRole.UserType = int8(userType)
  931. appRole.UserTitle = int8(userTitle)
  932. appRole.RoleIds = roleIds
  933. appRole.Intro = intro
  934. appRole.UserTitleName = user_title_name
  935. appRole.ModifyTime = time.Now().Unix()
  936. appRole.Sort = sort
  937. appRole.DepartmentId = department_id
  938. appRole.Department = department
  939. saveErr := service.SaveAppRole(appRole)
  940. if saveErr != nil {
  941. //beego.Error("修改App_Role失败:", saveErr)
  942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  943. } else {
  944. this.ServeSuccessJSON(nil)
  945. }
  946. }
  947. // /api/admin/setstatus [post]
  948. // @param uid:int
  949. // @param enable:bool
  950. func (this *RoleAPIController) AdminSetStatus() {
  951. adminUserInfo := this.GetAdminUserInfo()
  952. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  953. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  954. // return
  955. //}
  956. userID, _ := this.GetInt64("uid")
  957. if userID <= 0 {
  958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  959. return
  960. }
  961. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, userID)
  962. if getAppRoleErr != nil {
  963. //beego.Error("查询管理员信息失败:", getAppRoleErr)
  964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  965. return
  966. } else if appRole == nil {
  967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  968. return
  969. }
  970. enable, _ := this.GetBool("enable")
  971. if enable {
  972. appRole.Status = 1
  973. } else {
  974. appRole.Status = 0
  975. }
  976. appRole.ModifyTime = time.Now().Unix()
  977. saveErr := service.SaveAppRole(appRole)
  978. if saveErr != nil {
  979. //beego.Error("保存AppRole失败:", saveErr)
  980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  981. } else {
  982. this.ServeSuccessJSON(nil)
  983. }
  984. }
  985. // /api/admin/specialpermission/initdata [get]
  986. func (this *RoleAPIController) SpecialPermissionInitData() {
  987. adminUserInfo := this.GetAdminUserInfo()
  988. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  989. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  990. // return
  991. //}
  992. adminUsers, getAdminUsersErr := service.GetAllGeneralAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  993. if getAdminUsersErr != nil {
  994. this.ErrorLog("获取所有普通用户失败:%v", getAdminUsersErr)
  995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  996. return
  997. }
  998. headNurses, getAllHeadNursesErr := service.GetAllValidAdminUsersWithSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  999. if getAllHeadNursesErr != nil {
  1000. this.ErrorLog("获取所有拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1002. return
  1003. }
  1004. this.ServeSuccessJSON(map[string]interface{}{
  1005. "users": adminUsers,
  1006. "head_nurses": headNurses,
  1007. })
  1008. }
  1009. // /api/admin/specialpermission/dialysisrecord/submit [post]
  1010. // @param ids:string ("1,2,5")
  1011. func (this *RoleAPIController) SubmitDialysisRecordPermission() {
  1012. adminUserInfo := this.GetAdminUserInfo()
  1013. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1014. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1015. // return
  1016. //}
  1017. idsString := this.GetString("ids")
  1018. if len(idsString) == 0 {
  1019. // 取消所有用户的护士长权限
  1020. cancelErr := service.CancelAllSpecialPermissionAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1021. if cancelErr != nil {
  1022. this.ErrorLog("取消所有用户的护士长权限失败:%v", cancelErr)
  1023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1024. return
  1025. } else {
  1026. this.ServeSuccessJSON(nil)
  1027. return
  1028. }
  1029. } else {
  1030. ids := make([]int64, 0)
  1031. idStrs := strings.Split(idsString, ",")
  1032. for _, idStr := range idStrs {
  1033. id, parseErr := strconv.Atoi(idStr)
  1034. if parseErr != nil {
  1035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1036. return
  1037. }
  1038. ids = append(ids, int64(id))
  1039. }
  1040. headNurses, getAllHeadNursesErr := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1041. if getAllHeadNursesErr != nil {
  1042. this.ErrorLog("获取所有拥有或曾拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1044. return
  1045. }
  1046. cancelList := make([]*models.AdminUserSpecialPermission, 0)
  1047. addList := make([]*models.AdminUserSpecialPermission, 0)
  1048. for _, id := range ids {
  1049. exit := false
  1050. for _, headNurse := range headNurses {
  1051. if headNurse.AdminUserID == id {
  1052. exit = true
  1053. if headNurse.Status != 1 {
  1054. headNurse.Status = 1
  1055. headNurse.ModifyTime = time.Now().Unix()
  1056. addList = append(addList, headNurse)
  1057. }
  1058. break
  1059. }
  1060. }
  1061. if exit == false {
  1062. newHeadNurse := &models.AdminUserSpecialPermission{
  1063. OrgID: adminUserInfo.CurrentOrgId,
  1064. AppID: adminUserInfo.CurrentAppId,
  1065. AdminUserID: id,
  1066. Permission: int64(models.SpecialPermissionTypeHeadNurse),
  1067. Status: 1,
  1068. CreateTime: time.Now().Unix(),
  1069. ModifyTime: time.Now().Unix(),
  1070. }
  1071. addList = append(addList, newHeadNurse)
  1072. }
  1073. }
  1074. for _, headNurse := range headNurses {
  1075. cancel := true
  1076. for _, willAdd := range addList {
  1077. if willAdd.AdminUserID == headNurse.AdminUserID {
  1078. cancel = false
  1079. break
  1080. }
  1081. }
  1082. if cancel {
  1083. headNurse.Status = 0
  1084. headNurse.ModifyTime = time.Now().Unix()
  1085. cancelList = append(cancelList, headNurse)
  1086. }
  1087. }
  1088. addErr := service.BatchSaveSpecialPermissionAdminUsers(addList)
  1089. if addErr != nil {
  1090. this.ErrorLog("授权失败:%v", addErr)
  1091. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1092. return
  1093. }
  1094. cancelErr := service.BatchSaveSpecialPermissionAdminUsers(cancelList)
  1095. if cancelErr != nil {
  1096. this.ErrorLog("取消授权失败:%v", cancelErr)
  1097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1098. return
  1099. }
  1100. this.ServeSuccessJSON(nil)
  1101. }
  1102. }
  1103. func (this *RoleAPIController) GetAllOrgRole() {
  1104. adminUserInfo := this.GetAdminUserInfo()
  1105. var isSubSuperAdmin bool = false
  1106. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1107. if len(adminUserRole.RoleIds) > 0 {
  1108. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1109. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1110. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1111. if adminUserInfo.AdminUser.Id != org.Creator {
  1112. for _, item := range role_ids {
  1113. id, _ := strconv.ParseInt(item, 10, 64)
  1114. if id != 0 {
  1115. role, _ := service.GetRoleByRoleID(id)
  1116. if role != nil {
  1117. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1118. isSubSuperAdmin = true
  1119. }
  1120. }
  1121. }
  1122. }
  1123. }
  1124. }
  1125. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1126. roles, err := service.GetAllOrgValidRoles(adminUserInfo.CurrentOrgId, isSubSuperAdmin)
  1127. if err != nil {
  1128. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1129. return
  1130. } else {
  1131. this.ServeSuccessJSON(map[string]interface{}{
  1132. "roles": roles,
  1133. "isSubSuperAdmin": isSubSuperAdmin,
  1134. "org": org,
  1135. })
  1136. }
  1137. }
  1138. func (this *RoleAPIController) GetAllOrgUser() {
  1139. adminUserInfo := this.GetAdminUserInfo()
  1140. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1141. var isSubSuperAdmin bool = false
  1142. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1143. if len(adminUserRole.RoleIds) > 0 {
  1144. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1145. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1146. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1147. if adminUserInfo.AdminUser.Id != org.Creator {
  1148. for _, item := range role_ids {
  1149. id, _ := strconv.ParseInt(item, 10, 64)
  1150. if id != 0 {
  1151. role, _ := service.GetRoleByRoleID(id)
  1152. if role != nil {
  1153. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1154. isSubSuperAdmin = true
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. }
  1161. viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1162. this.ServeSuccessJSON(map[string]interface{}{
  1163. "admins": viewModels,
  1164. "org": org,
  1165. "isSubSuperAdmin": isSubSuperAdmin,
  1166. })
  1167. }
  1168. func (this *RoleAPIController) AddRoleStaff() {
  1169. //adminUserInfo := this.GetMobileAdminUserInfo()
  1170. role_id, _ := this.GetInt64("id", 0)
  1171. staff_ids := this.GetString("ids")
  1172. ids := strings.Split(staff_ids, ",")
  1173. for _, item := range ids {
  1174. id, _ := strconv.ParseInt(item, 10, 64)
  1175. role, _ := service.FindAdminUserID(id)
  1176. role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
  1177. service.SaveAdminUser(&role)
  1178. }
  1179. this.ServeSuccessJSON(map[string]interface{}{
  1180. "msg": "添加成功",
  1181. })
  1182. }
  1183. func (this *RoleAPIController) GetRoleStaff() {
  1184. adminUserInfo := this.GetAdminUserInfo()
  1185. var isSubSuperAdmin bool = false
  1186. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1187. if len(adminUserRole.RoleIds) > 0 {
  1188. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1189. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1190. if adminUserInfo.AdminUser.Id != org.Creator {
  1191. for _, item := range role_ids {
  1192. id, _ := strconv.ParseInt(item, 10, 64)
  1193. if id != 0 {
  1194. role, _ := service.GetRoleByRoleID(id)
  1195. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1196. isSubSuperAdmin = true
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }
  1202. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1203. viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1204. if getAdminsErr != nil {
  1205. //beego.Error("获取管理员列表失败:", getAdminsErr)
  1206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1207. return
  1208. }
  1209. this.ServeSuccessJSON(map[string]interface{}{
  1210. "admins": viewModels,
  1211. "org": org,
  1212. "isSubSuperAdmin": isSubSuperAdmin,
  1213. })
  1214. }
  1215. func (this *RoleAPIController) GetRoleInfo() {
  1216. roleId, _ := this.GetInt64("role_id")
  1217. if roleId <= 0 {
  1218. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1219. return
  1220. }
  1221. role, _ := service.GetRoleByRoleID(roleId)
  1222. this.ServeSuccessJSON(map[string]interface{}{
  1223. "role": role,
  1224. })
  1225. }