self_drug_api_congtroller.go 178KB

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