2
3

organize.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. package casbin
  2. import (
  3. "encoding/json"
  4. //"fmt"
  5. "dashoo.cn/backend/api/business/oilsupplier/technologyservice"
  6. "dashoo.cn/business2/userRole"
  7. "strings"
  8. "dashoo.cn/backend/api/business/organize"
  9. . "dashoo.cn/backend/api/controllers"
  10. "dashoo.cn/business2/permission"
  11. "dashoo.cn/utils"
  12. )
  13. // Operations about Users
  14. type OrganizesController struct {
  15. BaseController
  16. }
  17. type OrganizeModel struct {
  18. Parentid int `json:"parentid"`
  19. Fullname string `json:"fullname"`
  20. Description string `json:"description"`
  21. HaveChild int `json:"havechild"`
  22. IsInnerOrganize int
  23. }
  24. // @Title 报警器列表
  25. // @Description 设备列表
  26. // @Success 200 {object} business.device.DeviceChannels
  27. // @router /list [get]
  28. func (this *OrganizesController) List() {
  29. page := this.GetPageInfoForm()
  30. svc := organize.GetOrganizeService(utils.DBE)
  31. where := " ( Createuserid=" + this.User.Id + " or id = " + this.User.DepartmentId + ")"
  32. keyword := this.GetString("keyword")
  33. parentid := this.GetString("parentid")
  34. IsInnerOrganize := this.GetString("IsInnerOrganize")
  35. where = where + " and ( IsInnerOrganize= " + IsInnerOrganize + " or ParentId=0 ) "
  36. if keyword != "" {
  37. where = where + " and Fullname like '%" + keyword + "%'"
  38. }
  39. if parentid != "" && parentid != "-1" {
  40. ids := svc.GetAllChildByTopId(parentid, this.User.Id)
  41. where = where + " and Id in ( " + ids + " )"
  42. }
  43. list := make([]organize.Base_Organize, 0)
  44. total := svc.GetPagingEntitiesWithSortCode(page.CurrentPage, page.Size, "ParentId, CreateOn desc", &list, where)
  45. var datainfo DataInfo
  46. datainfo.Items = list
  47. datainfo.CurrentItemCount = total
  48. this.Data["json"] = &datainfo
  49. this.ServeJSON()
  50. }
  51. // @Title 根据用户AccCode get检验主表 客户原始信息内容
  52. // @Description get user by token
  53. // @Success 200 {object} models.Userblood
  54. // @router /cellsCollectionDetaillist [get]
  55. func (this *OrganizesController) CellsCollectionDetaillist() {
  56. svc := organize.GetOrganizeService(utils.DBE)
  57. where := "'" + this.User.AccCode + "'"
  58. list := svc.GetCollectionDetailviewlist(where)
  59. var datainfo DataInfo
  60. datainfo.Items = list
  61. this.Data["json"] = &datainfo
  62. this.ServeJSON()
  63. }
  64. // @Title get
  65. // @Description get SampleType by token
  66. // @Success 200
  67. // @router /detailed/:id [get]
  68. func (this *OrganizesController) Detailed() {
  69. svc := organize.GetOrganizeService(utils.DBE)
  70. id := this.Ctx.Input.Param(":id")
  71. var entity organize.Base_Organize
  72. where := " Id=" + id + ""
  73. entity = svc.QueryEntity(where)
  74. var datainfo DataInfo
  75. datainfo.Items = entity
  76. this.Data["json"] = &datainfo
  77. this.ServeJSON()
  78. }
  79. // @Title 组织列表带父级名称
  80. // @Description 设备列表
  81. // @Success 200 {object} business.device.DeviceChannels
  82. // @router /listbandparentname [get]
  83. func (this *OrganizesController) Listbandparentname() {
  84. page := this.GetPageInfoForm()
  85. svc := organize.GetOrganizeService(utils.DBE)
  86. where := "( a.Createuserid=" + this.User.Id + " or a.id = " + this.User.DepartmentId + ")"
  87. keyword := this.GetString("keyword")
  88. parentid := this.GetString("parentid")
  89. IsInnerOrganize := this.GetString("IsInnerOrganize")
  90. where = where + " and ( a.IsInnerOrganize= " + IsInnerOrganize + " or a.ParentId=0 ) "
  91. if keyword != "" {
  92. where = where + " and a.Fullname like '%" + keyword + "%'"
  93. }
  94. if parentid != "" && parentid != "-1" {
  95. ids := svc.GetAllChildByTopId(parentid, this.User.Id)
  96. where = where + " and a.Id in ( " + ids + " )"
  97. }
  98. total, list := svc.GetListbandparentname(page.CurrentPage, page.Size, "a.ParentId, a.CreateOn desc", where)
  99. var datainfo DataInfo
  100. datainfo.Items = list
  101. datainfo.CurrentItemCount = total
  102. this.Data["json"] = &datainfo
  103. this.ServeJSON()
  104. }
  105. // @Title 创建组织
  106. // @Description 创建组织
  107. // @Param body body business.device.DeviceChannels "传感器信息"
  108. // @Success 200 {object} controllers.Request
  109. // @router / [post]
  110. func (this *OrganizesController) AddOrganize() {
  111. var model OrganizeModel
  112. var jsonblob = this.Ctx.Input.RequestBody
  113. json.Unmarshal(jsonblob, &model)
  114. var errinfo ErrorInfo
  115. var entity organize.Base_Organize
  116. svc := organize.GetOrganizeService(utils.DBE)
  117. // 编辑后添加一条数据
  118. entity.Fullname = model.Fullname
  119. entity.Parentid = model.Parentid
  120. entity.Description = model.Description
  121. entity.Createuserid, _ = utils.StrTo(this.User.Id).Int()
  122. entity.Createby = this.User.Realname
  123. entity.AccCode = this.GetAccode()
  124. entity.Isinnerorganize = model.IsInnerOrganize
  125. _, err := svc.InsertEntity(&entity)
  126. if err == nil {
  127. errinfo.Message = "添加组织成功!"
  128. errinfo.Code = 0
  129. this.Data["json"] = &errinfo
  130. this.ServeJSON()
  131. return
  132. } else {
  133. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  134. errinfo.Code = -1
  135. this.Data["json"] = &errinfo
  136. this.ServeJSON()
  137. return
  138. }
  139. }
  140. // @Title 编辑组织
  141. // @Description 编辑组织
  142. // @Param id path string true "需要修改的传感器编号"
  143. // @Param body body business.device.DeviceChannels "传感器信息"
  144. // @Success 200 {object} controllers.Request
  145. // @router /:id [put]
  146. func (this *OrganizesController) EditOrganize() {
  147. id := this.Ctx.Input.Param(":id")
  148. var errinfo ErrorInfo
  149. if id == "" {
  150. errinfo.Message = "操作失败!请求信息不完整"
  151. errinfo.Code = -2
  152. this.Data["json"] = &errinfo
  153. this.ServeJSON()
  154. return
  155. }
  156. var model OrganizeModel
  157. var jsonblob = this.Ctx.Input.RequestBody
  158. json.Unmarshal(jsonblob, &model)
  159. var entity organize.Base_Organize
  160. var entityempty organize.Base_Organize
  161. svc := organize.GetOrganizeService(utils.DBE)
  162. has := svc.GetEntityById(id, &entity)
  163. if has {
  164. entity.Fullname = model.Fullname
  165. entity.Parentid = model.Parentid
  166. entity.Description = model.Description
  167. entity.Modifieduserid, _ = utils.StrTo(this.User.Id).Int()
  168. entity.Modifiedby = this.User.Realname
  169. var cols []string = []string{"Fullname", "Parentid", "Description", "Modifieduserid", "Modifiedby"}
  170. err := svc.UpdateEntityAndBackupByCols(id, &entity, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Realname)
  171. if err == nil {
  172. errinfo.Message = "保存成功!"
  173. errinfo.Code = 0
  174. this.Data["json"] = &errinfo
  175. this.ServeJSON()
  176. } else {
  177. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  178. errinfo.Code = -1
  179. this.Data["json"] = &errinfo
  180. this.ServeJSON()
  181. }
  182. } else {
  183. errinfo.Message = "操作失败!操作数据不存在"
  184. errinfo.Code = -3
  185. this.Data["json"] = &errinfo
  186. this.ServeJSON()
  187. return
  188. }
  189. }
  190. // @Title 删除组织
  191. // @Description 删除组织
  192. // @Param id path string true "需要删除的用户编号"
  193. // @Success 200 {object} ErrorInfo
  194. // @Failure 403 :id 为空
  195. // @router /:id [delete]
  196. func (this *OrganizesController) Delete() {
  197. id := this.Ctx.Input.Param(":id")
  198. var errinfo ErrorInfo
  199. if id == "" {
  200. errinfo.Message = "操作失败!请求信息不完整"
  201. errinfo.Code = -2
  202. this.Data["json"] = &errinfo
  203. this.ServeJSON()
  204. return
  205. }
  206. svc := organize.GetOrganizeService(utils.DBE)
  207. if svc.IsHaveChild(id) {
  208. errinfo.Message = "操作失败!请先删除下属组织"
  209. errinfo.Code = -3
  210. this.Data["json"] = &errinfo
  211. this.ServeJSON()
  212. return
  213. }
  214. if svc.IsHaveUserUse(id) {
  215. errinfo.Message = "操作失败!有用户在使用此组织,请先解除绑定"
  216. errinfo.Code = -4
  217. this.Data["json"] = &errinfo
  218. this.ServeJSON()
  219. return
  220. }
  221. if svc.IsHaveEquiUse(id) {
  222. errinfo.Message = "操作失败!有设备在使用此组织,请先解除绑定"
  223. errinfo.Code = -5
  224. this.Data["json"] = &errinfo
  225. this.ServeJSON()
  226. return
  227. }
  228. var entity organize.Base_Organize
  229. var entityempty organize.Base_Organize
  230. err := svc.DeleteEntityAndBackup(id, &entity, &entityempty, utils.ToStr(this.User.Id), this.User.Username)
  231. if err == nil {
  232. errinfo.Message = "删除成功"
  233. errinfo.Code = 0
  234. this.Data["json"] = &errinfo
  235. this.ServeJSON()
  236. } else {
  237. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  238. errinfo.Code = -1
  239. this.Data["json"] = &errinfo
  240. this.ServeJSON()
  241. }
  242. }
  243. // @Title 获取子集列表
  244. // @Description 获取子集列表
  245. // @Success 200 {object} business.device.DeviceChannels
  246. // @router /childlist/:id [get]
  247. func (this *OrganizesController) ChildList() {
  248. id := this.Ctx.Input.Param(":id")
  249. svc := organize.GetOrganizeService(utils.DBE)
  250. where := " Createuserid= " + this.User.Id
  251. where = where + " and ParentId = " + id + ""
  252. list := make([]organize.Base_Organize, 0)
  253. svc.GetDatasByCols(&list, where, "Sortcode, CreateOn desc", []string{"Id", "ParentId", "Fullname"})
  254. var datainfo DataInfo
  255. datainfo.Items = list
  256. this.Data["json"] = &datainfo
  257. this.ServeJSON()
  258. }
  259. // @Title 获取父集列表
  260. // @Description 获取父集列表
  261. // @Success 200 {object} business.device.DeviceChannels
  262. // @router /parentlist/:id [get]
  263. func (this *OrganizesController) ParentList() {
  264. id := this.Ctx.Input.Param(":id")
  265. svc := organize.GetOrganizeService(utils.DBE)
  266. var errinfo ErrorInfo
  267. errinfo.Message = svc.GetAllParentByTopId(id, this.User.Id)
  268. errinfo.Code = 0
  269. this.Data["json"] = &errinfo
  270. this.ServeJSON()
  271. }
  272. // @Title get 业务列表
  273. // @Description get SampleType by token
  274. // @Success 200 {object} sampletype.SampleType
  275. // @router /getorganizetreelist [get]
  276. func (this *OrganizesController) GetOrganizeTreeList() {
  277. svc := technologyservice.GetOilTechnologyServiceService(utils.DBE)
  278. where := " 1 = 1 "
  279. var list []organize.Base_Orgatree
  280. //获取技术服务类资质分类层级信息
  281. svc.GetEntitysByWhere("Base_Organize", where, &list)
  282. var datainfo DataInfo
  283. datainfo.Items = list
  284. this.Data["json"] = &datainfo
  285. this.ServeJSON()
  286. }
  287. // @Title 获取医院组织结构
  288. // @Description 获取医院
  289. // @Success 200 {object} business.device.DeviceChannels
  290. // @router /gethospitallist [get]
  291. func (this *OrganizesController) GetHospitalList() {
  292. svvv := permission.GetPermissionService(utils.DBE)
  293. entity := svvv.GetOrganizeTreeByAcccdeAndPermission(this.User.AccCode, "cellbank.cellorder.hospital")
  294. var datainfo DataInfo
  295. datainfo.Items = entity
  296. this.Data["json"] = &datainfo
  297. this.ServeJSON()
  298. }
  299. // @Title 判断用户审核权限
  300. // @Description
  301. // @Success 200 {object} business.device.DeviceChannels
  302. // @router /getorderapprove [get]
  303. func (this *OrganizesController) GetOrderApprove() {
  304. svc := permission.GetPermissionService(utils.DBE)
  305. entity := svc.IsAuthorized(this.User.Id, "cellbank.order.approve")
  306. var datainfo DataInfo
  307. datainfo.Items = entity
  308. this.Data["json"] = &datainfo
  309. this.ServeJSON()
  310. }
  311. // @Title 医院结构 获取父集列表
  312. // @Description 获取父集列表
  313. // @Success 200 {object} business.device.DeviceChannels
  314. // @router /organizeparentlist/:id [get]
  315. func (this *OrganizesController) OrganizeParentList() {
  316. id := this.Ctx.Input.Param(":id")
  317. svc := organize.GetOrganizeService(utils.DBE)
  318. var hoapital string
  319. model := svc.GetAllParentByTopAccCode(id, this.User.AccCode)
  320. arr := strings.Split(model, ",")
  321. for i := len(arr) - 4; i >= 0; i-- {
  322. if i == 0 {
  323. where := " Id= " + arr[i]
  324. entity := svc.QueryEntity(where)
  325. hoapital += entity.Fullname
  326. } else {
  327. where := " Id= " + arr[i]
  328. entity := svc.QueryEntity(where)
  329. hoapital += entity.Fullname + "/"
  330. }
  331. }
  332. var datainfo DataInfo
  333. datainfo.Items = hoapital
  334. this.Data["json"] = &datainfo
  335. this.ServeJSON()
  336. }
  337. // @Title 报警器列表
  338. // @Description 设备列表
  339. // @Success 200 {object} business.device.DeviceChannels
  340. // @router /listbydeptid [get]
  341. func (this *OrganizesController) ListByDeptId() {
  342. ParentId := this.GetString("ParentId")
  343. var user userRole.Base_User
  344. svc := organize.GetOrganizeService(utils.DBE)
  345. svc.GetEntityById(this.User.Id, &user)
  346. companyids := strings.Split(user.Superior, ",")
  347. ids := ""
  348. if ParentId != "" {
  349. ids = svc.GetAllChildById("100000180")
  350. } else {
  351. has := svc.UserInRoleById(this.User.Id, "10000203")
  352. if has {
  353. ids = svc.GetAllChildById("100000054")
  354. } else {
  355. ids = svc.GetAllChildById(companyids[len(companyids)-1])
  356. }
  357. }
  358. where := " Id in ( " + ids + " ) and AccCode='" + this.User.AccCode + "'"
  359. list := make([]organize.Base_Organize, 0)
  360. svc.GetEntities(&list, where)
  361. var datainfo DataInfo
  362. datainfo.Items = list
  363. this.Data["json"] = &datainfo
  364. this.ServeJSON()
  365. }
  366. // @Title 报警器列表
  367. // @Description 设备列表
  368. // @Success 200 {object} business.device.DeviceChannels
  369. // @router /orgalllist [get]
  370. func (this *OrganizesController) OrgAllList() {
  371. svc := organize.GetOrganizeService(utils.DBE)
  372. var user userRole.Base_User
  373. svc.GetEntityById(this.User.Id, &user)
  374. ids := svc.GetAllChildById("0")
  375. where := " Id in ( " + ids + " ) and AccCode='" + this.User.AccCode + "'"
  376. list := make([]organize.Base_Organize, 0)
  377. svc.GetEntities(&list, where)
  378. var datainfo DataInfo
  379. datainfo.Items = list
  380. this.Data["json"] = &datainfo
  381. this.ServeJSON()
  382. }