self_drug_api_congtroller.go 202KB

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