organize.go 15 KB

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