self_drug_api_congtroller.go 225KB

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