self_drug_api_congtroller.go 212KB

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