organize.go 15 KB

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