self_drug_api_congtroller.go 123KB

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