secondary_order_api_contorller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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. beego.Router("/api/secondary/ttttt", &SecondaryOrderApiController{}, "get:TTTTT")
  37. }
  38. //ceshi
  39. func (this *SecondaryOrderApiController) TTTTT() {
  40. orgid := this.GetAdminUserInfo().CurrentOrgId
  41. err := service.GetDefaultStorehouse(orgid)
  42. if err != nil {
  43. utils.ErrorLog("创建默认仓库失败,原因为:", err)
  44. }
  45. this.ServeSuccessJSON(map[string]interface{}{
  46. "list": err,
  47. })
  48. return
  49. }
  50. //获取仓库编码
  51. func (this *SecondaryOrderApiController) GetStoreCode() {
  52. orgId := this.GetAdminUserInfo().CurrentOrgId
  53. var code string
  54. for a := true; a == true; {
  55. code = service.CreateCode()
  56. tmp := service.FindStorehouseCode(orgId, code)
  57. //如果没有重复的编码结束循环
  58. if tmp == false {
  59. a = false
  60. }
  61. }
  62. this.ServeSuccessJSON(map[string]interface{}{
  63. "list": code,
  64. })
  65. return
  66. }
  67. //修改仓库状态
  68. func (this *SecondaryOrderApiController) UpdateStatus() {
  69. orgId := this.GetAdminUserInfo().CurrentOrgId
  70. check := map[string][]string{
  71. "id": {"must", "int", "id"},
  72. }
  73. _, err := checkParams(this, &check)
  74. if err != nil {
  75. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  76. return
  77. }
  78. id, _ := this.GetInt64("id")
  79. //判断该仓库的库存是否为零
  80. boolean := service.IsStorehouseNil(id, orgId)
  81. if boolean == false {
  82. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  83. return
  84. }
  85. //判断该仓库是否在仓库配置表中
  86. boolean = service.IsInConfig(orgId, id)
  87. if boolean == true {
  88. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  89. return
  90. }
  91. //修改仓库状态
  92. err = service.UpdateStorehouseStatus(id)
  93. if err != nil {
  94. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  95. return
  96. }
  97. this.ServeSuccessJSON(map[string]interface{}{
  98. "list": "修改成功",
  99. })
  100. return
  101. }
  102. //删除仓库
  103. func (this *SecondaryOrderApiController) DeleteStorehouse() {
  104. orgId := this.GetAdminUserInfo().CurrentOrgId
  105. check := map[string][]string{
  106. "id": {"must", "int", "id"},
  107. }
  108. _, err := checkParams(this, &check)
  109. if err != nil {
  110. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  111. return
  112. }
  113. id, _ := this.GetInt64("id")
  114. //判断该仓库的库存是否为零
  115. boolean := service.IsStorehouseNil(id, orgId)
  116. if boolean == false {
  117. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  118. return
  119. }
  120. //判断该仓库是否在仓库配置表中
  121. boolean = service.IsInConfig(orgId, id)
  122. if boolean == true {
  123. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  124. return
  125. }
  126. err = service.DeleteStorehouse(id)
  127. if err != nil {
  128. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  129. return
  130. }
  131. this.ServeSuccessJSON(map[string]interface{}{
  132. "list": "删除成功",
  133. })
  134. return
  135. }
  136. //仓库名称是否重复
  137. func (this *SecondaryOrderApiController) IsStorehouseName() {
  138. orgId := this.GetAdminUserInfo().CurrentOrgId
  139. storehouse_name := this.GetString("storehouse_name")
  140. check := map[string][]string{
  141. "storehouse_name": {"must", "string", "storehouse_name"},
  142. }
  143. _, err := checkParams(this, &check)
  144. if err != nil {
  145. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  146. return
  147. }
  148. var bo bool
  149. bo, err = service.IsStorehouseName(orgId, storehouse_name)
  150. if bo == true {
  151. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  152. return
  153. }
  154. this.ServeSuccessJSON(map[string]interface{}{
  155. "list": "ok",
  156. })
  157. return
  158. }
  159. //仓库地址是否重复
  160. func (this *SecondaryOrderApiController) IsStorehouseAddress() {
  161. orgId := this.GetAdminUserInfo().CurrentOrgId
  162. storehouse_address := this.GetString("storehouse_address")
  163. check := map[string][]string{
  164. "storehouse_address": {"must", "string", "storehouse_address"},
  165. }
  166. _, err := checkParams(this, &check)
  167. if err != nil {
  168. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  169. return
  170. }
  171. var bo bool
  172. bo, err = service.IsStorehouseAddress(orgId, storehouse_address)
  173. if bo == true {
  174. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  175. return
  176. }
  177. this.ServeSuccessJSON(map[string]interface{}{
  178. "list": "ok",
  179. })
  180. return
  181. }
  182. //分页
  183. func (this *SecondaryOrderApiController) StorehouseList() {
  184. adminUserInfo := this.GetAdminUserInfo()
  185. page, _ := this.GetInt64("page") //页码
  186. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  187. check := map[string][]string{
  188. "page": {"must", "string", "page"},
  189. "limit": {"must", "string", "limit"},
  190. }
  191. _, err := checkParams(this, &check)
  192. keyword := this.GetString("keyword")
  193. orgId := this.GetAdminUserInfo().CurrentOrgId
  194. if err != nil {
  195. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  196. }
  197. namemap := make(map[int64]string)
  198. //根据管理员id获取管理员
  199. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  200. for _, v := range viewModels {
  201. namemap[int64(v.AdminUserId)] = v.UserName
  202. }
  203. slicekey := make([]int64, 0)
  204. if len(keyword) > 0 {
  205. for k, v := range namemap {
  206. res := strings.Contains(v, keyword)
  207. if res == true {
  208. slicekey = append(slicekey, k)
  209. }
  210. }
  211. }
  212. //获取分页的数据
  213. list, total, err := service.StorehouseList(page, limit, orgId, keyword, slicekey)
  214. //分页
  215. type Storehouselist struct {
  216. ID int64
  217. StorehouseCode string //仓库编号
  218. StorehouseName string //仓库名称
  219. StorehouseAddress string //仓库地址
  220. StorehouseStatus int64 //仓库状态
  221. Status int64 //数据状态
  222. StorehouseAdminId int64 //仓库管理员id
  223. StorehouseAdminName string //仓库管理员名字
  224. UserOrgId int64
  225. }
  226. //初始化该结构体
  227. tmplist := []*Storehouselist{}
  228. for i := 0; i < len(list); i++ {
  229. tlist := &Storehouselist{
  230. list[i].ID,
  231. list[i].StorehouseCode,
  232. list[i].StorehouseName,
  233. list[i].StorehouseAddress,
  234. list[i].StorehouseStatus,
  235. list[i].Status,
  236. list[i].StorehouseAdminId,
  237. "",
  238. list[i].UserOrgId,
  239. }
  240. tmplist = append(tmplist, tlist)
  241. }
  242. for _, v := range tmplist {
  243. if k, ok := namemap[v.StorehouseAdminId]; ok {
  244. v.StorehouseAdminName = k
  245. } else {
  246. v.StorehouseAdminName = "超级管理员"
  247. }
  248. }
  249. this.ServeSuccessJSON(map[string]interface{}{
  250. "list": tmplist,
  251. "total": total,
  252. })
  253. }
  254. //新增仓库
  255. func (this *SecondaryOrderApiController) AddStorehouse() {
  256. orgId := this.GetAdminUserInfo().CurrentOrgId
  257. dataBody := make(map[string]interface{}, 0)
  258. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  259. if err != nil {
  260. utils.ErrorLog(err.Error())
  261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  262. return
  263. }
  264. var storehouse_status, admin_id int64
  265. tmpstatus := dataBody["storehouse_status"]
  266. tmpid := dataBody["storehouse_admin_id"] //管理员id
  267. if tmpstatus == nil {
  268. storehouse_status = 1
  269. } else {
  270. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  271. }
  272. if tmpid == nil {
  273. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  274. return
  275. } else {
  276. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  277. }
  278. switch {
  279. case dataBody["storehouse_code"] == nil:
  280. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库编号不能为空")
  281. return
  282. case dataBody["storehouse_name"] == nil:
  283. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  284. return
  285. case dataBody["storehouse_address"] == nil:
  286. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  287. return
  288. }
  289. code := dataBody["storehouse_code"].(string) //仓库编号
  290. name := dataBody["storehouse_name"].(string) //仓库名称
  291. address := dataBody["storehouse_address"].(string) //地址
  292. switch {
  293. case name == "":
  294. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  295. return
  296. case address == "":
  297. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  298. return
  299. }
  300. //判断仓库名称是否重复
  301. var bo bool
  302. bo, err = service.IsStorehouseName(orgId, name)
  303. if bo == true {
  304. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  305. return
  306. }
  307. //判断仓库地址是否重复
  308. bo, err = service.IsStorehouseAddress(orgId, address)
  309. if bo == true {
  310. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  311. return
  312. }
  313. storehouse := models.Storehouse{
  314. StorehouseCode: code,
  315. StorehouseName: name,
  316. StorehouseAddress: address,
  317. StorehouseStatus: storehouse_status,
  318. UserOrgId: orgId,
  319. Status: 1,
  320. StorehouseAdminId: admin_id,
  321. Ctime: time.Now().Unix(),
  322. }
  323. err = service.AddStroehouse(storehouse)
  324. if err != nil {
  325. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  326. return
  327. }
  328. this.ServeSuccessJSON(map[string]interface{}{
  329. "list": "保存成功",
  330. })
  331. return
  332. }
  333. //修改仓库
  334. func (this *SecondaryOrderApiController) UpdateStorehouse() {
  335. orgId := this.GetAdminUserInfo().CurrentOrgId
  336. dataBody := make(map[string]interface{}, 0)
  337. //orgId := this.GetAdminUserInfo().CurrentOrgId
  338. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  339. if err != nil {
  340. utils.ErrorLog(err.Error())
  341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  342. return
  343. }
  344. var storehouse_status, admin_id int64
  345. tmpstatus := dataBody["storehouse_status"]
  346. tmpid := dataBody["storehouse_admin_id"]
  347. if tmpstatus == nil {
  348. storehouse_status = 1
  349. } else {
  350. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  351. }
  352. if tmpid == nil {
  353. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  354. return
  355. } else {
  356. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  357. }
  358. switch {
  359. case dataBody["id"] == nil:
  360. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库id不能为空")
  361. return
  362. case dataBody["storehouse_name"] == nil:
  363. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  364. return
  365. case dataBody["storehouse_address"] == nil:
  366. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  367. return
  368. }
  369. id := int64(dataBody["id"].(float64))
  370. name := dataBody["storehouse_name"].(string) //仓库名称
  371. address := dataBody["storehouse_address"].(string) //地址
  372. //查询当前仓库状态,根据当前状态判断是否需要更改
  373. list, errs := service.GetOneStorehouse(id, orgId)
  374. if errs != nil {
  375. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  376. return
  377. }
  378. if storehouse_status != list.StorehouseStatus && storehouse_status == 0 {
  379. //判断该仓库的库存是否为零
  380. boolean := service.IsStorehouseNil(id, orgId)
  381. if boolean == false {
  382. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  383. return
  384. }
  385. //判断该仓库是否在仓库配置表中
  386. boolean = service.IsInConfig(orgId, id)
  387. if boolean == true {
  388. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  389. return
  390. }
  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. }