secondary_order_api_contorller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "strings"
  12. "time"
  13. )
  14. type SecondaryOrderApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func SecondaryOrderApiRegistRouters() {
  18. beego.Router("/api/secondary/getcode", &SecondaryOrderApiController{}, "get:GetStoreCode") //获取仓库编码
  19. beego.Router("/api/secondary/updatestatus", &SecondaryOrderApiController{}, "get:UpdateStatus") //修改仓库状态
  20. beego.Router("/api/secondary/deletestorehouse", &SecondaryOrderApiController{}, "get:DeleteStorehouse") //删除仓库
  21. beego.Router("/api/secondary/isstorehousename", &SecondaryOrderApiController{}, "get:IsStorehouseName") //仓库名称是否重复
  22. beego.Router("/api/secondary/isstorehouseaddress", &SecondaryOrderApiController{}, "get:IsStorehouseAddress") //仓库地址是否重复
  23. beego.Router("/api/secondary/storehouselist", &SecondaryOrderApiController{}, "get:StorehouseList") //分页
  24. beego.Router("/api/secondary/addstorehouse", &SecondaryOrderApiController{}, "post:AddStorehouse") //新增仓库
  25. beego.Router("/api/secondary/updatestorehouse", &SecondaryOrderApiController{}, "post:UpdateStorehouse") //修改
  26. beego.Router("/api/secondary/getonestorehouse", &SecondaryOrderApiController{}, "get:GetOneStorehouse") //查一条仓库的信息
  27. beego.Router("/api/secondary/getallstorehousename", &SecondaryOrderApiController{}, "get:GetAllStorehouseName") //获取当前机构的所有可用仓库名称
  28. beego.Router("/api/secondary/findstorehouseconfig", &SecondaryOrderApiController{}, "get:FindStorehouseConfig") //查询该机构的仓库配置
  29. beego.Router("/api/secondary/updateinfo", &SecondaryOrderApiController{}, "get:UpdateInfo") //更改耗材自动入库仓库
  30. beego.Router("/api/secondary/updateoutinfo", &SecondaryOrderApiController{}, "get:UpdateOutInfo") //更改耗材自动出库仓库
  31. beego.Router("/api/secondary/updatedruginfo", &SecondaryOrderApiController{}, "get:UpdateDrugInfo") //更改药品自动入库仓库
  32. beego.Router("/api/secondary/updatedrugout", &SecondaryOrderApiController{}, "get:UpdateDrugOut") //更改药品自动出库仓库
  33. beego.Router("/api/secondary/getusername", &SecondaryOrderApiController{}, "get:GetuserName") //获取仓库管理员信息
  34. beego.Router("/api/secondary/byliinit", &SecondaryOrderApiController{}, "get:Byliinit") //初始化旧数据
  35. beego.Router("/api/secondary/getcreaterid", &SecondaryOrderApiController{}, "get:GetCreaterId") //获取当前登录的人的id
  36. }
  37. //获取仓库编码
  38. func (this *SecondaryOrderApiController) GetStoreCode() {
  39. orgId := this.GetAdminUserInfo().CurrentOrgId
  40. var code string
  41. for a := true; a == true; {
  42. code = service.CreateCode()
  43. tmp := service.FindStorehouseCode(orgId, code)
  44. //如果没有重复的编码结束循环
  45. if tmp == false {
  46. a = false
  47. }
  48. }
  49. this.ServeSuccessJSON(map[string]interface{}{
  50. "list": code,
  51. })
  52. return
  53. }
  54. //修改仓库状态
  55. func (this *SecondaryOrderApiController) UpdateStatus() {
  56. orgId := this.GetAdminUserInfo().CurrentOrgId
  57. check := map[string][]string{
  58. "id": {"must", "int", "id"},
  59. }
  60. _, err := checkParams(this, &check)
  61. if err != nil {
  62. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  63. return
  64. }
  65. id, _ := this.GetInt64("id")
  66. //判断该仓库的库存是否为零
  67. boolean := service.IsStorehouseNil(id, orgId)
  68. if boolean == false {
  69. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  70. return
  71. }
  72. //判断该仓库是否在仓库配置表中
  73. boolean = service.IsInConfig(orgId, id)
  74. if boolean == true {
  75. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  76. return
  77. }
  78. //修改仓库状态
  79. err = service.UpdateStorehouseStatus(id)
  80. if err != nil {
  81. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  82. return
  83. }
  84. this.ServeSuccessJSON(map[string]interface{}{
  85. "list": "修改成功",
  86. })
  87. return
  88. }
  89. //删除仓库
  90. func (this *SecondaryOrderApiController) DeleteStorehouse() {
  91. orgId := this.GetAdminUserInfo().CurrentOrgId
  92. check := map[string][]string{
  93. "id": {"must", "int", "id"},
  94. }
  95. _, err := checkParams(this, &check)
  96. if err != nil {
  97. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  98. return
  99. }
  100. id, _ := this.GetInt64("id")
  101. //判断该仓库的库存是否为零
  102. boolean := service.IsStorehouseNil(id, orgId)
  103. if boolean == false {
  104. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  105. return
  106. }
  107. //判断该仓库是否在仓库配置表中
  108. boolean = service.IsInConfig(orgId, id)
  109. if boolean == true {
  110. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  111. return
  112. }
  113. err = service.DeleteStorehouse(id)
  114. if err != nil {
  115. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  116. return
  117. }
  118. this.ServeSuccessJSON(map[string]interface{}{
  119. "list": "删除成功",
  120. })
  121. return
  122. }
  123. //仓库名称是否重复
  124. func (this *SecondaryOrderApiController) IsStorehouseName() {
  125. orgId := this.GetAdminUserInfo().CurrentOrgId
  126. storehouse_name := this.GetString("storehouse_name")
  127. check := map[string][]string{
  128. "storehouse_name": {"must", "string", "storehouse_name"},
  129. }
  130. _, err := checkParams(this, &check)
  131. if err != nil {
  132. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  133. return
  134. }
  135. var bo bool
  136. bo, err = service.IsStorehouseName(orgId, storehouse_name)
  137. if bo == true {
  138. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  139. return
  140. }
  141. this.ServeSuccessJSON(map[string]interface{}{
  142. "list": "ok",
  143. })
  144. return
  145. }
  146. //仓库地址是否重复
  147. func (this *SecondaryOrderApiController) IsStorehouseAddress() {
  148. orgId := this.GetAdminUserInfo().CurrentOrgId
  149. storehouse_address := this.GetString("storehouse_address")
  150. check := map[string][]string{
  151. "storehouse_address": {"must", "string", "storehouse_address"},
  152. }
  153. _, err := checkParams(this, &check)
  154. if err != nil {
  155. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  156. return
  157. }
  158. var bo bool
  159. bo, err = service.IsStorehouseAddress(orgId, storehouse_address)
  160. if bo == true {
  161. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  162. return
  163. }
  164. this.ServeSuccessJSON(map[string]interface{}{
  165. "list": "ok",
  166. })
  167. return
  168. }
  169. //分页
  170. func (this *SecondaryOrderApiController) StorehouseList() {
  171. adminUserInfo := this.GetAdminUserInfo()
  172. page, _ := this.GetInt64("page") //页码
  173. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  174. check := map[string][]string{
  175. "page": {"must", "string", "page"},
  176. "limit": {"must", "string", "limit"},
  177. }
  178. _, err := checkParams(this, &check)
  179. keyword := this.GetString("keyword")
  180. orgId := this.GetAdminUserInfo().CurrentOrgId
  181. if err != nil {
  182. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  183. }
  184. namemap := make(map[int64]string)
  185. //根据管理员id获取管理员
  186. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  187. for _, v := range viewModels {
  188. namemap[int64(v.AdminUserId)] = v.UserName
  189. }
  190. slicekey := make([]int64, 0)
  191. if len(keyword) > 0 {
  192. for k, v := range namemap {
  193. res := strings.Contains(v, keyword)
  194. if res == true {
  195. slicekey = append(slicekey, k)
  196. }
  197. }
  198. }
  199. //获取分页的数据
  200. list, total, err := service.StorehouseList(page, limit, orgId, keyword, slicekey)
  201. //分页
  202. type Storehouselist struct {
  203. ID int64
  204. StorehouseCode string //仓库编号
  205. StorehouseName string //仓库名称
  206. StorehouseAddress string //仓库地址
  207. StorehouseStatus int64 //仓库状态
  208. Status int64 //数据状态
  209. StorehouseAdminId int64 //仓库管理员id
  210. StorehouseAdminName string //仓库管理员名字
  211. UserOrgId int64
  212. }
  213. //初始化该结构体
  214. tmplist := []*Storehouselist{}
  215. for i := 0; i < len(list); i++ {
  216. tlist := &Storehouselist{
  217. list[i].ID,
  218. list[i].StorehouseCode,
  219. list[i].StorehouseName,
  220. list[i].StorehouseAddress,
  221. list[i].StorehouseStatus,
  222. list[i].Status,
  223. list[i].StorehouseAdminId,
  224. "",
  225. list[i].UserOrgId,
  226. }
  227. tmplist = append(tmplist, tlist)
  228. }
  229. for _, v := range tmplist {
  230. if k, ok := namemap[v.StorehouseAdminId]; ok {
  231. v.StorehouseAdminName = k
  232. } else {
  233. v.StorehouseAdminName = "超级管理员"
  234. }
  235. }
  236. this.ServeSuccessJSON(map[string]interface{}{
  237. "list": tmplist,
  238. "total": total,
  239. })
  240. }
  241. //新增仓库
  242. func (this *SecondaryOrderApiController) AddStorehouse() {
  243. orgId := this.GetAdminUserInfo().CurrentOrgId
  244. dataBody := make(map[string]interface{}, 0)
  245. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  246. if err != nil {
  247. utils.ErrorLog(err.Error())
  248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  249. return
  250. }
  251. var storehouse_status, admin_id int64
  252. tmpstatus := dataBody["storehouse_status"]
  253. tmpid := dataBody["storehouse_admin_id"] //管理员id
  254. if tmpstatus == nil {
  255. storehouse_status = 1
  256. } else {
  257. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  258. }
  259. if tmpid == nil {
  260. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  261. return
  262. } else {
  263. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  264. }
  265. switch {
  266. case dataBody["storehouse_code"] == nil:
  267. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库编号不能为空")
  268. return
  269. case dataBody["storehouse_name"] == nil:
  270. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  271. return
  272. case dataBody["storehouse_address"] == nil:
  273. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  274. return
  275. }
  276. code := dataBody["storehouse_code"].(string) //仓库编号
  277. name := dataBody["storehouse_name"].(string) //仓库名称
  278. address := dataBody["storehouse_address"].(string) //地址
  279. switch {
  280. case name == "":
  281. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  282. return
  283. case address == "":
  284. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  285. return
  286. }
  287. //判断仓库名称是否重复
  288. var bo bool
  289. bo, err = service.IsStorehouseName(orgId, name)
  290. if bo == true {
  291. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  292. return
  293. }
  294. //判断仓库地址是否重复
  295. bo, err = service.IsStorehouseAddress(orgId, address)
  296. if bo == true {
  297. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  298. return
  299. }
  300. storehouse := models.Storehouse{
  301. StorehouseCode: code,
  302. StorehouseName: name,
  303. StorehouseAddress: address,
  304. StorehouseStatus: storehouse_status,
  305. UserOrgId: orgId,
  306. Status: 1,
  307. StorehouseAdminId: admin_id,
  308. Ctime: time.Now().Unix(),
  309. }
  310. err = service.AddStroehouse(storehouse)
  311. if err != nil {
  312. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  313. return
  314. }
  315. this.ServeSuccessJSON(map[string]interface{}{
  316. "list": "保存成功",
  317. })
  318. return
  319. }
  320. //修改仓库
  321. func (this *SecondaryOrderApiController) UpdateStorehouse() {
  322. orgId := this.GetAdminUserInfo().CurrentOrgId
  323. dataBody := make(map[string]interface{}, 0)
  324. //orgId := this.GetAdminUserInfo().CurrentOrgId
  325. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  326. if err != nil {
  327. utils.ErrorLog(err.Error())
  328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  329. return
  330. }
  331. var storehouse_status, admin_id int64
  332. tmpstatus := dataBody["storehouse_status"]
  333. tmpid := dataBody["storehouse_admin_id"]
  334. if tmpstatus == nil {
  335. storehouse_status = 1
  336. } else {
  337. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  338. }
  339. if tmpid == nil {
  340. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  341. return
  342. } else {
  343. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  344. }
  345. switch {
  346. case dataBody["id"] == nil:
  347. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库id不能为空")
  348. return
  349. case dataBody["storehouse_name"] == nil:
  350. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  351. return
  352. case dataBody["storehouse_address"] == nil:
  353. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  354. return
  355. }
  356. id := int64(dataBody["id"].(float64))
  357. name := dataBody["storehouse_name"].(string) //仓库名称
  358. address := dataBody["storehouse_address"].(string) //地址
  359. //查询当前仓库状态,根据当前状态判断是否需要更改
  360. list, errs := service.GetOneStorehouse(id, orgId)
  361. if errs != nil {
  362. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  363. return
  364. }
  365. if storehouse_status != list.StorehouseStatus && storehouse_status == 0 {
  366. //判断该仓库的库存是否为零
  367. boolean := service.IsStorehouseNil(id, orgId)
  368. if boolean == false {
  369. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  370. return
  371. }
  372. //判断该仓库是否在仓库配置表中
  373. boolean = service.IsInConfig(orgId, id)
  374. if boolean == true {
  375. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  376. return
  377. }
  378. }
  379. //判断仓库名称是否重复
  380. var bo bool
  381. bo, err = service.IsStorehouseNameUp(orgId, id, name)
  382. if bo == true {
  383. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  384. return
  385. }
  386. //判断仓库地址是否重复
  387. bo, err = service.IsStorehouseAddressUp(orgId, id, address)
  388. if bo == true {
  389. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  390. return
  391. }
  392. storehouse := models.Storehouse{
  393. ID: id,
  394. StorehouseName: name,
  395. StorehouseAddress: address,
  396. StorehouseStatus: storehouse_status,
  397. StorehouseAdminId: admin_id,
  398. Mtime: time.Now().Unix(),
  399. }
  400. err = service.UpdateStroehouse(storehouse)
  401. if err != nil {
  402. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  403. return
  404. }
  405. this.ServeSuccessJSON(map[string]interface{}{
  406. "list": "保存成功",
  407. })
  408. return
  409. }
  410. //查询一条仓库信息
  411. func (this *SecondaryOrderApiController) GetOneStorehouse() {
  412. orgId := this.GetAdminUserInfo().CurrentOrgId
  413. check := map[string][]string{
  414. "id": {"must", "int", "id"},
  415. }
  416. _, err := checkParams(this, &check)
  417. if err != nil {
  418. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  419. return
  420. }
  421. id, _ := this.GetInt64("id")
  422. var list models.Storehouse
  423. list, err = service.GetOneStorehouse(id, orgId)
  424. if err != nil {
  425. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  426. return
  427. }
  428. this.ServeSuccessJSON(map[string]interface{}{
  429. "list": list,
  430. })
  431. return
  432. }
  433. //获取当前机构所有可用仓库的名字
  434. func (this *SecondaryOrderApiController) GetAllStorehouseName() {
  435. orgId := this.GetAdminUserInfo().CurrentOrgId
  436. list, err := service.GetAllStorehouseName(orgId)
  437. if err != nil {
  438. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  439. return
  440. }
  441. this.ServeSuccessJSON(map[string]interface{}{
  442. "list": list,
  443. })
  444. }
  445. //根据机构id查询仓库配置
  446. func (this *SecondaryOrderApiController) FindStorehouseConfig() {
  447. orgId := this.GetAdminUserInfo().CurrentOrgId
  448. storehouse, err := service.FindStorehouseConfig(orgId)
  449. //如果没有仓库配置信息就新建一个
  450. if err == gorm.ErrRecordNotFound {
  451. err := service.GetDefaultStorehouse(orgId)
  452. if err != nil {
  453. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  454. return
  455. }
  456. storehouse, err = service.FindStorehouseConfig(orgId)
  457. if err != nil {
  458. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  459. return
  460. }
  461. }
  462. if err != nil && err.Error() != "record not found" {
  463. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  464. return
  465. }
  466. var storehouse_info, storehouse_out_info, drug_storehouse_info, drug_storehouse_out models.Storehouse
  467. storehouse_info, err = service.FindStorehouseName(storehouse.StorehouseInfo)
  468. if err != nil {
  469. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  470. return
  471. }
  472. storehouse_out_info, err = service.FindStorehouseName(storehouse.StorehouseOutInfo)
  473. if err != nil {
  474. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  475. return
  476. }
  477. drug_storehouse_info, err = service.FindStorehouseName(storehouse.DrugStorehouseInfo)
  478. if err != nil {
  479. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  480. return
  481. }
  482. drug_storehouse_out, err = service.FindStorehouseName(storehouse.DrugStorehouseOut)
  483. if err != nil {
  484. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  485. return
  486. }
  487. this.ServeSuccessJSON(map[string]interface{}{
  488. "storehouse_info": storehouse_info.StorehouseName,
  489. "storehouse_out_info": storehouse_out_info.StorehouseName,
  490. "drug_storehouse_info": drug_storehouse_info.StorehouseName,
  491. "drug_storehouse_out": drug_storehouse_out.StorehouseName,
  492. })
  493. return
  494. }
  495. //更改耗材自动入库仓库
  496. func (this *SecondaryOrderApiController) UpdateInfo() {
  497. orgId := this.GetAdminUserInfo().CurrentOrgId
  498. check := map[string][]string{
  499. "id": {"must", "int", "id"},
  500. }
  501. _, err := checkParams(this, &check)
  502. if err != nil {
  503. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  504. return
  505. }
  506. id, _ := this.GetInt64("id")
  507. err = service.UpdateInfo(orgId, id)
  508. if err != nil {
  509. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  510. return
  511. }
  512. this.ServeSuccessJSON(map[string]interface{}{
  513. "list": "修改成功",
  514. })
  515. return
  516. }
  517. //更改耗材自动出库仓库
  518. func (this *SecondaryOrderApiController) UpdateOutInfo() {
  519. orgId := this.GetAdminUserInfo().CurrentOrgId
  520. check := map[string][]string{
  521. "id": {"must", "int", "id"},
  522. }
  523. _, err := checkParams(this, &check)
  524. if err != nil {
  525. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  526. return
  527. }
  528. id, _ := this.GetInt64("id")
  529. err = service.UpdateOutInfo(orgId, id)
  530. if err != nil {
  531. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  532. return
  533. }
  534. this.ServeSuccessJSON(map[string]interface{}{
  535. "list": "修改成功",
  536. })
  537. return
  538. }
  539. //更改药品自动入库仓库
  540. func (this *SecondaryOrderApiController) UpdateDrugInfo() {
  541. orgId := this.GetAdminUserInfo().CurrentOrgId
  542. check := map[string][]string{
  543. "id": {"must", "int", "id"},
  544. }
  545. _, err := checkParams(this, &check)
  546. if err != nil {
  547. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  548. return
  549. }
  550. id, _ := this.GetInt64("id")
  551. err = service.UpdateDrugInfo2(orgId, id)
  552. if err != nil {
  553. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  554. return
  555. }
  556. this.ServeSuccessJSON(map[string]interface{}{
  557. "list": "修改成功",
  558. })
  559. return
  560. }
  561. //更改药品自动出库仓库
  562. func (this *SecondaryOrderApiController) UpdateDrugOut() {
  563. orgId := this.GetAdminUserInfo().CurrentOrgId
  564. check := map[string][]string{
  565. "id": {"must", "int", "id"},
  566. }
  567. _, err := checkParams(this, &check)
  568. if err != nil {
  569. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  570. return
  571. }
  572. id, _ := this.GetInt64("id")
  573. err = service.UpdateDrugOut(orgId, id)
  574. if err != nil {
  575. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  576. return
  577. }
  578. this.ServeSuccessJSON(map[string]interface{}{
  579. "list": "修改成功",
  580. })
  581. return
  582. }
  583. //判断前端参数是否为空
  584. func checkParams(this *SecondaryOrderApiController, m *map[string][]string) (map[string]string, error) {
  585. tmp := make(map[string]string)
  586. for k, v := range *m {
  587. t := this.GetString(k)
  588. if v[0] == "must" && t == "" {
  589. return nil, fmt.Errorf(v[2] + "不能为空")
  590. }
  591. tmp[k] = t
  592. }
  593. return tmp, nil
  594. }
  595. //兼容旧数据
  596. func (this *SecondaryOrderApiController) Byliinit() {
  597. err := service.Byliinit()
  598. if err != nil {
  599. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  600. return
  601. }
  602. this.ServeSuccessJSON(map[string]interface{}{
  603. "list": "初始化成功",
  604. })
  605. return
  606. }
  607. //查询机构所属管理员
  608. func (this *SecondaryOrderApiController) GetuserName() {
  609. adminUserInfo := this.GetAdminUserInfo()
  610. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  611. c, _ := service.Getcreateid(adminUserInfo.CurrentOrgId)
  612. //c.Creator
  613. admin := []*service.AdminUserManageViewModel{} //记录当前管理员的信息
  614. //去除禁用的角色
  615. tmp := []*service.AdminUserManageViewModel{}
  616. for i := 0; i < len(viewModels); i++ {
  617. if viewModels[i].Status == 1 {
  618. tmp = append(tmp, viewModels[i])
  619. }
  620. if int64(viewModels[i].AdminUserId) == c.Creator {
  621. admin = append(admin, viewModels[i])
  622. }
  623. }
  624. roles := service.FindRoles(adminUserInfo.CurrentOrgId)
  625. //去除没有权限的角色
  626. tmplist := []*service.AdminUserManageViewModel{}
  627. if roles == nil || len(roles) == 0 {
  628. this.ServeSuccessJSON(map[string]interface{}{
  629. "list": tmplist,
  630. })
  631. return
  632. }
  633. for i := 0; i < len(tmp); i++ {
  634. boolean := false
  635. //获取并解析当前用户的角色
  636. tmproles := strings.Split(tmp[i].RoleIds, ",")
  637. for j := 0; j < len(tmproles); j++ {
  638. //判断这些角色是否有权限
  639. if _, ok := roles[tmproles[j]]; ok {
  640. boolean = true
  641. }
  642. }
  643. if boolean {
  644. tmplist = append(tmplist, tmp[i])
  645. }
  646. }
  647. isappend := true //判断结果中是否添加机构创建者,true添加,false不添加
  648. if len(tmplist) > 0 {
  649. for i := 0; i < len(tmplist); i++ {
  650. if int64(tmplist[i].AdminUserId) == c.Creator {
  651. isappend = false
  652. }
  653. }
  654. }
  655. if isappend {
  656. tmplist = append(tmplist, admin...)
  657. }
  658. this.ServeSuccessJSON(map[string]interface{}{
  659. "list": tmplist,
  660. })
  661. return
  662. }
  663. func (this *SecondaryOrderApiController) GetCreaterId() {
  664. creater := this.GetAdminUserInfo().AdminUser.Id
  665. this.ServeSuccessJSON(map[string]interface{}{
  666. "list": creater,
  667. })
  668. }