self_drug_api_congtroller.go 222KB

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