12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694 |
- package controllers
-
- import (
- "fmt"
- "github.com/jinzhu/gorm"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
-
- "github.com/astaxie/beego"
- )
-
- func RoleAPIControllerRegistRouters() {
- beego.Router("/api/roles", &RoleAPIController{}, "get:GetRoles")
- beego.Router("/api/role/create", &RoleAPIController{}, "post:CreateRole")
- beego.Router("/api/role/modify", &RoleAPIController{}, "post:ModifyRole")
- beego.Router("/api/role/setstatus", &RoleAPIController{}, "post:ModifyRoleStatus")
-
- beego.Router("/role/purview/editinit", &RoleAPIController{}, "get:EditPurviewInitData")
- beego.Router("/role/purview/edit", &RoleAPIController{}, "post:EditPurview")
-
- beego.Router("/api/adminmain", &RoleAPIController{}, "get:AdminMainView")
- beego.Router("/api/admins", &RoleAPIController{}, "get:Admins")
- beego.Router("/api/admin/addinit", &RoleAPIController{}, "get:AddAdminInitData")
- beego.Router("/api/admin/add", &RoleAPIController{}, "get:AddAdmin")
- beego.Router("/api/admin/editinit", &RoleAPIController{}, "get:EditAdminInitData")
- beego.Router("/api/admin/edit", &RoleAPIController{}, "get:EditAdmin")
- beego.Router("/api/admin/setstatus", &RoleAPIController{}, "post:AdminSetStatus")
-
- beego.Router("/api/admin/specialpermission/initdata", &RoleAPIController{}, "get:SpecialPermissionInitData")
- beego.Router("/api/admin/specialpermission/dialysisrecord/submit", &RoleAPIController{}, "post:SubmitDialysisRecordPermission")
-
- beego.Router("/api/roles/list", &RoleAPIController{}, "get:GetAllOrgRole")
- beego.Router("/api/staff", &RoleAPIController{}, "get:GetAllOrgUser")
- beego.Router("/api/role/addStaff", &RoleAPIController{}, "post:AddRoleStaff")
-
- beego.Router("/api/role/staff", &RoleAPIController{}, "get:GetRoleStaff")
-
- beego.Router("/api/role", &RoleAPIController{}, "get:GetRoleInfo")
-
- }
-
- type RoleAPIController struct {
- BaseAuthAPIController
- }
-
- // /api/roles [get]
- // @param page?:int
- func (this *RoleAPIController) GetRoles() {
- page, _ := this.GetInt("page")
- adminUserInfo := this.GetAdminUserInfo()
- //beego.Alert(adminUserInfo.AdminUser)
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
- if page <= 0 {
- page = 1
- }
- roles, total, getRoleErr := service.GetRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
- if getRoleErr != nil {
- //beego.Error("获取角色列表失败:", getRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "roles": roles,
- "total_count": total,
- })
- }
- }
-
- // /api/role/create [post]
- // @param name:string
- // @param intro:string
- func (this *RoleAPIController) CreateRole() {
- name := this.GetString("name")
- intro := this.GetString("intro")
- if len(name) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- total := service.FindRoleRecordByRoleName(name, adminUserInfo.CurrentOrgId)
- if total > 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNameIsExist)
- return
- }
- role, createErr := service.CreateRole(adminUserInfo.AdminUser.Id, adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, name, intro)
- if createErr != nil {
- //beego.Error("创建角色失败:", createErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "id": role.Id,
- "name": role.RoleName,
- "intro": role.RoleIntro,
- "status": role.Status,
- })
- }
- }
-
- // /api/role/modify
- // @param role_id:int
- // @param name:string
- // @param intro:string
- func (this *RoleAPIController) ModifyRole() {
- roleID, _ := this.GetInt64("role_id")
- name := this.GetString("name")
- intro := this.GetString("intro")
- if roleID <= 0 || len(name) == 0 || len(intro) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- role, getRoleErr := service.GetRoleByRoleID(roleID)
- if getRoleErr != nil {
- //beego.Error("获取角色失败:", getRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if role == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
- return
- }
-
- role.RoleName = name
- role.RoleIntro = intro
- role.ModifyTime = time.Now().Unix()
- saveErr := service.ModifyRole(role)
- if saveErr != nil {
- //beego.Error("修改角色失败:", role.Id, saveErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- } else {
- this.ServeSuccessJSON(nil)
- }
- }
-
- // /api/role/setstatus
- // @param role_id:int
- // @param enable:bool
- func (this *RoleAPIController) ModifyRoleStatus() {
- roleID, _ := this.GetInt64("role_id")
- enable, _ := this.GetBool("enable")
- if roleID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- role, getRoleErr := service.GetRoleByRoleID(roleID)
- if getRoleErr != nil {
- //beego.Error("获取角色失败:", getRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if role == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
- return
- }
-
- if enable == false {
- if count, _ := service.RoleAdminUserCountTwo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleID); count != 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCannotRemoveRole)
- return
- }
- }
-
- if enable {
- role.Status = 1
- } else {
- role.Status = 2
- }
- role.ModifyTime = time.Now().Unix()
- saveErr := service.ModifyRole(role)
- if saveErr != nil {
- //beego.Error("修改角色失败:", role.Id, saveErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- } else {
- this.ServeSuccessJSON(nil)
- }
- }
-
- // /role/purview/editinit [get]
- // @param role_id:int
- func (this *RoleAPIController) EditPurviewInitData() {
- //adminUserInfo := this.GetAdminUserInfo()
- //if
- //}
-
- roleId, _ := this.GetInt64("role_id")
- if roleId <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- role, _ := service.GetRoleByRoleID(roleId)
-
- //purviews_xt, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(3)
- purviews_scrm, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(6)
- purviews_cdm, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(4)
- purviews_mall, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(7)
- purviews_ky_mall, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(8)
-
- purviews_func, _ := service.GetAllGeneralFuncPurviewVMsProcessed()
-
- //门诊
- _, _, outpatientRegistration := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientRegistration/manage")
- fmt.Println(outpatientRegistration)
- //电子病历
- _, _, originEle := service.GetOtherAllGeneralPurviewVMsProcessed("/patinets/ele")
- //透析管理
- _, _, originDialysis := service.GetOtherAllGeneralPurviewVMsProcessed("/dialysis/manage")
- //库房管理
- _, _, originStock := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/manange")
- //配置管理
- //_, _, orginConfig := service.GetOtherAllGeneralPurviewVMsProcessed("/config/manage")
-
- //门诊管理
- _, _, YajinPurview := service.GetOtherAllGeneralPurviewVMsProcessed("DepositManagement")
- //_, _, YaofangPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/api/pharmacy")
- _, _, DengjiPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/hospitalRecord/index")
- _, _, GongjuPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/hisTool")
- _, _, ShoufeiPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/hospitalCharges")
- _, _, outpatientRegistrationPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientRegistration/index")
- _, _, outpatientRegistrationPurviewTwo := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientDoctorStation")
- _, _, outpatientRegistrationPurviewThree := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientCharges")
- _, _, outpatientRegistrationPurviewFour := service.GetOtherAllGeneralPurviewVMsProcessed("/hospitalStation")
-
- //透析管理
- _, _, originDialysisWatchPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/dialysis/watch")
- _, _, originWorkforcePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/workforce/patient")
- _, _, originSignPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/sign/lineup")
- _, _, originMedicalSchedulingPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/medicalScheduling/index")
- _, _, originQcdPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/qcd/manage")
- _, _, originDevicePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/device/manage")
- _, _, originDataUploadPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/data/upload")
-
- _, _, originConsumablesPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/consumablesManagement")
- _, _, originDrugsPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/drugs")
- _, _, originSelfPreparedMedicinePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/selfPreparedMedicineIndex")
- _, _, originOtherPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/other")
-
- _, _, originCkPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/warehousequery")
-
- _, _, originIntegrationPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/integration/manage")
- _, _, originTemplatePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/template/manage")
- _, _, originDictMedicinePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/dict/manage")
- _, _, originBedPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/bed/manage")
-
- //采购管理
- _, _, purchaseManagerPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/supply/query")
-
- //门诊管理
-
- subYajinPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- subPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- subPurviewTreeViewModelTwo := []*service.PurviewTreeViewModel{}
- subPurviewTreeViewModelThree := []*service.PurviewTreeViewModel{}
- //subYaoFangPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- subDengjiPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- subPurviewTreeViewModelFour := []*service.PurviewTreeViewModel{}
- subPurviewTreeViewModelFive := []*service.PurviewTreeViewModel{}
- subGongJuPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- subShouFeiPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
-
- for _, item := range YajinPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subYajinPurviewTreeViewModel = append(subYajinPurviewTreeViewModel, temp)
- }
-
- //for _, item := range YaofangPurview {
- // temp := &service.PurviewTreeViewModel{
- // ID: item.Id,
- // PID: item.Parentid,
- // Name: item.Name,
- // Number: 1,
- // }
- // subYaoFangPurviewTreeViewModel = append(subYaoFangPurviewTreeViewModel, temp)
- //}
-
- for _, item := range DengjiPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subDengjiPurviewTreeViewModel = append(subDengjiPurviewTreeViewModel, temp)
- }
-
- for _, item := range GongjuPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subGongJuPurviewTreeViewModel = append(subGongJuPurviewTreeViewModel, temp)
- }
-
- for _, item := range ShoufeiPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subShouFeiPurviewTreeViewModel = append(subShouFeiPurviewTreeViewModel, temp)
- }
-
- for _, item := range outpatientRegistrationPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subPurviewTreeViewModel = append(subPurviewTreeViewModel, temp)
- }
-
- for _, item := range outpatientRegistrationPurviewTwo {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subPurviewTreeViewModelTwo = append(subPurviewTreeViewModelTwo, temp)
- }
-
- for _, item := range outpatientRegistrationPurviewThree {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subPurviewTreeViewModelThree = append(subPurviewTreeViewModelThree, temp)
- }
-
- for _, item := range outpatientRegistrationPurviewFour {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subPurviewTreeViewModelFour = append(subPurviewTreeViewModelFour, temp)
- }
-
- //采购管理
- for _, item := range purchaseManagerPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subPurviewTreeViewModelFive = append(subPurviewTreeViewModelFive, temp)
- }
-
- //透析管理
- subOutpatientPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range outpatientRegistration {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subOutpatientPurviewTreeViewModel = append(subOutpatientPurviewTreeViewModel, temp)
- }
-
- for _, item := range subOutpatientPurviewTreeViewModel {
- if item.Name == "押金管理" {
- item.Childs = append(item.Childs, subYajinPurviewTreeViewModel...)
- }
-
- if item.Name == "门诊挂号" {
- item.Childs = append(item.Childs, subPurviewTreeViewModel...)
- }
-
- if item.Name == "门诊医生站" {
- item.Childs = append(item.Childs, subPurviewTreeViewModelTwo...)
- }
-
- if item.Name == "门诊收费" {
-
- item.Childs = append(item.Childs, subPurviewTreeViewModelThree...)
- }
- //if item.Name == "药房管理" {
- // item.Childs = append(item.Childs, subYaoFangPurviewTreeViewModel...)
- //}
-
- if item.Name == "住院登记" {
- item.Childs = append(item.Childs, subDengjiPurviewTreeViewModel...)
- }
-
- if item.Name == "住院工作站" {
-
- item.Childs = append(item.Childs, subPurviewTreeViewModelFour...)
- }
-
- if item.Name == "住院收费" {
- item.Childs = append(item.Childs, subShouFeiPurviewTreeViewModel...)
- }
-
- if item.Name == "HIS工具" {
-
- item.Childs = append(item.Childs, subGongJuPurviewTreeViewModel...)
- }
- }
-
- //电子病历
-
- subElePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originEle {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subElePurviewTreeViewModel = append(subElePurviewTreeViewModel, temp)
- }
-
- //透析管理
- subDialysisPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originDialysis {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subDialysisPurviewTreeViewModel = append(subDialysisPurviewTreeViewModel, temp)
- }
-
- //库存管理
- subStockPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originStock {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subStockPurviewTreeViewModel = append(subStockPurviewTreeViewModel, temp)
- }
-
- ////配置管理
- //subConfigPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- //for _, item := range orginConfig {
- // temp := &service.PurviewTreeViewModel{
- // ID: item.Id,
- // PID: item.Parentid,
- // Name: item.Name,
- // Number: 1,
- // }
- // subConfigPurviewTreeViewModel = append(subConfigPurviewTreeViewModel, temp)
- //}
- //
- //
-
- //监测管理
- subWatchPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originDialysisWatchPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subWatchPurviewTreeViewModel = append(subWatchPurviewTreeViewModel, temp)
- }
-
- //排班管理
- subWorkforcePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originWorkforcePurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subWorkforcePurviewTreeViewModel = append(subWorkforcePurviewTreeViewModel, temp)
- }
-
- //签到排队
- subSignPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originSignPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subSignPurviewTreeViewModel = append(subSignPurviewTreeViewModel, temp)
- }
-
- //医护排班
- subMedicalSchedulingPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originMedicalSchedulingPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subMedicalSchedulingPurviewTreeViewModel = append(subMedicalSchedulingPurviewTreeViewModel, temp)
- }
-
- subQCDPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originQcdPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subQCDPurviewTreeViewModel = append(subQCDPurviewTreeViewModel, temp)
- }
-
- subDevicePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originDevicePurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subDevicePurviewTreeViewModel = append(subDevicePurviewTreeViewModel, temp)
- }
-
- subDataUploadPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originDataUploadPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subDataUploadPurviewTreeViewModel = append(subDataUploadPurviewTreeViewModel, temp)
- }
-
- subConsumablesPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originConsumablesPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subConsumablesPurviewTreeViewModel = append(subConsumablesPurviewTreeViewModel, temp)
- }
-
- subDrugPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originDrugsPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subDrugPurviewTreeViewModel = append(subDrugPurviewTreeViewModel, temp)
- }
-
- subSelfPreparedMedicinePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originSelfPreparedMedicinePurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subSelfPreparedMedicinePurviewTreeViewModel = append(subSelfPreparedMedicinePurviewTreeViewModel, temp)
- }
-
- subOtherPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originOtherPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subOtherPurviewTreeViewModel = append(subOtherPurviewTreeViewModel, temp)
- }
-
- subCkPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originCkPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subCkPurviewTreeViewModel = append(subCkPurviewTreeViewModel, temp)
- }
-
- subIntegrationPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originIntegrationPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subIntegrationPurviewTreeViewModel = append(subIntegrationPurviewTreeViewModel, temp)
- }
-
- subTemplatePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originTemplatePurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subTemplatePurviewTreeViewModel = append(subTemplatePurviewTreeViewModel, temp)
- }
-
- subDictPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originDictMedicinePurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subDictPurviewTreeViewModel = append(subDictPurviewTreeViewModel, temp)
- }
-
- subBedPrviewTreeViewModel := []*service.PurviewTreeViewModel{}
- for _, item := range originBedPurview {
- temp := &service.PurviewTreeViewModel{
- ID: item.Id,
- PID: item.Parentid,
- Name: item.Name,
- Number: 1,
- }
- subBedPrviewTreeViewModel = append(subBedPrviewTreeViewModel, temp)
- }
-
- for _, item := range subDialysisPurviewTreeViewModel {
- if item.Name == "透析记录" {
- item.Childs = append(item.Childs, purviews_func...)
- }
- if item.Name == "透析监控" {
- item.Childs = append(item.Childs, subWatchPurviewTreeViewModel...)
- }
- if item.Name == "患者排班" {
- item.Childs = append(item.Childs, subWorkforcePurviewTreeViewModel...)
- }
- if item.Name == "签到排队" {
- item.Childs = append(item.Childs, subSignPurviewTreeViewModel...)
- }
- if item.Name == "医护排班" {
- item.Childs = append(item.Childs, subMedicalSchedulingPurviewTreeViewModel...)
- }
- if item.Name == "质控管理" {
- item.Childs = append(item.Childs, subQCDPurviewTreeViewModel...)
- }
- if item.Name == "院感管理" {
- item.Childs = append(item.Childs, subDevicePurviewTreeViewModel...)
- }
- if item.Name == "质控上报" {
- item.Childs = append(item.Childs, subDataUploadPurviewTreeViewModel...)
- }
- }
-
- for _, item := range subStockPurviewTreeViewModel {
- if item.Name == "耗材管理" {
- item.Childs = append(item.Childs, subConsumablesPurviewTreeViewModel...)
- }
- if item.Name == "药库管理" {
- item.Childs = append(item.Childs, subDrugPurviewTreeViewModel...)
- }
- if item.Name == "自备药管理" {
- item.Childs = append(item.Childs, subSelfPreparedMedicinePurviewTreeViewModel...)
- }
- if item.Name == "其他管理" {
- item.Childs = append(item.Childs, subOtherPurviewTreeViewModel...)
- }
- if item.Name == "仓库管理" {
- item.Childs = append(item.Childs, subCkPurviewTreeViewModel...)
- }
-
- }
-
- //for _, item := range subConfigPurviewTreeViewModel {
- // if item.Name == "集成管理" {
- // item.Childs = append(item.Childs, subIntegrationPurviewTreeViewModel...)
- // }
- // if item.Name == "模版管理" {
- // item.Childs = append(item.Childs, subTemplatePurviewTreeViewModel...)
- // }
- // if item.Name == "字典管理" {
- // item.Childs = append(item.Childs, subDictPurviewTreeViewModel...)
- // }
- // if item.Name == "床位管理" {
- // item.Childs = append(item.Childs, subBedPrviewTreeViewModel...)
- // }
- //
- //}
-
- purviews := []*service.PurviewTreeViewModel{}
-
- menzhen := &service.PurviewTreeViewModel{
- ID: 0,
- PID: 0,
- Name: "门诊管理",
- Number: 3,
- Childs: subOutpatientPurviewTreeViewModel,
- }
- purviews = append(purviews, menzhen)
-
- dianzi := &service.PurviewTreeViewModel{
- ID: 0,
- PID: 0,
- Name: "电子病历",
- Number: 3,
- Childs: subElePurviewTreeViewModel,
- }
- purviews = append(purviews, dianzi)
-
- caigou := &service.PurviewTreeViewModel{
- ID: 0,
- PID: 0,
- Name: "采购管理",
- Number: 3,
- Childs: subPurviewTreeViewModelFive,
- }
- purviews = append(purviews, caigou)
-
- touxi := &service.PurviewTreeViewModel{
- ID: 0,
- PID: 0,
- Name: "透析管理",
- Number: 3,
- Childs: subDialysisPurviewTreeViewModel,
- }
- purviews = append(purviews, touxi)
-
- kufang := &service.PurviewTreeViewModel{
- ID: 0,
- PID: 0,
- Name: "库房管理",
- Number: 3,
- Childs: subStockPurviewTreeViewModel,
- }
- purviews = append(purviews, kufang)
-
- ky_mall := &service.PurviewTreeViewModel{
- ID: 0,
- PID: 0,
- Name: "酷医商城",
- Number: 3,
- Childs: purviews_ky_mall,
- }
- purviews = append(purviews, ky_mall)
-
- cdm := &service.PurviewTreeViewModel{
- ID: 0,
- PID: 0,
- Number: 3,
- Name: "慢病管理",
- Childs: purviews_cdm,
- }
-
- purviews = append(purviews, cdm)
-
- scrm := &service.PurviewTreeViewModel{
- ID: 0,
- PID: 0,
- Name: "营销管理",
- Number: 3,
- Childs: purviews_scrm,
- }
-
- purviews = append(purviews, scrm)
-
- mall := &service.PurviewTreeViewModel{
- ID: 0,
- PID: 0,
- Name: "分销商城",
- Number: 3,
- Childs: purviews_mall,
- }
-
- purviews = append(purviews, mall)
-
- //peizhi := &service.PurviewTreeViewModel{
- // ID: 0,
- // PID: 0,
- // Name: "配置管理",
- // Number: 3,
- // Childs: subConfigPurviewTreeViewModel,
- //}
- //purviews = append(purviews, peizhi)
-
- if getPurviewsErr != nil {
- //beego.Error("获取所有权限时出错:", getPurviewsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- rolePurviewIdStr, getRPIdsErr := service.GetRolePurviewIds(roleId)
- if getRPIdsErr != nil {
- //beego.Error("获取角色的权限时出错:", getRPIdsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- roleFuncPurview, getFuncRPIdsErr := service.GetRoleFuncPurview(roleId)
- if getFuncRPIdsErr == gorm.ErrRecordNotFound {
- //beego.Error("获取角色的权限时出错:", getRPIdsErr)
- if roleFuncPurview.ID == 0 {
- rolePurviewIdStr = rolePurviewIdStr
-
- } else {
- rolePurviewIdStr = rolePurviewIdStr + "," + roleFuncPurview.PurviewIds
- }
- } else if getFuncRPIdsErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
-
- } else {
- if roleFuncPurview.ID == 0 {
- rolePurviewIdStr = rolePurviewIdStr
- } else {
- rolePurviewIdStr = rolePurviewIdStr + "," + roleFuncPurview.PurviewIds
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "purviews": purviews,
- "role": role,
- "role_purview_ids": rolePurviewIdStr + "," + roleFuncPurview.PurviewIds,
- })
- }
-
- // /role/purview/edit [post]
- // @param role_id:int
- // @param purview_ids:string
- func (this *RoleAPIController) EditPurview() {
- adminUserInfo := this.GetAdminUserInfo()
- roleId, _ := this.GetInt64("role_id")
- purviewIds := this.GetString("purview_ids")
- funcPurviewIds := this.GetString("func_purview_ids")
-
- if roleId <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- redis := service.RedisClient()
- defer redis.Close()
-
- users := service.GetAllUserRole(adminUserInfo.CurrentOrgId)
- for _, item := range users {
- key := "purviews_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + strconv.FormatInt(item.AdminUserId, 10)
- redis.Set(key, "", time.Second)
- }
-
- err := service.SaveRolePurviewIds(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId, purviewIds)
- err = service.SaveFuncRolePurviewIds(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId, funcPurviewIds)
-
- if err != nil {
- //beego.Error("设置角色的权限时出错:", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- } else {
- this.ServeSuccessJSON(nil)
- }
- }
-
- // func (this *RoleAPIController) doesUserHaveAccess(userID int64) bool {
- // adminUser, getAdminUserErr := service.GetAdminUserByUserID(userID)
- // if getAdminUserErr != nil {
- // beego.Error("获取用户信息失败:%v", getAdminUserErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return false
- // } else if adminUser == nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
- // return false
- // } else if adminUser.Status == 2 {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUserWasForbidden)
- // return false
- // } else if adminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return false
- // }
- // return true
- // }
-
- // func (this *RoleAPIController) isAppRoleExist(orgID int64, appID int64, userID int64) bool {
- // appRole, getAppRoleErr := service.GetAppRole(orgID, appID, userID)
- // if getAppRoleErr != nil {
- // beego.Error("检查用户和机构应用对应关系时失败:%v", getAppRoleErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return false
- // } else if appRole == nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return false
- // }
- // return true
- // }
-
- // /api/adminmain [get]
- func (this *RoleAPIController) AdminMainView() {
- adminUserInfo := this.GetAdminUserInfo()
- var isSubSuperAdmin bool = false
- adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
- if len(adminUserRole.RoleIds) > 0 {
- role_ids := strings.Split(adminUserRole.RoleIds, ",")
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
- if adminUserInfo.AdminUser.Id != org.Creator {
- for _, item := range role_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- if id != 0 {
- role, _ := service.GetRoleByRoleID(id)
- if role != nil {
- if role.IsSystem == 1 && role.RoleName == "子管理员" {
- isSubSuperAdmin = true
- }
- }
- }
- }
- }
- }
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
-
- viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
- if getAdminsErr != nil {
- //beego.Error("获取管理员列表失败:", getAdminsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "admins": viewModels,
- "org": org,
- "isSubSuperAdmin": isSubSuperAdmin,
- })
- }
-
- // /api/admins [get]
- // @param page?:int
- func (this *RoleAPIController) Admins() {
- adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- page, _ := this.GetInt("page")
- viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
- if getAdminsErr != nil {
- //beego.Error("获取管理员列表失败:", getAdminsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "admins": viewModels,
- "total_count": total,
- })
- }
- }
-
- // /api/admin/addinit [get]
- func (this *RoleAPIController) AddAdminInitData() {
- adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- var isSubSuperAdmin bool = false
- adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
-
- if len(adminUserRole.RoleIds) > 0 {
- //app_role, _ := service.GetAppRoleById(adminUserInfo.)
- role_ids := strings.Split(adminUserRole.RoleIds, ",")
-
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
-
- if adminUserInfo.AdminUser.Id != org.Creator {
- for _, item := range role_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- if id != 0 {
- role, _ := service.GetRoleByRoleID(id)
- if role != nil {
- if role.IsSystem == 1 && role.RoleName == "子管理员" {
- isSubSuperAdmin = true
- }
- }
- }
- }
- }
- }
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
-
- roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
- if getRoleErr != nil {
- //beego.Error("获取所有角色失败:", getRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- redisClient := service.RedisClient()
- defer redisClient.Close()
- qntoken, _ := redisClient.Get("qn_token").Result()
-
- this.ServeSuccessJSON(map[string]interface{}{
- "roles": roles,
- "qntoken": qntoken,
- "isSubSuperAdmin": isSubSuperAdmin,
- "org": org,
- })
- }
-
- // /api/admin/add [post]
- // @param mobile:string
- // @param name:string
- // @param type:int 管理员类型:2.医生 3.护士 4.运营
- // @param title:int 用户职称(1.医士;2.医师;3.住院医师;4.主治医师;5.副主任医师;6.主任医师;7.护士;8.护师;9.主管护师;10.副主任护师;11.主任护师;12.运营专员;13.运营主管)
- // @param role:int
- // @param intro?:string
- func (this *RoleAPIController) AddAdmin() {
- adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- mobile := this.GetString("mobile")
- name := this.GetString("name")
- userType, _ := this.GetInt("type")
- userTitle, _ := this.GetInt("title")
- roleIds := this.GetString("role")
- user_title_name := this.GetString("user_title_name")
- department := this.GetString("department")
- department_id, _ := this.GetInt64("department_id")
-
- sex, _ := this.GetInt64("sex")
-
- age, _ := this.GetInt64("age")
- nation := this.GetString("nation")
- card_type, _ := this.GetInt64("card_type")
- id_card := this.GetString("id_card")
- education, _ := this.GetInt64("education")
- study_major_name := this.GetString("study_major_name")
- work_major_name := this.GetString("work_major_name")
- role_type, _ := this.GetInt64("role_type")
- medical_code := this.GetString("medical_code")
- doctor_code := this.GetString("doctor_code")
- licensing, _ := this.GetInt64("licensing")
- job_number := this.GetString("job_number")
-
- prescription_qualification_identification, _ := this.GetInt64("prescription_qualification_identification")
- identification_outpatients, _ := this.GetInt64("identification_outpatients")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
-
- theStartTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
-
- medical_range_code, _ := this.GetInt64("medical_range_code")
- medical_level, _ := this.GetInt64("medical_level")
- medical_type_job, _ := this.GetInt64("medical_type_job")
- pharmacist_registration_number := this.GetString("pharmacist_registration_number")
- doctor_range_code, _ := this.GetInt64("doctor_range_code")
- doctor_level, _ := this.GetInt64("doctor_level")
- doctor_type_job, _ := this.GetInt64("doctor_type_job")
- doctor_number := this.GetString("doctor_number")
- outpatient_illnessCategory := this.GetString("outpatient_illnessCategory")
- is_active, _ := this.GetInt64("is_active")
- active_status, _ := this.GetInt64("active_status")
- fmt.Println("active_status", active_status)
- if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || len(roleIds) <= 0 {
-
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- // 判断是否已存在该手机号
- if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
- //beego.Error("查询用户是否已被添加为管理员时失败:", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- if adminUser == nil { //新增账号和用户
- _, 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)
- if createErr != nil {
- //beego.Error("创建管理员失败:", createErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
-
- } else {
- sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
- if sendSMSErr != nil {
- }
-
- this.ServeSuccessJSON(nil)
- return
- }
- } else {
-
- total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.CurrentOrgId)
- if total <= 0 {
- //新增用户
- app_role := &models.App_Role{
- AdminUserId: adminUser.Id,
- OrgId: adminUserInfo.CurrentOrgId,
- AppId: adminUserInfo.CurrentAppId,
- Avatar: "",
- UserName: name,
- UserTitleName: user_title_name,
- Status: 1,
- UserType: int8(userType),
- UserTitle: int8(userTitle),
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- RoleIds: roleIds,
- Department: department,
- DepartmentId: department_id,
- Sex: sex,
- Age: age,
- Nation: nation,
- CardType: card_type,
- IdCard: id_card,
- Education: education,
- StudyMajorName: study_major_name,
- WorkMajorName: work_major_name,
- RoleType: role_type,
- MedicalCode: medical_code,
- DoctorCode: doctor_code,
- Licensing: licensing,
- JobNumber: job_number,
- PrescriptionQualificationIdentification: prescription_qualification_identification,
- IdentificationOutpatients: identification_outpatients,
- StartTime: theStartTime.Unix(),
- MedicalRangeCode: medical_range_code,
- MedicalLevel: medical_level,
- MedicalTypeJob: medical_type_job,
- PharmacistRegistrationNumber: pharmacist_registration_number,
- DoctorRangeCode: doctor_range_code,
- DoctorLevel: doctor_level,
- DoctorTypeJob: doctor_type_job,
- DoctorNumber: doctor_number,
- OutpatientIllnesscategory: outpatient_illnessCategory,
- IsActive: is_active,
- ActiveStatus: active_status,
- }
- err := service.CreateUserRole(app_role)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
- this.ServeSuccessJSON(nil)
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
- return
- }
-
- return
- }
- }
-
- }
-
- // /api/admin/editinit [get]
- // @param uid:int
- func (this *RoleAPIController) EditAdminInitData() {
- adminUserInfo := this.GetAdminUserInfo()
-
- admin_user_id, _ := this.GetInt64("uid")
- if admin_user_id <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
- if getAppRoleErr != nil {
- //beego.Error("查询管理员信息时失败:", getAppRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if appRole == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
- return
- }
-
- roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
- if getRoleErr != nil {
- //beego.Error("获取所有角色失败:", getRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- var isSubSuperAdmin bool = false
- adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
- if len(adminUserRole.RoleIds) > 0 {
- role_ids := strings.Split(adminUserRole.RoleIds, ",")
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
- if adminUserInfo.AdminUser.Id != org.Creator {
- for _, item := range role_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- if id != 0 {
- role, _ := service.GetRoleByRoleID(id)
- if role.IsSystem == 1 && role.RoleName == "子管理员" {
- isSubSuperAdmin = true
- }
- }
- }
- }
- }
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
-
- redisClient := service.RedisClient()
- defer redisClient.Close()
- qntoken, _ := redisClient.Get("qn_token").Result()
-
- this.ServeSuccessJSON(map[string]interface{}{
- "admin": appRole,
- "roles": roles,
- "qntoken": qntoken,
- "isSubSuperAdmin": isSubSuperAdmin,
- "org": org,
- })
- }
-
- // /api/admin/edit [post]
- // @param uid:int
- // @param name:string
- // @param type:int
- // @param title:int
- // @param role:int
- // @param intro?:string
- func (this *RoleAPIController) EditAdmin() {
- adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- adminUserId, _ := this.GetInt64("uid")
- name := this.GetString("name")
- userType, _ := this.GetInt("type")
- userTitle, _ := this.GetInt("title")
- roleIds := this.GetString("role")
- intro := this.GetString("intro")
- user_title_name := this.GetString("user_title_name")
- department := this.GetString("department")
- department_id, _ := this.GetInt64("department_id")
- sort, _ := this.GetInt64("sort")
- sex, _ := this.GetInt64("sex")
- age, _ := this.GetInt64("age")
- nation := this.GetString("nation")
- card_type, _ := this.GetInt64("card_type")
- id_card := this.GetString("id_card")
- education, _ := this.GetInt64("education")
- study_major_name := this.GetString("study_major_name")
- work_major_name := this.GetString("work_major_name")
- role_type, _ := this.GetInt64("role_type")
- medical_code := this.GetString("medical_code")
- doctor_code := this.GetString("doctor_code")
- licensing, _ := this.GetInt64("licensing")
- job_number := this.GetString("job_number")
-
- prescription_qualification_identification, _ := this.GetInt64("prescription_qualification_identification")
- identification_outpatients, _ := this.GetInt64("identification_outpatients")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- fmt.Println("start_time22222222222", start_time)
- theStartTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
-
- medical_range_code, _ := this.GetInt64("medical_range_code")
- medical_level, _ := this.GetInt64("medical_level")
- medical_type_job, _ := this.GetInt64("medical_type_job")
- pharmacist_registration_number := this.GetString("pharmacist_registration_number")
- doctor_range_code, _ := this.GetInt64("doctor_range_code")
- doctor_level, _ := this.GetInt64("doctor_level")
- doctor_type_job, _ := this.GetInt64("doctor_type_job")
- doctor_number := this.GetString("doctor_number")
- outpatient_illnessCategory := this.GetString("outpatient_illnessCategory")
- is_active, _ := this.GetInt64("is_active")
- active_status, _ := this.GetInt64("active_status")
-
- _, titleExist := models.UserTitle[userTitle]
- fmt.Println(titleExist)
- if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || len(roleIds) <= 0 {
- fmt.Println("进来了吗")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserId)
- if getAppRoleErr != nil {
- //beego.Error("查询管理员信息时失败:", getAppRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if appRole == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
- return
- }
- appRole.OrgId = this.GetAdminUserInfo().CurrentOrgId
- appRole.Department = department
- appRole.DepartmentId = department_id
- appRole.UserName = name
- appRole.UserType = int8(userType)
- appRole.UserTitle = int8(userTitle)
- appRole.RoleIds = roleIds
- appRole.Intro = intro
- appRole.UserTitleName = user_title_name
- appRole.ModifyTime = time.Now().Unix()
- appRole.Sort = sort
- appRole.Age = age
- appRole.Nation = nation
- appRole.CardType = card_type
- appRole.IdCard = id_card
- appRole.Education = education
- appRole.StudyMajorName = study_major_name
- appRole.WorkMajorName = work_major_name
- appRole.RoleType = role_type
- appRole.MedicalCode = medical_code
- appRole.DoctorCode = doctor_code
- appRole.Licensing = licensing
- appRole.JobNumber = job_number
- appRole.PrescriptionQualificationIdentification = prescription_qualification_identification
- appRole.IdentificationOutpatients = identification_outpatients
- appRole.StartTime = theStartTime.Unix()
- appRole.MedicalCode = medical_code
- appRole.MedicalRangeCode = medical_range_code
- appRole.MedicalLevel = medical_level
- appRole.MedicalTypeJob = medical_type_job
- appRole.PharmacistRegistrationNumber = pharmacist_registration_number
- appRole.DoctorRangeCode = doctor_range_code
- appRole.DoctorLevel = doctor_level
- appRole.DoctorTypeJob = doctor_type_job
- appRole.DoctorNumber = doctor_number
- appRole.OutpatientIllnesscategory = outpatient_illnessCategory
- appRole.IsActive = is_active
- appRole.ActiveStatus = active_status
- appRole.Sex = sex
- saveErr := service.SaveAppRole(appRole)
- if saveErr != nil {
- //beego.Error("修改App_Role失败:", saveErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
-
- } else {
- //判断当前角色是否为机构管理员
-
- this.ServeSuccessJSON(map[string]interface{}{
- "approle": appRole,
- })
- this.ServeSuccessJSON(nil)
- }
- }
-
- // /api/admin/setstatus [post]
- // @param uid:int
- // @param enable:bool
- func (this *RoleAPIController) AdminSetStatus() {
- adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- userID, _ := this.GetInt64("uid")
- if userID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, userID)
- if getAppRoleErr != nil {
- //beego.Error("查询管理员信息失败:", getAppRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if appRole == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
- return
- }
-
- enable, _ := this.GetBool("enable")
-
- if enable {
- appRole.Status = 1
- } else {
- appRole.Status = 0
- }
- appRole.ModifyTime = time.Now().Unix()
- saveErr := service.SaveAppRole(appRole)
- if saveErr != nil {
- //beego.Error("保存AppRole失败:", saveErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
-
- } else {
- this.ServeSuccessJSON(nil)
- }
- }
-
- // /api/admin/specialpermission/initdata [get]
- func (this *RoleAPIController) SpecialPermissionInitData() {
- adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- adminUsers, getAdminUsersErr := service.GetAllGeneralAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
- if getAdminUsersErr != nil {
- this.ErrorLog("获取所有普通用户失败:%v", getAdminUsersErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- headNurses, getAllHeadNursesErr := service.GetAllValidAdminUsersWithSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
- if getAllHeadNursesErr != nil {
- this.ErrorLog("获取所有拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "users": adminUsers,
- "head_nurses": headNurses,
- })
- }
-
- // /api/admin/specialpermission/dialysisrecord/submit [post]
- // @param ids:string ("1,2,5")
- func (this *RoleAPIController) SubmitDialysisRecordPermission() {
- adminUserInfo := this.GetAdminUserInfo()
- //if adminUserInfo.AdminUser.IsSuperAdmin == false {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
- // return
- //}
-
- idsString := this.GetString("ids")
- if len(idsString) == 0 {
- // 取消所有用户的护士长权限
- cancelErr := service.CancelAllSpecialPermissionAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
- if cancelErr != nil {
- this.ErrorLog("取消所有用户的护士长权限失败:%v", cancelErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- this.ServeSuccessJSON(nil)
- return
- }
-
- } else {
- ids := make([]int64, 0)
- idStrs := strings.Split(idsString, ",")
- for _, idStr := range idStrs {
- id, parseErr := strconv.Atoi(idStr)
- if parseErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- ids = append(ids, int64(id))
- }
-
- headNurses, getAllHeadNursesErr := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
- if getAllHeadNursesErr != nil {
- this.ErrorLog("获取所有拥有或曾拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- cancelList := make([]*models.AdminUserSpecialPermission, 0)
- addList := make([]*models.AdminUserSpecialPermission, 0)
- for _, id := range ids {
- exit := false
- for _, headNurse := range headNurses {
- if headNurse.AdminUserID == id {
- exit = true
- if headNurse.Status != 1 {
- headNurse.Status = 1
- headNurse.ModifyTime = time.Now().Unix()
- addList = append(addList, headNurse)
- }
- break
- }
- }
- if exit == false {
- newHeadNurse := &models.AdminUserSpecialPermission{
- OrgID: adminUserInfo.CurrentOrgId,
- AppID: adminUserInfo.CurrentAppId,
- AdminUserID: id,
- Permission: int64(models.SpecialPermissionTypeHeadNurse),
- Status: 1,
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- }
- addList = append(addList, newHeadNurse)
- }
- }
-
- for _, headNurse := range headNurses {
- cancel := true
- for _, willAdd := range addList {
- if willAdd.AdminUserID == headNurse.AdminUserID {
- cancel = false
- break
- }
- }
- if cancel {
- headNurse.Status = 0
- headNurse.ModifyTime = time.Now().Unix()
- cancelList = append(cancelList, headNurse)
- }
- }
-
- addErr := service.BatchSaveSpecialPermissionAdminUsers(addList)
- if addErr != nil {
- this.ErrorLog("授权失败:%v", addErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- cancelErr := service.BatchSaveSpecialPermissionAdminUsers(cancelList)
- if cancelErr != nil {
- this.ErrorLog("取消授权失败:%v", cancelErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(nil)
- }
-
- }
-
- func (this *RoleAPIController) GetAllOrgRole() {
- adminUserInfo := this.GetAdminUserInfo()
-
- var isSubSuperAdmin bool = false
- adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
-
- if len(adminUserRole.RoleIds) > 0 {
- //app_role, _ := service.GetAppRoleById(adminUserInfo.)
- role_ids := strings.Split(adminUserRole.RoleIds, ",")
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
- if adminUserInfo.AdminUser.Id != org.Creator {
- for _, item := range role_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- if id != 0 {
- role, _ := service.GetRoleByRoleID(id)
- if role != nil {
- if role.IsSystem == 1 && role.RoleName == "子管理员" {
- isSubSuperAdmin = true
- }
- }
- }
- }
- }
- }
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
-
- roles, err := service.GetAllOrgValidRoles(adminUserInfo.CurrentOrgId, isSubSuperAdmin)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "roles": roles,
- "isSubSuperAdmin": isSubSuperAdmin,
- "org": org,
- })
- }
-
- }
-
- func (this *RoleAPIController) GetAllOrgUser() {
- adminUserInfo := this.GetAdminUserInfo()
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
- var isSubSuperAdmin bool = false
- adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
- if len(adminUserRole.RoleIds) > 0 {
- //app_role, _ := service.GetAppRoleById(adminUserInfo.)
- role_ids := strings.Split(adminUserRole.RoleIds, ",")
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
- if adminUserInfo.AdminUser.Id != org.Creator {
- for _, item := range role_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- if id != 0 {
- role, _ := service.GetRoleByRoleID(id)
- if role != nil {
- if role.IsSystem == 1 && role.RoleName == "子管理员" {
- isSubSuperAdmin = true
- }
- }
- }
- }
- }
- }
- viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
- this.ServeSuccessJSON(map[string]interface{}{
- "admins": viewModels,
- "org": org,
- "isSubSuperAdmin": isSubSuperAdmin,
- })
- }
-
- func (this *RoleAPIController) AddRoleStaff() {
- //adminUserInfo := this.GetMobileAdminUserInfo()
- role_id, _ := this.GetInt64("id", 0)
- staff_ids := this.GetString("ids")
- ids := strings.Split(staff_ids, ",")
- for _, item := range ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- role, _ := service.FindAdminUserID(id)
- role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
- service.SaveAdminUser(&role)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "添加成功",
- })
-
- }
-
- func (this *RoleAPIController) GetRoleStaff() {
- adminUserInfo := this.GetAdminUserInfo()
-
- var isSubSuperAdmin bool = false
- adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
- if len(adminUserRole.RoleIds) > 0 {
- role_ids := strings.Split(adminUserRole.RoleIds, ",")
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
- if adminUserInfo.AdminUser.Id != org.Creator {
- for _, item := range role_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- if id != 0 {
- role, _ := service.GetRoleByRoleID(id)
- if role.IsSystem == 1 && role.RoleName == "子管理员" {
- isSubSuperAdmin = true
- }
- }
- }
- }
- }
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
- viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
- if getAdminsErr != nil {
- //beego.Error("获取管理员列表失败:", getAdminsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "admins": viewModels,
- "org": org,
- "isSubSuperAdmin": isSubSuperAdmin,
- })
-
- }
-
- func (this *RoleAPIController) GetRoleInfo() {
- roleId, _ := this.GetInt64("role_id")
- if roleId <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- role, _ := service.GetRoleByRoleID(roleId)
- this.ServeSuccessJSON(map[string]interface{}{
- "role": role,
- })
-
- }
|