self_drug_api_congtroller.go 226KB

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