self_drug_api_congtroller.go 214KB

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