self_drug_api_congtroller.go 214KB

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