self_drug_api_congtroller.go 202KB

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