self_drug_api_congtroller.go 212KB

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