self_drug_service.go 187KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414
  1. package service
  2. import (
  3. "fmt"
  4. "strconv"
  5. "time"
  6. "XT_New/models"
  7. "github.com/jinzhu/gorm"
  8. )
  9. func GetCurrentPatient(orgid int64) (patients []*models.DrugPatients, err error) {
  10. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patients).Error
  11. return patients, err
  12. }
  13. func GetAllDrugName(orgid int64) (baseDrug []*models.XtBaseDrug, err error) {
  14. err = XTReadDB().Group("drug_name").Where("org_id = ? and status = 1 and find_in_set('停用',drug_status) = 0", orgid).Find(&baseDrug).Error
  15. return baseDrug, err
  16. }
  17. func GetDrugName(drugname string, orgid int64) (*models.XtDrugName, error) {
  18. drugName := models.XtDrugName{}
  19. err := XTReadDB().Model(&drugName).Where("drug_name = ? and user_org_id = ? and status =1", drugname, orgid).Find(&drugName).Error
  20. if err == gorm.ErrRecordNotFound {
  21. return nil, err
  22. }
  23. if err != nil {
  24. return nil, err
  25. }
  26. return &drugName, nil
  27. }
  28. func SaveDrugName(drugname *models.XtDrugName) error {
  29. err := XTWriteDB().Create(&drugname).Error
  30. return err
  31. }
  32. func GetDrugNameList(orgid int64) (druname []*models.XtDrugName, err error) {
  33. err = XTReadDB().Model(&druname).Where("user_org_id = ? and status = 1", orgid).Find(&druname).Error
  34. return druname, err
  35. }
  36. func GetRulleName(orgid int64, name string) (baseDrug []*models.XtBaseDrug, err error) {
  37. err = XTReadDB().Model(&baseDrug).Where("org_id = ? and drug_name = ? and status = 1", orgid, name).Find(&baseDrug).Error
  38. return baseDrug, err
  39. }
  40. func GetDrugId(id int64) (models.XtSelfMedical, error) {
  41. medical := models.XtSelfMedical{}
  42. err := XTReadDB().Model(&medical).Where("id = ? and status = 1", id).Find(&medical).Error
  43. return medical, err
  44. }
  45. func GetRulleList(orgid int64, id int64) (rulleName []*models.XtStandName, err error) {
  46. err = XTReadDB().Model(&rulleName).Where("user_org_id = ? and drug_id = ? and status = 1", orgid, id).Find(&rulleName).Error
  47. return rulleName, err
  48. }
  49. func GetUnitByBaseId(id int64) (models.XtBaseDrug, error) {
  50. drug := models.XtBaseDrug{}
  51. err := XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
  52. return drug, err
  53. }
  54. func IsExistStandName(drugname string, drugspec string, orgid int64) (*models.XtStandName, error) {
  55. standName := models.XtStandName{}
  56. err := XTReadDB().Model(&standName).Where("drug_name = ? and drug_spec = ? and user_org_id = ? and status = 1", drugname, drugspec, orgid).Find(&standName).Error
  57. if err == gorm.ErrRecordNotFound {
  58. return nil, err
  59. }
  60. if err != nil {
  61. return nil, err
  62. }
  63. return &standName, nil
  64. }
  65. func SaveRulleName(rullName *models.XtStandName) error {
  66. err := XTWriteDB().Model(&rullName).Create(&rullName).Error
  67. return err
  68. }
  69. func GetRullerNameDetail(id int64) (models.XtStandName, error) {
  70. rullerName := models.XtStandName{}
  71. err := XTReadDB().Model(&rullerName).Where("id= ? and status = 1", id).Find(&rullerName).Error
  72. return rullerName, err
  73. }
  74. func GetIsExit(drugname string, drugspec string, id int64) (*models.XtStandName, error) {
  75. standName := models.XtStandName{}
  76. err := XTReadDB().Model(&standName).Where("drug_name = ? and drug_spec = ? and id <> ? and status = 1", drugname, drugspec, id).Find(&standName).Error
  77. if err == gorm.ErrRecordNotFound {
  78. return nil, err
  79. }
  80. if err != nil {
  81. return nil, err
  82. }
  83. return &standName, nil
  84. }
  85. func UpdatedRullerName(id int64, re *models.XtStandName) error {
  86. err := XTWriteDB().Model(&re).Where("id=?", id).Update(map[string]interface{}{"drug_spec": re.DrugSpec, "min_unit": re.MinUnit, "price": re.Price, "drug_stock_limit": re.DrugStockLimit, "drug_name": re.DrugName, "drug_name_id": re.DrugNameId, "drug_id": re.DrugId}).Error
  87. return err
  88. }
  89. //func GetAllDrugNameList(orgid int64) (rullername []*models.XtStandName, err error) {
  90. //
  91. // err = XTReadDB().Group("drug_name").Model(&rullername).Where("user_org_id = ? and status = 1", orgid).Find(&rullername).Error
  92. // return rullername, err
  93. //}
  94. func GetAllDrugNameList(orgid int64) (drugName []*models.XtDrugName, err error) {
  95. err = XTReadDB().Model(&drugName).Where("user_org_id = ? and status = 1", orgid).Find(&drugName).Error
  96. return drugName, err
  97. }
  98. func GetRullerListByDrugName(drugname string, orgid int64) (rullername []*models.XtStandName, err error) {
  99. err = XTReadDB().Model(&rullername).Where("drug_id = ? and user_org_id = ? and status = 1", drugname, orgid).Find(&rullername).Error
  100. return rullername, err
  101. }
  102. func GetBaseDrugMedical(id int64) (models.XtBaseDrug, error) {
  103. drug := models.XtBaseDrug{}
  104. err := XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
  105. return drug, err
  106. }
  107. func GetNewBaseDrugMedical(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
  108. drug := models.XtBaseDrug{}
  109. err := tx.Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
  110. if err != gorm.ErrRecordNotFound {
  111. if err != nil {
  112. tx.Rollback()
  113. return drug, err
  114. }
  115. }
  116. return drug, err
  117. }
  118. func GetDrugWarehosueInfoById(drug_id int64, org_id int64) (drugInfo []*models.XtDrugWarehouseInfo, err error) {
  119. err = XTReadDB().Where("drug_id = ? and org_id = ? and status =1", drug_id, org_id).Find(&drugInfo).Error
  120. return drugInfo, err
  121. }
  122. func GetBaseDrugMedicalOne(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
  123. drug := models.XtBaseDrug{}
  124. err := tx.Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
  125. if err != gorm.ErrRecordNotFound {
  126. if err != nil {
  127. tx.Rollback()
  128. return drug, err
  129. }
  130. }
  131. return drug, err
  132. }
  133. func ModifyDrugWarehouseByInfoId(id int64, stock_max_number int64) error {
  134. info := models.DrugWarehouseInfo{}
  135. err := XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", stock_max_number)).Error
  136. return err
  137. }
  138. func ModifyDrugWarehouseByStockMin(id int64, stock_min_number int64) error {
  139. info := models.DrugWarehouseInfo{}
  140. err := XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", stock_min_number)).Error
  141. return err
  142. }
  143. func GetSelfMedicalByDrugName(drugname string, drug_spec string, patientid int64) (*models.XtSelfMedical, error) {
  144. medical := models.XtSelfMedical{}
  145. err := XTReadDB().Model(&medical).Where("drug_name = ? and drug_spec = ? and patient_id = ? and status = 1", drugname, drug_spec, patientid).Find(&medical).Error
  146. if err == gorm.ErrRecordNotFound {
  147. return nil, err
  148. }
  149. if err != nil {
  150. return nil, err
  151. }
  152. return &medical, err
  153. }
  154. func CreateSelfMedical(medical *models.XtSelfMedical) error {
  155. err = XTWriteDB().Model(&medical).Create(&medical).Error
  156. return err
  157. }
  158. func GetCurrentOrgAllStaff(orgid int64, app int64) (role []*models.SgjUserAdminRole, err error) {
  159. err = UserReadDB().Model(&role).Where("org_id = ? and app_id = ? and status = 1", orgid, app).Find(&role).Error
  160. return role, err
  161. }
  162. func CreateStock(stock *models.XtSelfStock) error {
  163. err := XTWriteDB().Model(&stock).Create(&stock).Error
  164. return err
  165. }
  166. func CreateOutStock(stock *models.XtSelfOutStock) error {
  167. err := XTWriteDB().Model(&stock).Create(&stock).Error
  168. return err
  169. }
  170. func GetStandDrugByDrugName(drugname string, orgid int64) (*models.XtStandName, error) {
  171. standname := models.XtStandName{}
  172. err := XTReadDB().Model(&standname).Where("drug_name = ? and user_org_id = ? and status = 1", drugname, orgid).Find(&standname).Error
  173. if err == gorm.ErrRecordNotFound {
  174. return nil, err
  175. }
  176. if err != nil {
  177. return nil, err
  178. }
  179. return &standname, nil
  180. }
  181. func DeleteDrugName(id int64) (models.XtDrugName, error) {
  182. standName := models.XtDrugName{}
  183. err := XTWriteDB().Model(&standName).Where("id = ?", id).Update(map[string]interface{}{"status": 0}).Error
  184. return standName, err
  185. }
  186. func GetDrugSetByUserOrgId(orgid int64) (*models.XtDrugSet, error) {
  187. set := models.XtDrugSet{}
  188. err := XTReadDB().Model(&set).Where("user_org_id = ? and status = 1", orgid).Find(&set).Error
  189. if err == gorm.ErrRecordNotFound {
  190. return nil, err
  191. }
  192. if err != nil {
  193. return nil, err
  194. }
  195. return &set, nil
  196. }
  197. func SaveRadio(drugSet *models.XtDrugSet) error {
  198. err := XTWriteDB().Model(&drugSet).Create(&drugSet).Error
  199. return err
  200. }
  201. func UpdateDrugSet(set *models.XtDrugSet, orgid int64) error {
  202. err := XTWriteDB().Model(&set).Where("user_org_id = ?", orgid).Update(map[string]interface{}{"drug_start": set.DrugStart}).Error
  203. return err
  204. }
  205. func GetMedicalsByName(orgid int64, drugname string) (*models.XtSelfMedical, error) {
  206. medical := models.XtSelfMedical{}
  207. err := XTReadDB().Model(&medical).Where("user_org_id = ? and drug_name = ? and status = 1", orgid, drugname).Find(&medical).Error
  208. if err == gorm.ErrRecordNotFound {
  209. return nil, err
  210. }
  211. if err != nil {
  212. return nil, err
  213. }
  214. return &medical, nil
  215. }
  216. func DeleteDrugStand(id int64) error {
  217. standName := models.XtStandName{}
  218. err := XTWriteDB().Model(&standName).Where("id =?", id).Update(map[string]interface{}{"status": 0}).Error
  219. return err
  220. }
  221. //func GetStockList(patientid int64, startime int64, keyword string) (stock []*models.SelfStocks, err error) {
  222. // db := XTReadDB().Table("xt_self_stock as x").Where("x.status = 1")
  223. // likeKey := "%" + keyword + "%"
  224. // table := XTReadDB().Table("xt_patients as s")
  225. // fmt.Println(table)
  226. // if patientid > 0 {
  227. // db = db.Where("x.patient_id = ?", patientid)
  228. // }
  229. // if startime > 0 {
  230. // db = db.Where("x.storck_time <= ?", startime)
  231. // }
  232. // err = db.Group("x.drug_name,x.drug_spec").Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.remarks,x.store_number,x.admin_user_id,x.storck_time,x.user_org_id,x.stock_in_number,x.patient_id,x.min_unit,sum(x.store_number) as total").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stock).Error
  233. // return stock, err
  234. //}
  235. func GetStockList(patientid int64, startime int64, keyword string, orgid int64) (stock []*models.XtSelfMedicals, err error) {
  236. likeKey := "%" + keyword + "%"
  237. db := XTReadDB().Table("xt_self_medical as x").Where("x.status = 1")
  238. if patientid > 0 {
  239. db = db.Where("x.patient_id = ?", patientid)
  240. }
  241. if orgid > 0 {
  242. db = db.Where("x.user_org_id = ?", orgid)
  243. }
  244. err = db.Group("x.drug_name,x.drug_spec").Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.min_unit,sum(t.store_number) as total,t.remarks,x.patient_id,t.stock_in_number,t.storck_time,t.admin_user_id,t.medic_id").Joins("left join xt_self_stock as t on t.medic_id = x.id").Where("t.storck_time<=?", startime).Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stock).Error
  245. return stock, err
  246. }
  247. func GetOutStockList(patientid int64, startime int64, keyword string, orgid int64) (outStock []*models.SelfOutStock, err error) {
  248. likeKey := "%" + keyword + "%"
  249. db := XTReadDB().Table("xt_self_medical as x").Where("x.status = 1")
  250. if patientid > 0 {
  251. db = db.Where("x.patient_id = ?", patientid)
  252. }
  253. if orgid > 0 {
  254. db = db.Where("x.user_org_id = ?", orgid)
  255. }
  256. err = db.Group("x.drug_name,x.drug_spec").Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.min_unit,sum(t.outstore_number) as count,t.remarks,x.patient_id,t.stock_out_number,t.storck_time,t.admin_user_id,t.medic_id").Joins("left join xt_self_out_stock as t on t.medic_id = x.id").Where("t.storck_time<=?", startime).Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&outStock).Error
  257. return outStock, err
  258. }
  259. func GetTotalOutStockList(patientid int64, startime int64, keyword string, orgid int64) (outStock []*models.SelfOutStock, err error) {
  260. likeKey := "%" + keyword + "%"
  261. db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
  262. if patientid > 0 {
  263. db = db.Where("x.patient_id = ?", patientid)
  264. }
  265. if orgid > 0 {
  266. db = db.Where("x.user_org_id = ?", orgid)
  267. }
  268. if startime > 0 {
  269. db = db.Where("x.storck_time<=?", startime)
  270. }
  271. err = db.Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.remarks,x.outstore_number,x.admin_user_id,x.storck_time,x.user_org_id,x.patient_id,x.exit_mode,x.medic_id").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Find(&outStock).Error
  272. return outStock, err
  273. }
  274. //func GetOutStockList(patientid int64, startime int64, keyword string) (outStock []*models.XtSelfOutStocks, err error) {
  275. // db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
  276. // likeKey := "%" + keyword + "%"
  277. // table := XTReadDB().Table("xt_patients as s")
  278. // fmt.Println(table)
  279. // if patientid > 0 {
  280. // db = db.Where("x.patient_id = ?", patientid)
  281. // }
  282. // if startime > 0 {
  283. // db = db.Where("x.storck_time <= ?", startime)
  284. // }
  285. // err = db.Group("x.drug_name,x.drug_spec").Select("x.drug_name,x.drug_spec,x.patient_id,x.stock_out_number,sum(x.outstore_number) as count").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&outStock).Error
  286. // return outStock, err
  287. //}
  288. func GetMedicalList(patientid int64, orgid int64, keyword string) (medical []*models.XtSelfMedicals, err error) {
  289. likeKey := "%" + keyword + "%"
  290. db := XTReadDB().Table("xt_self_medical as x").Where("x.status = 1")
  291. if patientid > 0 {
  292. db = db.Where("x.patient_id = ?", patientid)
  293. }
  294. if orgid > 0 {
  295. db = db.Where("x.user_org_id = ?", orgid)
  296. }
  297. err = db.Select("x.drug_name,x.id,x.drug_spec,x.patient_id,x.min_unit").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Group("x.drug_name,x.drug_spec").Scan(&medical).Error
  298. //err = XTReadDB().Model(&medical).Where("patient_id = ? and user_org_id = ? and status = 1", patientid, orgid).Group("drug_name,drug_spec").Find(&medical).Error
  299. return medical, err
  300. }
  301. func GetStockOutDetail(durgname string, patientid int64) (stock []*models.XtSelfOutStock, err error) {
  302. err = XTReadDB().Model(&stock).Where("drug_name = ? and patient_id = ? and status = 1", durgname, patientid).Find(&stock).Error
  303. return stock, err
  304. }
  305. func DeleteDrugStockNumber(drugname string, patientid int64) (models.XtSelfStock, error) {
  306. stock := models.XtSelfStock{}
  307. err := XTWriteDB().Model(&stock).Where("drug_name = ? and patient_id = ?", drugname, patientid).Update(map[string]interface{}{"status": 0}).Error
  308. return stock, err
  309. }
  310. func GetStockDetail(drugname string, drugspec string, startime int64, endtime int64, patientid int64, orgid int64) (stock []*models.XtSelfStock, err error) {
  311. err = XTReadDB().Model(&stock).Where("drug_name = ? and drug_spec = ? and patient_id =? and user_org_id = ? and status = 1 and storck_time>=? and storck_time<=?", drugname, drugspec, patientid, orgid, startime, endtime).Order("storck_time asc").Find(&stock).Error
  312. return stock, err
  313. }
  314. func GetOutStockDetail(drugname string, drugspec string, startime int64, endtime int64, patientid int64, orgid int64) (outStock []*models.XtSelfOutStock, err error) {
  315. err = XTReadDB().Model(&outStock).Where("drug_name = ? and drug_spec=? and patient_id = ? and user_org_id = ? and status = 1 and storck_time>=? and storck_time<=?", drugname, drugspec, patientid, orgid, startime, endtime).Order("storck_time asc").Find(&outStock).Error
  316. return outStock, err
  317. }
  318. func GetAllPatientStockList(drug_name string, drug_spec string, startime int64, endtime int64, keyword string, orgid int64) (stocks []*models.SelfStocks, err error) {
  319. db := XTReadDB().Table("xt_self_stock as x").Where("x.status = 1")
  320. likeKey := "%" + keyword + "%"
  321. table := XTReadDB().Table("xt_patients as s")
  322. fmt.Println(table)
  323. if len(drug_name) > 0 {
  324. db = db.Where("x.drug_name = ?", drug_name)
  325. }
  326. if len(drug_spec) > 0 {
  327. db = db.Where("x.drug_spec = ?", drug_spec)
  328. }
  329. //if startime > 0 {
  330. // db = db.Where("x.storck_time >= ?", startime)
  331. //}
  332. //if endtime > 0 {
  333. // db = db.Where("x.storck_time <= ?", endtime)
  334. //}
  335. if orgid > 0 {
  336. db = db.Where("x.user_org_id = ?", orgid)
  337. }
  338. err = db.Group("x.patient_id,x.drug_name,x.drug_spec").Select("t.drug_name,t.drug_spec,x.patient_id,x.store_number,sum(x.store_number) as total,s.name,s.dialysis_no,x.min_unit,x.drug_name_id").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_self_medical as t on t.id = x.medic_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stocks).Error
  339. return stocks, err
  340. }
  341. func GetAllPatientOutStockList(drug_name string, drug_spec string, startime int64, endtime int64, keyword string, orgid int64) (outStock []*models.XtSelfOutStocks, err error) {
  342. db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
  343. likeKey := "%" + keyword + "%"
  344. table := XTReadDB().Table("xt_patients as s")
  345. fmt.Println(table)
  346. if len(drug_name) > 0 {
  347. db = db.Where("x.drug_name = ?", drug_name)
  348. }
  349. if len(drug_spec) > 0 {
  350. db = db.Where("x.drug_spec=?", drug_spec)
  351. }
  352. if startime > 0 {
  353. db = db.Where("x.storck_time >= ?", startime)
  354. }
  355. if endtime > 0 {
  356. db = db.Where("x.storck_time<=?", endtime)
  357. }
  358. if orgid > 0 {
  359. db = db.Where("x.user_org_id = ?", orgid)
  360. }
  361. err = db.Group("x.patient_id,x.drug_name,x.drug_spec").Select("x.drug_name,x.drug_spec,x.patient_id,x.stock_out_number,sum(x.outstore_number) as count,s.name,s.dialysis_no,x.drug_name_id").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&outStock).Error
  362. return outStock, err
  363. }
  364. func GetDrugDataByPatientId(patientid int64) (selfMedical []*models.XtSelfMedical, err error) {
  365. err = XTReadDB().Group("drug_name,drug_spec").Model(&selfMedical).Where("patient_id = ? and status = 1", patientid).Find(&selfMedical).Error
  366. return selfMedical, err
  367. }
  368. func GetDruckStockConfig(orgid int64) (models.XtDrugStockConfig, error) {
  369. drugConfig := models.XtDrugStockConfig{}
  370. err := XTReadDB().Model(&drugConfig).Where("org_id = ? and status = 1", orgid).Find(&drugConfig).Error
  371. return drugConfig, err
  372. }
  373. func GetSetSelfMedical(orgid int64) (models.XtDrugSet, error) {
  374. medical := models.XtDrugSet{}
  375. err := XTReadDB().Model(&medical).Where("user_org_id = ? and status = 1", orgid).Find(&medical).Error
  376. return medical, err
  377. }
  378. func GetSelfMedicalList(patientid int64) (selfmedical []*models.XtSelfMedical, err error) {
  379. err = XTReadDB().Group("drug_name").Model(&selfmedical).Where("patient_id = ? and status = 1", patientid).Find(&selfmedical).Error
  380. return selfmedical, err
  381. }
  382. func GetDrugDescByDrugName(drugname string, patient_id int64, orgid int64) (selfMedical []*models.XtSelfMedical, err error) {
  383. err = XTReadDB().Model(&selfMedical).Where("drug_name = ? and patient_id = ? and user_org_id = ? and status = 1", drugname, patient_id, orgid).Find(&selfMedical).Error
  384. return selfMedical, err
  385. }
  386. func GetBaseMedcal(drugname string, orgid int64) (baseDrug []*models.XtBaseDrug, err error) {
  387. err = XTReadDB().Model(&baseDrug).Where("drug_name = ? and org_id = ? and status = 1", drugname, orgid).Find(&baseDrug).Error
  388. return baseDrug, err
  389. }
  390. func GetTotalBaseMedicalCount(drug_id int64, orgid int64) (drugInfo []*models.DrugWarehousingInfo, err error) {
  391. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
  392. err = db.Select("x.drug_id,sum(x.warehousing_count) as count").Where("drug_id = ? and org_id = ?", drug_id, orgid).Scan(&drugInfo).Error
  393. return drugInfo, err
  394. }
  395. func GetTotalBaseMedicalCountOut(drug_id int64, orgid int64) (drugOut []*models.DrugWarehousingInfo, err error) {
  396. db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
  397. err = db.Select("x.drug_id,sum(x.count) as count").Where("drug_id = ? and org_id = ?", drug_id, orgid).Scan(&drugOut).Error
  398. return drugOut, err
  399. }
  400. func GetDrugWareseOut(startime int64, orgid int64) (*models.XtDrugWarehouse, error) {
  401. warehouse := models.XtDrugWarehouse{}
  402. err := XTReadDB().Model(&warehouse).Where("warehousing_time = ? and org_id = ? and status = 1", startime, orgid).Find(&warehouse).Error
  403. if err == gorm.ErrRecordNotFound {
  404. return nil, err
  405. }
  406. if err != nil {
  407. return nil, err
  408. }
  409. return &warehouse, nil
  410. }
  411. func GetManufacturer(id int64) (models.XtBaseDrug, error) {
  412. drug := models.XtBaseDrug{}
  413. err := XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
  414. return drug, err
  415. }
  416. func CreateDrugWarehoue(warehouse *models.XtDrugWarehouse) error {
  417. err := XTWriteDB().Model(&warehouse).Create(&warehouse).Error
  418. return err
  419. }
  420. func GetTodayWareHousringOrder(startime int64, orgid int64) (models.XtDrugWarehouseOut, error) {
  421. warehouse := models.XtDrugWarehouseOut{}
  422. err := XTReadDB().Model(&warehouse).Where("warehouse_out_time = ? and org_id = ? and status = 1", startime, orgid).Find(&warehouse).Error
  423. return warehouse, err
  424. }
  425. func CreateDrugWareHouseOut(out *models.XtDrugWarehouseOut) error {
  426. err := XTWriteDB().Model(&out).Create(&out).Error
  427. return err
  428. }
  429. func CreateWareHouseOutInfo(info *models.XtDrugWarehouseOutInfo) error {
  430. err := XTWriteDB().Model(&info).Create(&info).Error
  431. return err
  432. }
  433. func CreateAotoMaticReduceDetail(detail *models.XtDrugAutomaticReduceDetail) error {
  434. err := XTWriteDB().Model(&detail).Create(&detail).Error
  435. return err
  436. }
  437. func GetDrugStockConfig(orgid int64) (models.XtDrugStockConfig, error) {
  438. config := models.XtDrugStockConfig{}
  439. err := XTReadDB().Model(&config).Where("org_id =? and status = 1", orgid).Find(&config).Error
  440. return config, err
  441. }
  442. func GetDrugSet(orgid int64) (models.XtDrugSet, error) {
  443. drugSet := models.XtDrugSet{}
  444. err := XTReadDB().Model(&drugSet).Where("user_org_id =? and status = 1", orgid).Find(&drugSet).Error
  445. return drugSet, err
  446. }
  447. type Drugs struct {
  448. ID int64 `gorm:"column:id" json:"id" form:"id"`
  449. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  450. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  451. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  452. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  453. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  454. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  455. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  456. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  457. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  458. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  459. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  460. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  461. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  462. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  463. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  464. Status int64 `gorm:"column:status" json:"status" form:"status"`
  465. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  466. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  467. Drugs []*Drugs `gorm:"ForeignKey:DrugName;AssociationForeignKey:DrugName" json:"drug_specs"`
  468. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  469. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  470. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  471. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  472. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  473. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  474. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  475. DrugDoseUnit int64 `grom:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  476. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  477. }
  478. func (Drugs) TableName() string {
  479. return "xt_base_drug"
  480. }
  481. func GetAllBaseDrugLibList(org_id int64) (drugs []*Drugs, err error) {
  482. db := readDb.Model(&models.BaseDrugLib{}).Preload("Drugs", "status = 1 AND org_id = ? AND find_in_set('停用',drug_status) = 0", org_id).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Group("drug_name")
  483. err = db.Find(&drugs).Error
  484. return
  485. }
  486. func GetAllBaseDrugLibListTwo(org_id int64) (drugs []*Drugs, err error) {
  487. err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&drugs).Error
  488. return drugs, err
  489. }
  490. type PrivateDrug struct {
  491. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  492. ID int64 `gorm:"column:id" json:"id" form:"id"`
  493. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  494. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  495. DrugNameId int64 `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
  496. Status int64 `gorm:"column:status" json:"status" form:"status"`
  497. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  498. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  499. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  500. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  501. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  502. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  503. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  504. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  505. PrivateDrug []*PrivateDrug `gorm:"ForeignKey:DrugName;AssociationForeignKey:DrugName" json:"drug_specs"`
  506. }
  507. func (PrivateDrug) TableName() string {
  508. return "xt_self_medical"
  509. }
  510. func GetPrivateDrugList(patient_id int64, org_id int64) (pds []*PrivateDrug, err error) {
  511. err = XTReadDB().Model(&PrivateDrug{}).Preload("PrivateDrug", "status = 1 AND user_org_id = ? AND patient_id = ? ", org_id, patient_id).Where("patient_id = ? and status = 1 AND user_org_id = ?", patient_id, org_id).Group("drug_name_id").Find(&pds).Error
  512. return
  513. }
  514. func GetAllMedicalList(orgid int64) (list []*models.XtSelfMedical, err error) {
  515. err = XTReadDB().Model(&list).Where("user_org_id = ? and status = 1", orgid).Group("drug_name").Find(&list).Error
  516. return list, err
  517. }
  518. func DeleteDrugNameById(id int64) (models.XtSelfMedical, error) {
  519. medical := models.XtSelfMedical{}
  520. err := XTWriteDB().Model(&medical).Where("id = ?", id).Updates(map[string]interface{}{"status": 0}).Error
  521. return medical, err
  522. }
  523. func GetDrugNameIsExist(drugid int64, orgid int64) (*models.XtDrugName, error) {
  524. drugName := models.XtDrugName{}
  525. err := XTReadDB().Model(&drugName).Where("drug_id = ? and user_org_id = ? and status = 1", drugid, orgid).Find(&drugName).Error
  526. if err == gorm.ErrRecordNotFound {
  527. return nil, err
  528. }
  529. if err != nil {
  530. return nil, err
  531. }
  532. return &drugName, nil
  533. }
  534. func UpdatedDrugName(id int64, orgid int64, drugName *models.XtDrugName) error {
  535. err := XTWriteDB().Model(&drugName).Where("drug_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_name": drugName.DrugName}).Error
  536. return err
  537. }
  538. func GetStandNameIsExist(id int64, orgid int64) (*models.XtStandName, error) {
  539. standName := models.XtStandName{}
  540. err := XTReadDB().Model(&standName).Where("drug_name_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&standName).Error
  541. if err == gorm.ErrRecordNotFound {
  542. return nil, err
  543. }
  544. if err != nil {
  545. return nil, err
  546. }
  547. return &standName, nil
  548. }
  549. func UpdateStandName(id int64, orgid int64, standName *models.XtStandName) error {
  550. err := XTWriteDB().Model(&standName).Where("drug_name_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_name": standName.DrugName, "drug_spec": standName.DrugSpec, "drug_stock_limit": standName.DrugStockLimit, "min_unit": standName.MinUnit}).Error
  551. return err
  552. }
  553. func GetSelfMedicalIsExist(id int64, orgid int64) (*models.XtSelfMedical, error) {
  554. medical := models.XtSelfMedical{}
  555. err := XTReadDB().Model(&medical).Where("drug_name_id = ? and user_org_id = ? and status =1", id, orgid).Find(&medical).Error
  556. if err == gorm.ErrRecordNotFound {
  557. return nil, err
  558. }
  559. if err != nil {
  560. return nil, err
  561. }
  562. return &medical, nil
  563. }
  564. func UpdateSelfMedical(id int64, orgid int64, medical *models.XtSelfMedical) error {
  565. err := XTWriteDB().Model(&medical).Where("drug_name_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_name": medical.DrugName, "drug_spec": medical.DrugSpec, "execution_frequency": medical.ExecutionFrequency, "prescribing_number": medical.PrescribingNumber, "delivery_way": medical.DeliveryWay, "single_dose": medical.SingleDose, "min_unit": medical.MinUnit}).Error
  566. return err
  567. }
  568. func GetDrugNameId(id int64, orgid int64) (models.XtSelfMedical, error) {
  569. medical := models.XtSelfMedical{}
  570. err := XTReadDB().Model(&medical).Where("drug_name_id = ? and status = 1 and user_org_id = ?", id, orgid).Find(&medical).Error
  571. return medical, err
  572. }
  573. func GetSelfStosckIsExist(id int64, orgid int64) (*models.XtSelfStock, error) {
  574. medical := models.XtSelfStock{}
  575. err := XTReadDB().Model(&medical).Where("drug_name_id = ? and user_org_id = ? and status =1", id, orgid).Find(&medical).Error
  576. if err == gorm.ErrRecordNotFound {
  577. return nil, err
  578. }
  579. if err != nil {
  580. return nil, err
  581. }
  582. return &medical, nil
  583. }
  584. func UpdatedSelfStock(stock *models.XtSelfStock, id int64, orgid int64) error {
  585. err := XTWriteDB().Model(&stock).Where("drug_name_id=? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_name": stock.DrugName, "min_unit": stock.MinUnit, "drug_spec": stock.DrugSpec}).Error
  586. return err
  587. }
  588. func GetOutSelfOutStockIsExist(id int64, orgid int64) (*models.XtSelfOutStock, error) {
  589. outStock := models.XtSelfOutStock{}
  590. err := XTReadDB().Model(&outStock).Where("drug_name_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&outStock).Error
  591. if err == gorm.ErrRecordNotFound {
  592. return nil, err
  593. }
  594. if err != nil {
  595. return nil, err
  596. }
  597. return &outStock, nil
  598. }
  599. func UpdatedOutSelfStock(stock *models.XtSelfOutStock, id int64, orgid int64) error {
  600. err := XTWriteDB().Model(&stock).Where("drug_name_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_name": stock.DrugName, "drug_spec": stock.DrugSpec}).Error
  601. return err
  602. }
  603. func GetDoctorAdviceIsExist(id int64, orgid int64) (*models.DoctorAdvice, error) {
  604. advice := models.DoctorAdvice{}
  605. err := XTReadDB().Model(&advice).Where("drug_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&advice).Error
  606. if err == gorm.ErrRecordNotFound {
  607. return nil, err
  608. }
  609. if err != nil {
  610. return nil, err
  611. }
  612. return &advice, nil
  613. }
  614. func UpdateNoExcuteDoctorAdvice(id int64, orgid int64, advice *models.DoctorAdvice) error {
  615. err := XTWriteDB().Model(&advice).Where("drug_id = ? and user_org_id = ? and status = 1 and execution_state = 2", id, orgid).Updates(map[string]interface{}{"advice_name": advice.AdviceName, "advice_desc": advice.AdviceDesc, "single_dose": advice.SingleDose, "single_dose_unit": advice.SingleDoseUnit, "delivery_way": advice.DeliveryWay, "execution_frequency": advice.ExecutionFrequency}).Error
  616. return err
  617. }
  618. func GetDoctorAdviceTemplateIsExist(id int64, orgid int64) (*models.DoctorAdviceTemplate, error) {
  619. template := models.DoctorAdviceTemplate{}
  620. err := XTReadDB().Model(&template).Where("drug_id = ? and org_id = ? and status = 1", id, orgid).Find(&template).Error
  621. if err == gorm.ErrRecordNotFound {
  622. return nil, err
  623. }
  624. if err != nil {
  625. return nil, err
  626. }
  627. return &template, nil
  628. }
  629. func UpdatedDoctorAdviceTemplate(id int64, orgid int64, template *models.DoctorAdviceTemplate) error {
  630. err := XTWriteDB().Model(&template).Where("drug_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"advice_name": template.AdviceName, "advice_desc": template.AdviceDesc, "single_dose": template.SingleDose, "single_dose_unit": template.SingleDoseUnit, "delivery_way": template.DeliveryWay, "execution_frequency": template.ExecutionFrequency}).Error
  631. return err
  632. }
  633. func ToSeachPatient(keyword string, orgid int64) (patients []*models.Patients, err error) {
  634. likeKey := "%" + keyword + "%"
  635. err = XTReadDB().Model(&patients).Where("name like ? and user_org_id = ? and status = 1", likeKey, orgid).Find(&patients).Error
  636. return patients, err
  637. }
  638. func GetMedicalDrugNameList(orgid int64) (drugName []*models.DrugName, err error) {
  639. db := XTReadDB().Model(&drugName).Where("user_org_id = ? and status = 1", orgid)
  640. err = db.Preload("XtStandName", "status =1 and user_org_id = ?", orgid).Find(&drugName).Error
  641. return drugName, err
  642. }
  643. func GetSelfOutStock(orgid int64, advicedate int64, patientid int64, adivicename string, advicedesc string) (*models.XtSelfOutStock, error) {
  644. stock := models.XtSelfOutStock{}
  645. err = XTReadDB().Model(&stock).Where("user_org_id = ? and storck_time = ? and patient_id = ? and drug_name = ? and drug_spec = ? and status = 1", orgid, advicedate, patientid, adivicename, advicedesc).Find(&stock).Error
  646. if err == gorm.ErrRecordNotFound {
  647. return nil, err
  648. }
  649. if err != nil {
  650. return nil, err
  651. }
  652. return &stock, err
  653. }
  654. func UpdatedSelfOutSatock(id int64, stock *models.XtSelfOutStock) error {
  655. err := XTWriteDB().Model(&stock).Where("id = ?", id).Updates(map[string]interface{}{"drug_name": stock.DrugName, "drug_name_id": stock.DrugNameId, "drug_spec": stock.DrugSpec, "outstore_number": stock.OutstoreNumber, "admin_user_id": stock.AdminUserId, "storck_time": stock.StorckTime, "patient_id": stock.PatientId, "stock_out_number": stock.StockOutNumber, "exit_mode": stock.ExitMode, "medic_id": stock.MedicId, "updated_time": time.Now().Unix()}).Error
  656. return err
  657. }
  658. func GetSelfStockQuery(typename int64, keywords string, startime int64, endtime int64, orgid int64, limit int64, page int64) (selfoutstock []*models.XtSelfOutStockOne, total int64, err error) {
  659. offset := (page - 1) * limit
  660. db := XTReadDB().Table("xt_self_stock as x").Where("x.status = 1")
  661. likeKey := "%" + keywords + "%"
  662. if len(keywords) > 0 {
  663. db = db.Where("x.drug_name like ? ", likeKey)
  664. }
  665. if startime > 0 {
  666. db = db.Where("x.storck_time >=?", startime)
  667. }
  668. if endtime > 0 {
  669. db = db.Where("x.storck_time<=?", endtime)
  670. }
  671. if orgid > 0 {
  672. db = db.Where("x.user_org_id = ?", orgid)
  673. }
  674. if typename > 0 {
  675. err = db.Select("x.drug_name,x.drug_name_id,x.drug_spec,Sum(store_number) as count,b.drug_type").Joins("left join xt_base_drug as b on b.id = x.drug_name_id and b.org_id = ? and b.status =1 ", orgid).Where("b.drug_type = ?", typename).Group("x.drug_name_id").Count(&total).Offset(offset).Limit(limit).Scan(&selfoutstock).Error
  676. } else {
  677. err = db.Select("x.drug_name,x.drug_name_id,x.drug_spec,Sum(store_number) as count,b.drug_type").Joins("left join xt_base_drug as b on b.id = x.drug_name_id and b.org_id = ? and b.status =1", orgid).Group("x.drug_name_id").Count(&total).Offset(offset).Limit(limit).Scan(&selfoutstock).Error
  678. }
  679. return selfoutstock, total, err
  680. }
  681. func GetSelfOutStockQuery(startTime int64, endTime int64, orgid int64) (selfoutstock []*models.XtSelfOutStockOne, err error) {
  682. db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
  683. if startTime > 0 {
  684. db = db.Where("x.storck_time >?", startTime)
  685. }
  686. if endTime > 0 {
  687. db = db.Where("x.storck_time<=?", endTime)
  688. }
  689. if orgid > 0 {
  690. db = db.Where("x.user_org_id = ?", orgid)
  691. }
  692. err = db.Select("x.drug_name_id,Sum(x.outstore_number) as count").Group("x.drug_name").Scan(&selfoutstock).Error
  693. return selfoutstock, err
  694. }
  695. func GetLastDrugWarehouseOutInfo(drugid int64, warehouseOutId int64, orgid int64) (models.XtDrugWarehouseOutInfo, error) {
  696. info := models.XtDrugWarehouseOutInfo{}
  697. err = XTReadDB().Model(&info).Where("drug_id = ? and warehouse_out_id = ? and org_id = ? and status = 1", drugid, warehouseOutId, orgid).Last(&info).Error
  698. return info, err
  699. }
  700. func PostSearchDrugWarehouseList(keyword string, orgid int64, storehouse_id int64) (info []*models.BloodDrugWarehouseInfo, err error) {
  701. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1 and (x.stock_max_number>0 or x.stock_min_number>0)")
  702. table := XTReadDB().Table("xt_base_drug as t").Where("t.status")
  703. fmt.Println(table)
  704. likeKey := "%" + keyword + "%"
  705. if orgid > 0 {
  706. db = db.Where("x.org_id = ?", orgid)
  707. }
  708. if storehouse_id > 0 {
  709. db = db.Where("x.storehouse_id = ?", storehouse_id)
  710. }
  711. err = db.Group("x.drug_id").Select("x.id,x.warehousing_id,x.drug_id,t.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,x.remark,x.warehousing_order,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.batch_number,x.storehouse_id,t.drug_origin_place,t.drug_name,t.min_unit,x.manufacturer,t.retail_price,t.max_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.drug_origin_place").Joins("left join xt_base_drug as t on t.id = x.drug_id").Where("t.drug_name like ? and t.org_id = ?", likeKey, orgid).Order("x.ctime desc").Scan(&info).Error
  712. return info, err
  713. }
  714. func CreateDrugPrice(price models.XtDrugAdjustPrice) error {
  715. err := XTWriteDB().Create(&price).Error
  716. return err
  717. }
  718. func GetDrugPriceList(startime int64, endtime int64, orgId int64, keyword string, limit int64, page int64) (adjust []*models.VmDrugAdjustPrice, total int64, err error) {
  719. likeKey := "%" + keyword + "%"
  720. offset := (page - 1) * limit
  721. db := XTReadDB().Table("xt_drug_adjust_price as x").Where("x.status = 1")
  722. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  723. tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  724. fmt.Println(table, tab)
  725. if len(keyword) > 0 {
  726. db = db.Where("x.warehousing_order = ? or r.user_name like ?", keyword, likeKey)
  727. }
  728. if orgId > 0 {
  729. db = db.Where("x.user_org_id = ?", orgId)
  730. }
  731. if startime > 0 {
  732. db = db.Where("x.ctime>=?", startime)
  733. }
  734. if endtime > 0 {
  735. db = db.Where("x.ctime<=?", endtime)
  736. }
  737. err = db.Group("x.id").Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.number").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Offset(offset).Limit(limit).Scan(&adjust).Error
  738. return adjust, total, err
  739. }
  740. func UpdateDrugAdjuestPrice(ids []string, info models.XtDrugAdjustPrice) error {
  741. err := XTWriteDB().Model(&info).Where("id in(?)", ids).Updates(map[string]interface{}{"checker": info.Checker, "checker_status": info.CheckerStatus, "checker_time": info.CheckerTime}).Error
  742. return err
  743. }
  744. func GetDrugAdjuestPrice(ids []string) (info []*models.XtDrugAdjustPrice, err error) {
  745. err = XTReadDB().Model(&info).Where("id in(?) and status = 1", ids).Find(&info).Error
  746. return info, err
  747. }
  748. func GetDrugDamage(ids []string) (info []*models.XtDrugDamage, err error) {
  749. err = XTReadDB().Model(&info).Where("id in(?) and status = 1", ids).Find(&info).Error
  750. return info, err
  751. }
  752. func CreateDrugDamage(damage models.XtDrugDamage) error {
  753. err := XTWriteDB().Create(&damage).Error
  754. return err
  755. }
  756. func GetDrugDamageList(startime int64, endtime int64, orgId int64, keyword string, limit int64, page int64, storehouse_id int64) (adjust []*models.VmDrugInventory, total int64, err error) {
  757. likeKey := "%" + keyword + "%"
  758. offset := (page - 1) * limit
  759. db := XTReadDB().Table("xt_drug_inventory as x").Where("x.status = 1 and type = 4")
  760. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  761. tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  762. fmt.Println(table, tab)
  763. //if len(keyword) > 0 {
  764. // db = db.Where("x.warehousing_order = ? or r.user_name like ?", keyword, likeKey)
  765. //}
  766. if len(keyword) > 0 {
  767. db = db.Where("x.drug_name like ?", likeKey)
  768. }
  769. if orgId > 0 {
  770. db = db.Where("x.user_org_id = ?", orgId)
  771. }
  772. if startime > 0 {
  773. db = db.Where("x.ctime >=?", startime)
  774. }
  775. if endtime > 0 {
  776. db = db.Where("x.ctime <=?", endtime)
  777. }
  778. if storehouse_id > 0 {
  779. db = db.Where("x.storehouse_id = ?", storehouse_id)
  780. }
  781. err = db.Group("x.drug_id").Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.number,x.drug_origin_place,x.warehouse_info_id,x.batch_number,x.stock_max_number,x.stock_min_number,x.storehouse_id,t.min_number,t.max_unit,t.min_unit,t.min_price").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Offset(offset).Limit(limit).Scan(&adjust).Error
  782. return adjust, total, err
  783. }
  784. func GetDrugDamageByOrgId(orgid int64) (list []*models.XtDrugInventory, err error) {
  785. err = XTReadDB().Model(&list).Where("user_org_id = ? and type = 4 and status = 1", orgid).Find(&list).Error
  786. return list, err
  787. }
  788. func UpdateDrugDamage(ids []string, damage models.XtDrugDamage) error {
  789. err := XTWriteDB().Model(&damage).Where("id in(?)", ids).Updates(map[string]interface{}{"checker": damage.Checker, "checker_status": damage.CheckerStatus, "checker_time": damage.CheckerTime}).Error
  790. return err
  791. }
  792. func GetDrugModifyPrice(id int64) (models.XtDrugAdjustPrice, error) {
  793. adjuest := models.XtDrugAdjustPrice{}
  794. err := XTReadDB().Model(&adjuest).Where("id=? and status = 1", id).Find(&adjuest).Error
  795. return adjuest, err
  796. }
  797. func ModifyDrugPrice(id int64, adjust models.XtDrugAdjustPrice) error {
  798. err := XTWriteDB().Model(&adjust).Where("id=? and status = 1", id).Updates(map[string]interface{}{"drug_name": adjust.DrugName, "retail_price": adjust.RetailPrice, "new_price": adjust.NewPrice, "count": adjust.Count, "remark": adjust.Remark, "specification_name": adjust.SpecificationName, "warehousing_unit": adjust.WarehousingUnit, "manufacturer": adjust.Manufacturer, "number": adjust.Number, "drug_id": adjust.DrugId}).Error
  799. return err
  800. }
  801. func GetModifyPricePrint(ids []string) (info []*models.XtDrugAdjustPrice, err error) {
  802. err = XTReadDB().Model(&info).Where("id in(?) and status = 1", ids).Find(&info).Error
  803. return info, err
  804. }
  805. func GetDrugDamageDetail(id int64) (models.XtDrugDamage, error) {
  806. damage := models.XtDrugDamage{}
  807. err := XTReadDB().Model(&damage).Where("id=? and status = 1", id).Find(&damage).Error
  808. return damage, err
  809. }
  810. func ModifyDrugDamage(id int64, damage models.XtDrugDamage) error {
  811. err := XTWriteDB().Model(&damage).Where("id=? and status = 1", id).Updates(map[string]interface{}{"drug_name": damage.DrugName, "warehousing_unit": damage.WarehousingUnit, "count": damage.Count, "last_price": damage.LastPrice, "retail_price": damage.RetailPrice, "new_price": damage.NewPrice, "manufacturer": damage.Manufacturer, "remark": damage.Remark, "number": damage.Number, "drug_id": damage.DrugId, "stock_max_number": damage.StockMaxNumber, "stock_min_number": damage.StockMinNumber, "warehousing_info_id": damage.WarehousingInfoId, "drug_origin_place": damage.DrugOriginPlace}).Error
  812. return err
  813. }
  814. func DeleteDrugDamage(id int64) error {
  815. damage := models.XtDrugDamage{}
  816. err := XTWriteDB().Model(&damage).Where("id=? and status = 1").Updates(map[string]interface{}{"status": 0}).Error
  817. return err
  818. }
  819. func GetDrugDamagePrint(ids []string) (damage []*models.XtDrugDamage, err error) {
  820. err = XTReadDB().Model(&damage).Where("id in(?) and status = 1", ids).Find(&damage).Error
  821. return damage, err
  822. }
  823. func GetWarehoseInfoById(id int64, storehouse_id int64, orgid int64) (info []*models.XtDrugWarehouseInfo, err error) {
  824. if orgid == 10191 {
  825. err = XTReadDB().Model(&info).Where("drug_id=? and status = 1 and storehouse_id = ? and is_check = 1", id, storehouse_id).Preload("XtBaseDrug", "status= 1").Find(&info).Error
  826. return info, err
  827. } else {
  828. err = XTReadDB().Model(&info).Where("drug_id=? and status = 1 and storehouse_id = ? and is_check = 1 and (stock_max_number>0 or stock_min_number>0)", id, storehouse_id).Preload("XtBaseDrug", "status= 1").Find(&info).Error
  829. return info, err
  830. }
  831. }
  832. func CreateDrugInventory(inventory models.XtDrugInventory) error {
  833. err := XTWriteDB().Create(&inventory).Error
  834. return err
  835. }
  836. func GetDrugInventoryList(keyword string, page int64, limit int64, orgid int64, startime int64, endtime int64) (list []*models.VmDrugInventory, total int64, err error) {
  837. fmt.Println("startdate", limit, page)
  838. likeKey := "%" + keyword + "%"
  839. offset := (page - 1) * limit
  840. db := XTReadDB().Table("xt_drug_inventory as x").Where("x.status = 1")
  841. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  842. tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  843. fmt.Println(table, tab)
  844. if len(keyword) > 0 {
  845. db = db.Where("x.warehousing_order = ? or r.user_name like ?", keyword, likeKey)
  846. }
  847. if orgid > 0 {
  848. db = db.Where("x.user_org_id = ?", orgid)
  849. }
  850. if startime > 0 {
  851. db = db.Where("x.start_time >=?", startime)
  852. }
  853. if endtime > 0 {
  854. db = db.Where("x.start_time<=?", endtime)
  855. }
  856. err = db.Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.number,x.batch_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.min_count,x.min_unit,t.dose,t.dose_unit,t.max_unit,t.min_unit").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Order("x.id desc").Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
  857. return list, total, err
  858. }
  859. func UpdateDrugInventory(ids []string, inventory models.XtDrugInventory) error {
  860. err := XTWriteDB().Model(&inventory).Where("id in(?) and status = 1", ids).Updates(map[string]interface{}{"checker": inventory.Checker, "checker_status": inventory.CheckerStatus, "checker_time": inventory.CheckerTime}).Error
  861. return err
  862. }
  863. func GetDrugInventoryListByIds(ids []string) (inventory []*models.XtDrugInventory, err error) {
  864. err = XTReadDB().Model(&inventory).Where("id in(?) and status = 1", ids).Find(&inventory).Error
  865. return inventory, err
  866. }
  867. func GetDrugDetailByDrugId(drug_id int64) (models.XtBaseDrug, error) {
  868. drug := models.XtBaseDrug{}
  869. err := XTReadDB().Model(&drug).Where("id = ? and status = 1", drug_id).Find(&drug).Error
  870. return drug, err
  871. }
  872. func GetDrugWareInfoById(id int64) (models.XtDrugWarehouseInfo, error) {
  873. info := models.XtDrugWarehouseInfo{}
  874. err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
  875. return info, err
  876. }
  877. func GetDrugWareInfoByIdTwo(id int64) (info []*models.XtDrugWarehouseInfo, err error) {
  878. err = XTReadDB().Model(&info).Where("(id = ? or warehousing_info_id = ?) and status = 1", id, id).Find(&info).Error
  879. return info, err
  880. }
  881. func GetLastDrugWarehouse(orgid int64) (models.DrugWarehouse, error) {
  882. info := models.DrugWarehouse{}
  883. err := XTReadDB().Model(&info).Where("org_id=? and status = 1", orgid).Last(&info).Error
  884. return info, err
  885. }
  886. func GetLastDrugWarehouseOut(orgid int64) (models.DrugWarehouseOut, error) {
  887. info := models.DrugWarehouseOut{}
  888. err := XTReadDB().Model(&info).Where("org_id=? and status = 1", orgid).Last(&info).Error
  889. return info, err
  890. }
  891. func GetLastDrugWarehouseInfSix(drugid int64) (models.XtDrugWarehouseInfo, error) {
  892. info := models.XtDrugWarehouseInfo{}
  893. err := XTReadDB().Model(&info).Where("drug_id=? and status = 1", drugid).Last(&info).Error
  894. return info, err
  895. }
  896. func GetFirstDrugWarehouseInfo(drugid int64) (models.XtDrugWarehouseInfo, error) {
  897. info := models.XtDrugWarehouseInfo{}
  898. err := XTReadDB().Model(&info).Where("id=? and status = 1", drugid).First(&info).Error
  899. return info, err
  900. }
  901. func GetDrugInventoryDetail(id int64) (models.XtDrugInventory, error) {
  902. inventory := models.XtDrugInventory{}
  903. err := XTReadDB().Model(&inventory).Where("id = ? and status = 1", id).Find(&inventory).Error
  904. return inventory, err
  905. }
  906. func ModifyDrugInventory(id int64, info models.XtDrugInventory) error {
  907. err := XTWriteDB().Model(&info).Where("id=? and status = 1", id).Updates(map[string]interface{}{"drug_name": info.DrugName, "specification_name": info.SpecificationName, "warehousing_unit": info.WarehousingUnit, "count": info.Count, "last_price": info.LastPrice, "manufacturer": info.Manufacturer, "remark": info.Remark, "drug_id": info.DrugId, "warehousing_order": info.WarehousingOrder, "number": info.Number, "total": info.Number, "drug_origin_place": info.DrugOriginPlace, "stock_max_number": info.StockMaxNumber, "stock_min_number": info.StockMinNumber, "warehouse_info_id": info.WarehouseInfoId, "min_count": info.MinCount, "min_unit": info.MinUnit}).Error
  908. return err
  909. }
  910. func DeleteDrugInventory(id int64) error {
  911. inventory := models.XtDrugInventory{}
  912. err := XTWriteDB().Model(&inventory).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  913. return err
  914. }
  915. func GetDrugInventoryPrintList(ids []string) (info []*models.XtDrugInventory, err error) {
  916. err = XTReadDB().Where("id in(?) and status = 1", ids).Find(&info).Error
  917. return info, err
  918. }
  919. func GetDrugInventoryDetailList(keyword string, page int64, limit int64, orgid int64, storehouse_id int64) (list []*models.VmDrugInventory, total int64, err error) {
  920. likeKey := "%" + keyword + "%"
  921. offset := (page - 1) * limit
  922. db := XTReadDB().Table("xt_drug_inventory as x").Where("x.status = 1")
  923. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  924. tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  925. fmt.Println(table, tab)
  926. if len(keyword) > 0 {
  927. db = db.Where("x.warehousing_order = ? or r.user_name like ? or t.drug_name like ?", keyword, likeKey, likeKey)
  928. }
  929. if orgid > 0 {
  930. db = db.Where("x.user_org_id = ?", orgid)
  931. }
  932. if storehouse_id > 0 {
  933. db = db.Where("x.storehouse_id = ?", storehouse_id)
  934. }
  935. err = db.Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.number,x.batch_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.drug_origin_place,x.expiry_date,x.product_date,x.min_count,x.storehouse_id,x.ctime,x.warehouse_info_id,t.dose,t.dose_unit,t.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.last_stock_max_number,x.last_stock_min_number,x.inventory_type,t.min_number,t.retail_price").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.id desc").Scan(&list).Error
  936. return list, total, err
  937. }
  938. func GetDrugInventoryDetailMapList(keyword string, page int64, limit int64, orgid int64, storehouse_id int64, ids []string) (list []*models.VmDrugInventory, total int64, err error) {
  939. likeKey := "%" + keyword + "%"
  940. offset := (page - 1) * limit
  941. db := XTReadDB().Table("xt_drug_inventory as x").Where("x.status = 1")
  942. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  943. tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
  944. fmt.Println(table, tab)
  945. if len(keyword) > 0 {
  946. db = db.Where("x.warehousing_order = ? or r.user_name like ? or t.drug_name like ?", keyword, likeKey, likeKey)
  947. }
  948. if orgid > 0 {
  949. db = db.Where("x.user_org_id = ?", orgid)
  950. }
  951. if storehouse_id > 0 {
  952. db = db.Where("x.storehouse_id = ?", storehouse_id)
  953. }
  954. if len(ids) > 0 {
  955. db = db.Where("x.id in(?)", ids)
  956. }
  957. err = db.Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.number,x.batch_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.drug_origin_place,x.expiry_date,x.product_date,x.min_count,x.storehouse_id,x.warehouse_info_id,t.dose,t.dose_unit,t.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.last_stock_max_number,x.last_stock_min_number,x.inventory_type,t.min_number,t.retail_price").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Offset(offset).Limit(limit).Scan(&list).Error
  958. return list, total, err
  959. }
  960. func GetDrugInventoryDetailListTwo(keyword string, page int64, limit int64, orgid int64, storehouse_id int64) (list []*models.XtDrugInventory, total int64, err error) {
  961. db := XTReadDB().Model(&list).Where("status = 1")
  962. if orgid > 0 {
  963. db = db.Where("user_org_id = ?", orgid)
  964. }
  965. if storehouse_id > 0 {
  966. db = db.Where("storehouse_id = ?", storehouse_id)
  967. }
  968. offset := (page - 1) * limit
  969. err = db.Preload("BaseDrugLib", "org_id = ? and status = 1", orgid).Preload("DrugWarehouseInfo", "org_id = ? and status = 1", orgid).Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  970. return list, total, err
  971. }
  972. func UpdateDrugProofInventory(id int64, inventory *models.XtDrugInventory) error {
  973. err := XTWriteDB().Model(&inventory).Where("id=? and status = 1", id).Updates(map[string]interface{}{"warehouse_info_id": inventory.WarehouseInfoId, "proof_count": inventory.ProofCount, "warehousing_unit": inventory.WarehousingUnit, "remark": inventory.Remark}).Error
  974. return err
  975. }
  976. func UpdateDrugWarehouseInfoById(id int64, inventory *models.XtDrugWarehouseInfo) error {
  977. err := XTWriteDB().Model(&inventory).Where("id = ?", id).Updates(map[string]interface{}{"stock_max_number": inventory.StockMaxNumber}).Error
  978. return err
  979. }
  980. func GetDrugWarehouseInfoTotal(id int64) (list []*models.XtDrugWarehouseInfo, err error) {
  981. err = XTReadDB().Where("id = ? or warehousing_info_id = ? and status = 1", id, id).Preload("XtBaseDrug", "status = 1").Find(&list).Error
  982. return list, err
  983. }
  984. func CreateDrugWarehouseInfo(info models.DrugWarehouseInfo) error {
  985. err := XTWriteDB().Create(&info).Error
  986. return err
  987. }
  988. func CreateDrugWarehouseOutInfo(info models.DrugWarehouseOutInfo) error {
  989. err := XTWriteDB().Create(&info).Error
  990. return err
  991. }
  992. func GetDamageByDrugId(drugid int64, warhousingorder string, drugtype int64) (drug []*models.VmXtDrugInventory, err error) {
  993. db := XTReadDB().Table("xt_drug_inventory").Where("status = 1")
  994. if drugid > 0 {
  995. db = db.Where("drug_id = ?", drugid)
  996. }
  997. if len(warhousingorder) > 0 {
  998. db = db.Where("warehousing_order = ?", warhousingorder)
  999. }
  1000. if drugtype > 0 {
  1001. db = db.Where("type = ?", drugtype)
  1002. }
  1003. if drugtype == 0 {
  1004. db = db.Where("type = 4")
  1005. }
  1006. err = db.Preload("XtBaseDrug", "status = 1").Find(&drug).Error
  1007. return drug, err
  1008. }
  1009. func GetInventoryModeList(orgid int64) (info []*models.PatientDrugWarehouseInfo, err error) {
  1010. if orgid == 10653 {
  1011. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and (x.warehousing_count>0) and (x.stock_max_number>0 or x.stock_min_number>0)")
  1012. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  1013. fmt.Println(table)
  1014. if orgid > 0 {
  1015. db = db.Where("x.org_id = ?", orgid)
  1016. }
  1017. err = db.Select("x.drug_id,x.number,x.product_date,x.expiry_date,x.stock_max_number,x.stock_min_number,x.batch_number,t.drug_name,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,x.manufacturer,x.dealer,t.sum_count").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id,x.batch_number").Scan(&info).Error
  1018. return info, err
  1019. } else {
  1020. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and (x.warehousing_count>0)")
  1021. table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
  1022. fmt.Println(table)
  1023. if orgid > 0 {
  1024. db = db.Where("x.org_id = ?", orgid)
  1025. }
  1026. err = db.Select("x.drug_id,x.number,x.product_date,x.expiry_date,x.stock_max_number,x.stock_min_number,x.batch_number,t.drug_name,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,x.manufacturer,x.dealer,t.sum_count").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id,x.batch_number").Scan(&info).Error
  1027. return info, err
  1028. }
  1029. }
  1030. func GetManufacturerListByKeyword(orgid int64, keyword string) (list []*models.BloodManufacturer, err error) {
  1031. likeKey := "%" + keyword + "%"
  1032. db := XTReadDB().Model(&list).Where("status = 1")
  1033. if orgid > 0 {
  1034. db = db.Where("org_id = ?", orgid)
  1035. }
  1036. if len(keyword) > 0 {
  1037. db = db.Where("manufacturer_name like ?", likeKey)
  1038. }
  1039. err = db.Find(&list).Error
  1040. return list, err
  1041. }
  1042. func GetGoodNameByword(orgid int64, keyword string) (list []*models.GoodInfo, err error) {
  1043. likeKey := "%" + keyword + "%"
  1044. db := XTReadDB().Model(&list).Where("status = 1")
  1045. if orgid > 0 {
  1046. db = db.Where("org_id = ?", orgid)
  1047. }
  1048. if len(keyword) > 0 {
  1049. db = db.Where("good_name like ?", likeKey)
  1050. }
  1051. err = db.Find(&list).Error
  1052. return list, err
  1053. }
  1054. func GetDrugNameByword(orgid int64, keyword string) (list []*models.XtBaseDrug, err error) {
  1055. likeKey := "%" + keyword + "%"
  1056. db := XTReadDB().Model(&list).Where("status = 1")
  1057. if orgid > 0 {
  1058. db = db.Where("org_id = ?", orgid)
  1059. }
  1060. if len(keyword) > 0 {
  1061. db = db.Where("drug_name like ?", likeKey)
  1062. }
  1063. err = db.Find(&list).Error
  1064. return list, err
  1065. }
  1066. func GetDrugNameBywordOne(orgid int64, keyword string) (list []*models.XtBaseDrug, err error) {
  1067. likeKey := "%" + keyword + "%"
  1068. db := XTReadDB().Model(&list).Where("status = 1 and is_self_drug =1")
  1069. if orgid > 0 {
  1070. db = db.Where("org_id = ?", orgid)
  1071. }
  1072. if len(keyword) > 0 {
  1073. db = db.Where("drug_name like ?", likeKey)
  1074. }
  1075. err = db.Find(&list).Error
  1076. return list, err
  1077. }
  1078. func GetGoodWarehouseInfoByOrgId(orgid int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
  1079. db := XTReadDB().Model(&info).Where("is_check =1 and status =1")
  1080. if orgid > 0 {
  1081. db = db.Where("org_id = ?", orgid)
  1082. }
  1083. if storehouse_id > 0 {
  1084. db = db.Where("storehouse_id = ?", storehouse_id)
  1085. }
  1086. err = db.Group("good_id").Find(&info).Error
  1087. return info, err
  1088. }
  1089. func GetGoodWarehouseInfoByOrgIdTwo(orgid int64) (info []*models.GoodQueryNewWarehousingInfo, err error) {
  1090. db := XTReadDB().Model(&info).Where("is_check =1 and status =1")
  1091. if orgid > 0 {
  1092. db = db.Where("org_id = ?", orgid)
  1093. }
  1094. err = db.Group("good_id").Find(&info).Error
  1095. return info, err
  1096. }
  1097. func GetGoodNewQuery(orgId int64, storehouse_id int64, good_type int64, keyword string, page int64, limit int64, ids []int64, goodIds []int64, startime int64, endtime int64) (good []*models.NewGoodInformation, total int64, err error) {
  1098. offset := (page - 1) * limit
  1099. likeKey := "%" + keyword + "%"
  1100. db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1 and x.total_count > 0 and x.org_id =?", orgId)
  1101. if good_type == 2 {
  1102. db = db.Where(" x.total_count<=x.stock_warn_count")
  1103. }
  1104. if len(goodIds) > 0 {
  1105. db = db.Where("id in(?)", goodIds)
  1106. }
  1107. if len(keyword) > 0 {
  1108. db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
  1109. }
  1110. err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Find(&good).Error
  1111. return good, total, err
  1112. }
  1113. func FindGoodWarehouseInfoGroup(good_id int64, orgid int64, storhouse_id int64, startime int64, endtime int64) (info []*models.WarehousingInfo, err error) {
  1114. db := XTReadDB().Model(&info).Where("status = 1 and is_check = 1")
  1115. if good_id > 0 {
  1116. db = db.Where("good_id = ?", good_id)
  1117. }
  1118. if orgid > 0 {
  1119. db = db.Where("org_id = ?", orgid)
  1120. }
  1121. if storhouse_id > 0 {
  1122. db = db.Where("storehouse_id = ?", storhouse_id)
  1123. }
  1124. if startime > 0 {
  1125. db = db.Where("ctime >=?", startime)
  1126. }
  1127. if endtime > 0 {
  1128. db = db.Where("ctime<=?", endtime)
  1129. }
  1130. db.Group("storehouse_id").Find(&info)
  1131. return info, err
  1132. }
  1133. func FindGoodWarehouseInfo(good_id int64, orgid int64, storhouse_id int64, startime int64, endtime int64) (info []*models.WarehousingInfo, err error) {
  1134. db := XTReadDB().Model(&info).Where("status = 1 and is_check = 1")
  1135. if good_id > 0 {
  1136. db = db.Where("good_id = ?", good_id)
  1137. }
  1138. if orgid > 0 {
  1139. db = db.Where("org_id = ?", orgid)
  1140. }
  1141. if storhouse_id > 0 {
  1142. db = db.Where("storehouse_id = ?", storhouse_id)
  1143. }
  1144. if startime > 0 {
  1145. db = db.Where("ctime >=?", startime)
  1146. }
  1147. if endtime > 0 {
  1148. db = db.Where("ctime<=?", endtime)
  1149. }
  1150. db.Find(&info)
  1151. return info, err
  1152. }
  1153. func FindGoodWarehouseOutInfo(good_id int64, orgid int64, storhouse_id int64, startime int64, endtime int64) (out []*models.WarehouseOutInfo, err error) {
  1154. db := XTReadDB().Model(&out).Where("status = 1 and is_check = 1")
  1155. if good_id > 0 {
  1156. db = db.Where("good_id = ?", good_id)
  1157. }
  1158. if orgid > 0 {
  1159. db = db.Where("org_id = ?", orgid)
  1160. }
  1161. if storhouse_id > 0 {
  1162. db = db.Where("storehouse_id = ?", storhouse_id)
  1163. }
  1164. if startime > 0 {
  1165. db = db.Where("ctime>=?", startime)
  1166. }
  1167. if endtime > 0 {
  1168. db = db.Where("ctime<=?", endtime)
  1169. }
  1170. err = db.Find(&out).Error
  1171. return out, err
  1172. }
  1173. func FindCancelStockInfo(good_id int64, orgid int64, storhouse_id int64, startime int64, endtime int64) (info []*models.CancelStockInfo, err error) {
  1174. db := XTReadDB().Model(&info).Where("status = 1 and is_check = 1")
  1175. if good_id > 0 {
  1176. db = db.Where("good_id = ?", good_id)
  1177. }
  1178. if orgid > 0 {
  1179. db = db.Where("org_id = ?", orgid)
  1180. }
  1181. if storhouse_id > 0 {
  1182. db = db.Where("storehouse_id = ?", storhouse_id)
  1183. }
  1184. if startime > 0 {
  1185. db = db.Where("ctime>=?", startime)
  1186. }
  1187. if endtime > 0 {
  1188. db = db.Where("ctime<=?", endtime)
  1189. }
  1190. err = db.Find(&info).Error
  1191. return info, err
  1192. }
  1193. func FindGoodStockOutFlow(good_id int64, user_org_id int64, storhouse_id int64, startime int64, endtime int64) (info []*models.VmStockFlow, err error) {
  1194. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 2 or consumable_type = 3)")
  1195. if good_id > 0 {
  1196. db = db.Where("good_id = ?", good_id)
  1197. }
  1198. if user_org_id > 0 {
  1199. db = db.Where("user_org_id = ?", user_org_id)
  1200. }
  1201. if storhouse_id > 0 {
  1202. db = db.Where("storehouse_id = ?", storhouse_id)
  1203. }
  1204. if startime > 0 {
  1205. db = db.Where("ctime >= ?", storhouse_id)
  1206. }
  1207. if endtime > 0 {
  1208. db = db.Where("ctime <= ?", storhouse_id)
  1209. }
  1210. err = db.Find(&info).Error
  1211. return info, err
  1212. }
  1213. func FindGoodCancelFlow(good_id int64, user_org_id int64, storhouse_id int64, startime int64, endtime int64) (info []*models.VmStockFlow, err error) {
  1214. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 4 or consumable_type = 7)")
  1215. if good_id > 0 {
  1216. db = db.Where("good_id = ?", good_id)
  1217. }
  1218. if user_org_id > 0 {
  1219. db = db.Where("user_org_id = ?", user_org_id)
  1220. }
  1221. if storhouse_id > 0 {
  1222. db = db.Where("storehouse_id = ?", storhouse_id)
  1223. }
  1224. if startime > 0 {
  1225. db = db.Where("ctime >= ?", storhouse_id)
  1226. }
  1227. if endtime > 0 {
  1228. db = db.Where("ctime <= ?", storhouse_id)
  1229. }
  1230. err = db.Find(&info).Error
  1231. return info, err
  1232. }
  1233. func GetGoodWarehouseOutInfoByIdList(good_id int64, limit int64, page int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (info []*models.WarehouseOutInfo, total int64, err error) {
  1234. db := XTReadDB().Model(&info).Where("status = 1")
  1235. offset := (page - 1) * limit
  1236. if good_id > 0 {
  1237. db = db.Where("good_id = ?", good_id)
  1238. }
  1239. if orgid > 0 {
  1240. db = db.Where("org_id =?", orgid)
  1241. }
  1242. if startime > 0 {
  1243. db = db.Where("ctime >=?", startime)
  1244. }
  1245. if endtime > 0 {
  1246. db = db.Where("ctime<=?", endtime)
  1247. }
  1248. if storehouse_id > 0 {
  1249. db = db.Where("storehouse_id = ?", storehouse_id)
  1250. }
  1251. err = db.Count(&total).Offset(offset).Limit(limit).Preload("VmStockFlow", "status = 1 and user_org_id = ?", orgid).Preload("GoodInfo", "status = 1 and org_id = ?", orgid).Order("id desc").Find(&info).Error
  1252. return info, total, err
  1253. }
  1254. func GetStockFlushByGoodId(good_id int64, org_id int64, startime int64, endtime int64) (flushinfo []*models.XtWarehouseFlushInfo, err error) {
  1255. db := XTReadDB().Model(&models.XtWarehouseFlushInfo{}).Where("status = 1 and type = 1")
  1256. if good_id > 0 {
  1257. db = db.Where("good_id = ?", good_id)
  1258. }
  1259. if org_id > 0 {
  1260. db = db.Where("user_org_id = ?", org_id)
  1261. }
  1262. if startime > 0 {
  1263. db = db.Where("ctime >=?", startime)
  1264. }
  1265. if endtime > 0 {
  1266. db = db.Where("ctime<=?", endtime)
  1267. }
  1268. err = db.Find(&flushinfo).Error
  1269. return flushinfo, err
  1270. }
  1271. func GetGoodWarehouseOutInfoByIdListTwenty(good_id int64, limit int64, page int64, orgid int64, startime int64, endtime int64) (info []*models.WarehouseOutInfo, err error) {
  1272. db := XTReadDB().Model(&info).Where("status = 1")
  1273. if good_id > 0 {
  1274. db = db.Where("good_id = ?", good_id)
  1275. }
  1276. if orgid > 0 {
  1277. db = db.Where("org_id =?", orgid)
  1278. }
  1279. if startime > 0 {
  1280. db = db.Where("ctime >=?", startime)
  1281. }
  1282. if endtime > 0 {
  1283. db = db.Where("ctime<=?", endtime)
  1284. }
  1285. err = db.Find(&info).Error
  1286. return info, err
  1287. }
  1288. func GetGoodWarehouseInfoByList(goodid int64, orgid int64, startime int64, endtime int64) (info []*models.WarehousingInfo, err error) {
  1289. db := XTReadDB().Model(&info).Where("status= 1 and is_check = 1")
  1290. if goodid > 0 {
  1291. db = db.Where("good_id = ?", goodid)
  1292. }
  1293. if orgid > 0 {
  1294. db = db.Where("org_id = ?", orgid)
  1295. }
  1296. err = db.Find(&info).Error
  1297. return info, err
  1298. }
  1299. func GetGoodCancelStockInfoByList(goodid int64, orgid int64, startime int64, endtime int64) (info []*models.CancelStockInfo, err error) {
  1300. db := XTReadDB().Model(&info).Where("status = 1 and is_check = 1")
  1301. if goodid > 0 {
  1302. db = db.Where("good_id = ?", goodid)
  1303. }
  1304. if orgid > 0 {
  1305. db = db.Where("org_id = ?", orgid)
  1306. }
  1307. err = db.Find(&info).Error
  1308. return info, err
  1309. }
  1310. func GetGoodPatientList(orgid int64, keyword string) (patient []*models.XtPatients, err error) {
  1311. likeKey := "%" + keyword + "%"
  1312. if len(keyword) > 0 {
  1313. err = XTReadDB().Where("user_org_id = ? and status = 1 and name like ?", orgid, likeKey).Find(&patient).Error
  1314. } else {
  1315. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patient).Error
  1316. }
  1317. return patient, err
  1318. }
  1319. func GetWarehouseOutDetailByPatientIdOne(orgid int64, patient_id int64, startime int64, endtime int64, limit int64, page int64) (info []*models.WarehouseOutInfo, total int64, err error) {
  1320. db := XTReadDB().Model(&info).Where("status = 1 and (is_sys = 1 or is_sys = 5)")
  1321. offset := (page - 1) * limit
  1322. if orgid > 0 {
  1323. db = db.Where("org_id = ?", orgid)
  1324. }
  1325. if patient_id > 0 {
  1326. db = db.Where("patient_id = ?", patient_id)
  1327. }
  1328. if startime > 0 {
  1329. db = db.Where("ctime>=?", startime)
  1330. }
  1331. if endtime > 0 {
  1332. db = db.Where("ctime<=?", endtime)
  1333. }
  1334. err = db.Group("good_id").Preload("GoodInfo", "org_id = ? and status = 1", orgid).Count(&total).Offset(offset).Limit(limit).Find(&info).Error
  1335. return info, total, err
  1336. }
  1337. func GetWarehouseOutDetailByPatientId(orgid int64, patient_id int64, startime int64, endtime int64) (info []*models.WarehouseOutInfo, err error) {
  1338. db := XTReadDB().Model(&info).Where("status = 1 and (is_sys = 1 or is_sys =5)")
  1339. if orgid > 0 {
  1340. db = db.Where("org_id = ?", orgid)
  1341. }
  1342. if patient_id > 0 {
  1343. db = db.Where("patient_id = ?", patient_id)
  1344. }
  1345. if startime > 0 {
  1346. db = db.Where("ctime>=?", startime)
  1347. }
  1348. if endtime > 0 {
  1349. db = db.Where("ctime<=?", endtime)
  1350. }
  1351. err = db.Preload("GoodInfo", "org_id = ? and status = 1", orgid).Find(&info).Error
  1352. return info, err
  1353. }
  1354. func GetGoodExpiryDateQuery(storehouse_id int64, expiry_type int64, keyword string, page int64, limit int64, orgid int64, ids []int64, goodIds []int64, startime int64, endtime int64) (info []*models.WarehousingInfo, total int64, err error) {
  1355. offset := (page - 1) * limit
  1356. db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1 and x.is_check = 1 and x.stock_count >0")
  1357. if storehouse_id > 0 {
  1358. db = db.Where("x.storehouse_id = ?", storehouse_id)
  1359. }
  1360. //已过期
  1361. if expiry_type == 1 {
  1362. db = db.Where("x.expiry_date < ?", startime)
  1363. }
  1364. if expiry_type > 1 {
  1365. db = db.Where("x.expiry_date > ? and x.expiry_date<=?", startime, endtime)
  1366. }
  1367. if orgid > 0 {
  1368. db = db.Where("x.org_id = ?", orgid)
  1369. }
  1370. if len(keyword) > 0 {
  1371. db = db.Where("x.manufacturer in(?) or x.good_id in(?)", ids, goodIds)
  1372. }
  1373. err = db.Count(&total).Offset(offset).Limit(limit).Preload("GoodInfo", "org_id = ? and status = 1", orgid).Find(&info).Error
  1374. return info, total, err
  1375. }
  1376. func GetGoodPurchaseStockQuery(good_type int64, keyword string, page int64, limit int64, orgid int64, ids []int64, goodIds []int64) (goodinfo []*models.GoodInfoTwenty, total int64, err error) {
  1377. db := XTReadDB().Model(&goodinfo).Where("status = 1 and total_count > 0")
  1378. offset := (page - 1) * limit
  1379. likeKey := "%" + keyword + "%"
  1380. if good_type > 0 {
  1381. db = db.Where("good_type_id = ?", good_type)
  1382. }
  1383. if orgid > 0 {
  1384. db = db.Where("org_id = ?", orgid)
  1385. }
  1386. if len(ids) > 0 {
  1387. db = db.Where("id in(?)", goodIds)
  1388. }
  1389. if len(keyword) > 0 {
  1390. db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
  1391. }
  1392. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&goodinfo).Error
  1393. return goodinfo, total, err
  1394. }
  1395. func GetDrugWarehouseOutDetailByPatientIdOne(patient_id int64, orgid int64, startime int64, endtime int64, page int64, limit int64) (info []*models.DrugWarehouseOutInfo, total int64, err error) {
  1396. db := XTReadDB().Model(&info).Where("status = 1")
  1397. offset := (page - 1) * limit
  1398. if patient_id > 0 {
  1399. db = db.Where("patient_id = ?", patient_id)
  1400. }
  1401. if orgid > 0 {
  1402. db = db.Where("org_id = ?", orgid)
  1403. }
  1404. if startime > 0 {
  1405. db = db.Where("sys_record_time >= ?", startime)
  1406. }
  1407. if endtime > 0 {
  1408. db = db.Where("sys_record_time <= ?", endtime)
  1409. }
  1410. err = db.Group("drug_id").Count(&total).Offset(offset).Limit(limit).Preload("BaseDrugLib", "status = 1 and org_id = ?", orgid).Find(&info).Error
  1411. return
  1412. }
  1413. func GetDrugWarehouseOutDetailByPatientId(patient_id int64, orgid int64, startime int64, endtime int64) (info []*models.DrugWarehouseOutInfo, err error) {
  1414. db := XTReadDB().Model(&info).Where("status = 1")
  1415. if patient_id > 0 {
  1416. db = db.Where("patient_id = ?", patient_id)
  1417. }
  1418. if orgid > 0 {
  1419. db = db.Where("org_id = ?", orgid)
  1420. }
  1421. if startime > 0 {
  1422. db = db.Where("sys_record_time >= ?", startime)
  1423. }
  1424. if endtime > 0 {
  1425. db = db.Where("sys_record_time <= ?", endtime)
  1426. }
  1427. err = db.Preload("BaseDrugLib", "status = 1 and org_id = ?", orgid).Find(&info).Error
  1428. return
  1429. }
  1430. func GetDrugExpiryDateQuery(storehouse_id int64, expiry_type int64, keyword string, page int64, limit int64, orgid int64, ids []int64, goodIds []int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseInfo, total int64, err error) {
  1431. offset := (page - 1) * limit
  1432. db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1 and (x.stock_max_number>0 or x.stock_min_number >0)")
  1433. if storehouse_id > 0 {
  1434. db = db.Where("x.storehouse_id = ?", storehouse_id)
  1435. }
  1436. //已过期
  1437. if expiry_type == 1 {
  1438. db = db.Where("x.expiry_date < ?", startime)
  1439. }
  1440. if expiry_type > 1 {
  1441. db = db.Where("x.expiry_date > ? and x.expiry_date<=?", startime, endtime)
  1442. }
  1443. if orgid > 0 {
  1444. db = db.Where("x.org_id = ?", orgid)
  1445. }
  1446. if len(keyword) > 0 {
  1447. db = db.Where("x.manufacturer in(?) or x.drug_id in(?)", ids, goodIds)
  1448. }
  1449. err = db.Count(&total).Offset(offset).Limit(limit).Preload("XtBaseDrug", "org_id = ? and status = 1", orgid).Find(&info).Error
  1450. return info, total, err
  1451. }
  1452. func GetDrugPurchaseStockQuery(good_type int64, keyword string, page int64, limit int64, orgid int64, startime int64, endtime int64, ids []int64, infos []int64) (druginfo []*models.VmBaseDrugTwenty, total int64, err error) {
  1453. db := XTReadDB().Model(&druginfo).Where("status = 1")
  1454. offset := (page - 1) * limit
  1455. likeKey := "%" + keyword + "%"
  1456. if good_type > 0 {
  1457. db = db.Where("drug_type = ?", good_type)
  1458. }
  1459. if orgid > 0 {
  1460. db = db.Where("org_id = ?", orgid)
  1461. }
  1462. if len(keyword) > 0 {
  1463. db = db.Where("drug_name like ? or manufacturer in(?)", likeKey, ids)
  1464. }
  1465. if len(infos) > 0 {
  1466. db = db.Where("id in(?)", infos)
  1467. }
  1468. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&druginfo).Error
  1469. return druginfo, total, err
  1470. }
  1471. func GetDrugWarehouseInfoByOrgId(orgid int64, storehouse_id int64) (info []*models.XtDrugWarehouseInfo, err error) {
  1472. db := XTReadDB().Model(&info).Where("is_check = 1 and status = 1")
  1473. if orgid > 0 {
  1474. db = db.Where("org_id = ?", orgid)
  1475. }
  1476. if storehouse_id > 0 {
  1477. db = db.Where("storehouse_id = ?", storehouse_id)
  1478. }
  1479. err = db.Group("drug_id").Find(&info).Error
  1480. return info, err
  1481. }
  1482. func GetDrugWarehouseInfoByOrgIdTwo(orgid int64) (info []*models.XtDrugWarehouseInfo, err error) {
  1483. db := XTReadDB().Model(&info).Where("is_check = 1 and status = 1")
  1484. if orgid > 0 {
  1485. db = db.Where("org_id = ?", orgid)
  1486. }
  1487. err = db.Group("drug_id").Find(&info).Error
  1488. return info, err
  1489. }
  1490. func GetDrugNewQuery(orgId int64, storehouse_id int64, good_type int64, keyword string, page int64, limit int64, ids []int64, goodIds []int64, startime int64, endtime int64) (drug []*models.VmBaseDrug, total int64, err error) {
  1491. offset := (page - 1) * limit
  1492. likeKey := "%" + keyword + "%"
  1493. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1494. if good_type == 2 {
  1495. db = db.Where("x.total_count<=x.drug_stock_limit")
  1496. }
  1497. if storehouse_id > 0 {
  1498. db = db.Preload("DrugWarehouseInfo", "org_id = ? and status = 1 and storehouse_id = ? and is_check = 1", orgId, storehouse_id)
  1499. } else {
  1500. db = db.Preload("DrugWarehouseInfo", "org_id = ? and status = 1 and is_check = 1", orgId)
  1501. }
  1502. if len(goodIds) > 0 {
  1503. db = db.Where("id in(?)", goodIds)
  1504. }
  1505. if len(keyword) > 0 {
  1506. db = db.Where("drug_name like ? or manufacturer in(?)", likeKey, ids)
  1507. }
  1508. if orgId > 0 {
  1509. db = db.Where("x.org_id = ?", orgId)
  1510. }
  1511. err = db.Count(&total).Offset(offset).Limit(limit).Preload("DrugWarehouse", func(db *gorm.DB) *gorm.DB {
  1512. if startime > 0 {
  1513. db = db.Where("ctime>=?", startime)
  1514. }
  1515. if endtime > 0 {
  1516. db = db.Where("ctime<=?", endtime)
  1517. }
  1518. if storehouse_id > 0 {
  1519. db = db.Where("storehouse_id = ?", storehouse_id)
  1520. }
  1521. return db.Where("status = 1").Group("drug_id,storehouse_id")
  1522. }).Preload("DrugCancelStockInfo", func(db *gorm.DB) *gorm.DB {
  1523. if startime > 0 {
  1524. db = db.Where("ctime>=?", startime)
  1525. }
  1526. if endtime > 0 {
  1527. db = db.Where("ctime<=?", endtime)
  1528. }
  1529. return db.Where("status = 1")
  1530. }).Preload("DrugWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  1531. if startime > 0 {
  1532. db = db.Where("ctime>=?", startime)
  1533. }
  1534. if endtime > 0 {
  1535. db = db.Where("ctime<=?", endtime)
  1536. }
  1537. return db.Where("status = 1")
  1538. }).Preload("DrugFlowWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  1539. if startime > 0 {
  1540. db = db.Where("ctime>=?", startime)
  1541. }
  1542. if endtime > 0 {
  1543. db = db.Where("ctime<=?", endtime)
  1544. }
  1545. if storehouse_id > 0 {
  1546. db = db.Where("storehouse_id = ?", storehouse_id)
  1547. }
  1548. return db.Where("status = 1 and (consumable_type = 2 or consumable_type = 3) and user_org_id = ?", orgId)
  1549. }).Preload("DrugActFlowWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  1550. if startime > 0 {
  1551. db = db.Where("ctime>=?", startime)
  1552. }
  1553. if endtime > 0 {
  1554. db = db.Where("ctime<=?", endtime)
  1555. }
  1556. if storehouse_id > 0 {
  1557. db = db.Where("storehouse_id = ?", storehouse_id)
  1558. }
  1559. return db.Where("status = 1 and (consumable_type = 2 or consumable_type = 3) and user_org_id = ?", orgId)
  1560. }).Order("x.ctime desc").Find(&drug).Error
  1561. return drug, total, err
  1562. }
  1563. func GetDrugStockCountList(orgId int64, storehouse_id int64, good_type int64, keyword string, page int64, limit int64, ids []int64, goodIds []int64, startime int64, endtime int64) (drug []*models.NewBaseDrugOne, total int64, err error) {
  1564. offset := (page - 1) * limit
  1565. likeKey := "%" + keyword + "%"
  1566. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1 AND find_in_set('停用',x.drug_status) = 0 and x.is_self_drug!=1")
  1567. if good_type == 2 {
  1568. db = db.Where("x.sum_count<=x.drug_stock_limit")
  1569. }
  1570. if good_type == 3 {
  1571. db = db.Where("x.sum_count = 0")
  1572. }
  1573. if good_type == 4 {
  1574. db = db.Where("x.sum_count > 0")
  1575. }
  1576. if storehouse_id > 0 {
  1577. db = db.Preload("DrugWarehouseInfo", "org_id = ? and status = 1 and storehouse_id = ? and is_check = 1", orgId, storehouse_id)
  1578. } else {
  1579. db = db.Preload("DrugWarehouseInfo", "org_id = ? and status = 1 and is_check = 1", orgId)
  1580. }
  1581. if len(keyword) > 0 {
  1582. db = db.Where("x.drug_name like ? or x.manufacturer in(?)", likeKey, ids)
  1583. }
  1584. if orgId > 0 {
  1585. db = db.Where("x.org_id = ?", orgId)
  1586. }
  1587. if orgId == 10489 {
  1588. err = db.Preload("XtDrugStockCount", func(db *gorm.DB) *gorm.DB {
  1589. if storehouse_id > 0 {
  1590. db = db.Where("storehouse_id = ?", storehouse_id)
  1591. }
  1592. return db.Where("status = 1 and user_org_id = ?", orgId)
  1593. }).Preload("DrugStockCount", func(db *gorm.DB) *gorm.DB {
  1594. if storehouse_id > 0 {
  1595. db = db.Where("storehouse_id = ?", storehouse_id)
  1596. }
  1597. return db.Where("status = 1 and user_org_id = ?", orgId).Group("drug_id,storehouse_id")
  1598. }).Count(&total).Offset(offset).Limit(limit).Order("x.sum_count desc").Find(&drug).Error
  1599. } else {
  1600. err = db.Preload("XtDrugStockCount", func(db *gorm.DB) *gorm.DB {
  1601. if storehouse_id > 0 {
  1602. db = db.Where("storehouse_id = ?", storehouse_id)
  1603. }
  1604. return db.Where("status = 1 and user_org_id = ?", orgId)
  1605. }).Preload("DrugStockCount", func(db *gorm.DB) *gorm.DB {
  1606. if storehouse_id > 0 {
  1607. db = db.Where("storehouse_id = ?", storehouse_id)
  1608. }
  1609. return db.Where("status = 1 and user_org_id = ?", orgId).Group("drug_id,storehouse_id")
  1610. }).Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Find(&drug).Error
  1611. }
  1612. return drug, total, err
  1613. }
  1614. func GetDrugWarehouseOutInfoByIdList(good_id int64, limit int64, page int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (info []*models.DrugWarehouseOutInfo, total int64, err error) {
  1615. db := XTReadDB().Model(&info).Where("status = 1")
  1616. offset := (page - 1) * limit
  1617. if good_id > 0 {
  1618. db = db.Where("drug_id = ?", good_id)
  1619. }
  1620. if orgid > 0 {
  1621. db = db.Where("org_id =?", orgid)
  1622. }
  1623. if startime > 0 {
  1624. db = db.Where("ctime >=?", startime)
  1625. }
  1626. if endtime > 0 {
  1627. db = db.Where("ctime<=?", endtime)
  1628. }
  1629. if storehouse_id > 0 {
  1630. db = db.Where("storehouse_id = ?", storehouse_id)
  1631. }
  1632. err = db.Count(&total).Offset(offset).Limit(limit).Preload("BaseDrugLib", "status=1 and org_id = ?", orgid).Order("id desc").Find(&info).Error
  1633. return info, total, err
  1634. }
  1635. func GetAllGoodListSeven(orgid int64) (good []*models.GoodInfoSeven, err error) {
  1636. err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&good).Error
  1637. return good, err
  1638. }
  1639. func GetAllGoodListEight(orgid int64) (good []*models.GoodInfoSeven, err error) {
  1640. err = XTReadDB().Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Find(&good).Error
  1641. return good, err
  1642. }
  1643. func GetGoodInformationWarehouseInfo(good_id int64, orgid int64) (info []*models.WarehousingInfoTen, err error) {
  1644. err = XTReadDB().Where("good_id = ? and org_id = ? and status = 1 and is_check = 1 and stock_count > 0", good_id, orgid).Find(&info).Error
  1645. return info, err
  1646. }
  1647. func UpdateGoodInformation(id int64, orgid int64, total_count int64) error {
  1648. err := XTWriteDB().Model(&models.GoodInfoTen{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"total_count": total_count}).Error
  1649. return err
  1650. }
  1651. func UpdateGoodListCount(user_org_id int64, over_count int64, good_id int64, sotrehouse_id int64) error {
  1652. err := XTWriteDB().Model(&models.XtGoodStockCount{}).Where("status=1 and user_org_id =? and good_id =? and storehouse_id=?", user_org_id, good_id, sotrehouse_id).Update(map[string]interface{}{"stock_out_count": over_count}).Error
  1653. return err
  1654. }
  1655. func UpdateGoodListCountOne(user_org_id int64, over_count int64, good_id int64, storehouse_id int64) error {
  1656. err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("status=1 and user_org_id =? and good_id = ? and storehouse_id = ?", user_org_id, good_id, storehouse_id).Update(map[string]interface{}{"stock_act_out_count": over_count}).Error
  1657. return err
  1658. }
  1659. func GetBaseDrugName(orgid int64) (drug []*models.BaseDrugLibTwenty, err error) {
  1660. err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&drug).Error
  1661. return drug, err
  1662. }
  1663. func GetDrugWarehouseInfoName(drugid int64, orgid int64) (info []*models.DrugWarehouseInfoTen, err error) {
  1664. err = XTReadDB().Where("drug_id = ? and org_id = ? and is_check = 1 and (stock_max_number >0 or stock_min_number > 0) and status = 1", drugid, orgid).Find(&info).Error
  1665. return info, err
  1666. }
  1667. func UpdateDrugById(id int64, orgid int64, limit_count int64, total_count int64) error {
  1668. err := XTWriteDB().Model(&models.BaseDrugLibTen{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_stock_limit_count": limit_count, "sum_count": total_count}).Error
  1669. return err
  1670. }
  1671. func GetDrugFlowFlush(drugid int64, org_id int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseFlushInfo, err error) {
  1672. db := XTReadDB().Model(&info).Where("status = 1 and type = 1")
  1673. if drugid > 0 {
  1674. db = db.Where("drug_id = ?", drugid)
  1675. }
  1676. if org_id > 0 {
  1677. db = db.Where("user_org_id = ?", org_id)
  1678. }
  1679. if startime > 0 {
  1680. db = db.Where("ctime >=?", startime)
  1681. }
  1682. if endtime > 0 {
  1683. db = db.Where("ctime <=?", endtime)
  1684. }
  1685. err = db.Find(&info).Error
  1686. return info, err
  1687. }
  1688. func GetDrugFlowFlushOne(drugid int64, org_id int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseFlushInfo, err error) {
  1689. db := XTReadDB().Model(&info).Where("status = 0 and type = 1")
  1690. if drugid > 0 {
  1691. db = db.Where("drug_id = ?", drugid)
  1692. }
  1693. if org_id > 0 {
  1694. db = db.Where("user_org_id = ?", org_id)
  1695. }
  1696. if startime > 0 {
  1697. db = db.Where("ctime >=?", startime)
  1698. }
  1699. if endtime > 0 {
  1700. db = db.Where("ctime <=?", endtime)
  1701. }
  1702. err = db.Find(&info).Error
  1703. return info, err
  1704. }
  1705. func GetStartGoodWarehouseInfoList(good_id int64, orgid int64, startime int64) (info []*models.StartWarehousingInfo, err error) {
  1706. db := XTReadDB().Model(&info).Where("status = 1 and is_check =1")
  1707. if good_id > 0 {
  1708. db = db.Where("good_id = ?", good_id)
  1709. }
  1710. if orgid > 0 {
  1711. db = db.Where("org_id = ?", orgid)
  1712. }
  1713. if startime > 0 {
  1714. db = db.Where("ctime <?", startime)
  1715. }
  1716. err = db.Find(&info).Error
  1717. return info, err
  1718. }
  1719. func GetEndGoodWarehouseInfoList(good_id int64, orgid int64, endtime int64) (info []*models.StartWarehousingInfo, err error) {
  1720. db := XTReadDB().Model(&info).Where("status = 1 and is_check =1")
  1721. if good_id > 0 {
  1722. db = db.Where("good_id = ?", good_id)
  1723. }
  1724. if orgid > 0 {
  1725. db = db.Where("org_id = ?", orgid)
  1726. }
  1727. if endtime > 0 {
  1728. db = db.Where("ctime <=?", endtime)
  1729. }
  1730. err = db.Find(&info).Error
  1731. return info, err
  1732. }
  1733. func GetAddGoodWarehouseInfoList(good_id int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (info []*models.StartWarehousingInfo, err error) {
  1734. db := XTReadDB().Model(&info).Where("status = 1 and is_check =1")
  1735. if good_id > 0 {
  1736. db = db.Where("good_id = ?", good_id)
  1737. }
  1738. if orgid > 0 {
  1739. db = db.Where("org_id = ?", orgid)
  1740. }
  1741. if startime > 0 {
  1742. db = db.Where("ctime >=?", startime)
  1743. }
  1744. if endtime > 0 {
  1745. db = db.Where("ctime <=?", endtime)
  1746. }
  1747. if storehouse_id > 0 {
  1748. db = db.Where("storehouse_id = ?", storehouse_id)
  1749. }
  1750. err = db.Find(&info).Error
  1751. return info, err
  1752. }
  1753. func GetAddGoodWarehouseInfoListTwenty(good_id int64, orgid int64, startime int64, endtime int64) (info []*models.StartWarehousingInfo, err error) {
  1754. db := XTReadDB().Model(&info).Where("status = 1 and is_check =1")
  1755. if good_id > 0 {
  1756. db = db.Where("good_id = ?", good_id)
  1757. }
  1758. if orgid > 0 {
  1759. db = db.Where("org_id = ?", orgid)
  1760. }
  1761. if startime > 0 {
  1762. db = db.Where("ctime >=?", startime)
  1763. }
  1764. if endtime > 0 {
  1765. db = db.Where("ctime <=?", endtime)
  1766. }
  1767. err = db.Find(&info).Error
  1768. return info, err
  1769. }
  1770. func GetAddStartFlow(good_id int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (info []*models.VmStockFlowTwenty, err error) {
  1771. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type =1 or consumable_type = 13)")
  1772. if good_id > 0 {
  1773. db = db.Where("good_id = ?", good_id)
  1774. }
  1775. if orgid > 0 {
  1776. db = db.Where("user_org_id = ?", orgid)
  1777. }
  1778. if startime > 0 {
  1779. db = db.Where("ctime >=?", startime)
  1780. }
  1781. if endtime > 0 {
  1782. db = db.Where("ctime <=?", endtime)
  1783. }
  1784. if storehouse_id > 0 {
  1785. db = db.Where("storehouse_id =?", storehouse_id)
  1786. }
  1787. err = db.Find(&info).Error
  1788. return info, err
  1789. }
  1790. func GetAddStartFlowTwenty(good_id int64, orgid int64, startime int64, endtime int64) (info []*models.VmStockFlowTwenty, err error) {
  1791. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type =1)")
  1792. if good_id > 0 {
  1793. db = db.Where("good_id = ?", good_id)
  1794. }
  1795. if orgid > 0 {
  1796. db = db.Where("user_org_id = ?", orgid)
  1797. }
  1798. if startime > 0 {
  1799. db = db.Where("ctime >=?", startime)
  1800. }
  1801. if endtime > 0 {
  1802. db = db.Where("ctime <=?", endtime)
  1803. }
  1804. err = db.Find(&info).Error
  1805. return info, err
  1806. }
  1807. func GetReduceWarehouseInfoList(good_id int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  1808. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type= 15)")
  1809. if good_id > 0 {
  1810. db = db.Where("good_id = ?", good_id)
  1811. }
  1812. if orgid > 0 {
  1813. db = db.Where("user_org_id = ?", orgid)
  1814. }
  1815. if startime > 0 {
  1816. db = db.Where("ctime >=?", startime)
  1817. }
  1818. if endtime > 0 {
  1819. db = db.Where("ctime <=?", endtime)
  1820. }
  1821. if storehouse_id > 0 {
  1822. db = db.Where("storehouse_id = ?", storehouse_id)
  1823. }
  1824. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  1825. return outinfo, err
  1826. }
  1827. func GetReduceWarehouseInfoListTwenty(good_id int64, orgid int64, startime int64, endtime int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  1828. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type= 15)")
  1829. if good_id > 0 {
  1830. db = db.Where("good_id = ?", good_id)
  1831. }
  1832. if orgid > 0 {
  1833. db = db.Where("user_org_id = ?", orgid)
  1834. }
  1835. if startime > 0 {
  1836. db = db.Where("ctime >=?", startime)
  1837. }
  1838. if endtime > 0 {
  1839. db = db.Where("ctime <=?", endtime)
  1840. }
  1841. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  1842. return outinfo, err
  1843. }
  1844. func GetStartEndCancelFLowInfo(good_id int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  1845. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 7)")
  1846. if good_id > 0 {
  1847. db = db.Where("good_id = ?", good_id)
  1848. }
  1849. if orgid > 0 {
  1850. db = db.Where("user_org_id = ?", orgid)
  1851. }
  1852. if startime > 0 {
  1853. db = db.Where("ctime >=?", startime)
  1854. }
  1855. if endtime > 0 {
  1856. db = db.Where("ctime <=?", endtime)
  1857. }
  1858. if storehouse_id > 0 {
  1859. db = db.Where("storehouse_id =?", storehouse_id)
  1860. }
  1861. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  1862. return outinfo, err
  1863. }
  1864. func GetStartEndCancelFLowInfoTwenty(good_id int64, orgid int64, startime int64, endtime int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  1865. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 7)")
  1866. if good_id > 0 {
  1867. db = db.Where("good_id = ?", good_id)
  1868. }
  1869. if orgid > 0 {
  1870. db = db.Where("user_org_id = ?", orgid)
  1871. }
  1872. if startime > 0 {
  1873. db = db.Where("ctime >=?", startime)
  1874. }
  1875. if endtime > 0 {
  1876. db = db.Where("ctime <=?", endtime)
  1877. }
  1878. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  1879. return outinfo, err
  1880. }
  1881. func FindeStartFlowInfo(good_id int64, orgid int64, startime int64) (info []*models.VmStockFlowTwenty, err error) {
  1882. db := XTReadDB().Model(&info).Where("status = 1 and consumable_type = 1")
  1883. if good_id > 0 {
  1884. db = db.Where("good_id = ?", good_id)
  1885. }
  1886. if orgid > 0 {
  1887. db = db.Where("user_org_id = ?", orgid)
  1888. }
  1889. if startime > 0 {
  1890. db = db.Where("ctime <?", startime)
  1891. }
  1892. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&info).Error
  1893. return info, err
  1894. }
  1895. func FindeStartFlowOutInfo(good_id int64, orgid int64, startime int64) (info []*models.VmStockFlowTwenty, err error) {
  1896. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 2 or consumable_type = 3)")
  1897. if good_id > 0 {
  1898. db = db.Where("good_id = ?", good_id)
  1899. }
  1900. if orgid > 0 {
  1901. db = db.Where("user_org_id = ?", orgid)
  1902. }
  1903. if startime > 0 {
  1904. db = db.Where("ctime <?", startime)
  1905. }
  1906. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&info).Error
  1907. return info, err
  1908. }
  1909. func FindeStartCancelInfo(good_id int64, orgid int64, startime int64) (info []*models.VmStockFlowTwenty, err error) {
  1910. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 4 or consumable_type = 7)")
  1911. if good_id > 0 {
  1912. db = db.Where("good_id = ?", good_id)
  1913. }
  1914. if orgid > 0 {
  1915. db = db.Where("user_org_id = ?", orgid)
  1916. }
  1917. if startime > 0 {
  1918. db = db.Where("ctime <?", startime)
  1919. }
  1920. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&info).Error
  1921. return info, err
  1922. }
  1923. func FindEndStartFlowInfo(good_id int64, orgid int64, endtime int64) (info []*models.VmStockFlowTwenty, err error) {
  1924. db := XTReadDB().Model(&info).Where("status = 1 and consumable_type = 1")
  1925. if good_id > 0 {
  1926. db = db.Where("good_id = ?", good_id)
  1927. }
  1928. if orgid > 0 {
  1929. db = db.Where("user_org_id = ?", orgid)
  1930. }
  1931. if endtime > 0 {
  1932. db = db.Where("ctime <=?", endtime)
  1933. }
  1934. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&info).Error
  1935. return info, err
  1936. }
  1937. func FindeEndFLowOutInfo(good_id int64, orgid int64, endtime int64) (info []*models.VmStockFlowTwenty, err error) {
  1938. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 2 or consumable_type = 3)")
  1939. if good_id > 0 {
  1940. db = db.Where("good_id = ?", good_id)
  1941. }
  1942. if orgid > 0 {
  1943. db = db.Where("user_org_id = ?", orgid)
  1944. }
  1945. if endtime > 0 {
  1946. db = db.Where("ctime <?", endtime)
  1947. }
  1948. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&info).Error
  1949. return info, err
  1950. }
  1951. func FindEndCancelInfo(good_id int64, orgid int64, endtime int64) (info []*models.VmStockFlowTwenty, err error) {
  1952. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 4 or consumable_type = 7)")
  1953. if good_id > 0 {
  1954. db = db.Where("good_id = ?", good_id)
  1955. }
  1956. if orgid > 0 {
  1957. db = db.Where("user_org_id = ?", orgid)
  1958. }
  1959. if endtime > 0 {
  1960. db = db.Where("ctime <?", endtime)
  1961. }
  1962. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&info).Error
  1963. return info, err
  1964. }
  1965. func FindeWarehouseOutInfo(good_id int64, orgid int64, startime int64, storehouse_id int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  1966. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type = 15)")
  1967. if good_id > 0 {
  1968. db = db.Where("good_id = ?", good_id)
  1969. }
  1970. if orgid > 0 {
  1971. db = db.Where("user_org_id = ?", orgid)
  1972. }
  1973. if startime > 0 {
  1974. db = db.Where("ctime <?", startime)
  1975. }
  1976. if storehouse_id > 0 {
  1977. db = db.Where("storehouse_id= ?", storehouse_id)
  1978. }
  1979. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  1980. return outinfo, err
  1981. }
  1982. func FindeWarehouseOutInfoTwenty(good_id int64, orgid int64, startime int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  1983. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type = 15)")
  1984. if good_id > 0 {
  1985. db = db.Where("good_id = ?", good_id)
  1986. }
  1987. if orgid > 0 {
  1988. db = db.Where("user_org_id = ?", orgid)
  1989. }
  1990. if startime > 0 {
  1991. db = db.Where("ctime <?", startime)
  1992. }
  1993. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  1994. return outinfo, err
  1995. }
  1996. func FindeStartStockInventoryProfit(good_id int64, orgid int64, startime int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  1997. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 10)")
  1998. if good_id > 0 {
  1999. db = db.Where("good_id = ?", good_id)
  2000. }
  2001. if orgid > 0 {
  2002. db = db.Where("user_org_id = ?", orgid)
  2003. }
  2004. if startime > 0 {
  2005. db = db.Where("ctime <?", startime)
  2006. }
  2007. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  2008. return outinfo, err
  2009. }
  2010. func FindeEndStokInventoryProfit(good_id int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  2011. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 10)")
  2012. if good_id > 0 {
  2013. db = db.Where("good_id = ?", good_id)
  2014. }
  2015. if orgid > 0 {
  2016. db = db.Where("user_org_id = ?", orgid)
  2017. }
  2018. if startime > 0 {
  2019. db = db.Where("ctime >=?", startime)
  2020. }
  2021. if endtime > 0 {
  2022. db = db.Where("ctime <=?", endtime)
  2023. }
  2024. if storehouse_id > 0 {
  2025. db = db.Where("storehouse_id = ?", storehouse_id)
  2026. }
  2027. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  2028. return outinfo, err
  2029. }
  2030. func FindeEndStokInventoryProfitTwenty(good_id int64, orgid int64, startime int64, endtime int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  2031. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 10)")
  2032. if good_id > 0 {
  2033. db = db.Where("good_id = ?", good_id)
  2034. }
  2035. if orgid > 0 {
  2036. db = db.Where("user_org_id = ?", orgid)
  2037. }
  2038. if startime > 0 {
  2039. db = db.Where("ctime >=?", startime)
  2040. }
  2041. if endtime > 0 {
  2042. db = db.Where("ctime <=?", endtime)
  2043. }
  2044. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  2045. return outinfo, err
  2046. }
  2047. func FindeEndStockInventoryLosses(good_id int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  2048. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 11)")
  2049. if good_id > 0 {
  2050. db = db.Where("good_id = ?", good_id)
  2051. }
  2052. if orgid > 0 {
  2053. db = db.Where("user_org_id = ?", orgid)
  2054. }
  2055. if startime > 0 {
  2056. db = db.Where("ctime >=?", startime)
  2057. }
  2058. if endtime > 0 {
  2059. db = db.Where("ctime <=?", endtime)
  2060. }
  2061. if storehouse_id > 0 {
  2062. db = db.Where("storehouse_id = ?", storehouse_id)
  2063. }
  2064. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  2065. return outinfo, err
  2066. }
  2067. func FindeEndStockInventoryLossesTwenty(good_id int64, orgid int64, startime int64, endtime int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  2068. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 11)")
  2069. if good_id > 0 {
  2070. db = db.Where("good_id = ?", good_id)
  2071. }
  2072. if orgid > 0 {
  2073. db = db.Where("user_org_id = ?", orgid)
  2074. }
  2075. if startime > 0 {
  2076. db = db.Where("ctime >=?", startime)
  2077. }
  2078. if endtime > 0 {
  2079. db = db.Where("ctime <=?", endtime)
  2080. }
  2081. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  2082. return outinfo, err
  2083. }
  2084. func FindStartStockInventoryLosses(good_id int64, orgid int64, startime int64) (outinfo []*models.VmStockFlowTwenty, err error) {
  2085. db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 11)")
  2086. if good_id > 0 {
  2087. db = db.Where("good_id = ?", good_id)
  2088. }
  2089. if orgid > 0 {
  2090. db = db.Where("user_org_id = ?", orgid)
  2091. }
  2092. if startime > 0 {
  2093. db = db.Where("ctime <?", startime)
  2094. }
  2095. err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&outinfo).Error
  2096. return outinfo, err
  2097. }
  2098. func GetDrugWarehouseInfoStart(drug_id int64, orgid int64, startTime int64) (info []*models.DrugFlowTwenty, err error) {
  2099. db := XTReadDB().Model(&info).Where("status = 1 and consumable_type=1 ")
  2100. if drug_id > 0 {
  2101. db = db.Where("drug_id = ?", drug_id)
  2102. }
  2103. if orgid > 0 {
  2104. db = db.Where("user_org_id = ?", orgid)
  2105. }
  2106. if startTime > 0 {
  2107. db = db.Where("ctime<?", startTime)
  2108. }
  2109. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", orgid).Find(&info).Error
  2110. return info, err
  2111. }
  2112. func DrugWarehouseInfoEnd(drug_id int64, orgid int64, endTime int64) (info []*models.DrugFlowTwenty, err error) {
  2113. db := XTReadDB().Model(&info).Where("status = 1 and consumable_type = 1")
  2114. if drug_id > 0 {
  2115. db = db.Where("drug_id = ?", drug_id)
  2116. }
  2117. if orgid > 0 {
  2118. db = db.Where("user_org_id = ?", orgid)
  2119. }
  2120. if endTime > 0 {
  2121. db = db.Where("ctime<=?", endTime)
  2122. }
  2123. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", orgid).Find(&info).Error
  2124. return info, err
  2125. }
  2126. func DrugWarehouseOutInfoEnd(drug_id int64, orgid int64, endTime int64) (info []*models.DrugFlowTwenty, err error) {
  2127. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 2 or consumable_type= 3 or consumable_type= 15)")
  2128. if drug_id > 0 {
  2129. db = db.Where("drug_id = ?", drug_id)
  2130. }
  2131. if orgid > 0 {
  2132. db = db.Where("user_org_id = ?", orgid)
  2133. }
  2134. if endTime > 0 {
  2135. db = db.Where("ctime<=?", endTime)
  2136. }
  2137. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", orgid).Find(&info).Error
  2138. return info, err
  2139. }
  2140. func GetEndDrugFlowCancelInfo(drug_id int64, orgid int64, endTime int64) (info []*models.DrugFlowTwenty, err error) {
  2141. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 4 or consumable_type= 7)")
  2142. if drug_id > 0 {
  2143. db = db.Where("drug_id = ?", drug_id)
  2144. }
  2145. if orgid > 0 {
  2146. db = db.Where("user_org_id = ?", orgid)
  2147. }
  2148. if endTime > 0 {
  2149. db = db.Where("ctime<=?", endTime)
  2150. }
  2151. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", orgid).Find(&info).Error
  2152. return info, err
  2153. }
  2154. func GetDrugWarehouseStartEnd(drug_id int64, orgid int64, startTime int64, endTime int64) (info []*models.DrugFlowTwenty, err error) {
  2155. db := XTReadDB().Model(&info).Where("status = 1 and consumable_type = 1")
  2156. if drug_id > 0 {
  2157. db = db.Where("drug_id = ?", drug_id)
  2158. }
  2159. if orgid > 0 {
  2160. db = db.Where("user_org_id = ?", orgid)
  2161. }
  2162. if startTime > 0 {
  2163. db = db.Where("ctime>=?", startTime)
  2164. }
  2165. if endTime > 0 {
  2166. db = db.Where("ctime<=?", endTime)
  2167. }
  2168. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", orgid).Find(&info).Error
  2169. return info, err
  2170. }
  2171. func FindeDrugWarehouseOutInfo(drug_id int64, orgid int64, startTime int64, endTime int64) (info []*models.DrugFlowTwenty, err error) {
  2172. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 2 or consumable_type= 3 or consumable_type= 15 )")
  2173. if drug_id > 0 {
  2174. db = db.Where("drug_id = ?", drug_id)
  2175. }
  2176. if orgid > 0 {
  2177. db = db.Where("user_org_id = ?", orgid)
  2178. }
  2179. if startTime > 0 {
  2180. db = db.Where("ctime>=?", startTime)
  2181. }
  2182. if endTime > 0 {
  2183. db = db.Where("ctime<=?", endTime)
  2184. }
  2185. err = db.Preload("DrugWarehouseInfoOne", "status= 1 and org_id = ?", orgid).Find(&info).Error
  2186. return info, err
  2187. }
  2188. func FindStartEndDrugWarehouseOutInfo(drug_id int64, orgid int64, startTime int64, endTime int64) (info []*models.DrugFlowTwenty, err error) {
  2189. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type= 7)")
  2190. if drug_id > 0 {
  2191. db = db.Where("drug_id = ?", drug_id)
  2192. }
  2193. if orgid > 0 {
  2194. db = db.Where("user_org_id = ?", orgid)
  2195. }
  2196. if startTime > 0 {
  2197. db = db.Where("ctime>=?", startTime)
  2198. }
  2199. if endTime > 0 {
  2200. db = db.Where("ctime<=?", endTime)
  2201. }
  2202. err = db.Preload("DrugWarehouseInfoOne", "status= 1 and org_id = ?", orgid).Find(&info).Error
  2203. return info, err
  2204. }
  2205. func FindeDrugWarehouseOutStart(drug_id int64, orgid int64, startTime int64) (info []*models.DrugFlow, err error) {
  2206. db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 2 or consumable_type= 3)")
  2207. if drug_id > 0 {
  2208. db = db.Where("drug_id = ?", drug_id)
  2209. }
  2210. if orgid > 0 {
  2211. db = db.Where("user_org_id = ?", orgid)
  2212. }
  2213. if startTime > 0 {
  2214. db = db.Where("ctime <?", startTime)
  2215. }
  2216. err = db.Preload("DrugWarehouseInfoOne", "status= 1 and org_id = ?", orgid).Find(&info).Error
  2217. return info, err
  2218. }
  2219. func GetHisPrescriptionProjectByOrgId(orgid int64) (project []*models.HisPrescriptionProject, err error) {
  2220. err = XTReadDB().Where("user_org_id = ? and status = 0 and type = 3", orgid).Find(&project).Error
  2221. return project, err
  2222. }
  2223. func GetPatientStockFlow(patient_id int64, record_date int64, good_id int64) (models.VmStockFlow, error) {
  2224. flow := models.VmStockFlow{}
  2225. err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ?", patient_id, record_date, good_id).Find(&flow).Error
  2226. return flow, err
  2227. }
  2228. func ModifyPatientStockFlow(id int64, flow models.VmStockFlow) error {
  2229. err = XTReadDB().Model(&models.VmStockFlow{}).Where("id = ?", id).Updates(map[string]interface{}{"count": flow.Count, "status": 1, "is_read": 1}).Error
  2230. return err
  2231. }
  2232. func GetDrugFlowSart(drug_id int64, user_org_id int64, ctime int64) (flow []*models.DrugFlow, err error) {
  2233. db := XTReadDB().Model(&flow).Where("status = 1 and consumable_type = 1")
  2234. if drug_id > 0 {
  2235. db = db.Where("drug_id = ?", drug_id)
  2236. }
  2237. if user_org_id > 0 {
  2238. db = db.Where("user_org_id = ?", user_org_id)
  2239. }
  2240. if ctime > 0 {
  2241. db = db.Where("ctime <?", ctime)
  2242. }
  2243. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", user_org_id).Find(&flow).Error
  2244. return flow, err
  2245. }
  2246. func GetDrugFlowOut(drug_id int64, user_org_id int64, ctime int64) (flow []*models.DrugFlowTwenty, err error) {
  2247. db := XTReadDB().Model(&flow).Where("status = 1 and (consumable_type = 2 or consumable_type= 3 or consumable_type= 15)")
  2248. if drug_id > 0 {
  2249. db = db.Where("drug_id = ?", drug_id)
  2250. }
  2251. if user_org_id > 0 {
  2252. db = db.Where("user_org_id = ?", user_org_id)
  2253. }
  2254. if ctime > 0 {
  2255. db = db.Where("ctime <?", ctime)
  2256. }
  2257. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", user_org_id).Find(&flow).Error
  2258. return flow, err
  2259. }
  2260. func GetStartDrugFlowCancelInfo(drug_id int64, user_org_id int64, ctime int64) (flow []*models.DrugFlowTwenty, err error) {
  2261. db := XTReadDB().Model(&flow).Where("status = 1 and (consumable_type = 4 or consumable_type = 7)")
  2262. if drug_id > 0 {
  2263. db = db.Where("drug_id = ?", drug_id)
  2264. }
  2265. if user_org_id > 0 {
  2266. db = db.Where("user_org_id = ?", user_org_id)
  2267. }
  2268. if ctime > 0 {
  2269. db = db.Where("ctime <?", ctime)
  2270. }
  2271. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", user_org_id).Find(&flow).Error
  2272. return flow, err
  2273. }
  2274. func GetDrugFlowStartProfit(drug_id int64, user_org_id int64, ctime int64) (flow []*models.DrugFlowTwenty, err error) {
  2275. db := XTReadDB().Model(&flow).Where("status = 1 and consumable_type = 10")
  2276. if drug_id > 0 {
  2277. db = db.Where("drug_id = ?", drug_id)
  2278. }
  2279. if user_org_id > 0 {
  2280. db = db.Where("user_org_id = ?", user_org_id)
  2281. }
  2282. if ctime > 0 {
  2283. db = db.Where("ctime <?", ctime)
  2284. }
  2285. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", user_org_id).Find(&flow).Error
  2286. return flow, err
  2287. }
  2288. func GetDrugFlowStartLosses(drug_id int64, user_org_id int64, ctime int64) (flow []*models.DrugFlowTwenty, err error) {
  2289. db := XTReadDB().Model(&flow).Where("status = 1 and consumable_type = 11 ")
  2290. if drug_id > 0 {
  2291. db = db.Where("drug_id = ?", drug_id)
  2292. }
  2293. if user_org_id > 0 {
  2294. db = db.Where("user_org_id = ?", user_org_id)
  2295. }
  2296. if ctime > 0 {
  2297. db = db.Where("ctime <?", ctime)
  2298. }
  2299. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", user_org_id).Find(&flow).Error
  2300. return flow, err
  2301. }
  2302. func GetDrugFlowEndProfit(drug_id int64, user_org_id int64, endtime int64) (flow []*models.DrugFlowTwenty, err error) {
  2303. db := XTReadDB().Model(&flow).Where("status = 1 and consumable_type = 10")
  2304. if drug_id > 0 {
  2305. db = db.Where("drug_id = ?", drug_id)
  2306. }
  2307. if user_org_id > 0 {
  2308. db = db.Where("user_org_id = ?", user_org_id)
  2309. }
  2310. if endtime > 0 {
  2311. db = db.Where("ctime <=?", endtime)
  2312. }
  2313. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", user_org_id).Find(&flow).Error
  2314. return flow, err
  2315. }
  2316. func GetDrugFlowEndLosses(drug_id int64, user_org_id int64, endtime int64) (flow []*models.DrugFlowTwenty, err error) {
  2317. db := XTReadDB().Model(&flow).Where("status = 1 and consumable_type = 11")
  2318. if drug_id > 0 {
  2319. db = db.Where("drug_id = ?", drug_id)
  2320. }
  2321. if user_org_id > 0 {
  2322. db = db.Where("user_org_id = ?", user_org_id)
  2323. }
  2324. if endtime > 0 {
  2325. db = db.Where("ctime <=?", endtime)
  2326. }
  2327. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", user_org_id).Find(&flow).Error
  2328. return flow, err
  2329. }
  2330. func GetDrugFlowStartEndProfit(drug_id int64, user_org_id int64, startime int64, endtime int64) (flow []*models.DrugFlowTwenty, err error) {
  2331. db := XTReadDB().Model(&flow).Where("status = 1 and consumable_type = 10 ")
  2332. if drug_id > 0 {
  2333. db = db.Where("drug_id = ?", drug_id)
  2334. }
  2335. if user_org_id > 0 {
  2336. db = db.Where("user_org_id = ?", user_org_id)
  2337. }
  2338. if startime > 0 {
  2339. db = db.Where("ctime >=?", startime)
  2340. }
  2341. if endtime > 0 {
  2342. db = db.Where("ctime<=?", endtime)
  2343. }
  2344. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", user_org_id).Find(&flow).Error
  2345. return flow, err
  2346. }
  2347. func GetDrugFlowStartEndLosses(drug_id int64, user_org_id int64, startime int64, endtime int64) (flow []*models.DrugFlowTwenty, err error) {
  2348. db := XTReadDB().Model(&flow).Where("status = 1 and consumable_type = 11 ")
  2349. if drug_id > 0 {
  2350. db = db.Where("drug_id = ?", drug_id)
  2351. }
  2352. if user_org_id > 0 {
  2353. db = db.Where("user_org_id = ?", user_org_id)
  2354. }
  2355. if startime > 0 {
  2356. db = db.Where("ctime >=?", startime)
  2357. }
  2358. if endtime > 0 {
  2359. db = db.Where("ctime<=?", endtime)
  2360. }
  2361. err = db.Preload("DrugWarehouseInfoOne", "org_id =? and status = 1", user_org_id).Find(&flow).Error
  2362. return flow, err
  2363. }
  2364. func GetDrugWarehouseInfoStorehouseList(orgid int64) (info []*models.DrugWarehouseInfo, err error) {
  2365. err = XTReadDB().Where("org_id = ? and is_check= 1 and status = 1", orgid).Group("drug_id,storehouse_id").Find(&info).Error
  2366. return info, err
  2367. }
  2368. func GetDrugStockCout(drug_id int64, storehouse_id int64, user_org_id int64) (models.XtDrugStockCount, error) {
  2369. drugCount := models.XtDrugStockCount{}
  2370. err := XTReadDB().Where("drug_id = ? and storehouse_id = ? and user_org_id = ? and status = 1", drug_id, storehouse_id, user_org_id).Find(&drugCount).Error
  2371. return drugCount, err
  2372. }
  2373. func GetDrugWarehouseInfoByStorehouseId(storehouse_id int64, drug_id int64, org_id int64) (info []*models.DrugWarehouseInfo, err error) {
  2374. err = XTReadDB().Where("drug_id = ? and storehouse_id = ? and org_id = ? and status =1 and is_check = 1", drug_id, storehouse_id, org_id).Find(&info).Error
  2375. return info, err
  2376. }
  2377. func GetDrugFlowStockOutCount(storehouse_id int64, drug_id int64, org_id int64) (flow []*models.DrugFlow, err error) {
  2378. err = XTReadDB().Where("storehouse_id = ? and drug_id = ? and user_org_id = ? and status = 1 and (consumable_type = 2 or consumable_type =3)", storehouse_id, drug_id, org_id).Find(&flow).Error
  2379. return flow, err
  2380. }
  2381. func GetDrugFlowStockCancelCount(storehouse_id int64, drug_id int64, org_id int64) (flow []*models.DrugFlow, err error) {
  2382. err = XTReadDB().Where("storehouse_id = ? and drug_id = ? and user_org_id = ? and status = 1 and consumable_type = 7", storehouse_id, drug_id, org_id).Find(&flow).Error
  2383. return flow, err
  2384. }
  2385. func CreateDrugStockCount(stockCount models.XtDrugStockCount) error {
  2386. err := XTWriteDB().Create(&stockCount).Error
  2387. return err
  2388. }
  2389. func GetGoodNewPurchaseStockQuery(good_type int64, keyword string, page int64, limit int64, orgid int64, ids []int64, goodIds []int64) (goodinfo []*models.GoodInfoTwenty, total int64, err error) {
  2390. db := XTReadDB().Model(&goodinfo).Where("status = 1")
  2391. offset := (page - 1) * limit
  2392. likeKey := "%" + keyword + "%"
  2393. if good_type > 0 {
  2394. db = db.Where("good_type_id = ?", good_type)
  2395. }
  2396. if orgid > 0 {
  2397. db = db.Where("org_id = ?", orgid)
  2398. }
  2399. //if len(ids) > 0 {
  2400. // db = db.Where("id in(?)", goodIds)
  2401. //}
  2402. if len(keyword) > 0 {
  2403. db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
  2404. }
  2405. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&goodinfo).Error
  2406. return goodinfo, total, err
  2407. }
  2408. func GetGoodNewPurchaseStockQueryOne(good_type int64, keyword string, page int64, limit int64, orgid int64, ids []int64, goodIds []int64) (goodinfo []*models.GoodInfoTwenty, total int64, err error) {
  2409. db := XTReadDB().Model(&goodinfo).Where("status = 1")
  2410. if orgid == 10697 || orgid == 10644 {
  2411. db = db.Where("find_in_set('停用',good_status) = 0")
  2412. }
  2413. offset := (page - 1) * limit
  2414. likeKey := "%" + keyword + "%"
  2415. if good_type > 0 {
  2416. db = db.Where("good_type_id = ?", good_type)
  2417. }
  2418. if orgid > 0 {
  2419. db = db.Where("org_id = ?", orgid)
  2420. }
  2421. if len(ids) > 0 {
  2422. db = db.Where("id in(?)", goodIds)
  2423. }
  2424. if len(keyword) > 0 {
  2425. db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
  2426. }
  2427. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&goodinfo).Error
  2428. return goodinfo, total, err
  2429. }
  2430. func GetStartLastFLow(goodid int64, orgid int64, startime int64, storehouse_id int64) (models.VmStockFlowTwenty, error) {
  2431. flwo := models.VmStockFlowTwenty{}
  2432. err := XTReadDB().Where("good_id = ? and user_org_id = ? and status = 1 and ctime < ? and storehouse_id = ?", goodid, orgid, startime, storehouse_id).Last(&flwo).Error
  2433. return flwo, err
  2434. }
  2435. func GetStartLastFLowTwenty(goodid int64, orgid int64, startime int64) (models.VmStockFlowTwenty, error) {
  2436. flwo := models.VmStockFlowTwenty{}
  2437. err := XTReadDB().Where("good_id = ? and user_org_id = ? and status = 1 and ctime < ?", goodid, orgid, startime).Order("ctime desc").Last(&flwo).Error
  2438. return flwo, err
  2439. }
  2440. func GetEndLastFlow(goodid int64, orgid int64, endtime int64, storehouse_id int64) (models.VmStockFlowTwenty, error) {
  2441. flwo := models.VmStockFlowTwenty{}
  2442. err := XTReadDB().Where("good_id = ? and user_org_id = ? and status = 1 and ctime <= ? and storehouse_id= ?", goodid, orgid, endtime, storehouse_id).Order("ctime desc").Last(&flwo).Error
  2443. return flwo, err
  2444. }
  2445. func GetEndLastFlowTwenty(goodid int64, orgid int64, endtime int64) (models.VmStockFlowTwenty, error) {
  2446. flwo := models.VmStockFlowTwenty{}
  2447. err := XTReadDB().Where("good_id = ? and user_org_id = ? and status = 1 and ctime <= ?", goodid, orgid, endtime).Last(&flwo).Error
  2448. return flwo, err
  2449. }
  2450. func GetDrugNewPurchaseStockQuery(good_type int64, keyword string, page int64, limit int64, orgid int64, startime int64, endtime int64, ids []int64, infos []int64) (druginfo []*models.VmBaseDrugTwenty, total int64, err error) {
  2451. db := XTReadDB().Model(&druginfo).Where("status = 1 and is_self_drug!=1")
  2452. offset := (page - 1) * limit
  2453. likeKey := "%" + keyword + "%"
  2454. if good_type > 0 {
  2455. db = db.Where("drug_type = ?", good_type)
  2456. }
  2457. if orgid == 10697 || orgid == 10644 {
  2458. db = db.Where("find_in_set('停用',drug_status) = 0")
  2459. }
  2460. if orgid > 0 {
  2461. db = db.Where("org_id = ?", orgid)
  2462. }
  2463. if len(keyword) > 0 {
  2464. db = db.Where("drug_name like ? or manufacturer in(?)", likeKey, ids)
  2465. }
  2466. //if len(infos) > 0 {
  2467. // db = db.Where("id in(?)", infos)
  2468. //}
  2469. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&druginfo).Error
  2470. return druginfo, total, err
  2471. }
  2472. func GetDrugNewPurchaseStockQueryList(good_type int64, keyword string, page int64, limit int64, orgid int64, startime int64, endtime int64, ids []int64, infos []int64) (druginfo []*models.VmBaseDrugTwenty, total int64, err error) {
  2473. db := XTReadDB().Model(&druginfo).Where("status = 1")
  2474. offset := (page - 1) * limit
  2475. likeKey := "%" + keyword + "%"
  2476. if good_type > 0 {
  2477. db = db.Where("drug_type = ?", good_type)
  2478. }
  2479. if orgid > 0 {
  2480. db = db.Where("org_id = ?", orgid)
  2481. }
  2482. if len(keyword) > 0 {
  2483. db = db.Where("drug_name like ? or manufacturer in(?)", likeKey, ids)
  2484. }
  2485. if len(infos) > 0 {
  2486. db = db.Where("id in(?)", infos)
  2487. }
  2488. err = db.Count(&total).Offset(offset).Limit(limit).Order("drug_alias desc").Find(&druginfo).Error
  2489. return druginfo, total, err
  2490. }
  2491. func GetDrugStartFlow(drug_id int64, user_org_id int64, startime int64) (models.DrugFlowTwenty, error) {
  2492. flow := models.DrugFlowTwenty{}
  2493. err := XTReadDB().Where("drug_id = ? and user_org_id = ? and ctime<? and status = 1", drug_id, user_org_id, startime).Order("ctime desc").Last(&flow).Error
  2494. return flow, err
  2495. }
  2496. func GetDrugEndFlow(drug_id int64, user_org_id int64, endtime int64) (models.DrugFlowTwenty, error) {
  2497. flow := models.DrugFlowTwenty{}
  2498. err := XTReadDB().Where("drug_id = ? and user_org_id = ? and ctime<=? and status = 1", drug_id, user_org_id, endtime).Order("ctime desc").Last(&flow).Error
  2499. return flow, err
  2500. }
  2501. func GetAllStockCount(orgid int64) (stock []*models.XtGoodStockCount, err error) {
  2502. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&stock).Error
  2503. return stock, err
  2504. }
  2505. func GetLastStockFlow(good_id int64) (models.VmStockFlow, error) {
  2506. flow := models.VmStockFlow{}
  2507. err := XTReadDB().Where("good_id = ? and status =1 and ctime<=1667231999", good_id).Last(&flow).Error
  2508. return flow, err
  2509. }
  2510. func ModifyStockFlowById(id int64, over_count int64) error {
  2511. err := XTWriteDB().Model(&models.VmStockFlow{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"over_count": over_count}).Error
  2512. return err
  2513. }
  2514. func GetAllDrugCount(user_org_id int64) (drug []*models.XtDrugStockCount, err error) {
  2515. err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&drug).Error
  2516. return drug, err
  2517. }
  2518. func GetLastDrugFlow(drug_id int64) (models.DrugFlow, error) {
  2519. flow := models.DrugFlow{}
  2520. err := XTReadDB().Where("drug_id = ? and status =1 and ctime<=1667231999", drug_id).Last(&flow).Error
  2521. return flow, err
  2522. }
  2523. func ModifyDrugFlowById(id int64, over_count int64) error {
  2524. err := XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"over_count": over_count}).Error
  2525. return err
  2526. }
  2527. func GetDrugInventoryWarehouseInfoList(org_id int64, storehouse_id int64) (info []*models.XtDrugWarehouseInfo, err error) {
  2528. if org_id == 10138 || org_id == 10278 {
  2529. err = XTReadDB().Model(&info).Where("status = 1 and storehouse_id = ? and is_check = 1 and org_id = ?", storehouse_id, org_id).Preload("XtBaseDrug", "status= 1").Order("drug_id").Find(&info).Error
  2530. return info, err
  2531. } else {
  2532. err = XTReadDB().Model(&info).Where("status = 1 and storehouse_id = ? and is_check = 1 and org_id = ? and (stock_max_number >0 or stock_min_number >0)", storehouse_id, org_id).Preload("XtBaseDrug", "status= 1").Order("drug_id").Find(&info).Error
  2533. return info, err
  2534. }
  2535. }
  2536. func GetGoodStockCountList(user_org_id int64, good_id int64) (stock []*models.XtGoodStockCount, err error) {
  2537. err = XTReadDB().Where("user_org_id =? and status=1 and good_id = ?", user_org_id, good_id).Find(&stock).Error
  2538. return stock, err
  2539. }
  2540. func GetDrugCountMapList(drug_id int64, user_org_id int64) (drug []*models.XtDrugStockCount, err error) {
  2541. err = XTReadDB().Where("drug_id = ? and user_org_id =? and status=1", drug_id, user_org_id).Find(&drug).Error
  2542. return drug, err
  2543. }
  2544. func UpdateDrugStockInCount(drugId int64, storehouseId int64, over_count int64, user_org_id int64) error {
  2545. err := XTWriteDB().Model(&models.XtDrugStockCount{}).Where("drug_id =? and storehouse_id =? and status=1 and user_org_id =?", drugId, storehouseId, user_org_id).Update(map[string]interface{}{"sum_out_count": over_count}).Error
  2546. return err
  2547. }
  2548. func UpdateDrugStockInCountOne(drugId int64, storehouseId int64, over_count int64, user_org_id int64) error {
  2549. err := XTWriteDB().Model(&models.XtDrugStockCount{}).Where("drug_id =? and storehouse_id =? and status=1 and user_org_id =?", drugId, storehouseId, user_org_id).Update(map[string]interface{}{"sum_act_out_count": over_count}).Error
  2550. return err
  2551. }
  2552. func GetPurchaseStockQueryList(good_type int64, keyword string, page int64, limit int64, orgid int64, ids []int64, goodIds []int64) (goodinfo []*models.GoodInfoTwenty, total int64, err error) {
  2553. db := XTReadDB().Model(&goodinfo).Where("status = 1")
  2554. offset := (page - 1) * limit
  2555. likeKey := "%" + keyword + "%"
  2556. if good_type > 0 {
  2557. db = db.Where("good_type_id = ?", good_type)
  2558. }
  2559. if orgid > 0 {
  2560. db = db.Where("org_id = ?", orgid)
  2561. }
  2562. if len(ids) > 0 {
  2563. db = db.Where("id in(?)", goodIds)
  2564. }
  2565. if len(keyword) > 0 {
  2566. db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
  2567. }
  2568. err = db.Count(&total).Offset(offset).Limit(limit).Order("good_number desc").Find(&goodinfo).Error
  2569. return goodinfo, total, err
  2570. }
  2571. func GetInitBalanceList(good_id int64, user_org_id int64, start_time int64, end_time int64, storehouse_id int64) (list []*models.StWarehousingInfoOne, err error) {
  2572. db := XTReadDB().Model(&list).Where("status=1 and is_check=1")
  2573. if good_id > 0 {
  2574. db = db.Where("good_id = ?", good_id)
  2575. }
  2576. if user_org_id > 0 {
  2577. db = db.Where("org_id = ?", user_org_id)
  2578. }
  2579. if start_time > 0 {
  2580. db = db.Where("ctime<?", start_time)
  2581. }
  2582. if storehouse_id > 0 {
  2583. db = db.Where("storehouse_id = ?", storehouse_id)
  2584. }
  2585. err = db.Find(&list).Error
  2586. return list, err
  2587. }
  2588. func GetInitOutBanceTenty(good_id int64, user_org_id int64, start_time int64, end_time int64, storehouse_id int64) (list []*models.VmStockFlowTwenty, err error) {
  2589. db := XTReadDB().Model(&list).Where("status=1 and (consumable_type=2 or consumable_type =3)")
  2590. if good_id > 0 {
  2591. db = db.Where("good_id = ?", good_id)
  2592. }
  2593. if user_org_id > 0 {
  2594. db = db.Where("user_org_id = ?", user_org_id)
  2595. }
  2596. if start_time > 0 {
  2597. db = db.Where("ctime<?", start_time)
  2598. }
  2599. if storehouse_id > 0 {
  2600. db = db.Where("storehouse_id = ?", storehouse_id)
  2601. }
  2602. err = db.Find(&list).Error
  2603. return list, err
  2604. }
  2605. func GetInitOutBanceList(good_id int64, user_org_id int64, start_time int64, end_time int64, storehouse_id int64) (list []*models.WarehouseOutInfoTenty, err error) {
  2606. db := XTReadDB().Model(&list).Where("status=1")
  2607. if good_id > 0 {
  2608. db = db.Where("good_id = ?", good_id)
  2609. }
  2610. if user_org_id > 0 {
  2611. db = db.Where("org_id = ?", user_org_id)
  2612. }
  2613. if start_time > 0 {
  2614. db = db.Where("ctime<?", start_time)
  2615. }
  2616. if storehouse_id > 0 {
  2617. db = db.Where("storehouse_id = ?", storehouse_id)
  2618. }
  2619. err = db.Group("patient_id,good_id,sys_record_time,is_sys,ctime").Find(&list).Error
  2620. return list, err
  2621. }
  2622. func GetInitInfoFlow(good_id int64, user_org_id int64, start_time int64, end_time int64, storehouse_id int64) (list []*models.VmStockFlowTwenty, err error) {
  2623. db := XTReadDB().Model(&list).Where("status=1 and consumable_type =10")
  2624. if good_id > 0 {
  2625. db = db.Where("good_id = ?", good_id)
  2626. }
  2627. if user_org_id > 0 {
  2628. db = db.Where("user_org_id = ?", user_org_id)
  2629. }
  2630. if start_time > 0 {
  2631. db = db.Where("ctime<?", start_time)
  2632. }
  2633. if storehouse_id > 0 {
  2634. db = db.Where("storehouse_id = ?", storehouse_id)
  2635. }
  2636. err = db.Find(&list).Error
  2637. return list, err
  2638. }
  2639. func GetInitOutInfoFlow(good_id int64, user_org_id int64, start_time int64, end_time int64, storehouse_id int64) (list []*models.VmStockFlowTwenty, err error) {
  2640. db := XTReadDB().Model(&list).Where("status=1 and consumable_type =11")
  2641. if good_id > 0 {
  2642. db = db.Where("good_id = ?", good_id)
  2643. }
  2644. if user_org_id > 0 {
  2645. db = db.Where("user_org_id = ?", user_org_id)
  2646. }
  2647. if start_time > 0 {
  2648. db = db.Where("ctime<?", start_time)
  2649. }
  2650. if storehouse_id > 0 {
  2651. db = db.Where("storehouse_id = ?", storehouse_id)
  2652. }
  2653. err = db.Find(&list).Error
  2654. return list, err
  2655. }
  2656. func GetNewDrugFlowInWarehouseInfo(drug_id int64, user_org_id int64, start_time int64) (list []*models.DrugFlowTwenty, err error) {
  2657. db := XTReadDB().Model(&list).Where("status=1 and consumable_type=1")
  2658. if drug_id > 0 {
  2659. db = db.Where("drug_id = ?", drug_id)
  2660. }
  2661. if user_org_id > 0 {
  2662. db = db.Where("user_org_id = ?", user_org_id)
  2663. }
  2664. if start_time > 0 {
  2665. db = db.Where("ctime<?", start_time)
  2666. }
  2667. err = db.Find(&list).Error
  2668. return list, err
  2669. }
  2670. func GetNewDrugFlowPofitWarehouseInfo(drug_id int64, user_org_id int64, start_time int64) (list []*models.DrugFlowTwenty, err error) {
  2671. db := XTReadDB().Model(&list).Where("status=1 and consumable_type=10")
  2672. if drug_id > 0 {
  2673. db = db.Where("drug_id = ?", drug_id)
  2674. }
  2675. if user_org_id > 0 {
  2676. db = db.Where("user_org_id = ?", user_org_id)
  2677. }
  2678. if start_time > 0 {
  2679. db = db.Where("ctime<?", start_time)
  2680. }
  2681. err = db.Find(&list).Error
  2682. return list, err
  2683. }
  2684. func GetNewDrugFlowOutWarehouseInfo(drug_id int64, user_org_id int64, start_time int64) (list []*models.DrugFlowTwenty, err error) {
  2685. db := XTReadDB().Model(&list).Where("status=1 and (consumable_type=3 or consumable_type=2)")
  2686. if drug_id > 0 {
  2687. db = db.Where("drug_id = ?", drug_id)
  2688. }
  2689. if user_org_id > 0 {
  2690. db = db.Where("user_org_id = ?", user_org_id)
  2691. }
  2692. if start_time > 0 {
  2693. db = db.Where("ctime<?", start_time)
  2694. }
  2695. err = db.Find(&list).Error
  2696. return list, err
  2697. }
  2698. func GetNewDrugFlowCacelWarehouseInfo(drug_id int64, user_org_id int64, start_time int64) (list []*models.DrugFlowTwenty, err error) {
  2699. db := XTReadDB().Model(&list).Where("status=1 and consumable_type=7")
  2700. if drug_id > 0 {
  2701. db = db.Where("drug_id = ?", drug_id)
  2702. }
  2703. if user_org_id > 0 {
  2704. db = db.Where("user_org_id = ?", user_org_id)
  2705. }
  2706. if start_time > 0 {
  2707. db = db.Where("ctime<?", start_time)
  2708. }
  2709. err = db.Find(&list).Error
  2710. return list, err
  2711. }
  2712. func GetNewDrugFlowNoPofitWarehouseInfo(drug_id int64, user_org_id int64, start_time int64) (list []*models.DrugFlowTwenty, err error) {
  2713. db := XTReadDB().Model(&list).Where("status=1 and consumable_type=11")
  2714. if drug_id > 0 {
  2715. db = db.Where("drug_id = ?", drug_id)
  2716. }
  2717. if user_org_id > 0 {
  2718. db = db.Where("user_org_id = ?", user_org_id)
  2719. }
  2720. if start_time > 0 {
  2721. db = db.Where("ctime<?", start_time)
  2722. }
  2723. err = db.Find(&list).Error
  2724. return list, err
  2725. }
  2726. func GetHisAdviceGroupList(drug_id int64, user_org_id int64) (advicelist []*models.HisDoctorAdviceInfo, err error) {
  2727. if user_org_id == 10265 {
  2728. err = XTReadDB().Where("drug_id = ? and user_org_id = ? and status=1 and execution_state =1", drug_id, user_org_id).Order("advice_date asc").Find(&advicelist).Error
  2729. return advicelist, err
  2730. } else {
  2731. err = XTReadDB().Where("drug_id = ? and user_org_id = ? and status=1", drug_id, user_org_id).Order("advice_date asc").Find(&advicelist).Error
  2732. return advicelist, err
  2733. }
  2734. }
  2735. func GetDrugWarehousOutInfo(drug_id int64, org_id int64) (out []*models.XtDrugWarehouseOutInfo, err error) {
  2736. err = XTReadDB().Where("drug_id = ? and status=1 and org_id=? and is_sys=1", drug_id, org_id).Order("sys_record_time asc").Find(&out).Error
  2737. return out, err
  2738. }
  2739. func GetDrugWarehousOutInfoOne(drug_id int64, org_id int64) (out []*models.XtDrugWarehouseOutInfo, err error) {
  2740. err = XTReadDB().Where("drug_id = ? and status=1 and org_id=? and is_sys=0", drug_id, org_id).Order("sys_record_time asc").Find(&out).Error
  2741. return out, err
  2742. }
  2743. func GetCheckDrugFlow(drug_id int64, user_org_id int64) (drugflow []*models.DrugFlow, err error) {
  2744. err = XTReadDB().Where("drug_id =? and status=1 and (consumable_type =10 or consumable_type =11) and user_org_id = ?", drug_id, user_org_id).Order("system_time asc").Find(&drugflow).Error
  2745. return drugflow, err
  2746. }
  2747. func GetCheckGoodBatchList(good_id int64, user_org_id int64) (project []*models.HisPrescriptionProject, err error) {
  2748. err = XTReadDB().Where("project_id = ? and user_org_id = ? and status =1 and type =3", good_id, user_org_id).Order("record_date asc").Find(&project).Error
  2749. return project, err
  2750. }
  2751. func GetCheckGoodWarehouseList(good_id int64, org_id int64) (info []*models.WarehouseOutInfo, err error) {
  2752. err = XTReadDB().Where("good_id = ? and org_id = ? and status=1 and is_sys=0", good_id, org_id).Order("sys_record_time").Find(&info).Error
  2753. return info, err
  2754. }
  2755. func GetHisAdviceListBySysRrecordTime(drug_id int64, sys_record_time int64, user_org_id int64) (info []*models.HisDoctorAdviceInfo, err error) {
  2756. err = XTReadDB().Where("drug_id=? and advice_date = ? and user_org_id = ? and status =1", drug_id, sys_record_time, user_org_id).Find(&info).Error
  2757. return info, err
  2758. }
  2759. func GetDrugWarehouseOutInfoBySysRecordTime(drug_id int64, sys_record_time int64, user_org_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
  2760. err = XTReadDB().Where("drug_id=? and sys_record_time =? and org_id = ? and status =1", drug_id, sys_record_time, user_org_id).Find(&info).Error
  2761. return info, err
  2762. }
  2763. func GetGoodProjectList(good_id int64, sys_record_time int64, user_org_id int64) (project []*models.HisPrescriptionProject, err error) {
  2764. err = XTReadDB().Where("project_id = ? and status =1 and record_date = ? and user_org_id=? and type =3", good_id, sys_record_time, user_org_id).Find(&project).Error
  2765. return project, err
  2766. }
  2767. func GetWarehouseOutListBySysrecordTime(good_id int64, sys_record_time int64, user_org_id int64) (out []*models.WarehouseOutInfo, err error) {
  2768. err = XTReadDB().Where("good_id = ? and sys_record_time =? and org_id = ? and status=1 and is_sys=1", good_id, sys_record_time, user_org_id).Find(&out).Error
  2769. return out, err
  2770. }
  2771. func UpdateBaseDrugById(id int64, drug_str string) (models.XtBaseDrug, error) {
  2772. baseDrug := models.XtBaseDrug{}
  2773. err := XTWriteDB().Model(&baseDrug).Where("id = ? and status =1", id).Updates(map[string]interface{}{"drug_spec": drug_str}).Error
  2774. return baseDrug, err
  2775. }
  2776. func UpdateDosageFormListById(drug_dosage_form_name string, drug_id int64) (models.XtBaseDrug, error) {
  2777. drug := models.XtBaseDrug{}
  2778. err := XTWriteDB().Model(&drug).Where("id = ? and status =1", drug_id).Updates(map[string]interface{}{"drug_dosage_form_name": drug_dosage_form_name}).Error
  2779. return drug, err
  2780. }
  2781. func GetDosageFormListById(id int64, orgId int64) (str string) {
  2782. var drugDosageForm = "药品剂型"
  2783. drugDosageFormParent, _ := GetDrugDataConfig(0, drugDosageForm)
  2784. drugDosageFormList, _ := GetParentDataConfig(drugDosageFormParent.ID, orgId)
  2785. for _, item := range drugDosageFormList {
  2786. if id == int64(item.Value) {
  2787. str = item.Name
  2788. }
  2789. }
  2790. return str
  2791. }
  2792. func GetDrugAllInfo(org_id int64) (warehouseInfo []*models.DrugWarehouseInfo, err error) {
  2793. err = XTReadDB().Where("org_id = ? and status= 1 and ctime>=1640966400 and ctime<=1703952000", org_id).Find(&warehouseInfo).Error
  2794. return warehouseInfo, err
  2795. }
  2796. func GetDrugOutAllInfo(org_id int64) (warehouseInfo []*models.DrugWarehouseOutInfo, err error) {
  2797. err = XTReadDB().Where("org_id = ? and status= 1 and ctime>=1672502400 and ctime<=1704038399", org_id).Find(&warehouseInfo).Error
  2798. return warehouseInfo, err
  2799. }
  2800. func UpdateDealerManufacturer(id int64, dealer_name string, manufactruer string) (err error) {
  2801. warehouseInfo := models.DrugWarehouseInfo{}
  2802. err = XTWriteDB().Model(&warehouseInfo).Where("id = ? and status =1", id).Updates(map[string]interface{}{"manafacturer_name": manufactruer, "dealer_name": dealer_name}).Error
  2803. return err
  2804. }
  2805. func UpdateDealerManufacturerOne(id int64, manufactruer string) (err error) {
  2806. warehouseInfo := models.DrugWarehouseOutInfo{}
  2807. err = XTWriteDB().Model(&warehouseInfo).Where("id = ? and status =1", id).Updates(map[string]interface{}{"manafacturer_name": manufactruer}).Error
  2808. return err
  2809. }
  2810. func GetDrugWarehouseInfoByItemId(drug_id int64) (list []*models.XtDrugWarehouseInfo, err error) {
  2811. err = XTReadDB().Where("drug_id = ? and status=1 and is_check=1 and ctime<1704038399", drug_id).Find(&list).Error
  2812. return list, err
  2813. }
  2814. func GetDrugWarehosueOutInfoByItemId(drug_id int64) (list []*models.XtDrugWarehouseOutInfo, err error) {
  2815. err = XTReadDB().Where("drug_id = ? and status=1 and is_check=1 and ctime<1704038399", drug_id).Find(&list).Error
  2816. return list, err
  2817. }
  2818. func UpdateBaseDrugByIdCount(drug_id int64, flush_count int64) (models.XtBaseDrug, error) {
  2819. drug := models.XtBaseDrug{}
  2820. err := XTWriteDB().Model(&drug).Model(&drug).Where("id = ? and status=1", drug_id).Updates(map[string]interface{}{"total_count_one": flush_count}).Error
  2821. return drug, err
  2822. }
  2823. func UpdateBaseDrugByIdCountTwo(drug_id int64, flush_count int64) (models.XtBaseDrug, error) {
  2824. drug := models.XtBaseDrug{}
  2825. err := XTWriteDB().Model(&drug).Model(&drug).Where("id = ? and status=1", drug_id).Updates(map[string]interface{}{"total_count_two": flush_count}).Error
  2826. return drug, err
  2827. }
  2828. func GetAllWareHouseInforByUserOrg(org_id int64) (info []*models.WarehousingInfo, err error) {
  2829. err = XTReadDB().Where("org_id =? and status =1 and is_check=1 and ctime>=1672502400 and ctime<=1703952000", org_id).Find(&info).Error
  2830. return info, err
  2831. }
  2832. func GetAllWareHouseOutByUserOrg(org_id int64) (info []*models.WarehouseOutInfo, err error) {
  2833. err = XTReadDB().Where("org_id =? and status =1 and is_check=1 and ctime>=1672502400 and ctime<=1703952000", org_id).Find(&info).Error
  2834. return info, err
  2835. }
  2836. func UpdateGoodInfoByUserOrgId(id int64, dealer_name string, manufactruer string) (err error) {
  2837. warehousingInfo := models.WarehousingInfo{}
  2838. err = XTWriteDB().Model(&warehousingInfo).Where("id = ? and status =1", id).Updates(map[string]interface{}{"dealer_name": dealer_name, "manafacturer_name": manufactruer}).Error
  2839. return err
  2840. }
  2841. func UpdateGoodInfoByUserOrgIdTwo(id int64, dealer_name string) (err error) {
  2842. WarehouseOutInfo := models.WarehouseOutInfo{}
  2843. err = XTWriteDB().Model(&WarehouseOutInfo).Where("id = ? and status =1", id).Updates(map[string]interface{}{"dealer_name": dealer_name}).Error
  2844. return err
  2845. }
  2846. func GetAllWarehouseSumInCount(org_id int64) (infor []*models.WarehousingInfo, err error) {
  2847. err = XTReadDB().Where("id = ? and status =1 and is_check =1 and ctime<1704038399", org_id).Find(&infor).Error
  2848. return infor, err
  2849. }
  2850. func GetAllWarehouseSumOutCount(org_id int64) (infor []*models.WarehouseOutInfo, err error) {
  2851. err = XTReadDB().Where("id = ? and status =1 and is_check =1 and ctime<1704038399", org_id).Find(&infor).Error
  2852. return infor, err
  2853. }
  2854. func UpdateGoodInfoById(id int64, total_count_one int64) error {
  2855. err := XTWriteDB().Model(&models.GoodInfoSevenThirty{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"total_count_one": total_count_one}).Error
  2856. return err
  2857. }
  2858. func UpdateGoodInfoByIdOne(id int64, total_count_one int64) error {
  2859. err := XTWriteDB().Model(&models.GoodInfoSevenThirty{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"total_count_two": total_count_one}).Error
  2860. return err
  2861. }
  2862. func GetAllSelfDrugInfoList(org_id int64) (base []*models.BaseDrugLibThrity, err error) {
  2863. err = XTReadDB().Where("org_id = ? and status =1 and is_self_drug =1", org_id).Find(&base).Error
  2864. return base, err
  2865. }
  2866. func GetAllPatientListByUserOrg(org_id int64) (patient []*models.XtPatients, err error) {
  2867. err = XTReadDB().Where("user_org_id =? and status=1", org_id).Find(&patient).Error
  2868. return patient, err
  2869. }
  2870. func PostSearchSelfDrugList(keywords string, user_org_id int64) (drug []*models.BaseDrugLibThrity, err error) {
  2871. db := XTReadDB().Model(&drug).Where("org_id=? and status=1 and is_self_drug=1", user_org_id)
  2872. if len(keywords) > 0 {
  2873. likekey := "%" + keywords + "%"
  2874. err = db.Where("(drug_name LIKE ?)", likekey).Preload("LastDrugWarehouseInfo", "org_id=? and status = 1 and (stock_max_number > 0 or stock_min_number>0) and storehouse_id = ?", user_org_id).Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  2875. return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0", user_org_id).Group("id")
  2876. }).Find(&drug).Error
  2877. } else {
  2878. err = db.Preload("LastDrugWarehouseInfo", "org_id=? and status = 1 and (stock_max_number > 0 or stock_min_number>0)", user_org_id).Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  2879. return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0 ", user_org_id).Group("id")
  2880. }).Find(&drug).Error
  2881. }
  2882. return
  2883. }
  2884. func FindAllSelfDrugList(org_id int64, patient_id int64) (total int64, err error) {
  2885. err = readDb.Model(&models.XtSelfDrugWarehouseInfo{}).Where("org_id = ? and patient_id", org_id, patient_id).Count(&total).Error
  2886. return total, err
  2887. }
  2888. func CreatedSlefWarehouseing(info *models.XtSelfDrugWarehouseInfo, tx *gorm.DB) {
  2889. err := tx.Create(&info).Error
  2890. if err != nil {
  2891. tx.Rollback()
  2892. return
  2893. }
  2894. return
  2895. }
  2896. func UpdateSelfWarehouseing(info *models.XtSelfDrugWarehouseInfo, tx *gorm.DB) error {
  2897. err := tx.Save(&info).Error
  2898. if err != nil {
  2899. tx.Rollback()
  2900. return err
  2901. }
  2902. return err
  2903. }
  2904. func FindSelfDrugWarehouseInfoListById(id int64, org_id int64, patient_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  2905. err = tx.Where("warehousing_id = ? and org_id = ? and patient_id = ? and status=1", id, org_id, patient_id).Preload("BaseDrugLib", "status=1").Find(&info).Error
  2906. if err != gorm.ErrRecordNotFound {
  2907. if err != nil {
  2908. tx.Rollback()
  2909. return info, err
  2910. }
  2911. }
  2912. return info, err
  2913. }
  2914. func GetAllBaseDrugListByKeyWord(keyword string, org_id int64) (base []*models.BaseDrugLibSeven, err error) {
  2915. likeKey := "%" + keyword + "%"
  2916. db := XTReadDB().Model(&base).Where("status=1 and is_self_drug = 1")
  2917. if len(keyword) > 0 {
  2918. db = db.Where("drug_name like ?", likeKey)
  2919. }
  2920. if org_id > 0 {
  2921. db = db.Where("org_id = ?", org_id)
  2922. }
  2923. err = db.Find(&base).Error
  2924. return base, err
  2925. }
  2926. func GetAllSelfDrugWarehouseInfoList(ids []int64, org_id int64, patient_id int64) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  2927. db := XTReadDB().Model(&info).Where("status=1")
  2928. if len(ids) > 0 {
  2929. db = db.Where("drug_id in(?)", ids)
  2930. }
  2931. if org_id > 0 {
  2932. db = db.Where("org_id = ?", org_id)
  2933. }
  2934. if patient_id > 0 {
  2935. db = db.Where("patient_id = ?", patient_id)
  2936. }
  2937. err = db.Preload("BaseDrugLib", "status =1").Find(&info).Error
  2938. return info, err
  2939. }
  2940. func AddSelfDrugWarehouse(warehouse *models.XtSelfDrugWarehouse, tx *gorm.DB) error {
  2941. err := tx.Create(&warehouse).Error
  2942. if err != nil {
  2943. tx.Rollback()
  2944. return err
  2945. }
  2946. return err
  2947. }
  2948. func GetSelfDrugWarehouseByWaresingId(patient_id int64, record_time int64, org_id int64, tx *gorm.DB) (models.XtSelfDrugWarehouse, error) {
  2949. warehouse := models.XtSelfDrugWarehouse{}
  2950. err := tx.Where("patient_id = ? and warehousing_time = ? and org_id = ? and is_sys=1 and status=1", patient_id, record_time, org_id).Find(&warehouse).Error
  2951. if err != gorm.ErrRecordNotFound {
  2952. if err != nil {
  2953. tx.Rollback()
  2954. return warehouse, err
  2955. }
  2956. }
  2957. return warehouse, err
  2958. }
  2959. func UpdateSelfDrugWarehouse(warehouse *models.XtSelfDrugWarehouse, tx *gorm.DB) error {
  2960. err := tx.Save(&warehouse).Error
  2961. if err != nil {
  2962. tx.Rollback()
  2963. return err
  2964. }
  2965. return err
  2966. }
  2967. func FindSelfAllWarehouseTotal(org_id int64, tx *gorm.DB) (total int64, err2 error) {
  2968. err = tx.Model(&models.XtSelfDrugWarehouse{}).Where("org_id = ?", org_id).Count(&total).Error
  2969. if err != gorm.ErrRecordNotFound {
  2970. if err != nil {
  2971. tx.Rollback()
  2972. return total, err
  2973. }
  2974. }
  2975. return total, err
  2976. }
  2977. func FindLastSelfWarehousing(user_org_id int64, patient_id int64, tx *gorm.DB) (models.XtSelfDrugWarehouse, error) {
  2978. selfDrugWarehouse := models.XtSelfDrugWarehouse{}
  2979. err := tx.Where("org_id=? and patient_id =?", user_org_id, patient_id).Last(&selfDrugWarehouse).Error
  2980. if err != gorm.ErrRecordNotFound {
  2981. if err != nil {
  2982. tx.Rollback()
  2983. return selfDrugWarehouse, err
  2984. }
  2985. }
  2986. return selfDrugWarehouse, err
  2987. }
  2988. func GetSelfDrugWarehouseInfoByID(id int64) (models.XtSelfDrugWarehouseInfo, error) {
  2989. selfDrugWarehouseInfo := models.XtSelfDrugWarehouseInfo{}
  2990. err := XTReadDB().Where("warehousing_id = ? and status=1", id).Preload("BaseDrugLib", "status=1").Find(&selfDrugWarehouseInfo).Error
  2991. return selfDrugWarehouseInfo, err
  2992. }
  2993. func GetSelfDrugWarehouseInfoByIDOne(id int64) (selfDrugWarehouseInfo []*models.XtSelfDrugWarehouseInfo, err error) {
  2994. err = XTReadDB().Where("warehousing_id = ? and status=1", id).Preload("BaseDrugLib", "status=1").Find(&selfDrugWarehouseInfo).Error
  2995. return selfDrugWarehouseInfo, err
  2996. }
  2997. func GetSelfDrugWarehouseInfo(id int64) (models.XtSelfDrugWarehouse, error) {
  2998. warehouse := models.XtSelfDrugWarehouse{}
  2999. err := XTReadDB().Where("id = ? and status=1", id).Find(&warehouse).Error
  3000. return warehouse, err
  3001. }
  3002. func DeleteSelfDrugWarehouse(id int64, tx *gorm.DB) error {
  3003. info := models.XtSelfDrugWarehouseInfo{}
  3004. err := tx.Model(&info).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3005. if err != nil {
  3006. tx.Rollback()
  3007. return err
  3008. }
  3009. return err
  3010. }
  3011. func GetSelfWarehouseInfoByWarehouseInfo(id int64, patient_id int64, org_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3012. err = tx.Where("warehousing_id =? and patient_id =? and status=1 and org_id =?", id, patient_id, org_id).Find(&info).Error
  3013. if err != gorm.ErrRecordNotFound {
  3014. if err != nil {
  3015. tx.Rollback()
  3016. return info, err
  3017. }
  3018. }
  3019. return info, err
  3020. }
  3021. func AddSelfDrugWarehouseStockMaxNumber(count int64, id int64, tx *gorm.DB) error {
  3022. err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
  3023. if err != nil {
  3024. tx.Rollback()
  3025. return err
  3026. }
  3027. err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
  3028. if err != nil {
  3029. tx.Rollback()
  3030. return err
  3031. }
  3032. return err
  3033. }
  3034. func AddSelfDrugWarehouseStockMinNumber(count int64, id int64, tx *gorm.DB) error {
  3035. err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
  3036. if err != nil {
  3037. tx.Rollback()
  3038. return err
  3039. }
  3040. err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
  3041. if err != nil {
  3042. tx.Rollback()
  3043. return err
  3044. }
  3045. return err
  3046. }
  3047. func GetDrugSumCountByPatient(patient_id int64, org_id int64, drug_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3048. err = tx.Where("patient_id = ? and org_id = ? and drug_id = ? and status =1", patient_id, org_id, drug_id).Find(&info).Error
  3049. if err != gorm.ErrRecordNotFound {
  3050. if err != nil {
  3051. tx.Rollback()
  3052. return info, err
  3053. }
  3054. }
  3055. return info, err
  3056. }
  3057. func CreateSelfDrugFlow(flow *models.XtSelfDrugFlow, tx *gorm.DB) error {
  3058. err := tx.Create(&flow).Error
  3059. if err != nil {
  3060. tx.Rollback()
  3061. return err
  3062. }
  3063. return err
  3064. }
  3065. func GetSelfDrugSumCountByStorehouseId(patient_id int64, orgid int64, drug_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3066. err = tx.Where("patient_id = ? and org_id = ? and status = 1 and drug_id =? and is_check = 1", patient_id, orgid, drug_id).Find(&info).Error
  3067. if err != gorm.ErrRecordNotFound {
  3068. if err != nil {
  3069. tx.Rollback()
  3070. return info, err
  3071. }
  3072. }
  3073. return info, err
  3074. }
  3075. func CreateSelfDrugStockSum(drug models.XtSelfDrugStockCount, tx *gorm.DB) error {
  3076. err := tx.Create(&drug).Error
  3077. if err != nil {
  3078. tx.Rollback()
  3079. return err
  3080. }
  3081. return err
  3082. }
  3083. func GetSelfDrugWarehouseOutListById(warehouse_out_id int64, orgId int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseOutInfo, err error) {
  3084. err = tx.Where("warehouse_out_id = ? and org_id =? and status = 1", warehouse_out_id, orgId).Preload("BaseDrugLib", "status=1").Find(&info).Error
  3085. if err != gorm.ErrRecordNotFound {
  3086. if err != nil {
  3087. tx.Rollback()
  3088. return info, err
  3089. }
  3090. }
  3091. return info, err
  3092. }
  3093. func GetAllSelfDrugWarehouseOutList(ids []int64, patient_id int64, start_time int64, end_time int64, org_id int64) (outInfo []*models.XtSelfDrugWarehouseOutInfo, err error) {
  3094. db := XTReadDB().Model(&outInfo).Where("status =1")
  3095. if len(ids) > 0 {
  3096. db = db.Where("drug_id in(?)", ids)
  3097. }
  3098. if patient_id > 0 {
  3099. db = db.Where("patient_id = ?", patient_id)
  3100. }
  3101. if start_time > 0 {
  3102. db = db.Where("sys_record_time >=?", start_time)
  3103. }
  3104. if end_time > 0 {
  3105. db = db.Where("sys_record_time <=?", end_time)
  3106. }
  3107. if org_id > 0 {
  3108. db = db.Where("org_id =?", org_id)
  3109. }
  3110. err = db.Preload("BaseDrugLib", "status=1 and org_id = ?", org_id).Find(&outInfo).Error
  3111. return outInfo, err
  3112. }
  3113. func DeleteSelfWarehouseOut(id int64) (models.XtSelfDrugWarehouseOutInfo, error) {
  3114. outInfo := models.XtSelfDrugWarehouseOutInfo{}
  3115. err := XTWriteDB().Model(&outInfo).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3116. return outInfo, err
  3117. }
  3118. func GetSelfDrugWarehouseOutById(id int64) (outInfo []*models.XtSelfDrugWarehouseOutInfo, err error) {
  3119. err = XTReadDB().Where("warehouse_out_id = ? and status =1", id).Preload("BaseDrugLib", "status=1").Find(&outInfo).Error
  3120. return outInfo, err
  3121. }
  3122. func GetSelfDrugWarehouseOutOne(id int64) (models.XtSelfDrugWarehouseOut, error) {
  3123. out := models.XtSelfDrugWarehouseOut{}
  3124. err = XTReadDB().Where("id = ? and status =1", id).Find(&out).Error
  3125. return out, err
  3126. }
  3127. func GetSelfDrugQuery(user_org_id int64, ids []int64) (drug []*models.XtSelfDrugStockCount, total int64, err error) {
  3128. db := XTReadDB().Model(&drug).Where("status=1")
  3129. if len(ids) > 0 {
  3130. db = db.Where("drug_id in(?)", ids)
  3131. }
  3132. if user_org_id > 0 {
  3133. db = db.Where("user_org_id = ?", user_org_id)
  3134. }
  3135. err = db.Preload("BaseDrugLib", "org_id = ? and status =1", user_org_id).Find(&drug).Error
  3136. return drug, total, err
  3137. }
  3138. func GetSelfDrugWarehouseOutListByIdOne(warehouse_out_id int64, orgId int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseOutInfo, err error) {
  3139. err = tx.Where("warehouse_out_id = ? and org_id =? and status = 1", warehouse_out_id, orgId).Preload("BaseDrugLib", "status=1").Find(&info).Error
  3140. if err != gorm.ErrRecordNotFound {
  3141. if err != nil {
  3142. tx.Rollback()
  3143. return
  3144. }
  3145. }
  3146. return info, err
  3147. }
  3148. func GetSelfDrugWarehouseOutByLastId(id int64, tx *gorm.DB) (models.XtSelfDrugWarehouseOut, error) {
  3149. out := models.XtSelfDrugWarehouseOut{}
  3150. err := tx.Where("id = ? and status = 1", id).Find(&out).Error
  3151. if err != gorm.ErrRecordNotFound {
  3152. if err != nil {
  3153. tx.Rollback()
  3154. return out, err
  3155. }
  3156. }
  3157. return out, err
  3158. }
  3159. func GetSelfDrugAllStockInfo(patient_id int64, orgid int64, drugid int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3160. err = tx.Where("patient_id = ? and org_id = ? and status = 1 and drug_id = ? and is_check = 1", patient_id, orgid, drugid).Find(&info).Error
  3161. if err != gorm.ErrRecordNotFound {
  3162. if err != nil {
  3163. tx.Rollback()
  3164. return info, err
  3165. }
  3166. }
  3167. return info, err
  3168. }
  3169. func FindSelfBaseDrugLibRecord(org_id int64, id int64, tx *gorm.DB) (lib models.BaseDrugLib, err error) {
  3170. err = tx.Model(&models.BaseDrugLib{}).Where("id = ? AND org_id = ? AND status = 1", id, org_id).First(&lib).Error
  3171. if err != gorm.ErrRecordNotFound {
  3172. if err != nil {
  3173. tx.Rollback()
  3174. return lib, err
  3175. }
  3176. }
  3177. return lib, err
  3178. }
  3179. func GetSelfBaseDrugMedical(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
  3180. drug := models.XtBaseDrug{}
  3181. err := tx.Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
  3182. if err != gorm.ErrRecordNotFound {
  3183. if err != nil {
  3184. tx.Rollback()
  3185. return drug, err
  3186. }
  3187. }
  3188. return drug, err
  3189. }
  3190. func AddSelfDrugCount(drug_id int64, org_id int64, patient_id int64, out_count int64, tx *gorm.DB) error {
  3191. err := tx.Model(&models.XtSelfDrugStockCount{}).Where("patient_id = ? and status = 1 and user_org_id = ? and drug_id = ?", patient_id, org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", out_count)).Error
  3192. if err != nil {
  3193. tx.Rollback()
  3194. return err
  3195. }
  3196. err = tx.Model(&models.XtSelfDrugStockCount{}).Where("patient_id = ? and status = 1 and user_org_id = ? and drug_id = ?", patient_id, org_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", out_count)).Error
  3197. if err != nil {
  3198. tx.Rollback()
  3199. return err
  3200. }
  3201. return err
  3202. }
  3203. func UpdateSelfCheckDrugOut(out models.XtSelfDrugWarehouseOut, id int64, tx *gorm.DB) error {
  3204. err := tx.Model(&models.XtSelfDrugWarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": out.IsCheck}).Error
  3205. if err != nil {
  3206. tx.Rollback()
  3207. return err
  3208. }
  3209. err = tx.Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
  3210. if err != nil {
  3211. tx.Rollback()
  3212. return err
  3213. }
  3214. return err
  3215. }
  3216. func FindSelfLastDrugWarehousingInfoByID(drug_id int64, patient_id int64, tx *gorm.DB) (info models.XtSelfDrugWarehouseInfo, err error) {
  3217. err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) and patient_id = ? and is_check = 1", drug_id, patient_id).Order("ctime").First(&info).Error
  3218. if err != gorm.ErrRecordNotFound {
  3219. if err != nil {
  3220. tx.Rollback()
  3221. return info, err
  3222. }
  3223. }
  3224. return info, err
  3225. }
  3226. func ChangeSelfMaxNumber(id int64, count int64, tx *gorm.DB) error {
  3227. err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
  3228. if err != nil {
  3229. tx.Rollback()
  3230. return err
  3231. }
  3232. return err
  3233. }
  3234. func UpdateSelfMinNumber(id int64, count int64, tx *gorm.DB) error {
  3235. err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).Update(map[string]interface{}{"stock_min_number": count}).Error
  3236. if err != nil {
  3237. tx.Rollback()
  3238. return err
  3239. }
  3240. return err
  3241. }
  3242. func ChangeSelfMaxNumberOne(id int64, count int64, tx *gorm.DB) error {
  3243. err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).Updates(map[string]interface{}{"stock_max_number": count, "stock_min_number": 0}).Error
  3244. if err != nil {
  3245. tx.Rollback()
  3246. return err
  3247. }
  3248. return err
  3249. }
  3250. func UpDateSelfDrugWarehouseInfoByStock(info *models.XtSelfDrugWarehouseInfo, tx *gorm.DB) (err error) {
  3251. err = tx.Save(&info).Error
  3252. if err != nil {
  3253. tx.Rollback()
  3254. return err
  3255. }
  3256. return err
  3257. }
  3258. func FindSelfDrugWarehouseInfoFlushCount(drug_id int64, orgid int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3259. err = tx.Where("drug_id = ? and org_id = ? and status = 1 and is_check = 1", drug_id, orgid).Find(&info).Error
  3260. if err != nil {
  3261. tx.Rollback()
  3262. return info, err
  3263. }
  3264. return info, err
  3265. }
  3266. func GetSelfLastWarehouseOutInfoById(drugid int64, tx *gorm.DB) (models.XtSelfDrugWarehouseOutInfo, error) {
  3267. flow := models.XtSelfDrugWarehouseOutInfo{}
  3268. err := tx.Where("drug_id = ? and status = 1", drugid).Last(&flow).Error
  3269. if err != gorm.ErrRecordNotFound {
  3270. if err != nil {
  3271. tx.Rollback()
  3272. return flow, err
  3273. }
  3274. }
  3275. return flow, err
  3276. }
  3277. func UpdateSelfDrugWarehouseOutInfo(id int64, warehouse_info_id int64, org_id int64, over_count int64, drug_price float64, tx *gorm.DB) error {
  3278. err = tx.Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("id = ? and org_id = ? and status = 1", id, org_id).Update(map[string]interface{}{"warehouse_info_id": warehouse_info_id, "over_count": over_count, "price": drug_price, "retail_price": drug_price}).Error
  3279. if err != nil {
  3280. tx.Rollback()
  3281. return err
  3282. }
  3283. return err
  3284. }
  3285. func UpdateSelfCheckDrugOutInfoList(info models.XtSelfDrugWarehouseOutInfo, warehouse_out_id int64, tx *gorm.DB) error {
  3286. err := tx.Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", warehouse_out_id).Update(map[string]interface{}{"is_check": 2}).Error
  3287. if err != nil {
  3288. tx.Rollback()
  3289. return err
  3290. }
  3291. return err
  3292. }
  3293. func UpdateSelfDrugMaxNumber(count int64, id int64, tx *gorm.DB) error {
  3294. err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
  3295. if err != nil {
  3296. tx.Rollback()
  3297. return err
  3298. }
  3299. return err
  3300. }
  3301. func UpdateSelfDrugMinNumber(count int64, id int64, tx *gorm.DB) error {
  3302. err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
  3303. if err != nil {
  3304. tx.Rollback()
  3305. return err
  3306. }
  3307. return err
  3308. }
  3309. func ModifySelfReduceDrugInformation(id int64, count int64, orgid int64, tx *gorm.DB) error {
  3310. err = tx.Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", id, orgid).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", count)).Error
  3311. if err != nil {
  3312. tx.Rollback()
  3313. return err
  3314. }
  3315. return err
  3316. }
  3317. func DeleteSelfDrugOutFlow(id int64, orgid int64, tx *gorm.DB) error {
  3318. err := tx.Model(models.XtSelfDrugFlow{}).Where("warehouse_out_detail_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
  3319. if err != nil {
  3320. tx.Rollback()
  3321. return err
  3322. }
  3323. return err
  3324. }
  3325. func ReduceSelfDrugCount(drug_id int64, org_id int64, patient_id int64, out_count int64, tx *gorm.DB) error {
  3326. err := tx.Model(&models.XtSelfDrugStockCount{}).Where("patient_id = ? and status = 1 and user_org_id = ? and drug_id = ?", patient_id, org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", out_count)).Error
  3327. if err != nil {
  3328. tx.Rollback()
  3329. return err
  3330. }
  3331. err = tx.Model(&models.XtSelfDrugStockCount{}).Where("patient_id = ? and status = 1 and user_org_id = ? and drug_id = ?", patient_id, org_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count - ?", out_count)).Error
  3332. if err != nil {
  3333. tx.Rollback()
  3334. return err
  3335. }
  3336. return err
  3337. }
  3338. func UpdateSelfDrugStockCount(drug_id int64, org_id int64, patient_id int64, flush_count int64, tx *gorm.DB) error {
  3339. drug := models.XtSelfDrugStockCount{}
  3340. err := tx.Model(&drug).Where("drug_id = ? and user_org_id = ? and patient_id = ? and status = 1", drug_id, org_id, patient_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
  3341. if err != nil {
  3342. tx.Rollback()
  3343. return err
  3344. }
  3345. return err
  3346. }
  3347. func FindSelfDrugWarehouseInfoFlushCountByStorehouse(drug_id int64, orgid int64, patient_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3348. err = tx.Where("drug_id = ? and org_id = ? and status = 1 and is_check = 1 and patient_id =?", drug_id, orgid, patient_id).Find(&info).Error
  3349. if err != nil {
  3350. tx.Rollback()
  3351. return info, err
  3352. }
  3353. return info, err
  3354. }
  3355. func GetSelfWarehousingInfoByList(id int64, orgid int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3356. err = tx.Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
  3357. if err != nil {
  3358. tx.Rollback()
  3359. return info, err
  3360. }
  3361. return info, err
  3362. }
  3363. func GetSelfDrugWarehouseOutByWarehouseInfoId(warehouse_info_id int64, drug_id int64, orgid int64, tx *gorm.DB) (outInfo []*models.XtSelfDrugWarehouseOutInfo, err error) {
  3364. err = tx.Where("warehouse_info_id = ? and drug_id = ? and org_id = ? and is_check = 1 and status = 1", warehouse_info_id, drug_id, orgid).Find(&outInfo).Error
  3365. if err != gorm.ErrRecordNotFound {
  3366. if err != nil {
  3367. tx.Rollback()
  3368. return outInfo, err
  3369. }
  3370. }
  3371. return outInfo, err
  3372. }
  3373. func UpdateSelfWarehousingInfoFlow(id int64, orgid int64, tx *gorm.DB) error {
  3374. err := tx.Model(&models.XtSelfDrugFlow{}).Where("warehousing_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
  3375. if err != nil {
  3376. tx.Rollback()
  3377. return err
  3378. }
  3379. return err
  3380. }
  3381. func AddSelfDrugReturnWarehouseStockMaxNumber(count int64, id int64, tx *gorm.DB) error {
  3382. err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
  3383. if err != nil {
  3384. tx.Rollback()
  3385. return err
  3386. }
  3387. err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
  3388. if err != nil {
  3389. tx.Rollback()
  3390. return err
  3391. }
  3392. return err
  3393. }
  3394. func AddSelfDrugReturnWarehouseStockMinNumber(count int64, id int64, tx *gorm.DB) error {
  3395. err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", count)).Error
  3396. if err != nil {
  3397. tx.Rollback()
  3398. return err
  3399. }
  3400. err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
  3401. if err != nil {
  3402. tx.Rollback()
  3403. return err
  3404. }
  3405. return err
  3406. }
  3407. func ReduceSelfDrugStockCount(patient_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64, tx *gorm.DB) error {
  3408. err = tx.Model(&models.XtSelfDrugStockCount{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1", user_org_id, patient_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", waresing_count)).Error
  3409. if err != nil {
  3410. tx.Rollback()
  3411. return err
  3412. }
  3413. err = tx.Model(&models.XtSelfDrugStockCount{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1", user_org_id, patient_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
  3414. if err != nil {
  3415. tx.Rollback()
  3416. return err
  3417. }
  3418. return err
  3419. }
  3420. func ReturnSelfCheckWarehouseingInfo(id int64, orgid int64, tx *gorm.DB) error {
  3421. err := tx.Model(&models.XtSelfDrugWarehouse{}).Where("id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
  3422. if err != nil {
  3423. tx.Rollback()
  3424. return err
  3425. }
  3426. err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("warehousing_id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
  3427. if err != nil {
  3428. tx.Rollback()
  3429. return err
  3430. }
  3431. return err
  3432. }
  3433. func CheckSelfWarehousingInfo(id int64, orgid int64, checker int64, tx *gorm.DB) error {
  3434. err := tx.Model(&models.XtSelfDrugWarehouse{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"is_check": 1, "checker": checker}).Error
  3435. if err != nil {
  3436. tx.Rollback()
  3437. return err
  3438. }
  3439. return err
  3440. }
  3441. func GetSelfDrugFlow(drug_id int64, start_time int64, end_time int64, user_org_id int64, page int64, limit int64, patient_id int64) (flow []*models.XtSelfDrugFlow, total int64, err error) {
  3442. db := XTReadDB().Model(&flow).Where("status=1")
  3443. if drug_id > 0 {
  3444. db = db.Where("drug_id =?", drug_id)
  3445. }
  3446. if patient_id > 0 {
  3447. db = db.Where("patient_id = ?", patient_id)
  3448. }
  3449. if start_time > 0 {
  3450. db = db.Where("ctime>=?", start_time)
  3451. }
  3452. if end_time > 0 {
  3453. db = db.Where("etime <=?", end_time)
  3454. }
  3455. if user_org_id > 0 {
  3456. db = db.Where("user_org_id =?", user_org_id)
  3457. }
  3458. offset := (page - 1) * limit
  3459. err = db.Count(&total).Offset(offset).Limit(limit).Preload("BaseDrugLib", "status=1 and org_id = ?", user_org_id).Order("id desc").Find(&flow).Error
  3460. return flow, total, err
  3461. }
  3462. func GetSelfBasedrugByIdOne(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
  3463. lib := models.BaseDrugLib{}
  3464. err := XTReadDB().Where("id = ? and org_id =? and status=1", drug_id, user_org_id).Find(&lib).Error
  3465. return lib, err
  3466. }
  3467. func GetSelfDrugStockCountByPatientId(drug_id int64, patient_id int64, user_org_id int64) (models.XtSelfDrugStockCount, error) {
  3468. selfDrugStockCount := models.XtSelfDrugStockCount{}
  3469. err := XTReadDB().Where("drug_id = ? and patient_id = ? and user_org_id = ? and status =1", drug_id, patient_id, user_org_id).Find(&selfDrugStockCount).Error
  3470. return selfDrugStockCount, err
  3471. }
  3472. func GetSelfBasedrugById(drug_id int64, user_org_id int64, tx *gorm.DB) (models.BaseDrugLib, error) {
  3473. lib := models.BaseDrugLib{}
  3474. err := tx.Where("id = ? and org_id =? and status=1", drug_id, user_org_id).Find(&lib).Error
  3475. if err != gorm.ErrRecordNotFound {
  3476. if err != nil {
  3477. tx.Rollback()
  3478. return lib, err
  3479. }
  3480. }
  3481. return lib, err
  3482. }
  3483. func GetSelfDrugBatchNumberList(drug_id int64, start_time int64, end_time int64, user_org_id int64, page int64, limit int64, patient_id int64) (flow []*models.XtSelfDrugFlow, total int64, err error) {
  3484. db := XTReadDB().Model(&flow).Where("status=1 and consumable_type =1")
  3485. if drug_id > 0 {
  3486. db = db.Where("drug_id =?", drug_id)
  3487. }
  3488. if start_time > 0 {
  3489. db = db.Where("ctime>=?", start_time)
  3490. }
  3491. if end_time > 0 {
  3492. db = db.Where("etime <=?", end_time)
  3493. }
  3494. if user_org_id > 0 {
  3495. db = db.Where("user_org_id =?", user_org_id)
  3496. }
  3497. if patient_id > 0 {
  3498. db = db.Where("patient_id = ?", patient_id)
  3499. }
  3500. offset := (page - 1) * limit
  3501. err = db.Count(&total).Offset(offset).Limit(limit).Find(&flow).Error
  3502. return flow, total, err
  3503. }
  3504. func GetAllSelfDrugWarehouse(keyword string, start_time int64, end_time int64, check_type int64, orgId int64, page int64, limit int64, patient_id int64) (warehouse []*models.XtSelfDrugWarehouse, total int64, err error) {
  3505. db := XTReadDB().Model(&warehouse).Where("status=1")
  3506. likeKey := "%" + keyword + "%"
  3507. if len(keyword) > 0 {
  3508. db = db.Where("warehousing_order like ?", likeKey)
  3509. }
  3510. if start_time > 0 {
  3511. db = db.Where("operation_time>=?", start_time)
  3512. }
  3513. if end_time > 0 {
  3514. db = db.Where("operation_time<=?", end_time)
  3515. }
  3516. if check_type > 0 {
  3517. db = db.Where("is_check = ?", check_type)
  3518. }
  3519. if orgId > 0 {
  3520. db = db.Where("org_id = ?", orgId)
  3521. }
  3522. if patient_id > 0 {
  3523. db = db.Where("patient_id=?", patient_id)
  3524. }
  3525. offset := (page - 1) * limit
  3526. err = db.Count(&total).Offset(offset).Limit(limit).Order("operation_time desc").Find(&warehouse).Error
  3527. return warehouse, total, err
  3528. }
  3529. func DeleteSelfWarehouse(id int64) error {
  3530. err := XTWriteDB().Model(&models.XtSelfDrugWarehouse{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3531. err = XTWriteDB().Model(&models.XtSelfDrugWarehouseInfo{}).Where("warehousing_id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3532. return err
  3533. }
  3534. func GetAllSelfDrugWarehouseOut(start_time int64, end_time int64, org_id int64, page int64, limit int64, patient_id int64, keyword string, check_type int64) (out []*models.XtSelfDrugWarehouseOut, total int64, err error) {
  3535. db := XTReadDB().Model(&out).Where("status=1")
  3536. offset := (page - 1) * limit
  3537. likeKey := "%" + keyword + "%"
  3538. if len(keyword) > 0 {
  3539. db = db.Where("warehouse_out_order_number like ?", likeKey)
  3540. }
  3541. if start_time > 0 {
  3542. db = db.Where("operation_time>=?", start_time)
  3543. }
  3544. if end_time > 0 {
  3545. db = db.Where("operation_time<=?", end_time)
  3546. }
  3547. if org_id > 0 {
  3548. db = db.Where("org_id = ?", org_id)
  3549. }
  3550. if patient_id > 0 {
  3551. db = db.Where("patient_id = ?", patient_id)
  3552. }
  3553. if check_type > 0 {
  3554. db = db.Where("is_check=?", check_type)
  3555. }
  3556. err = db.Count(&total).Offset(offset).Limit(limit).Order("operation_time desc").Find(&out).Error
  3557. return out, total, err
  3558. }
  3559. func DeleteSelfWarehouseOutList(id int64) (models.XtSelfDrugWarehouseOut, error) {
  3560. warehouseOut := models.XtSelfDrugWarehouseOut{}
  3561. err := XTWriteDB().Model(&warehouseOut).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3562. err = XTWriteDB().Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3563. return warehouseOut, err
  3564. }
  3565. func FindSelfDrugWarehouseInfoList(drugid int64, orgid int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3566. err = tx.Where("drug_id = ? and org_id = ? and status =1 and is_check =1 and (stock_max_number>0 or stock_min_number>0)", drugid, orgid).Find(&info).Error
  3567. if err != gorm.ErrRecordNotFound {
  3568. if err != nil {
  3569. tx.Rollback()
  3570. return info, err
  3571. }
  3572. }
  3573. return info, err
  3574. }
  3575. func GetSelfDrugWarehouseInfoByInfo(advice_id int64, patient_id int64, advice_date int64, user_org_id int64, drug_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3576. err = tx.Where("advice_id = ? and patient_id = ? and record_date = ? and org_id = ? and status=1 and drug_id = ?", advice_id, patient_id, advice_date, user_org_id, drug_id).Find(&info).Error
  3577. return info, err
  3578. }
  3579. func CreateSelfDrugWarehouseInfo(info *models.XtSelfDrugWarehouseInfo, tx *gorm.DB) error {
  3580. err := tx.Create(&info).Error
  3581. if err != nil {
  3582. tx.Rollback()
  3583. return err
  3584. }
  3585. return err
  3586. }
  3587. func GetLastSelfDrugWarehouseInfoById(org_id int64, tx *gorm.DB) (models.XtSelfDrugWarehouseInfo, error) {
  3588. info := models.XtSelfDrugWarehouseInfo{}
  3589. err := tx.Where("org_id = ? and status =1", org_id).Last(&info).Error
  3590. return info, err
  3591. }
  3592. func GetSelfDrugWarehouseOutDrugFlow(patient_id int64, drug_id int64, user_org_id int64, advice_id int64, tx *gorm.DB) (flow []*models.XtSelfDrugFlow, err error) {
  3593. err = tx.Where("patient_id = ? and drug_id = ? and user_org_id =? and status=1 and consumable_type =20 and advice_id =?", patient_id, drug_id, user_org_id, advice_id).Find(&flow).Error
  3594. if err != gorm.ErrRecordNotFound {
  3595. if err != nil {
  3596. tx.Rollback()
  3597. return
  3598. }
  3599. }
  3600. return flow, err
  3601. }
  3602. func GetSelfDrugLastWarehouseOutTwety(orgid int64, record_date int64, tx *gorm.DB, is_sys int64) (models.XtSelfDrugWarehouseOut, error) {
  3603. out := models.XtSelfDrugWarehouseOut{}
  3604. err := tx.Where("org_id = ? and status = 1 and warehouse_out_time = ? and is_sys =?", orgid, record_date, is_sys).Find(&out).Error
  3605. if err != gorm.ErrRecordNotFound {
  3606. if err != nil {
  3607. tx.Rollback()
  3608. return out, err
  3609. }
  3610. }
  3611. return out, err
  3612. }
  3613. func GetSelfHisPrescriptionAdviceByID(id int64, tx *gorm.DB) (advices []*models.HisDoctorAdviceInfo, err error) {
  3614. err = tx.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  3615. if err != gorm.ErrRecordNotFound {
  3616. if err != nil {
  3617. tx.Rollback()
  3618. return advices, err
  3619. }
  3620. }
  3621. return
  3622. }
  3623. func GetSelfNewDrugWarehouseOutInfoSix(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64, warehouse_info_id int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
  3624. info := models.DrugWarehouseOutInfo{}
  3625. var err error
  3626. err = tx.Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ? and status = 1 and advice_id = ? and warehouse_info_id = ?", drugid, patient_id, record_date, org_id, advice_id, warehouse_info_id).Find(&info).Error
  3627. if err != gorm.ErrRecordNotFound {
  3628. if err != nil {
  3629. tx.Rollback()
  3630. return info, err
  3631. }
  3632. }
  3633. return info, err
  3634. }
  3635. func UpdateSelfDrugWarehouseOutInfoTen(patient_id int64, sys_record_time int64, advice_id int64, tx *gorm.DB) error {
  3636. err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("patient_id = ? and sys_record_time = ? and status=1 and advice_id = ?", patient_id, sys_record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
  3637. if err != nil {
  3638. tx.Rollback()
  3639. return err
  3640. }
  3641. return err
  3642. }
  3643. func GetSelfWarehouseInfoByWarehouseInfoTwo(drug_id int64, patient_id int64, org_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
  3644. err = tx.Where("drug_id =? and patient_id =? and status=1 and org_id =? and is_check=1", drug_id, patient_id, org_id).Find(&info).Error
  3645. if err != gorm.ErrRecordNotFound {
  3646. if err != nil {
  3647. tx.Rollback()
  3648. return info, err
  3649. }
  3650. }
  3651. return info, err
  3652. }
  3653. func GetSelfDrugWarehouseOutDetailByPatientId(patient_id int64, page int64, limit int64, user_org_id int64) (out []*models.XtSelfDrugStockCount, total int64, err error) {
  3654. db := XTReadDB().Model(&out).Where("status=1")
  3655. if patient_id > 0 {
  3656. db = db.Where("patient_id = ?", patient_id)
  3657. }
  3658. if user_org_id > 0 {
  3659. db = db.Where("user_org_id = ?", user_org_id)
  3660. }
  3661. offset := (page - 1) * limit
  3662. err = db.Count(&total).Offset(offset).Limit(limit).Preload("BaseDrugLib", "status=1 and org_id = ?", user_org_id).Find(&out).Error
  3663. return out, total, err
  3664. }
  3665. func GetSelfBasedrugByIdTwo(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
  3666. lib := models.BaseDrugLib{}
  3667. err := XTReadDB().Where("id = ? and org_id =? and status=1", drug_id, user_org_id).Find(&lib).Error
  3668. return lib, err
  3669. }
  3670. //自动退库分装方法
  3671. func SelfDrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) error {
  3672. //查询该批次病人该药品出库数据
  3673. info, _ := GetSelfDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  3674. list, _ := GetSelfDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  3675. //退库
  3676. drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3677. //如果剩余数量 + 退库数量 < 总入库数量
  3678. if len(list) > 0 {
  3679. for _, its := range list {
  3680. //查询该批次病人该药品出库数据
  3681. infos, _ := GetSelfDrugAutoWarehouseOutTen(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID, its.WarehouseInfoId)
  3682. //查询该药品出库批次总入库数量
  3683. druginfo, _ := GetSelfDrugInfoSix(its.WarehouseInfoId, infos.OrgId)
  3684. var out_count int64 //该批次出库库存
  3685. var sum_count int64 //该批次总库存
  3686. var over_count int64 //剩余数量
  3687. if druginfo.MaxUnit != druginfo.MinUnit {
  3688. over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
  3689. }
  3690. if druginfo.MaxUnit == druginfo.MinUnit {
  3691. over_count = druginfo.StockMaxNumber + druginfo.StockMinNumber
  3692. }
  3693. if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3694. out_count = infos.Count * drug.MinNumber
  3695. }
  3696. if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3697. out_count = infos.Count
  3698. }
  3699. if infos.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3700. out_count = infos.Count
  3701. }
  3702. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3703. sum_count = druginfo.WarehousingCount * drug.MinNumber
  3704. }
  3705. if druginfo.MaxUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3706. sum_count = druginfo.WarehousingCount
  3707. }
  3708. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3709. sum_count = druginfo.WarehousingCount
  3710. }
  3711. if (over_count + out_count) <= sum_count {
  3712. if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3713. //退库
  3714. warehouseInfo := models.XtSelfDrugWarehouseInfo{
  3715. StockMinNumber: its.Count,
  3716. }
  3717. UpdateSelfDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
  3718. //增加退库数量
  3719. AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count)
  3720. //出库数量减少
  3721. UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count)
  3722. }
  3723. if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3724. warehouseInfo := models.XtSelfDrugWarehouseInfo{
  3725. StockMaxNumber: its.Count,
  3726. }
  3727. UpdateSelfDrugWarehouseTwo(its.WarehouseInfoId, warehouseInfo)
  3728. //增加退库数量
  3729. AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
  3730. //出库数量减少
  3731. UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count*drug.MinNumber)
  3732. }
  3733. if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3734. warehouseInfo := models.XtSelfDrugWarehouseInfo{
  3735. StockMaxNumber: its.Count,
  3736. }
  3737. UpdateSelfDrugWarehouseTwo(its.WarehouseInfoId, warehouseInfo)
  3738. //增加退库数量
  3739. AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
  3740. //出库数量减少
  3741. UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count*drug.MinNumber)
  3742. }
  3743. }
  3744. }
  3745. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  3746. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3747. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3748. //查询剩余库存
  3749. stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
  3750. var sum_count int64
  3751. for _, its := range stockInfo {
  3752. if its.MaxUnit == drug.MaxUnit {
  3753. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  3754. }
  3755. sum_count += its.StockMaxNumber + its.StockMinNumber
  3756. }
  3757. var count_one int64
  3758. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3759. count_one = prescribingNumber * drug.MinNumber
  3760. }
  3761. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3762. count_one = prescribingNumber
  3763. }
  3764. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3765. count_one = prescribingNumber * drug.MinNumber
  3766. }
  3767. flow := models.XtSelfDrugFlow{
  3768. WarehousingId: info.WarehouseInfoId,
  3769. DrugId: info.DrugId,
  3770. Number: "",
  3771. BatchNumber: info.BatchNumber,
  3772. Count: count_one,
  3773. UserOrgId: advice.UserOrgId,
  3774. PatientId: advice.PatientId,
  3775. SystemTime: info.SysRecordTime,
  3776. ConsumableType: 7,
  3777. IsSys: 0,
  3778. WarehousingOrder: "",
  3779. WarehouseOutId: 0,
  3780. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3781. IsEdit: 0,
  3782. CancelStockId: 0,
  3783. CancelOrderNumber: "",
  3784. Manufacturer: info.Manufacturer,
  3785. Dealer: info.Dealer,
  3786. Creator: creater,
  3787. UpdateCreator: 0,
  3788. Status: 1,
  3789. Ctime: info.SysRecordTime,
  3790. Mtime: 0,
  3791. Price: info.Price,
  3792. WarehousingDetailId: info.WarehouseInfoId,
  3793. WarehouseOutDetailId: 0,
  3794. CancelOutDetailId: 0,
  3795. ExpireDate: info.ExpiryDate,
  3796. ProductDate: info.ProductDate,
  3797. MaxUnit: drug.MinUnit,
  3798. MinUnit: "",
  3799. AdviceId: info.AdviceId,
  3800. StorehouseId: 0,
  3801. OverCount: sum_count,
  3802. OperateTime: time.Now().Unix(),
  3803. }
  3804. CreateSelfDrugFlowTwo(flow)
  3805. //删除出库记录
  3806. UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  3807. //删除流水
  3808. UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  3809. }
  3810. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3811. //查询剩余库存
  3812. stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
  3813. var sum_count int64
  3814. for _, its := range stockInfo {
  3815. if its.MaxUnit == drug.MaxUnit {
  3816. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  3817. }
  3818. sum_count += its.StockMaxNumber + its.StockMinNumber
  3819. }
  3820. var count_one int64
  3821. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3822. count_one = prescribingNumber * drug.MinNumber
  3823. }
  3824. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3825. count_one = prescribingNumber
  3826. }
  3827. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3828. count_one = prescribingNumber * drug.MinNumber
  3829. }
  3830. flow := models.XtSelfDrugFlow{
  3831. WarehousingId: info.WarehouseInfoId,
  3832. DrugId: info.DrugId,
  3833. Number: "",
  3834. BatchNumber: info.BatchNumber,
  3835. Count: count_one,
  3836. UserOrgId: advice.UserOrgId,
  3837. PatientId: advice.PatientId,
  3838. SystemTime: info.SysRecordTime,
  3839. ConsumableType: 7,
  3840. IsSys: 0,
  3841. WarehousingOrder: "",
  3842. WarehouseOutId: 0,
  3843. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3844. IsEdit: 0,
  3845. CancelStockId: 0,
  3846. CancelOrderNumber: "",
  3847. Manufacturer: info.Manufacturer,
  3848. Dealer: info.Dealer,
  3849. Creator: creater,
  3850. UpdateCreator: 0,
  3851. Status: 1,
  3852. Ctime: info.SysRecordTime,
  3853. Mtime: 0,
  3854. Price: info.Price,
  3855. WarehousingDetailId: info.WarehouseInfoId,
  3856. WarehouseOutDetailId: 0,
  3857. CancelOutDetailId: 0,
  3858. ExpireDate: info.ExpiryDate,
  3859. ProductDate: info.ProductDate,
  3860. MaxUnit: drug.MinUnit,
  3861. MinUnit: "",
  3862. AdviceId: info.AdviceId,
  3863. StorehouseId: 0,
  3864. OverCount: sum_count,
  3865. OperateTime: time.Now().Unix(),
  3866. }
  3867. CreateSelfDrugFlowTwo(flow)
  3868. //删除出库记录
  3869. UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  3870. //删除流水
  3871. UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  3872. }
  3873. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3874. //查询剩余库存
  3875. stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
  3876. var sum_count int64
  3877. for _, its := range stockInfo {
  3878. if its.MaxUnit == drug.MaxUnit {
  3879. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  3880. }
  3881. sum_count += its.StockMaxNumber + its.StockMinNumber
  3882. }
  3883. flow := models.XtSelfDrugFlow{
  3884. WarehousingId: info.WarehouseInfoId,
  3885. DrugId: info.DrugId,
  3886. Number: "",
  3887. BatchNumber: info.BatchNumber,
  3888. Count: prescribingNumber,
  3889. UserOrgId: advice.UserOrgId,
  3890. PatientId: advice.PatientId,
  3891. SystemTime: info.SysRecordTime,
  3892. ConsumableType: 7,
  3893. IsSys: 0,
  3894. WarehousingOrder: "",
  3895. WarehouseOutId: 0,
  3896. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3897. IsEdit: 0,
  3898. CancelStockId: 0,
  3899. CancelOrderNumber: "",
  3900. Manufacturer: info.Manufacturer,
  3901. Dealer: info.Dealer,
  3902. Creator: creater,
  3903. UpdateCreator: 0,
  3904. Status: 1,
  3905. Ctime: info.SysRecordTime,
  3906. Mtime: 0,
  3907. Price: info.Price,
  3908. WarehousingDetailId: info.WarehouseInfoId,
  3909. WarehouseOutDetailId: 0,
  3910. CancelOutDetailId: 0,
  3911. ExpireDate: info.ExpiryDate,
  3912. ProductDate: info.ProductDate,
  3913. MaxUnit: advice.PrescribingNumberUnit,
  3914. MinUnit: "",
  3915. AdviceId: info.AdviceId,
  3916. StorehouseId: 0,
  3917. OverCount: sum_count,
  3918. OperateTime: time.Now().Unix(),
  3919. }
  3920. CreateSelfDrugFlowTwo(flow)
  3921. //删除出库记录
  3922. UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  3923. //删除流水
  3924. UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  3925. }
  3926. //更新字典里面的库存
  3927. stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
  3928. //查询改药品信息
  3929. medical, _ := GetBaseDrugMedical(advice.DrugId)
  3930. var sum_count_one int64
  3931. for _, its := range stockInfo {
  3932. if its.MaxUnit == medical.MaxUnit {
  3933. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  3934. }
  3935. sum_count_one += its.StockMaxNumber + its.StockMinNumber
  3936. }
  3937. //更新库存
  3938. UpdateSumDrugTwo(advice.UserOrgId, advice.PatientId, advice.DrugId, sum_count_one)
  3939. }
  3940. return err
  3941. }
  3942. func SelfDrugAutoAddCancelInfoOne(advice *models.DoctorAdvice, creater int64) error {
  3943. //查询该批次病人该药品出库数据
  3944. info, _ := GetSelfDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  3945. list, _ := GetSelfDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  3946. //退库
  3947. drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3948. //如果剩余数量 + 退库数量 < 总入库数量
  3949. if len(list) > 0 {
  3950. for _, its := range list {
  3951. //查询该批次病人该药品出库数据
  3952. infos, _ := GetSelfDrugAutoWarehouseOutTen(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID, its.WarehouseInfoId)
  3953. //查询该药品出库批次总入库数量
  3954. druginfo, _ := GetSelfDrugInfoSix(its.WarehouseInfoId, infos.OrgId)
  3955. var out_count int64 //该批次出库库存
  3956. var sum_count int64 //该批次总库存
  3957. var over_count int64 //剩余数量
  3958. if druginfo.MaxUnit != druginfo.MinUnit {
  3959. over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
  3960. }
  3961. if druginfo.MaxUnit == druginfo.MinUnit {
  3962. over_count = druginfo.StockMaxNumber + druginfo.StockMinNumber
  3963. }
  3964. if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3965. out_count = infos.Count * drug.MinNumber
  3966. }
  3967. if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3968. out_count = infos.Count
  3969. }
  3970. if infos.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3971. out_count = infos.Count
  3972. }
  3973. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3974. sum_count = druginfo.WarehousingCount * drug.MinNumber
  3975. }
  3976. if druginfo.MaxUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3977. sum_count = druginfo.WarehousingCount
  3978. }
  3979. if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3980. sum_count = druginfo.WarehousingCount
  3981. }
  3982. fmt.Println("over_count-----------", over_count)
  3983. fmt.Println("out_count-----------", out_count)
  3984. fmt.Println("sum_count-----------", sum_count)
  3985. fmt.Println("its.count-------------", its.CountUnit)
  3986. fmt.Println("drug.MaxUnit-------------", drug.MaxUnit)
  3987. fmt.Println("drug.MinUnit-------------", drug.MinUnit)
  3988. if (over_count + out_count) <= sum_count {
  3989. if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3990. //退库
  3991. warehouseInfo := models.XtSelfDrugWarehouseInfo{
  3992. StockMinNumber: its.Count,
  3993. }
  3994. UpdateSelfDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
  3995. //增加退库数量
  3996. AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count)
  3997. //出库数量减少
  3998. UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count)
  3999. }
  4000. if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4001. warehouseInfo := models.XtSelfDrugWarehouseInfo{
  4002. StockMaxNumber: its.Count,
  4003. }
  4004. UpdateSelfDrugWarehouseTwo(its.WarehouseInfoId, warehouseInfo)
  4005. //增加退库数量
  4006. AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
  4007. //出库数量减少
  4008. UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count*drug.MinNumber)
  4009. }
  4010. if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4011. warehouseInfo := models.XtSelfDrugWarehouseInfo{
  4012. StockMaxNumber: its.Count,
  4013. }
  4014. UpdateSelfDrugWarehouseTwo(its.WarehouseInfoId, warehouseInfo)
  4015. //增加退库数量
  4016. AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
  4017. //出库数量减少
  4018. UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count*drug.MinNumber)
  4019. }
  4020. }
  4021. }
  4022. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  4023. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4024. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4025. //查询剩余库存
  4026. stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
  4027. var sum_count int64
  4028. for _, its := range stockInfo {
  4029. if its.MaxUnit == drug.MaxUnit {
  4030. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  4031. }
  4032. sum_count += its.StockMaxNumber + its.StockMinNumber
  4033. }
  4034. var count_one int64
  4035. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4036. count_one = prescribingNumber * drug.MinNumber
  4037. }
  4038. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4039. count_one = prescribingNumber
  4040. }
  4041. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4042. count_one = prescribingNumber * drug.MinNumber
  4043. }
  4044. flow := models.XtSelfDrugFlow{
  4045. WarehousingId: info.WarehouseInfoId,
  4046. DrugId: info.DrugId,
  4047. Number: "",
  4048. BatchNumber: info.BatchNumber,
  4049. Count: count_one,
  4050. UserOrgId: advice.UserOrgId,
  4051. PatientId: advice.PatientId,
  4052. SystemTime: info.SysRecordTime,
  4053. ConsumableType: 7,
  4054. IsSys: 0,
  4055. WarehousingOrder: "",
  4056. WarehouseOutId: 0,
  4057. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4058. IsEdit: 0,
  4059. CancelStockId: 0,
  4060. CancelOrderNumber: "",
  4061. Manufacturer: info.Manufacturer,
  4062. Dealer: info.Dealer,
  4063. Creator: creater,
  4064. UpdateCreator: 0,
  4065. Status: 1,
  4066. Ctime: info.SysRecordTime,
  4067. Mtime: 0,
  4068. Price: info.Price,
  4069. WarehousingDetailId: info.WarehouseInfoId,
  4070. WarehouseOutDetailId: 0,
  4071. CancelOutDetailId: 0,
  4072. ExpireDate: info.ExpiryDate,
  4073. ProductDate: info.ProductDate,
  4074. MaxUnit: drug.MinUnit,
  4075. MinUnit: "",
  4076. AdviceId: info.AdviceId,
  4077. StorehouseId: 0,
  4078. OverCount: sum_count,
  4079. OperateTime: time.Now().Unix(),
  4080. }
  4081. CreateSelfDrugFlowTwo(flow)
  4082. //删除出库记录
  4083. UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  4084. //删除流水
  4085. UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  4086. }
  4087. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4088. //查询剩余库存
  4089. stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
  4090. var sum_count int64
  4091. for _, its := range stockInfo {
  4092. if its.MaxUnit == drug.MaxUnit {
  4093. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  4094. }
  4095. sum_count += its.StockMaxNumber + its.StockMinNumber
  4096. }
  4097. var count_one int64
  4098. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4099. count_one = prescribingNumber * drug.MinNumber
  4100. }
  4101. if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4102. count_one = prescribingNumber
  4103. }
  4104. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4105. count_one = prescribingNumber * drug.MinNumber
  4106. }
  4107. flow := models.XtSelfDrugFlow{
  4108. WarehousingId: info.WarehouseInfoId,
  4109. DrugId: info.DrugId,
  4110. Number: "",
  4111. BatchNumber: info.BatchNumber,
  4112. Count: count_one,
  4113. UserOrgId: advice.UserOrgId,
  4114. PatientId: advice.PatientId,
  4115. SystemTime: info.SysRecordTime,
  4116. ConsumableType: 7,
  4117. IsSys: 0,
  4118. WarehousingOrder: "",
  4119. WarehouseOutId: 0,
  4120. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4121. IsEdit: 0,
  4122. CancelStockId: 0,
  4123. CancelOrderNumber: "",
  4124. Manufacturer: info.Manufacturer,
  4125. Dealer: info.Dealer,
  4126. Creator: creater,
  4127. UpdateCreator: 0,
  4128. Status: 1,
  4129. Ctime: info.SysRecordTime,
  4130. Mtime: 0,
  4131. Price: info.Price,
  4132. WarehousingDetailId: info.WarehouseInfoId,
  4133. WarehouseOutDetailId: 0,
  4134. CancelOutDetailId: 0,
  4135. ExpireDate: info.ExpiryDate,
  4136. ProductDate: info.ProductDate,
  4137. MaxUnit: drug.MinUnit,
  4138. MinUnit: "",
  4139. AdviceId: info.AdviceId,
  4140. StorehouseId: 0,
  4141. OverCount: sum_count,
  4142. OperateTime: time.Now().Unix(),
  4143. }
  4144. CreateSelfDrugFlowTwo(flow)
  4145. //删除出库记录
  4146. UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  4147. //删除流水
  4148. UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  4149. }
  4150. if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4151. //查询剩余库存
  4152. stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
  4153. var sum_count int64
  4154. for _, its := range stockInfo {
  4155. if its.MaxUnit == drug.MaxUnit {
  4156. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  4157. }
  4158. sum_count += its.StockMaxNumber + its.StockMinNumber
  4159. }
  4160. flow := models.XtSelfDrugFlow{
  4161. WarehousingId: info.WarehouseInfoId,
  4162. DrugId: info.DrugId,
  4163. Number: "",
  4164. BatchNumber: info.BatchNumber,
  4165. Count: prescribingNumber,
  4166. UserOrgId: advice.UserOrgId,
  4167. PatientId: advice.PatientId,
  4168. SystemTime: info.SysRecordTime,
  4169. ConsumableType: 7,
  4170. IsSys: 0,
  4171. WarehousingOrder: "",
  4172. WarehouseOutId: 0,
  4173. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4174. IsEdit: 0,
  4175. CancelStockId: 0,
  4176. CancelOrderNumber: "",
  4177. Manufacturer: info.Manufacturer,
  4178. Dealer: info.Dealer,
  4179. Creator: creater,
  4180. UpdateCreator: 0,
  4181. Status: 1,
  4182. Ctime: info.SysRecordTime,
  4183. Mtime: 0,
  4184. Price: info.Price,
  4185. WarehousingDetailId: info.WarehouseInfoId,
  4186. WarehouseOutDetailId: 0,
  4187. CancelOutDetailId: 0,
  4188. ExpireDate: info.ExpiryDate,
  4189. ProductDate: info.ProductDate,
  4190. MaxUnit: advice.PrescribingNumberUnit,
  4191. MinUnit: "",
  4192. AdviceId: info.AdviceId,
  4193. StorehouseId: 0,
  4194. OverCount: sum_count,
  4195. OperateTime: time.Now().Unix(),
  4196. }
  4197. CreateSelfDrugFlowTwo(flow)
  4198. //删除出库记录
  4199. UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
  4200. //删除流水
  4201. UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  4202. }
  4203. //更新字典里面的库存
  4204. stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
  4205. //查询改药品信息
  4206. medical, _ := GetBaseDrugMedical(advice.DrugId)
  4207. var sum_count_one int64
  4208. for _, its := range stockInfo {
  4209. if its.MaxUnit == medical.MaxUnit {
  4210. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  4211. }
  4212. sum_count_one += its.StockMaxNumber + its.StockMinNumber
  4213. }
  4214. //更新库存
  4215. UpdateSumDrugTwo(advice.UserOrgId, advice.PatientId, advice.DrugId, sum_count_one)
  4216. }
  4217. return err
  4218. }
  4219. func GetDrugInventoryRecordList(limit int64, page int64, keyword string, storehouse_id int64, startTime int64, endTime int64, orgId int64) (list []*models.XtDrugStockInventoryList, total int64, err error) {
  4220. likeKey := "%" + keyword + "%"
  4221. offset := (page - 1) * limit
  4222. db := XTReadDB().Model(&list).Where("status=1")
  4223. if len(keyword) > 0 {
  4224. db = db.Where("drug_name like ?", likeKey)
  4225. }
  4226. if storehouse_id > 0 {
  4227. db = db.Where("storehouse_id = ?", storehouse_id)
  4228. }
  4229. if startTime > 0 {
  4230. db = db.Where("record_date>=?", startTime)
  4231. }
  4232. if endTime > 0 {
  4233. db = db.Where("record_date<=?", endTime)
  4234. }
  4235. if orgId > 0 {
  4236. db = db.Where("user_org_id =?", orgId)
  4237. }
  4238. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&list).Error
  4239. return list, total, err
  4240. }
  4241. func GetDrugInventoryRecordPrintList(limit int64, page int64, keyword string, storehouse_id int64, orgId int64, startTime int64, endTime int64, idSplit []string) (list []*models.XtDrugStockInventoryList, total int64, err error) {
  4242. offset := (page - 1) * limit
  4243. likeKey := "%" + keyword + "%"
  4244. db := XTReadDB().Model(&list).Where("status =1")
  4245. if len(keyword) > 0 {
  4246. db = db.Where("drug_name like ?", likeKey)
  4247. }
  4248. if storehouse_id > 0 {
  4249. db = db.Where("storehouse_id = ?", storehouse_id)
  4250. }
  4251. if orgId > 0 {
  4252. db = db.Where("user_org_id = ?", orgId)
  4253. }
  4254. if startTime > 0 {
  4255. db = db.Where("record_date>=?", startTime)
  4256. }
  4257. if endTime > 0 {
  4258. db = db.Where("record_date<=?", endTime)
  4259. }
  4260. if len(idSplit) > 0 {
  4261. db = db.Where("id in(?)", idSplit)
  4262. }
  4263. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&list).Error
  4264. return list, total, err
  4265. }
  4266. func GetDrugWarehosueInfoList(org_id int64, start_time int64, end_time int64) (flow []*models.XtDrugFlowList, err error) {
  4267. db := XTReadDB().Model(&flow).Where("status=1 and (consumable_type=1 or consumable_type =10)")
  4268. if org_id > 0 {
  4269. db = db.Where("user_org_id = ?", org_id)
  4270. }
  4271. if start_time > 0 {
  4272. db = db.Where("ctime >= ?", start_time)
  4273. }
  4274. if end_time > 0 {
  4275. db = db.Where("ctime<=?", end_time)
  4276. }
  4277. err = db.Find(&flow).Error
  4278. return flow, err
  4279. }
  4280. func GetDrugWarhouseHouseOutInfo(org_id int64, start_time int64, end_time int64) (flow []*models.XtDrugFlowList, err error) {
  4281. db := XTReadDB().Model(&flow).Where("status=1 and (consumable_type=2 or consumable_type=3 or consumable_type=11)")
  4282. if org_id > 0 {
  4283. db = db.Where("user_org_id = ?", org_id)
  4284. }
  4285. if start_time > 0 {
  4286. db = db.Where("ctime >= ?", start_time)
  4287. }
  4288. if end_time > 0 {
  4289. db = db.Where("ctime<=?", end_time)
  4290. }
  4291. err = db.Find(&flow).Error
  4292. return flow, err
  4293. }
  4294. func GetDrugWarehouseCancelOutInfo(org_id int64, start_time int64, end_time int64) (flow []*models.XtDrugFlowList, err error) {
  4295. db := XTReadDB().Model(&flow).Where("status=1 and (consumable_type= 7)")
  4296. if org_id > 0 {
  4297. db = db.Where("user_org_id = ?", org_id)
  4298. }
  4299. if start_time > 0 {
  4300. db = db.Where("ctime >= ?", start_time)
  4301. }
  4302. if end_time > 0 {
  4303. db = db.Where("ctime<=?", end_time)
  4304. }
  4305. err = db.Find(&flow).Error
  4306. return flow, err
  4307. }
  4308. func GetDrugMonthWarehouseInfo(org_id int64, start_time int64) (flow []*models.XtDrugFlowList, err error) {
  4309. db := XTReadDB().Model(&flow).Where("status=1 and (consumable_type=1 or consumable_type=10)")
  4310. if org_id > 0 {
  4311. db = db.Where("user_org_id = ?", org_id)
  4312. }
  4313. if start_time > 0 {
  4314. db = db.Where("ctime < ?", start_time)
  4315. }
  4316. err = db.Find(&flow).Error
  4317. return flow, err
  4318. }
  4319. func GetDrugMonthWarehouseOutInfo(org_id int64, start_time int64) (flow []*models.XtDrugFlowList, err error) {
  4320. db := XTReadDB().Model(&flow).Where("status=1 and (consumable_type=2 or consumable_type=3 or consumable_type=11)")
  4321. if org_id > 0 {
  4322. db = db.Where("user_org_id = ?", org_id)
  4323. }
  4324. if start_time > 0 {
  4325. db = db.Where("ctime < ?", start_time)
  4326. }
  4327. err = db.Find(&flow).Error
  4328. return flow, err
  4329. }
  4330. func GetDrugMonthCancelOutInfo(org_id int64, start_time int64) (flow []*models.XtDrugFlowList, err error) {
  4331. db := XTReadDB().Model(&flow).Where("status=1 and (consumable_type=7)")
  4332. if org_id > 0 {
  4333. db = db.Where("user_org_id = ?", org_id)
  4334. }
  4335. if start_time > 0 {
  4336. db = db.Where("ctime < ?", start_time)
  4337. }
  4338. err = db.Find(&flow).Error
  4339. return flow, err
  4340. }
  4341. func ModifyDrugCodeWarehosueInfo(id int64, drug_code string) (models.XtDrugWarehouseInfo, error) {
  4342. drugWarehouseInfo := models.XtDrugWarehouseInfo{}
  4343. err := XTWriteDB().Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status=1", id).Update(map[string]interface{}{"drug_code": drug_code}).Error
  4344. return drugWarehouseInfo, err
  4345. }
  4346. func GetAllDrugInfoList(drug_id int64, user_org_id int64) (info []*models.XtDrugWarehouseInfo, err error) {
  4347. err = XTReadDB().Where("drug_id = ? and org_id = ? and status =1 and is_check =1", drug_id, user_org_id).Find(&info).Find(&info).Error
  4348. return info, err
  4349. }
  4350. func GetHisDocInfoList(drug_id int64, user_org_id int64) (info []*models.HisDoctorAdviceInfo, err error) {
  4351. err = XTReadDB().Where("drug_id = ? and user_org_id = ? and status=1", drug_id, user_org_id).Find(&info).Error
  4352. return info, err
  4353. }