self_drug_api_congtroller.go 179KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "XT_New/enums"
  10. "XT_New/models"
  11. "XT_New/service"
  12. "XT_New/utils"
  13. "github.com/astaxie/beego"
  14. "github.com/jinzhu/gorm"
  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/getinventorydetailprintlist", &SelfDrugApiController{}, "Get:GetInventoryDetailPrintList")
  77. beego.Router("/api/drug/savedrugproofinventory", &SelfDrugApiController{}, "Get:SaveDrugProofInventory")
  78. beego.Router("/api/drug/getdrugwarehouseinfototal", &StockManagerApiController{}, "Get:GetDrugWarehouseInfoTotal")
  79. beego.Router("/api/drug/saveinentorylist", &SelfDrugApiController{}, "Post:SaveInventoryList")
  80. beego.Router("/api/drug/getdamagebydrugid", &SelfDrugApiController{}, "Get:GetDamageByDrugId")
  81. beego.Router("/api/drug/getinventorymodelist", &SelfDrugApiController{}, "Get:GetInventoryModeList")
  82. //耗材库存优化接口
  83. beego.Router("/api/drug/getstorehouselist", &SelfDrugApiController{}, "Get:GetStorehouseList")
  84. beego.Router("/api/drug/getgoodnewquery", &SelfDrugApiController{}, "Get:GetGoodNewQuery")
  85. beego.Router("/api/drug/getgoodwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetGoodWarehouseOutInfoByIdList")
  86. beego.Router("/api/good/getgoodpatientlist", &SelfDrugApiController{}, "Get:GetGoodPatientList")
  87. beego.Router("/api/good/getwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetWarehouseOutDetailByPatientId")
  88. beego.Router("/api/good/getgoodexpirydatequery", &SelfDrugApiController{}, "Get:GetGoodExpiryDateQuery")
  89. beego.Router("/api/good/getpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodPurchaseStockQuery")
  90. //药品库存优化接口
  91. beego.Router("/api/good/getdrugwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetDrugWarehouseOutDetailByPatientId")
  92. beego.Router("/api/drug/getdrugexpirydatequery", &SelfDrugApiController{}, "Get:GetDrugExpiryDateQuery")
  93. beego.Router("/api/drug/getpurchasedrugquery", &SelfDrugApiController{}, "Get:GetPurchaseDrugQuery")
  94. beego.Router("/api/drug/getdrugnewquery", &SelfDrugApiController{}, "Get:GetDrugNewQuery")
  95. beego.Router("/api/drug/getdrugwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetDrugWarehouseInfoById")
  96. //耗材脚本
  97. beego.Router("/api/stock/tosendgoodinfomation", &SelfDrugApiController{}, "Get:GetSendGoodInformation")
  98. //药品脚本
  99. beego.Router("/api/drug/getdruginitdatalist", &SelfDrugApiController{}, "Get:GetDrugInitDetailList")
  100. //新数据
  101. beego.Router("/api/stock/getnewpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodNewPurchaseStockQuery")
  102. beego.Router("/api/stock/getpurchasenewdrugquery", &SelfDrugApiController{}, "Get:GetPurchaseNewDrugQuery")
  103. beego.Router("/api/stock/getgoodovercount", &SelfDrugApiController{}, "Get:GetGoodOverCount")
  104. beego.Router("/api/stock/getdrugovercount", &SelfDrugApiController{}, "Get:GetDrugOverCount")
  105. beego.Router("/api/stock/getdruginfolist", &SelfDrugApiController{}, "Get:GetDrugInventoryWarehouseInfoList")
  106. beego.Router("/api/drug/getdrugflowdetailbyid", &SelfDrugApiController{}, "Get:GetDrugFlowDetailById")
  107. //康允新版本
  108. beego.Router("/api/stock/getpurchaseDrugQueryList", &SelfDrugApiController{}, "Get:GetPurchaseDrugQueryList")
  109. beego.Router("/api/stock/getpurchasestockquerylist", &SelfDrugApiController{}, "Get:GetPurchaseStockQueryList")
  110. beego.Router("/api/drug/getcheckdrugbatchlist", &SelfDrugApiController{}, "Get:GetCheckDrugBatchList")
  111. beego.Router("/api/good/getcheckgoodbatchlist", &SelfDrugApiController{}, "Get:GetCheckGoodBatchList")
  112. beego.Router("/api/drug/getdrugpatientname", &SelfDrugApiController{}, "Get:GetDrugPatientName")
  113. //自备药的接口
  114. beego.Router("/api/drug/getallselfdruginfolist", &SelfDrugApiController{}, "Get:GetAllSelfDrugInfoList")
  115. beego.Router("/api/drug/getallpatientlist", &SelfDrugApiController{}, "Get:GetAllPatientList")
  116. beego.Router("/api/drug/postsearchselfdruglist", &SelfDrugApiController{}, "Get:PostSearchSelfDrugList")
  117. beego.Router("/api/drug/postselfdrugwarehouse", &SelfDrugApiController{}, "Post:PostSelfDrugWarehouse")
  118. beego.Router("/api/drug/getallselfdrugwarehosueinfolist", &SelfDrugApiController{}, "Get:GetAllSelfDrugWarehouseInfoList")
  119. beego.Router("/api/drug/getselfdrugwarehouseinfobyid", &SelfDrugApiController{}, "Get:GetSelfDrugWarehouseInfoByID")
  120. beego.Router("/api/drug/modifyselfdrugwarehouse", &SelfDrugApiController{}, "Post:ModifySelfDrugWarehouse")
  121. beego.Router("/api/drug/deleteselfwarehouseinfo", &SelfDrugApiController{}, "Get:DeleteSelfDrugWarehouse")
  122. beego.Router("/api/drug/tocheckselfwarehouseinginfo", &SelfDrugApiController{}, "Get:TocheckSelfWarehouseingInfo")
  123. beego.Router("/api/drug/getselfdrugbatchnumber", &SelfDrugApiController{}, "Get:GetSelfDrugBatchNumber")
  124. beego.Router("/api/drug/postsetfdrugwarehouseout", &SelfDrugApiController{}, "Post:PostSelfDrugWarehouseOut")
  125. beego.Router("/api/drug/getallselfdrugwarehouseoutlist", &SelfDrugApiController{}, "Get:GetAllSelfDrugWarehouseOutList")
  126. beego.Router("/api/drug/deleteselfwarehouseout", &SelfDrugApiController{}, "Get:DeleteSelfWarehouseOut")
  127. beego.Router("/api/drug/getselfdrugwarehouseoutbyid", &SelfDrugApiController{}, "Get:GetSelfDrugWarehouseOutById")
  128. }
  129. func (this *SelfDrugApiController) GetCurrentPatient() {
  130. adminUserInfo := this.GetAdminUserInfo()
  131. orgId := adminUserInfo.CurrentOrgId
  132. patient, err := service.GetCurrentPatient(orgId)
  133. if err != nil {
  134. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  135. return
  136. }
  137. this.ServeSuccessJSON(map[string]interface{}{
  138. "patient": patient,
  139. })
  140. }
  141. func (this *SelfDrugApiController) GetAllDrugName() {
  142. adminUserInfo := this.GetAdminUserInfo()
  143. orgId := adminUserInfo.CurrentOrgId
  144. //查询药品库是否开启
  145. //configStock, _ := service.GetDrugStockConfig(orgId)
  146. //if configStock.IsOpen == 1 {
  147. //
  148. //}
  149. drugName, err := service.GetAllDrugName(orgId)
  150. if err != nil {
  151. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
  152. return
  153. }
  154. this.ServeSuccessJSON(map[string]interface{}{
  155. "drugName": drugName,
  156. })
  157. }
  158. func (this *SelfDrugApiController) SaveDrugName() {
  159. adminUserInfo := this.GetAdminUserInfo()
  160. orgId := adminUserInfo.CurrentOrgId
  161. drug_name := this.GetString("drug_name")
  162. id, _ := this.GetInt64("id")
  163. //fmt.Println("drug_name", drug_name)
  164. drugName := models.XtDrugName{
  165. UserOrgId: orgId,
  166. DrugName: drug_name,
  167. Status: 1,
  168. CreatedTime: time.Now().Unix(),
  169. DrugId: id,
  170. }
  171. _, errcode := service.GetDrugName(drug_name, orgId)
  172. if errcode == gorm.ErrRecordNotFound {
  173. err := service.SaveDrugName(&drugName)
  174. if err != nil {
  175. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  176. return
  177. }
  178. this.ServeSuccessJSON(map[string]interface{}{
  179. "drugName": drugName,
  180. })
  181. } else {
  182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  183. return
  184. }
  185. }
  186. func (this *SelfDrugApiController) GetDrugNameList() {
  187. adminUserInfo := this.GetAdminUserInfo()
  188. orgId := adminUserInfo.CurrentOrgId
  189. list, err := service.GetDrugNameList(orgId)
  190. if err != nil {
  191. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  192. return
  193. }
  194. this.ServeSuccessJSON(map[string]interface{}{
  195. "list": list,
  196. })
  197. }
  198. func (this *SelfDrugApiController) GetRulleName() {
  199. adminUserInfo := this.GetAdminUserInfo()
  200. orgId := adminUserInfo.CurrentOrgId
  201. id, _ := this.GetInt64("id")
  202. drugId, _ := service.GetDrugId(id)
  203. rullerList, err := service.GetRulleList(orgId, drugId.DrugId)
  204. if err != nil {
  205. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  206. return
  207. }
  208. this.ServeSuccessJSON(map[string]interface{}{
  209. "rullerList": rullerList,
  210. })
  211. }
  212. func (this *SelfDrugApiController) GetUnitByBaseId() {
  213. id, _ := this.GetInt64("id")
  214. baseList, err := service.GetUnitByBaseId(id)
  215. if err != nil {
  216. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  217. return
  218. }
  219. this.ServeSuccessJSON(map[string]interface{}{
  220. "baseList": baseList,
  221. })
  222. }
  223. func (this *SelfDrugApiController) SaveRulleName() {
  224. drug_name := this.GetString("drug_name")
  225. drug_spec := this.GetString("drug_spec")
  226. drug_stock_limit := this.GetString("drug_stock_limit")
  227. drug_name_id, _ := this.GetInt64("drug_name_id")
  228. drug_id, _ := this.GetInt64("drug_id")
  229. price, _ := this.GetInt64("price")
  230. prices := strconv.FormatInt(price, 10)
  231. durg_price, _ := strconv.ParseFloat(prices, 64)
  232. unit := this.GetString("unit")
  233. adminUserInfo := this.GetAdminUserInfo()
  234. orgId := adminUserInfo.CurrentOrgId
  235. fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
  236. drugSpecName := models.XtStandName{
  237. DrugName: drug_name,
  238. DrugSpec: drug_spec,
  239. DrugStockLimit: drug_stock_limit,
  240. DrugNameId: drug_name_id,
  241. Price: durg_price,
  242. MinUnit: unit,
  243. UserOrgId: orgId,
  244. Status: 1,
  245. CreatedTime: time.Now().Unix(),
  246. DrugId: drug_id,
  247. }
  248. //查询该机构下药品规格名称是否存在
  249. _, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
  250. if errcode == gorm.ErrRecordNotFound {
  251. err := service.SaveRulleName(&drugSpecName)
  252. if err != nil {
  253. this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
  254. return
  255. }
  256. this.ServeSuccessJSON(map[string]interface{}{
  257. "RullerName": drugSpecName,
  258. })
  259. } else if errcode == nil {
  260. this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
  261. return
  262. }
  263. }
  264. func (this *SelfDrugApiController) EditRullerName() {
  265. id, _ := this.GetInt64("id")
  266. rullerDetail, err := service.GetRullerNameDetail(id)
  267. if err != nil {
  268. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  269. return
  270. }
  271. this.ServeSuccessJSON(map[string]interface{}{
  272. "rullerDetail": rullerDetail,
  273. })
  274. }
  275. func (this *SelfDrugApiController) UpdatedRullerName() {
  276. id, _ := this.GetInt64("id")
  277. drug_name := this.GetString("drug_name")
  278. drug_stock_limit := this.GetString("drug_stock_limit")
  279. price, _ := this.GetInt64("price")
  280. prices := strconv.FormatInt(price, 10)
  281. durg_price, _ := strconv.ParseFloat(prices, 64)
  282. drug_spec := this.GetString("drug_spec")
  283. unit := this.GetString("unit")
  284. drug_name_id, _ := this.GetInt64("drug_name_id")
  285. drug_id, _ := this.GetInt64("drug_id")
  286. RullerName := models.XtStandName{
  287. DrugName: drug_name,
  288. DrugStockLimit: drug_stock_limit,
  289. Price: durg_price,
  290. DrugSpec: drug_spec,
  291. MinUnit: unit,
  292. DrugNameId: drug_name_id,
  293. DrugId: drug_id,
  294. }
  295. _, errcode := service.GetIsExit(drug_name, drug_spec, id)
  296. if errcode == gorm.ErrRecordNotFound {
  297. err := service.UpdatedRullerName(id, &RullerName)
  298. if err != nil {
  299. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  300. return
  301. }
  302. this.ServeSuccessJSON(map[string]interface{}{
  303. "RullerName": RullerName,
  304. })
  305. } else if errcode == nil {
  306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  307. return
  308. }
  309. }
  310. func (this *SelfDrugApiController) GetAllDrugNameList() {
  311. adminUserInfo := this.GetAdminUserInfo()
  312. orgId := adminUserInfo.CurrentOrgId
  313. rullerName, err := service.GetAllDrugNameList(orgId)
  314. list, err := service.GetMedicalDrugNameList(orgId)
  315. if err != nil {
  316. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  317. return
  318. }
  319. this.ServeSuccessJSON(map[string]interface{}{
  320. "rullerName": rullerName,
  321. "list": list,
  322. })
  323. }
  324. func (this *SelfDrugApiController) GetRullerListByDrugName() {
  325. id := this.GetString("id")
  326. adminUserInfo := this.GetAdminUserInfo()
  327. orgId := adminUserInfo.CurrentOrgId
  328. fmt.Println("orgid", orgId)
  329. drugName, err := service.GetRullerListByDrugName(id, orgId)
  330. if err != nil {
  331. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  332. return
  333. }
  334. this.ServeSuccessJSON(map[string]interface{}{
  335. "drugName": drugName,
  336. })
  337. }
  338. func (this *SelfDrugApiController) SaveSelfMedicines() {
  339. dataBody := make(map[string]interface{}, 0)
  340. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  341. fmt.Println(err)
  342. patient_id := int64(dataBody["patient_id"].(float64))
  343. medicineData, _ := dataBody["medicineData"].([]interface{})
  344. adminUserInfo := this.GetAdminUserInfo()
  345. orgId := adminUserInfo.CurrentOrgId
  346. for _, item := range medicineData {
  347. items := item.(map[string]interface{})
  348. drug_name := items["drug_name"].(string)
  349. drug_name_id := int64(items["drug_name_id"].(float64))
  350. drug_spec := items["drug_spec"].(string)
  351. min_unit := items["min_unit"].(string)
  352. drug_id := int64(items["drug_id"].(float64))
  353. //根据drug_id
  354. drugMedical, _ := service.GetBaseDrugMedical(drug_name_id)
  355. medical := models.XtSelfMedical{
  356. DrugName: drug_name,
  357. DrugNameId: drug_name_id,
  358. DrugSpec: drug_spec,
  359. CreatedTime: time.Now().Unix(),
  360. Status: 1,
  361. UserOrgId: orgId,
  362. PatientId: patient_id,
  363. MinUnit: min_unit,
  364. ExecutionFrequency: drugMedical.ExecutionFrequency,
  365. PrescribingNumber: drugMedical.PrescribingNumber,
  366. DeliveryWay: drugMedical.DeliveryWay,
  367. SingleDose: drugMedical.SingleDose,
  368. DrugId: drug_id,
  369. }
  370. //查询同个病人同个药品同个规格是否已存在
  371. _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
  372. if errcode == gorm.ErrRecordNotFound {
  373. err := service.CreateSelfMedical(&medical)
  374. fmt.Println(err)
  375. } else if errcode == nil {
  376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  377. return
  378. }
  379. }
  380. returnData := make(map[string]interface{}, 0)
  381. returnData["msg"] = "ok"
  382. this.ServeSuccessJSON(returnData)
  383. return
  384. }
  385. func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
  386. adminUserInfo := this.GetAdminUserInfo()
  387. orgid := adminUserInfo.CurrentOrgId
  388. //fmt.Println(orgid)
  389. appId := adminUserInfo.CurrentAppId
  390. staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
  391. if err != nil {
  392. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  393. return
  394. }
  395. this.ServeSuccessJSON(map[string]interface{}{
  396. "staff": staff,
  397. })
  398. }
  399. func (this *SelfDrugApiController) SaveStock() {
  400. timeLayout := "2006-01-02"
  401. loc, _ := time.LoadLocation("Local")
  402. start_time := this.GetString("start_time")
  403. fmt.Println("start_time", start_time)
  404. admin_user_id, _ := this.GetInt64("admin_user_id")
  405. fmt.Println("admin_user_id", admin_user_id)
  406. patient_id, _ := this.GetInt64("patient_id")
  407. dataBody := make(map[string]interface{}, 0)
  408. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  409. fmt.Println(err)
  410. stocks, _ := dataBody["stocks"].([]interface{})
  411. adminUserInfo := this.GetAdminUserInfo()
  412. orgId := adminUserInfo.CurrentOrgId
  413. for _, item := range stocks {
  414. items := item.(map[string]interface{})
  415. drug_name := items["drug_name"].(string)
  416. fmt.Println("drug_name", drug_name)
  417. drug_name_id := int64(items["drug_name_id"].(float64))
  418. fmt.Println("parient_id", drug_name_id)
  419. drug_spec := items["drug_spec"].(string)
  420. store_number := items["store_number"].(string)
  421. fmt.Println("store_number", store_number)
  422. storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
  423. remarks := items["remarks"].(string)
  424. min_unit := items["min_unit"].(string)
  425. medic_id := int64(items["id"].(float64))
  426. timeStr := time.Now().Format("2006-01-02")
  427. timeArr := strings.Split(timeStr, "-")
  428. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  429. total = total + 1
  430. warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  431. number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
  432. number = number + total
  433. warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
  434. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  435. stock := models.XtSelfStock{
  436. DrugName: drug_name,
  437. DrugNameId: drug_name_id,
  438. DrugSpec: drug_spec,
  439. StoreNumber: storeNumber,
  440. Remarks: remarks,
  441. AdminUserId: admin_user_id,
  442. StorckTime: theTime.Unix(),
  443. CreatedTime: time.Now().Unix(),
  444. Status: 1,
  445. UserOrgId: orgId,
  446. StockInNumber: warehousing_in_order,
  447. PatientId: patient_id,
  448. MinUnit: min_unit,
  449. StorageMode: 1,
  450. MedicId: medic_id,
  451. }
  452. err := service.CreateStock(&stock)
  453. fmt.Println("err", err)
  454. }
  455. returnData := make(map[string]interface{}, 0)
  456. returnData["msg"] = "ok"
  457. this.ServeSuccessJSON(returnData)
  458. return
  459. }
  460. func (this *SelfDrugApiController) SaveOutStock() {
  461. timeLayout := "2006-01-02"
  462. loc, _ := time.LoadLocation("Local")
  463. start_time := this.GetString("start_time")
  464. admin_user_id, _ := this.GetInt64("admin_user_id")
  465. patient_id, _ := this.GetInt64("patient_id")
  466. dataBody := make(map[string]interface{}, 0)
  467. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  468. fmt.Println(err)
  469. outStocks, _ := dataBody["outStocks"].([]interface{})
  470. adminUserInfo := this.GetAdminUserInfo()
  471. orgId := adminUserInfo.CurrentOrgId
  472. for _, item := range outStocks {
  473. items := item.(map[string]interface{})
  474. drug_name := items["drug_name"].(string)
  475. drug_name_id := int64(items["drug_name_id"].(float64))
  476. drug_spec := items["drug_spec"].(string)
  477. outstore_number := items["outstore_number"].(string)
  478. outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
  479. remarks := items["remarks"].(string)
  480. medic_id := int64(items["id"].(float64))
  481. timeStr := time.Now().Format("2006-01-02")
  482. timeArr := strings.Split(timeStr, "-")
  483. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  484. total = total + 1
  485. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  486. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  487. number = number + total
  488. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  489. fmt.Println(remarks)
  490. fmt.Println(items)
  491. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  492. stock := models.XtSelfOutStock{
  493. DrugName: drug_name,
  494. DrugNameId: drug_name_id,
  495. DrugSpec: drug_spec,
  496. OutstoreNumber: outStoreNumber,
  497. Remarks: remarks,
  498. AdminUserId: admin_user_id,
  499. StorckTime: theTime.Unix(),
  500. CreatedTime: time.Now().Unix(),
  501. Status: 1,
  502. UserOrgId: orgId,
  503. StockOutNumber: warehousing_out_order,
  504. PatientId: patient_id,
  505. ExitMode: 1,
  506. MedicId: medic_id,
  507. }
  508. err := service.CreateOutStock(&stock)
  509. fmt.Println("err", err)
  510. }
  511. returnData := make(map[string]interface{}, 0)
  512. returnData["msg"] = "ok"
  513. this.ServeSuccessJSON(returnData)
  514. return
  515. }
  516. func (this *SelfDrugApiController) DeleteDrugById() {
  517. id, _ := this.GetInt64("id")
  518. drug_name := this.GetString("drug_name")
  519. adminUserInfo := this.GetAdminUserInfo()
  520. orgId := adminUserInfo.CurrentOrgId
  521. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  522. if errcode == gorm.ErrRecordNotFound {
  523. service.DeleteDrugName(id)
  524. returnData := make(map[string]interface{}, 0)
  525. returnData["msg"] = "ok"
  526. this.ServeSuccessJSON(returnData)
  527. } else if errcode == nil {
  528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  529. return
  530. }
  531. }
  532. func (this *SelfDrugApiController) SaveRadio() {
  533. radio, _ := this.GetInt64("radio")
  534. adminUserInfo := this.GetAdminUserInfo()
  535. orgId := adminUserInfo.CurrentOrgId
  536. drugSet := models.XtDrugSet{
  537. DrugStart: radio,
  538. UserOrgId: orgId,
  539. Status: 1,
  540. CreatedTime: time.Now().Unix(),
  541. }
  542. _, errcode := service.GetDrugSetByUserOrgId(orgId)
  543. if errcode == gorm.ErrRecordNotFound {
  544. err := service.SaveRadio(&drugSet)
  545. if err != nil {
  546. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  547. return
  548. }
  549. this.ServeSuccessJSON(map[string]interface{}{
  550. "drugSet": drugSet,
  551. })
  552. } else if errcode == nil {
  553. err := service.UpdateDrugSet(&drugSet, orgId)
  554. if err != nil {
  555. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  556. return
  557. }
  558. this.ServeSuccessJSON(map[string]interface{}{
  559. "drugSet": drugSet,
  560. })
  561. }
  562. }
  563. func (this *SelfDrugApiController) DeleteDrugStand() {
  564. id, _ := this.GetInt64("id")
  565. name := this.GetString("name")
  566. adminUserInfo := this.GetAdminUserInfo()
  567. orgId := adminUserInfo.CurrentOrgId
  568. _, errcode := service.GetMedicalsByName(orgId, name)
  569. if errcode == gorm.ErrRecordNotFound {
  570. err := service.DeleteDrugStand(id)
  571. fmt.Println(err)
  572. returnData := make(map[string]interface{}, 0)
  573. returnData["msg"] = "ok"
  574. this.ServeSuccessJSON(returnData)
  575. } else if errcode == nil {
  576. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  577. return
  578. }
  579. }
  580. func (this *SelfDrugApiController) GetStockList() {
  581. patientid, _ := this.GetInt64("id")
  582. start_time := this.GetString("start_time")
  583. fmt.Println("开始时间", start_time)
  584. timeLayout := "2006-01-02"
  585. loc, _ := time.LoadLocation("Local")
  586. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  587. startimeUnix := theTime.Unix()
  588. keyword := this.GetString("keyword")
  589. fmt.Println("keyword", keyword)
  590. adminUserInfo := this.GetAdminUserInfo()
  591. orgId := adminUserInfo.CurrentOrgId
  592. //获取
  593. medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
  594. //统计总数量
  595. stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
  596. //统计出库数量
  597. outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
  598. //统计该病人时间段内出库条数
  599. outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
  600. if err != nil {
  601. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  602. return
  603. }
  604. this.ServeSuccessJSON(map[string]interface{}{
  605. "medicalList": medicalList,
  606. "stocklist": stocklist,
  607. "outStocklist": outStocklist,
  608. "outList": outList,
  609. })
  610. }
  611. func (this *SelfDrugApiController) DeleteDrugName() {
  612. drug_name := this.GetString("drugname")
  613. patient_id, _ := this.GetInt64("patientid")
  614. //查询该药品是否出库
  615. stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
  616. if len(stocklist) == 0 {
  617. //删除该药品
  618. service.DeleteDrugStockNumber(drug_name, patient_id)
  619. returnData := make(map[string]interface{}, 0)
  620. returnData["msg"] = "ok"
  621. this.ServeSuccessJSON(returnData)
  622. } else {
  623. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. }
  627. func (this *SelfDrugApiController) GetDrugDetail() {
  628. timeLayout := "2006-01-02"
  629. loc, _ := time.LoadLocation("Local")
  630. drug_name := this.GetString("drug_name")
  631. drug_spec := this.GetString("drug_spec")
  632. start_time := this.GetString("start_time")
  633. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  634. end_time := this.GetString("end_time")
  635. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  636. patient_id, _ := this.GetInt64("patient_id")
  637. adminUserInfo := this.GetAdminUserInfo()
  638. orgId := adminUserInfo.CurrentOrgId
  639. //查询入库明细
  640. stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  641. //查询出库明细
  642. outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  643. if err != nil {
  644. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  645. return
  646. }
  647. this.ServeSuccessJSON(map[string]interface{}{
  648. "stockDetail": stockDetail,
  649. "outStockDetail": outStockDetail,
  650. })
  651. }
  652. func (this *SelfDrugApiController) GetAllPatientStockList() {
  653. timeLayout := "2006-01-02"
  654. loc, _ := time.LoadLocation("Local")
  655. drug_name := this.GetString("drug_name")
  656. drug_spec := this.GetString("drug_spec")
  657. start_time := this.GetString("start_time")
  658. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  659. startUnix := theTime.Unix()
  660. end_time := this.GetString("end_time")
  661. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  662. endTimeUnix := endTimes.Unix()
  663. keywords := this.GetString("search_input")
  664. adminUserInfo := this.GetAdminUserInfo()
  665. orgId := adminUserInfo.CurrentOrgId
  666. //入库
  667. stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  668. //出库
  669. outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  670. if err != nil {
  671. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  672. return
  673. }
  674. this.ServeSuccessJSON(map[string]interface{}{
  675. "stocklist": stocklist,
  676. "outStockList": outStockList,
  677. })
  678. }
  679. func (this *SelfDrugApiController) GetDrugDataByPatientId() {
  680. patient_id, _ := this.GetInt64("patient_id")
  681. fmt.Println("patient_id", patient_id)
  682. medicalList, err := service.GetDrugDataByPatientId(patient_id)
  683. if err != nil {
  684. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  685. return
  686. }
  687. this.ServeSuccessJSON(map[string]interface{}{
  688. "medicalList": medicalList,
  689. })
  690. }
  691. func (this *SelfDrugApiController) GetSelfMedicalList() {
  692. patient_id, _ := this.GetInt64("patient_id")
  693. adminUserInfo := this.GetAdminUserInfo()
  694. orgId := adminUserInfo.CurrentOrgId
  695. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  696. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(orgId)
  697. drugList, _ := service.GetAllBaseDrugLibList(orgId)
  698. privateDrugList, _ := service.GetPrivateDrugList(patient_id, orgId)
  699. this.ServeSuccessJSON(map[string]interface{}{
  700. "base_drug_config": drugStockConfig,
  701. "private_drug_config": privateDrugConfig,
  702. "base_drug_list": drugList,
  703. "private_drug_list": privateDrugList,
  704. })
  705. ////查询是否开启药品库
  706. //config, _ := service.GetDruckStockConfig(orgId)
  707. //
  708. //fmt.Println("--------------------------",config.IsOpen)
  709. ////开启
  710. //if config.IsOpen == 1 {
  711. // //查询该机构下的药品库
  712. // drugName, _ := service.GetAllDrugName(orgId)
  713. //
  714. // //查询该机构是否开启自备药
  715. // medical, _ := service.GetSetSelfMedical(orgId)
  716. // fmt.Println("medical+++++++++++++++++",medical.DrugStart)
  717. // //开启
  718. // if medical.DrugStart == 1 {
  719. // list, err := service.GetSelfMedicalList(patient_id)
  720. // if err != nil {
  721. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  722. // return
  723. // }
  724. // this.ServeSuccessJSON(map[string]interface{}{
  725. // "medicalList": list,
  726. // "drugName": drugName,
  727. // })
  728. // } else {
  729. // this.ServeSuccessJSON(map[string]interface{}{
  730. // "drugName": drugName,
  731. // })
  732. // }
  733. //}
  734. }
  735. func (this *SelfDrugApiController) GetDrugDescByDrugName() {
  736. drug_name := this.GetString("drug_name")
  737. patient_id, _ := this.GetInt64("patient_id")
  738. way, _ := this.GetInt64("way")
  739. adminUserInfo := this.GetAdminUserInfo()
  740. orgId := adminUserInfo.CurrentOrgId
  741. drug_id, _ := this.GetInt64("id")
  742. //从基础库查询
  743. if way == 1 {
  744. //查询基础库数据
  745. medcal, err := service.GetBaseMedcal(drug_name, orgId)
  746. //统计入库数量
  747. countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
  748. //统计出库数量
  749. countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
  750. if err != nil {
  751. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  752. return
  753. }
  754. this.ServeSuccessJSON(map[string]interface{}{
  755. "drugspec": medcal,
  756. "countInfo": countInfo,
  757. "countout": countout,
  758. })
  759. }
  760. //从自备药库查询
  761. if way == 2 {
  762. drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
  763. if err != nil {
  764. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  765. return
  766. }
  767. this.ServeSuccessJSON(map[string]interface{}{
  768. "drugspec": drugspec,
  769. })
  770. }
  771. }
  772. func (this *SelfDrugApiController) GetDrugSet() {
  773. adminUserInfo := this.GetAdminUserInfo()
  774. orgId := adminUserInfo.CurrentOrgId
  775. drugSet, err := service.GetDrugSet(orgId)
  776. if err != nil {
  777. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  778. return
  779. }
  780. this.ServeSuccessJSON(map[string]interface{}{
  781. "drugSet": drugSet,
  782. })
  783. }
  784. func (this *SelfDrugApiController) GetAllMedicalList() {
  785. adminUserInfo := this.GetAdminUserInfo()
  786. orgId := adminUserInfo.CurrentOrgId
  787. list, err := service.GetAllMedicalList(orgId)
  788. if err != nil {
  789. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  790. return
  791. }
  792. this.ServeSuccessJSON(map[string]interface{}{
  793. "drugName": list,
  794. })
  795. }
  796. func (this *SelfDrugApiController) GetStandName() {
  797. name := this.GetString("name")
  798. adminUserInfo := this.GetAdminUserInfo()
  799. orgId := adminUserInfo.CurrentOrgId
  800. rullerlist, err := service.GetRulleName(orgId, name)
  801. if err != nil {
  802. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  803. return
  804. }
  805. this.ServeSuccessJSON(map[string]interface{}{
  806. "rullerlist": rullerlist,
  807. })
  808. }
  809. func (this *SelfDrugApiController) GetRullerList() {
  810. id, _ := this.GetInt64("id")
  811. adminUserInfo := this.GetAdminUserInfo()
  812. orgId := adminUserInfo.CurrentOrgId
  813. rullerList, err := service.GetRulleList(orgId, id)
  814. if err != nil {
  815. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  816. return
  817. }
  818. this.ServeSuccessJSON(map[string]interface{}{
  819. "rullerlist": rullerList,
  820. })
  821. }
  822. func (this *SelfDrugApiController) DeleteDrugNameById() {
  823. id, _ := this.GetInt64("id")
  824. drug_name := this.GetString("drug_name")
  825. adminUserInfo := this.GetAdminUserInfo()
  826. orgId := adminUserInfo.CurrentOrgId
  827. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  828. if errcode == gorm.ErrRecordNotFound {
  829. service.DeleteDrugNameById(id)
  830. returnData := make(map[string]interface{}, 0)
  831. returnData["msg"] = "ok"
  832. this.ServeSuccessJSON(returnData)
  833. } else if errcode == nil {
  834. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  835. return
  836. }
  837. }
  838. func (this *SelfDrugApiController) GetPatientDetail() {
  839. id, _ := this.GetInt64("id")
  840. adminUserInfo := this.GetAdminUserInfo()
  841. patientDetail, err := service.GetPatientDetail(id, adminUserInfo.CurrentOrgId)
  842. if err != nil {
  843. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  844. return
  845. }
  846. this.ServeSuccessJSON(map[string]interface{}{
  847. "patientDetail": patientDetail,
  848. })
  849. }
  850. //func (this *SelfDrugApiController) ToPatientDetail() {
  851. //
  852. // keyword := this.GetString("keyword")
  853. // adminUser := this.GetAdminUserInfo()
  854. // orgId := adminUser.CurrentOrgId
  855. // patient, err := service.ToSeachPatient(keyword, orgId)
  856. // if err != nil {
  857. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  858. // return
  859. // }
  860. // this.ServeSuccessJSON(map[string]interface{}{
  861. // "patient": patient,
  862. // })
  863. //}
  864. func (this *SelfDrugApiController) GetSelfStockQuery() {
  865. adminUserInfo := this.GetAdminUserInfo()
  866. orgId := adminUserInfo.CurrentOrgId
  867. type_name, _ := this.GetInt64("type_name")
  868. keywords := this.GetString("keywords")
  869. timeLayout := "2006-01-02"
  870. loc, _ := time.LoadLocation("Local")
  871. start_time := this.GetString("start_time")
  872. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  873. startUnix := theTime.Unix()
  874. end_time := this.GetString("end_time")
  875. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  876. endTimeUnix := endTimes.Unix()
  877. page, _ := this.GetInt64("page")
  878. limit, _ := this.GetInt64("limit")
  879. //统计入库数量
  880. stockQuery, total, err := service.GetSelfStockQuery(type_name, keywords, startUnix, endTimeUnix, orgId, limit, page)
  881. //统计出库数量
  882. stockOutQuery, err := service.GetSelfOutStockQuery(startUnix, endTimeUnix, orgId)
  883. if err != nil {
  884. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  885. return
  886. }
  887. this.ServeSuccessJSON(map[string]interface{}{
  888. "stockQuery": stockQuery,
  889. "total": total,
  890. "stockOutQuery": stockOutQuery,
  891. })
  892. }
  893. func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
  894. keyword := this.GetString("keyword")
  895. storehouse_id, _ := this.GetInt64("storehouse_id")
  896. orgId := this.GetAdminUserInfo().CurrentOrgId
  897. list, err := service.PostSearchDrugWarehouseList(keyword, orgId, storehouse_id)
  898. manufacturerList, err := service.GetAllManufacturerList(orgId)
  899. dealerList, err := service.GetAllDealerList(orgId)
  900. if err != nil {
  901. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  902. return
  903. }
  904. this.ServeSuccessJSON(map[string]interface{}{
  905. "list": list,
  906. "manufacturerList": manufacturerList,
  907. "dealerList": dealerList,
  908. })
  909. }
  910. func (this *SelfDrugApiController) SaveDrugPrice() {
  911. timeLayout := "2006-01-02"
  912. loc, _ := time.LoadLocation("Local")
  913. dataBody := make(map[string]interface{}, 0)
  914. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  915. fmt.Println(err)
  916. tableData, _ := dataBody["tableData"].([]interface{})
  917. fmt.Println("999939433443", tableData)
  918. if len(tableData) > 0 {
  919. for _, item := range tableData {
  920. items := item.(map[string]interface{})
  921. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  922. utils.ErrorLog("drug_name")
  923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  924. return
  925. }
  926. drug_name := items["drug_name"].(string)
  927. fmt.Println("drug_aname23232323232", drug_name)
  928. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  929. utils.ErrorLog("drug_name")
  930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  931. return
  932. }
  933. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  934. utils.ErrorLog("retail_price")
  935. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  936. return
  937. }
  938. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  939. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  940. utils.ErrorLog("warehousing_order")
  941. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  942. return
  943. }
  944. warehousing_order := items["warehousing_order"].(string)
  945. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  946. utils.ErrorLog("number")
  947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  948. return
  949. }
  950. number := items["number"].(string)
  951. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  952. utils.ErrorLog("dealer")
  953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  954. return
  955. }
  956. dealer := items["dealer"].(string)
  957. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  958. utils.ErrorLog("manufacturer")
  959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  960. return
  961. }
  962. manufacturer := items["manufacturer"].(string)
  963. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  964. utils.ErrorLog("specification_name")
  965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  966. return
  967. }
  968. specification_name := items["specification_name"].(string)
  969. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  970. utils.ErrorLog("remark")
  971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  972. return
  973. }
  974. remark := items["remark"].(string)
  975. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  976. utils.ErrorLog("warehousing_unit")
  977. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  978. return
  979. }
  980. warehousing_unit := items["warehousing_unit"].(string)
  981. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  982. utils.ErrorLog("last_price")
  983. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  984. return
  985. }
  986. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  987. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  988. utils.ErrorLog("new_price")
  989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  990. return
  991. }
  992. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  993. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  994. utils.ErrorLog("drug_id")
  995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  996. return
  997. }
  998. drug_id := int64(items["drug_id"].(float64))
  999. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1000. utils.ErrorLog("start_time")
  1001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1002. return
  1003. }
  1004. var startTime int64
  1005. start_time := items["start_time"].(string)
  1006. if len(start_time) > 0 {
  1007. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1008. if err != nil {
  1009. fmt.Println(err)
  1010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1011. return
  1012. }
  1013. startTime = theTime.Unix()
  1014. }
  1015. orgId := this.GetAdminUserInfo().CurrentOrgId
  1016. Creater := this.GetAdminUserInfo().AdminUser.Id
  1017. drugAdjust := models.XtDrugAdjustPrice{
  1018. DrugName: drug_name,
  1019. SpecificationName: specification_name,
  1020. WarehousingUnit: warehousing_unit,
  1021. LastPrice: last_price,
  1022. RetailPrice: retail_price,
  1023. NewPrice: new_price,
  1024. Manufacturer: manufacturer,
  1025. Dealer: dealer,
  1026. Remark: remark,
  1027. DrugId: drug_id,
  1028. UserOrgId: orgId,
  1029. Ctime: time.Now().Unix(),
  1030. Mtime: 0,
  1031. Status: 1,
  1032. WarehousingOrder: warehousing_order,
  1033. Number: number,
  1034. StartTime: startTime,
  1035. Creater: Creater,
  1036. Checker: 0,
  1037. CheckerStatus: 2,
  1038. CheckerTime: 0,
  1039. }
  1040. err := service.CreateDrugPrice(drugAdjust)
  1041. fmt.Println(err)
  1042. }
  1043. }
  1044. returnData := make(map[string]interface{}, 0)
  1045. returnData["msg"] = "ok"
  1046. this.ServeSuccessJSON(returnData)
  1047. return
  1048. }
  1049. func (this *SelfDrugApiController) GetDrugPriceList() {
  1050. timeLayout := "2006-01-02"
  1051. loc, _ := time.LoadLocation("Local")
  1052. dataBody := make(map[string]interface{}, 0)
  1053. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1054. fmt.Println(err)
  1055. orgId := this.GetAdminUserInfo().CurrentOrgId
  1056. keyword := this.GetString("keyword")
  1057. start_time := this.GetString("start_time")
  1058. end_time := this.GetString("end_time")
  1059. var startTime int64
  1060. if len(start_time) > 0 {
  1061. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1062. if err != nil {
  1063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1064. return
  1065. }
  1066. startTime = theTime.Unix()
  1067. }
  1068. var endTime int64
  1069. if len(end_time) > 0 {
  1070. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1071. if err != nil {
  1072. utils.ErrorLog(err.Error())
  1073. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1074. return
  1075. }
  1076. endTime = theTime.Unix()
  1077. }
  1078. limit, _ := this.GetInt64("limit")
  1079. page, _ := this.GetInt64("page")
  1080. list, total, err := service.GetDrugPriceList(startTime, endTime, orgId, keyword, limit, page)
  1081. doctorList, err := service.GetAllDoctorThree(orgId)
  1082. if err != nil {
  1083. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1084. return
  1085. }
  1086. this.ServeSuccessJSON(map[string]interface{}{
  1087. "total": total,
  1088. "list": list,
  1089. "doctorList": doctorList,
  1090. })
  1091. }
  1092. func (this *SelfDrugApiController) SaveCheckDrugPrice() {
  1093. timeLayout := "2006-01-02"
  1094. loc, _ := time.LoadLocation("Local")
  1095. dataBody := make(map[string]interface{}, 0)
  1096. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1097. fmt.Println(err)
  1098. idstr := this.GetString("ids")
  1099. ids := strings.Split(idstr, ",")
  1100. check_time := this.GetString("check_time")
  1101. var checkTime int64
  1102. if len(check_time) > 0 {
  1103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1104. if err != nil {
  1105. fmt.Println(err)
  1106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1107. return
  1108. }
  1109. checkTime = theTime.Unix()
  1110. }
  1111. checker, _ := this.GetInt64("checker")
  1112. adjustPrice := models.XtDrugAdjustPrice{
  1113. Checker: checker,
  1114. CheckerStatus: 1,
  1115. CheckerTime: checkTime,
  1116. }
  1117. err = service.UpdateDrugAdjuestPrice(ids, adjustPrice)
  1118. fmt.Println("err", err)
  1119. list, _ := service.GetDrugAdjuestPrice(ids)
  1120. for _, item := range list {
  1121. drug := models.BaseDrugLib{
  1122. RetailPrice: item.NewPrice,
  1123. LastPrice: item.NewPrice,
  1124. }
  1125. service.UpdateBaseDrugOne(drug, item.DrugId)
  1126. }
  1127. this.ServeSuccessJSON(map[string]interface{}{
  1128. "adjustPrice": adjustPrice,
  1129. })
  1130. }
  1131. func (this *SelfDrugApiController) SaveDrugDamage() {
  1132. timeLayout := "2006-01-02"
  1133. loc, _ := time.LoadLocation("Local")
  1134. dataBody := make(map[string]interface{}, 0)
  1135. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1136. fmt.Println(err)
  1137. tableData, _ := dataBody["tableData"].([]interface{})
  1138. fmt.Println("999939433443", tableData)
  1139. if len(tableData) > 0 {
  1140. for _, item := range tableData {
  1141. items := item.(map[string]interface{})
  1142. drug_name := items["drug_name"].(string)
  1143. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1144. utils.ErrorLog("drug_name")
  1145. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1146. return
  1147. }
  1148. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1149. utils.ErrorLog("retail_price")
  1150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1151. return
  1152. }
  1153. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1154. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1155. utils.ErrorLog("warehousing_order")
  1156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1157. return
  1158. }
  1159. warehousing_order := items["warehousing_order"].(string)
  1160. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1161. utils.ErrorLog("number")
  1162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1163. return
  1164. }
  1165. number := items["number"].(string)
  1166. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1167. utils.ErrorLog("dealer")
  1168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1169. return
  1170. }
  1171. dealer := items["dealer"].(string)
  1172. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1173. utils.ErrorLog("manufacturer")
  1174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1175. return
  1176. }
  1177. manufacturer := items["manufacturer"].(string)
  1178. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1179. utils.ErrorLog("specification_name")
  1180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1181. return
  1182. }
  1183. specification_name := items["specification_name"].(string)
  1184. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1185. utils.ErrorLog("remark")
  1186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1187. return
  1188. }
  1189. remark := items["remark"].(string)
  1190. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1191. utils.ErrorLog("warehousing_unit")
  1192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1193. return
  1194. }
  1195. warehousing_unit := items["warehousing_unit"].(string)
  1196. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1197. utils.ErrorLog("last_price")
  1198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1199. return
  1200. }
  1201. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1202. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1203. utils.ErrorLog("count")
  1204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. count := int64(items["count"].(float64))
  1208. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1209. utils.ErrorLog("new_price")
  1210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1211. return
  1212. }
  1213. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1214. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1215. utils.ErrorLog("drug_id")
  1216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1217. return
  1218. }
  1219. drug_id := int64(items["drug_id"].(float64))
  1220. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1221. utils.ErrorLog("start_time")
  1222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1223. return
  1224. }
  1225. var startTime int64
  1226. start_time := items["start_time"].(string)
  1227. if len(start_time) > 0 {
  1228. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1229. if err != nil {
  1230. fmt.Println(err)
  1231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1232. return
  1233. }
  1234. startTime = theTime.Unix()
  1235. }
  1236. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  1237. utils.ErrorLog("warehousing_info_id")
  1238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1239. return
  1240. }
  1241. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  1242. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1243. utils.ErrorLog("expiry_date")
  1244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1245. return
  1246. }
  1247. expiry_date := int64(items["expiry_date"].(float64))
  1248. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1249. utils.ErrorLog("product_date")
  1250. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1251. return
  1252. }
  1253. product_date := int64(items["product_date"].(float64))
  1254. if items["drug_origin_place"] == nil || reflect.TypeOf(items["drug_origin_place"]).String() != "string" {
  1255. utils.ErrorLog("drug_origin_place")
  1256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1257. return
  1258. }
  1259. drug_origin_place := items["drug_origin_place"].(string)
  1260. orgId := this.GetAdminUserInfo().CurrentOrgId
  1261. Creater := this.GetAdminUserInfo().AdminUser.Id
  1262. if items["stock_max_number"] == nil || reflect.TypeOf(items["stock_max_number"]).String() != "float64" {
  1263. utils.ErrorLog("stock_max_number")
  1264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1265. return
  1266. }
  1267. stock_max_number := int64(items["stock_max_number"].(float64))
  1268. if items["stock_min_number"] == nil || reflect.TypeOf(items["stock_min_number"]).String() != "float64" {
  1269. utils.ErrorLog("stock_min_number")
  1270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1271. return
  1272. }
  1273. stock_min_number := int64(items["stock_min_number"].(float64))
  1274. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1275. utils.ErrorLog("total")
  1276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1277. return
  1278. }
  1279. total := items["total"].(string)
  1280. drugDamage := models.XtDrugDamage{
  1281. DrugName: drug_name,
  1282. SpecificationName: specification_name,
  1283. WarehousingUnit: warehousing_unit,
  1284. Count: count,
  1285. LastPrice: last_price,
  1286. RetailPrice: retail_price,
  1287. NewPrice: new_price,
  1288. Manufacturer: manufacturer,
  1289. Dealer: dealer,
  1290. Remark: remark,
  1291. DrugId: drug_id,
  1292. UserOrgId: orgId,
  1293. Ctime: time.Now().Unix(),
  1294. Mtime: 0,
  1295. Status: 1,
  1296. WarehousingOrder: warehousing_order,
  1297. Number: number,
  1298. StartTime: startTime,
  1299. Creater: Creater,
  1300. Checker: 0,
  1301. CheckerStatus: 2,
  1302. CheckerTime: 0,
  1303. ExpiryDate: expiry_date,
  1304. ProductDate: product_date,
  1305. WarehousingInfoId: warehousing_info_id,
  1306. DrugOriginPlace: drug_origin_place,
  1307. StockMaxNumber: stock_max_number,
  1308. StockMinNumber: stock_min_number,
  1309. Total: total,
  1310. }
  1311. err := service.CreateDrugDamage(drugDamage)
  1312. fmt.Println(err)
  1313. }
  1314. }
  1315. returnData := make(map[string]interface{}, 0)
  1316. returnData["msg"] = "ok"
  1317. this.ServeSuccessJSON(returnData)
  1318. }
  1319. func (this *SelfDrugApiController) GetDrugDamageList() {
  1320. timeLayout := "2006-01-02"
  1321. loc, _ := time.LoadLocation("Local")
  1322. dataBody := make(map[string]interface{}, 0)
  1323. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1324. fmt.Println(err)
  1325. orgId := this.GetAdminUserInfo().CurrentOrgId
  1326. keyword := this.GetString("keyword")
  1327. start_time := this.GetString("start_time")
  1328. end_time := this.GetString("end_time")
  1329. storehouse_id, _ := this.GetInt64("storehouse_id")
  1330. var startTime int64
  1331. if len(start_time) > 0 {
  1332. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1333. if err != nil {
  1334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1335. return
  1336. }
  1337. startTime = theTime.Unix()
  1338. }
  1339. var endTime int64
  1340. if len(end_time) > 0 {
  1341. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1342. if err != nil {
  1343. utils.ErrorLog(err.Error())
  1344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. endTime = theTime.Unix()
  1348. }
  1349. limit, _ := this.GetInt64("limit")
  1350. page, _ := this.GetInt64("page")
  1351. list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page, storehouse_id)
  1352. damagelist, _ := service.GetDrugDamageByOrgId(orgId)
  1353. doctorList, err := service.GetAllDoctorThree(orgId)
  1354. houseList, _ := service.GetAllStoreHouseList(orgId)
  1355. if err != nil {
  1356. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1357. return
  1358. }
  1359. this.ServeSuccessJSON(map[string]interface{}{
  1360. "total": total,
  1361. "list": list,
  1362. "damagelist": damagelist,
  1363. "doctorList": doctorList,
  1364. "houseList": houseList,
  1365. })
  1366. }
  1367. func (this *SelfDrugApiController) SaveDrugDamagePrice() {
  1368. timeLayout := "2006-01-02"
  1369. loc, _ := time.LoadLocation("Local")
  1370. dataBody := make(map[string]interface{}, 0)
  1371. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1372. fmt.Println(err)
  1373. idstr := this.GetString("ids")
  1374. ids := strings.Split(idstr, ",")
  1375. check_time := this.GetString("check_time")
  1376. var checkTime int64
  1377. if len(check_time) > 0 {
  1378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1379. if err != nil {
  1380. fmt.Println(err)
  1381. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1382. return
  1383. }
  1384. checkTime = theTime.Unix()
  1385. }
  1386. checker, _ := this.GetInt64("checker")
  1387. damage := models.XtDrugDamage{
  1388. Checker: checker,
  1389. CheckerStatus: 1,
  1390. CheckerTime: checkTime,
  1391. }
  1392. err = service.UpdateDrugDamage(ids, damage)
  1393. fmt.Println(err)
  1394. list, _ := service.GetDrugDamage(ids)
  1395. ctime := time.Now().Unix()
  1396. adminUserInfo := this.GetAdminUserInfo()
  1397. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1398. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  1399. var manufacturer_id int64
  1400. var dealer_id int64
  1401. timeStr := time.Now().Format("2006-01-02")
  1402. timeArr := strings.Split(timeStr, "-")
  1403. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1404. total = total + 1
  1405. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1406. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1407. number = number + total
  1408. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1409. operation_time := time.Now().Unix()
  1410. creater := adminUserInfo.AdminUser.Id
  1411. warehouseOut := models.DrugWarehouseOut{
  1412. WarehouseOutOrderNumber: warehousing_out_order,
  1413. OperationTime: operation_time,
  1414. OrgId: adminUserInfo.CurrentOrgId,
  1415. Creater: creater,
  1416. Ctime: ctime,
  1417. Status: 1,
  1418. WarehouseOutTime: time.Now().Unix(),
  1419. Type: 1,
  1420. }
  1421. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1422. for _, item := range list {
  1423. for _, it := range manufacturerList {
  1424. if item.Manufacturer == it.ManufacturerName {
  1425. manufacturer_id = it.ID
  1426. }
  1427. }
  1428. for _, its := range dealerList {
  1429. if its.DealerName == item.Dealer {
  1430. dealer_id = its.ID
  1431. }
  1432. }
  1433. warehouseOutInfo := models.XtDrugWarehouseOutInfo{
  1434. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1435. WarehouseOutId: warehouseOut.ID,
  1436. DrugId: item.DrugId,
  1437. Count: item.Count,
  1438. Price: item.RetailPrice,
  1439. Status: 1,
  1440. Ctime: ctime,
  1441. Remark: item.Remark,
  1442. OrgId: adminUserInfo.CurrentOrgId,
  1443. Type: 1,
  1444. Manufacturer: manufacturer_id,
  1445. Dealer: dealer_id,
  1446. RetailPrice: item.RetailPrice,
  1447. CountUnit: item.WarehousingUnit,
  1448. ExpiryDate: item.ExpiryDate,
  1449. ProductDate: item.ProductDate,
  1450. Number: item.Number,
  1451. BatchNumber: item.BatchNumber,
  1452. IsSys: 0,
  1453. WarehouseInfoId: item.WarehousingInfoId,
  1454. }
  1455. drugflow := models.DrugFlow{
  1456. WarehouseOutId: warehouseOut.ID,
  1457. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1458. DrugId: item.DrugId,
  1459. Number: item.Number,
  1460. ProductDate: item.ProductDate,
  1461. ExpireDate: item.ExpiryDate,
  1462. Count: item.Count,
  1463. Price: item.RetailPrice,
  1464. Status: 1,
  1465. Ctime: ctime,
  1466. UserOrgId: adminUserInfo.CurrentOrgId,
  1467. Manufacturer: manufacturer_id,
  1468. Dealer: dealer_id,
  1469. BatchNumber: item.BatchNumber,
  1470. MaxUnit: item.WarehousingUnit,
  1471. ConsumableType: 5,
  1472. IsEdit: 1,
  1473. Creator: adminUserInfo.AdminUser.Id,
  1474. IsSys: 0,
  1475. }
  1476. service.CreateWareHouseOutInfo(&warehouseOutInfo)
  1477. service.CreateDrugFlowOne(drugflow)
  1478. info, _ := service.GetDrugByWarehouseInfo(item.WarehousingInfoId)
  1479. //扣减库存
  1480. warehouseInfo := models.XtDrugWarehouseInfo{
  1481. StockMaxNumber: info.StockMaxNumber - info.StockMaxNumber,
  1482. }
  1483. service.UpdateDrugWarehouseingInfo(item.WarehousingInfoId, warehouseInfo)
  1484. }
  1485. this.ServeSuccessJSON(map[string]interface{}{
  1486. "damage": damage,
  1487. })
  1488. }
  1489. func (this *SelfDrugApiController) GetDrugModifyPrice() {
  1490. id, _ := this.GetInt64("id")
  1491. detail, err := service.GetDrugModifyPrice(id)
  1492. fmt.Println(err)
  1493. this.ServeSuccessJSON(map[string]interface{}{
  1494. "detail": detail,
  1495. })
  1496. }
  1497. func (this *SelfDrugApiController) ModifyDrugPrice() {
  1498. drug_name := this.GetString("drug_name")
  1499. specification_name := this.GetString("specification_name")
  1500. warehousing_unit := this.GetString("warehousing_unit")
  1501. manufacturer := this.GetString("manufacturer")
  1502. number := this.GetString("number")
  1503. retailPrice := this.GetString("retail_price")
  1504. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1505. newPrice := this.GetString("new_price")
  1506. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1507. count, _ := this.GetInt64("count")
  1508. remark := this.GetString("remark")
  1509. id, _ := this.GetInt64("id")
  1510. drug_id, _ := this.GetInt64("drug_id")
  1511. adjustPrice := models.XtDrugAdjustPrice{
  1512. DrugName: drug_name,
  1513. Count: count,
  1514. RetailPrice: retail_price,
  1515. NewPrice: new_price,
  1516. Remark: remark,
  1517. SpecificationName: specification_name,
  1518. WarehousingUnit: warehousing_unit,
  1519. Manufacturer: manufacturer,
  1520. Number: number,
  1521. DrugId: drug_id,
  1522. }
  1523. err := service.ModifyDrugPrice(id, adjustPrice)
  1524. fmt.Println(err)
  1525. this.ServeSuccessJSON(map[string]interface{}{
  1526. "adjustPrice": adjustPrice,
  1527. })
  1528. }
  1529. func (this *SelfDrugApiController) GetModifyPricePrint() {
  1530. ids := this.GetString("ids")
  1531. idsSplit := strings.Split(ids, ",")
  1532. list, err := service.GetModifyPricePrint(idsSplit)
  1533. fmt.Println(err)
  1534. this.ServeSuccessJSON(map[string]interface{}{
  1535. "list": list,
  1536. })
  1537. }
  1538. func (this *SelfDrugApiController) GetDrugDamageDetail() {
  1539. id, _ := this.GetInt64("id")
  1540. detail, _ := service.GetDrugDamageDetail(id)
  1541. this.ServeSuccessJSON(map[string]interface{}{
  1542. "detail": detail,
  1543. })
  1544. }
  1545. func (this *SelfDrugApiController) ModifyDrugDamage() {
  1546. id, _ := this.GetInt64("id")
  1547. drug_id, _ := this.GetInt64("drug_id")
  1548. drug_name := this.GetString("drug_name")
  1549. drug_origin_place := this.GetString("drug_origin_place")
  1550. lastPrice := this.GetString("last_price")
  1551. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  1552. newPrice := this.GetString("new_price")
  1553. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1554. manufacturer := this.GetString("manufacturer")
  1555. number := this.GetString("number")
  1556. retailPrice := this.GetString("retail_price")
  1557. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1558. remark := this.GetString("remark")
  1559. count, _ := this.GetInt64("count")
  1560. warehousing_unit := this.GetString("warehousing_unit")
  1561. stock_max_number, _ := this.GetInt64("stock_max_number")
  1562. stock_min_number, _ := this.GetInt64("stock_min_number")
  1563. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  1564. damage := models.XtDrugDamage{
  1565. DrugName: drug_name,
  1566. SpecificationName: "",
  1567. WarehousingUnit: warehousing_unit,
  1568. Count: count,
  1569. LastPrice: last_price,
  1570. RetailPrice: retail_price,
  1571. NewPrice: new_price,
  1572. Manufacturer: manufacturer,
  1573. Dealer: "",
  1574. Remark: remark,
  1575. DrugId: drug_id,
  1576. Number: number,
  1577. StockMaxNumber: stock_max_number,
  1578. StockMinNumber: stock_min_number,
  1579. WarehousingInfoId: warehousing_info_id,
  1580. DrugOriginPlace: drug_origin_place,
  1581. }
  1582. err := service.ModifyDrugDamage(id, damage)
  1583. fmt.Println(err)
  1584. this.ServeSuccessJSON(map[string]interface{}{
  1585. "damage": damage,
  1586. })
  1587. }
  1588. func (this *SelfDrugApiController) DeleteDrugDamage() {
  1589. id, _ := this.GetInt64("id")
  1590. err := service.DeleteDrugDamage(id)
  1591. fmt.Println(err)
  1592. returnData := make(map[string]interface{}, 0)
  1593. returnData["msg"] = "ok"
  1594. this.ServeSuccessJSON(returnData)
  1595. }
  1596. func (this *SelfDrugApiController) GetDrugDamagePrint() {
  1597. idsSplit := this.GetString("ids")
  1598. ids := strings.Split(idsSplit, ",")
  1599. list, _ := service.GetDrugDamagePrint(ids)
  1600. this.ServeSuccessJSON(map[string]interface{}{
  1601. "list": list,
  1602. })
  1603. }
  1604. func (this *SelfDrugApiController) GetWarehoseInfoById() {
  1605. id, _ := this.GetInt64("id")
  1606. storehouse_id, _ := this.GetInt64("storehouse_id")
  1607. orgId := this.GetAdminUserInfo().CurrentOrgId
  1608. list, _ := service.GetWarehoseInfoById(id, storehouse_id, orgId)
  1609. this.ServeSuccessJSON(map[string]interface{}{
  1610. "list": list,
  1611. })
  1612. }
  1613. func (this *SelfDrugApiController) SaveDrugInventory() {
  1614. timeLayout := "2006-01-02"
  1615. loc, _ := time.LoadLocation("Local")
  1616. dataBody := make(map[string]interface{}, 0)
  1617. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1618. fmt.Println(err)
  1619. tableData, _ := dataBody["tableData"].([]interface{})
  1620. if len(tableData) > 0 {
  1621. for _, item := range tableData {
  1622. items := item.(map[string]interface{})
  1623. drug_name := items["drug_name"].(string)
  1624. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1625. utils.ErrorLog("drug_name")
  1626. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1627. return
  1628. }
  1629. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1630. utils.ErrorLog("retail_price")
  1631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1632. return
  1633. }
  1634. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1635. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1636. utils.ErrorLog("warehousing_order")
  1637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. warehousing_order := items["warehousing_order"].(string)
  1641. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1642. utils.ErrorLog("dealer")
  1643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. return
  1645. }
  1646. dealer := items["dealer"].(string)
  1647. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1648. utils.ErrorLog("manufacturer")
  1649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1650. return
  1651. }
  1652. manufacturer := items["manufacturer"].(string)
  1653. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1654. utils.ErrorLog("specification_name")
  1655. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. specification_name := items["specification_name"].(string)
  1659. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1660. utils.ErrorLog("remark")
  1661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1662. return
  1663. }
  1664. remark := items["remark"].(string)
  1665. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1666. utils.ErrorLog("warehousing_unit")
  1667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1668. return
  1669. }
  1670. warehousing_unit := items["warehousing_unit"].(string)
  1671. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1672. utils.ErrorLog("last_price")
  1673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1674. return
  1675. }
  1676. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1677. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1678. utils.ErrorLog("count")
  1679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1680. return
  1681. }
  1682. count := int64(items["count"].(float64))
  1683. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1684. utils.ErrorLog("new_price")
  1685. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1686. return
  1687. }
  1688. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1689. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1690. utils.ErrorLog("drug_id")
  1691. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1692. return
  1693. }
  1694. drug_id := int64(items["drug_id"].(float64))
  1695. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1696. utils.ErrorLog("start_time")
  1697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1698. return
  1699. }
  1700. var startTime int64
  1701. start_time := items["start_time"].(string)
  1702. if len(start_time) > 0 {
  1703. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1704. if err != nil {
  1705. fmt.Println(err)
  1706. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1707. return
  1708. }
  1709. startTime = theTime.Unix()
  1710. }
  1711. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1712. utils.ErrorLog("product_date")
  1713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1714. return
  1715. }
  1716. product_date := int64(items["product_date"].(float64))
  1717. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1718. utils.ErrorLog("expiry_date")
  1719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1720. return
  1721. }
  1722. expiry_date := int64(items["expiry_date"].(float64))
  1723. orgId := this.GetAdminUserInfo().CurrentOrgId
  1724. Creater := this.GetAdminUserInfo().AdminUser.Id
  1725. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1726. utils.ErrorLog("number")
  1727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1728. return
  1729. }
  1730. numbers := items["number"].(string)
  1731. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1732. utils.ErrorLog("warehouse_info_id")
  1733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1734. return
  1735. }
  1736. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1737. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1738. utils.ErrorLog("total")
  1739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1740. return
  1741. }
  1742. total := items["total"].(string)
  1743. drug_origin_place := items["drug_origin_place"].(string)
  1744. min_count := int64(items["min_count"].(float64))
  1745. min_unit := items["min_unit"].(string)
  1746. inventory := models.XtDrugInventory{
  1747. DrugName: drug_name,
  1748. SpecificationName: specification_name,
  1749. WarehousingUnit: warehousing_unit,
  1750. Count: count,
  1751. LastPrice: last_price,
  1752. RetailPrice: retail_price,
  1753. NewPrice: new_price,
  1754. Manufacturer: manufacturer,
  1755. Dealer: dealer,
  1756. Remark: remark,
  1757. DrugId: drug_id,
  1758. UserOrgId: orgId,
  1759. Ctime: time.Now().Unix(),
  1760. Mtime: 0,
  1761. Status: 1,
  1762. WarehousingOrder: warehousing_order,
  1763. LicenseNumber: "",
  1764. StartTime: startTime,
  1765. Creater: Creater,
  1766. Checker: 0,
  1767. CheckerStatus: 2,
  1768. CheckerTime: 0,
  1769. ExpiryDate: expiry_date,
  1770. ProductDate: product_date,
  1771. Number: numbers,
  1772. //BatchNumber: batch_number,
  1773. Total: total,
  1774. WarehouseInfoId: warehouse_info_id,
  1775. DrugOriginPlace: drug_origin_place,
  1776. MinUnit: min_unit,
  1777. MinCount: min_count,
  1778. }
  1779. err = service.CreateDrugInventory(inventory)
  1780. fmt.Println(err)
  1781. }
  1782. }
  1783. this.ServeSuccessJSON(map[string]interface{}{
  1784. "msg": "msg",
  1785. })
  1786. }
  1787. func (this *SelfDrugApiController) GetDrugInventoryList() {
  1788. timeLayout := "2006-01-02"
  1789. loc, _ := time.LoadLocation("Local")
  1790. dataBody := make(map[string]interface{}, 0)
  1791. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1792. fmt.Println(err)
  1793. orgId := this.GetAdminUserInfo().CurrentOrgId
  1794. keyword := this.GetString("keyword")
  1795. start_time := this.GetString("start_time")
  1796. end_time := this.GetString("end_time")
  1797. var startTime int64
  1798. if len(start_time) > 0 {
  1799. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1800. if err != nil {
  1801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1802. return
  1803. }
  1804. startTime = theTime.Unix()
  1805. }
  1806. var endTime int64
  1807. if len(end_time) > 0 {
  1808. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1809. if err != nil {
  1810. utils.ErrorLog(err.Error())
  1811. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1812. return
  1813. }
  1814. endTime = theTime.Unix()
  1815. }
  1816. limit, _ := this.GetInt64("limit")
  1817. page, _ := this.GetInt64("page")
  1818. list, total, err := service.GetDrugInventoryList(keyword, page, limit, orgId, startTime, endTime)
  1819. doctorList, _ := service.GetAllDoctorThree(orgId)
  1820. houseList, _ := service.GetAllStoreHouseList(orgId)
  1821. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1822. if err != nil {
  1823. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1824. return
  1825. }
  1826. this.ServeSuccessJSON(map[string]interface{}{
  1827. "total": total,
  1828. "list": list,
  1829. "doctorList": doctorList,
  1830. "houseList": houseList,
  1831. "houseConfig": houseConfig,
  1832. })
  1833. }
  1834. func (this *SelfDrugApiController) SaveDrugCheckInventory() {
  1835. timeLayout := "2006-01-02"
  1836. loc, _ := time.LoadLocation("Local")
  1837. dataBody := make(map[string]interface{}, 0)
  1838. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1839. fmt.Println(err)
  1840. idstr := this.GetString("ids")
  1841. ids := strings.Split(idstr, ",")
  1842. check_time := this.GetString("check_time")
  1843. var checkTime int64
  1844. if len(check_time) > 0 {
  1845. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1846. if err != nil {
  1847. fmt.Println(err)
  1848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1849. return
  1850. }
  1851. checkTime = theTime.Unix()
  1852. }
  1853. checker, _ := this.GetInt64("checker")
  1854. inventory := models.XtDrugInventory{
  1855. Checker: checker,
  1856. CheckerStatus: 1,
  1857. CheckerTime: checkTime,
  1858. }
  1859. err = service.UpdateDrugInventory(ids, inventory)
  1860. fmt.Println(err)
  1861. list, _ := service.GetDrugInventoryListByIds(ids)
  1862. adminUserInfo := this.GetAdminUserInfo()
  1863. var stock_total int64
  1864. var proof_count int64
  1865. var maxNumber int64
  1866. var minNumber int64
  1867. for _, item := range list {
  1868. //查询药品信息
  1869. drug, _ := service.GetDrugDetailByDrugId(item.DrugId)
  1870. //查询库存
  1871. info, _ := service.GetDrugWareInfoByIdTwo(item.WarehouseInfoId)
  1872. var max_count int64
  1873. var min_count int64
  1874. for _, it := range info {
  1875. max_count += it.StockMaxNumber
  1876. min_count += it.StockMinNumber
  1877. }
  1878. //获取最晚的库存数量
  1879. lastInfo, _ := service.GetLastDrugWarehouseInfo(item.DrugId)
  1880. firstInfo, _ := service.GetFirstDrugWarehouseInfo(item.DrugId)
  1881. stock_total = max_count*drug.MinNumber + min_count
  1882. proof_count = item.Count*drug.MinNumber + item.MinCount
  1883. fmt.Println("stock_total", stock_total)
  1884. fmt.Println("proof_count", proof_count)
  1885. //判断 如果库存数量 大于盘点库存,则出库
  1886. if stock_total > proof_count {
  1887. minNumber = (stock_total - proof_count) % drug.MinNumber
  1888. maxNumber = (stock_total - proof_count) / drug.MinNumber
  1889. ctime := time.Now().Unix()
  1890. timeStr := time.Now().Format("2006-01-02")
  1891. timeArr := strings.Split(timeStr, "-")
  1892. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1893. total = total + 1
  1894. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1895. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1896. number = number + total
  1897. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1898. operation_time := time.Now().Unix()
  1899. creater := adminUserInfo.AdminUser.Id
  1900. warehouseOut := models.DrugWarehouseOut{
  1901. WarehouseOutOrderNumber: warehousing_out_order,
  1902. OperationTime: operation_time,
  1903. OrgId: adminUserInfo.CurrentOrgId,
  1904. Creater: creater,
  1905. Ctime: ctime,
  1906. Status: 1,
  1907. WarehouseOutTime: ctime,
  1908. Type: 1,
  1909. }
  1910. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1911. warehouse, _ := service.GetLastDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1912. warehouseOutInfo := models.DrugWarehouseOutInfo{
  1913. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1914. WarehouseOutId: warehouse.ID,
  1915. DrugId: item.DrugId,
  1916. Count: maxNumber,
  1917. Price: firstInfo.Price,
  1918. TotalPrice: firstInfo.TotalPrice,
  1919. Status: 1,
  1920. Ctime: ctime,
  1921. Remark: item.Remark,
  1922. OrgId: adminUserInfo.CurrentOrgId,
  1923. Type: 1,
  1924. Manufacturer: firstInfo.Manufacturer,
  1925. Dealer: firstInfo.Dealer,
  1926. RetailPrice: firstInfo.RetailPrice,
  1927. RetailTotalPrice: firstInfo.RetailTotalPrice,
  1928. CountUnit: drug.MaxUnit,
  1929. ExpiryDate: firstInfo.ExpiryDate,
  1930. ProductDate: firstInfo.ProductDate,
  1931. Number: firstInfo.Number,
  1932. BatchNumber: firstInfo.BatchNumber,
  1933. IsSys: 0,
  1934. WarehouseInfoId: firstInfo.ID,
  1935. }
  1936. drugflow := models.DrugFlow{
  1937. WarehouseOutId: warehouseOut.ID,
  1938. WarehouseOutOrderNumber: warehousing_out_order,
  1939. DrugId: item.DrugId,
  1940. Number: firstInfo.Number,
  1941. ProductDate: firstInfo.ProductDate,
  1942. ExpireDate: firstInfo.ExpiryDate,
  1943. Count: maxNumber,
  1944. Price: firstInfo.Price,
  1945. Status: 1,
  1946. Ctime: ctime,
  1947. UserOrgId: adminUserInfo.CurrentOrgId,
  1948. Manufacturer: firstInfo.Manufacturer,
  1949. Dealer: firstInfo.Dealer,
  1950. BatchNumber: firstInfo.BatchNumber,
  1951. MaxUnit: drug.MaxUnit,
  1952. ConsumableType: 2,
  1953. IsEdit: 1,
  1954. Creator: adminUserInfo.AdminUser.Id,
  1955. IsSys: 0,
  1956. }
  1957. service.CreateDrugWarehouseOutInfo(warehouseOutInfo)
  1958. service.CreateDrugFlowOne(drugflow)
  1959. //扣减当前批次号的库存
  1960. var total_count int64
  1961. //查询当前批次库存的数量
  1962. warehosueInfoList, _ := service.GetCurrentWarehosueInfo(item.WarehouseInfoId)
  1963. fmt.Println(warehosueInfoList)
  1964. for _, item := range warehosueInfoList {
  1965. total_count += item.StockMaxNumber*drug.MinNumber + item.StockMinNumber
  1966. }
  1967. //判断当前批次库存 和 需要出库的数据
  1968. //出库
  1969. if proof_count <= total_count {
  1970. //var total_count_one int64
  1971. //获取当前批次号的库存
  1972. //warehouseinfoOne, _ := service.GetCurrentWarehosueInfoOne(item.WarehouseInfoId)
  1973. //total_count_one = warehouseinfoOne.StockMaxNumber * drug.MinNumber + warehouseinfoOne.StockMinNumber
  1974. }
  1975. //报错提示
  1976. if proof_count > total_count {
  1977. this.ServeSuccessJSON(map[string]interface{}{
  1978. "msg": "1",
  1979. })
  1980. }
  1981. }
  1982. //判断 如果库存数量 小于于盘点库存,则入库
  1983. fmt.Println("stock_total2332322323223", stock_total, proof_count)
  1984. if stock_total < proof_count {
  1985. maxNumber = (proof_count - stock_total) / drug.MinNumber
  1986. minNumber = (proof_count - stock_total) % drug.MinNumber
  1987. fmt.Println("min_number23233232323223322323", minNumber)
  1988. ctime := time.Now().Unix()
  1989. timeStr := time.Now().Format("2006-01-02")
  1990. timeArr := strings.Split(timeStr, "-")
  1991. total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
  1992. total = total + 1
  1993. fmt.Println("total2323232323232", total)
  1994. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1995. operation_time := time.Now().Unix()
  1996. creater := adminUserInfo.AdminUser.Id
  1997. warehousing := models.DrugWarehouse{
  1998. WarehousingOrder: warehousing_order,
  1999. OperationTime: operation_time,
  2000. OrgId: adminUserInfo.CurrentOrgId,
  2001. Creater: creater,
  2002. Ctime: ctime,
  2003. Status: 1,
  2004. WarehousingTime: ctime,
  2005. Type: 1,
  2006. }
  2007. service.AddSigleDrugWarehouse(&warehousing)
  2008. warehouse, _ := service.GetLastDrugWarehouse(adminUserInfo.CurrentOrgId)
  2009. warehouseInfo := models.DrugWarehouseInfo{
  2010. WarehousingOrder: warehousing.WarehousingOrder,
  2011. WarehousingId: warehouse.ID,
  2012. DrugId: item.DrugId,
  2013. Number: lastInfo.Number,
  2014. ProductDate: lastInfo.ProductDate,
  2015. ExpiryDate: lastInfo.ExpiryDate,
  2016. WarehousingCount: maxNumber,
  2017. Price: lastInfo.Price,
  2018. TotalPrice: lastInfo.TotalPrice,
  2019. Status: 1,
  2020. Ctime: ctime,
  2021. Remark: item.Remark,
  2022. OrgId: adminUserInfo.CurrentOrgId,
  2023. Type: 1,
  2024. Manufacturer: lastInfo.Manufacturer,
  2025. Dealer: lastInfo.Dealer,
  2026. StockMaxNumber: maxNumber,
  2027. StockMinNumber: minNumber,
  2028. RetailTotalPrice: lastInfo.RetailTotalPrice,
  2029. BatchNumber: lastInfo.BatchNumber,
  2030. MaxUnit: drug.MaxUnit,
  2031. MinUnit: drug.MinUnit,
  2032. WarehousingInfoId: item.WarehouseInfoId,
  2033. }
  2034. drugflow := models.DrugFlow{
  2035. WarehousingOrder: warehousing.WarehousingOrder,
  2036. WarehousingId: warehouse.ID,
  2037. DrugId: item.DrugId,
  2038. Number: lastInfo.Number,
  2039. ProductDate: lastInfo.ProductDate,
  2040. ExpireDate: lastInfo.ExpiryDate,
  2041. Count: maxNumber,
  2042. Price: lastInfo.Price,
  2043. Status: 1,
  2044. Ctime: ctime,
  2045. UserOrgId: adminUserInfo.CurrentOrgId,
  2046. Manufacturer: lastInfo.Manufacturer,
  2047. Dealer: lastInfo.Dealer,
  2048. BatchNumber: lastInfo.BatchNumber,
  2049. MaxUnit: drug.MaxUnit,
  2050. MinUnit: drug.MinUnit,
  2051. ConsumableType: 1,
  2052. IsEdit: 1,
  2053. Creator: adminUserInfo.AdminUser.Id,
  2054. IsSys: 0,
  2055. }
  2056. service.CreateDrugWarehouseInfo(warehouseInfo)
  2057. service.CreateDrugFlowOne(drugflow)
  2058. }
  2059. }
  2060. returnData := make(map[string]interface{}, 0)
  2061. returnData["msg"] = "ok"
  2062. this.ServeSuccessJSON(returnData)
  2063. }
  2064. func (this *SelfDrugApiController) GetDrugInventoryDetail() {
  2065. id, _ := this.GetInt64("id")
  2066. detail, err := service.GetDrugInventoryDetail(id)
  2067. if err != nil {
  2068. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2069. return
  2070. }
  2071. this.ServeSuccessJSON(map[string]interface{}{
  2072. "detail": detail,
  2073. })
  2074. }
  2075. func (this *SelfDrugApiController) ModifyInventory() {
  2076. id, _ := this.GetInt64("id")
  2077. drug_id, _ := this.GetInt64("drug_id")
  2078. drug_name := this.GetString("drug_name")
  2079. specification_name := this.GetString("specification_name")
  2080. retailPrice := this.GetString("retail_price")
  2081. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  2082. warehousing_order := this.GetString("warehousing_order")
  2083. number := this.GetString("number")
  2084. manufacturer := this.GetString("manufacturer")
  2085. remark := this.GetString("remark")
  2086. warehousing_unit := this.GetString("warehousing_unit")
  2087. total := this.GetString("total")
  2088. lastPrice := this.GetString("last_price")
  2089. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  2090. count, _ := this.GetInt64("count")
  2091. drug_origin_place := this.GetString("drug_origin_place")
  2092. stock_max_number, _ := this.GetInt64("stock_max_number")
  2093. stock_min_number, _ := this.GetInt64("stock_min_number")
  2094. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2095. min_count, _ := this.GetInt64("min_count")
  2096. min_unit := this.GetString("min_unit")
  2097. inventory := models.XtDrugInventory{
  2098. DrugName: drug_name,
  2099. SpecificationName: specification_name,
  2100. WarehousingUnit: warehousing_unit,
  2101. Count: count,
  2102. LastPrice: last_price,
  2103. RetailPrice: retail_price,
  2104. Manufacturer: manufacturer,
  2105. Remark: remark,
  2106. DrugId: drug_id,
  2107. WarehousingOrder: warehousing_order,
  2108. Number: number,
  2109. Total: total,
  2110. DrugOriginPlace: drug_origin_place,
  2111. StockMaxNumber: stock_max_number,
  2112. StockMinNumber: stock_min_number,
  2113. WarehouseInfoId: warehouse_info_id,
  2114. MinCount: min_count,
  2115. MinUnit: min_unit,
  2116. }
  2117. err := service.ModifyDrugInventory(id, inventory)
  2118. if err != nil {
  2119. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2120. return
  2121. }
  2122. this.ServeSuccessJSON(map[string]interface{}{
  2123. "inventory": inventory,
  2124. })
  2125. }
  2126. func (this *SelfDrugApiController) DeleteDrugInventory() {
  2127. id, _ := this.GetInt64("id")
  2128. err := service.DeleteDrugInventory(id)
  2129. fmt.Println(err)
  2130. returnData := make(map[string]interface{}, 0)
  2131. returnData["msg"] = "ok"
  2132. this.ServeSuccessJSON(returnData)
  2133. }
  2134. func (this *SelfDrugApiController) GetDrugInventoryPrintList() {
  2135. ids := this.GetString("ids")
  2136. idssplit := strings.Split(ids, ",")
  2137. list, err := service.GetDrugInventoryPrintList(idssplit)
  2138. if err != nil {
  2139. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2140. return
  2141. }
  2142. this.ServeSuccessJSON(map[string]interface{}{
  2143. "list": list,
  2144. })
  2145. }
  2146. func (this *SelfDrugApiController) GetDrugInventoryDetailList() {
  2147. keyword := this.GetString("keyword")
  2148. limit, _ := this.GetInt64("limit")
  2149. page, _ := this.GetInt64("page")
  2150. storehouse_id, _ := this.GetInt64("storehouse_id")
  2151. orgId := this.GetAdminUserInfo().CurrentOrgId
  2152. appId := this.GetAdminUserInfo().CurrentAppId
  2153. list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId, storehouse_id)
  2154. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  2155. houseList, _ := service.GetAllStoreHouseList(orgId)
  2156. doctorList, _ := service.GetAllDoctorListSix(orgId, appId)
  2157. if err != nil {
  2158. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2159. return
  2160. }
  2161. this.ServeSuccessJSON(map[string]interface{}{
  2162. "total": total,
  2163. "list": list,
  2164. "doctorList": doctorList,
  2165. "houseList": houseList,
  2166. "inventoryList": inventoryList,
  2167. })
  2168. }
  2169. func (this *SelfDrugApiController) SaveDrugProofInventory() {
  2170. id, _ := this.GetInt64("id")
  2171. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2172. warehousing_unit := this.GetString("warehousing_unit")
  2173. remark := this.GetString("remark")
  2174. proof_count, _ := this.GetInt64("proof_count")
  2175. inventory := models.XtDrugInventory{
  2176. WarehouseInfoId: warehouse_info_id,
  2177. ProofCount: proof_count,
  2178. WarehousingUnit: warehousing_unit,
  2179. Remark: remark,
  2180. }
  2181. err := service.UpdateDrugProofInventory(id, &inventory)
  2182. info := models.XtDrugWarehouseInfo{
  2183. StockMaxNumber: proof_count,
  2184. }
  2185. service.UpdateDrugWarehouseInfoById(warehouse_info_id, &info)
  2186. if err != nil {
  2187. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2188. return
  2189. }
  2190. this.ServeSuccessJSON(map[string]interface{}{
  2191. "inventory": inventory,
  2192. })
  2193. }
  2194. func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
  2195. id, _ := this.GetInt64("id")
  2196. list, _ := service.GetDrugWarehouseInfoTotal(id)
  2197. this.ServeSuccessJSON(map[string]interface{}{
  2198. "list": list,
  2199. })
  2200. }
  2201. //新改造
  2202. func (this *SelfDrugApiController) SaveInventoryList() {
  2203. dataBody := make(map[string]interface{}, 0)
  2204. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2205. fmt.Println(err)
  2206. tableData, _ := dataBody["tableData"].([]interface{})
  2207. if len(tableData) > 0 {
  2208. for _, item := range tableData {
  2209. items := item.(map[string]interface{})
  2210. drug_name := items["drug_name"].(string)
  2211. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  2212. utils.ErrorLog("drug_name")
  2213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2214. return
  2215. }
  2216. fmt.Println("drug_name", drug_name)
  2217. specification_name := items["specification_name"].(string)
  2218. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  2219. utils.ErrorLog("specification_name")
  2220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2221. return
  2222. }
  2223. max_unit := items["max_unit"].(string)
  2224. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  2225. utils.ErrorLog("max_unit")
  2226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2227. return
  2228. }
  2229. min_unit := items["min_unit"].(string)
  2230. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  2231. utils.ErrorLog("min_unit")
  2232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2233. return
  2234. }
  2235. drug_id := int64(items["drug_id"].(float64))
  2236. min_number := int64(items["min_number"].(float64))
  2237. stock_max_number := int64(items["stock_max_number"].(float64))
  2238. stock_min_number := int64(items["stock_min_number"].(float64))
  2239. last_stock_max_number := int64(items["last_stock_max_number"].(float64))
  2240. last_stock_min_number := int64(items["last_stock_min_number"].(float64))
  2241. warehousing_order := items["warehousing_order"].(string)
  2242. price := items["price"].(float64)
  2243. manufacturer_name := items["manufacturer_name"].(string)
  2244. batch_number := items["batch_number"].(string)
  2245. id := int64(items["id"].(float64))
  2246. orgId := this.GetAdminUserInfo().CurrentOrgId
  2247. type_id := int64(items["type"].(float64))
  2248. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  2249. utils.ErrorLog("expiry_date")
  2250. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2251. return
  2252. }
  2253. expiry_date := int64(items["expiry_date"].(float64))
  2254. manufacturer := int64(items["manufacturer"].(float64))
  2255. storehouse_id := int64(items["storehouse_id"].(float64))
  2256. timeLayout := "2006-01-02"
  2257. loc, _ := time.LoadLocation("Local")
  2258. timeNow := time.Now().Format("2006-01-02")
  2259. locationTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeNow+" 00:00:00", loc)
  2260. var consumable_type int64
  2261. var consumable_count int64
  2262. var ord_total int64
  2263. var new_total int64
  2264. var total int64
  2265. ord_total = stock_max_number*min_number + stock_min_number
  2266. new_total = last_stock_max_number*min_number + last_stock_min_number
  2267. medical, _ := service.GetBaseDrugMedical(drug_id)
  2268. //改变库存
  2269. info := models.DrugWarehouseInfo{
  2270. DrugId: drug_id,
  2271. StockMaxNumber: last_stock_max_number,
  2272. StockMinNumber: last_stock_min_number,
  2273. WarehousingCount: last_stock_max_number,
  2274. MaxUnit: max_unit,
  2275. MinUnit: min_unit,
  2276. }
  2277. drugInfo, _ := service.GetCurrentWarehosueInfoOne(id)
  2278. if drugInfo.MaxUnit == medical.MaxUnit {
  2279. total = drugInfo.WarehousingCount * medical.MinNumber
  2280. }
  2281. if drugInfo.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2282. total = drugInfo.WarehousingCount
  2283. }
  2284. //如果库存数据大于盘点数据,则减去数量
  2285. if ord_total > new_total {
  2286. consumable_type = 11
  2287. consumable_count = ord_total - new_total
  2288. err = service.ModifyDrugWarehouseInfo(&info, id)
  2289. }
  2290. //如果库存数据小于盘点数据,则增加数量
  2291. if ord_total < new_total && new_total <= total {
  2292. consumable_type = 10
  2293. consumable_count = new_total - ord_total
  2294. err = service.ModifyDrugWarehouseInfo(&info, id)
  2295. }
  2296. if ord_total < new_total && new_total > total {
  2297. consumable_type = 10
  2298. consumable_count = new_total - ord_total
  2299. err = service.ModifyDrugWarehouseInfoSix(&info, id)
  2300. }
  2301. //查询默认仓库
  2302. houseConfig, _ := service.GetAllStoreHouseConfig(drugInfo.OrgId)
  2303. //查询默认仓库剩余多少库存
  2304. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, drugInfo.OrgId, drugInfo.DrugId)
  2305. var sum_count int64
  2306. var sum_in_count int64
  2307. for _, it := range list {
  2308. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2309. if it.MaxUnit == baseDrug.MaxUnit {
  2310. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2311. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2312. }
  2313. sum_count += it.StockMaxNumber + it.StockMinNumber
  2314. sum_in_count += it.WarehousingCount
  2315. }
  2316. service.UpdateMedicalSumCount(drugInfo.DrugId, sum_count, sum_in_count, drugInfo.OrgId)
  2317. //更新剩余库存
  2318. service.UpdateDrugStockCount(drugInfo.DrugId, drugInfo.OrgId, houseConfig.DrugStorehouseOut, sum_count)
  2319. inventory := models.XtDrugInventory{
  2320. DrugName: drug_name,
  2321. SpecificationName: specification_name,
  2322. WarehousingUnit: max_unit,
  2323. Count: consumable_count,
  2324. LastPrice: price,
  2325. RetailPrice: 0,
  2326. NewPrice: 0,
  2327. Manufacturer: manufacturer_name,
  2328. Dealer: "",
  2329. Remark: "",
  2330. DrugId: drug_id,
  2331. UserOrgId: orgId,
  2332. Ctime: time.Now().Unix(),
  2333. Mtime: 0,
  2334. Status: 1,
  2335. WarehousingOrder: warehousing_order,
  2336. LicenseNumber: "",
  2337. StartTime: locationTime.Unix(),
  2338. Creater: this.GetAdminUserInfo().AdminUser.Id,
  2339. Checker: 0,
  2340. CheckerStatus: 0,
  2341. CheckerTime: 0,
  2342. ExpiryDate: expiry_date,
  2343. ProductDate: 0,
  2344. Number: "",
  2345. BatchNumber: batch_number,
  2346. Total: "",
  2347. DrugOriginPlace: "",
  2348. WarehouseInfoId: id,
  2349. ProofCount: 0,
  2350. StockMaxNumber: stock_max_number,
  2351. StockMinNumber: stock_min_number,
  2352. MinCount: 0,
  2353. MinUnit: min_unit,
  2354. LastStockMaxNumber: last_stock_max_number,
  2355. LastStockMinNumber: last_stock_min_number,
  2356. InventoryType: consumable_type,
  2357. Type: type_id,
  2358. StorehouseId: storehouse_id,
  2359. }
  2360. err = service.CreateDrugInventory(inventory)
  2361. flow := models.DrugFlow{
  2362. WarehousingId: id,
  2363. DrugId: drug_id,
  2364. Number: "",
  2365. BatchNumber: batch_number,
  2366. Count: consumable_count,
  2367. UserOrgId: orgId,
  2368. PatientId: 0,
  2369. SystemTime: locationTime.Unix(),
  2370. ConsumableType: consumable_type,
  2371. IsSys: 1,
  2372. WarehousingOrder: warehousing_order,
  2373. WarehouseOutId: 0,
  2374. WarehouseOutOrderNumber: "",
  2375. IsEdit: 0,
  2376. CancelStockId: 0,
  2377. CancelOrderNumber: "",
  2378. Manufacturer: manufacturer,
  2379. Dealer: 0,
  2380. Creator: this.GetAdminUserInfo().AdminUser.Id,
  2381. UpdateCreator: 0,
  2382. Status: 1,
  2383. Ctime: time.Now().Unix(),
  2384. Mtime: 0,
  2385. Price: price,
  2386. WarehousingDetailId: id,
  2387. WarehouseOutDetailId: 0,
  2388. CancelOutDetailId: 0,
  2389. ExpireDate: expiry_date,
  2390. ProductDate: 0,
  2391. MaxUnit: min_unit,
  2392. MinUnit: min_unit,
  2393. StorehouseId: storehouse_id,
  2394. OverCount: sum_count,
  2395. }
  2396. if ord_total != new_total {
  2397. service.CreateDrugFlowOne(flow)
  2398. }
  2399. if err != nil {
  2400. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2401. return
  2402. }
  2403. this.ServeSuccessJSON(map[string]interface{}{
  2404. "inventory": inventory,
  2405. })
  2406. }
  2407. }
  2408. }
  2409. func (this *SelfDrugApiController) GetDamageByDrugId() {
  2410. drug_id, _ := this.GetInt64("drug_id")
  2411. warehousing_order := this.GetString("warehouseing_order")
  2412. drug_type, _ := this.GetInt64("type")
  2413. list, err := service.GetDamageByDrugId(drug_id, warehousing_order, drug_type)
  2414. if err != nil {
  2415. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2416. return
  2417. }
  2418. this.ServeSuccessJSON(map[string]interface{}{
  2419. "list": list,
  2420. })
  2421. }
  2422. func (this *SelfDrugApiController) GetInventoryModeList() {
  2423. orgId := this.GetAdminUserInfo().CurrentOrgId
  2424. list, err := service.GetInventoryModeList(orgId)
  2425. manufacturerList, err := service.GetAllManufacturerList(orgId)
  2426. if err != nil {
  2427. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2428. return
  2429. }
  2430. this.ServeSuccessJSON(map[string]interface{}{
  2431. "list": list,
  2432. "manufacturerList": manufacturerList,
  2433. })
  2434. }
  2435. // 库存优化接口
  2436. func (this *SelfDrugApiController) GetStorehouseList() {
  2437. orgId := this.GetAdminUserInfo().CurrentOrgId
  2438. list, err := service.GetAllStoreHouseList(orgId)
  2439. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  2440. goodType, _ := service.GetAllNewGoodType(orgId)
  2441. patientList, _ := service.GetAllpatientThirty(orgId)
  2442. dealerList, _ := service.GetAllDealerList(orgId)
  2443. if err != nil {
  2444. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取仓库失败")
  2445. return
  2446. }
  2447. this.ServeSuccessJSON(map[string]interface{}{
  2448. "list": list,
  2449. "manufacturerList": manufacturerList,
  2450. "goodTypeList": goodType,
  2451. "patientList": patientList,
  2452. "dealerList": dealerList,
  2453. })
  2454. }
  2455. func (this *SelfDrugApiController) GetGoodNewQuery() {
  2456. orgId := this.GetAdminUserInfo().CurrentOrgId
  2457. storehouse_id, _ := this.GetInt64("storehouse_id")
  2458. good_type, _ := this.GetInt64("good_type")
  2459. keyword := this.GetString("keyword")
  2460. page, _ := this.GetInt64("page")
  2461. limit, _ := this.GetInt64("limit")
  2462. // 查询该机构所有耗材入库信息
  2463. //goodList, _ := service.GetAllGoodListSeven(orgId)
  2464. //
  2465. //for _, it := range goodList {
  2466. // var sum_total int64
  2467. // //查询该耗材入库信息
  2468. // warehouseinfo, _ := service.GetGoodInformationWarehouseInfo(it.ID, orgId)
  2469. // for _, item := range warehouseinfo {
  2470. // sum_total += item.StockCount
  2471. // }
  2472. // service.UpdateGoodInformation(it.ID, orgId, sum_total)
  2473. //}
  2474. var ids []int64
  2475. if len(keyword) > 0 {
  2476. manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2477. for _, it := range manufacturerList {
  2478. ids = append(ids, it.ID)
  2479. }
  2480. }
  2481. stockList, total, err := service.GetGoodStockList(orgId, storehouse_id, good_type, keyword, page, limit, ids)
  2482. if err != nil {
  2483. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
  2484. return
  2485. }
  2486. this.ServeSuccessJSON(map[string]interface{}{
  2487. "total": total,
  2488. "stockList": stockList,
  2489. })
  2490. }
  2491. func (this *SelfDrugApiController) GetGoodWarehouseOutInfoByIdList() {
  2492. good_id, _ := this.GetInt64("good_id")
  2493. limit, _ := this.GetInt64("limit")
  2494. page, _ := this.GetInt64("page")
  2495. start_time := this.GetString("start_first_time")
  2496. end_time := this.GetString("end_first_time")
  2497. storehouse_id, _ := this.GetInt64("storehouse_id")
  2498. orgId := this.GetAdminUserInfo().CurrentOrgId
  2499. timeLayout := "2006-01-02"
  2500. loc, _ := time.LoadLocation("Local")
  2501. var startTime int64
  2502. if len(start_time) > 0 {
  2503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2504. if err != nil {
  2505. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2506. return
  2507. }
  2508. startTime = theTime.Unix()
  2509. }
  2510. var endTime int64
  2511. if len(end_time) > 0 {
  2512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2513. if err != nil {
  2514. utils.ErrorLog(err.Error())
  2515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2516. return
  2517. }
  2518. endTime = theTime.Unix()
  2519. }
  2520. list, total, err := service.GetGoodWarehouseOutInfoByIdList(good_id, limit, page, orgId, startTime, endTime, storehouse_id)
  2521. //flushList, _ := service.GetStockFlushByGoodId(good_id, orgId, startTime, endTime)
  2522. //warehouseInfoByList, _ := service.GetGoodWarehouseInfoByList(good_id, orgId, startTime, endTime)
  2523. //cancelStockInfoByList, _ := service.GetGoodCancelStockInfoByList(good_id, orgId, startTime, endTime)
  2524. //warehouseOutByList,_ := service.GetGoodWarehouseOutInfoByIdListTwenty(good_id, limit, page, orgId, startTime, endTime)
  2525. if err != nil {
  2526. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
  2527. return
  2528. }
  2529. this.ServeSuccessJSON(map[string]interface{}{
  2530. "total": total,
  2531. "list": list,
  2532. //"warehouseInfoByList":warehouseInfoByList,
  2533. //"cancelStockInfoByList":cancelStockInfoByList,
  2534. //"warehouseOutByList":warehouseOutByList,
  2535. //"flushList":flushList,
  2536. })
  2537. }
  2538. func (this *SelfDrugApiController) GetGoodPatientList() {
  2539. orgId := this.GetAdminUserInfo().CurrentOrgId
  2540. keyword := this.GetString("keyword")
  2541. list, err := service.GetGoodPatientList(orgId, keyword)
  2542. if err != nil {
  2543. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2544. return
  2545. }
  2546. this.ServeSuccessJSON(map[string]interface{}{
  2547. "list": list,
  2548. })
  2549. }
  2550. func (this *SelfDrugApiController) GetWarehouseOutDetailByPatientId() {
  2551. patient_id, _ := this.GetInt64("patient_id")
  2552. start_time := this.GetString("start_time")
  2553. end_time := this.GetString("end_time")
  2554. limit, _ := this.GetInt64("limit")
  2555. page, _ := this.GetInt64("page")
  2556. orgId := this.GetAdminUserInfo().CurrentOrgId
  2557. timeLayout := "2006-01-02"
  2558. loc, _ := time.LoadLocation("Local")
  2559. var startTime int64
  2560. if len(start_time) > 0 {
  2561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2562. if err != nil {
  2563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2564. return
  2565. }
  2566. startTime = theTime.Unix()
  2567. }
  2568. var endTime int64
  2569. if len(end_time) > 0 {
  2570. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2571. if err != nil {
  2572. utils.ErrorLog(err.Error())
  2573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2574. return
  2575. }
  2576. endTime = theTime.Unix()
  2577. }
  2578. list, total, err := service.GetWarehouseOutDetailByPatientIdOne(orgId, patient_id, startTime, endTime, limit, page)
  2579. outlist, _ := service.GetWarehouseOutDetailByPatientId(orgId, patient_id, startTime, endTime)
  2580. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2581. if err != nil {
  2582. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2583. return
  2584. }
  2585. this.ServeSuccessJSON(map[string]interface{}{
  2586. "list": list,
  2587. "manufacturerList": manufacturerList,
  2588. "total": total,
  2589. "outlist": outlist,
  2590. })
  2591. }
  2592. func (this *SelfDrugApiController) GetGoodExpiryDateQuery() {
  2593. storehouse_id, _ := this.GetInt64("storehouse_id")
  2594. expiry_type, _ := this.GetInt64("expiry_type")
  2595. keyword := this.GetString("keyword")
  2596. page, _ := this.GetInt64("page")
  2597. limit, _ := this.GetInt64("limit")
  2598. orgId := this.GetAdminUserInfo().CurrentOrgId
  2599. start_time := this.GetString("start_time")
  2600. timeLayout := "2006-01-02"
  2601. loc, _ := time.LoadLocation("Local")
  2602. var endTime int64
  2603. if len(start_time) > 0 {
  2604. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2605. if err != nil {
  2606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2607. return
  2608. }
  2609. endTime = theTime.Unix()
  2610. }
  2611. recordDateStr := time.Now().Format("2006-01-02")
  2612. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2613. fmt.Scan("parseDateErr", parseDateErr)
  2614. nowtime := recordDate.Unix()
  2615. var ids []int64
  2616. var goodIds []int64
  2617. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2618. for _, it := range manufacturers {
  2619. ids = append(ids, it.ID)
  2620. }
  2621. goodList, _ := service.GetGoodNameByword(orgId, keyword)
  2622. for _, it := range goodList {
  2623. goodIds = append(goodIds, it.ID)
  2624. }
  2625. list, total, err := service.GetGoodExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2626. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2627. if err != nil {
  2628. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2629. return
  2630. }
  2631. this.ServeSuccessJSON(map[string]interface{}{
  2632. "list": list,
  2633. "manufacturerList": manufacturerList,
  2634. "total": total,
  2635. "nowtime": nowtime,
  2636. })
  2637. }
  2638. func (this *SelfDrugApiController) GetGoodPurchaseStockQuery() {
  2639. good_type, _ := this.GetInt64("good_type")
  2640. keyword := this.GetString("keyword")
  2641. page, _ := this.GetInt64("page")
  2642. limit, _ := this.GetInt64("limit")
  2643. start_time := this.GetString("start_time")
  2644. end_time := this.GetString("end_time")
  2645. orgId := this.GetAdminUserInfo().CurrentOrgId
  2646. timeLayout := "2006-01-02"
  2647. loc, _ := time.LoadLocation("Local")
  2648. var startTime int64
  2649. if len(start_time) > 0 {
  2650. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2651. if err != nil {
  2652. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2653. return
  2654. }
  2655. startTime = theTime.Unix()
  2656. }
  2657. var endTime int64
  2658. if len(end_time) > 0 {
  2659. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2660. if err != nil {
  2661. utils.ErrorLog(err.Error())
  2662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2663. return
  2664. }
  2665. endTime = theTime.Unix()
  2666. }
  2667. var ids []int64
  2668. var goodIds []int64
  2669. infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  2670. for _, it := range infoList {
  2671. goodIds = append(goodIds, it.GoodId)
  2672. }
  2673. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2674. for _, it := range manufacturers {
  2675. ids = append(ids, it.ID)
  2676. }
  2677. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2678. list, total, err := service.GetGoodPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
  2679. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2680. for _, item := range list {
  2681. //获取期初结余数量
  2682. infoList, _ := service.GetStartGoodWarehouseInfoList(item.ID, orgId, startTime)
  2683. for _, it := range infoList {
  2684. item.WarehousingInfoStart = append(item.WarehousingInfoStart, it)
  2685. }
  2686. //获取期末结余数量
  2687. warehouseInfoList, _ := service.GetEndGoodWarehouseInfoList(item.ID, orgId, endTime)
  2688. for _, it := range warehouseInfoList {
  2689. item.WarehousingInfoEnd = append(item.WarehousingInfoEnd, it)
  2690. }
  2691. //获取期间增加
  2692. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2693. for _, it := range goodWarehouseInfoList {
  2694. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  2695. }
  2696. //获取本期增加
  2697. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2698. for _, it := range WarehouseInfoFlowList {
  2699. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  2700. }
  2701. //获取本期减少
  2702. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2703. for _, it := range reduceWarehouseInfoList {
  2704. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  2705. }
  2706. //获取期中减少退库
  2707. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2708. for _, it := range lowInfo {
  2709. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  2710. }
  2711. //
  2712. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  2713. for _, it := range outInfo {
  2714. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  2715. }
  2716. //获取期初结余
  2717. info, _ := service.FindeStartFlowInfo(item.ID, orgId, startTime)
  2718. for _, it := range info {
  2719. item.StartFlowInfo = append(item.StartFlowInfo, it)
  2720. }
  2721. //获取期初结余
  2722. flowOutInfo, _ := service.FindeStartFlowOutInfo(item.ID, orgId, startTime)
  2723. for _, it := range flowOutInfo {
  2724. item.StartOutFlowInfo = append(item.StartOutFlowInfo, it)
  2725. }
  2726. //获取期初退库
  2727. cancelInfo, _ := service.FindeStartCancelInfo(item.ID, orgId, startTime)
  2728. for _, it := range cancelInfo {
  2729. item.StartCancelFlowInfo = append(item.StartCancelFlowInfo, it)
  2730. }
  2731. //获取期末结余
  2732. flowInfo, _ := service.FindEndStartFlowInfo(item.ID, orgId, endTime)
  2733. for _, it := range flowInfo {
  2734. item.EndFlowInfo = append(item.EndFlowInfo, it)
  2735. }
  2736. //获取期末出库
  2737. lowOutInfo, _ := service.FindeEndFLowOutInfo(item.ID, orgId, endTime)
  2738. for _, it := range lowOutInfo {
  2739. item.EndFlowOutInfo = append(item.EndFlowOutInfo, it)
  2740. }
  2741. //获取期末退库
  2742. endCancelInfo, _ := service.FindEndCancelInfo(item.ID, orgId, endTime)
  2743. for _, it := range endCancelInfo {
  2744. item.EndCancelFLowInfo = append(item.EndCancelFLowInfo, it)
  2745. }
  2746. //期初盘赢
  2747. inventory, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, startTime)
  2748. for _, it := range inventory {
  2749. item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  2750. }
  2751. //期初盘亏
  2752. stockInventory, _ := service.FindStartStockInventoryLosses(item.ID, orgId, startTime)
  2753. for _, it := range stockInventory {
  2754. item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  2755. }
  2756. //期末盘盈
  2757. inventoryProfit, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, endTime)
  2758. for _, it := range inventoryProfit {
  2759. item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  2760. }
  2761. //期末盘亏
  2762. inventoryLosses, _ := service.FindStartStockInventoryLosses(item.ID, orgId, endTime)
  2763. for _, it := range inventoryLosses {
  2764. item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  2765. }
  2766. //期中盘盈
  2767. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2768. for _, it := range profit {
  2769. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  2770. }
  2771. //期中盘亏
  2772. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2773. for _, it := range losses {
  2774. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  2775. }
  2776. }
  2777. if err != nil {
  2778. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2779. return
  2780. }
  2781. this.ServeSuccessJSON(map[string]interface{}{
  2782. "list": list,
  2783. "manufacturerList": manufacturerList,
  2784. "total": total,
  2785. })
  2786. }
  2787. func (this *SelfDrugApiController) GetDrugWarehouseOutDetailByPatientId() {
  2788. patient_id, _ := this.GetInt64("patient_id")
  2789. start_time := this.GetString("start_time")
  2790. end_time := this.GetString("end_time")
  2791. orgId := this.GetAdminUserInfo().CurrentOrgId
  2792. limit, _ := this.GetInt64("limit")
  2793. page, _ := this.GetInt64("page")
  2794. timeLayout := "2006-01-02"
  2795. loc, _ := time.LoadLocation("Local")
  2796. var startTime int64
  2797. if len(start_time) > 0 {
  2798. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2799. if err != nil {
  2800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. startTime = theTime.Unix()
  2804. }
  2805. var endTime int64
  2806. if len(end_time) > 0 {
  2807. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2808. if err != nil {
  2809. utils.ErrorLog(err.Error())
  2810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2811. return
  2812. }
  2813. endTime = theTime.Unix()
  2814. }
  2815. list, total, _ := service.GetDrugWarehouseOutDetailByPatientIdOne(patient_id, orgId, startTime, endTime, page, limit)
  2816. outlist, _ := service.GetDrugWarehouseOutDetailByPatientId(patient_id, orgId, startTime, endTime)
  2817. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2818. this.ServeSuccessJSON(map[string]interface{}{
  2819. "list": list,
  2820. "total": total,
  2821. "manufacturerList": manufacturerList,
  2822. "outlist": outlist,
  2823. })
  2824. }
  2825. func (this *SelfDrugApiController) GetDrugExpiryDateQuery() {
  2826. storehouse_id, _ := this.GetInt64("storehouse_id")
  2827. expiry_type, _ := this.GetInt64("expiry_type")
  2828. keyword := this.GetString("keyword")
  2829. page, _ := this.GetInt64("page")
  2830. limit, _ := this.GetInt64("limit")
  2831. orgId := this.GetAdminUserInfo().CurrentOrgId
  2832. start_time := this.GetString("start_time")
  2833. timeLayout := "2006-01-02"
  2834. loc, _ := time.LoadLocation("Local")
  2835. var endTime int64
  2836. if len(start_time) > 0 {
  2837. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2838. if err != nil {
  2839. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2840. return
  2841. }
  2842. endTime = theTime.Unix()
  2843. }
  2844. recordDateStr := time.Now().Format("2006-01-02")
  2845. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2846. fmt.Scan("parseDateErr", parseDateErr)
  2847. nowtime := recordDate.Unix()
  2848. var ids []int64
  2849. var goodIds []int64
  2850. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2851. for _, it := range manufacturers {
  2852. ids = append(ids, it.ID)
  2853. }
  2854. drugList, _ := service.GetDrugNameByword(orgId, keyword)
  2855. for _, it := range drugList {
  2856. goodIds = append(goodIds, it.ID)
  2857. }
  2858. list, total, err := service.GetDrugExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2859. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2860. var drugType = "药品类型"
  2861. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2862. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  2863. if err != nil {
  2864. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2865. return
  2866. }
  2867. this.ServeSuccessJSON(map[string]interface{}{
  2868. "list": list,
  2869. "manufacturerList": manufacturerList,
  2870. "total": total,
  2871. "nowtime": nowtime,
  2872. "drugTypeList": drugTypeList,
  2873. })
  2874. }
  2875. func (this *SelfDrugApiController) GetPurchaseDrugQuery() {
  2876. good_type, _ := this.GetInt64("good_type")
  2877. keyword := this.GetString("keyword")
  2878. page, _ := this.GetInt64("page")
  2879. limit, _ := this.GetInt64("limit")
  2880. start_time := this.GetString("start_time")
  2881. end_time := this.GetString("end_time")
  2882. orgId := this.GetAdminUserInfo().CurrentOrgId
  2883. timeLayout := "2006-01-02"
  2884. loc, _ := time.LoadLocation("Local")
  2885. var startTime int64
  2886. if len(start_time) > 0 {
  2887. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2888. if err != nil {
  2889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2890. return
  2891. }
  2892. startTime = theTime.Unix()
  2893. }
  2894. var endTime int64
  2895. if len(end_time) > 0 {
  2896. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2897. if err != nil {
  2898. utils.ErrorLog(err.Error())
  2899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2900. return
  2901. }
  2902. endTime = theTime.Unix()
  2903. }
  2904. var ids []int64
  2905. var infoIds []int64
  2906. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2907. for _, it := range manufacturers {
  2908. ids = append(ids, it.ID)
  2909. }
  2910. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  2911. for _, it := range infoList {
  2912. infoIds = append(infoIds, it.DrugId)
  2913. }
  2914. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  2915. list, total, err := service.GetDrugPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  2916. for _, item := range list {
  2917. //获取期初结余入库数量
  2918. startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
  2919. for _, it := range startDrugInfo {
  2920. item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
  2921. }
  2922. //获取期初结余出库数量
  2923. flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
  2924. for _, it := range flowOutList {
  2925. item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
  2926. }
  2927. //获取期初结余退库数量
  2928. cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
  2929. for _, it := range cancelInfo {
  2930. item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
  2931. }
  2932. //获取期末结余入库数量
  2933. drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
  2934. for _, it := range drugwarehouseinfoend {
  2935. item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
  2936. }
  2937. //获取期末出库结余
  2938. endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
  2939. for _, it := range endDrugInfo {
  2940. item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
  2941. }
  2942. //获取期末退库数量
  2943. flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
  2944. for _, it := range flowCancelInfo {
  2945. item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
  2946. }
  2947. //期中增加
  2948. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  2949. for _, it := range drugWarehouse {
  2950. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  2951. }
  2952. //期中减少
  2953. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  2954. for _, it := range outInfo {
  2955. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  2956. }
  2957. //期中退库
  2958. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  2959. for _, it := range cancelstartInfo {
  2960. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  2961. }
  2962. //获取期初盘盈
  2963. startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
  2964. for _, it := range startProfit {
  2965. item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  2966. }
  2967. //获取期初盘亏
  2968. startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
  2969. for _, it := range startLosses {
  2970. item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  2971. }
  2972. //获取期末盘盈
  2973. endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
  2974. for _, it := range endProfit {
  2975. item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  2976. }
  2977. //获取期末盘亏
  2978. losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
  2979. for _, it := range losses {
  2980. item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  2981. }
  2982. //获取期中盘盈
  2983. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  2984. for _, it := range profit {
  2985. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  2986. }
  2987. //获取期中盘亏
  2988. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  2989. for _, it := range endLosses {
  2990. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  2991. }
  2992. }
  2993. if err != nil {
  2994. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2995. return
  2996. }
  2997. var drugType = "药品类型"
  2998. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2999. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3000. this.ServeSuccessJSON(map[string]interface{}{
  3001. "list": list,
  3002. "manufacturerList": manufacturerList,
  3003. "total": total,
  3004. "drugTypeList": drugTypeList,
  3005. })
  3006. }
  3007. func (this *SelfDrugApiController) GetDrugNewQuery() {
  3008. orgId := this.GetAdminUserInfo().CurrentOrgId
  3009. storehouse_id, _ := this.GetInt64("storehouse_id")
  3010. good_type, _ := this.GetInt64("good_type")
  3011. keyword := this.GetString("keyword")
  3012. page, _ := this.GetInt64("page")
  3013. limit, _ := this.GetInt64("limit")
  3014. start_time := this.GetString("start_time")
  3015. end_time := this.GetString("end_time")
  3016. timeLayout := "2006-01-02"
  3017. loc, _ := time.LoadLocation("Local")
  3018. var startTime int64
  3019. if len(start_time) > 0 {
  3020. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3021. if err != nil {
  3022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3023. return
  3024. }
  3025. startTime = theTime.Unix()
  3026. }
  3027. var endTime int64
  3028. if len(end_time) > 0 {
  3029. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3030. if err != nil {
  3031. utils.ErrorLog(err.Error())
  3032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3033. return
  3034. }
  3035. endTime = theTime.Unix()
  3036. }
  3037. var ids []int64
  3038. var goodIds []int64
  3039. if len(keyword) > 0 {
  3040. manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3041. for _, it := range manufacturerList {
  3042. ids = append(ids, it.ID)
  3043. }
  3044. }
  3045. //查询药品库信息
  3046. //drug, _ := service.GetBaseDrugName(orgId)
  3047. //
  3048. //for _, it := range drug {
  3049. // var sum_count int64
  3050. // var limit_count int64
  3051. // drugInfo, _ := service.GetDrugWarehouseInfoName(it.ID, orgId)
  3052. // for _, item := range drugInfo {
  3053. //
  3054. // sum_count += item.StockMaxNumber*it.MinNumber + item.StockMinNumber
  3055. // }
  3056. // stockInt, _ := strconv.ParseInt(it.DrugStockLimit, 10, 64)
  3057. // limit_count = stockInt * it.MinNumber
  3058. // service.UpdateDrugById(it.ID, orgId, limit_count, sum_count)
  3059. //}
  3060. if storehouse_id > 0 {
  3061. infoList, _ := service.GetDrugWarehouseInfoByOrgId(orgId, storehouse_id)
  3062. for _, it := range infoList {
  3063. goodIds = append(goodIds, it.DrugId)
  3064. }
  3065. }
  3066. countList, total, err := service.GetDrugStockCountList(orgId, storehouse_id, good_type, keyword, page, limit, ids, goodIds, startTime, endTime)
  3067. if err != nil {
  3068. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
  3069. return
  3070. }
  3071. var drugType = "药品类型"
  3072. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3073. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3074. this.ServeSuccessJSON(map[string]interface{}{
  3075. "total": total,
  3076. "drugTypeList": drugTypeList,
  3077. "countList": countList,
  3078. })
  3079. }
  3080. func (this *SelfDrugApiController) GetDrugWarehouseInfoById() {
  3081. drug_id, _ := this.GetInt64("drug_id")
  3082. limit, _ := this.GetInt64("limit")
  3083. page, _ := this.GetInt64("page")
  3084. start_time := this.GetString("start_first_time")
  3085. end_time := this.GetString("end_first_time")
  3086. storehouse_id, _ := this.GetInt64("storehouse_id")
  3087. orgId := this.GetAdminUserInfo().CurrentOrgId
  3088. timeLayout := "2006-01-02"
  3089. loc, _ := time.LoadLocation("Local")
  3090. var startTime int64
  3091. if len(start_time) > 0 {
  3092. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3093. if err != nil {
  3094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3095. return
  3096. }
  3097. startTime = theTime.Unix()
  3098. }
  3099. var endTime int64
  3100. if len(end_time) > 0 {
  3101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3102. if err != nil {
  3103. utils.ErrorLog(err.Error())
  3104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3105. return
  3106. }
  3107. endTime = theTime.Unix()
  3108. }
  3109. list, total, err := service.GetDrugWarehouseOutInfoByIdList(drug_id, limit, page, orgId, startTime, endTime, storehouse_id)
  3110. flushList, _ := service.GetDrugFlowFlush(drug_id, orgId, startTime, endTime)
  3111. flushOne, _ := service.GetDrugFlowFlushOne(drug_id, orgId, startTime, endTime)
  3112. if err != nil {
  3113. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
  3114. return
  3115. }
  3116. this.ServeSuccessJSON(map[string]interface{}{
  3117. "total": total,
  3118. "list": list,
  3119. "flushList": flushList,
  3120. "flushListOne": flushOne,
  3121. })
  3122. }
  3123. func (this *SelfDrugApiController) GetSendGoodInformation() {
  3124. orgId := this.GetAdminUserInfo().CurrentOrgId
  3125. fmt.Println("orgid", orgId)
  3126. list, _ := service.GetWarehouseOutInfo(10485)
  3127. for _, it := range list {
  3128. service.UpdateWarehosueOutInfo(it.ID, it.WarehouseOutTime)
  3129. }
  3130. //获取入库数据
  3131. //list, _ := service.GetSendGoodInformation(10265)
  3132. //
  3133. ////project, _ := service.GetHisPrescriptionList(10265)
  3134. //
  3135. //for _, it := range list {
  3136. // service.UpdateGoodFlow(it.ID, it.PackingPrice)
  3137. //}
  3138. //for _, it := range list {
  3139. // //查询是否有数据
  3140. // _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
  3141. // //获取总退库数量
  3142. // var cancel_count int64
  3143. // var out_count int64
  3144. // var act_count int64
  3145. // //退库总数量
  3146. // cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
  3147. // for _, item := range cancellist {
  3148. // cancel_count += item.Count
  3149. // }
  3150. // //出库总数量
  3151. // outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  3152. // for _, item := range outlist {
  3153. // out_count += item.Count
  3154. // }
  3155. //
  3156. // //实际出库总数量
  3157. // actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  3158. // for _, item := range actlist {
  3159. // act_count += item.Count
  3160. // }
  3161. //
  3162. // if errcode == gorm.ErrRecordNotFound {
  3163. // good := models.XtGoodStockCount{
  3164. // UserOrgId: it.OrgId,
  3165. // GoodId: it.GoodId,
  3166. // StorehouseId: it.StorehouseId,
  3167. // Status: 1,
  3168. // Ctime: time.Now().Unix(),
  3169. // Mtime: 0,
  3170. // StockInCount: it.WarehousingCount,
  3171. // StockOutCount: out_count - cancel_count,
  3172. // StockCancelCount: cancel_count,
  3173. // FlushCount: it.StockCount,
  3174. // StockActOutCount: act_count,
  3175. // }
  3176. // service.CreateGoodCountSix(good)
  3177. // }
  3178. // if errcode == nil {
  3179. // service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
  3180. // }
  3181. //}
  3182. this.ServeSuccessJSON(map[string]interface{}{
  3183. "msg": "1",
  3184. })
  3185. }
  3186. func (this *SelfDrugApiController) GetDrugInitDetailList() {
  3187. orgId := this.GetAdminUserInfo().CurrentOrgId
  3188. //获取所有的入库仓库
  3189. list, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
  3190. for _, item := range list {
  3191. //查询该药品该仓库是否有数据
  3192. drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
  3193. //查询该仓库该药品的入库数量
  3194. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  3195. var sum_in_count int64
  3196. var flush_count int64
  3197. var sum_out_count int64
  3198. var cancel_out_count int64
  3199. //查询入库数量和剩余库存
  3200. infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
  3201. for _, it := range infolist {
  3202. if it.MaxUnit == medical.MaxUnit {
  3203. it.WarehousingCount = it.WarehousingCount * medical.MinNumber
  3204. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  3205. }
  3206. sum_in_count += it.WarehousingCount
  3207. flush_count += it.StockMaxNumber + it.StockMinNumber
  3208. }
  3209. //获取出库数量
  3210. outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
  3211. for _, it := range outinfolist {
  3212. if it.MaxUnit == medical.MaxUnit {
  3213. it.Count = it.Count * medical.MinNumber
  3214. }
  3215. sum_out_count += it.Count
  3216. }
  3217. //获取退库数量
  3218. cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
  3219. for _, it := range cancelinfolist {
  3220. if it.MaxUnit == medical.MaxUnit {
  3221. it.Count = it.Count * medical.MinNumber
  3222. }
  3223. cancel_out_count += it.Count
  3224. }
  3225. //新增
  3226. if drug.ID == 0 {
  3227. drugstock := models.XtDrugStockCount{
  3228. UserOrgId: orgId,
  3229. StorehouseId: item.StorehouseId,
  3230. SumInCount: sum_in_count,
  3231. SumOutCount: sum_out_count - cancel_out_count,
  3232. SumCancelCount: cancel_out_count,
  3233. DrugId: item.DrugId,
  3234. Ctime: time.Now().Unix(),
  3235. Mtime: 0,
  3236. Status: 1,
  3237. FlushCount: flush_count,
  3238. SumActOutCount: sum_out_count,
  3239. }
  3240. service.CreateDrugStockCount(drugstock)
  3241. }
  3242. }
  3243. this.ServeSuccessJSON(map[string]interface{}{
  3244. "msg": "1",
  3245. })
  3246. }
  3247. func (this *SelfDrugApiController) GetGoodNewPurchaseStockQuery() {
  3248. good_type, _ := this.GetInt64("good_type")
  3249. keyword := this.GetString("keyword")
  3250. page, _ := this.GetInt64("page")
  3251. limit, _ := this.GetInt64("limit")
  3252. start_time := this.GetString("start_time")
  3253. end_time := this.GetString("end_time")
  3254. orgId := this.GetAdminUserInfo().CurrentOrgId
  3255. timeLayout := "2006-01-02"
  3256. loc, _ := time.LoadLocation("Local")
  3257. var startTime int64
  3258. if len(start_time) > 0 {
  3259. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3260. if err != nil {
  3261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3262. return
  3263. }
  3264. startTime = theTime.Unix()
  3265. }
  3266. var endTime int64
  3267. if len(end_time) > 0 {
  3268. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3269. if err != nil {
  3270. utils.ErrorLog(err.Error())
  3271. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3272. return
  3273. }
  3274. endTime = theTime.Unix()
  3275. }
  3276. var ids []int64
  3277. var goodIds []int64
  3278. //infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  3279. //for _, it := range infoList {
  3280. // goodIds = append(goodIds, it.GoodId)
  3281. //}
  3282. if len(keyword) > 0 {
  3283. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3284. for _, it := range manufacturers {
  3285. ids = append(ids, it.ID)
  3286. }
  3287. }
  3288. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  3289. if orgId == 10265 {
  3290. //storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3291. list, total, err := service.GetGoodNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
  3292. for _, item := range list {
  3293. //获取期初结余
  3294. low, _ := service.GetStartLastFLowTwenty(item.ID, orgId, startTime)
  3295. item.GoodStartFlowInfo = low
  3296. //获取期末结余
  3297. flow, _ := service.GetEndLastFlowTwenty(item.ID, orgId, endTime)
  3298. item.GoodEndFlowInfo = flow
  3299. //获取期间增加
  3300. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
  3301. for _, it := range goodWarehouseInfoList {
  3302. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3303. }
  3304. //获取本期增加
  3305. WarehouseInfoFlowList, _ := service.GetAddStartFlowTwenty(item.ID, orgId, startTime, endTime)
  3306. for _, it := range WarehouseInfoFlowList {
  3307. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3308. }
  3309. //获取本期减少
  3310. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
  3311. for _, it := range reduceWarehouseInfoList {
  3312. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3313. }
  3314. //获取期中减少退库
  3315. lowInfo, _ := service.GetStartEndCancelFLowInfoTwenty(item.ID, orgId, startTime, endTime)
  3316. for _, it := range lowInfo {
  3317. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3318. }
  3319. //
  3320. outInfo, _ := service.FindeWarehouseOutInfoTwenty(item.ID, orgId, startTime)
  3321. for _, it := range outInfo {
  3322. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3323. }
  3324. //期中盘盈
  3325. profit, _ := service.FindeEndStokInventoryProfitTwenty(item.ID, orgId, startTime, endTime)
  3326. for _, it := range profit {
  3327. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3328. }
  3329. //期中盘亏
  3330. losses, _ := service.FindeEndStockInventoryLossesTwenty(item.ID, orgId, startTime, endTime)
  3331. for _, it := range losses {
  3332. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3333. }
  3334. }
  3335. if err != nil {
  3336. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3337. return
  3338. }
  3339. this.ServeSuccessJSON(map[string]interface{}{
  3340. "list": list,
  3341. "manufacturerList": manufacturerList,
  3342. "total": total,
  3343. })
  3344. }
  3345. if orgId != 10265 {
  3346. list, total, err := service.GetGoodNewPurchaseStockQueryOne(good_type, keyword, page, limit, orgId, ids, goodIds)
  3347. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3348. for _, item := range list {
  3349. //获取期初结余
  3350. low, _ := service.GetStartLastFLow(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3351. item.GoodStartFlowInfo = low
  3352. //获取期末结余
  3353. flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime, storeConfig.StorehouseOutInfo)
  3354. item.GoodEndFlowInfo = flow
  3355. //获取期间增加
  3356. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3357. for _, it := range goodWarehouseInfoList {
  3358. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3359. }
  3360. //获取本期增加
  3361. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3362. for _, it := range WarehouseInfoFlowList {
  3363. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3364. }
  3365. //获取本期减少
  3366. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3367. for _, it := range reduceWarehouseInfoList {
  3368. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3369. }
  3370. //获取期中减少退库
  3371. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3372. for _, it := range lowInfo {
  3373. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3374. }
  3375. //
  3376. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3377. for _, it := range outInfo {
  3378. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3379. }
  3380. //期中盘盈
  3381. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3382. for _, it := range profit {
  3383. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3384. }
  3385. //期中盘亏
  3386. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3387. for _, it := range losses {
  3388. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3389. }
  3390. //获取期初结余
  3391. balanceList, _ := service.GetInitBalanceList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3392. for _, it := range balanceList {
  3393. item.StWarehousingInfoTwo = append(item.StWarehousingInfoTwo, it)
  3394. }
  3395. //期间减少
  3396. banceOutList, _ := service.GetInitOutBanceList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3397. //banceOutList, _ := service.GetInitOutBanceTenty(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3398. for _, it := range banceOutList {
  3399. item.WarehouseOutInfoTenty = append(item.WarehouseOutInfoTenty, it)
  3400. }
  3401. //期间盘盈
  3402. infoFlow, _ := service.GetInitInfoFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3403. for _, it := range infoFlow {
  3404. item.WareStartInStockFlow = append(item.WareStartInStockFlow, it)
  3405. }
  3406. //期间盘亏
  3407. outInfoFlow, _ := service.GetInitOutInfoFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3408. for _, it := range outInfoFlow {
  3409. item.WareStartOutStockFlow = append(item.WareStartOutStockFlow, it)
  3410. }
  3411. }
  3412. if err != nil {
  3413. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3414. return
  3415. }
  3416. this.ServeSuccessJSON(map[string]interface{}{
  3417. "list": list,
  3418. "manufacturerList": manufacturerList,
  3419. "total": total,
  3420. })
  3421. }
  3422. }
  3423. func (this *SelfDrugApiController) GetPurchaseNewDrugQuery() {
  3424. good_type, _ := this.GetInt64("good_type")
  3425. keyword := this.GetString("keyword")
  3426. page, _ := this.GetInt64("page")
  3427. limit, _ := this.GetInt64("limit")
  3428. start_time := this.GetString("start_time")
  3429. end_time := this.GetString("end_time")
  3430. orgId := this.GetAdminUserInfo().CurrentOrgId
  3431. timeLayout := "2006-01-02"
  3432. loc, _ := time.LoadLocation("Local")
  3433. var startTime int64
  3434. if len(start_time) > 0 {
  3435. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3436. if err != nil {
  3437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3438. return
  3439. }
  3440. startTime = theTime.Unix()
  3441. }
  3442. var endTime int64
  3443. if len(end_time) > 0 {
  3444. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3445. if err != nil {
  3446. utils.ErrorLog(err.Error())
  3447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3448. return
  3449. }
  3450. endTime = theTime.Unix()
  3451. }
  3452. var ids []int64
  3453. var infoIds []int64
  3454. if len(keyword) > 0 {
  3455. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3456. for _, it := range manufacturers {
  3457. ids = append(ids, it.ID)
  3458. }
  3459. }
  3460. //infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  3461. //for _, it := range infoList {
  3462. // infoIds = append(infoIds, it.DrugId)
  3463. //}
  3464. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3465. list, total, err := service.GetDrugNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  3466. for _, item := range list {
  3467. //获取期初结余
  3468. flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
  3469. item.DrugStatFlow = flow
  3470. //获取期末结余
  3471. endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
  3472. item.DrugEndFlow = endFlow
  3473. //期中增加
  3474. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  3475. for _, it := range drugWarehouse {
  3476. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  3477. }
  3478. //期中减少
  3479. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3480. for _, it := range outInfo {
  3481. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  3482. }
  3483. //期中退库
  3484. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3485. for _, it := range cancelstartInfo {
  3486. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  3487. }
  3488. //获取期中盘盈
  3489. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  3490. for _, it := range profit {
  3491. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3492. }
  3493. //获取期中盘亏
  3494. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  3495. for _, it := range endLosses {
  3496. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3497. }
  3498. if orgId != 10215 && orgId != 10265 {
  3499. //获取入库
  3500. infoFLow, _ := service.GetNewDrugFlowInWarehouseInfo(item.ID, orgId, startTime)
  3501. for _, it := range infoFLow {
  3502. item.NewDrugFlowInWarehouseInfo = append(item.NewDrugFlowInWarehouseInfo, it)
  3503. }
  3504. //获取盘盈
  3505. infoProfitFlow, _ := service.GetNewDrugFlowPofitWarehouseInfo(item.ID, orgId, startTime)
  3506. for _, it := range infoProfitFlow {
  3507. item.NewDrugFlowPofitWarehouseInfo = append(item.NewDrugFlowPofitWarehouseInfo, it)
  3508. }
  3509. //获取出库
  3510. infoOutFlow, _ := service.GetNewDrugFlowOutWarehouseInfo(item.ID, orgId, startTime)
  3511. for _, it := range infoOutFlow {
  3512. item.NewDrugFlowOutWarehouseInfo = append(item.NewDrugFlowOutWarehouseInfo, it)
  3513. }
  3514. //获取退库
  3515. infoCacelFlow, _ := service.GetNewDrugFlowCacelWarehouseInfo(item.ID, orgId, startTime)
  3516. for _, it := range infoCacelFlow {
  3517. item.NewDrugFlowNoCancelWarehouseInfo = append(item.NewDrugFlowNoCancelWarehouseInfo, it)
  3518. }
  3519. //获取盘亏
  3520. infoNoPofitFlow, _ := service.GetNewDrugFlowNoPofitWarehouseInfo(item.ID, orgId, startTime)
  3521. for _, it := range infoNoPofitFlow {
  3522. item.NewDrugFlowNoPofitWarehouseInfo = append(item.NewDrugFlowNoPofitWarehouseInfo, it)
  3523. }
  3524. }
  3525. }
  3526. if err != nil {
  3527. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3528. return
  3529. }
  3530. var drugType = "药品类型"
  3531. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3532. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3533. this.ServeSuccessJSON(map[string]interface{}{
  3534. "list": list,
  3535. "manufacturerList": manufacturerList,
  3536. "total": total,
  3537. "drugTypeList": drugTypeList,
  3538. })
  3539. }
  3540. func (this *SelfDrugApiController) GetGoodOverCount() {
  3541. orgId := this.GetAdminUserInfo().CurrentOrgId
  3542. list, _ := service.GetAllStockCount(orgId)
  3543. for _, item := range list {
  3544. flow, _ := service.GetLastStockFlow(item.GoodId)
  3545. service.ModifyStockFlowById(flow.ID, item.FlushCount)
  3546. }
  3547. returnData := make(map[string]interface{}, 0)
  3548. returnData["msg"] = "ok"
  3549. this.ServeSuccessJSON(returnData)
  3550. return
  3551. }
  3552. func (this *SelfDrugApiController) GetDrugOverCount() {
  3553. orgId := this.GetAdminUserInfo().CurrentOrgId
  3554. list, _ := service.GetAllDrugCount(orgId)
  3555. for _, item := range list {
  3556. service.GetLastDrugFlow(item.DrugId)
  3557. service.ModifyDrugFlowById(item.ID, item.FlushCount)
  3558. }
  3559. returnData := make(map[string]interface{}, 0)
  3560. returnData["msg"] = "ok"
  3561. this.ServeSuccessJSON(returnData)
  3562. return
  3563. }
  3564. func (this *SelfDrugApiController) GetDrugInventoryWarehouseInfoList() {
  3565. storehouse_id, _ := this.GetInt64("storehouse_id")
  3566. orgId := this.GetAdminUserInfo().CurrentOrgId
  3567. list, _ := service.GetDrugInventoryWarehouseInfoList(orgId, storehouse_id)
  3568. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3569. dealerList, _ := service.GetAllDealerList(orgId)
  3570. this.ServeSuccessJSON(map[string]interface{}{
  3571. "list": list,
  3572. "manufacturerList": manufacturerList,
  3573. "dealerList": dealerList,
  3574. })
  3575. }
  3576. func (this *SelfDrugApiController) GetInventoryDetailPrintList() {
  3577. keyword := this.GetString("keyword")
  3578. limit, _ := this.GetInt64("limit")
  3579. page, _ := this.GetInt64("page")
  3580. storehouse_id, _ := this.GetInt64("storehouse_id")
  3581. ids := this.GetString("ids")
  3582. idSplit := strings.Split(ids, ",")
  3583. orgId := this.GetAdminUserInfo().CurrentOrgId
  3584. list, total, err := service.GetDrugInventoryDetailMapList(keyword, page, limit, orgId, storehouse_id, idSplit)
  3585. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  3586. houseList, _ := service.GetAllStoreHouseList(orgId)
  3587. doctorList, _ := service.GetAllDoctorThree(orgId)
  3588. if err != nil {
  3589. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  3590. return
  3591. }
  3592. this.ServeSuccessJSON(map[string]interface{}{
  3593. "total": total,
  3594. "list": list,
  3595. "doctorList": doctorList,
  3596. "houseList": houseList,
  3597. "inventoryList": inventoryList,
  3598. })
  3599. }
  3600. func (this *SelfDrugApiController) GetDrugFlowDetailById() {
  3601. drug_id, _ := this.GetInt64("drug_id")
  3602. orgId := this.GetAdminUserInfo().CurrentOrgId
  3603. list, _ := service.GetDrugFlowDetailById(drug_id, orgId)
  3604. drugMedical, _ := service.GetBaseDrugMedical(drug_id)
  3605. for index, _ := range list {
  3606. if list[index].ConsumableType == 3 || list[index].ConsumableType == 2 || list[index].ConsumableType == 11 || list[index].ConsumableType == 12 || list[index].ConsumableType == 15 {
  3607. var count int64
  3608. if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
  3609. list[index].Count = list[index].Count * drugMedical.MinNumber
  3610. }
  3611. if index == 0 {
  3612. count = list[index].FlushOverCount - list[index].Count
  3613. service.UpdateDrugOverCount(list[index+1].ID, count)
  3614. }
  3615. if index >= 1 {
  3616. lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
  3617. count = lastStockFlow.FlushOverCount - list[index].Count
  3618. service.UpdateDrugOverCount(list[index].ID, count)
  3619. }
  3620. }
  3621. if list[index].ConsumableType == 7 || list[index].ConsumableType == 4 || list[index].ConsumableType == 1 || list[index].ConsumableType == 10 || list[index].ConsumableType == 13 {
  3622. if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
  3623. list[index].Count = list[index].Count * drugMedical.MinNumber
  3624. }
  3625. if index == 0 {
  3626. var count int64
  3627. count = list[index].FlushOverCount + list[index].Count
  3628. service.UpdateDrugOverCount(list[index+1].ID, count)
  3629. }
  3630. if index >= 1 {
  3631. var count int64
  3632. lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
  3633. count = lastStockFlow.FlushOverCount + list[index].Count
  3634. service.UpdateDrugOverCount(list[index].ID, count)
  3635. }
  3636. }
  3637. }
  3638. }
  3639. func (this *SelfDrugApiController) GetPurchaseDrugQueryList() {
  3640. good_type, _ := this.GetInt64("good_type")
  3641. keyword := this.GetString("keyword")
  3642. page, _ := this.GetInt64("page")
  3643. limit, _ := this.GetInt64("limit")
  3644. start_time := this.GetString("start_time")
  3645. end_time := this.GetString("end_time")
  3646. orgId := this.GetAdminUserInfo().CurrentOrgId
  3647. timeLayout := "2006-01-02"
  3648. loc, _ := time.LoadLocation("Local")
  3649. var startTime int64
  3650. if len(start_time) > 0 {
  3651. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3652. if err != nil {
  3653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3654. return
  3655. }
  3656. startTime = theTime.Unix()
  3657. }
  3658. var endTime int64
  3659. if len(end_time) > 0 {
  3660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3661. if err != nil {
  3662. utils.ErrorLog(err.Error())
  3663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3664. return
  3665. }
  3666. endTime = theTime.Unix()
  3667. }
  3668. var ids []int64
  3669. var infoIds []int64
  3670. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3671. for _, it := range manufacturers {
  3672. ids = append(ids, it.ID)
  3673. }
  3674. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  3675. for _, it := range infoList {
  3676. infoIds = append(infoIds, it.DrugId)
  3677. }
  3678. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3679. list, total, err := service.GetDrugNewPurchaseStockQueryList(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  3680. for _, item := range list {
  3681. //获取期初结余
  3682. flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
  3683. item.DrugStatFlow = flow
  3684. //获取期末结余
  3685. endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
  3686. item.DrugEndFlow = endFlow
  3687. //获取期初结余入库数量
  3688. //期中增加
  3689. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  3690. for _, it := range drugWarehouse {
  3691. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  3692. }
  3693. //期中减少
  3694. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3695. for _, it := range outInfo {
  3696. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  3697. }
  3698. //期中退库
  3699. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3700. for _, it := range cancelstartInfo {
  3701. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  3702. }
  3703. //获取期中盘盈
  3704. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  3705. for _, it := range profit {
  3706. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3707. }
  3708. //获取期中盘亏
  3709. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  3710. for _, it := range endLosses {
  3711. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3712. }
  3713. }
  3714. if err != nil {
  3715. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3716. return
  3717. }
  3718. var drugType = "药品类型"
  3719. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3720. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3721. this.ServeSuccessJSON(map[string]interface{}{
  3722. "list": list,
  3723. "manufacturerList": manufacturerList,
  3724. "total": total,
  3725. "drugTypeList": drugTypeList,
  3726. })
  3727. }
  3728. func (this *SelfDrugApiController) GetPurchaseStockQueryList() {
  3729. good_type, _ := this.GetInt64("good_type")
  3730. keyword := this.GetString("keyword")
  3731. page, _ := this.GetInt64("page")
  3732. limit, _ := this.GetInt64("limit")
  3733. start_time := this.GetString("start_time")
  3734. end_time := this.GetString("end_time")
  3735. orgId := this.GetAdminUserInfo().CurrentOrgId
  3736. timeLayout := "2006-01-02"
  3737. loc, _ := time.LoadLocation("Local")
  3738. var startTime int64
  3739. if len(start_time) > 0 {
  3740. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3741. if err != nil {
  3742. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3743. return
  3744. }
  3745. startTime = theTime.Unix()
  3746. }
  3747. var endTime int64
  3748. if len(end_time) > 0 {
  3749. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3750. if err != nil {
  3751. utils.ErrorLog(err.Error())
  3752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3753. return
  3754. }
  3755. endTime = theTime.Unix()
  3756. }
  3757. var ids []int64
  3758. var goodIds []int64
  3759. infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  3760. for _, it := range infoList {
  3761. goodIds = append(goodIds, it.GoodId)
  3762. }
  3763. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3764. for _, it := range manufacturers {
  3765. ids = append(ids, it.ID)
  3766. }
  3767. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  3768. list, total, err := service.GetPurchaseStockQueryList(good_type, keyword, page, limit, orgId, ids, goodIds)
  3769. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3770. for _, item := range list {
  3771. //获取期初结余
  3772. low, _ := service.GetStartLastFLow(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3773. item.GoodStartFlowInfo = low
  3774. //获取期末结余
  3775. flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime, storeConfig.StorehouseOutInfo)
  3776. item.GoodEndFlowInfo = flow
  3777. //获取期间增加
  3778. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3779. for _, it := range goodWarehouseInfoList {
  3780. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3781. }
  3782. //获取本期增加
  3783. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3784. for _, it := range WarehouseInfoFlowList {
  3785. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3786. }
  3787. //获取本期减少
  3788. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3789. for _, it := range reduceWarehouseInfoList {
  3790. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3791. }
  3792. //获取期中减少退库
  3793. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3794. for _, it := range lowInfo {
  3795. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3796. }
  3797. //
  3798. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3799. for _, it := range outInfo {
  3800. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3801. }
  3802. //期中盘盈
  3803. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3804. for _, it := range profit {
  3805. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3806. }
  3807. //期中盘亏
  3808. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3809. for _, it := range losses {
  3810. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3811. }
  3812. //获取期初结余
  3813. //service.GetNewOverInCount(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3814. }
  3815. if err != nil {
  3816. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3817. return
  3818. }
  3819. this.ServeSuccessJSON(map[string]interface{}{
  3820. "list": list,
  3821. "manufacturerList": manufacturerList,
  3822. "total": total,
  3823. })
  3824. }
  3825. func (this *SelfDrugApiController) GetCheckDrugBatchList() {
  3826. drug_id, _ := this.GetInt64("drug_id")
  3827. orgId := this.GetAdminUserInfo().CurrentOrgId
  3828. advicelist, _ := service.GetHisAdviceGroupList(drug_id, orgId)
  3829. outInfo, _ := service.GetDrugWarehousOutInfo(drug_id, orgId)
  3830. outInfoOne, _ := service.GetDrugWarehousOutInfoOne(drug_id, orgId)
  3831. baseDrugList, _ := service.GetDrugByGoodId(drug_id)
  3832. drugflow, _ := service.GetCheckDrugFlow(drug_id, orgId)
  3833. this.ServeSuccessJSON(map[string]interface{}{
  3834. "advicelist": advicelist,
  3835. "outInfo": outInfo,
  3836. "outInfoOne": outInfoOne,
  3837. "baseDrugList": baseDrugList,
  3838. "drugflow": drugflow,
  3839. })
  3840. }
  3841. func (this *SelfDrugApiController) GetCheckGoodBatchList() {
  3842. id, _ := this.GetInt64("id")
  3843. orgId := this.GetAdminUserInfo().CurrentOrgId
  3844. projectList, _ := service.GetCheckGoodBatchList(id, orgId)
  3845. warehouseList, _ := service.GetCheckGoodWarehouseList(id, orgId)
  3846. this.ServeSuccessJSON(map[string]interface{}{
  3847. "projectList": projectList,
  3848. "warehouseList": warehouseList,
  3849. })
  3850. }
  3851. func (this *SelfDrugApiController) GetDrugPatientName() {
  3852. drug_id, _ := this.GetInt64("drug_id")
  3853. sys_record_time, _ := this.GetInt64("sys_record_time")
  3854. orgId := this.GetAdminUserInfo().CurrentOrgId
  3855. advicelist, _ := service.GetHisAdviceListBySysRrecordTime(drug_id, sys_record_time, orgId)
  3856. outInfor, _ := service.GetDrugWarehouseOutInfoBySysRecordTime(drug_id, sys_record_time, orgId)
  3857. patients, _ := service.GetAllpatient(orgId)
  3858. this.ServeSuccessJSON(map[string]interface{}{
  3859. "advicelist": advicelist,
  3860. "outInfor": outInfor,
  3861. "patients": patients,
  3862. })
  3863. }
  3864. func (this *SelfDrugApiController) GetAllSelfDrugInfoList() {
  3865. orgId := this.GetAdminUserInfo().CurrentOrgId
  3866. drugInfoList, _ := service.GetAllSelfDrugInfoList(orgId)
  3867. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3868. dealerList, _ := service.GetAllDealerList(orgId)
  3869. this.ServeSuccessJSON(map[string]interface{}{
  3870. "drugInfoList": drugInfoList,
  3871. "manufacturerList": manufacturerList,
  3872. "dealerList": dealerList,
  3873. })
  3874. }
  3875. func (this *SelfDrugApiController) GetAllPatientList() {
  3876. orgId := this.GetAdminUserInfo().CurrentOrgId
  3877. patient, _ := service.GetAllPatientListByUserOrg(orgId)
  3878. this.ServeSuccessJSON(map[string]interface{}{
  3879. "patient": patient,
  3880. })
  3881. }
  3882. func (this *SelfDrugApiController) PostSearchSelfDrugList() {
  3883. keyword := this.GetString("keyword")
  3884. orgId := this.GetAdminUserInfo().CurrentOrgId
  3885. drugList, _ := service.PostSearchSelfDrugList(keyword, orgId)
  3886. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3887. dealerList, _ := service.GetAllDealerList(orgId)
  3888. var drugType = "药品类型"
  3889. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3890. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3891. this.ServeSuccessJSON(map[string]interface{}{
  3892. "manufacturerList": manufacturerList,
  3893. "dealerList": dealerList,
  3894. "list": drugList,
  3895. "drugTypeList": drugTypeList,
  3896. })
  3897. }
  3898. func (c *SelfDrugApiController) PostSelfDrugWarehouse() {
  3899. patient_id, _ := c.GetInt64("patient_id")
  3900. warehousing_time := c.GetString("warehousing_time")
  3901. warehousing_id, _ := c.GetInt64("warehousing_id")
  3902. adminUserInfo := c.GetAdminUserInfo()
  3903. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  3904. if parseDateErr != nil {
  3905. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  3906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3907. return
  3908. }
  3909. // 开始主事务
  3910. db := service.XTWriteDB()
  3911. tx := db.Begin()
  3912. // 在函数结束时处理事务回滚
  3913. defer func() {
  3914. if r := recover(); r != nil {
  3915. tx.Rollback()
  3916. } else {
  3917. tx.Commit()
  3918. }
  3919. }()
  3920. timeStr := time.Now().Format("2006-01-02")
  3921. timeArr := strings.Split(timeStr, "-")
  3922. total, _ := service.FindSelfAllWarehouseTotal(adminUserInfo.CurrentOrgId, tx)
  3923. total = total + 1
  3924. operation_time := time.Now().Unix()
  3925. creater := adminUserInfo.AdminUser.Id
  3926. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3927. warehousing := models.XtSelfDrugWarehouse{
  3928. ID: warehousing_id,
  3929. WarehousingOrder: warehousing_order,
  3930. OperationTime: operation_time,
  3931. OrgId: adminUserInfo.CurrentOrgId,
  3932. Creater: creater,
  3933. Ctime: time.Now().Unix(),
  3934. Status: 1,
  3935. WarehousingTime: warehousingDate.Unix(),
  3936. Type: 0,
  3937. StorehouseId: 0,
  3938. IsCheck: 2,
  3939. PatientId: patient_id,
  3940. }
  3941. if warehousing_id == 0 {
  3942. service.AddSelfDrugWarehouse(&warehousing, tx)
  3943. }
  3944. if warehousing_id > 0 {
  3945. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  3946. }
  3947. info, _ := service.FindLastSelfWarehousing(adminUserInfo.CurrentOrgId, patient_id, tx)
  3948. dataBody := make(map[string]interface{}, 0)
  3949. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3950. if err != nil {
  3951. utils.ErrorLog(err.Error())
  3952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3953. return
  3954. }
  3955. var warehousingInfo []*models.XtSelfDrugWarehouseInfo
  3956. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  3957. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  3958. if len(thisStockIn) > 0 {
  3959. for _, item := range thisStockIn {
  3960. items := item.(map[string]interface{})
  3961. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3962. utils.ErrorLog("id")
  3963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3964. return
  3965. }
  3966. id := int64(items["id"].(float64))
  3967. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  3968. utils.ErrorLog("drug_id")
  3969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3970. return
  3971. }
  3972. drug_id := int64(items["drug_id"].(float64))
  3973. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  3974. utils.ErrorLog("warehousing_count")
  3975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3976. return
  3977. }
  3978. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  3979. var productDates int64
  3980. var expiryDates int64
  3981. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  3982. expiryDates = 0
  3983. } else {
  3984. if len(items["expiry_date"].(string)) == 0 {
  3985. expiryDates = 0
  3986. } else {
  3987. expiryDate, _ := items["expiry_date"].(string)
  3988. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  3989. expiryDates = expiry_date.Unix()
  3990. }
  3991. }
  3992. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  3993. productDates = 0
  3994. } else {
  3995. if len(items["product_date"].(string)) == 0 {
  3996. productDates = 0
  3997. } else {
  3998. productDate, _ := items["product_date"].(string)
  3999. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  4000. productDates = product_date.Unix()
  4001. }
  4002. }
  4003. number, _ := items["number"].(string)
  4004. batch_number, _ := items["batch_number"].(string)
  4005. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  4006. utils.ErrorLog("max_unit")
  4007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4008. return
  4009. }
  4010. max_unit, _ := items["max_unit"].(string)
  4011. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  4012. utils.ErrorLog("min_unit")
  4013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4014. return
  4015. }
  4016. min_unit, _ := items["min_unit"].(string)
  4017. var remark string
  4018. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4019. remark = ""
  4020. } else {
  4021. remark = items["remark"].(string)
  4022. }
  4023. manufacturer := int64(items["manufacturer"].(float64))
  4024. dealer := int64(items["dealer"].(float64))
  4025. warehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4026. ID: id,
  4027. WarehousingOrder: warehousing_order,
  4028. WarehousingId: info.ID,
  4029. DrugId: drug_id,
  4030. Number: number,
  4031. ProductDate: productDates,
  4032. ExpiryDate: expiryDates,
  4033. WarehousingCount: warehousing_count,
  4034. Price: 0,
  4035. TotalPrice: 0,
  4036. Status: 1,
  4037. Ctime: time.Now().Unix(),
  4038. Remark: remark,
  4039. OrgId: adminUserInfo.CurrentOrgId,
  4040. Type: 0,
  4041. Manufacturer: manufacturer,
  4042. Dealer: dealer,
  4043. StockMaxNumber: 0,
  4044. RetailTotalPrice: 0,
  4045. BatchNumber: batch_number,
  4046. MaxUnit: max_unit,
  4047. MinUnit: min_unit,
  4048. RetailPrice: 0,
  4049. StorehouseId: 0,
  4050. IsCheck: 2,
  4051. StockMinNumber: 0,
  4052. PatientId: patient_id,
  4053. IsSys: 0,
  4054. RecordDate: warehousingDate.Unix(),
  4055. }
  4056. warehousingInfo = append(warehousingInfo, warehouseInfo)
  4057. }
  4058. }
  4059. }
  4060. for _, item := range warehousingInfo {
  4061. if item.ID == 0 {
  4062. service.CreatedSlefWarehouseing(item, tx)
  4063. }
  4064. if item.ID > 0 {
  4065. service.UpdateSelfWarehouseing(item, tx)
  4066. }
  4067. }
  4068. list, _ := service.FindSelfDrugWarehouseInfoListById(info.ID, adminUserInfo.CurrentOrgId, patient_id, tx)
  4069. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4070. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4071. var drugType = "药品类型"
  4072. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4073. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
  4074. c.ServeSuccessJSON(map[string]interface{}{
  4075. "warehousingInfo": warehousingInfo,
  4076. "list": list,
  4077. "manufacturerList": manufacturerList,
  4078. "dealerList": dealerList,
  4079. "drugTypeList": drugTypeList,
  4080. "info": info,
  4081. })
  4082. }
  4083. func (c *SelfDrugApiController) GetAllSelfDrugWarehouseInfoList() {
  4084. keyword := c.GetString("keyword")
  4085. orgId := c.GetAdminUserInfo().CurrentOrgId
  4086. patient_id, _ := c.GetInt64("patient_id")
  4087. baseList, _ := service.GetAllBaseDrugListByKeyWord(keyword, orgId)
  4088. var ids []int64
  4089. for _, item := range baseList {
  4090. ids = append(ids, item.ID)
  4091. }
  4092. infoList, _ := service.GetAllSelfDrugWarehouseInfoList(ids, orgId, patient_id)
  4093. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4094. dealerList, _ := service.GetAllDealerList(orgId)
  4095. var drugType = "药品类型"
  4096. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4097. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  4098. c.ServeSuccessJSON(map[string]interface{}{
  4099. "infoList": infoList,
  4100. "manufacturerList": manufacturerList,
  4101. "dealerList": dealerList,
  4102. "drugTypeList": drugTypeList,
  4103. })
  4104. }
  4105. func (c *SelfDrugApiController) GetSelfDrugWarehouseInfoByID() {
  4106. id, _ := c.GetInt64("id")
  4107. info, _ := service.GetSelfDrugWarehouseInfoByID(id)
  4108. warehouseInfo, _ := service.GetSelfDrugWarehouseInfo(info.WarehousingId)
  4109. orgId := c.GetAdminUserInfo().CurrentOrgId
  4110. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4111. dealerList, _ := service.GetAllDealerList(orgId)
  4112. var drugType = "药品类型"
  4113. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4114. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  4115. c.ServeSuccessJSON(map[string]interface{}{
  4116. "info": info,
  4117. "manufacturerList": manufacturerList,
  4118. "dealerList": dealerList,
  4119. "drugTypeList": drugTypeList,
  4120. "warehouseInfo": warehouseInfo,
  4121. })
  4122. }
  4123. func (c *SelfDrugApiController) ModifySelfDrugWarehouse() {
  4124. patient_id, _ := c.GetInt64("patient_id")
  4125. warehousing_time := c.GetString("warehousing_time")
  4126. warehousing_id, _ := c.GetInt64("warehousing_id")
  4127. adminUserInfo := c.GetAdminUserInfo()
  4128. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  4129. if parseDateErr != nil {
  4130. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  4131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4132. return
  4133. }
  4134. // 开始主事务
  4135. db := service.XTWriteDB()
  4136. tx := db.Begin()
  4137. // 在函数结束时处理事务回滚
  4138. defer func() {
  4139. if r := recover(); r != nil {
  4140. tx.Rollback()
  4141. } else {
  4142. tx.Commit()
  4143. }
  4144. }()
  4145. timeStr := time.Now().Format("2006-01-02")
  4146. timeArr := strings.Split(timeStr, "-")
  4147. total, _ := service.FindSelfAllWarehouseTotal(adminUserInfo.CurrentOrgId, tx)
  4148. total = total + 1
  4149. operation_time := time.Now().Unix()
  4150. creater := adminUserInfo.AdminUser.Id
  4151. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4152. warehousing := models.XtSelfDrugWarehouse{
  4153. ID: warehousing_id,
  4154. WarehousingOrder: warehousing_order,
  4155. OperationTime: operation_time,
  4156. OrgId: adminUserInfo.CurrentOrgId,
  4157. Creater: creater,
  4158. Ctime: time.Now().Unix(),
  4159. Status: 1,
  4160. WarehousingTime: warehousingDate.Unix(),
  4161. Type: 0,
  4162. StorehouseId: 0,
  4163. IsCheck: 2,
  4164. PatientId: patient_id,
  4165. }
  4166. if warehousing_id == 0 {
  4167. service.AddSelfDrugWarehouse(&warehousing, tx)
  4168. }
  4169. if warehousing_id > 0 {
  4170. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4171. }
  4172. info, _ := service.FindLastSelfWarehousing(adminUserInfo.CurrentOrgId, patient_id, tx)
  4173. dataBody := make(map[string]interface{}, 0)
  4174. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4175. if err != nil {
  4176. utils.ErrorLog(err.Error())
  4177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4178. return
  4179. }
  4180. var warehousingInfo []*models.XtSelfDrugWarehouseInfo
  4181. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  4182. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  4183. if len(thisStockIn) > 0 {
  4184. for _, item := range thisStockIn {
  4185. items := item.(map[string]interface{})
  4186. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4187. utils.ErrorLog("id")
  4188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4189. return
  4190. }
  4191. id := int64(items["id"].(float64))
  4192. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  4193. utils.ErrorLog("drug_id")
  4194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4195. return
  4196. }
  4197. drug_id := int64(items["drug_id"].(float64))
  4198. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  4199. utils.ErrorLog("warehousing_count")
  4200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4201. return
  4202. }
  4203. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  4204. var productDates int64
  4205. var expiryDates int64
  4206. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  4207. expiryDates = 0
  4208. } else {
  4209. if len(items["expiry_date"].(string)) == 0 {
  4210. expiryDates = 0
  4211. } else {
  4212. expiryDate, _ := items["expiry_date"].(string)
  4213. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  4214. expiryDates = expiry_date.Unix()
  4215. }
  4216. }
  4217. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  4218. productDates = 0
  4219. } else {
  4220. if len(items["product_date"].(string)) == 0 {
  4221. productDates = 0
  4222. } else {
  4223. productDate, _ := items["product_date"].(string)
  4224. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  4225. productDates = product_date.Unix()
  4226. }
  4227. }
  4228. number, _ := items["number"].(string)
  4229. batch_number, _ := items["batch_number"].(string)
  4230. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  4231. utils.ErrorLog("max_unit")
  4232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4233. return
  4234. }
  4235. max_unit, _ := items["max_unit"].(string)
  4236. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  4237. utils.ErrorLog("min_unit")
  4238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4239. return
  4240. }
  4241. min_unit, _ := items["min_unit"].(string)
  4242. var remark string
  4243. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4244. remark = ""
  4245. } else {
  4246. remark = items["remark"].(string)
  4247. }
  4248. manufacturer := int64(items["manufacturer"].(float64))
  4249. dealer := int64(items["dealer"].(float64))
  4250. warehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4251. ID: id,
  4252. WarehousingOrder: warehousing_order,
  4253. WarehousingId: info.ID,
  4254. DrugId: drug_id,
  4255. Number: number,
  4256. ProductDate: productDates,
  4257. ExpiryDate: expiryDates,
  4258. WarehousingCount: warehousing_count,
  4259. Price: 0,
  4260. TotalPrice: 0,
  4261. Status: 1,
  4262. Ctime: time.Now().Unix(),
  4263. Remark: remark,
  4264. OrgId: adminUserInfo.CurrentOrgId,
  4265. Type: 0,
  4266. Manufacturer: manufacturer,
  4267. Dealer: dealer,
  4268. StockMaxNumber: 0,
  4269. RetailTotalPrice: 0,
  4270. BatchNumber: batch_number,
  4271. MaxUnit: max_unit,
  4272. MinUnit: min_unit,
  4273. RetailPrice: 0,
  4274. StorehouseId: 0,
  4275. IsCheck: 2,
  4276. StockMinNumber: 0,
  4277. PatientId: patient_id,
  4278. IsSys: 0,
  4279. RecordDate: warehousingDate.Unix(),
  4280. }
  4281. warehousingInfo = append(warehousingInfo, warehouseInfo)
  4282. }
  4283. }
  4284. }
  4285. for _, item := range warehousingInfo {
  4286. if item.ID == 0 {
  4287. service.CreatedSlefWarehouseing(item, tx)
  4288. }
  4289. if item.ID > 0 {
  4290. service.UpdateSelfWarehouseing(item, tx)
  4291. }
  4292. }
  4293. list, _ := service.FindSelfDrugWarehouseInfoListById(info.ID, adminUserInfo.CurrentOrgId, patient_id, tx)
  4294. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4295. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4296. var drugType = "药品类型"
  4297. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4298. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
  4299. c.ServeSuccessJSON(map[string]interface{}{
  4300. "warehousingInfo": warehousingInfo,
  4301. "list": list,
  4302. "manufacturerList": manufacturerList,
  4303. "dealerList": dealerList,
  4304. "drugTypeList": drugTypeList,
  4305. "info": info,
  4306. })
  4307. }
  4308. func (c *SelfDrugApiController) DeleteSelfDrugWarehouse() {
  4309. id, _ := c.GetInt64("id")
  4310. // 开始主事务
  4311. db := service.XTWriteDB()
  4312. tx := db.Begin()
  4313. defer func() {
  4314. if r := recover(); r != nil {
  4315. tx.Rollback()
  4316. } else {
  4317. tx.Commit()
  4318. }
  4319. }()
  4320. service.DeleteSelfDrugWarehouse(id, tx)
  4321. c.ServeSuccessJSON(map[string]interface{}{
  4322. "msg": "删除成功",
  4323. })
  4324. }
  4325. func (c *SelfDrugApiController) TocheckSelfWarehouseingInfo() {
  4326. id, _ := c.GetInt64("warehousing_id")
  4327. patient_id, _ := c.GetInt64("patient_id")
  4328. orgId := c.GetAdminUserInfo().CurrentOrgId
  4329. info, _ := service.GetSelfWarehouseInfoByWarehouseInfo(id, patient_id, orgId)
  4330. db := service.XTWriteDB()
  4331. tx := db.Begin()
  4332. defer func() {
  4333. if r := recover(); r != nil {
  4334. tx.Rollback()
  4335. } else {
  4336. tx.Commit()
  4337. }
  4338. }()
  4339. if len(info) > 0 {
  4340. for _, item := range info {
  4341. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4342. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4343. //新增库存
  4344. service.AddSelfDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
  4345. }
  4346. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4347. //新增库存
  4348. service.AddSelfDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
  4349. }
  4350. if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4351. //新增库存
  4352. service.AddSelfDrugWarehouseStockMinNumber(item.WarehousingCount, item.ID, tx)
  4353. }
  4354. Creator := c.GetAdminUserInfo().AdminUser.Id
  4355. //查询默认仓库剩余多少库存
  4356. list, _ := service.GetDrugSumCountByPatient(patient_id, item.OrgId, item.DrugId, tx)
  4357. var sum_count int64
  4358. var sum_in_count int64
  4359. for _, it := range list {
  4360. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  4361. if it.MaxUnit == baseDrug.MaxUnit {
  4362. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4363. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4364. }
  4365. sum_count += it.StockMaxNumber + it.StockMinNumber
  4366. sum_in_count += it.WarehousingCount
  4367. }
  4368. flow := &models.XtSelfDrugFlow{
  4369. WarehousingId: 0,
  4370. DrugId: item.DrugId,
  4371. Number: item.Number,
  4372. BatchNumber: item.BatchNumber,
  4373. Count: item.WarehousingCount,
  4374. UserOrgId: item.OrgId,
  4375. PatientId: item.PatientId,
  4376. SystemTime: time.Now().Unix(),
  4377. ConsumableType: 1,
  4378. IsSys: 0,
  4379. WarehousingOrder: item.WarehousingOrder,
  4380. WarehouseOutId: 0,
  4381. WarehouseOutOrderNumber: "",
  4382. IsEdit: 0,
  4383. CancelStockId: 0,
  4384. CancelOrderNumber: "",
  4385. Manufacturer: 0,
  4386. Dealer: 0,
  4387. Creator: Creator,
  4388. UpdateCreator: Creator,
  4389. Status: 1,
  4390. Ctime: item.Ctime,
  4391. Mtime: 0,
  4392. Price: item.Price,
  4393. WarehousingDetailId: item.ID,
  4394. WarehouseOutDetailId: 0,
  4395. CancelOutDetailId: 0,
  4396. ExpireDate: item.ExpiryDate,
  4397. ProductDate: item.ProductDate,
  4398. MaxUnit: item.MaxUnit,
  4399. MinUnit: item.MinUnit,
  4400. StorehouseId: item.StorehouseId,
  4401. OverCount: sum_count,
  4402. OperateTime: time.Now().Unix(),
  4403. }
  4404. service.CreateSelfDrugFlow(flow, tx)
  4405. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.OrgId, item.DrugId, tx)
  4406. var total_count int64 // 入库总数量
  4407. var over_count int64 //剩余库存
  4408. for _, it := range drugInfolist {
  4409. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  4410. if it.MaxUnit == baseDrug.MaxUnit {
  4411. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4412. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4413. }
  4414. }
  4415. for _, it := range drugInfolist {
  4416. total_count += it.WarehousingCount
  4417. over_count += it.StockMaxNumber + it.StockMinNumber
  4418. }
  4419. //查询该仓库是否有默认数据
  4420. _, errcode := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.OrgId, tx)
  4421. if errcode == gorm.ErrRecordNotFound {
  4422. drugStock := models.XtSelfDrugStockCount{
  4423. UserOrgId: item.OrgId,
  4424. PatientId: item.PatientId,
  4425. SumInCount: total_count,
  4426. SumOutCount: 0,
  4427. SumCancelCount: 0,
  4428. DrugId: item.DrugId,
  4429. Ctime: time.Now().Unix(),
  4430. Mtime: 0,
  4431. Status: 1,
  4432. FlushCount: over_count,
  4433. SumActOutCount: 0,
  4434. }
  4435. service.CreateSelfDrugStockSum(drugStock, tx)
  4436. } else if errcode == nil {
  4437. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.OrgId, total_count, over_count, tx)
  4438. }
  4439. }
  4440. c.ServeSuccessJSON(map[string]interface{}{
  4441. "list": info,
  4442. })
  4443. }
  4444. }
  4445. func (c *SelfDrugApiController) GetSelfDrugBatchNumber() {
  4446. id, _ := c.GetInt64("id")
  4447. orgId := c.GetAdminUserInfo().CurrentOrgId
  4448. list, _ := service.GetSelfDrugBatchNumber(id, orgId)
  4449. c.ServeSuccessJSON(map[string]interface{}{
  4450. "list": list,
  4451. })
  4452. }
  4453. func (c *SelfDrugApiController) PostSelfDrugWarehouseOut() {
  4454. db := service.XTWriteDB()
  4455. tx := db.Begin()
  4456. defer func() {
  4457. if r := recover(); r != nil {
  4458. tx.Rollback()
  4459. } else {
  4460. tx.Commit()
  4461. }
  4462. }()
  4463. patient_id, _ := c.GetInt64("patient_id")
  4464. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  4465. ctime := time.Now().Unix()
  4466. adminUserInfo := c.GetAdminUserInfo()
  4467. warehousing_out_time := c.GetString("warehousing_out_time")
  4468. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  4469. if parseDateErr != nil {
  4470. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  4471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4472. return
  4473. }
  4474. timeStr := time.Now().Format("2006-01-02")
  4475. timeArr := strings.Split(timeStr, "-")
  4476. total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.CurrentOrgId, tx)
  4477. total = total + 1
  4478. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4479. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4480. number = number + total
  4481. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  4482. operation_time := time.Now().Unix()
  4483. creater := adminUserInfo.AdminUser.Id
  4484. //创建一个出库单
  4485. warehouseOut := models.XtSelfDrugWarehouseOut{
  4486. WarehouseOutOrderNumber: warehousing_out_order,
  4487. OperationTime: operation_time,
  4488. OrgId: adminUserInfo.CurrentOrgId,
  4489. Creater: creater,
  4490. Ctime: ctime,
  4491. Status: 1,
  4492. WarehouseOutTime: warehousingOutDate.Unix(),
  4493. Type: 0,
  4494. PatientId: patient_id,
  4495. IsCheck: 2,
  4496. }
  4497. if warehouse_out_id == 0 {
  4498. service.AddSelfSigleDrugWarehouseOut(&warehouseOut, tx)
  4499. }
  4500. if warehouse_out_id > 0 {
  4501. service.UpdateSelfSingleDrugWarehouseOut(warehouse_out_id, patient_id, tx)
  4502. }
  4503. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOut(adminUserInfo.CurrentOrgId, tx)
  4504. dataBody := make(map[string]interface{}, 0)
  4505. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4506. if err != nil {
  4507. utils.ErrorLog(err.Error())
  4508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4509. return
  4510. }
  4511. //出库单详情
  4512. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  4513. //把前端的参数加工为出库单详情
  4514. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  4515. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  4516. if len(thisStockIn) > 0 {
  4517. for _, item := range thisStockIn {
  4518. items := item.(map[string]interface{})
  4519. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  4520. utils.ErrorLog("drug_id")
  4521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4522. return
  4523. }
  4524. drug_id := int64(items["drug_id"].(float64))
  4525. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4526. utils.ErrorLog("count")
  4527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4528. return
  4529. }
  4530. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4531. remark := items["remark"].(string)
  4532. max_unit := items["max_unit"].(string)
  4533. dealer := int64(items["dealer"].(float64))
  4534. manufacturer := int64(items["manufacturer"].(float64))
  4535. batch_number := items["batch_number"].(string)
  4536. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  4537. var productDates int64
  4538. var expiryDates int64
  4539. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  4540. expiryDates = 0
  4541. } else {
  4542. if len(items["expiry_date"].(string)) == 0 {
  4543. expiryDates = 0
  4544. } else {
  4545. expiryDate, _ := items["expiry_date"].(string)
  4546. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  4547. expiryDates = expiry_date.Unix()
  4548. }
  4549. }
  4550. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  4551. productDates = 0
  4552. } else {
  4553. if len(items["product_date"].(string)) == 0 {
  4554. productDates = 0
  4555. } else {
  4556. productDate, _ := items["product_date"].(string)
  4557. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  4558. productDates = product_date.Unix()
  4559. }
  4560. }
  4561. stock_count, _ := items["stock_count"].(string)
  4562. patient_id := int64(items["patient_id"].(float64))
  4563. id := int64(items["id"].(float64))
  4564. class_type, _ := items["class_type"].(string)
  4565. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  4566. ID: id,
  4567. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4568. WarehouseOutId: lastWarehouseOut.ID,
  4569. DrugId: drug_id,
  4570. Count: count,
  4571. Price: 0,
  4572. TotalPrice: 0,
  4573. Status: 1,
  4574. Ctime: warehousingOutDate.Unix(),
  4575. Mtime: ctime,
  4576. Remark: remark,
  4577. OrgId: adminUserInfo.CurrentOrgId,
  4578. Type: 0,
  4579. Manufacturer: manufacturer,
  4580. Dealer: dealer,
  4581. RetailPrice: 0,
  4582. RetailTotalPrice: 0,
  4583. CountUnit: max_unit,
  4584. ExpiryDate: expiryDates,
  4585. ProductDate: productDates,
  4586. Number: "",
  4587. BatchNumber: batch_number,
  4588. IsSys: 0,
  4589. WarehouseInfoId: warehouse_info_id,
  4590. AdminUserId: 0,
  4591. StockCount: stock_count,
  4592. IsCheck: 2,
  4593. SysRecordTime: warehousingOutDate.Unix(),
  4594. PatientId: patient_id,
  4595. ClassType: class_type,
  4596. }
  4597. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  4598. }
  4599. }
  4600. }
  4601. //调用出库逻辑
  4602. for _, item := range warehousingOutInfo {
  4603. if item.ID == 0 {
  4604. errOne := service.AddSelfSigleDrugWarehouseOutInfo(item, tx)
  4605. fmt.Println(errOne)
  4606. }
  4607. if item.ID > 0 {
  4608. service.UpdatedSelfDrugWarehouseInfo(item, item.ID, tx)
  4609. }
  4610. }
  4611. list, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4612. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4613. warehousingOutInfoList, _ := service.GetSelfDrugWarehouseOutListById(lastWarehouseOut.ID, adminUserInfo.CurrentOrgId, tx)
  4614. var drugType = "药品类型"
  4615. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4616. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
  4617. c.ServeSuccessJSON(map[string]interface{}{
  4618. "msg": "2",
  4619. "drug_name": "",
  4620. "dose": "",
  4621. "dose_unit": "",
  4622. "min_number": "",
  4623. "min_unit": "",
  4624. "max_unit": "",
  4625. "dealerList": list,
  4626. "manufacturerList": manufacturerList,
  4627. "warehousingOutInfo": warehousingOutInfoList,
  4628. "warehouseOut": lastWarehouseOut,
  4629. "drugTypeList": drugTypeList,
  4630. })
  4631. return
  4632. }
  4633. func (c *SelfDrugApiController) GetAllSelfDrugWarehouseOutList() {
  4634. keyword := c.GetString("keyword")
  4635. patient_id, _ := c.GetInt64("patient_id")
  4636. start_time := c.GetString("start_time")
  4637. end_time := c.GetString("end_time")
  4638. timeLayout := "2006-01-02"
  4639. loc, _ := time.LoadLocation("Local")
  4640. var startTime int64
  4641. if len(start_time) > 0 {
  4642. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4643. if err != nil {
  4644. fmt.Println(err)
  4645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4646. return
  4647. }
  4648. startTime = theTime.Unix()
  4649. }
  4650. var endTime int64
  4651. if len(end_time) > 0 {
  4652. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4653. if err != nil {
  4654. utils.ErrorLog(err.Error())
  4655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4656. return
  4657. }
  4658. endTime = theTime.Unix()
  4659. }
  4660. orgId := c.GetAdminUserInfo().CurrentOrgId
  4661. baseList, _ := service.GetAllBaseDrugListByKeyWord(keyword, orgId)
  4662. var ids []int64
  4663. for _, item := range baseList {
  4664. ids = append(ids, item.ID)
  4665. }
  4666. outInfo, _ := service.GetAllSelfDrugWarehouseOutList(ids, patient_id, startTime, endTime, orgId)
  4667. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4668. dealerList, _ := service.GetAllDealerList(orgId)
  4669. var drugType = "药品类型"
  4670. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4671. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  4672. c.ServeSuccessJSON(map[string]interface{}{
  4673. "outInfo": outInfo,
  4674. "manufacturerList": manufacturerList,
  4675. "dealerList": dealerList,
  4676. "drugTypeList": drugTypeList,
  4677. })
  4678. }
  4679. func (c *SelfDrugApiController) DeleteSelfWarehouseOut() {
  4680. id, _ := c.GetInt64("id")
  4681. service.DeleteSelfWarehouseOut(id)
  4682. c.ServeSuccessJSON(map[string]interface{}{
  4683. "msg": "ok",
  4684. })
  4685. return
  4686. }
  4687. func (c *SelfDrugApiController) GetSelfDrugWarehouseOutById() {
  4688. id, _ := c.GetInt64("id")
  4689. outInfo, _ := service.GetSelfDrugWarehouseOutById(id)
  4690. c.ServeSuccessJSON(map[string]interface{}{
  4691. "outInfo": outInfo,
  4692. })
  4693. }