self_drug_api_congtroller.go 210KB

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