self_drug_api_congtroller.go 223KB

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