self_drug_api_congtroller.go 187KB

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