organize.go 13 KB

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