| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- package casbin
- import (
- "dashoo.cn/backend/api/business/register"
- "dashoo.cn/business2/parameter"
- "encoding/json"
- "strconv"
- "dashoo.cn/business2/userRole"
- "strings"
- "dashoo.cn/backend/api/business/organize"
- . "dashoo.cn/backend/api/controllers"
- "dashoo.cn/business2/permission"
- "dashoo.cn/utils"
- )
- // Operations about Users
- type OrganizesController struct {
- BaseController
- }
- type OrganizeModel struct {
- Parentid int `json:"parentid"`
- Fullname string `json:"fullname"`
- Category string `json:"category"`
- Description string `json:"description"`
- HaveChild int `json:"havechild"`
- IsInnerOrganize int
- }
- // @Title 报警器列表
- // @Description 设备列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /list [get]
- func (this *OrganizesController) List() {
- page := this.GetPageInfoForm()
- svc := organize.GetOrganizeService(utils.DBE)
- svcPerm := permission.GetPermissionService(utils.DBE)
- isauth := svcPerm.IsAuthorized(this.User.Id, "oil_system.organize.AllRecord")
- topid := ""
- if isauth {
- paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
- topid = paramSvc.GetBaseparameterMessage("", "paramset", "HeadquartersID") // 总公司Id
- } else {
- topid = svc.GetMyUnitDepartmentId(this.User.DepartmentId)
- }
- depids := svc.GetAllChildById(topid)
- where := "( Createuserid=" + this.User.Id + " or id in (" + depids + "))"
- keyword := this.GetString("keyword")
- parentid := this.GetString("parentid")
- IsInnerOrganize := this.GetString("IsInnerOrganize")
- where = where + " and ( IsInnerOrganize= " + IsInnerOrganize + " or ParentId=0 ) "
- if keyword != "" {
- where = where + " and Fullname like '%" + keyword + "%'"
- }
- if parentid != "" && parentid != "-1" {
- ids := svc.GetAllChildByTopId(parentid, this.User.Id)
- where = where + " and Id in ( " + ids + " )"
- }
- list := make([]organize.Base_Organize, 0)
- total := svc.GetPagingEntitiesWithSortCode(page.CurrentPage, page.Size, "ParentId, CreateOn desc", &list, where)
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 根据用户AccCode get检验主表 客户原始信息内容
- // @Description get user by token
- // @Success 200 {object} models.Userblood
- // @router /cellsCollectionDetaillist [get]
- func (this *OrganizesController) CellsCollectionDetaillist() {
- svc := organize.GetOrganizeService(utils.DBE)
- where := "'" + this.User.AccCode + "'"
- list := svc.GetCollectionDetailviewlist(where)
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title get
- // @Description get SampleType by token
- // @Success 200
- // @router /detailed/:id [get]
- func (this *OrganizesController) Detailed() {
- svc := organize.GetOrganizeService(utils.DBE)
- id := this.Ctx.Input.Param(":id")
- var entity organize.Base_Organize
- where := " Id=" + id + ""
- entity = svc.QueryEntity(where)
- var datainfo DataInfo
- datainfo.Items = entity
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 组织列表带父级名称
- // @Description 设备列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /listbandparentname [get]
- func (this *OrganizesController) Listbandparentname() {
- page := this.GetPageInfoForm()
- svc := organize.GetOrganizeService(utils.DBE)
- svcPerm := permission.GetPermissionService(utils.DBE)
- isauth := svcPerm.IsAuthorized(this.User.Id, "oil_admin")
- topid := ""
- if isauth {
- paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
- topid = paramSvc.GetBaseparameterMessage("", "paramset", "HeadquartersID") // 总公司Id
- } else {
- topid = svc.GetMyUnitDepartmentId(this.User.DepartmentId)
- }
- depids := svc.GetAllChildById(topid)
- where := "( a.Createuserid=" + this.User.Id + " or a.id in (" + depids + "))"
- keyword := this.GetString("keyword")
- parentid := this.GetString("parentid")
- IsInnerOrganize := this.GetString("IsInnerOrganize")
- where = where + " and ( a.IsInnerOrganize= " + IsInnerOrganize + " or a.ParentId=0 ) "
- if keyword != "" {
- where = where + " and a.Fullname like '%" + keyword + "%'"
- }
- if parentid != "" && parentid != "-1" {
- ids := svc.GetAllChildByTopId(parentid, this.User.Id)
- where = where + " and a.Id in ( " + ids + " )"
- }
- total, list := svc.GetListbandparentname(page.CurrentPage, page.Size, "a.ParentId, a.CreateOn desc", where)
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 创建组织
- // @Description 创建组织
- // @Param body body business.device.DeviceChannels "传感器信息"
- // @Success 200 {object} controllers.Request
- // @router / [post]
- func (this *OrganizesController) AddOrganize() {
- var model OrganizeModel
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- var errinfo ErrorInfo
- var entity organize.Base_Organize
- svc := organize.GetOrganizeService(utils.DBE)
- // 编辑后添加一条数据
- entity.Fullname = model.Fullname
- entity.Parentid = model.Parentid
- entity.Description = model.Description
- entity.Createuserid, _ = utils.StrTo(this.User.Id).Int()
- entity.Createby = this.User.Realname
- entity.AccCode = this.GetAccode()
- entity.Isinnerorganize = model.IsInnerOrganize
- _, err := svc.InsertEntity(&entity)
- if err == nil {
- errinfo.Message = "添加组织成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- }
- // @Title 编辑组织
- // @Description 编辑组织
- // @Param id path string true "需要修改的传感器编号"
- // @Param body body business.device.DeviceChannels "传感器信息"
- // @Success 200 {object} controllers.Request
- // @router /:id [put]
- func (this *OrganizesController) EditOrganize() {
- id := this.Ctx.Input.Param(":id")
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model OrganizeModel
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- var entity organize.Base_Organize
- var entityempty organize.Base_Organize
- svc := organize.GetOrganizeService(utils.DBE)
- has := svc.GetEntityById(id, &entity)
- if has {
- entity.Fullname = model.Fullname
- entity.Parentid = model.Parentid
- if model.Category == "1" {
- entity.Category = "unit"
- } else {
- entity.Category = ""
- }
- entity.Description = model.Description
- entity.Modifieduserid, _ = utils.StrTo(this.User.Id).Int()
- entity.Modifiedby = this.User.Realname
- var cols []string = []string{"Fullname", "Parentid", "Description", "Category", "Modifieduserid", "Modifiedby"}
- err := svc.UpdateEntityAndBackupByCols(id, &entity, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Realname)
- if err == nil {
- errinfo.Message = "保存成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- } else {
- errinfo.Message = "操作失败!操作数据不存在"
- errinfo.Code = -3
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- }
- // @Title 删除组织
- // @Description 删除组织
- // @Param id path string true "需要删除的用户编号"
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /:id [delete]
- func (this *OrganizesController) Delete() {
- id := this.Ctx.Input.Param(":id")
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- svc := organize.GetOrganizeService(utils.DBE)
- if svc.IsHaveChild(id) {
- errinfo.Message = "操作失败!请先删除下属组织"
- errinfo.Code = -3
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- if svc.IsHaveUserUse(id) {
- errinfo.Message = "操作失败!有用户在使用此组织,请先解除绑定"
- errinfo.Code = -4
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- if svc.IsHaveEquiUse(id) {
- errinfo.Message = "操作失败!有设备在使用此组织,请先解除绑定"
- errinfo.Code = -5
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var entity organize.Base_Organize
- var entityempty organize.Base_Organize
- err := svc.DeleteEntityAndBackup(id, &entity, &entityempty, utils.ToStr(this.User.Id), this.User.Username)
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 获取子集列表
- // @Description 获取子集列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /childlist/:id [get]
- func (this *OrganizesController) ChildList() {
- id := this.Ctx.Input.Param(":id")
- svc := organize.GetOrganizeService(utils.DBE)
- where := " Createuserid= " + this.User.Id
- where = where + " and ParentId = " + id + ""
- list := make([]organize.Base_Organize, 0)
- svc.GetDatasByCols(&list, where, "Sortcode, CreateOn desc", []string{"Id", "ParentId", "Fullname"})
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 获取父集列表
- // @Description 获取父集列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /parentlist/:id [get]
- func (this *OrganizesController) ParentList() {
- id := this.Ctx.Input.Param(":id")
- svc := organize.GetOrganizeService(utils.DBE)
- var errinfo ErrorInfo
- errinfo.Message = svc.GetAllParentByTopId(id, this.User.Id)
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- // @Title get 业务列表
- // @Description get SampleType by token
- // @Success 200 {object} sampletype.SampleType
- // @router /getorganizetreelist [get]
- func (this *OrganizesController) GetOrganizeTreeList() {
- svc := organize.GetOrganizeService(utils.DBE)
- where := " 1 = 1 "
- var list []organize.Base_Orgatree
- //获取技术服务类资质分类层级信息
- svc.GetEntitysByWhere("Base_Organize", where, &list)
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 获取医院组织结构
- // @Description 获取医院
- // @Success 200 {object} business.device.DeviceChannels
- // @router /gethospitallist [get]
- func (this *OrganizesController) GetHospitalList() {
- svvv := permission.GetPermissionService(utils.DBE)
- entity := svvv.GetOrganizeTreeByAcccdeAndPermission(this.User.AccCode, "cellbank.cellorder.hospital")
- var datainfo DataInfo
- datainfo.Items = entity
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 判断用户审核权限
- // @Description
- // @Success 200 {object} business.device.DeviceChannels
- // @router /getorderapprove [get]
- func (this *OrganizesController) GetOrderApprove() {
- svc := permission.GetPermissionService(utils.DBE)
- entity := svc.IsAuthorized(this.User.Id, "cellbank.order.approve")
- var datainfo DataInfo
- datainfo.Items = entity
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 医院结构 获取父集列表
- // @Description 获取父集列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /organizeparentlist/:id [get]
- func (this *OrganizesController) OrganizeParentList() {
- id := this.Ctx.Input.Param(":id")
- svc := organize.GetOrganizeService(utils.DBE)
- var hoapital string
- model := svc.GetAllParentByTopAccCode(id, this.User.AccCode)
- arr := strings.Split(model, ",")
- for i := len(arr) - 4; i >= 0; i-- {
- if i == 0 {
- where := " Id= " + arr[i]
- entity := svc.QueryEntity(where)
- hoapital += entity.Fullname
- } else {
- where := " Id= " + arr[i]
- entity := svc.QueryEntity(where)
- hoapital += entity.Fullname + "/"
- }
- }
- var datainfo DataInfo
- datainfo.Items = hoapital
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 报警器列表
- // @Description 设备列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /listbydeptid [get]
- func (this *OrganizesController) ListByDeptId() {
- svc := organize.GetOrganizeService(utils.DBE)
- svcPerm := permission.GetPermissionService(utils.DBE)
- isauth := svcPerm.IsAuthorized(this.User.Id, "oil_admin")
- unitId := ""
- if isauth {
- paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
- unitId = paramSvc.GetBaseparameterMessage("", "paramset", "HeadquartersID") // 总公司Id
- } else {
- unitId = svc.GetMyUnitDepartmentId(this.User.DepartmentId)
- }
- ids := svc.GetAllChildById(unitId)
- where := " Id in ( " + ids + " ) "
- list := make([]organize.Base_Organize, 0)
- svc.GetEntities(&list, where)
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 报警器列表
- // @Description 设备列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /orgalllist [get]
- func (this *OrganizesController) OrgAllList() {
- svc := organize.GetOrganizeService(utils.DBE)
- var user userRole.Base_User
- svc.GetEntityById(this.User.Id, &user)
- ids := ""
- if this.User.DepartmentId == "" {
- ids = svc.GetAllChildById("100000000")
- } else {
- unitId := svc.GetMyUnitDepartmentId(this.User.DepartmentId)
- ids = svc.GetAllChildById(unitId)
- }
- where := " Id in ( " + ids + " )"
- list := make([]organize.Base_Organize, 0)
- svc.GetEntities(&list, where)
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 报警器列表
- // @Description 设备列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /orgalllistfenban [get]
- func (this *OrganizesController) OrgAllListFen() {
- svc := organize.GetOrganizeService(utils.DBE)
- var user userRole.Base_User
- svc.GetEntityById(this.User.Id, &user)
- var model register.OilCorporateInfo
- where := "UserId=" + this.User.Id
- has := svc.GetEntity(&model, where)
- ids := ""
- if has {
- ids = svc.GetAllChildById(strconv.Itoa(model.CheckUnitId))
- } else {
- ids = svc.GetAllChildById("0")
- }
- where = " Id in ( " + ids + " )"
- list := make([]organize.Base_Organize, 0)
- svc.GetEntities(&list, where)
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 组织列表信息(不需要验证登录)
- // @Description 组织列表信息(不需要验证登录)
- // @Success 200 {object} organize.Base_Organize
- // @router /getorglist [get]
- func (this *OrganizesController) GetOrgList() {
- svc := organize.GetOrganizeService(utils.DBE)
- var user userRole.Base_User
- svc.GetEntityById(this.User.Id, &user)
- ids := svc.GetAllChildById("0")
- where := " Id in ( " + ids + " )"
- list := make([]organize.Base_Organize, 0)
- svc.GetEntities(&list, where)
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
|