self_drug_api_congtroller.go 102KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079
  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. "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{}, "Get: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. beego.Router("/api/drug/saveinentorylist", &SelfDrugApiController{}, "Post:SaveInventoryList")
  79. beego.Router("/api/drug/getdamagebydrugid", &SelfDrugApiController{}, "Get:GetDamageByDrugId")
  80. beego.Router("/api/drug/getinventorymodelist", &SelfDrugApiController{}, "Get:GetInventoryModeList")
  81. //耗材库存优化接口
  82. beego.Router("/api/drug/getstorehouselist", &SelfDrugApiController{}, "Get:GetStorehouseList")
  83. beego.Router("/api/drug/getgoodnewquery", &SelfDrugApiController{}, "Get:GetGoodNewQuery")
  84. beego.Router("/api/drug/getgoodwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetGoodWarehouseOutInfoByIdList")
  85. beego.Router("/api/good/getgoodpatientlist", &SelfDrugApiController{}, "Get:GetGoodPatientList")
  86. beego.Router("/api/good/getwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetWarehouseOutDetailByPatientId")
  87. beego.Router("/api/good/getgoodexpirydatequery", &SelfDrugApiController{}, "Get:GetGoodExpiryDateQuery")
  88. beego.Router("/api/good/getpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodPurchaseStockQuery")
  89. //药品库存优化接口
  90. beego.Router("/api/good/getdrugwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetDrugWarehouseOutDetailByPatientId")
  91. beego.Router("/api/drug/getdrugexpirydatequery", &SelfDrugApiController{}, "Get:GetDrugExpiryDateQuery")
  92. }
  93. func (this *SelfDrugApiController) GetCurrentPatient() {
  94. adminUserInfo := this.GetAdminUserInfo()
  95. orgId := adminUserInfo.CurrentOrgId
  96. patient, err := service.GetCurrentPatient(orgId)
  97. if err != nil {
  98. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  99. return
  100. }
  101. this.ServeSuccessJSON(map[string]interface{}{
  102. "patient": patient,
  103. })
  104. }
  105. func (this *SelfDrugApiController) GetAllDrugName() {
  106. adminUserInfo := this.GetAdminUserInfo()
  107. orgId := adminUserInfo.CurrentOrgId
  108. //查询药品库是否开启
  109. //configStock, _ := service.GetDrugStockConfig(orgId)
  110. //if configStock.IsOpen == 1 {
  111. //
  112. //}
  113. drugName, err := service.GetAllDrugName(orgId)
  114. if err != nil {
  115. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
  116. return
  117. }
  118. this.ServeSuccessJSON(map[string]interface{}{
  119. "drugName": drugName,
  120. })
  121. }
  122. func (this *SelfDrugApiController) SaveDrugName() {
  123. adminUserInfo := this.GetAdminUserInfo()
  124. orgId := adminUserInfo.CurrentOrgId
  125. drug_name := this.GetString("drug_name")
  126. id, _ := this.GetInt64("id")
  127. //fmt.Println("drug_name", drug_name)
  128. drugName := models.XtDrugName{
  129. UserOrgId: orgId,
  130. DrugName: drug_name,
  131. Status: 1,
  132. CreatedTime: time.Now().Unix(),
  133. DrugId: id,
  134. }
  135. _, errcode := service.GetDrugName(drug_name, orgId)
  136. if errcode == gorm.ErrRecordNotFound {
  137. err := service.SaveDrugName(&drugName)
  138. if err != nil {
  139. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  140. return
  141. }
  142. this.ServeSuccessJSON(map[string]interface{}{
  143. "drugName": drugName,
  144. })
  145. } else {
  146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  147. return
  148. }
  149. }
  150. func (this *SelfDrugApiController) GetDrugNameList() {
  151. adminUserInfo := this.GetAdminUserInfo()
  152. orgId := adminUserInfo.CurrentOrgId
  153. list, err := service.GetDrugNameList(orgId)
  154. if err != nil {
  155. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  156. return
  157. }
  158. this.ServeSuccessJSON(map[string]interface{}{
  159. "list": list,
  160. })
  161. }
  162. func (this *SelfDrugApiController) GetRulleName() {
  163. adminUserInfo := this.GetAdminUserInfo()
  164. orgId := adminUserInfo.CurrentOrgId
  165. id, _ := this.GetInt64("id")
  166. drugId, _ := service.GetDrugId(id)
  167. rullerList, err := service.GetRulleList(orgId, drugId.DrugId)
  168. if err != nil {
  169. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  170. return
  171. }
  172. this.ServeSuccessJSON(map[string]interface{}{
  173. "rullerList": rullerList,
  174. })
  175. }
  176. func (this *SelfDrugApiController) GetUnitByBaseId() {
  177. id, _ := this.GetInt64("id")
  178. baseList, err := service.GetUnitByBaseId(id)
  179. if err != nil {
  180. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  181. return
  182. }
  183. this.ServeSuccessJSON(map[string]interface{}{
  184. "baseList": baseList,
  185. })
  186. }
  187. func (this *SelfDrugApiController) SaveRulleName() {
  188. drug_name := this.GetString("drug_name")
  189. drug_spec := this.GetString("drug_spec")
  190. drug_stock_limit := this.GetString("drug_stock_limit")
  191. drug_name_id, _ := this.GetInt64("drug_name_id")
  192. drug_id, _ := this.GetInt64("drug_id")
  193. price, _ := this.GetInt64("price")
  194. prices := strconv.FormatInt(price, 10)
  195. durg_price, _ := strconv.ParseFloat(prices, 64)
  196. unit := this.GetString("unit")
  197. adminUserInfo := this.GetAdminUserInfo()
  198. orgId := adminUserInfo.CurrentOrgId
  199. fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
  200. drugSpecName := models.XtStandName{
  201. DrugName: drug_name,
  202. DrugSpec: drug_spec,
  203. DrugStockLimit: drug_stock_limit,
  204. DrugNameId: drug_name_id,
  205. Price: durg_price,
  206. MinUnit: unit,
  207. UserOrgId: orgId,
  208. Status: 1,
  209. CreatedTime: time.Now().Unix(),
  210. DrugId: drug_id,
  211. }
  212. //查询该机构下药品规格名称是否存在
  213. _, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
  214. if errcode == gorm.ErrRecordNotFound {
  215. err := service.SaveRulleName(&drugSpecName)
  216. if err != nil {
  217. this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
  218. return
  219. }
  220. this.ServeSuccessJSON(map[string]interface{}{
  221. "RullerName": drugSpecName,
  222. })
  223. } else if errcode == nil {
  224. this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
  225. return
  226. }
  227. }
  228. func (this *SelfDrugApiController) EditRullerName() {
  229. id, _ := this.GetInt64("id")
  230. rullerDetail, err := service.GetRullerNameDetail(id)
  231. if err != nil {
  232. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  233. return
  234. }
  235. this.ServeSuccessJSON(map[string]interface{}{
  236. "rullerDetail": rullerDetail,
  237. })
  238. }
  239. func (this *SelfDrugApiController) UpdatedRullerName() {
  240. id, _ := this.GetInt64("id")
  241. drug_name := this.GetString("drug_name")
  242. drug_stock_limit := this.GetString("drug_stock_limit")
  243. price, _ := this.GetInt64("price")
  244. prices := strconv.FormatInt(price, 10)
  245. durg_price, _ := strconv.ParseFloat(prices, 64)
  246. drug_spec := this.GetString("drug_spec")
  247. unit := this.GetString("unit")
  248. drug_name_id, _ := this.GetInt64("drug_name_id")
  249. drug_id, _ := this.GetInt64("drug_id")
  250. RullerName := models.XtStandName{
  251. DrugName: drug_name,
  252. DrugStockLimit: drug_stock_limit,
  253. Price: durg_price,
  254. DrugSpec: drug_spec,
  255. MinUnit: unit,
  256. DrugNameId: drug_name_id,
  257. DrugId: drug_id,
  258. }
  259. _, errcode := service.GetIsExit(drug_name, drug_spec, id)
  260. if errcode == gorm.ErrRecordNotFound {
  261. err := service.UpdatedRullerName(id, &RullerName)
  262. if err != nil {
  263. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  264. return
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "RullerName": RullerName,
  268. })
  269. } else if errcode == nil {
  270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  271. return
  272. }
  273. }
  274. func (this *SelfDrugApiController) GetAllDrugNameList() {
  275. adminUserInfo := this.GetAdminUserInfo()
  276. orgId := adminUserInfo.CurrentOrgId
  277. rullerName, err := service.GetAllDrugNameList(orgId)
  278. list, err := service.GetMedicalDrugNameList(orgId)
  279. if err != nil {
  280. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  281. return
  282. }
  283. this.ServeSuccessJSON(map[string]interface{}{
  284. "rullerName": rullerName,
  285. "list": list,
  286. })
  287. }
  288. func (this *SelfDrugApiController) GetRullerListByDrugName() {
  289. id := this.GetString("id")
  290. adminUserInfo := this.GetAdminUserInfo()
  291. orgId := adminUserInfo.CurrentOrgId
  292. fmt.Println("orgid", orgId)
  293. drugName, err := service.GetRullerListByDrugName(id, orgId)
  294. if err != nil {
  295. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  296. return
  297. }
  298. this.ServeSuccessJSON(map[string]interface{}{
  299. "drugName": drugName,
  300. })
  301. }
  302. func (this *SelfDrugApiController) SaveSelfMedicines() {
  303. dataBody := make(map[string]interface{}, 0)
  304. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  305. fmt.Println(err)
  306. patient_id := int64(dataBody["patient_id"].(float64))
  307. medicineData, _ := dataBody["medicineData"].([]interface{})
  308. adminUserInfo := this.GetAdminUserInfo()
  309. orgId := adminUserInfo.CurrentOrgId
  310. for _, item := range medicineData {
  311. items := item.(map[string]interface{})
  312. drug_name := items["drug_name"].(string)
  313. drug_name_id := int64(items["drug_name_id"].(float64))
  314. drug_spec := items["drug_spec"].(string)
  315. min_unit := items["min_unit"].(string)
  316. drug_id := int64(items["drug_id"].(float64))
  317. //根据drug_id
  318. drugMedical, _ := service.GetBaseDrugMedical(drug_name_id)
  319. medical := models.XtSelfMedical{
  320. DrugName: drug_name,
  321. DrugNameId: drug_name_id,
  322. DrugSpec: drug_spec,
  323. CreatedTime: time.Now().Unix(),
  324. Status: 1,
  325. UserOrgId: orgId,
  326. PatientId: patient_id,
  327. MinUnit: min_unit,
  328. ExecutionFrequency: drugMedical.ExecutionFrequency,
  329. PrescribingNumber: drugMedical.PrescribingNumber,
  330. DeliveryWay: drugMedical.DeliveryWay,
  331. SingleDose: drugMedical.SingleDose,
  332. DrugId: drug_id,
  333. }
  334. //查询同个病人同个药品同个规格是否已存在
  335. _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
  336. if errcode == gorm.ErrRecordNotFound {
  337. err := service.CreateSelfMedical(&medical)
  338. fmt.Println(err)
  339. } else if errcode == nil {
  340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  341. return
  342. }
  343. }
  344. returnData := make(map[string]interface{}, 0)
  345. returnData["msg"] = "ok"
  346. this.ServeSuccessJSON(returnData)
  347. return
  348. }
  349. func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
  350. adminUserInfo := this.GetAdminUserInfo()
  351. orgid := adminUserInfo.CurrentOrgId
  352. //fmt.Println(orgid)
  353. appId := adminUserInfo.CurrentAppId
  354. staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
  355. if err != nil {
  356. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  357. return
  358. }
  359. this.ServeSuccessJSON(map[string]interface{}{
  360. "staff": staff,
  361. })
  362. }
  363. func (this *SelfDrugApiController) SaveStock() {
  364. timeLayout := "2006-01-02"
  365. loc, _ := time.LoadLocation("Local")
  366. start_time := this.GetString("start_time")
  367. fmt.Println("start_time", start_time)
  368. admin_user_id, _ := this.GetInt64("admin_user_id")
  369. fmt.Println("admin_user_id", admin_user_id)
  370. patient_id, _ := this.GetInt64("patient_id")
  371. dataBody := make(map[string]interface{}, 0)
  372. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  373. fmt.Println(err)
  374. stocks, _ := dataBody["stocks"].([]interface{})
  375. adminUserInfo := this.GetAdminUserInfo()
  376. orgId := adminUserInfo.CurrentOrgId
  377. for _, item := range stocks {
  378. items := item.(map[string]interface{})
  379. drug_name := items["drug_name"].(string)
  380. fmt.Println("drug_name", drug_name)
  381. drug_name_id := int64(items["drug_name_id"].(float64))
  382. fmt.Println("parient_id", drug_name_id)
  383. drug_spec := items["drug_spec"].(string)
  384. store_number := items["store_number"].(string)
  385. fmt.Println("store_number", store_number)
  386. storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
  387. remarks := items["remarks"].(string)
  388. min_unit := items["min_unit"].(string)
  389. medic_id := int64(items["id"].(float64))
  390. timeStr := time.Now().Format("2006-01-02")
  391. timeArr := strings.Split(timeStr, "-")
  392. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  393. total = total + 1
  394. warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  395. number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
  396. number = number + total
  397. warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
  398. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  399. stock := models.XtSelfStock{
  400. DrugName: drug_name,
  401. DrugNameId: drug_name_id,
  402. DrugSpec: drug_spec,
  403. StoreNumber: storeNumber,
  404. Remarks: remarks,
  405. AdminUserId: admin_user_id,
  406. StorckTime: theTime.Unix(),
  407. CreatedTime: time.Now().Unix(),
  408. Status: 1,
  409. UserOrgId: orgId,
  410. StockInNumber: warehousing_in_order,
  411. PatientId: patient_id,
  412. MinUnit: min_unit,
  413. StorageMode: 1,
  414. MedicId: medic_id,
  415. }
  416. err := service.CreateStock(&stock)
  417. fmt.Println("err", err)
  418. }
  419. returnData := make(map[string]interface{}, 0)
  420. returnData["msg"] = "ok"
  421. this.ServeSuccessJSON(returnData)
  422. return
  423. }
  424. func (this *SelfDrugApiController) SaveOutStock() {
  425. timeLayout := "2006-01-02"
  426. loc, _ := time.LoadLocation("Local")
  427. start_time := this.GetString("start_time")
  428. admin_user_id, _ := this.GetInt64("admin_user_id")
  429. patient_id, _ := this.GetInt64("patient_id")
  430. dataBody := make(map[string]interface{}, 0)
  431. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  432. fmt.Println(err)
  433. outStocks, _ := dataBody["outStocks"].([]interface{})
  434. adminUserInfo := this.GetAdminUserInfo()
  435. orgId := adminUserInfo.CurrentOrgId
  436. for _, item := range outStocks {
  437. items := item.(map[string]interface{})
  438. drug_name := items["drug_name"].(string)
  439. drug_name_id := int64(items["drug_name_id"].(float64))
  440. drug_spec := items["drug_spec"].(string)
  441. outstore_number := items["outstore_number"].(string)
  442. outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
  443. remarks := items["remarks"].(string)
  444. medic_id := int64(items["id"].(float64))
  445. timeStr := time.Now().Format("2006-01-02")
  446. timeArr := strings.Split(timeStr, "-")
  447. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  448. total = total + 1
  449. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  450. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  451. number = number + total
  452. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  453. fmt.Println(remarks)
  454. fmt.Println(items)
  455. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  456. stock := models.XtSelfOutStock{
  457. DrugName: drug_name,
  458. DrugNameId: drug_name_id,
  459. DrugSpec: drug_spec,
  460. OutstoreNumber: outStoreNumber,
  461. Remarks: remarks,
  462. AdminUserId: admin_user_id,
  463. StorckTime: theTime.Unix(),
  464. CreatedTime: time.Now().Unix(),
  465. Status: 1,
  466. UserOrgId: orgId,
  467. StockOutNumber: warehousing_out_order,
  468. PatientId: patient_id,
  469. ExitMode: 1,
  470. MedicId: medic_id,
  471. }
  472. err := service.CreateOutStock(&stock)
  473. fmt.Println("err", err)
  474. }
  475. returnData := make(map[string]interface{}, 0)
  476. returnData["msg"] = "ok"
  477. this.ServeSuccessJSON(returnData)
  478. return
  479. }
  480. func (this *SelfDrugApiController) DeleteDrugById() {
  481. id, _ := this.GetInt64("id")
  482. drug_name := this.GetString("drug_name")
  483. adminUserInfo := this.GetAdminUserInfo()
  484. orgId := adminUserInfo.CurrentOrgId
  485. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  486. if errcode == gorm.ErrRecordNotFound {
  487. service.DeleteDrugName(id)
  488. returnData := make(map[string]interface{}, 0)
  489. returnData["msg"] = "ok"
  490. this.ServeSuccessJSON(returnData)
  491. } else if errcode == nil {
  492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  493. return
  494. }
  495. }
  496. func (this *SelfDrugApiController) SaveRadio() {
  497. radio, _ := this.GetInt64("radio")
  498. adminUserInfo := this.GetAdminUserInfo()
  499. orgId := adminUserInfo.CurrentOrgId
  500. drugSet := models.XtDrugSet{
  501. DrugStart: radio,
  502. UserOrgId: orgId,
  503. Status: 1,
  504. CreatedTime: time.Now().Unix(),
  505. }
  506. _, errcode := service.GetDrugSetByUserOrgId(orgId)
  507. if errcode == gorm.ErrRecordNotFound {
  508. err := service.SaveRadio(&drugSet)
  509. if err != nil {
  510. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  511. return
  512. }
  513. this.ServeSuccessJSON(map[string]interface{}{
  514. "drugSet": drugSet,
  515. })
  516. } else if errcode == nil {
  517. err := service.UpdateDrugSet(&drugSet, orgId)
  518. if err != nil {
  519. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  520. return
  521. }
  522. this.ServeSuccessJSON(map[string]interface{}{
  523. "drugSet": drugSet,
  524. })
  525. }
  526. }
  527. func (this *SelfDrugApiController) DeleteDrugStand() {
  528. id, _ := this.GetInt64("id")
  529. name := this.GetString("name")
  530. adminUserInfo := this.GetAdminUserInfo()
  531. orgId := adminUserInfo.CurrentOrgId
  532. _, errcode := service.GetMedicalsByName(orgId, name)
  533. if errcode == gorm.ErrRecordNotFound {
  534. err := service.DeleteDrugStand(id)
  535. fmt.Println(err)
  536. returnData := make(map[string]interface{}, 0)
  537. returnData["msg"] = "ok"
  538. this.ServeSuccessJSON(returnData)
  539. } else if errcode == nil {
  540. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  541. return
  542. }
  543. }
  544. func (this *SelfDrugApiController) GetStockList() {
  545. patientid, _ := this.GetInt64("id")
  546. start_time := this.GetString("start_time")
  547. fmt.Println("开始时间", start_time)
  548. timeLayout := "2006-01-02"
  549. loc, _ := time.LoadLocation("Local")
  550. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  551. startimeUnix := theTime.Unix()
  552. keyword := this.GetString("keyword")
  553. fmt.Println("keyword", keyword)
  554. adminUserInfo := this.GetAdminUserInfo()
  555. orgId := adminUserInfo.CurrentOrgId
  556. //获取
  557. medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
  558. //统计总数量
  559. stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
  560. //统计出库数量
  561. outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
  562. //统计该病人时间段内出库条数
  563. outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
  564. if err != nil {
  565. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  566. return
  567. }
  568. this.ServeSuccessJSON(map[string]interface{}{
  569. "medicalList": medicalList,
  570. "stocklist": stocklist,
  571. "outStocklist": outStocklist,
  572. "outList": outList,
  573. })
  574. }
  575. func (this *SelfDrugApiController) DeleteDrugName() {
  576. drug_name := this.GetString("drugname")
  577. patient_id, _ := this.GetInt64("patientid")
  578. //查询该药品是否出库
  579. stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
  580. if len(stocklist) == 0 {
  581. //删除该药品
  582. service.DeleteDrugStockNumber(drug_name, patient_id)
  583. returnData := make(map[string]interface{}, 0)
  584. returnData["msg"] = "ok"
  585. this.ServeSuccessJSON(returnData)
  586. } else {
  587. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  588. return
  589. }
  590. }
  591. func (this *SelfDrugApiController) GetDrugDetail() {
  592. timeLayout := "2006-01-02"
  593. loc, _ := time.LoadLocation("Local")
  594. drug_name := this.GetString("drug_name")
  595. drug_spec := this.GetString("drug_spec")
  596. start_time := this.GetString("start_time")
  597. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  598. end_time := this.GetString("end_time")
  599. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  600. patient_id, _ := this.GetInt64("patient_id")
  601. adminUserInfo := this.GetAdminUserInfo()
  602. orgId := adminUserInfo.CurrentOrgId
  603. //查询入库明细
  604. stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  605. //查询出库明细
  606. outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  607. if err != nil {
  608. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  609. return
  610. }
  611. this.ServeSuccessJSON(map[string]interface{}{
  612. "stockDetail": stockDetail,
  613. "outStockDetail": outStockDetail,
  614. })
  615. }
  616. func (this *SelfDrugApiController) GetAllPatientStockList() {
  617. timeLayout := "2006-01-02"
  618. loc, _ := time.LoadLocation("Local")
  619. drug_name := this.GetString("drug_name")
  620. drug_spec := this.GetString("drug_spec")
  621. start_time := this.GetString("start_time")
  622. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  623. startUnix := theTime.Unix()
  624. end_time := this.GetString("end_time")
  625. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  626. endTimeUnix := endTimes.Unix()
  627. keywords := this.GetString("search_input")
  628. adminUserInfo := this.GetAdminUserInfo()
  629. orgId := adminUserInfo.CurrentOrgId
  630. //入库
  631. stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  632. //出库
  633. outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  634. if err != nil {
  635. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  636. return
  637. }
  638. this.ServeSuccessJSON(map[string]interface{}{
  639. "stocklist": stocklist,
  640. "outStockList": outStockList,
  641. })
  642. }
  643. func (this *SelfDrugApiController) GetDrugDataByPatientId() {
  644. patient_id, _ := this.GetInt64("patient_id")
  645. fmt.Println("patient_id", patient_id)
  646. medicalList, err := service.GetDrugDataByPatientId(patient_id)
  647. if err != nil {
  648. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  649. return
  650. }
  651. this.ServeSuccessJSON(map[string]interface{}{
  652. "medicalList": medicalList,
  653. })
  654. }
  655. func (this *SelfDrugApiController) GetSelfMedicalList() {
  656. patient_id, _ := this.GetInt64("patient_id")
  657. adminUserInfo := this.GetAdminUserInfo()
  658. orgId := adminUserInfo.CurrentOrgId
  659. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  660. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(orgId)
  661. drugList, _ := service.GetAllBaseDrugLibList(orgId)
  662. privateDrugList, _ := service.GetPrivateDrugList(patient_id, orgId)
  663. this.ServeSuccessJSON(map[string]interface{}{
  664. "base_drug_config": drugStockConfig,
  665. "private_drug_config": privateDrugConfig,
  666. "base_drug_list": drugList,
  667. "private_drug_list": privateDrugList,
  668. })
  669. ////查询是否开启药品库
  670. //config, _ := service.GetDruckStockConfig(orgId)
  671. //
  672. //fmt.Println("--------------------------",config.IsOpen)
  673. ////开启
  674. //if config.IsOpen == 1 {
  675. // //查询该机构下的药品库
  676. // drugName, _ := service.GetAllDrugName(orgId)
  677. //
  678. // //查询该机构是否开启自备药
  679. // medical, _ := service.GetSetSelfMedical(orgId)
  680. // fmt.Println("medical+++++++++++++++++",medical.DrugStart)
  681. // //开启
  682. // if medical.DrugStart == 1 {
  683. // list, err := service.GetSelfMedicalList(patient_id)
  684. // if err != nil {
  685. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  686. // return
  687. // }
  688. // this.ServeSuccessJSON(map[string]interface{}{
  689. // "medicalList": list,
  690. // "drugName": drugName,
  691. // })
  692. // } else {
  693. // this.ServeSuccessJSON(map[string]interface{}{
  694. // "drugName": drugName,
  695. // })
  696. // }
  697. //}
  698. }
  699. func (this *SelfDrugApiController) GetDrugDescByDrugName() {
  700. drug_name := this.GetString("drug_name")
  701. patient_id, _ := this.GetInt64("patient_id")
  702. way, _ := this.GetInt64("way")
  703. adminUserInfo := this.GetAdminUserInfo()
  704. orgId := adminUserInfo.CurrentOrgId
  705. drug_id, _ := this.GetInt64("id")
  706. //从基础库查询
  707. if way == 1 {
  708. //查询基础库数据
  709. medcal, err := service.GetBaseMedcal(drug_name, orgId)
  710. //统计入库数量
  711. countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
  712. //统计出库数量
  713. countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
  714. if err != nil {
  715. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  716. return
  717. }
  718. this.ServeSuccessJSON(map[string]interface{}{
  719. "drugspec": medcal,
  720. "countInfo": countInfo,
  721. "countout": countout,
  722. })
  723. }
  724. //从自备药库查询
  725. if way == 2 {
  726. drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
  727. if err != nil {
  728. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  729. return
  730. }
  731. this.ServeSuccessJSON(map[string]interface{}{
  732. "drugspec": drugspec,
  733. })
  734. }
  735. }
  736. func (this *SelfDrugApiController) GetDrugSet() {
  737. adminUserInfo := this.GetAdminUserInfo()
  738. orgId := adminUserInfo.CurrentOrgId
  739. drugSet, err := service.GetDrugSet(orgId)
  740. if err != nil {
  741. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  742. return
  743. }
  744. this.ServeSuccessJSON(map[string]interface{}{
  745. "drugSet": drugSet,
  746. })
  747. }
  748. func (this *SelfDrugApiController) GetAllMedicalList() {
  749. adminUserInfo := this.GetAdminUserInfo()
  750. orgId := adminUserInfo.CurrentOrgId
  751. list, err := service.GetAllMedicalList(orgId)
  752. if err != nil {
  753. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  754. return
  755. }
  756. this.ServeSuccessJSON(map[string]interface{}{
  757. "drugName": list,
  758. })
  759. }
  760. func (this *SelfDrugApiController) GetStandName() {
  761. name := this.GetString("name")
  762. adminUserInfo := this.GetAdminUserInfo()
  763. orgId := adminUserInfo.CurrentOrgId
  764. rullerlist, err := service.GetRulleName(orgId, name)
  765. if err != nil {
  766. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  767. return
  768. }
  769. this.ServeSuccessJSON(map[string]interface{}{
  770. "rullerlist": rullerlist,
  771. })
  772. }
  773. func (this *SelfDrugApiController) GetRullerList() {
  774. id, _ := this.GetInt64("id")
  775. adminUserInfo := this.GetAdminUserInfo()
  776. orgId := adminUserInfo.CurrentOrgId
  777. rullerList, err := service.GetRulleList(orgId, id)
  778. if err != nil {
  779. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  780. return
  781. }
  782. this.ServeSuccessJSON(map[string]interface{}{
  783. "rullerlist": rullerList,
  784. })
  785. }
  786. func (this *SelfDrugApiController) DeleteDrugNameById() {
  787. id, _ := this.GetInt64("id")
  788. drug_name := this.GetString("drug_name")
  789. adminUserInfo := this.GetAdminUserInfo()
  790. orgId := adminUserInfo.CurrentOrgId
  791. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  792. if errcode == gorm.ErrRecordNotFound {
  793. service.DeleteDrugNameById(id)
  794. returnData := make(map[string]interface{}, 0)
  795. returnData["msg"] = "ok"
  796. this.ServeSuccessJSON(returnData)
  797. } else if errcode == nil {
  798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  799. return
  800. }
  801. }
  802. func (this *SelfDrugApiController) GetPatientDetail() {
  803. id, _ := this.GetInt64("id")
  804. adminUserInfo := this.GetAdminUserInfo()
  805. patientDetail, err := service.GetPatientDetail(id, adminUserInfo.CurrentOrgId)
  806. if err != nil {
  807. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  808. return
  809. }
  810. this.ServeSuccessJSON(map[string]interface{}{
  811. "patientDetail": patientDetail,
  812. })
  813. }
  814. //func (this *SelfDrugApiController) ToPatientDetail() {
  815. //
  816. // keyword := this.GetString("keyword")
  817. // adminUser := this.GetAdminUserInfo()
  818. // orgId := adminUser.CurrentOrgId
  819. // patient, err := service.ToSeachPatient(keyword, orgId)
  820. // if err != nil {
  821. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  822. // return
  823. // }
  824. // this.ServeSuccessJSON(map[string]interface{}{
  825. // "patient": patient,
  826. // })
  827. //}
  828. func (this *SelfDrugApiController) GetSelfStockQuery() {
  829. adminUserInfo := this.GetAdminUserInfo()
  830. orgId := adminUserInfo.CurrentOrgId
  831. type_name, _ := this.GetInt64("type_name")
  832. keywords := this.GetString("keywords")
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. start_time := this.GetString("start_time")
  836. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  837. startUnix := theTime.Unix()
  838. end_time := this.GetString("end_time")
  839. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  840. endTimeUnix := endTimes.Unix()
  841. page, _ := this.GetInt64("page")
  842. limit, _ := this.GetInt64("limit")
  843. //统计入库数量
  844. stockQuery, total, err := service.GetSelfStockQuery(type_name, keywords, startUnix, endTimeUnix, orgId, limit, page)
  845. //统计出库数量
  846. stockOutQuery, err := service.GetSelfOutStockQuery(startUnix, endTimeUnix, orgId)
  847. if err != nil {
  848. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  849. return
  850. }
  851. this.ServeSuccessJSON(map[string]interface{}{
  852. "stockQuery": stockQuery,
  853. "total": total,
  854. "stockOutQuery": stockOutQuery,
  855. })
  856. }
  857. func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
  858. keyword := this.GetString("keyword")
  859. storehouse_id, _ := this.GetInt64("storehouse_id")
  860. orgId := this.GetAdminUserInfo().CurrentOrgId
  861. list, err := service.PostSearchDrugWarehouseList(keyword, orgId, storehouse_id)
  862. manufacturerList, err := service.GetAllManufacturerList(orgId)
  863. dealerList, err := service.GetAllDealerList(orgId)
  864. if err != nil {
  865. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  866. return
  867. }
  868. this.ServeSuccessJSON(map[string]interface{}{
  869. "list": list,
  870. "manufacturerList": manufacturerList,
  871. "dealerList": dealerList,
  872. })
  873. }
  874. func (this *SelfDrugApiController) SaveDrugPrice() {
  875. timeLayout := "2006-01-02"
  876. loc, _ := time.LoadLocation("Local")
  877. dataBody := make(map[string]interface{}, 0)
  878. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  879. fmt.Println(err)
  880. tableData, _ := dataBody["tableData"].([]interface{})
  881. fmt.Println("999939433443", tableData)
  882. if len(tableData) > 0 {
  883. for _, item := range tableData {
  884. items := item.(map[string]interface{})
  885. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  886. utils.ErrorLog("drug_name")
  887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  888. return
  889. }
  890. drug_name := items["drug_name"].(string)
  891. fmt.Println("drug_aname23232323232", drug_name)
  892. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  893. utils.ErrorLog("drug_name")
  894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  895. return
  896. }
  897. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  898. utils.ErrorLog("retail_price")
  899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  900. return
  901. }
  902. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  903. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  904. utils.ErrorLog("warehousing_order")
  905. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  906. return
  907. }
  908. warehousing_order := items["warehousing_order"].(string)
  909. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  910. utils.ErrorLog("number")
  911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  912. return
  913. }
  914. number := items["number"].(string)
  915. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  916. utils.ErrorLog("dealer")
  917. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  918. return
  919. }
  920. dealer := items["dealer"].(string)
  921. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  922. utils.ErrorLog("manufacturer")
  923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  924. return
  925. }
  926. manufacturer := items["manufacturer"].(string)
  927. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  928. utils.ErrorLog("specification_name")
  929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  930. return
  931. }
  932. specification_name := items["specification_name"].(string)
  933. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  934. utils.ErrorLog("remark")
  935. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  936. return
  937. }
  938. remark := items["remark"].(string)
  939. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  940. utils.ErrorLog("warehousing_unit")
  941. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  942. return
  943. }
  944. warehousing_unit := items["warehousing_unit"].(string)
  945. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  946. utils.ErrorLog("last_price")
  947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  948. return
  949. }
  950. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  951. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  952. utils.ErrorLog("new_price")
  953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  954. return
  955. }
  956. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  957. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  958. utils.ErrorLog("drug_id")
  959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  960. return
  961. }
  962. drug_id := int64(items["drug_id"].(float64))
  963. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  964. utils.ErrorLog("start_time")
  965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  966. return
  967. }
  968. var startTime int64
  969. start_time := items["start_time"].(string)
  970. if len(start_time) > 0 {
  971. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  972. if err != nil {
  973. fmt.Println(err)
  974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  975. return
  976. }
  977. startTime = theTime.Unix()
  978. }
  979. orgId := this.GetAdminUserInfo().CurrentOrgId
  980. Creater := this.GetAdminUserInfo().AdminUser.Id
  981. drugAdjust := models.XtDrugAdjustPrice{
  982. DrugName: drug_name,
  983. SpecificationName: specification_name,
  984. WarehousingUnit: warehousing_unit,
  985. LastPrice: last_price,
  986. RetailPrice: retail_price,
  987. NewPrice: new_price,
  988. Manufacturer: manufacturer,
  989. Dealer: dealer,
  990. Remark: remark,
  991. DrugId: drug_id,
  992. UserOrgId: orgId,
  993. Ctime: time.Now().Unix(),
  994. Mtime: 0,
  995. Status: 1,
  996. WarehousingOrder: warehousing_order,
  997. Number: number,
  998. StartTime: startTime,
  999. Creater: Creater,
  1000. Checker: 0,
  1001. CheckerStatus: 2,
  1002. CheckerTime: 0,
  1003. }
  1004. err := service.CreateDrugPrice(drugAdjust)
  1005. fmt.Println(err)
  1006. }
  1007. }
  1008. returnData := make(map[string]interface{}, 0)
  1009. returnData["msg"] = "ok"
  1010. this.ServeSuccessJSON(returnData)
  1011. return
  1012. }
  1013. func (this *SelfDrugApiController) GetDrugPriceList() {
  1014. timeLayout := "2006-01-02"
  1015. loc, _ := time.LoadLocation("Local")
  1016. dataBody := make(map[string]interface{}, 0)
  1017. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1018. fmt.Println(err)
  1019. orgId := this.GetAdminUserInfo().CurrentOrgId
  1020. keyword := this.GetString("keyword")
  1021. start_time := this.GetString("start_time")
  1022. end_time := this.GetString("end_time")
  1023. var startTime int64
  1024. if len(start_time) > 0 {
  1025. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1026. if err != nil {
  1027. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1028. return
  1029. }
  1030. startTime = theTime.Unix()
  1031. }
  1032. var endTime int64
  1033. if len(end_time) > 0 {
  1034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1035. if err != nil {
  1036. utils.ErrorLog(err.Error())
  1037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1038. return
  1039. }
  1040. endTime = theTime.Unix()
  1041. }
  1042. limit, _ := this.GetInt64("limit")
  1043. page, _ := this.GetInt64("page")
  1044. list, total, err := service.GetDrugPriceList(startTime, endTime, orgId, keyword, limit, page)
  1045. doctorList, err := service.GetAllDoctorThree(orgId)
  1046. if err != nil {
  1047. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1048. return
  1049. }
  1050. this.ServeSuccessJSON(map[string]interface{}{
  1051. "total": total,
  1052. "list": list,
  1053. "doctorList": doctorList,
  1054. })
  1055. }
  1056. func (this *SelfDrugApiController) SaveCheckDrugPrice() {
  1057. timeLayout := "2006-01-02"
  1058. loc, _ := time.LoadLocation("Local")
  1059. dataBody := make(map[string]interface{}, 0)
  1060. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1061. fmt.Println(err)
  1062. idstr := this.GetString("ids")
  1063. ids := strings.Split(idstr, ",")
  1064. check_time := this.GetString("check_time")
  1065. var checkTime int64
  1066. if len(check_time) > 0 {
  1067. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1068. if err != nil {
  1069. fmt.Println(err)
  1070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1071. return
  1072. }
  1073. checkTime = theTime.Unix()
  1074. }
  1075. checker, _ := this.GetInt64("checker")
  1076. adjustPrice := models.XtDrugAdjustPrice{
  1077. Checker: checker,
  1078. CheckerStatus: 1,
  1079. CheckerTime: checkTime,
  1080. }
  1081. err = service.UpdateDrugAdjuestPrice(ids, adjustPrice)
  1082. fmt.Println("err", err)
  1083. list, _ := service.GetDrugAdjuestPrice(ids)
  1084. for _, item := range list {
  1085. drug := models.BaseDrugLib{
  1086. RetailPrice: item.NewPrice,
  1087. LastPrice: item.NewPrice,
  1088. }
  1089. service.UpdateBaseDrugOne(drug, item.DrugId)
  1090. }
  1091. this.ServeSuccessJSON(map[string]interface{}{
  1092. "adjustPrice": adjustPrice,
  1093. })
  1094. }
  1095. func (this *SelfDrugApiController) SaveDrugDamage() {
  1096. timeLayout := "2006-01-02"
  1097. loc, _ := time.LoadLocation("Local")
  1098. dataBody := make(map[string]interface{}, 0)
  1099. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1100. fmt.Println(err)
  1101. tableData, _ := dataBody["tableData"].([]interface{})
  1102. fmt.Println("999939433443", tableData)
  1103. if len(tableData) > 0 {
  1104. for _, item := range tableData {
  1105. items := item.(map[string]interface{})
  1106. drug_name := items["drug_name"].(string)
  1107. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1108. utils.ErrorLog("drug_name")
  1109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. return
  1111. }
  1112. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1113. utils.ErrorLog("retail_price")
  1114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1115. return
  1116. }
  1117. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1118. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1119. utils.ErrorLog("warehousing_order")
  1120. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1121. return
  1122. }
  1123. warehousing_order := items["warehousing_order"].(string)
  1124. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1125. utils.ErrorLog("number")
  1126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1127. return
  1128. }
  1129. number := items["number"].(string)
  1130. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1131. utils.ErrorLog("dealer")
  1132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1133. return
  1134. }
  1135. dealer := items["dealer"].(string)
  1136. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1137. utils.ErrorLog("manufacturer")
  1138. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1139. return
  1140. }
  1141. manufacturer := items["manufacturer"].(string)
  1142. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1143. utils.ErrorLog("specification_name")
  1144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1145. return
  1146. }
  1147. specification_name := items["specification_name"].(string)
  1148. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1149. utils.ErrorLog("remark")
  1150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1151. return
  1152. }
  1153. remark := items["remark"].(string)
  1154. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1155. utils.ErrorLog("warehousing_unit")
  1156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1157. return
  1158. }
  1159. warehousing_unit := items["warehousing_unit"].(string)
  1160. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1161. utils.ErrorLog("last_price")
  1162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1163. return
  1164. }
  1165. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1166. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1167. utils.ErrorLog("count")
  1168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1169. return
  1170. }
  1171. count := int64(items["count"].(float64))
  1172. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1173. utils.ErrorLog("new_price")
  1174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1175. return
  1176. }
  1177. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1178. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1179. utils.ErrorLog("drug_id")
  1180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1181. return
  1182. }
  1183. drug_id := int64(items["drug_id"].(float64))
  1184. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1185. utils.ErrorLog("start_time")
  1186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1187. return
  1188. }
  1189. var startTime int64
  1190. start_time := items["start_time"].(string)
  1191. if len(start_time) > 0 {
  1192. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1193. if err != nil {
  1194. fmt.Println(err)
  1195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1196. return
  1197. }
  1198. startTime = theTime.Unix()
  1199. }
  1200. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  1201. utils.ErrorLog("warehousing_info_id")
  1202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  1206. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1207. utils.ErrorLog("expiry_date")
  1208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1209. return
  1210. }
  1211. expiry_date := int64(items["expiry_date"].(float64))
  1212. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1213. utils.ErrorLog("product_date")
  1214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1215. return
  1216. }
  1217. product_date := int64(items["product_date"].(float64))
  1218. if items["drug_origin_place"] == nil || reflect.TypeOf(items["drug_origin_place"]).String() != "string" {
  1219. utils.ErrorLog("drug_origin_place")
  1220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1221. return
  1222. }
  1223. drug_origin_place := items["drug_origin_place"].(string)
  1224. orgId := this.GetAdminUserInfo().CurrentOrgId
  1225. Creater := this.GetAdminUserInfo().AdminUser.Id
  1226. if items["stock_max_number"] == nil || reflect.TypeOf(items["stock_max_number"]).String() != "float64" {
  1227. utils.ErrorLog("stock_max_number")
  1228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1229. return
  1230. }
  1231. stock_max_number := int64(items["stock_max_number"].(float64))
  1232. if items["stock_min_number"] == nil || reflect.TypeOf(items["stock_min_number"]).String() != "float64" {
  1233. utils.ErrorLog("stock_min_number")
  1234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1235. return
  1236. }
  1237. stock_min_number := int64(items["stock_min_number"].(float64))
  1238. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1239. utils.ErrorLog("total")
  1240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1241. return
  1242. }
  1243. total := items["total"].(string)
  1244. drugDamage := models.XtDrugDamage{
  1245. DrugName: drug_name,
  1246. SpecificationName: specification_name,
  1247. WarehousingUnit: warehousing_unit,
  1248. Count: count,
  1249. LastPrice: last_price,
  1250. RetailPrice: retail_price,
  1251. NewPrice: new_price,
  1252. Manufacturer: manufacturer,
  1253. Dealer: dealer,
  1254. Remark: remark,
  1255. DrugId: drug_id,
  1256. UserOrgId: orgId,
  1257. Ctime: time.Now().Unix(),
  1258. Mtime: 0,
  1259. Status: 1,
  1260. WarehousingOrder: warehousing_order,
  1261. Number: number,
  1262. StartTime: startTime,
  1263. Creater: Creater,
  1264. Checker: 0,
  1265. CheckerStatus: 2,
  1266. CheckerTime: 0,
  1267. ExpiryDate: expiry_date,
  1268. ProductDate: product_date,
  1269. WarehousingInfoId: warehousing_info_id,
  1270. DrugOriginPlace: drug_origin_place,
  1271. StockMaxNumber: stock_max_number,
  1272. StockMinNumber: stock_min_number,
  1273. Total: total,
  1274. }
  1275. err := service.CreateDrugDamage(drugDamage)
  1276. fmt.Println(err)
  1277. }
  1278. }
  1279. returnData := make(map[string]interface{}, 0)
  1280. returnData["msg"] = "ok"
  1281. this.ServeSuccessJSON(returnData)
  1282. }
  1283. func (this *SelfDrugApiController) GetDrugDamageList() {
  1284. timeLayout := "2006-01-02"
  1285. loc, _ := time.LoadLocation("Local")
  1286. dataBody := make(map[string]interface{}, 0)
  1287. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1288. fmt.Println(err)
  1289. orgId := this.GetAdminUserInfo().CurrentOrgId
  1290. keyword := this.GetString("keyword")
  1291. start_time := this.GetString("start_time")
  1292. end_time := this.GetString("end_time")
  1293. storehouse_id, _ := this.GetInt64("storehouse_id")
  1294. var startTime int64
  1295. if len(start_time) > 0 {
  1296. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1297. if err != nil {
  1298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1299. return
  1300. }
  1301. startTime = theTime.Unix()
  1302. }
  1303. var endTime int64
  1304. if len(end_time) > 0 {
  1305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1306. if err != nil {
  1307. utils.ErrorLog(err.Error())
  1308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1309. return
  1310. }
  1311. endTime = theTime.Unix()
  1312. }
  1313. limit, _ := this.GetInt64("limit")
  1314. page, _ := this.GetInt64("page")
  1315. list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page, storehouse_id)
  1316. damagelist, _ := service.GetDrugDamageByOrgId(orgId)
  1317. doctorList, err := service.GetAllDoctorThree(orgId)
  1318. houseList, _ := service.GetAllStoreHouseList(orgId)
  1319. if err != nil {
  1320. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1321. return
  1322. }
  1323. this.ServeSuccessJSON(map[string]interface{}{
  1324. "total": total,
  1325. "list": list,
  1326. "damagelist": damagelist,
  1327. "doctorList": doctorList,
  1328. "houseList": houseList,
  1329. })
  1330. }
  1331. func (this *SelfDrugApiController) SaveDrugDamagePrice() {
  1332. timeLayout := "2006-01-02"
  1333. loc, _ := time.LoadLocation("Local")
  1334. dataBody := make(map[string]interface{}, 0)
  1335. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1336. fmt.Println(err)
  1337. idstr := this.GetString("ids")
  1338. ids := strings.Split(idstr, ",")
  1339. check_time := this.GetString("check_time")
  1340. var checkTime int64
  1341. if len(check_time) > 0 {
  1342. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1343. if err != nil {
  1344. fmt.Println(err)
  1345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1346. return
  1347. }
  1348. checkTime = theTime.Unix()
  1349. }
  1350. checker, _ := this.GetInt64("checker")
  1351. damage := models.XtDrugDamage{
  1352. Checker: checker,
  1353. CheckerStatus: 1,
  1354. CheckerTime: checkTime,
  1355. }
  1356. err = service.UpdateDrugDamage(ids, damage)
  1357. fmt.Println(err)
  1358. list, _ := service.GetDrugDamage(ids)
  1359. ctime := time.Now().Unix()
  1360. adminUserInfo := this.GetAdminUserInfo()
  1361. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1362. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  1363. var manufacturer_id int64
  1364. var dealer_id int64
  1365. timeStr := time.Now().Format("2006-01-02")
  1366. timeArr := strings.Split(timeStr, "-")
  1367. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1368. total = total + 1
  1369. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1370. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1371. number = number + total
  1372. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1373. operation_time := time.Now().Unix()
  1374. creater := adminUserInfo.AdminUser.Id
  1375. warehouseOut := models.DrugWarehouseOut{
  1376. WarehouseOutOrderNumber: warehousing_out_order,
  1377. OperationTime: operation_time,
  1378. OrgId: adminUserInfo.CurrentOrgId,
  1379. Creater: creater,
  1380. Ctime: ctime,
  1381. Status: 1,
  1382. WarehouseOutTime: time.Now().Unix(),
  1383. Type: 1,
  1384. }
  1385. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1386. for _, item := range list {
  1387. for _, it := range manufacturerList {
  1388. if item.Manufacturer == it.ManufacturerName {
  1389. manufacturer_id = it.ID
  1390. }
  1391. }
  1392. for _, its := range dealerList {
  1393. if its.DealerName == item.Dealer {
  1394. dealer_id = its.ID
  1395. }
  1396. }
  1397. warehouseOutInfo := models.XtDrugWarehouseOutInfo{
  1398. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1399. WarehouseOutId: warehouseOut.ID,
  1400. DrugId: item.DrugId,
  1401. Count: item.Count,
  1402. Price: item.RetailPrice,
  1403. Status: 1,
  1404. Ctime: ctime,
  1405. Remark: item.Remark,
  1406. OrgId: adminUserInfo.CurrentOrgId,
  1407. Type: 1,
  1408. Manufacturer: manufacturer_id,
  1409. Dealer: dealer_id,
  1410. RetailPrice: item.RetailPrice,
  1411. CountUnit: item.WarehousingUnit,
  1412. ExpiryDate: item.ExpiryDate,
  1413. ProductDate: item.ProductDate,
  1414. Number: item.Number,
  1415. BatchNumber: item.BatchNumber,
  1416. IsSys: 0,
  1417. WarehouseInfoId: item.WarehousingInfoId,
  1418. }
  1419. drugflow := models.DrugFlow{
  1420. WarehouseOutId: warehouseOut.ID,
  1421. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1422. DrugId: item.DrugId,
  1423. Number: item.Number,
  1424. ProductDate: item.ProductDate,
  1425. ExpireDate: item.ExpiryDate,
  1426. Count: item.Count,
  1427. Price: item.RetailPrice,
  1428. Status: 1,
  1429. Ctime: ctime,
  1430. UserOrgId: adminUserInfo.CurrentOrgId,
  1431. Manufacturer: manufacturer_id,
  1432. Dealer: dealer_id,
  1433. BatchNumber: item.BatchNumber,
  1434. MaxUnit: item.WarehousingUnit,
  1435. ConsumableType: 5,
  1436. IsEdit: 1,
  1437. Creator: adminUserInfo.AdminUser.Id,
  1438. IsSys: 0,
  1439. }
  1440. service.CreateWareHouseOutInfo(&warehouseOutInfo)
  1441. service.CreateDrugFlowOne(drugflow)
  1442. info, _ := service.GetDrugByWarehouseInfo(item.WarehousingInfoId)
  1443. //扣减库存
  1444. warehouseInfo := models.XtDrugWarehouseInfo{
  1445. StockMaxNumber: info.StockMaxNumber - info.StockMaxNumber,
  1446. }
  1447. service.UpdateDrugWarehouseingInfo(item.WarehousingInfoId, warehouseInfo)
  1448. }
  1449. this.ServeSuccessJSON(map[string]interface{}{
  1450. "damage": damage,
  1451. })
  1452. }
  1453. func (this *SelfDrugApiController) GetDrugModifyPrice() {
  1454. id, _ := this.GetInt64("id")
  1455. detail, err := service.GetDrugModifyPrice(id)
  1456. fmt.Println(err)
  1457. this.ServeSuccessJSON(map[string]interface{}{
  1458. "detail": detail,
  1459. })
  1460. }
  1461. func (this *SelfDrugApiController) ModifyDrugPrice() {
  1462. drug_name := this.GetString("drug_name")
  1463. specification_name := this.GetString("specification_name")
  1464. warehousing_unit := this.GetString("warehousing_unit")
  1465. manufacturer := this.GetString("manufacturer")
  1466. number := this.GetString("number")
  1467. retailPrice := this.GetString("retail_price")
  1468. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1469. newPrice := this.GetString("new_price")
  1470. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1471. count, _ := this.GetInt64("count")
  1472. remark := this.GetString("remark")
  1473. id, _ := this.GetInt64("id")
  1474. drug_id, _ := this.GetInt64("drug_id")
  1475. adjustPrice := models.XtDrugAdjustPrice{
  1476. DrugName: drug_name,
  1477. Count: count,
  1478. RetailPrice: retail_price,
  1479. NewPrice: new_price,
  1480. Remark: remark,
  1481. SpecificationName: specification_name,
  1482. WarehousingUnit: warehousing_unit,
  1483. Manufacturer: manufacturer,
  1484. Number: number,
  1485. DrugId: drug_id,
  1486. }
  1487. err := service.ModifyDrugPrice(id, adjustPrice)
  1488. fmt.Println(err)
  1489. this.ServeSuccessJSON(map[string]interface{}{
  1490. "adjustPrice": adjustPrice,
  1491. })
  1492. }
  1493. func (this *SelfDrugApiController) GetModifyPricePrint() {
  1494. ids := this.GetString("ids")
  1495. idsSplit := strings.Split(ids, ",")
  1496. list, err := service.GetModifyPricePrint(idsSplit)
  1497. fmt.Println(err)
  1498. this.ServeSuccessJSON(map[string]interface{}{
  1499. "list": list,
  1500. })
  1501. }
  1502. func (this *SelfDrugApiController) GetDrugDamageDetail() {
  1503. id, _ := this.GetInt64("id")
  1504. detail, _ := service.GetDrugDamageDetail(id)
  1505. this.ServeSuccessJSON(map[string]interface{}{
  1506. "detail": detail,
  1507. })
  1508. }
  1509. func (this *SelfDrugApiController) ModifyDrugDamage() {
  1510. id, _ := this.GetInt64("id")
  1511. drug_id, _ := this.GetInt64("drug_id")
  1512. drug_name := this.GetString("drug_name")
  1513. drug_origin_place := this.GetString("drug_origin_place")
  1514. lastPrice := this.GetString("last_price")
  1515. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  1516. newPrice := this.GetString("new_price")
  1517. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1518. manufacturer := this.GetString("manufacturer")
  1519. number := this.GetString("number")
  1520. retailPrice := this.GetString("retail_price")
  1521. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1522. remark := this.GetString("remark")
  1523. count, _ := this.GetInt64("count")
  1524. warehousing_unit := this.GetString("warehousing_unit")
  1525. stock_max_number, _ := this.GetInt64("stock_max_number")
  1526. stock_min_number, _ := this.GetInt64("stock_min_number")
  1527. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  1528. damage := models.XtDrugDamage{
  1529. DrugName: drug_name,
  1530. SpecificationName: "",
  1531. WarehousingUnit: warehousing_unit,
  1532. Count: count,
  1533. LastPrice: last_price,
  1534. RetailPrice: retail_price,
  1535. NewPrice: new_price,
  1536. Manufacturer: manufacturer,
  1537. Dealer: "",
  1538. Remark: remark,
  1539. DrugId: drug_id,
  1540. Number: number,
  1541. StockMaxNumber: stock_max_number,
  1542. StockMinNumber: stock_min_number,
  1543. WarehousingInfoId: warehousing_info_id,
  1544. DrugOriginPlace: drug_origin_place,
  1545. }
  1546. err := service.ModifyDrugDamage(id, damage)
  1547. fmt.Println(err)
  1548. this.ServeSuccessJSON(map[string]interface{}{
  1549. "damage": damage,
  1550. })
  1551. }
  1552. func (this *SelfDrugApiController) DeleteDrugDamage() {
  1553. id, _ := this.GetInt64("id")
  1554. err := service.DeleteDrugDamage(id)
  1555. fmt.Println(err)
  1556. returnData := make(map[string]interface{}, 0)
  1557. returnData["msg"] = "ok"
  1558. this.ServeSuccessJSON(returnData)
  1559. }
  1560. func (this *SelfDrugApiController) GetDrugDamagePrint() {
  1561. idsSplit := this.GetString("ids")
  1562. ids := strings.Split(idsSplit, ",")
  1563. list, _ := service.GetDrugDamagePrint(ids)
  1564. this.ServeSuccessJSON(map[string]interface{}{
  1565. "list": list,
  1566. })
  1567. }
  1568. func (this *SelfDrugApiController) GetWarehoseInfoById() {
  1569. id, _ := this.GetInt64("id")
  1570. storehouse_id, _ := this.GetInt64("storehouse_id")
  1571. list, _ := service.GetWarehoseInfoById(id, storehouse_id)
  1572. this.ServeSuccessJSON(map[string]interface{}{
  1573. "list": list,
  1574. })
  1575. }
  1576. func (this *SelfDrugApiController) SaveDrugInventory() {
  1577. timeLayout := "2006-01-02"
  1578. loc, _ := time.LoadLocation("Local")
  1579. dataBody := make(map[string]interface{}, 0)
  1580. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1581. fmt.Println(err)
  1582. tableData, _ := dataBody["tableData"].([]interface{})
  1583. fmt.Println("999939433443", tableData)
  1584. if len(tableData) > 0 {
  1585. for _, item := range tableData {
  1586. items := item.(map[string]interface{})
  1587. drug_name := items["drug_name"].(string)
  1588. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1589. utils.ErrorLog("drug_name")
  1590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1594. utils.ErrorLog("retail_price")
  1595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1596. return
  1597. }
  1598. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1599. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1600. utils.ErrorLog("warehousing_order")
  1601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1602. return
  1603. }
  1604. warehousing_order := items["warehousing_order"].(string)
  1605. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1606. utils.ErrorLog("dealer")
  1607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1608. return
  1609. }
  1610. dealer := items["dealer"].(string)
  1611. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1612. utils.ErrorLog("manufacturer")
  1613. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1614. return
  1615. }
  1616. manufacturer := items["manufacturer"].(string)
  1617. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1618. utils.ErrorLog("specification_name")
  1619. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1620. return
  1621. }
  1622. specification_name := items["specification_name"].(string)
  1623. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1624. utils.ErrorLog("remark")
  1625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1626. return
  1627. }
  1628. remark := items["remark"].(string)
  1629. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1630. utils.ErrorLog("warehousing_unit")
  1631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1632. return
  1633. }
  1634. warehousing_unit := items["warehousing_unit"].(string)
  1635. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1636. utils.ErrorLog("last_price")
  1637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1641. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1642. utils.ErrorLog("count")
  1643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. return
  1645. }
  1646. count := int64(items["count"].(float64))
  1647. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1648. utils.ErrorLog("new_price")
  1649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1650. return
  1651. }
  1652. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1653. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1654. utils.ErrorLog("drug_id")
  1655. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. drug_id := int64(items["drug_id"].(float64))
  1659. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1660. utils.ErrorLog("start_time")
  1661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1662. return
  1663. }
  1664. var startTime int64
  1665. start_time := items["start_time"].(string)
  1666. if len(start_time) > 0 {
  1667. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1668. if err != nil {
  1669. fmt.Println(err)
  1670. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1671. return
  1672. }
  1673. startTime = theTime.Unix()
  1674. }
  1675. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1676. utils.ErrorLog("product_date")
  1677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1678. return
  1679. }
  1680. product_date := int64(items["product_date"].(float64))
  1681. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1682. utils.ErrorLog("expiry_date")
  1683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1684. return
  1685. }
  1686. expiry_date := int64(items["expiry_date"].(float64))
  1687. orgId := this.GetAdminUserInfo().CurrentOrgId
  1688. Creater := this.GetAdminUserInfo().AdminUser.Id
  1689. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1690. utils.ErrorLog("number")
  1691. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1692. return
  1693. }
  1694. numbers := items["number"].(string)
  1695. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1696. utils.ErrorLog("warehouse_info_id")
  1697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1698. return
  1699. }
  1700. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1701. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1702. utils.ErrorLog("total")
  1703. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1704. return
  1705. }
  1706. total := items["total"].(string)
  1707. drug_origin_place := items["drug_origin_place"].(string)
  1708. min_count := int64(items["min_count"].(float64))
  1709. min_unit := items["min_unit"].(string)
  1710. inventory := models.XtDrugInventory{
  1711. DrugName: drug_name,
  1712. SpecificationName: specification_name,
  1713. WarehousingUnit: warehousing_unit,
  1714. Count: count,
  1715. LastPrice: last_price,
  1716. RetailPrice: retail_price,
  1717. NewPrice: new_price,
  1718. Manufacturer: manufacturer,
  1719. Dealer: dealer,
  1720. Remark: remark,
  1721. DrugId: drug_id,
  1722. UserOrgId: orgId,
  1723. Ctime: time.Now().Unix(),
  1724. Mtime: 0,
  1725. Status: 1,
  1726. WarehousingOrder: warehousing_order,
  1727. LicenseNumber: "",
  1728. StartTime: startTime,
  1729. Creater: Creater,
  1730. Checker: 0,
  1731. CheckerStatus: 2,
  1732. CheckerTime: 0,
  1733. ExpiryDate: expiry_date,
  1734. ProductDate: product_date,
  1735. Number: numbers,
  1736. //BatchNumber: batch_number,
  1737. Total: total,
  1738. WarehouseInfoId: warehouse_info_id,
  1739. DrugOriginPlace: drug_origin_place,
  1740. MinUnit: min_unit,
  1741. MinCount: min_count,
  1742. }
  1743. err = service.CreateDrugInventory(inventory)
  1744. fmt.Println(err)
  1745. }
  1746. }
  1747. this.ServeSuccessJSON(map[string]interface{}{
  1748. "msg": "msg",
  1749. })
  1750. }
  1751. func (this *SelfDrugApiController) GetDrugInventoryList() {
  1752. timeLayout := "2006-01-02"
  1753. loc, _ := time.LoadLocation("Local")
  1754. dataBody := make(map[string]interface{}, 0)
  1755. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1756. fmt.Println(err)
  1757. orgId := this.GetAdminUserInfo().CurrentOrgId
  1758. keyword := this.GetString("keyword")
  1759. start_time := this.GetString("start_time")
  1760. end_time := this.GetString("end_time")
  1761. var startTime int64
  1762. if len(start_time) > 0 {
  1763. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1764. if err != nil {
  1765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1766. return
  1767. }
  1768. startTime = theTime.Unix()
  1769. }
  1770. var endTime int64
  1771. if len(end_time) > 0 {
  1772. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1773. if err != nil {
  1774. utils.ErrorLog(err.Error())
  1775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1776. return
  1777. }
  1778. endTime = theTime.Unix()
  1779. }
  1780. limit, _ := this.GetInt64("limit")
  1781. page, _ := this.GetInt64("page")
  1782. list, total, err := service.GetDrugInventoryList(keyword, page, limit, orgId, startTime, endTime)
  1783. doctorList, _ := service.GetAllDoctorThree(orgId)
  1784. houseList, _ := service.GetAllStoreHouseList(orgId)
  1785. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1786. if err != nil {
  1787. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1788. return
  1789. }
  1790. this.ServeSuccessJSON(map[string]interface{}{
  1791. "total": total,
  1792. "list": list,
  1793. "doctorList": doctorList,
  1794. "houseList": houseList,
  1795. "houseConfig": houseConfig,
  1796. })
  1797. }
  1798. func (this *SelfDrugApiController) SaveDrugCheckInventory() {
  1799. timeLayout := "2006-01-02"
  1800. loc, _ := time.LoadLocation("Local")
  1801. dataBody := make(map[string]interface{}, 0)
  1802. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1803. fmt.Println(err)
  1804. idstr := this.GetString("ids")
  1805. ids := strings.Split(idstr, ",")
  1806. check_time := this.GetString("check_time")
  1807. var checkTime int64
  1808. if len(check_time) > 0 {
  1809. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1810. if err != nil {
  1811. fmt.Println(err)
  1812. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1813. return
  1814. }
  1815. checkTime = theTime.Unix()
  1816. }
  1817. checker, _ := this.GetInt64("checker")
  1818. inventory := models.XtDrugInventory{
  1819. Checker: checker,
  1820. CheckerStatus: 1,
  1821. CheckerTime: checkTime,
  1822. }
  1823. err = service.UpdateDrugInventory(ids, inventory)
  1824. fmt.Println(err)
  1825. list, _ := service.GetDrugInventoryListByIds(ids)
  1826. adminUserInfo := this.GetAdminUserInfo()
  1827. var stock_total int64
  1828. var proof_count int64
  1829. var maxNumber int64
  1830. var minNumber int64
  1831. for _, item := range list {
  1832. //查询药品信息
  1833. drug, _ := service.GetDrugDetailByDrugId(item.DrugId)
  1834. //查询库存
  1835. info, _ := service.GetDrugWareInfoByIdTwo(item.WarehouseInfoId)
  1836. var max_count int64
  1837. var min_count int64
  1838. for _, it := range info {
  1839. max_count += it.StockMaxNumber
  1840. min_count += it.StockMinNumber
  1841. }
  1842. //获取最晚的库存数量
  1843. lastInfo, _ := service.GetLastDrugWarehouseInfo(item.DrugId)
  1844. firstInfo, _ := service.GetFirstDrugWarehouseInfo(item.DrugId)
  1845. stock_total = max_count*drug.MinNumber + min_count
  1846. proof_count = item.Count*drug.MinNumber + item.MinCount
  1847. fmt.Println("stock_total", stock_total)
  1848. fmt.Println("proof_count", proof_count)
  1849. //判断 如果库存数量 大于盘点库存,则出库
  1850. if stock_total > proof_count {
  1851. minNumber = (stock_total - proof_count) % drug.MinNumber
  1852. maxNumber = (stock_total - proof_count) / drug.MinNumber
  1853. ctime := time.Now().Unix()
  1854. timeStr := time.Now().Format("2006-01-02")
  1855. timeArr := strings.Split(timeStr, "-")
  1856. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1857. total = total + 1
  1858. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1859. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1860. number = number + total
  1861. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1862. operation_time := time.Now().Unix()
  1863. creater := adminUserInfo.AdminUser.Id
  1864. warehouseOut := models.DrugWarehouseOut{
  1865. WarehouseOutOrderNumber: warehousing_out_order,
  1866. OperationTime: operation_time,
  1867. OrgId: adminUserInfo.CurrentOrgId,
  1868. Creater: creater,
  1869. Ctime: ctime,
  1870. Status: 1,
  1871. WarehouseOutTime: ctime,
  1872. Type: 1,
  1873. }
  1874. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1875. warehouse, _ := service.GetLastDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1876. warehouseOutInfo := models.DrugWarehouseOutInfo{
  1877. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1878. WarehouseOutId: warehouse.ID,
  1879. DrugId: item.DrugId,
  1880. Count: maxNumber,
  1881. Price: firstInfo.Price,
  1882. TotalPrice: firstInfo.TotalPrice,
  1883. Status: 1,
  1884. Ctime: ctime,
  1885. Remark: item.Remark,
  1886. OrgId: adminUserInfo.CurrentOrgId,
  1887. Type: 1,
  1888. Manufacturer: firstInfo.Manufacturer,
  1889. Dealer: firstInfo.Dealer,
  1890. RetailPrice: firstInfo.RetailPrice,
  1891. RetailTotalPrice: firstInfo.RetailTotalPrice,
  1892. CountUnit: drug.MaxUnit,
  1893. ExpiryDate: firstInfo.ExpiryDate,
  1894. ProductDate: firstInfo.ProductDate,
  1895. Number: firstInfo.Number,
  1896. BatchNumber: firstInfo.BatchNumber,
  1897. IsSys: 0,
  1898. WarehouseInfoId: firstInfo.ID,
  1899. }
  1900. drugflow := models.DrugFlow{
  1901. WarehouseOutId: warehouseOut.ID,
  1902. WarehouseOutOrderNumber: warehousing_out_order,
  1903. DrugId: item.DrugId,
  1904. Number: firstInfo.Number,
  1905. ProductDate: firstInfo.ProductDate,
  1906. ExpireDate: firstInfo.ExpiryDate,
  1907. Count: maxNumber,
  1908. Price: firstInfo.Price,
  1909. Status: 1,
  1910. Ctime: ctime,
  1911. UserOrgId: adminUserInfo.CurrentOrgId,
  1912. Manufacturer: firstInfo.Manufacturer,
  1913. Dealer: firstInfo.Dealer,
  1914. BatchNumber: firstInfo.BatchNumber,
  1915. MaxUnit: drug.MaxUnit,
  1916. ConsumableType: 2,
  1917. IsEdit: 1,
  1918. Creator: adminUserInfo.AdminUser.Id,
  1919. IsSys: 0,
  1920. }
  1921. service.CreateDrugWarehouseOutInfo(warehouseOutInfo)
  1922. service.CreateDrugFlowOne(drugflow)
  1923. //扣减当前批次号的库存
  1924. var total_count int64
  1925. //查询当前批次库存的数量
  1926. warehosueInfoList, _ := service.GetCurrentWarehosueInfo(item.WarehouseInfoId)
  1927. fmt.Println(warehosueInfoList)
  1928. for _, item := range warehosueInfoList {
  1929. total_count += item.StockMaxNumber*drug.MinNumber + item.StockMinNumber
  1930. }
  1931. //判断当前批次库存 和 需要出库的数据
  1932. //出库
  1933. if proof_count <= total_count {
  1934. //var total_count_one int64
  1935. //获取当前批次号的库存
  1936. //warehouseinfoOne, _ := service.GetCurrentWarehosueInfoOne(item.WarehouseInfoId)
  1937. //total_count_one = warehouseinfoOne.StockMaxNumber * drug.MinNumber + warehouseinfoOne.StockMinNumber
  1938. }
  1939. //报错提示
  1940. if proof_count > total_count {
  1941. this.ServeSuccessJSON(map[string]interface{}{
  1942. "msg": "1",
  1943. })
  1944. }
  1945. }
  1946. //判断 如果库存数量 小于于盘点库存,则入库
  1947. fmt.Println("stock_total2332322323223", stock_total, proof_count)
  1948. if stock_total < proof_count {
  1949. maxNumber = (proof_count - stock_total) / drug.MinNumber
  1950. minNumber = (proof_count - stock_total) % drug.MinNumber
  1951. fmt.Println("min_number23233232323223322323", minNumber)
  1952. ctime := time.Now().Unix()
  1953. timeStr := time.Now().Format("2006-01-02")
  1954. timeArr := strings.Split(timeStr, "-")
  1955. total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
  1956. total = total + 1
  1957. fmt.Println("total2323232323232", total)
  1958. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1959. operation_time := time.Now().Unix()
  1960. creater := adminUserInfo.AdminUser.Id
  1961. warehousing := models.DrugWarehouse{
  1962. WarehousingOrder: warehousing_order,
  1963. OperationTime: operation_time,
  1964. OrgId: adminUserInfo.CurrentOrgId,
  1965. Creater: creater,
  1966. Ctime: ctime,
  1967. Status: 1,
  1968. WarehousingTime: ctime,
  1969. Type: 1,
  1970. }
  1971. service.AddSigleDrugWarehouse(&warehousing)
  1972. warehouse, _ := service.GetLastDrugWarehouse(adminUserInfo.CurrentOrgId)
  1973. warehouseInfo := models.DrugWarehouseInfo{
  1974. WarehousingOrder: warehousing.WarehousingOrder,
  1975. WarehousingId: warehouse.ID,
  1976. DrugId: item.DrugId,
  1977. Number: lastInfo.Number,
  1978. ProductDate: lastInfo.ProductDate,
  1979. ExpiryDate: lastInfo.ExpiryDate,
  1980. WarehousingCount: maxNumber,
  1981. Price: lastInfo.Price,
  1982. TotalPrice: lastInfo.TotalPrice,
  1983. Status: 1,
  1984. Ctime: ctime,
  1985. Remark: item.Remark,
  1986. OrgId: adminUserInfo.CurrentOrgId,
  1987. Type: 1,
  1988. Manufacturer: lastInfo.Manufacturer,
  1989. Dealer: lastInfo.Dealer,
  1990. StockMaxNumber: maxNumber,
  1991. StockMinNumber: minNumber,
  1992. RetailTotalPrice: lastInfo.RetailTotalPrice,
  1993. BatchNumber: lastInfo.BatchNumber,
  1994. MaxUnit: drug.MaxUnit,
  1995. MinUnit: drug.MinUnit,
  1996. WarehousingInfoId: item.WarehouseInfoId,
  1997. }
  1998. drugflow := models.DrugFlow{
  1999. WarehousingOrder: warehousing.WarehousingOrder,
  2000. WarehousingId: warehouse.ID,
  2001. DrugId: item.DrugId,
  2002. Number: lastInfo.Number,
  2003. ProductDate: lastInfo.ProductDate,
  2004. ExpireDate: lastInfo.ExpiryDate,
  2005. Count: maxNumber,
  2006. Price: lastInfo.Price,
  2007. Status: 1,
  2008. Ctime: ctime,
  2009. UserOrgId: adminUserInfo.CurrentOrgId,
  2010. Manufacturer: lastInfo.Manufacturer,
  2011. Dealer: lastInfo.Dealer,
  2012. BatchNumber: lastInfo.BatchNumber,
  2013. MaxUnit: drug.MaxUnit,
  2014. MinUnit: drug.MinUnit,
  2015. ConsumableType: 1,
  2016. IsEdit: 1,
  2017. Creator: adminUserInfo.AdminUser.Id,
  2018. IsSys: 0,
  2019. }
  2020. service.CreateDrugWarehouseInfo(warehouseInfo)
  2021. service.CreateDrugFlowOne(drugflow)
  2022. }
  2023. }
  2024. returnData := make(map[string]interface{}, 0)
  2025. returnData["msg"] = "ok"
  2026. this.ServeSuccessJSON(returnData)
  2027. }
  2028. func (this *SelfDrugApiController) GetDrugInventoryDetail() {
  2029. id, _ := this.GetInt64("id")
  2030. detail, err := service.GetDrugInventoryDetail(id)
  2031. if err != nil {
  2032. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2033. return
  2034. }
  2035. this.ServeSuccessJSON(map[string]interface{}{
  2036. "detail": detail,
  2037. })
  2038. }
  2039. func (this *SelfDrugApiController) ModifyInventory() {
  2040. id, _ := this.GetInt64("id")
  2041. drug_id, _ := this.GetInt64("drug_id")
  2042. drug_name := this.GetString("drug_name")
  2043. specification_name := this.GetString("specification_name")
  2044. retailPrice := this.GetString("retail_price")
  2045. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  2046. warehousing_order := this.GetString("warehousing_order")
  2047. number := this.GetString("number")
  2048. manufacturer := this.GetString("manufacturer")
  2049. remark := this.GetString("remark")
  2050. warehousing_unit := this.GetString("warehousing_unit")
  2051. total := this.GetString("total")
  2052. lastPrice := this.GetString("last_price")
  2053. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  2054. count, _ := this.GetInt64("count")
  2055. drug_origin_place := this.GetString("drug_origin_place")
  2056. stock_max_number, _ := this.GetInt64("stock_max_number")
  2057. stock_min_number, _ := this.GetInt64("stock_min_number")
  2058. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2059. min_count, _ := this.GetInt64("min_count")
  2060. min_unit := this.GetString("min_unit")
  2061. inventory := models.XtDrugInventory{
  2062. DrugName: drug_name,
  2063. SpecificationName: specification_name,
  2064. WarehousingUnit: warehousing_unit,
  2065. Count: count,
  2066. LastPrice: last_price,
  2067. RetailPrice: retail_price,
  2068. Manufacturer: manufacturer,
  2069. Remark: remark,
  2070. DrugId: drug_id,
  2071. WarehousingOrder: warehousing_order,
  2072. Number: number,
  2073. Total: total,
  2074. DrugOriginPlace: drug_origin_place,
  2075. StockMaxNumber: stock_max_number,
  2076. StockMinNumber: stock_min_number,
  2077. WarehouseInfoId: warehouse_info_id,
  2078. MinCount: min_count,
  2079. MinUnit: min_unit,
  2080. }
  2081. err := service.ModifyDrugInventory(id, inventory)
  2082. if err != nil {
  2083. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2084. return
  2085. }
  2086. this.ServeSuccessJSON(map[string]interface{}{
  2087. "inventory": inventory,
  2088. })
  2089. }
  2090. func (this *SelfDrugApiController) DeleteDrugInventory() {
  2091. id, _ := this.GetInt64("id")
  2092. err := service.DeleteDrugInventory(id)
  2093. fmt.Println(err)
  2094. returnData := make(map[string]interface{}, 0)
  2095. returnData["msg"] = "ok"
  2096. this.ServeSuccessJSON(returnData)
  2097. }
  2098. func (this *SelfDrugApiController) GetDrugInventoryPrintList() {
  2099. ids := this.GetString("ids")
  2100. idssplit := strings.Split(ids, ",")
  2101. list, err := service.GetDrugInventoryPrintList(idssplit)
  2102. if err != nil {
  2103. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2104. return
  2105. }
  2106. this.ServeSuccessJSON(map[string]interface{}{
  2107. "list": list,
  2108. })
  2109. }
  2110. func (this *SelfDrugApiController) GetDrugInventoryDetailList() {
  2111. keyword := this.GetString("keyword")
  2112. limit, _ := this.GetInt64("limit")
  2113. page, _ := this.GetInt64("page")
  2114. storehouse_id, _ := this.GetInt64("storehouse_id")
  2115. orgId := this.GetAdminUserInfo().CurrentOrgId
  2116. list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId, storehouse_id)
  2117. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  2118. houseList, _ := service.GetAllStoreHouseList(orgId)
  2119. doctorList, _ := service.GetAllDoctorThree(orgId)
  2120. if err != nil {
  2121. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2122. return
  2123. }
  2124. this.ServeSuccessJSON(map[string]interface{}{
  2125. "total": total,
  2126. "list": list,
  2127. "doctorList": doctorList,
  2128. "houseList": houseList,
  2129. "inventoryList": inventoryList,
  2130. })
  2131. }
  2132. func (this *SelfDrugApiController) SaveDrugProofInventory() {
  2133. id, _ := this.GetInt64("id")
  2134. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2135. warehousing_unit := this.GetString("warehousing_unit")
  2136. remark := this.GetString("remark")
  2137. proof_count, _ := this.GetInt64("proof_count")
  2138. inventory := models.XtDrugInventory{
  2139. WarehouseInfoId: warehouse_info_id,
  2140. ProofCount: proof_count,
  2141. WarehousingUnit: warehousing_unit,
  2142. Remark: remark,
  2143. }
  2144. err := service.UpdateDrugProofInventory(id, &inventory)
  2145. info := models.XtDrugWarehouseInfo{
  2146. StockMaxNumber: proof_count,
  2147. }
  2148. service.UpdateDrugWarehouseInfoById(warehouse_info_id, &info)
  2149. if err != nil {
  2150. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2151. return
  2152. }
  2153. this.ServeSuccessJSON(map[string]interface{}{
  2154. "inventory": inventory,
  2155. })
  2156. }
  2157. func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
  2158. id, _ := this.GetInt64("id")
  2159. list, _ := service.GetDrugWarehouseInfoTotal(id)
  2160. this.ServeSuccessJSON(map[string]interface{}{
  2161. "list": list,
  2162. })
  2163. }
  2164. //新改造
  2165. func (this *SelfDrugApiController) SaveInventoryList() {
  2166. dataBody := make(map[string]interface{}, 0)
  2167. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2168. fmt.Println(err)
  2169. tableData, _ := dataBody["tableData"].([]interface{})
  2170. if len(tableData) > 0 {
  2171. for _, item := range tableData {
  2172. items := item.(map[string]interface{})
  2173. drug_name := items["drug_name"].(string)
  2174. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  2175. utils.ErrorLog("drug_name")
  2176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2177. return
  2178. }
  2179. fmt.Println("drug_name", drug_name)
  2180. specification_name := items["specification_name"].(string)
  2181. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  2182. utils.ErrorLog("specification_name")
  2183. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2184. return
  2185. }
  2186. max_unit := items["max_unit"].(string)
  2187. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  2188. utils.ErrorLog("max_unit")
  2189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2190. return
  2191. }
  2192. min_unit := items["min_unit"].(string)
  2193. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  2194. utils.ErrorLog("min_unit")
  2195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2196. return
  2197. }
  2198. drug_id := int64(items["drug_id"].(float64))
  2199. min_number := int64(items["min_number"].(float64))
  2200. stock_max_number := int64(items["stock_max_number"].(float64))
  2201. stock_min_number := int64(items["stock_min_number"].(float64))
  2202. last_stock_max_number := int64(items["last_stock_max_number"].(float64))
  2203. last_stock_min_number := int64(items["last_stock_min_number"].(float64))
  2204. warehousing_order := items["warehousing_order"].(string)
  2205. price := items["price"].(float64)
  2206. manufacturer_name := items["manufacturer_name"].(string)
  2207. batch_number := items["batch_number"].(string)
  2208. id := int64(items["id"].(float64))
  2209. orgId := this.GetAdminUserInfo().CurrentOrgId
  2210. type_id := int64(items["type"].(float64))
  2211. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  2212. utils.ErrorLog("expiry_date")
  2213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2214. return
  2215. }
  2216. expiry_date := int64(items["expiry_date"].(float64))
  2217. manufacturer := int64(items["manufacturer"].(float64))
  2218. storehouse_id := int64(items["storehouse_id"].(float64))
  2219. timeLayout := "2006-01-02"
  2220. loc, _ := time.LoadLocation("Local")
  2221. timeNow := time.Now().Format("2006-01-02")
  2222. locationTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeNow+" 00:00:00", loc)
  2223. var consumable_type int64
  2224. var consumable_count int64
  2225. var ord_total int64
  2226. var new_total int64
  2227. var total int64
  2228. ord_total = stock_max_number*min_number + stock_min_number
  2229. new_total = last_stock_max_number*min_number + last_stock_min_number
  2230. medical, _ := service.GetBaseDrugMedical(drug_id)
  2231. //改变库存
  2232. info := models.DrugWarehouseInfo{
  2233. DrugId: drug_id,
  2234. StockMaxNumber: last_stock_max_number,
  2235. StockMinNumber: last_stock_min_number,
  2236. WarehousingCount: last_stock_max_number,
  2237. MaxUnit: max_unit,
  2238. MinUnit: min_unit,
  2239. }
  2240. drugInfo, _ := service.GetCurrentWarehosueInfoOne(id)
  2241. if drugInfo.MaxUnit == medical.MaxUnit {
  2242. total = drugInfo.WarehousingCount * medical.MinNumber
  2243. }
  2244. if drugInfo.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2245. total = drugInfo.WarehousingCount
  2246. }
  2247. //如果库存数据大于盘点数据,则减去数量
  2248. if ord_total > new_total {
  2249. consumable_type = 11
  2250. consumable_count = ord_total - new_total
  2251. err = service.ModifyDrugWarehouseInfo(&info, id)
  2252. }
  2253. //如果库存数据小于盘点数据,则增加数量
  2254. if ord_total < new_total && new_total <= total {
  2255. consumable_type = 10
  2256. consumable_count = new_total - ord_total
  2257. err = service.ModifyDrugWarehouseInfo(&info, id)
  2258. }
  2259. if ord_total < new_total && new_total > total {
  2260. consumable_type = 10
  2261. consumable_count = new_total - ord_total
  2262. err = service.ModifyDrugWarehouseInfoSix(&info, id)
  2263. }
  2264. //查询默认仓库
  2265. houseConfig, _ := service.GetAllStoreHouseConfig(drugInfo.OrgId)
  2266. //查询默认仓库剩余多少库存
  2267. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, drugInfo.OrgId, drugInfo.DrugId)
  2268. var sum_count int64
  2269. var sum_in_count int64
  2270. for _, it := range list {
  2271. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2272. if it.MaxUnit == baseDrug.MaxUnit {
  2273. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2274. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2275. }
  2276. sum_count += it.StockMaxNumber + it.StockMinNumber
  2277. sum_in_count += it.WarehousingCount
  2278. }
  2279. service.UpdateMedicalSumCount(drugInfo.DrugId, sum_count, sum_in_count, drugInfo.OrgId)
  2280. inventory := models.XtDrugInventory{
  2281. DrugName: drug_name,
  2282. SpecificationName: specification_name,
  2283. WarehousingUnit: max_unit,
  2284. Count: consumable_count,
  2285. LastPrice: price,
  2286. RetailPrice: 0,
  2287. NewPrice: 0,
  2288. Manufacturer: manufacturer_name,
  2289. Dealer: "",
  2290. Remark: "",
  2291. DrugId: drug_id,
  2292. UserOrgId: orgId,
  2293. Ctime: time.Now().Unix(),
  2294. Mtime: 0,
  2295. Status: 1,
  2296. WarehousingOrder: warehousing_order,
  2297. LicenseNumber: "",
  2298. StartTime: locationTime.Unix(),
  2299. Creater: this.GetAdminUserInfo().AdminUser.Id,
  2300. Checker: 0,
  2301. CheckerStatus: 0,
  2302. CheckerTime: 0,
  2303. ExpiryDate: expiry_date,
  2304. ProductDate: 0,
  2305. Number: "",
  2306. BatchNumber: batch_number,
  2307. Total: "",
  2308. DrugOriginPlace: "",
  2309. WarehouseInfoId: id,
  2310. ProofCount: 0,
  2311. StockMaxNumber: stock_max_number,
  2312. StockMinNumber: stock_min_number,
  2313. MinCount: 0,
  2314. MinUnit: min_unit,
  2315. LastStockMaxNumber: last_stock_max_number,
  2316. LastStockMinNumber: last_stock_min_number,
  2317. InventoryType: consumable_type,
  2318. Type: type_id,
  2319. StorehouseId: storehouse_id,
  2320. }
  2321. err = service.CreateDrugInventory(inventory)
  2322. flow := models.DrugFlow{
  2323. WarehousingId: id,
  2324. DrugId: drug_id,
  2325. Number: "",
  2326. BatchNumber: batch_number,
  2327. Count: consumable_count,
  2328. UserOrgId: orgId,
  2329. PatientId: 0,
  2330. SystemTime: locationTime.Unix(),
  2331. ConsumableType: consumable_type,
  2332. IsSys: 1,
  2333. WarehousingOrder: warehousing_order,
  2334. WarehouseOutId: 0,
  2335. WarehouseOutOrderNumber: "",
  2336. IsEdit: 0,
  2337. CancelStockId: 0,
  2338. CancelOrderNumber: "",
  2339. Manufacturer: manufacturer,
  2340. Dealer: 0,
  2341. Creator: this.GetAdminUserInfo().AdminUser.Id,
  2342. UpdateCreator: 0,
  2343. Status: 1,
  2344. Ctime: time.Now().Unix(),
  2345. Mtime: 0,
  2346. Price: price,
  2347. WarehousingDetailId: id,
  2348. WarehouseOutDetailId: 0,
  2349. CancelOutDetailId: 0,
  2350. ExpireDate: expiry_date,
  2351. ProductDate: 0,
  2352. MaxUnit: min_unit,
  2353. MinUnit: min_unit,
  2354. StorehouseId: storehouse_id,
  2355. }
  2356. if ord_total != new_total {
  2357. service.CreateDrugFlowOne(flow)
  2358. }
  2359. if err != nil {
  2360. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2361. return
  2362. }
  2363. this.ServeSuccessJSON(map[string]interface{}{
  2364. "inventory": inventory,
  2365. })
  2366. }
  2367. }
  2368. }
  2369. func (this *SelfDrugApiController) GetDamageByDrugId() {
  2370. drug_id, _ := this.GetInt64("drug_id")
  2371. warehousing_order := this.GetString("warehouseing_order")
  2372. drug_type, _ := this.GetInt64("type")
  2373. list, err := service.GetDamageByDrugId(drug_id, warehousing_order, drug_type)
  2374. if err != nil {
  2375. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2376. return
  2377. }
  2378. this.ServeSuccessJSON(map[string]interface{}{
  2379. "list": list,
  2380. })
  2381. }
  2382. func (this *SelfDrugApiController) GetInventoryModeList() {
  2383. orgId := this.GetAdminUserInfo().CurrentOrgId
  2384. list, err := service.GetInventoryModeList(orgId)
  2385. manufacturerList, err := service.GetAllManufacturerList(orgId)
  2386. if err != nil {
  2387. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2388. return
  2389. }
  2390. this.ServeSuccessJSON(map[string]interface{}{
  2391. "list": list,
  2392. "manufacturerList": manufacturerList,
  2393. })
  2394. }
  2395. //库存优化接口
  2396. func (this *SelfDrugApiController) GetStorehouseList() {
  2397. orgId := this.GetAdminUserInfo().CurrentOrgId
  2398. list, err := service.GetAllStoreHouseList(orgId)
  2399. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2400. goodType, _ := service.GetAllGoodType(orgId)
  2401. patientList, _ := service.GetAllpatient(orgId)
  2402. if err != nil {
  2403. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取仓库失败")
  2404. return
  2405. }
  2406. this.ServeSuccessJSON(map[string]interface{}{
  2407. "list": list,
  2408. "manufacturerList": manufacturerList,
  2409. "goodTypeList": goodType,
  2410. "patientList": patientList,
  2411. })
  2412. }
  2413. func (this *SelfDrugApiController) GetGoodNewQuery() {
  2414. orgId := this.GetAdminUserInfo().CurrentOrgId
  2415. storehouse_id, _ := this.GetInt64("storehouse_id")
  2416. good_type, _ := this.GetInt64("good_type")
  2417. keyword := this.GetString("keyword")
  2418. page, _ := this.GetInt64("page")
  2419. limit, _ := this.GetInt64("limit")
  2420. start_time := this.GetString("start_time")
  2421. end_time := this.GetString("end_time")
  2422. timeLayout := "2006-01-02"
  2423. loc, _ := time.LoadLocation("Local")
  2424. var startTime int64
  2425. if len(start_time) > 0 {
  2426. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2427. if err != nil {
  2428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2429. return
  2430. }
  2431. startTime = theTime.Unix()
  2432. }
  2433. var endTime int64
  2434. if len(end_time) > 0 {
  2435. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2436. if err != nil {
  2437. utils.ErrorLog(err.Error())
  2438. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2439. return
  2440. }
  2441. endTime = theTime.Unix()
  2442. }
  2443. var ids []int64
  2444. var goodIds []int64
  2445. manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2446. infoList, _ := service.GetGoodWarehouseInfoByOrgId(orgId)
  2447. for _, it := range manufacturerList {
  2448. ids = append(ids, it.ID)
  2449. }
  2450. for _, it := range infoList {
  2451. goodIds = append(goodIds, it.GoodId)
  2452. }
  2453. list, total, err := service.GetGoodNewQuery(orgId, storehouse_id, good_type, keyword, page, limit, ids, goodIds, startTime, endTime)
  2454. if err != nil {
  2455. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
  2456. return
  2457. }
  2458. this.ServeSuccessJSON(map[string]interface{}{
  2459. "total": total,
  2460. "list": list,
  2461. })
  2462. }
  2463. func (this *SelfDrugApiController) GetGoodWarehouseOutInfoByIdList() {
  2464. good_id, _ := this.GetInt64("good_id")
  2465. limit, _ := this.GetInt64("limit")
  2466. page, _ := this.GetInt64("page")
  2467. start_time := this.GetString("start_first_time")
  2468. end_time := this.GetString("end_first_time")
  2469. orgId := this.GetAdminUserInfo().CurrentOrgId
  2470. timeLayout := "2006-01-02"
  2471. loc, _ := time.LoadLocation("Local")
  2472. var startTime int64
  2473. if len(start_time) > 0 {
  2474. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2475. if err != nil {
  2476. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. startTime = theTime.Unix()
  2480. }
  2481. var endTime int64
  2482. if len(end_time) > 0 {
  2483. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2484. if err != nil {
  2485. utils.ErrorLog(err.Error())
  2486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2487. return
  2488. }
  2489. endTime = theTime.Unix()
  2490. }
  2491. list, total, err := service.GetGoodWarehouseOutInfoByIdList(good_id, limit, page, orgId, startTime, endTime)
  2492. if err != nil {
  2493. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
  2494. return
  2495. }
  2496. this.ServeSuccessJSON(map[string]interface{}{
  2497. "total": total,
  2498. "list": list,
  2499. })
  2500. }
  2501. func (this *SelfDrugApiController) GetGoodPatientList() {
  2502. orgId := this.GetAdminUserInfo().CurrentOrgId
  2503. keyword := this.GetString("keyword")
  2504. list, err := service.GetGoodPatientList(orgId, keyword)
  2505. if err != nil {
  2506. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2507. return
  2508. }
  2509. this.ServeSuccessJSON(map[string]interface{}{
  2510. "list": list,
  2511. })
  2512. }
  2513. func (this *SelfDrugApiController) GetWarehouseOutDetailByPatientId() {
  2514. patient_id, _ := this.GetInt64("patient_id")
  2515. start_time := this.GetString("start_first_time")
  2516. end_time := this.GetString("end_first_time")
  2517. limit, _ := this.GetInt64("limit")
  2518. page, _ := this.GetInt64("page")
  2519. orgId := this.GetAdminUserInfo().CurrentOrgId
  2520. timeLayout := "2006-01-02"
  2521. loc, _ := time.LoadLocation("Local")
  2522. var startTime int64
  2523. if len(start_time) > 0 {
  2524. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2525. if err != nil {
  2526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2527. return
  2528. }
  2529. startTime = theTime.Unix()
  2530. }
  2531. var endTime int64
  2532. if len(end_time) > 0 {
  2533. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2534. if err != nil {
  2535. utils.ErrorLog(err.Error())
  2536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2537. return
  2538. }
  2539. endTime = theTime.Unix()
  2540. }
  2541. list, total, err := service.GetWarehouseOutDetailByPatientId(orgId, patient_id, startTime, endTime, limit, page)
  2542. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2543. if err != nil {
  2544. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2545. return
  2546. }
  2547. this.ServeSuccessJSON(map[string]interface{}{
  2548. "list": list,
  2549. "manufacturerList": manufacturerList,
  2550. "total": total,
  2551. })
  2552. }
  2553. func (this *SelfDrugApiController) GetGoodExpiryDateQuery() {
  2554. storehouse_id, _ := this.GetInt64("storehouse_id")
  2555. expiry_type, _ := this.GetInt64("expiry_type")
  2556. keyword := this.GetString("keyword")
  2557. page, _ := this.GetInt64("page")
  2558. limit, _ := this.GetInt64("limit")
  2559. orgId := this.GetAdminUserInfo().CurrentOrgId
  2560. start_time := this.GetString("start_time")
  2561. timeLayout := "2006-01-02"
  2562. loc, _ := time.LoadLocation("Local")
  2563. var endTime int64
  2564. if len(start_time) > 0 {
  2565. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2566. if err != nil {
  2567. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2568. return
  2569. }
  2570. endTime = theTime.Unix()
  2571. }
  2572. recordDateStr := time.Now().Format("2006-01-02")
  2573. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2574. fmt.Scan("parseDateErr", parseDateErr)
  2575. nowtime := recordDate.Unix()
  2576. var ids []int64
  2577. var goodIds []int64
  2578. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2579. for _, it := range manufacturers {
  2580. ids = append(ids, it.ID)
  2581. }
  2582. goodList, _ := service.GetGoodNameByword(orgId, keyword)
  2583. for _, it := range goodList {
  2584. goodIds = append(goodIds, it.ID)
  2585. }
  2586. list, total, err := service.GetGoodExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2587. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2588. if err != nil {
  2589. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2590. return
  2591. }
  2592. this.ServeSuccessJSON(map[string]interface{}{
  2593. "list": list,
  2594. "manufacturerList": manufacturerList,
  2595. "total": total,
  2596. "nowtime": nowtime,
  2597. })
  2598. }
  2599. func (this *SelfDrugApiController) GetGoodPurchaseStockQuery() {
  2600. good_type, _ := this.GetInt64("good_type")
  2601. keyword := this.GetString("keyword")
  2602. page, _ := this.GetInt64("page")
  2603. limit, _ := this.GetInt64("limit")
  2604. start_time := this.GetString("start_first_time")
  2605. end_time := this.GetString("end_first_time")
  2606. orgId := this.GetAdminUserInfo().CurrentOrgId
  2607. timeLayout := "2006-01-02"
  2608. loc, _ := time.LoadLocation("Local")
  2609. var startTime int64
  2610. if len(start_time) > 0 {
  2611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2612. if err != nil {
  2613. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2614. return
  2615. }
  2616. startTime = theTime.Unix()
  2617. }
  2618. var endTime int64
  2619. if len(end_time) > 0 {
  2620. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2621. if err != nil {
  2622. utils.ErrorLog(err.Error())
  2623. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2624. return
  2625. }
  2626. endTime = theTime.Unix()
  2627. }
  2628. var ids []int64
  2629. var infoIds []int64
  2630. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2631. for _, it := range manufacturers {
  2632. ids = append(ids, it.ID)
  2633. }
  2634. infoList, _ := service.GetGoodWarehouseInfoByOrgId(orgId)
  2635. for _, it := range infoList {
  2636. infoIds = append(infoIds, it.GoodId)
  2637. }
  2638. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2639. list, total, err := service.GetGoodPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  2640. fmt.Println("list233323233233232332233232", list)
  2641. if err != nil {
  2642. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2643. return
  2644. }
  2645. this.ServeSuccessJSON(map[string]interface{}{
  2646. "list": list,
  2647. "manufacturerList": manufacturerList,
  2648. "total": total,
  2649. })
  2650. }
  2651. func (this *SelfDrugApiController) GetDrugWarehouseOutDetailByPatientId() {
  2652. patient_id, _ := this.GetInt64("patient_id")
  2653. start_time := this.GetString("start_time")
  2654. end_time := this.GetString("end_time")
  2655. orgId := this.GetAdminUserInfo().CurrentOrgId
  2656. limit, _ := this.GetInt64("limit")
  2657. page, _ := this.GetInt64("page")
  2658. timeLayout := "2006-01-02"
  2659. loc, _ := time.LoadLocation("Local")
  2660. var startTime int64
  2661. if len(start_time) > 0 {
  2662. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2663. if err != nil {
  2664. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2665. return
  2666. }
  2667. startTime = theTime.Unix()
  2668. }
  2669. var endTime int64
  2670. if len(end_time) > 0 {
  2671. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2672. if err != nil {
  2673. utils.ErrorLog(err.Error())
  2674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2675. return
  2676. }
  2677. endTime = theTime.Unix()
  2678. }
  2679. list, total, _ := service.GetDrugWarehouseOutDetailByPatientId(patient_id, orgId, startTime, endTime, page, limit)
  2680. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2681. this.ServeSuccessJSON(map[string]interface{}{
  2682. "list": list,
  2683. "total": total,
  2684. "manufacturerList": manufacturerList,
  2685. })
  2686. }
  2687. func (this *SelfDrugApiController) GetDrugExpiryDateQuery() {
  2688. storehouse_id, _ := this.GetInt64("storehouse_id")
  2689. expiry_type, _ := this.GetInt64("expiry_type")
  2690. keyword := this.GetString("keyword")
  2691. page, _ := this.GetInt64("page")
  2692. limit, _ := this.GetInt64("limit")
  2693. orgId := this.GetAdminUserInfo().CurrentOrgId
  2694. start_time := this.GetString("start_time")
  2695. timeLayout := "2006-01-02"
  2696. loc, _ := time.LoadLocation("Local")
  2697. var endTime int64
  2698. if len(start_time) > 0 {
  2699. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2700. if err != nil {
  2701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2702. return
  2703. }
  2704. endTime = theTime.Unix()
  2705. }
  2706. recordDateStr := time.Now().Format("2006-01-02")
  2707. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2708. fmt.Scan("parseDateErr", parseDateErr)
  2709. nowtime := recordDate.Unix()
  2710. var ids []int64
  2711. var goodIds []int64
  2712. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2713. for _, it := range manufacturers {
  2714. ids = append(ids, it.ID)
  2715. }
  2716. drugList, _ := service.GetDrugNameByword(orgId, keyword)
  2717. for _, it := range drugList {
  2718. goodIds = append(goodIds, it.ID)
  2719. }
  2720. list, total, err := service.GetDrugExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2721. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2722. var drugType = "药品类型"
  2723. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2724. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  2725. if err != nil {
  2726. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2727. return
  2728. }
  2729. this.ServeSuccessJSON(map[string]interface{}{
  2730. "list": list,
  2731. "manufacturerList": manufacturerList,
  2732. "total": total,
  2733. "nowtime": nowtime,
  2734. "drugTypeList": drugTypeList,
  2735. })
  2736. }