self_drug_api_congtroller.go 71KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158
  1. package controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_New/service"
  6. "Xcx_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type SelfDrugApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func SelfDrugRouters() {
  20. beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
  21. beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
  22. beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
  23. beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
  24. beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
  25. beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
  26. beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
  27. beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
  28. beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
  29. beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
  30. beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
  31. beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
  32. beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
  33. beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
  34. beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
  35. beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
  36. beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
  37. beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
  38. beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
  39. beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
  40. beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
  41. beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
  42. beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
  43. beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
  44. beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
  45. beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
  46. beego.Router("/api/drug/getallmedicallist", &SelfDrugApiController{}, "Get:GetAllMedicalList")
  47. beego.Router("/api/drug/getstandname", &SelfDrugApiController{}, "Get:GetStandName")
  48. beego.Router("/api/drug/getrullerlist", &SelfDrugApiController{}, "Get:GetRullerList")
  49. beego.Router("/api/drug/deleteDrugNamebyid", &SelfDrugApiController{}, "Get:DeleteDrugNameById")
  50. beego.Router("/api/drug/getpatientdetail", &SelfDrugApiController{}, "Get:GetPatientDetail")
  51. //beego.Router("/api/drug/getpatientdetail",&SelfDrugApiController{},"Get:ToPatientDetail")
  52. beego.Router("/api/drug/getselfstockquery", &SelfDrugApiController{}, "Get:GetSelfStockQuery")
  53. beego.Router("/api/drug/postsearchdrugwarehouselist", &SelfDrugApiController{}, "Get:PostSearchDrugWarehouseList")
  54. beego.Router("/api/drug/savedrugpriceone", &SelfDrugApiController{}, "Post:SaveDrugPrice")
  55. beego.Router("/api/drug/drugpricelist", &SelfDrugApiController{}, "Get:GetDrugPriceList")
  56. beego.Router("/api/drug/savecheckdrugprice", &SelfDrugApiController{}, "Get:SaveCheckDrugPrice")
  57. beego.Router("/api/drug/savedrugdamageone", &SelfDrugApiController{}, "Post:SaveDrugDamage")
  58. beego.Router("/api/drug/getdrugdamagelist", &SelfDrugApiController{}, "Get:GetDrugDamageList")
  59. beego.Router("/api/drug/savedrugdamageprice", &SelfDrugApiController{}, "Get:SaveDrugDamagePrice")
  60. beego.Router("/api/drug/getdrugmodifyprice", &SelfDrugApiController{}, "Get:GetDrugModifyPrice")
  61. beego.Router("/api/drug/modifydrugprice", &SelfDrugApiController{}, "Get:ModifyDrugPrice")
  62. beego.Router("/api/drug/getmodifypriceprint", &SelfDrugApiController{}, "Get:GetModifyPricePrint")
  63. beego.Router("/api/drug/getdrugdamagedetail", &SelfDrugApiController{}, "Get:GetDrugDamageDetail")
  64. beego.Router("/api/drug/modifydrugdamage", &SelfDrugApiController{}, "Get:ModifyDrugDamage")
  65. beego.Router("/api/drug/deletedrugdamage", &SelfDrugApiController{}, "Get:DeleteDrugDamage")
  66. beego.Router("/api/drug/getdrugdamageprint", &SelfDrugApiController{}, "Get:GetDrugDamagePrint")
  67. beego.Router("/api/drug/warehouseinfobyid", &SelfDrugApiController{}, "Get:GetWarehoseInfoById")
  68. beego.Router("/api/drug/savedruginventory", &SelfDrugApiController{}, "Post:SaveDrugInventory")
  69. beego.Router("/api/drug/getdruginventorylist", &SelfDrugApiController{}, "Get:GetDrugInventoryList")
  70. beego.Router("/api/drug/savedrugcheckinventory", &SelfDrugApiController{}, "Get:SaveDrugCheckInventory")
  71. beego.Router("/api/drug/getdruginventorydetail", &SelfDrugApiController{}, "Get:GetDrugInventoryDetail")
  72. beego.Router("/api/drug/modifyinventory", &SelfDrugApiController{}, "Get:ModifyInventory")
  73. beego.Router("/api/drug/deletedruginventory", &SelfDrugApiController{}, "Delete:DeleteDrugInventory")
  74. beego.Router("/api/drug/getdruginventoryprintlist", &SelfDrugApiController{}, "Get:GetDrugInventoryPrintList")
  75. beego.Router("/api/drug/getinventorydetaillist", &SelfDrugApiController{}, "Get:GetDrugInventoryDetailList")
  76. beego.Router("/api/drug/savedrugproofinventory", &SelfDrugApiController{}, "Get:SaveDrugProofInventory")
  77. beego.Router("/api/drug/getdrugwarehouseinfototal", &StockManagerApiController{}, "Get:GetDrugWarehouseInfoTotal")
  78. }
  79. func (this *SelfDrugApiController) GetCurrentPatient() {
  80. adminUserInfo := this.GetAdminUserInfo()
  81. orgId := adminUserInfo.CurrentOrgId
  82. patient, err := service.GetCurrentPatient(orgId)
  83. if err != nil {
  84. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  85. return
  86. }
  87. this.ServeSuccessJSON(map[string]interface{}{
  88. "patient": patient,
  89. })
  90. }
  91. func (this *SelfDrugApiController) GetAllDrugName() {
  92. adminUserInfo := this.GetAdminUserInfo()
  93. orgId := adminUserInfo.CurrentOrgId
  94. //查询药品库是否开启
  95. //configStock, _ := service.GetDrugStockConfig(orgId)
  96. //if configStock.IsOpen == 1 {
  97. //
  98. //}
  99. drugName, err := service.GetAllDrugName(orgId)
  100. if err != nil {
  101. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
  102. return
  103. }
  104. this.ServeSuccessJSON(map[string]interface{}{
  105. "drugName": drugName,
  106. })
  107. }
  108. func (this *SelfDrugApiController) SaveDrugName() {
  109. adminUserInfo := this.GetAdminUserInfo()
  110. orgId := adminUserInfo.CurrentOrgId
  111. drug_name := this.GetString("drug_name")
  112. id, _ := this.GetInt64("id")
  113. //fmt.Println("drug_name", drug_name)
  114. drugName := models.XtDrugName{
  115. UserOrgId: orgId,
  116. DrugName: drug_name,
  117. Status: 1,
  118. CreatedTime: time.Now().Unix(),
  119. DrugId: id,
  120. }
  121. _, errcode := service.GetDrugName(drug_name, orgId)
  122. if errcode == gorm.ErrRecordNotFound {
  123. err := service.SaveDrugName(&drugName)
  124. if err != nil {
  125. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  126. return
  127. }
  128. this.ServeSuccessJSON(map[string]interface{}{
  129. "drugName": drugName,
  130. })
  131. } else {
  132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  133. return
  134. }
  135. }
  136. func (this *SelfDrugApiController) GetDrugNameList() {
  137. adminUserInfo := this.GetAdminUserInfo()
  138. orgId := adminUserInfo.CurrentOrgId
  139. list, err := service.GetDrugNameList(orgId)
  140. if err != nil {
  141. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  142. return
  143. }
  144. this.ServeSuccessJSON(map[string]interface{}{
  145. "list": list,
  146. })
  147. }
  148. func (this *SelfDrugApiController) GetRulleName() {
  149. adminUserInfo := this.GetAdminUserInfo()
  150. orgId := adminUserInfo.CurrentOrgId
  151. id, _ := this.GetInt64("id")
  152. drugId, _ := service.GetDrugId(id)
  153. rullerList, err := service.GetRulleList(orgId, drugId.DrugId)
  154. if err != nil {
  155. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  156. return
  157. }
  158. this.ServeSuccessJSON(map[string]interface{}{
  159. "rullerList": rullerList,
  160. })
  161. }
  162. func (this *SelfDrugApiController) GetUnitByBaseId() {
  163. id, _ := this.GetInt64("id")
  164. baseList, err := service.GetUnitByBaseId(id)
  165. if err != nil {
  166. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  167. return
  168. }
  169. this.ServeSuccessJSON(map[string]interface{}{
  170. "baseList": baseList,
  171. })
  172. }
  173. func (this *SelfDrugApiController) SaveRulleName() {
  174. drug_name := this.GetString("drug_name")
  175. drug_spec := this.GetString("drug_spec")
  176. drug_stock_limit := this.GetString("drug_stock_limit")
  177. drug_name_id, _ := this.GetInt64("drug_name_id")
  178. drug_id, _ := this.GetInt64("drug_id")
  179. price, _ := this.GetInt64("price")
  180. prices := strconv.FormatInt(price, 10)
  181. durg_price, _ := strconv.ParseFloat(prices, 64)
  182. unit := this.GetString("unit")
  183. adminUserInfo := this.GetAdminUserInfo()
  184. orgId := adminUserInfo.CurrentOrgId
  185. fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
  186. drugSpecName := models.XtStandName{
  187. DrugName: drug_name,
  188. DrugSpec: drug_spec,
  189. DrugStockLimit: drug_stock_limit,
  190. DrugNameId: drug_name_id,
  191. Price: durg_price,
  192. MinUnit: unit,
  193. UserOrgId: orgId,
  194. Status: 1,
  195. CreatedTime: time.Now().Unix(),
  196. DrugId: drug_id,
  197. }
  198. //查询该机构下药品规格名称是否存在
  199. _, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
  200. if errcode == gorm.ErrRecordNotFound {
  201. err := service.SaveRulleName(&drugSpecName)
  202. if err != nil {
  203. this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
  204. return
  205. }
  206. this.ServeSuccessJSON(map[string]interface{}{
  207. "RullerName": drugSpecName,
  208. })
  209. } else if errcode == nil {
  210. this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
  211. return
  212. }
  213. }
  214. func (this *SelfDrugApiController) EditRullerName() {
  215. id, _ := this.GetInt64("id")
  216. rullerDetail, err := service.GetRullerNameDetail(id)
  217. if err != nil {
  218. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  219. return
  220. }
  221. this.ServeSuccessJSON(map[string]interface{}{
  222. "rullerDetail": rullerDetail,
  223. })
  224. }
  225. func (this *SelfDrugApiController) UpdatedRullerName() {
  226. id, _ := this.GetInt64("id")
  227. drug_name := this.GetString("drug_name")
  228. drug_stock_limit := this.GetString("drug_stock_limit")
  229. price, _ := this.GetInt64("price")
  230. prices := strconv.FormatInt(price, 10)
  231. durg_price, _ := strconv.ParseFloat(prices, 64)
  232. drug_spec := this.GetString("drug_spec")
  233. unit := this.GetString("unit")
  234. drug_name_id, _ := this.GetInt64("drug_name_id")
  235. drug_id, _ := this.GetInt64("drug_id")
  236. RullerName := models.XtStandName{
  237. DrugName: drug_name,
  238. DrugStockLimit: drug_stock_limit,
  239. Price: durg_price,
  240. DrugSpec: drug_spec,
  241. MinUnit: unit,
  242. DrugNameId: drug_name_id,
  243. DrugId: drug_id,
  244. }
  245. _, errcode := service.GetIsExit(drug_name, drug_spec, id)
  246. if errcode == gorm.ErrRecordNotFound {
  247. err := service.UpdatedRullerName(id, &RullerName)
  248. if err != nil {
  249. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  250. return
  251. }
  252. this.ServeSuccessJSON(map[string]interface{}{
  253. "RullerName": RullerName,
  254. })
  255. } else if errcode == nil {
  256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  257. return
  258. }
  259. }
  260. func (this *SelfDrugApiController) GetAllDrugNameList() {
  261. adminUserInfo := this.GetAdminUserInfo()
  262. orgId := adminUserInfo.CurrentOrgId
  263. rullerName, err := service.GetAllDrugNameList(orgId)
  264. list, err := service.GetMedicalDrugNameList(orgId)
  265. if err != nil {
  266. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  267. return
  268. }
  269. this.ServeSuccessJSON(map[string]interface{}{
  270. "rullerName": rullerName,
  271. "list": list,
  272. })
  273. }
  274. func (this *SelfDrugApiController) GetRullerListByDrugName() {
  275. id := this.GetString("id")
  276. adminUserInfo := this.GetAdminUserInfo()
  277. orgId := adminUserInfo.CurrentOrgId
  278. fmt.Println("orgid", orgId)
  279. drugName, err := service.GetRullerListByDrugName(id, orgId)
  280. if err != nil {
  281. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  282. return
  283. }
  284. this.ServeSuccessJSON(map[string]interface{}{
  285. "drugName": drugName,
  286. })
  287. }
  288. func (this *SelfDrugApiController) SaveSelfMedicines() {
  289. dataBody := make(map[string]interface{}, 0)
  290. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  291. fmt.Println(err)
  292. patient_id := int64(dataBody["patient_id"].(float64))
  293. medicineData, _ := dataBody["medicineData"].([]interface{})
  294. adminUserInfo := this.GetAdminUserInfo()
  295. orgId := adminUserInfo.CurrentOrgId
  296. for _, item := range medicineData {
  297. items := item.(map[string]interface{})
  298. drug_name := items["drug_name"].(string)
  299. drug_name_id := int64(items["drug_name_id"].(float64))
  300. drug_spec := items["drug_spec"].(string)
  301. min_unit := items["min_unit"].(string)
  302. drug_id := int64(items["drug_id"].(float64))
  303. //根据drug_id
  304. drugMedical, _ := service.GetBaseDrugMedical(drug_name_id)
  305. medical := models.XtSelfMedical{
  306. DrugName: drug_name,
  307. DrugNameId: drug_name_id,
  308. DrugSpec: drug_spec,
  309. CreatedTime: time.Now().Unix(),
  310. Status: 1,
  311. UserOrgId: orgId,
  312. PatientId: patient_id,
  313. MinUnit: min_unit,
  314. ExecutionFrequency: drugMedical.ExecutionFrequency,
  315. PrescribingNumber: drugMedical.PrescribingNumber,
  316. DeliveryWay: drugMedical.DeliveryWay,
  317. SingleDose: drugMedical.SingleDose,
  318. DrugId: drug_id,
  319. }
  320. //查询同个病人同个药品同个规格是否已存在
  321. _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
  322. if errcode == gorm.ErrRecordNotFound {
  323. err := service.CreateSelfMedical(&medical)
  324. fmt.Println(err)
  325. } else if errcode == nil {
  326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  327. return
  328. }
  329. }
  330. returnData := make(map[string]interface{}, 0)
  331. returnData["msg"] = "ok"
  332. this.ServeSuccessJSON(returnData)
  333. return
  334. }
  335. func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
  336. adminUserInfo := this.GetAdminUserInfo()
  337. orgid := adminUserInfo.CurrentOrgId
  338. //fmt.Println(orgid)
  339. appId := adminUserInfo.CurrentAppId
  340. staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
  341. if err != nil {
  342. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  343. return
  344. }
  345. this.ServeSuccessJSON(map[string]interface{}{
  346. "staff": staff,
  347. })
  348. }
  349. func (this *SelfDrugApiController) SaveStock() {
  350. timeLayout := "2006-01-02"
  351. loc, _ := time.LoadLocation("Local")
  352. start_time := this.GetString("start_time")
  353. fmt.Println("start_time", start_time)
  354. admin_user_id, _ := this.GetInt64("admin_user_id")
  355. fmt.Println("admin_user_id", admin_user_id)
  356. patient_id, _ := this.GetInt64("patient_id")
  357. dataBody := make(map[string]interface{}, 0)
  358. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  359. fmt.Println(err)
  360. stocks, _ := dataBody["stocks"].([]interface{})
  361. adminUserInfo := this.GetAdminUserInfo()
  362. orgId := adminUserInfo.CurrentOrgId
  363. for _, item := range stocks {
  364. items := item.(map[string]interface{})
  365. drug_name := items["drug_name"].(string)
  366. fmt.Println("drug_name", drug_name)
  367. drug_name_id := int64(items["drug_name_id"].(float64))
  368. fmt.Println("parient_id", drug_name_id)
  369. drug_spec := items["drug_spec"].(string)
  370. store_number := items["store_number"].(string)
  371. fmt.Println("store_number", store_number)
  372. storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
  373. remarks := items["remarks"].(string)
  374. min_unit := items["min_unit"].(string)
  375. medic_id := int64(items["id"].(float64))
  376. timeStr := time.Now().Format("2006-01-02")
  377. timeArr := strings.Split(timeStr, "-")
  378. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  379. total = total + 1
  380. warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  381. number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
  382. number = number + total
  383. warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
  384. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  385. stock := models.XtSelfStock{
  386. DrugName: drug_name,
  387. DrugNameId: drug_name_id,
  388. DrugSpec: drug_spec,
  389. StoreNumber: storeNumber,
  390. Remarks: remarks,
  391. AdminUserId: admin_user_id,
  392. StorckTime: theTime.Unix(),
  393. CreatedTime: time.Now().Unix(),
  394. Status: 1,
  395. UserOrgId: orgId,
  396. StockInNumber: warehousing_in_order,
  397. PatientId: patient_id,
  398. MinUnit: min_unit,
  399. StorageMode: 1,
  400. MedicId: medic_id,
  401. }
  402. err := service.CreateStock(&stock)
  403. fmt.Println("err", err)
  404. }
  405. returnData := make(map[string]interface{}, 0)
  406. returnData["msg"] = "ok"
  407. this.ServeSuccessJSON(returnData)
  408. return
  409. }
  410. func (this *SelfDrugApiController) SaveOutStock() {
  411. timeLayout := "2006-01-02"
  412. loc, _ := time.LoadLocation("Local")
  413. start_time := this.GetString("start_time")
  414. admin_user_id, _ := this.GetInt64("admin_user_id")
  415. patient_id, _ := this.GetInt64("patient_id")
  416. dataBody := make(map[string]interface{}, 0)
  417. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  418. fmt.Println(err)
  419. outStocks, _ := dataBody["outStocks"].([]interface{})
  420. adminUserInfo := this.GetAdminUserInfo()
  421. orgId := adminUserInfo.CurrentOrgId
  422. for _, item := range outStocks {
  423. items := item.(map[string]interface{})
  424. drug_name := items["drug_name"].(string)
  425. drug_name_id := int64(items["drug_name_id"].(float64))
  426. drug_spec := items["drug_spec"].(string)
  427. outstore_number := items["outstore_number"].(string)
  428. outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
  429. remarks := items["remarks"].(string)
  430. medic_id := int64(items["id"].(float64))
  431. timeStr := time.Now().Format("2006-01-02")
  432. timeArr := strings.Split(timeStr, "-")
  433. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  434. total = total + 1
  435. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  436. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  437. number = number + total
  438. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  439. fmt.Println(remarks)
  440. fmt.Println(items)
  441. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  442. stock := models.XtSelfOutStock{
  443. DrugName: drug_name,
  444. DrugNameId: drug_name_id,
  445. DrugSpec: drug_spec,
  446. OutstoreNumber: outStoreNumber,
  447. Remarks: remarks,
  448. AdminUserId: admin_user_id,
  449. StorckTime: theTime.Unix(),
  450. CreatedTime: time.Now().Unix(),
  451. Status: 1,
  452. UserOrgId: orgId,
  453. StockOutNumber: warehousing_out_order,
  454. PatientId: patient_id,
  455. ExitMode: 1,
  456. MedicId: medic_id,
  457. }
  458. err := service.CreateOutStock(&stock)
  459. fmt.Println("err", err)
  460. }
  461. returnData := make(map[string]interface{}, 0)
  462. returnData["msg"] = "ok"
  463. this.ServeSuccessJSON(returnData)
  464. return
  465. }
  466. func (this *SelfDrugApiController) DeleteDrugById() {
  467. id, _ := this.GetInt64("id")
  468. drug_name := this.GetString("drug_name")
  469. adminUserInfo := this.GetAdminUserInfo()
  470. orgId := adminUserInfo.CurrentOrgId
  471. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  472. if errcode == gorm.ErrRecordNotFound {
  473. service.DeleteDrugName(id)
  474. returnData := make(map[string]interface{}, 0)
  475. returnData["msg"] = "ok"
  476. this.ServeSuccessJSON(returnData)
  477. } else if errcode == nil {
  478. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  479. return
  480. }
  481. }
  482. func (this *SelfDrugApiController) SaveRadio() {
  483. radio, _ := this.GetInt64("radio")
  484. adminUserInfo := this.GetAdminUserInfo()
  485. orgId := adminUserInfo.CurrentOrgId
  486. drugSet := models.XtDrugSet{
  487. DrugStart: radio,
  488. UserOrgId: orgId,
  489. Status: 1,
  490. CreatedTime: time.Now().Unix(),
  491. }
  492. _, errcode := service.GetDrugSetByUserOrgId(orgId)
  493. if errcode == gorm.ErrRecordNotFound {
  494. err := service.SaveRadio(&drugSet)
  495. if err != nil {
  496. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  497. return
  498. }
  499. this.ServeSuccessJSON(map[string]interface{}{
  500. "drugSet": drugSet,
  501. })
  502. } else if errcode == nil {
  503. err := service.UpdateDrugSet(&drugSet, orgId)
  504. if err != nil {
  505. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  506. return
  507. }
  508. this.ServeSuccessJSON(map[string]interface{}{
  509. "drugSet": drugSet,
  510. })
  511. }
  512. }
  513. func (this *SelfDrugApiController) DeleteDrugStand() {
  514. id, _ := this.GetInt64("id")
  515. name := this.GetString("name")
  516. adminUserInfo := this.GetAdminUserInfo()
  517. orgId := adminUserInfo.CurrentOrgId
  518. _, errcode := service.GetMedicalsByName(orgId, name)
  519. if errcode == gorm.ErrRecordNotFound {
  520. err := service.DeleteDrugStand(id)
  521. fmt.Println(err)
  522. returnData := make(map[string]interface{}, 0)
  523. returnData["msg"] = "ok"
  524. this.ServeSuccessJSON(returnData)
  525. } else if errcode == nil {
  526. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  527. return
  528. }
  529. }
  530. func (this *SelfDrugApiController) GetStockList() {
  531. patientid, _ := this.GetInt64("id")
  532. start_time := this.GetString("start_time")
  533. fmt.Println("开始时间", start_time)
  534. timeLayout := "2006-01-02"
  535. loc, _ := time.LoadLocation("Local")
  536. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  537. startimeUnix := theTime.Unix()
  538. keyword := this.GetString("keyword")
  539. fmt.Println("keyword", keyword)
  540. adminUserInfo := this.GetAdminUserInfo()
  541. orgId := adminUserInfo.CurrentOrgId
  542. //获取
  543. medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
  544. //统计总数量
  545. stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
  546. //统计出库数量
  547. outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
  548. //统计该病人时间段内出库条数
  549. outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
  550. if err != nil {
  551. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  552. return
  553. }
  554. this.ServeSuccessJSON(map[string]interface{}{
  555. "medicalList": medicalList,
  556. "stocklist": stocklist,
  557. "outStocklist": outStocklist,
  558. "outList": outList,
  559. })
  560. }
  561. func (this *SelfDrugApiController) DeleteDrugName() {
  562. drug_name := this.GetString("drugname")
  563. patient_id, _ := this.GetInt64("patientid")
  564. //查询该药品是否出库
  565. stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
  566. if len(stocklist) == 0 {
  567. //删除该药品
  568. service.DeleteDrugStockNumber(drug_name, patient_id)
  569. returnData := make(map[string]interface{}, 0)
  570. returnData["msg"] = "ok"
  571. this.ServeSuccessJSON(returnData)
  572. } else {
  573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  574. return
  575. }
  576. }
  577. func (this *SelfDrugApiController) GetDrugDetail() {
  578. timeLayout := "2006-01-02"
  579. loc, _ := time.LoadLocation("Local")
  580. drug_name := this.GetString("drug_name")
  581. drug_spec := this.GetString("drug_spec")
  582. start_time := this.GetString("start_time")
  583. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  584. end_time := this.GetString("end_time")
  585. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  586. patient_id, _ := this.GetInt64("patient_id")
  587. adminUserInfo := this.GetAdminUserInfo()
  588. orgId := adminUserInfo.CurrentOrgId
  589. //查询入库明细
  590. stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  591. //查询出库明细
  592. outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  593. if err != nil {
  594. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  595. return
  596. }
  597. this.ServeSuccessJSON(map[string]interface{}{
  598. "stockDetail": stockDetail,
  599. "outStockDetail": outStockDetail,
  600. })
  601. }
  602. func (this *SelfDrugApiController) GetAllPatientStockList() {
  603. timeLayout := "2006-01-02"
  604. loc, _ := time.LoadLocation("Local")
  605. drug_name := this.GetString("drug_name")
  606. drug_spec := this.GetString("drug_spec")
  607. start_time := this.GetString("start_time")
  608. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  609. startUnix := theTime.Unix()
  610. end_time := this.GetString("end_time")
  611. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  612. endTimeUnix := endTimes.Unix()
  613. keywords := this.GetString("search_input")
  614. adminUserInfo := this.GetAdminUserInfo()
  615. orgId := adminUserInfo.CurrentOrgId
  616. //入库
  617. stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  618. //出库
  619. outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  620. if err != nil {
  621. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  622. return
  623. }
  624. this.ServeSuccessJSON(map[string]interface{}{
  625. "stocklist": stocklist,
  626. "outStockList": outStockList,
  627. })
  628. }
  629. func (this *SelfDrugApiController) GetDrugDataByPatientId() {
  630. patient_id, _ := this.GetInt64("patient_id")
  631. fmt.Println("patient_id", patient_id)
  632. medicalList, err := service.GetDrugDataByPatientId(patient_id)
  633. if err != nil {
  634. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  635. return
  636. }
  637. this.ServeSuccessJSON(map[string]interface{}{
  638. "medicalList": medicalList,
  639. })
  640. }
  641. func (this *SelfDrugApiController) GetSelfMedicalList() {
  642. patient_id, _ := this.GetInt64("patient_id")
  643. adminUserInfo := this.GetAdminUserInfo()
  644. orgId := adminUserInfo.CurrentOrgId
  645. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  646. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(orgId)
  647. drugList, _ := service.GetAllBaseDrugLibList(orgId)
  648. privateDrugList, _ := service.GetPrivateDrugList(patient_id, orgId)
  649. this.ServeSuccessJSON(map[string]interface{}{
  650. "base_drug_config": drugStockConfig,
  651. "private_drug_config": privateDrugConfig,
  652. "base_drug_list": drugList,
  653. "private_drug_list": privateDrugList,
  654. })
  655. ////查询是否开启药品库
  656. //config, _ := service.GetDruckStockConfig(orgId)
  657. //
  658. //fmt.Println("--------------------------",config.IsOpen)
  659. ////开启
  660. //if config.IsOpen == 1 {
  661. // //查询该机构下的药品库
  662. // drugName, _ := service.GetAllDrugName(orgId)
  663. //
  664. // //查询该机构是否开启自备药
  665. // medical, _ := service.GetSetSelfMedical(orgId)
  666. // fmt.Println("medical+++++++++++++++++",medical.DrugStart)
  667. // //开启
  668. // if medical.DrugStart == 1 {
  669. // list, err := service.GetSelfMedicalList(patient_id)
  670. // if err != nil {
  671. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  672. // return
  673. // }
  674. // this.ServeSuccessJSON(map[string]interface{}{
  675. // "medicalList": list,
  676. // "drugName": drugName,
  677. // })
  678. // } else {
  679. // this.ServeSuccessJSON(map[string]interface{}{
  680. // "drugName": drugName,
  681. // })
  682. // }
  683. //}
  684. }
  685. func (this *SelfDrugApiController) GetDrugDescByDrugName() {
  686. drug_name := this.GetString("drug_name")
  687. patient_id, _ := this.GetInt64("patient_id")
  688. way, _ := this.GetInt64("way")
  689. adminUserInfo := this.GetAdminUserInfo()
  690. orgId := adminUserInfo.CurrentOrgId
  691. drug_id, _ := this.GetInt64("id")
  692. //从基础库查询
  693. if way == 1 {
  694. //查询基础库数据
  695. medcal, err := service.GetBaseMedcal(drug_name, orgId)
  696. //统计入库数量
  697. countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
  698. //统计出库数量
  699. countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
  700. if err != nil {
  701. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  702. return
  703. }
  704. this.ServeSuccessJSON(map[string]interface{}{
  705. "drugspec": medcal,
  706. "countInfo": countInfo,
  707. "countout": countout,
  708. })
  709. }
  710. //从自备药库查询
  711. if way == 2 {
  712. drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
  713. if err != nil {
  714. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  715. return
  716. }
  717. this.ServeSuccessJSON(map[string]interface{}{
  718. "drugspec": drugspec,
  719. })
  720. }
  721. }
  722. func (this *SelfDrugApiController) GetDrugSet() {
  723. adminUserInfo := this.GetAdminUserInfo()
  724. orgId := adminUserInfo.CurrentOrgId
  725. drugSet, err := service.GetDrugSet(orgId)
  726. if err != nil {
  727. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  728. return
  729. }
  730. this.ServeSuccessJSON(map[string]interface{}{
  731. "drugSet": drugSet,
  732. })
  733. }
  734. func (this *SelfDrugApiController) GetAllMedicalList() {
  735. adminUserInfo := this.GetAdminUserInfo()
  736. orgId := adminUserInfo.CurrentOrgId
  737. list, err := service.GetAllMedicalList(orgId)
  738. if err != nil {
  739. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  740. return
  741. }
  742. this.ServeSuccessJSON(map[string]interface{}{
  743. "drugName": list,
  744. })
  745. }
  746. func (this *SelfDrugApiController) GetStandName() {
  747. name := this.GetString("name")
  748. adminUserInfo := this.GetAdminUserInfo()
  749. orgId := adminUserInfo.CurrentOrgId
  750. rullerlist, err := service.GetRulleName(orgId, name)
  751. if err != nil {
  752. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  753. return
  754. }
  755. this.ServeSuccessJSON(map[string]interface{}{
  756. "rullerlist": rullerlist,
  757. })
  758. }
  759. func (this *SelfDrugApiController) GetRullerList() {
  760. id, _ := this.GetInt64("id")
  761. adminUserInfo := this.GetAdminUserInfo()
  762. orgId := adminUserInfo.CurrentOrgId
  763. rullerList, err := service.GetRulleList(orgId, id)
  764. if err != nil {
  765. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  766. return
  767. }
  768. this.ServeSuccessJSON(map[string]interface{}{
  769. "rullerlist": rullerList,
  770. })
  771. }
  772. func (this *SelfDrugApiController) DeleteDrugNameById() {
  773. id, _ := this.GetInt64("id")
  774. drug_name := this.GetString("drug_name")
  775. adminUserInfo := this.GetAdminUserInfo()
  776. orgId := adminUserInfo.CurrentOrgId
  777. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  778. if errcode == gorm.ErrRecordNotFound {
  779. service.DeleteDrugNameById(id)
  780. returnData := make(map[string]interface{}, 0)
  781. returnData["msg"] = "ok"
  782. this.ServeSuccessJSON(returnData)
  783. } else if errcode == nil {
  784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  785. return
  786. }
  787. }
  788. func (this *SelfDrugApiController) GetPatientDetail() {
  789. id, _ := this.GetInt64("id")
  790. adminUserInfo := this.GetAdminUserInfo()
  791. patientDetail, err := service.GetPatientDetail(id, adminUserInfo.CurrentOrgId)
  792. if err != nil {
  793. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  794. return
  795. }
  796. this.ServeSuccessJSON(map[string]interface{}{
  797. "patientDetail": patientDetail,
  798. })
  799. }
  800. //func (this *SelfDrugApiController) ToPatientDetail() {
  801. //
  802. // keyword := this.GetString("keyword")
  803. // adminUser := this.GetAdminUserInfo()
  804. // orgId := adminUser.CurrentOrgId
  805. // patient, err := service.ToSeachPatient(keyword, orgId)
  806. // if err != nil {
  807. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  808. // return
  809. // }
  810. // this.ServeSuccessJSON(map[string]interface{}{
  811. // "patient": patient,
  812. // })
  813. //}
  814. func (this *SelfDrugApiController) GetSelfStockQuery() {
  815. adminUserInfo := this.GetAdminUserInfo()
  816. orgId := adminUserInfo.CurrentOrgId
  817. type_name, _ := this.GetInt64("type_name")
  818. keywords := this.GetString("keywords")
  819. timeLayout := "2006-01-02"
  820. loc, _ := time.LoadLocation("Local")
  821. start_time := this.GetString("start_time")
  822. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  823. startUnix := theTime.Unix()
  824. end_time := this.GetString("end_time")
  825. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  826. endTimeUnix := endTimes.Unix()
  827. page, _ := this.GetInt64("page")
  828. limit, _ := this.GetInt64("limit")
  829. //统计入库数量
  830. stockQuery, total, err := service.GetSelfStockQuery(type_name, keywords, startUnix, endTimeUnix, orgId, limit, page)
  831. //统计出库数量
  832. stockOutQuery, err := service.GetSelfOutStockQuery(startUnix, endTimeUnix, orgId)
  833. if err != nil {
  834. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  835. return
  836. }
  837. this.ServeSuccessJSON(map[string]interface{}{
  838. "stockQuery": stockQuery,
  839. "total": total,
  840. "stockOutQuery": stockOutQuery,
  841. })
  842. }
  843. func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
  844. keyword := this.GetString("keyword")
  845. orgId := this.GetAdminUserInfo().CurrentOrgId
  846. list, err := service.PostSearchDrugWarehouseList(keyword, orgId)
  847. manufacturerList, err := service.GetAllManufacturerList(orgId)
  848. dealerList, err := service.GetAllDealerList(orgId)
  849. if err != nil {
  850. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  851. return
  852. }
  853. this.ServeSuccessJSON(map[string]interface{}{
  854. "list": list,
  855. "manufacturerList": manufacturerList,
  856. "dealerList": dealerList,
  857. })
  858. }
  859. func (this *SelfDrugApiController) SaveDrugPrice() {
  860. timeLayout := "2006-01-02"
  861. loc, _ := time.LoadLocation("Local")
  862. dataBody := make(map[string]interface{}, 0)
  863. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  864. fmt.Println(err)
  865. tableData, _ := dataBody["tableData"].([]interface{})
  866. fmt.Println("999939433443", tableData)
  867. if len(tableData) > 0 {
  868. for _, item := range tableData {
  869. items := item.(map[string]interface{})
  870. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  871. utils.ErrorLog("drug_name")
  872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. return
  874. }
  875. drug_name := items["drug_name"].(string)
  876. fmt.Println("drug_aname23232323232", drug_name)
  877. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  878. utils.ErrorLog("drug_name")
  879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  880. return
  881. }
  882. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  883. utils.ErrorLog("retail_price")
  884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  885. return
  886. }
  887. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  888. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  889. utils.ErrorLog("warehousing_order")
  890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  891. return
  892. }
  893. warehousing_order := items["warehousing_order"].(string)
  894. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  895. utils.ErrorLog("number")
  896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  897. return
  898. }
  899. number := items["number"].(string)
  900. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  901. utils.ErrorLog("dealer")
  902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  903. return
  904. }
  905. dealer := items["dealer"].(string)
  906. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  907. utils.ErrorLog("manufacturer")
  908. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  909. return
  910. }
  911. manufacturer := items["manufacturer"].(string)
  912. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  913. utils.ErrorLog("specification_name")
  914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  915. return
  916. }
  917. specification_name := items["specification_name"].(string)
  918. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  919. utils.ErrorLog("remark")
  920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  921. return
  922. }
  923. remark := items["remark"].(string)
  924. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  925. utils.ErrorLog("warehousing_unit")
  926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  927. return
  928. }
  929. warehousing_unit := items["warehousing_unit"].(string)
  930. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  931. utils.ErrorLog("last_price")
  932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  933. return
  934. }
  935. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  936. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  937. utils.ErrorLog("new_price")
  938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  939. return
  940. }
  941. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  942. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  943. utils.ErrorLog("drug_id")
  944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  945. return
  946. }
  947. drug_id := int64(items["drug_id"].(float64))
  948. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  949. utils.ErrorLog("start_time")
  950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  951. return
  952. }
  953. var startTime int64
  954. start_time := items["start_time"].(string)
  955. if len(start_time) > 0 {
  956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  957. if err != nil {
  958. fmt.Println(err)
  959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  960. return
  961. }
  962. startTime = theTime.Unix()
  963. }
  964. orgId := this.GetAdminUserInfo().CurrentOrgId
  965. Creater := this.GetAdminUserInfo().AdminUser.Id
  966. drugAdjust := models.XtDrugAdjustPrice{
  967. DrugName: drug_name,
  968. SpecificationName: specification_name,
  969. WarehousingUnit: warehousing_unit,
  970. LastPrice: last_price,
  971. RetailPrice: retail_price,
  972. NewPrice: new_price,
  973. Manufacturer: manufacturer,
  974. Dealer: dealer,
  975. Remark: remark,
  976. DrugId: drug_id,
  977. UserOrgId: orgId,
  978. Ctime: time.Now().Unix(),
  979. Mtime: 0,
  980. Status: 1,
  981. WarehousingOrder: warehousing_order,
  982. Number: number,
  983. StartTime: startTime,
  984. Creater: Creater,
  985. Checker: 0,
  986. CheckerStatus: 2,
  987. CheckerTime: 0,
  988. }
  989. err := service.CreateDrugPrice(drugAdjust)
  990. fmt.Println(err)
  991. }
  992. }
  993. returnData := make(map[string]interface{}, 0)
  994. returnData["msg"] = "ok"
  995. this.ServeSuccessJSON(returnData)
  996. return
  997. }
  998. func (this *SelfDrugApiController) GetDrugPriceList() {
  999. timeLayout := "2006-01-02"
  1000. loc, _ := time.LoadLocation("Local")
  1001. dataBody := make(map[string]interface{}, 0)
  1002. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1003. fmt.Println(err)
  1004. orgId := this.GetAdminUserInfo().CurrentOrgId
  1005. keyword := this.GetString("keyword")
  1006. start_time := this.GetString("start_time")
  1007. end_time := this.GetString("end_time")
  1008. var startTime int64
  1009. if len(start_time) > 0 {
  1010. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1011. if err != nil {
  1012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1013. return
  1014. }
  1015. startTime = theTime.Unix()
  1016. }
  1017. var endTime int64
  1018. if len(end_time) > 0 {
  1019. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1020. if err != nil {
  1021. utils.ErrorLog(err.Error())
  1022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1023. return
  1024. }
  1025. endTime = theTime.Unix()
  1026. }
  1027. limit, _ := this.GetInt64("limit")
  1028. page, _ := this.GetInt64("page")
  1029. list, total, err := service.GetDrugPriceList(startTime, endTime, orgId, keyword, limit, page)
  1030. doctorList, err := service.GetAllDoctorThree(orgId)
  1031. if err != nil {
  1032. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1033. return
  1034. }
  1035. this.ServeSuccessJSON(map[string]interface{}{
  1036. "total": total,
  1037. "list": list,
  1038. "doctorList": doctorList,
  1039. })
  1040. }
  1041. func (this *SelfDrugApiController) SaveCheckDrugPrice() {
  1042. timeLayout := "2006-01-02"
  1043. loc, _ := time.LoadLocation("Local")
  1044. dataBody := make(map[string]interface{}, 0)
  1045. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1046. fmt.Println(err)
  1047. idstr := this.GetString("ids")
  1048. ids := strings.Split(idstr, ",")
  1049. check_time := this.GetString("check_time")
  1050. var checkTime int64
  1051. if len(check_time) > 0 {
  1052. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1053. if err != nil {
  1054. fmt.Println(err)
  1055. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1056. return
  1057. }
  1058. checkTime = theTime.Unix()
  1059. }
  1060. checker, _ := this.GetInt64("checker")
  1061. adjustPrice := models.XtDrugAdjustPrice{
  1062. Checker: checker,
  1063. CheckerStatus: 1,
  1064. CheckerTime: checkTime,
  1065. }
  1066. err = service.UpdateDrugAdjuestPrice(ids, adjustPrice)
  1067. fmt.Println("err", err)
  1068. list, _ := service.GetDrugAdjuestPrice(ids)
  1069. for _, item := range list {
  1070. drug := models.BaseDrugLib{
  1071. RetailPrice: item.NewPrice,
  1072. LastPrice: item.NewPrice,
  1073. }
  1074. service.UpdateBaseDrugOne(drug, item.DrugId)
  1075. }
  1076. this.ServeSuccessJSON(map[string]interface{}{
  1077. "adjustPrice": adjustPrice,
  1078. })
  1079. }
  1080. func (this *SelfDrugApiController) SaveDrugDamage() {
  1081. timeLayout := "2006-01-02"
  1082. loc, _ := time.LoadLocation("Local")
  1083. dataBody := make(map[string]interface{}, 0)
  1084. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1085. fmt.Println(err)
  1086. tableData, _ := dataBody["tableData"].([]interface{})
  1087. fmt.Println("999939433443", tableData)
  1088. if len(tableData) > 0 {
  1089. for _, item := range tableData {
  1090. items := item.(map[string]interface{})
  1091. drug_name := items["drug_name"].(string)
  1092. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1093. utils.ErrorLog("drug_name")
  1094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1095. return
  1096. }
  1097. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1098. utils.ErrorLog("retail_price")
  1099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1100. return
  1101. }
  1102. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1103. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1104. utils.ErrorLog("warehousing_order")
  1105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1106. return
  1107. }
  1108. warehousing_order := items["warehousing_order"].(string)
  1109. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1110. utils.ErrorLog("number")
  1111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1112. return
  1113. }
  1114. number := items["number"].(string)
  1115. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1116. utils.ErrorLog("dealer")
  1117. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1118. return
  1119. }
  1120. dealer := items["dealer"].(string)
  1121. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1122. utils.ErrorLog("manufacturer")
  1123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1124. return
  1125. }
  1126. manufacturer := items["manufacturer"].(string)
  1127. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1128. utils.ErrorLog("specification_name")
  1129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1130. return
  1131. }
  1132. specification_name := items["specification_name"].(string)
  1133. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1134. utils.ErrorLog("remark")
  1135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1136. return
  1137. }
  1138. remark := items["remark"].(string)
  1139. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1140. utils.ErrorLog("warehousing_unit")
  1141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1142. return
  1143. }
  1144. warehousing_unit := items["warehousing_unit"].(string)
  1145. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1146. utils.ErrorLog("last_price")
  1147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1148. return
  1149. }
  1150. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1151. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1152. utils.ErrorLog("count")
  1153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1154. return
  1155. }
  1156. count := int64(items["count"].(float64))
  1157. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1158. utils.ErrorLog("new_price")
  1159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1160. return
  1161. }
  1162. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1163. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1164. utils.ErrorLog("drug_id")
  1165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1166. return
  1167. }
  1168. drug_id := int64(items["drug_id"].(float64))
  1169. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1170. utils.ErrorLog("start_time")
  1171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1172. return
  1173. }
  1174. var startTime int64
  1175. start_time := items["start_time"].(string)
  1176. if len(start_time) > 0 {
  1177. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1178. if err != nil {
  1179. fmt.Println(err)
  1180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1181. return
  1182. }
  1183. startTime = theTime.Unix()
  1184. }
  1185. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  1186. utils.ErrorLog("warehousing_info_id")
  1187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1188. return
  1189. }
  1190. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  1191. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1192. utils.ErrorLog("expiry_date")
  1193. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1194. return
  1195. }
  1196. expiry_date := int64(items["expiry_date"].(float64))
  1197. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1198. utils.ErrorLog("product_date")
  1199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1200. return
  1201. }
  1202. product_date := int64(items["product_date"].(float64))
  1203. if items["drug_origin_place"] == nil || reflect.TypeOf(items["drug_origin_place"]).String() != "string" {
  1204. utils.ErrorLog("drug_origin_place")
  1205. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. drug_origin_place := items["drug_origin_place"].(string)
  1209. orgId := this.GetAdminUserInfo().CurrentOrgId
  1210. Creater := this.GetAdminUserInfo().AdminUser.Id
  1211. if items["stock_max_number"] == nil || reflect.TypeOf(items["stock_max_number"]).String() != "float64" {
  1212. utils.ErrorLog("stock_max_number")
  1213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1214. return
  1215. }
  1216. stock_max_number := int64(items["stock_max_number"].(float64))
  1217. if items["stock_min_number"] == nil || reflect.TypeOf(items["stock_min_number"]).String() != "float64" {
  1218. utils.ErrorLog("stock_min_number")
  1219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1220. return
  1221. }
  1222. stock_min_number := int64(items["stock_min_number"].(float64))
  1223. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1224. utils.ErrorLog("total")
  1225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1226. return
  1227. }
  1228. total := items["total"].(string)
  1229. drugDamage := models.XtDrugDamage{
  1230. DrugName: drug_name,
  1231. SpecificationName: specification_name,
  1232. WarehousingUnit: warehousing_unit,
  1233. Count: count,
  1234. LastPrice: last_price,
  1235. RetailPrice: retail_price,
  1236. NewPrice: new_price,
  1237. Manufacturer: manufacturer,
  1238. Dealer: dealer,
  1239. Remark: remark,
  1240. DrugId: drug_id,
  1241. UserOrgId: orgId,
  1242. Ctime: time.Now().Unix(),
  1243. Mtime: 0,
  1244. Status: 1,
  1245. WarehousingOrder: warehousing_order,
  1246. Number: number,
  1247. StartTime: startTime,
  1248. Creater: Creater,
  1249. Checker: 0,
  1250. CheckerStatus: 2,
  1251. CheckerTime: 0,
  1252. ExpiryDate: expiry_date,
  1253. ProductDate: product_date,
  1254. WarehousingInfoId: warehousing_info_id,
  1255. DrugOriginPlace: drug_origin_place,
  1256. StockMaxNumber: stock_max_number,
  1257. StockMinNumber: stock_min_number,
  1258. Total: total,
  1259. }
  1260. err := service.CreateDrugDamage(drugDamage)
  1261. fmt.Println(err)
  1262. }
  1263. }
  1264. returnData := make(map[string]interface{}, 0)
  1265. returnData["msg"] = "ok"
  1266. this.ServeSuccessJSON(returnData)
  1267. }
  1268. func (this *SelfDrugApiController) GetDrugDamageList() {
  1269. timeLayout := "2006-01-02"
  1270. loc, _ := time.LoadLocation("Local")
  1271. dataBody := make(map[string]interface{}, 0)
  1272. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1273. fmt.Println(err)
  1274. orgId := this.GetAdminUserInfo().CurrentOrgId
  1275. keyword := this.GetString("keyword")
  1276. start_time := this.GetString("start_time")
  1277. end_time := this.GetString("end_time")
  1278. var startTime int64
  1279. if len(start_time) > 0 {
  1280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1281. if err != nil {
  1282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1283. return
  1284. }
  1285. startTime = theTime.Unix()
  1286. }
  1287. var endTime int64
  1288. if len(end_time) > 0 {
  1289. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1290. if err != nil {
  1291. utils.ErrorLog(err.Error())
  1292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1293. return
  1294. }
  1295. endTime = theTime.Unix()
  1296. }
  1297. limit, _ := this.GetInt64("limit")
  1298. page, _ := this.GetInt64("page")
  1299. list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page)
  1300. doctorList, err := service.GetAllDoctorThree(orgId)
  1301. if err != nil {
  1302. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1303. return
  1304. }
  1305. this.ServeSuccessJSON(map[string]interface{}{
  1306. "total": total,
  1307. "list": list,
  1308. "doctorList": doctorList,
  1309. })
  1310. }
  1311. func (this *SelfDrugApiController) SaveDrugDamagePrice() {
  1312. timeLayout := "2006-01-02"
  1313. loc, _ := time.LoadLocation("Local")
  1314. dataBody := make(map[string]interface{}, 0)
  1315. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1316. fmt.Println(err)
  1317. idstr := this.GetString("ids")
  1318. ids := strings.Split(idstr, ",")
  1319. check_time := this.GetString("check_time")
  1320. var checkTime int64
  1321. if len(check_time) > 0 {
  1322. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1323. if err != nil {
  1324. fmt.Println(err)
  1325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. checkTime = theTime.Unix()
  1329. }
  1330. checker, _ := this.GetInt64("checker")
  1331. damage := models.XtDrugDamage{
  1332. Checker: checker,
  1333. CheckerStatus: 1,
  1334. CheckerTime: checkTime,
  1335. }
  1336. err = service.UpdateDrugDamage(ids, damage)
  1337. fmt.Println(err)
  1338. list, _ := service.GetDrugDamage(ids)
  1339. ctime := time.Now().Unix()
  1340. adminUserInfo := this.GetAdminUserInfo()
  1341. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1342. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  1343. var manufacturer_id int64
  1344. var dealer_id int64
  1345. timeStr := time.Now().Format("2006-01-02")
  1346. timeArr := strings.Split(timeStr, "-")
  1347. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1348. total = total + 1
  1349. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1350. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1351. number = number + total
  1352. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1353. operation_time := time.Now().Unix()
  1354. creater := adminUserInfo.AdminUser.Id
  1355. warehouseOut := models.DrugWarehouseOut{
  1356. WarehouseOutOrderNumber: warehousing_out_order,
  1357. OperationTime: operation_time,
  1358. OrgId: adminUserInfo.CurrentOrgId,
  1359. Creater: creater,
  1360. Ctime: ctime,
  1361. Status: 1,
  1362. WarehouseOutTime: time.Now().Unix(),
  1363. Type: 1,
  1364. }
  1365. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1366. for _, item := range list {
  1367. for _, it := range manufacturerList {
  1368. if item.Manufacturer == it.ManufacturerName {
  1369. manufacturer_id = it.ID
  1370. }
  1371. }
  1372. for _, its := range dealerList {
  1373. if its.DealerName == item.Dealer {
  1374. dealer_id = its.ID
  1375. }
  1376. }
  1377. warehouseOutInfo := models.XtDrugWarehouseOutInfo{
  1378. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1379. WarehouseOutId: warehouseOut.ID,
  1380. DrugId: item.DrugId,
  1381. Count: item.Count,
  1382. Price: item.RetailPrice,
  1383. Status: 1,
  1384. Ctime: ctime,
  1385. Remark: item.Remark,
  1386. OrgId: adminUserInfo.CurrentOrgId,
  1387. Type: 1,
  1388. Manufacturer: manufacturer_id,
  1389. Dealer: dealer_id,
  1390. RetailPrice: item.RetailPrice,
  1391. CountUnit: item.WarehousingUnit,
  1392. ExpiryDate: item.ExpiryDate,
  1393. ProductDate: item.ProductDate,
  1394. Number: item.Number,
  1395. BatchNumber: item.BatchNumber,
  1396. IsSys: 0,
  1397. WarehouseInfoId: item.WarehousingInfoId,
  1398. }
  1399. drugflow := models.DrugFlow{
  1400. WarehouseOutId: warehouseOut.ID,
  1401. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1402. DrugId: item.DrugId,
  1403. Number: item.Number,
  1404. ProductDate: item.ProductDate,
  1405. ExpireDate: item.ExpiryDate,
  1406. Count: item.Count,
  1407. Price: item.RetailPrice,
  1408. Status: 1,
  1409. Ctime: ctime,
  1410. UserOrgId: adminUserInfo.CurrentOrgId,
  1411. Manufacturer: manufacturer_id,
  1412. Dealer: dealer_id,
  1413. BatchNumber: item.BatchNumber,
  1414. MaxUnit: item.WarehousingUnit,
  1415. ConsumableType: 5,
  1416. IsEdit: 1,
  1417. Creator: adminUserInfo.AdminUser.Id,
  1418. IsSys: 0,
  1419. }
  1420. service.CreateWareHouseOutInfo(&warehouseOutInfo)
  1421. service.CreateDrugFlowOne(drugflow)
  1422. info, _ := service.GetDrugByWarehouseInfo(item.WarehousingInfoId)
  1423. //扣减库存
  1424. warehouseInfo := models.XtDrugWarehouseInfo{
  1425. StockMaxNumber: info.StockMaxNumber - info.StockMaxNumber,
  1426. }
  1427. service.UpdateDrugWarehouseingInfo(item.WarehousingInfoId, warehouseInfo)
  1428. }
  1429. this.ServeSuccessJSON(map[string]interface{}{
  1430. "damage": damage,
  1431. })
  1432. }
  1433. func (this *SelfDrugApiController) GetDrugModifyPrice() {
  1434. id, _ := this.GetInt64("id")
  1435. detail, err := service.GetDrugModifyPrice(id)
  1436. fmt.Println(err)
  1437. this.ServeSuccessJSON(map[string]interface{}{
  1438. "detail": detail,
  1439. })
  1440. }
  1441. func (this *SelfDrugApiController) ModifyDrugPrice() {
  1442. drug_name := this.GetString("drug_name")
  1443. specification_name := this.GetString("specification_name")
  1444. warehousing_unit := this.GetString("warehousing_unit")
  1445. manufacturer := this.GetString("manufacturer")
  1446. number := this.GetString("number")
  1447. retailPrice := this.GetString("retail_price")
  1448. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1449. newPrice := this.GetString("new_price")
  1450. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1451. count, _ := this.GetInt64("count")
  1452. remark := this.GetString("remark")
  1453. id, _ := this.GetInt64("id")
  1454. drug_id, _ := this.GetInt64("drug_id")
  1455. adjustPrice := models.XtDrugAdjustPrice{
  1456. DrugName: drug_name,
  1457. Count: count,
  1458. RetailPrice: retail_price,
  1459. NewPrice: new_price,
  1460. Remark: remark,
  1461. SpecificationName: specification_name,
  1462. WarehousingUnit: warehousing_unit,
  1463. Manufacturer: manufacturer,
  1464. Number: number,
  1465. DrugId: drug_id,
  1466. }
  1467. err := service.ModifyDrugPrice(id, adjustPrice)
  1468. fmt.Println(err)
  1469. this.ServeSuccessJSON(map[string]interface{}{
  1470. "adjustPrice": adjustPrice,
  1471. })
  1472. }
  1473. func (this *SelfDrugApiController) GetModifyPricePrint() {
  1474. ids := this.GetString("ids")
  1475. idsSplit := strings.Split(ids, ",")
  1476. list, err := service.GetModifyPricePrint(idsSplit)
  1477. fmt.Println(err)
  1478. this.ServeSuccessJSON(map[string]interface{}{
  1479. "list": list,
  1480. })
  1481. }
  1482. func (this *SelfDrugApiController) GetDrugDamageDetail() {
  1483. id, _ := this.GetInt64("id")
  1484. detail, _ := service.GetDrugDamageDetail(id)
  1485. this.ServeSuccessJSON(map[string]interface{}{
  1486. "detail": detail,
  1487. })
  1488. }
  1489. func (this *SelfDrugApiController) ModifyDrugDamage() {
  1490. id, _ := this.GetInt64("id")
  1491. drug_id, _ := this.GetInt64("drug_id")
  1492. drug_name := this.GetString("drug_name")
  1493. drug_origin_place := this.GetString("drug_origin_place")
  1494. lastPrice := this.GetString("last_price")
  1495. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  1496. newPrice := this.GetString("new_price")
  1497. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1498. manufacturer := this.GetString("manufacturer")
  1499. number := this.GetString("number")
  1500. retailPrice := this.GetString("retail_price")
  1501. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1502. remark := this.GetString("remark")
  1503. count, _ := this.GetInt64("count")
  1504. warehousing_unit := this.GetString("warehousing_unit")
  1505. stock_max_number, _ := this.GetInt64("stock_max_number")
  1506. stock_min_number, _ := this.GetInt64("stock_min_number")
  1507. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  1508. damage := models.XtDrugDamage{
  1509. DrugName: drug_name,
  1510. SpecificationName: "",
  1511. WarehousingUnit: warehousing_unit,
  1512. Count: count,
  1513. LastPrice: last_price,
  1514. RetailPrice: retail_price,
  1515. NewPrice: new_price,
  1516. Manufacturer: manufacturer,
  1517. Dealer: "",
  1518. Remark: remark,
  1519. DrugId: drug_id,
  1520. Number: number,
  1521. StockMaxNumber: stock_max_number,
  1522. StockMinNumber: stock_min_number,
  1523. WarehousingInfoId: warehousing_info_id,
  1524. DrugOriginPlace: drug_origin_place,
  1525. }
  1526. err := service.ModifyDrugDamage(id, damage)
  1527. fmt.Println(err)
  1528. this.ServeSuccessJSON(map[string]interface{}{
  1529. "damage": damage,
  1530. })
  1531. }
  1532. func (this *SelfDrugApiController) DeleteDrugDamage() {
  1533. id, _ := this.GetInt64("id")
  1534. err := service.DeleteDrugDamage(id)
  1535. fmt.Println(err)
  1536. returnData := make(map[string]interface{}, 0)
  1537. returnData["msg"] = "ok"
  1538. this.ServeSuccessJSON(returnData)
  1539. }
  1540. func (this *SelfDrugApiController) GetDrugDamagePrint() {
  1541. idsSplit := this.GetString("ids")
  1542. ids := strings.Split(idsSplit, ",")
  1543. list, _ := service.GetDrugDamagePrint(ids)
  1544. this.ServeSuccessJSON(map[string]interface{}{
  1545. "list": list,
  1546. })
  1547. }
  1548. func (this *SelfDrugApiController) GetWarehoseInfoById() {
  1549. id, _ := this.GetInt64("id")
  1550. list, _ := service.GetWarehoseInfoById(id)
  1551. this.ServeSuccessJSON(map[string]interface{}{
  1552. "list": list,
  1553. })
  1554. }
  1555. func (this *SelfDrugApiController) SaveDrugInventory() {
  1556. timeLayout := "2006-01-02"
  1557. loc, _ := time.LoadLocation("Local")
  1558. dataBody := make(map[string]interface{}, 0)
  1559. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1560. fmt.Println(err)
  1561. tableData, _ := dataBody["tableData"].([]interface{})
  1562. fmt.Println("999939433443", tableData)
  1563. if len(tableData) > 0 {
  1564. for _, item := range tableData {
  1565. items := item.(map[string]interface{})
  1566. drug_name := items["drug_name"].(string)
  1567. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1568. utils.ErrorLog("drug_name")
  1569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1570. return
  1571. }
  1572. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1573. utils.ErrorLog("retail_price")
  1574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1578. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1579. utils.ErrorLog("warehousing_order")
  1580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1581. return
  1582. }
  1583. warehousing_order := items["warehousing_order"].(string)
  1584. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1585. utils.ErrorLog("dealer")
  1586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1587. return
  1588. }
  1589. dealer := items["dealer"].(string)
  1590. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1591. utils.ErrorLog("manufacturer")
  1592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1593. return
  1594. }
  1595. manufacturer := items["manufacturer"].(string)
  1596. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1597. utils.ErrorLog("specification_name")
  1598. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. specification_name := items["specification_name"].(string)
  1602. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1603. utils.ErrorLog("remark")
  1604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1605. return
  1606. }
  1607. remark := items["remark"].(string)
  1608. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1609. utils.ErrorLog("warehousing_unit")
  1610. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1611. return
  1612. }
  1613. warehousing_unit := items["warehousing_unit"].(string)
  1614. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1615. utils.ErrorLog("last_price")
  1616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1617. return
  1618. }
  1619. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1620. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1621. utils.ErrorLog("count")
  1622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1623. return
  1624. }
  1625. count := int64(items["count"].(float64))
  1626. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1627. utils.ErrorLog("new_price")
  1628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1629. return
  1630. }
  1631. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1632. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1633. utils.ErrorLog("drug_id")
  1634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1635. return
  1636. }
  1637. drug_id := int64(items["drug_id"].(float64))
  1638. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1639. utils.ErrorLog("start_time")
  1640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. var startTime int64
  1644. start_time := items["start_time"].(string)
  1645. if len(start_time) > 0 {
  1646. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1647. if err != nil {
  1648. fmt.Println(err)
  1649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1650. return
  1651. }
  1652. startTime = theTime.Unix()
  1653. }
  1654. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1655. utils.ErrorLog("product_date")
  1656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1657. return
  1658. }
  1659. product_date := int64(items["product_date"].(float64))
  1660. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1661. utils.ErrorLog("expiry_date")
  1662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1663. return
  1664. }
  1665. expiry_date := int64(items["expiry_date"].(float64))
  1666. orgId := this.GetAdminUserInfo().CurrentOrgId
  1667. Creater := this.GetAdminUserInfo().AdminUser.Id
  1668. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1669. utils.ErrorLog("number")
  1670. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1671. return
  1672. }
  1673. numbers := items["number"].(string)
  1674. //if items["batch_number"] == nil || reflect.TypeOf(items["batch_number"]).String() != "string" {
  1675. // utils.ErrorLog("batch_number")
  1676. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1677. // return
  1678. //}
  1679. //
  1680. //batch_number := items["batch_number"].(string)
  1681. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1682. utils.ErrorLog("warehouse_info_id")
  1683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1684. return
  1685. }
  1686. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1687. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1688. utils.ErrorLog("total")
  1689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1690. return
  1691. }
  1692. total := items["total"].(string)
  1693. inventory := models.XtDrugInventory{
  1694. DrugName: drug_name,
  1695. SpecificationName: specification_name,
  1696. WarehousingUnit: warehousing_unit,
  1697. Count: count,
  1698. LastPrice: last_price,
  1699. RetailPrice: retail_price,
  1700. NewPrice: new_price,
  1701. Manufacturer: manufacturer,
  1702. Dealer: dealer,
  1703. Remark: remark,
  1704. DrugId: drug_id,
  1705. UserOrgId: orgId,
  1706. Ctime: time.Now().Unix(),
  1707. Mtime: 0,
  1708. Status: 1,
  1709. WarehousingOrder: warehousing_order,
  1710. LicenseNumber: "",
  1711. StartTime: startTime,
  1712. Creater: Creater,
  1713. Checker: 0,
  1714. CheckerStatus: 2,
  1715. CheckerTime: 0,
  1716. ExpiryDate: expiry_date,
  1717. ProductDate: product_date,
  1718. Number: numbers,
  1719. //BatchNumber: batch_number,
  1720. Total: total,
  1721. WarehouseInfoId: warehouse_info_id,
  1722. }
  1723. err = service.CreateDrugInventory(inventory)
  1724. fmt.Println(err)
  1725. }
  1726. }
  1727. this.ServeSuccessJSON(map[string]interface{}{
  1728. "msg": "msg",
  1729. })
  1730. }
  1731. func (this *SelfDrugApiController) GetDrugInventoryList() {
  1732. timeLayout := "2006-01-02"
  1733. loc, _ := time.LoadLocation("Local")
  1734. dataBody := make(map[string]interface{}, 0)
  1735. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1736. fmt.Println(err)
  1737. orgId := this.GetAdminUserInfo().CurrentOrgId
  1738. keyword := this.GetString("keyword")
  1739. start_time := this.GetString("start_time")
  1740. end_time := this.GetString("end_time")
  1741. var startTime int64
  1742. if len(start_time) > 0 {
  1743. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1744. if err != nil {
  1745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1746. return
  1747. }
  1748. startTime = theTime.Unix()
  1749. }
  1750. var endTime int64
  1751. if len(end_time) > 0 {
  1752. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1753. if err != nil {
  1754. utils.ErrorLog(err.Error())
  1755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1756. return
  1757. }
  1758. endTime = theTime.Unix()
  1759. }
  1760. limit, _ := this.GetInt64("limit")
  1761. page, _ := this.GetInt64("page")
  1762. list, total, err := service.GetDrugInventoryList(keyword, page, limit, orgId, startTime, endTime)
  1763. fmt.Println("list23232323223", list)
  1764. doctorList, _ := service.GetAllDoctorThree(orgId)
  1765. if err != nil {
  1766. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1767. return
  1768. }
  1769. this.ServeSuccessJSON(map[string]interface{}{
  1770. "total": total,
  1771. "list": list,
  1772. "doctorList": doctorList,
  1773. })
  1774. }
  1775. func (this *SelfDrugApiController) SaveDrugCheckInventory() {
  1776. timeLayout := "2006-01-02"
  1777. loc, _ := time.LoadLocation("Local")
  1778. dataBody := make(map[string]interface{}, 0)
  1779. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1780. fmt.Println(err)
  1781. idstr := this.GetString("ids")
  1782. ids := strings.Split(idstr, ",")
  1783. check_time := this.GetString("check_time")
  1784. var checkTime int64
  1785. if len(check_time) > 0 {
  1786. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1787. if err != nil {
  1788. fmt.Println(err)
  1789. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1790. return
  1791. }
  1792. checkTime = theTime.Unix()
  1793. }
  1794. checker, _ := this.GetInt64("checker")
  1795. inventory := models.XtDrugInventory{
  1796. Checker: checker,
  1797. CheckerStatus: 1,
  1798. CheckerTime: checkTime,
  1799. }
  1800. err = service.UpdateDrugInventory(ids, inventory)
  1801. fmt.Println(err)
  1802. returnData := make(map[string]interface{}, 0)
  1803. returnData["msg"] = "ok"
  1804. this.ServeSuccessJSON(returnData)
  1805. }
  1806. func (this *SelfDrugApiController) GetDrugInventoryDetail() {
  1807. id, _ := this.GetInt64("id")
  1808. detail, err := service.GetDrugInventoryDetail(id)
  1809. if err != nil {
  1810. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1811. return
  1812. }
  1813. this.ServeSuccessJSON(map[string]interface{}{
  1814. "detail": detail,
  1815. })
  1816. }
  1817. func (this *SelfDrugApiController) ModifyInventory() {
  1818. id, _ := this.GetInt64("id")
  1819. drug_id, _ := this.GetInt64("drug_id")
  1820. drug_name := this.GetString("drug_name")
  1821. specification_name := this.GetString("specification_name")
  1822. retailPrice := this.GetString("retail_price")
  1823. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1824. warehousing_order := this.GetString("warehousing_order")
  1825. number := this.GetString("number")
  1826. manufacturer := this.GetString("manufacturer")
  1827. remark := this.GetString("remark")
  1828. warehousing_unit := this.GetString("warehousing_unit")
  1829. total := this.GetString("total")
  1830. lastPrice := this.GetString("last_price")
  1831. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  1832. count, _ := this.GetInt64("count")
  1833. drug_origin_place := this.GetString("drug_origin_place")
  1834. inventory := models.XtDrugInventory{
  1835. DrugName: drug_name,
  1836. SpecificationName: specification_name,
  1837. WarehousingUnit: warehousing_unit,
  1838. Count: count,
  1839. LastPrice: last_price,
  1840. RetailPrice: retail_price,
  1841. Manufacturer: manufacturer,
  1842. Remark: remark,
  1843. DrugId: drug_id,
  1844. WarehousingOrder: warehousing_order,
  1845. Number: number,
  1846. Total: total,
  1847. DrugOriginPlace: drug_origin_place,
  1848. }
  1849. err := service.ModifyDrugInventory(id, inventory)
  1850. if err != nil {
  1851. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1852. return
  1853. }
  1854. this.ServeSuccessJSON(map[string]interface{}{
  1855. "inventory": inventory,
  1856. })
  1857. }
  1858. func (this *SelfDrugApiController) DeleteDrugInventory() {
  1859. id, _ := this.GetInt64("id")
  1860. err := service.DeleteDrugInventory(id)
  1861. fmt.Println(err)
  1862. returnData := make(map[string]interface{}, 0)
  1863. returnData["msg"] = "ok"
  1864. this.ServeSuccessJSON(returnData)
  1865. }
  1866. func (this *SelfDrugApiController) GetDrugInventoryPrintList() {
  1867. ids := this.GetString("ids")
  1868. idssplit := strings.Split(ids, ",")
  1869. list, err := service.GetDrugInventoryPrintList(idssplit)
  1870. if err != nil {
  1871. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1872. return
  1873. }
  1874. this.ServeSuccessJSON(map[string]interface{}{
  1875. "list": list,
  1876. })
  1877. }
  1878. func (this *SelfDrugApiController) GetDrugInventoryDetailList() {
  1879. keyword := this.GetString("keyword")
  1880. limit, _ := this.GetInt64("limit")
  1881. page, _ := this.GetInt64("page")
  1882. orgId := this.GetAdminUserInfo().CurrentOrgId
  1883. list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId)
  1884. fmt.Println("list23232323223", list)
  1885. doctorList, _ := service.GetAllDoctorThree(orgId)
  1886. if err != nil {
  1887. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1888. return
  1889. }
  1890. this.ServeSuccessJSON(map[string]interface{}{
  1891. "total": total,
  1892. "list": list,
  1893. "doctorList": doctorList,
  1894. })
  1895. }
  1896. func (this *SelfDrugApiController) SaveDrugProofInventory() {
  1897. id, _ := this.GetInt64("id")
  1898. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  1899. warehousing_unit := this.GetString("warehousing_unit")
  1900. remark := this.GetString("remark")
  1901. //total := this.GetString("total")
  1902. proof_count, _ := this.GetInt64("proof_count")
  1903. fmt.Println("pof_count2222222", proof_count)
  1904. inventory := models.XtDrugInventory{
  1905. WarehouseInfoId: warehouse_info_id,
  1906. ProofCount: proof_count,
  1907. WarehousingUnit: warehousing_unit,
  1908. Remark: remark,
  1909. }
  1910. err := service.UpdateDrugProofInventory(id, &inventory)
  1911. info := models.XtDrugWarehouseInfo{
  1912. StockMaxNumber: proof_count,
  1913. }
  1914. service.UpdateDrugWarehouseInfoById(warehouse_info_id, &info)
  1915. if err != nil {
  1916. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1917. return
  1918. }
  1919. this.ServeSuccessJSON(map[string]interface{}{
  1920. "inventory": inventory,
  1921. })
  1922. }
  1923. func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
  1924. id, _ := this.GetInt64("id")
  1925. list, _ := service.GetDrugWarehouseInfoTotal(id)
  1926. this.ServeSuccessJSON(map[string]interface{}{
  1927. "list": list,
  1928. })
  1929. }