secondary_order_api_contorller.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. storehouse := models.Storehouse{
  380. ID: id,
  381. StorehouseName: name,
  382. StorehouseAddress: address,
  383. StorehouseStatus: storehouse_status,
  384. StorehouseAdminId: admin_id,
  385. Mtime: time.Now().Unix(),
  386. }
  387. err = service.UpdateStroehouse(storehouse)
  388. if err != nil {
  389. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  390. return
  391. }
  392. this.ServeSuccessJSON(map[string]interface{}{
  393. "list": "保存成功",
  394. })
  395. return
  396. }
  397. //查询一条仓库信息
  398. func (this *SecondaryOrderApiController) GetOneStorehouse() {
  399. orgId := this.GetAdminUserInfo().CurrentOrgId
  400. check := map[string][]string{
  401. "id": {"must", "int", "id"},
  402. }
  403. _, err := checkParams(this, &check)
  404. if err != nil {
  405. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  406. return
  407. }
  408. id, _ := this.GetInt64("id")
  409. var list models.Storehouse
  410. list, err = service.GetOneStorehouse(id, orgId)
  411. if err != nil {
  412. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  413. return
  414. }
  415. this.ServeSuccessJSON(map[string]interface{}{
  416. "list": list,
  417. })
  418. return
  419. }
  420. //获取当前机构所有可用仓库的名字
  421. func (this *SecondaryOrderApiController) GetAllStorehouseName() {
  422. orgId := this.GetAdminUserInfo().CurrentOrgId
  423. list, err := service.GetAllStorehouseName(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. }
  432. //根据机构id查询仓库配置
  433. func (this *SecondaryOrderApiController) FindStorehouseConfig() {
  434. orgId := this.GetAdminUserInfo().CurrentOrgId
  435. storehouse, err := service.FindStorehouseConfig(orgId)
  436. //如果没有仓库配置信息就新建一个
  437. if err == gorm.ErrRecordNotFound {
  438. err := service.GetDefaultStorehouse(orgId)
  439. if err != nil {
  440. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  441. return
  442. }
  443. storehouse, err = service.FindStorehouseConfig(orgId)
  444. if err != nil {
  445. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  446. return
  447. }
  448. }
  449. if err != nil && err.Error() != "record not found" {
  450. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  451. return
  452. }
  453. var storehouse_info, storehouse_out_info, drug_storehouse_info, drug_storehouse_out models.Storehouse
  454. storehouse_info, err = service.FindStorehouseName(storehouse.StorehouseInfo)
  455. if err != nil {
  456. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  457. return
  458. }
  459. storehouse_out_info, err = service.FindStorehouseName(storehouse.StorehouseOutInfo)
  460. if err != nil {
  461. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  462. return
  463. }
  464. drug_storehouse_info, err = service.FindStorehouseName(storehouse.DrugStorehouseInfo)
  465. if err != nil {
  466. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  467. return
  468. }
  469. drug_storehouse_out, err = service.FindStorehouseName(storehouse.DrugStorehouseOut)
  470. if err != nil {
  471. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  472. return
  473. }
  474. this.ServeSuccessJSON(map[string]interface{}{
  475. "storehouse_info": storehouse_info.StorehouseName,
  476. "storehouse_out_info": storehouse_out_info.StorehouseName,
  477. "drug_storehouse_info": drug_storehouse_info.StorehouseName,
  478. "drug_storehouse_out": drug_storehouse_out.StorehouseName,
  479. })
  480. return
  481. }
  482. //更改耗材自动入库仓库
  483. func (this *SecondaryOrderApiController) UpdateInfo() {
  484. orgId := this.GetAdminUserInfo().CurrentOrgId
  485. check := map[string][]string{
  486. "id": {"must", "int", "id"},
  487. }
  488. _, err := checkParams(this, &check)
  489. if err != nil {
  490. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  491. return
  492. }
  493. id, _ := this.GetInt64("id")
  494. err = service.UpdateInfo(orgId, id)
  495. if err != nil {
  496. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  497. return
  498. }
  499. this.ServeSuccessJSON(map[string]interface{}{
  500. "list": "修改成功",
  501. })
  502. return
  503. }
  504. //更改耗材自动出库仓库
  505. func (this *SecondaryOrderApiController) UpdateOutInfo() {
  506. orgId := this.GetAdminUserInfo().CurrentOrgId
  507. check := map[string][]string{
  508. "id": {"must", "int", "id"},
  509. }
  510. _, err := checkParams(this, &check)
  511. if err != nil {
  512. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  513. return
  514. }
  515. id, _ := this.GetInt64("id")
  516. err = service.UpdateOutInfo(orgId, id)
  517. if err != nil {
  518. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  519. return
  520. }
  521. this.ServeSuccessJSON(map[string]interface{}{
  522. "list": "修改成功",
  523. })
  524. return
  525. }
  526. //更改药品自动入库仓库
  527. func (this *SecondaryOrderApiController) UpdateDrugInfo() {
  528. orgId := this.GetAdminUserInfo().CurrentOrgId
  529. check := map[string][]string{
  530. "id": {"must", "int", "id"},
  531. }
  532. _, err := checkParams(this, &check)
  533. if err != nil {
  534. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  535. return
  536. }
  537. id, _ := this.GetInt64("id")
  538. err = service.UpdateDrugInfo2(orgId, id)
  539. if err != nil {
  540. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  541. return
  542. }
  543. this.ServeSuccessJSON(map[string]interface{}{
  544. "list": "修改成功",
  545. })
  546. return
  547. }
  548. //更改药品自动出库仓库
  549. func (this *SecondaryOrderApiController) UpdateDrugOut() {
  550. orgId := this.GetAdminUserInfo().CurrentOrgId
  551. check := map[string][]string{
  552. "id": {"must", "int", "id"},
  553. }
  554. _, err := checkParams(this, &check)
  555. if err != nil {
  556. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  557. return
  558. }
  559. id, _ := this.GetInt64("id")
  560. err = service.UpdateDrugOut(orgId, id)
  561. if err != nil {
  562. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  563. return
  564. }
  565. this.ServeSuccessJSON(map[string]interface{}{
  566. "list": "修改成功",
  567. })
  568. return
  569. }
  570. //判断前端参数是否为空
  571. func checkParams(this *SecondaryOrderApiController, m *map[string][]string) (map[string]string, error) {
  572. tmp := make(map[string]string)
  573. for k, v := range *m {
  574. t := this.GetString(k)
  575. if v[0] == "must" && t == "" {
  576. return nil, fmt.Errorf(v[2] + "不能为空")
  577. }
  578. tmp[k] = t
  579. }
  580. return tmp, nil
  581. }
  582. //兼容旧数据
  583. func (this *SecondaryOrderApiController) Byliinit() {
  584. err := service.Byliinit()
  585. if err != nil {
  586. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  587. return
  588. }
  589. this.ServeSuccessJSON(map[string]interface{}{
  590. "list": "初始化成功",
  591. })
  592. return
  593. }
  594. //查询机构所属管理员
  595. func (this *SecondaryOrderApiController) GetuserName() {
  596. adminUserInfo := this.GetAdminUserInfo()
  597. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  598. c, _ := service.Getcreateid(adminUserInfo.CurrentOrgId)
  599. //c.Creator
  600. admin := []*service.AdminUserManageViewModel{} //记录当前管理员的信息
  601. //去除禁用的角色
  602. tmp := []*service.AdminUserManageViewModel{}
  603. for i := 0; i < len(viewModels); i++ {
  604. if viewModels[i].Status == 1 {
  605. tmp = append(tmp, viewModels[i])
  606. }
  607. if int64(viewModels[i].AdminUserId) == c.Creator {
  608. admin = append(admin, viewModels[i])
  609. }
  610. }
  611. roles := service.FindRoles(adminUserInfo.CurrentOrgId)
  612. //去除没有权限的角色
  613. tmplist := []*service.AdminUserManageViewModel{}
  614. if roles == nil || len(roles) == 0 {
  615. this.ServeSuccessJSON(map[string]interface{}{
  616. "list": tmplist,
  617. })
  618. return
  619. }
  620. for i := 0; i < len(tmp); i++ {
  621. boolean := false
  622. //获取并解析当前用户的角色
  623. tmproles := strings.Split(tmp[i].RoleIds, ",")
  624. for j := 0; j < len(tmproles); j++ {
  625. //判断这些角色是否有权限
  626. if _, ok := roles[tmproles[j]]; ok {
  627. boolean = true
  628. }
  629. }
  630. if boolean {
  631. tmplist = append(tmplist, tmp[i])
  632. }
  633. }
  634. isappend := true //判断结果中是否添加机构创建者,true添加,false不添加
  635. if len(tmplist) > 0 {
  636. for i := 0; i < len(tmplist); i++ {
  637. if int64(tmplist[i].AdminUserId) == c.Creator {
  638. isappend = false
  639. }
  640. }
  641. }
  642. if isappend {
  643. tmplist = append(tmplist, admin...)
  644. }
  645. this.ServeSuccessJSON(map[string]interface{}{
  646. "list": tmplist,
  647. })
  648. return
  649. }
  650. func (this *SecondaryOrderApiController) GetCreaterId() {
  651. creater := this.GetAdminUserInfo().AdminUser.Id
  652. this.ServeSuccessJSON(map[string]interface{}{
  653. "list": creater,
  654. })
  655. }