self_drug_api_congtroller.go 212KB

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