package casbin import ( "encoding/json" //"fmt" "dashoo.cn/backend/api/business/oilsupplier/technologyservice" "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"` 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) 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) 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 entity.Description = model.Description entity.Modifieduserid, _ = utils.StrTo(this.User.Id).Int() entity.Modifiedby = this.User.Realname var cols []string = []string{"Fullname", "Parentid", "Description", "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 := technologyservice.GetOilTechnologyServiceService(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() { //ParentId := this.GetString("ParentId") //var user userRole.Base_User svc := organize.GetOrganizeService(utils.DBE) unitId := svc.GetMyUnitDepartmentId(this.User.DepartmentId) //svc.GetEntityById(this.User.Id, &user) //companyids := strings.Split(user.Superior, ",") ids := svc.GetAllChildById(unitId) //ids := "" //if ParentId != "" { // ids = svc.GetAllChildById("100000180") //} else { // has := svc.UserInRoleById(this.User.Id, "10000203") // if has { // ids = svc.GetAllChildById("100000054") // } else { // ids = svc.GetAllChildById(companyids[len(companyids)-1]) // } //} where := " Id in ( " + ids + " ) and AccCode='" + this.User.AccCode + "'" 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 := svc.GetAllChildById("0") where := " Id in ( " + ids + " ) and AccCode='" + this.User.AccCode + "'" 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() }