self_drug_api_congtroller.go 224KB

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