self_drug_service.go 187KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401
  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 GetDrugWarehosueInfoById(drug_id int64, org_id int64) (drugInfo []*models.XtDrugWarehouseInfo, err error) {
  108. err = XTReadDB().Where("drug_id = ? and org_id = ? and status =1", drug_id, org_id).Find(&drugInfo).Error
  109. return drugInfo, err
  110. }
  111. func GetBaseDrugMedicalOne(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
  112. drug := models.XtBaseDrug{}
  113. err := tx.Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
  114. if err != gorm.ErrRecordNotFound {
  115. if err != nil {
  116. tx.Rollback()
  117. return drug, err
  118. }
  119. }
  120. return drug, err
  121. }
  122. func GetNewBaseDrugMedical(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. }