1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "reflect"
- "strconv"
- "strings"
- "time"
- )
-
- type SelfDrugApiController struct {
- BaseAuthAPIController
- }
-
- func SelfDrugRouters() {
-
- beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
- beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
- beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
- beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
- beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
- beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
- beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
- beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
- beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
- beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
- beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
- beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
- beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
- beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
- beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
- beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
- beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
- beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
- beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
- beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
- beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
- beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
- beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
- beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
- beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
- beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
- beego.Router("/api/drug/getallmedicallist", &SelfDrugApiController{}, "Get:GetAllMedicalList")
- beego.Router("/api/drug/getstandname", &SelfDrugApiController{}, "Get:GetStandName")
- beego.Router("/api/drug/getrullerlist", &SelfDrugApiController{}, "Get:GetRullerList")
- beego.Router("/api/drug/deleteDrugNamebyid", &SelfDrugApiController{}, "Get:DeleteDrugNameById")
- beego.Router("/api/drug/getpatientdetail", &SelfDrugApiController{}, "Get:GetPatientDetail")
- //beego.Router("/api/drug/getpatientdetail",&SelfDrugApiController{},"Get:ToPatientDetail")
- beego.Router("/api/drug/getselfstockquery", &SelfDrugApiController{}, "Get:GetSelfStockQuery")
- beego.Router("/api/drug/postsearchdrugwarehouselist", &SelfDrugApiController{}, "Get:PostSearchDrugWarehouseList")
- beego.Router("/api/drug/savedrugpriceone", &SelfDrugApiController{}, "Post:SaveDrugPrice")
- beego.Router("/api/drug/drugpricelist", &SelfDrugApiController{}, "Get:GetDrugPriceList")
- beego.Router("/api/drug/savecheckdrugprice", &SelfDrugApiController{}, "Get:SaveCheckDrugPrice")
- beego.Router("/api/drug/savedrugdamageone", &SelfDrugApiController{}, "Post:SaveDrugDamage")
- beego.Router("/api/drug/getdrugdamagelist", &SelfDrugApiController{}, "Get:GetDrugDamageList")
- beego.Router("/api/drug/savedrugdamageprice", &SelfDrugApiController{}, "Get:SaveDrugDamagePrice")
- beego.Router("/api/drug/getdrugmodifyprice", &SelfDrugApiController{}, "Get:GetDrugModifyPrice")
- beego.Router("/api/drug/modifydrugprice", &SelfDrugApiController{}, "Get:ModifyDrugPrice")
- beego.Router("/api/drug/getmodifypriceprint", &SelfDrugApiController{}, "Get:GetModifyPricePrint")
- beego.Router("/api/drug/getdrugdamagedetail", &SelfDrugApiController{}, "Get:GetDrugDamageDetail")
- beego.Router("/api/drug/modifydrugdamage", &SelfDrugApiController{}, "Get:ModifyDrugDamage")
- beego.Router("/api/drug/deletedrugdamage", &SelfDrugApiController{}, "Get:DeleteDrugDamage")
- beego.Router("/api/drug/getdrugdamageprint", &SelfDrugApiController{}, "Get:GetDrugDamagePrint")
- beego.Router("/api/drug/warehouseinfobyid", &SelfDrugApiController{}, "Get:GetWarehoseInfoById")
- beego.Router("/api/drug/savedruginventory", &SelfDrugApiController{}, "Post:SaveDrugInventory")
- beego.Router("/api/drug/getdruginventorylist", &SelfDrugApiController{}, "Get:GetDrugInventoryList")
- beego.Router("/api/drug/savedrugcheckinventory", &SelfDrugApiController{}, "Get:SaveDrugCheckInventory")
- beego.Router("/api/drug/getdruginventorydetail", &SelfDrugApiController{}, "Get:GetDrugInventoryDetail")
- beego.Router("/api/drug/modifyinventory", &SelfDrugApiController{}, "Get:ModifyInventory")
- beego.Router("/api/drug/deletedruginventory", &SelfDrugApiController{}, "Get:DeleteDrugInventory")
- beego.Router("/api/drug/getdruginventoryprintlist", &SelfDrugApiController{}, "Get:GetDrugInventoryPrintList")
- beego.Router("/api/drug/getinventorydetaillist", &SelfDrugApiController{}, "Get:GetDrugInventoryDetailList")
- beego.Router("/api/drug/getinventorydetailprintlist", &SelfDrugApiController{}, "Get:GetInventoryDetailPrintList")
- beego.Router("/api/drug/savedrugproofinventory", &SelfDrugApiController{}, "Get:SaveDrugProofInventory")
- beego.Router("/api/drug/getdrugwarehouseinfototal", &StockManagerApiController{}, "Get:GetDrugWarehouseInfoTotal")
-
- beego.Router("/api/drug/saveinentorylist", &SelfDrugApiController{}, "Post:SaveInventoryList")
-
- beego.Router("/api/drug/getdamagebydrugid", &SelfDrugApiController{}, "Get:GetDamageByDrugId")
-
- beego.Router("/api/drug/getinventorymodelist", &SelfDrugApiController{}, "Get:GetInventoryModeList")
-
- //耗材库存优化接口
- beego.Router("/api/drug/getstorehouselist", &SelfDrugApiController{}, "Get:GetStorehouseList")
- beego.Router("/api/drug/getgoodnewquery", &SelfDrugApiController{}, "Get:GetGoodNewQuery")
- beego.Router("/api/drug/getgoodwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetGoodWarehouseOutInfoByIdList")
- beego.Router("/api/good/getgoodpatientlist", &SelfDrugApiController{}, "Get:GetGoodPatientList")
- beego.Router("/api/good/getwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetWarehouseOutDetailByPatientId")
- beego.Router("/api/good/getgoodexpirydatequery", &SelfDrugApiController{}, "Get:GetGoodExpiryDateQuery")
- beego.Router("/api/good/getpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodPurchaseStockQuery")
-
- //药品库存优化接口
- beego.Router("/api/good/getdrugwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetDrugWarehouseOutDetailByPatientId")
- beego.Router("/api/drug/getdrugexpirydatequery", &SelfDrugApiController{}, "Get:GetDrugExpiryDateQuery")
- beego.Router("/api/drug/getpurchasedrugquery", &SelfDrugApiController{}, "Get:GetPurchaseDrugQuery")
- beego.Router("/api/drug/getdrugnewquery", &SelfDrugApiController{}, "Get:GetDrugNewQuery")
- beego.Router("/api/drug/getdrugwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetDrugWarehouseInfoById")
-
- //耗材脚本
- beego.Router("/api/stock/tosendgoodinfomation", &SelfDrugApiController{}, "Get:GetSendGoodInformation")
- //药品脚本
- beego.Router("/api/drug/getdruginitdatalist", &SelfDrugApiController{}, "Get:GetDrugInitDetailList")
-
- //新数据
- beego.Router("/api/stock/getnewpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodNewPurchaseStockQuery")
- beego.Router("/api/stock/getpurchasenewdrugquery", &SelfDrugApiController{}, "Get:GetPurchaseNewDrugQuery")
- beego.Router("/api/stock/getgoodovercount", &SelfDrugApiController{}, "Get:GetGoodOverCount")
- beego.Router("/api/stock/getdrugovercount", &SelfDrugApiController{}, "Get:GetDrugOverCount")
-
- beego.Router("/api/stock/getdruginfolist", &SelfDrugApiController{}, "Get:GetDrugInventoryWarehouseInfoList")
-
- beego.Router("/api/drug/getdrugflowdetailbyid", &SelfDrugApiController{}, "Get:GetDrugFlowDetailById")
-
- //康允新版本
- beego.Router("/api/stock/getpurchaseDrugQueryList", &SelfDrugApiController{}, "Get:GetPurchaseDrugQueryList")
- }
-
- func (this *SelfDrugApiController) GetCurrentPatient() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- patient, err := service.GetCurrentPatient(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (this *SelfDrugApiController) GetAllDrugName() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- //查询药品库是否开启
- //configStock, _ := service.GetDrugStockConfig(orgId)
- //if configStock.IsOpen == 1 {
- //
- //}
-
- drugName, err := service.GetAllDrugName(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugName": drugName,
- })
-
- }
-
- func (this *SelfDrugApiController) SaveDrugName() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- drug_name := this.GetString("drug_name")
- id, _ := this.GetInt64("id")
- //fmt.Println("drug_name", drug_name)
- drugName := models.XtDrugName{
- UserOrgId: orgId,
- DrugName: drug_name,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- DrugId: id,
- }
- _, errcode := service.GetDrugName(drug_name, orgId)
- if errcode == gorm.ErrRecordNotFound {
- err := service.SaveDrugName(&drugName)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugName": drugName,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- }
-
- func (this *SelfDrugApiController) GetDrugNameList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- list, err := service.GetDrugNameList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetRulleName() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- id, _ := this.GetInt64("id")
- drugId, _ := service.GetDrugId(id)
- rullerList, err := service.GetRulleList(orgId, drugId.DrugId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerList": rullerList,
- })
- }
-
- func (this *SelfDrugApiController) GetUnitByBaseId() {
-
- id, _ := this.GetInt64("id")
- baseList, err := service.GetUnitByBaseId(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "baseList": baseList,
- })
- }
-
- func (this *SelfDrugApiController) SaveRulleName() {
- drug_name := this.GetString("drug_name")
- drug_spec := this.GetString("drug_spec")
- drug_stock_limit := this.GetString("drug_stock_limit")
- drug_name_id, _ := this.GetInt64("drug_name_id")
- drug_id, _ := this.GetInt64("drug_id")
- price, _ := this.GetInt64("price")
- prices := strconv.FormatInt(price, 10)
- durg_price, _ := strconv.ParseFloat(prices, 64)
- unit := this.GetString("unit")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
- drugSpecName := models.XtStandName{
- DrugName: drug_name,
- DrugSpec: drug_spec,
- DrugStockLimit: drug_stock_limit,
- DrugNameId: drug_name_id,
- Price: durg_price,
- MinUnit: unit,
- UserOrgId: orgId,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- DrugId: drug_id,
- }
-
- //查询该机构下药品规格名称是否存在
- _, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
-
- if errcode == gorm.ErrRecordNotFound {
- err := service.SaveRulleName(&drugSpecName)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "RullerName": drugSpecName,
- })
- } else if errcode == nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
- return
- }
-
- }
-
- func (this *SelfDrugApiController) EditRullerName() {
-
- id, _ := this.GetInt64("id")
- rullerDetail, err := service.GetRullerNameDetail(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerDetail": rullerDetail,
- })
- }
-
- func (this *SelfDrugApiController) UpdatedRullerName() {
-
- id, _ := this.GetInt64("id")
- drug_name := this.GetString("drug_name")
- drug_stock_limit := this.GetString("drug_stock_limit")
- price, _ := this.GetInt64("price")
- prices := strconv.FormatInt(price, 10)
- durg_price, _ := strconv.ParseFloat(prices, 64)
-
- drug_spec := this.GetString("drug_spec")
- unit := this.GetString("unit")
- drug_name_id, _ := this.GetInt64("drug_name_id")
- drug_id, _ := this.GetInt64("drug_id")
-
- RullerName := models.XtStandName{
- DrugName: drug_name,
- DrugStockLimit: drug_stock_limit,
- Price: durg_price,
- DrugSpec: drug_spec,
- MinUnit: unit,
- DrugNameId: drug_name_id,
- DrugId: drug_id,
- }
- _, errcode := service.GetIsExit(drug_name, drug_spec, id)
- if errcode == gorm.ErrRecordNotFound {
- err := service.UpdatedRullerName(id, &RullerName)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "RullerName": RullerName,
- })
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- }
-
- func (this *SelfDrugApiController) GetAllDrugNameList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- rullerName, err := service.GetAllDrugNameList(orgId)
-
- list, err := service.GetMedicalDrugNameList(orgId)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerName": rullerName,
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetRullerListByDrugName() {
-
- id := this.GetString("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- fmt.Println("orgid", orgId)
- drugName, err := service.GetRullerListByDrugName(id, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugName": drugName,
- })
- }
-
- func (this *SelfDrugApiController) SaveSelfMedicines() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- patient_id := int64(dataBody["patient_id"].(float64))
- medicineData, _ := dataBody["medicineData"].([]interface{})
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- for _, item := range medicineData {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- drug_name_id := int64(items["drug_name_id"].(float64))
- drug_spec := items["drug_spec"].(string)
- min_unit := items["min_unit"].(string)
- drug_id := int64(items["drug_id"].(float64))
- //根据drug_id
- drugMedical, _ := service.GetBaseDrugMedical(drug_name_id)
- medical := models.XtSelfMedical{
- DrugName: drug_name,
- DrugNameId: drug_name_id,
- DrugSpec: drug_spec,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- UserOrgId: orgId,
- PatientId: patient_id,
- MinUnit: min_unit,
- ExecutionFrequency: drugMedical.ExecutionFrequency,
- PrescribingNumber: drugMedical.PrescribingNumber,
- DeliveryWay: drugMedical.DeliveryWay,
- SingleDose: drugMedical.SingleDose,
- DrugId: drug_id,
- }
- //查询同个病人同个药品同个规格是否已存在
- _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
-
- if errcode == gorm.ErrRecordNotFound {
- err := service.CreateSelfMedical(&medical)
- fmt.Println(err)
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgid := adminUserInfo.CurrentOrgId
- //fmt.Println(orgid)
- appId := adminUserInfo.CurrentAppId
- staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "staff": staff,
- })
- }
-
- func (this *SelfDrugApiController) SaveStock() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- fmt.Println("start_time", start_time)
- admin_user_id, _ := this.GetInt64("admin_user_id")
- fmt.Println("admin_user_id", admin_user_id)
- patient_id, _ := this.GetInt64("patient_id")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- stocks, _ := dataBody["stocks"].([]interface{})
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- for _, item := range stocks {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- fmt.Println("drug_name", drug_name)
- drug_name_id := int64(items["drug_name_id"].(float64))
- fmt.Println("parient_id", drug_name_id)
- drug_spec := items["drug_spec"].(string)
- store_number := items["store_number"].(string)
- fmt.Println("store_number", store_number)
- storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
- remarks := items["remarks"].(string)
- min_unit := items["min_unit"].(string)
- medic_id := int64(items["id"].(float64))
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
- number = number + total
- warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
-
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- stock := models.XtSelfStock{
- DrugName: drug_name,
- DrugNameId: drug_name_id,
- DrugSpec: drug_spec,
- StoreNumber: storeNumber,
- Remarks: remarks,
- AdminUserId: admin_user_id,
- StorckTime: theTime.Unix(),
- CreatedTime: time.Now().Unix(),
- Status: 1,
- UserOrgId: orgId,
- StockInNumber: warehousing_in_order,
- PatientId: patient_id,
- MinUnit: min_unit,
- StorageMode: 1,
- MedicId: medic_id,
- }
- err := service.CreateStock(&stock)
- fmt.Println("err", err)
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) SaveOutStock() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- admin_user_id, _ := this.GetInt64("admin_user_id")
- patient_id, _ := this.GetInt64("patient_id")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- outStocks, _ := dataBody["outStocks"].([]interface{})
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- for _, item := range outStocks {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- drug_name_id := int64(items["drug_name_id"].(float64))
- drug_spec := items["drug_spec"].(string)
- outstore_number := items["outstore_number"].(string)
- outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
- remarks := items["remarks"].(string)
- medic_id := int64(items["id"].(float64))
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- fmt.Println(remarks)
- fmt.Println(items)
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- stock := models.XtSelfOutStock{
- DrugName: drug_name,
- DrugNameId: drug_name_id,
- DrugSpec: drug_spec,
- OutstoreNumber: outStoreNumber,
- Remarks: remarks,
- AdminUserId: admin_user_id,
- StorckTime: theTime.Unix(),
- CreatedTime: time.Now().Unix(),
- Status: 1,
- UserOrgId: orgId,
- StockOutNumber: warehousing_out_order,
- PatientId: patient_id,
- ExitMode: 1,
- MedicId: medic_id,
- }
- err := service.CreateOutStock(&stock)
- fmt.Println("err", err)
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) DeleteDrugById() {
- id, _ := this.GetInt64("id")
- drug_name := this.GetString("drug_name")
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
-
- if errcode == gorm.ErrRecordNotFound {
- service.DeleteDrugName(id)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- }
-
- func (this *SelfDrugApiController) SaveRadio() {
-
- radio, _ := this.GetInt64("radio")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- drugSet := models.XtDrugSet{
- DrugStart: radio,
- UserOrgId: orgId,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- }
- _, errcode := service.GetDrugSetByUserOrgId(orgId)
- if errcode == gorm.ErrRecordNotFound {
- err := service.SaveRadio(&drugSet)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugSet": drugSet,
- })
- } else if errcode == nil {
- err := service.UpdateDrugSet(&drugSet, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugSet": drugSet,
- })
- }
-
- }
-
- func (this *SelfDrugApiController) DeleteDrugStand() {
-
- id, _ := this.GetInt64("id")
- name := this.GetString("name")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- _, errcode := service.GetMedicalsByName(orgId, name)
- if errcode == gorm.ErrRecordNotFound {
- err := service.DeleteDrugStand(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- } else if errcode == nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- }
-
- func (this *SelfDrugApiController) GetStockList() {
-
- patientid, _ := this.GetInt64("id")
- start_time := this.GetString("start_time")
- fmt.Println("开始时间", start_time)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- startimeUnix := theTime.Unix()
- keyword := this.GetString("keyword")
- fmt.Println("keyword", keyword)
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- //获取
- medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
- //统计总数量
- stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
- //统计出库数量
- outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
-
- //统计该病人时间段内出库条数
- outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "medicalList": medicalList,
- "stocklist": stocklist,
- "outStocklist": outStocklist,
- "outList": outList,
- })
- }
-
- func (this *SelfDrugApiController) DeleteDrugName() {
-
- drug_name := this.GetString("drugname")
- patient_id, _ := this.GetInt64("patientid")
-
- //查询该药品是否出库
- stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
- if len(stocklist) == 0 {
- //删除该药品
- service.DeleteDrugStockNumber(drug_name, patient_id)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- }
-
- func (this *SelfDrugApiController) GetDrugDetail() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- drug_name := this.GetString("drug_name")
- drug_spec := this.GetString("drug_spec")
- start_time := this.GetString("start_time")
- startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- end_time := this.GetString("end_time")
- endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- patient_id, _ := this.GetInt64("patient_id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- //查询入库明细
- stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
-
- //查询出库明细
- outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stockDetail": stockDetail,
- "outStockDetail": outStockDetail,
- })
- }
-
- func (this *SelfDrugApiController) GetAllPatientStockList() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- drug_name := this.GetString("drug_name")
- drug_spec := this.GetString("drug_spec")
- start_time := this.GetString("start_time")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- startUnix := theTime.Unix()
- end_time := this.GetString("end_time")
- endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- endTimeUnix := endTimes.Unix()
- keywords := this.GetString("search_input")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- //入库
- stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
-
- //出库
- outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stocklist": stocklist,
- "outStockList": outStockList,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugDataByPatientId() {
-
- patient_id, _ := this.GetInt64("patient_id")
- fmt.Println("patient_id", patient_id)
- medicalList, err := service.GetDrugDataByPatientId(patient_id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "medicalList": medicalList,
- })
- }
-
- func (this *SelfDrugApiController) GetSelfMedicalList() {
-
- patient_id, _ := this.GetInt64("patient_id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
- privateDrugConfig, _ := service.GetDrugSetByUserOrgId(orgId)
- drugList, _ := service.GetAllBaseDrugLibList(orgId)
- privateDrugList, _ := service.GetPrivateDrugList(patient_id, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "base_drug_config": drugStockConfig,
- "private_drug_config": privateDrugConfig,
- "base_drug_list": drugList,
- "private_drug_list": privateDrugList,
- })
- ////查询是否开启药品库
- //config, _ := service.GetDruckStockConfig(orgId)
- //
- //fmt.Println("--------------------------",config.IsOpen)
- ////开启
- //if config.IsOpen == 1 {
- // //查询该机构下的药品库
- // drugName, _ := service.GetAllDrugName(orgId)
- //
- // //查询该机构是否开启自备药
- // medical, _ := service.GetSetSelfMedical(orgId)
- // fmt.Println("medical+++++++++++++++++",medical.DrugStart)
- // //开启
- // if medical.DrugStart == 1 {
- // list, err := service.GetSelfMedicalList(patient_id)
- // if err != nil {
- // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- // return
- // }
- // this.ServeSuccessJSON(map[string]interface{}{
- // "medicalList": list,
- // "drugName": drugName,
- // })
- // } else {
- // this.ServeSuccessJSON(map[string]interface{}{
- // "drugName": drugName,
- // })
- // }
- //}
- }
-
- func (this *SelfDrugApiController) GetDrugDescByDrugName() {
-
- drug_name := this.GetString("drug_name")
- patient_id, _ := this.GetInt64("patient_id")
- way, _ := this.GetInt64("way")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- drug_id, _ := this.GetInt64("id")
- //从基础库查询
- if way == 1 {
- //查询基础库数据
- medcal, err := service.GetBaseMedcal(drug_name, orgId)
- //统计入库数量
- countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
-
- //统计出库数量
- countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugspec": medcal,
- "countInfo": countInfo,
- "countout": countout,
- })
- }
- //从自备药库查询
- if way == 2 {
- drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugspec": drugspec,
- })
- }
-
- }
-
- func (this *SelfDrugApiController) GetDrugSet() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- drugSet, err := service.GetDrugSet(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugSet": drugSet,
- })
-
- }
-
- func (this *SelfDrugApiController) GetAllMedicalList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- list, err := service.GetAllMedicalList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugName": list,
- })
- }
-
- func (this *SelfDrugApiController) GetStandName() {
-
- name := this.GetString("name")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- rullerlist, err := service.GetRulleName(orgId, name)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerlist": rullerlist,
- })
- }
-
- func (this *SelfDrugApiController) GetRullerList() {
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- rullerList, err := service.GetRulleList(orgId, id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerlist": rullerList,
- })
- }
-
- func (this *SelfDrugApiController) DeleteDrugNameById() {
-
- id, _ := this.GetInt64("id")
- drug_name := this.GetString("drug_name")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
-
- if errcode == gorm.ErrRecordNotFound {
- service.DeleteDrugNameById(id)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- }
-
- func (this *SelfDrugApiController) GetPatientDetail() {
-
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- patientDetail, err := service.GetPatientDetail(id, adminUserInfo.CurrentOrgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patientDetail": patientDetail,
- })
- }
-
- //func (this *SelfDrugApiController) ToPatientDetail() {
- //
- // keyword := this.GetString("keyword")
- // adminUser := this.GetAdminUserInfo()
- // orgId := adminUser.CurrentOrgId
- // patient, err := service.ToSeachPatient(keyword, orgId)
- // if err != nil {
- // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- // return
- // }
- // this.ServeSuccessJSON(map[string]interface{}{
- // "patient": patient,
- // })
- //}
-
- func (this *SelfDrugApiController) GetSelfStockQuery() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- type_name, _ := this.GetInt64("type_name")
- keywords := this.GetString("keywords")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- startUnix := theTime.Unix()
- end_time := this.GetString("end_time")
- endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- endTimeUnix := endTimes.Unix()
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- //统计入库数量
- stockQuery, total, err := service.GetSelfStockQuery(type_name, keywords, startUnix, endTimeUnix, orgId, limit, page)
- //统计出库数量
- stockOutQuery, err := service.GetSelfOutStockQuery(startUnix, endTimeUnix, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stockQuery": stockQuery,
- "total": total,
- "stockOutQuery": stockOutQuery,
- })
- }
-
- func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
-
- keyword := this.GetString("keyword")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, err := service.PostSearchDrugWarehouseList(keyword, orgId, storehouse_id)
- manufacturerList, err := service.GetAllManufacturerList(orgId)
- dealerList, err := service.GetAllDealerList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugPrice() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
- fmt.Println("999939433443", tableData)
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
-
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_name := items["drug_name"].(string)
- fmt.Println("drug_aname23232323232", drug_name)
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number := items["number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
- utils.ErrorLog("new_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- drugAdjust := models.XtDrugAdjustPrice{
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- LastPrice: last_price,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- Number: number,
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- }
-
- err := service.CreateDrugPrice(drugAdjust)
- fmt.Println(err)
- }
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) GetDrugPriceList() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- list, total, err := service.GetDrugPriceList(startTime, endTime, orgId, keyword, limit, page)
- doctorList, err := service.GetAllDoctorThree(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "doctorList": doctorList,
- })
- }
-
- func (this *SelfDrugApiController) SaveCheckDrugPrice() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- adjustPrice := models.XtDrugAdjustPrice{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err = service.UpdateDrugAdjuestPrice(ids, adjustPrice)
- fmt.Println("err", err)
- list, _ := service.GetDrugAdjuestPrice(ids)
- for _, item := range list {
- drug := models.BaseDrugLib{
- RetailPrice: item.NewPrice,
- LastPrice: item.NewPrice,
- }
- service.UpdateBaseDrugOne(drug, item.DrugId)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "adjustPrice": adjustPrice,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugDamage() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
- fmt.Println("999939433443", tableData)
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number := items["number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
- utils.ErrorLog("new_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
- utils.ErrorLog("warehousing_info_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_info_id := int64(items["warehousing_info_id"].(float64))
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
-
- if items["drug_origin_place"] == nil || reflect.TypeOf(items["drug_origin_place"]).String() != "string" {
- utils.ErrorLog("drug_origin_place")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_origin_place := items["drug_origin_place"].(string)
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- if items["stock_max_number"] == nil || reflect.TypeOf(items["stock_max_number"]).String() != "float64" {
- utils.ErrorLog("stock_max_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stock_max_number := int64(items["stock_max_number"].(float64))
-
- if items["stock_min_number"] == nil || reflect.TypeOf(items["stock_min_number"]).String() != "float64" {
- utils.ErrorLog("stock_min_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stock_min_number := int64(items["stock_min_number"].(float64))
-
- if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
- utils.ErrorLog("total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- total := items["total"].(string)
- drugDamage := models.XtDrugDamage{
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- LastPrice: last_price,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- Number: number,
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- ExpiryDate: expiry_date,
- ProductDate: product_date,
- WarehousingInfoId: warehousing_info_id,
- DrugOriginPlace: drug_origin_place,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- Total: total,
- }
-
- err := service.CreateDrugDamage(drugDamage)
- fmt.Println(err)
- }
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- }
-
- func (this *SelfDrugApiController) GetDrugDamageList() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
-
- list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page, storehouse_id)
-
- damagelist, _ := service.GetDrugDamageByOrgId(orgId)
- doctorList, err := service.GetAllDoctorThree(orgId)
-
- houseList, _ := service.GetAllStoreHouseList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "damagelist": damagelist,
- "doctorList": doctorList,
- "houseList": houseList,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugDamagePrice() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- damage := models.XtDrugDamage{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err = service.UpdateDrugDamage(ids, damage)
- fmt.Println(err)
- list, _ := service.GetDrugDamage(ids)
- ctime := time.Now().Unix()
- adminUserInfo := this.GetAdminUserInfo()
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var manufacturer_id int64
- var dealer_id int64
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.DrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: time.Now().Unix(),
- Type: 1,
- }
- service.AddSigleDrugWarehouseOut(&warehouseOut)
- for _, item := range list {
- for _, it := range manufacturerList {
- if item.Manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
-
- for _, its := range dealerList {
- if its.DealerName == item.Dealer {
- dealer_id = its.ID
- }
- }
-
- warehouseOutInfo := models.XtDrugWarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- DrugId: item.DrugId,
- Count: item.Count,
- Price: item.RetailPrice,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- RetailPrice: item.RetailPrice,
- CountUnit: item.WarehousingUnit,
- ExpiryDate: item.ExpiryDate,
- ProductDate: item.ProductDate,
- Number: item.Number,
- BatchNumber: item.BatchNumber,
- IsSys: 0,
- WarehouseInfoId: item.WarehousingInfoId,
- }
-
- drugflow := models.DrugFlow{
- WarehouseOutId: warehouseOut.ID,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- DrugId: item.DrugId,
- Number: item.Number,
- ProductDate: item.ProductDate,
- ExpireDate: item.ExpiryDate,
- Count: item.Count,
- Price: item.RetailPrice,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- BatchNumber: item.BatchNumber,
- MaxUnit: item.WarehousingUnit,
- ConsumableType: 5,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- }
- service.CreateWareHouseOutInfo(&warehouseOutInfo)
- service.CreateDrugFlowOne(drugflow)
-
- info, _ := service.GetDrugByWarehouseInfo(item.WarehousingInfoId)
- //扣减库存
- warehouseInfo := models.XtDrugWarehouseInfo{
- StockMaxNumber: info.StockMaxNumber - info.StockMaxNumber,
- }
- service.UpdateDrugWarehouseingInfo(item.WarehousingInfoId, warehouseInfo)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "damage": damage,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugModifyPrice() {
-
- id, _ := this.GetInt64("id")
- detail, err := service.GetDrugModifyPrice(id)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *SelfDrugApiController) ModifyDrugPrice() {
-
- drug_name := this.GetString("drug_name")
- specification_name := this.GetString("specification_name")
- warehousing_unit := this.GetString("warehousing_unit")
- manufacturer := this.GetString("manufacturer")
- number := this.GetString("number")
- retailPrice := this.GetString("retail_price")
- retail_price, _ := strconv.ParseFloat(retailPrice, 64)
- newPrice := this.GetString("new_price")
- new_price, _ := strconv.ParseFloat(newPrice, 64)
- count, _ := this.GetInt64("count")
- remark := this.GetString("remark")
- id, _ := this.GetInt64("id")
- drug_id, _ := this.GetInt64("drug_id")
- adjustPrice := models.XtDrugAdjustPrice{
- DrugName: drug_name,
- Count: count,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Remark: remark,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Manufacturer: manufacturer,
- Number: number,
- DrugId: drug_id,
- }
- err := service.ModifyDrugPrice(id, adjustPrice)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "adjustPrice": adjustPrice,
- })
- }
-
- func (this *SelfDrugApiController) GetModifyPricePrint() {
-
- ids := this.GetString("ids")
- idsSplit := strings.Split(ids, ",")
- list, err := service.GetModifyPricePrint(idsSplit)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugDamageDetail() {
-
- id, _ := this.GetInt64("id")
- detail, _ := service.GetDrugDamageDetail(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *SelfDrugApiController) ModifyDrugDamage() {
-
- id, _ := this.GetInt64("id")
- drug_id, _ := this.GetInt64("drug_id")
- drug_name := this.GetString("drug_name")
- drug_origin_place := this.GetString("drug_origin_place")
- lastPrice := this.GetString("last_price")
- last_price, _ := strconv.ParseFloat(lastPrice, 64)
- newPrice := this.GetString("new_price")
- new_price, _ := strconv.ParseFloat(newPrice, 64)
- manufacturer := this.GetString("manufacturer")
- number := this.GetString("number")
- retailPrice := this.GetString("retail_price")
- retail_price, _ := strconv.ParseFloat(retailPrice, 64)
- remark := this.GetString("remark")
- count, _ := this.GetInt64("count")
- warehousing_unit := this.GetString("warehousing_unit")
- stock_max_number, _ := this.GetInt64("stock_max_number")
- stock_min_number, _ := this.GetInt64("stock_min_number")
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- damage := models.XtDrugDamage{
- DrugName: drug_name,
- SpecificationName: "",
- WarehousingUnit: warehousing_unit,
- Count: count,
- LastPrice: last_price,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: "",
- Remark: remark,
- DrugId: drug_id,
- Number: number,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- WarehousingInfoId: warehousing_info_id,
- DrugOriginPlace: drug_origin_place,
- }
- err := service.ModifyDrugDamage(id, damage)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "damage": damage,
- })
- }
-
- func (this *SelfDrugApiController) DeleteDrugDamage() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteDrugDamage(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- }
-
- func (this *SelfDrugApiController) GetDrugDamagePrint() {
-
- idsSplit := this.GetString("ids")
- ids := strings.Split(idsSplit, ",")
- list, _ := service.GetDrugDamagePrint(ids)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetWarehoseInfoById() {
-
- id, _ := this.GetInt64("id")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetWarehoseInfoById(id, storehouse_id, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugInventory() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
- fmt.Println("999939433443", tableData)
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
-
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
- utils.ErrorLog("new_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- numbers := items["number"].(string)
-
- if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
- utils.ErrorLog("warehouse_info_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
-
- if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
- utils.ErrorLog("total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- total := items["total"].(string)
-
- drug_origin_place := items["drug_origin_place"].(string)
-
- min_count := int64(items["min_count"].(float64))
- min_unit := items["min_unit"].(string)
- inventory := models.XtDrugInventory{
-
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- LastPrice: last_price,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: "",
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- ExpiryDate: expiry_date,
- ProductDate: product_date,
- Number: numbers,
- //BatchNumber: batch_number,
- Total: total,
- WarehouseInfoId: warehouse_info_id,
- DrugOriginPlace: drug_origin_place,
- MinUnit: min_unit,
- MinCount: min_count,
- }
- err = service.CreateDrugInventory(inventory)
- fmt.Println(err)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "msg",
- })
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryList() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- list, total, err := service.GetDrugInventoryList(keyword, page, limit, orgId, startTime, endTime)
-
- doctorList, _ := service.GetAllDoctorThree(orgId)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "doctorList": doctorList,
- "houseList": houseList,
- "houseConfig": houseConfig,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugCheckInventory() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- inventory := models.XtDrugInventory{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err = service.UpdateDrugInventory(ids, inventory)
- fmt.Println(err)
-
- list, _ := service.GetDrugInventoryListByIds(ids)
-
- adminUserInfo := this.GetAdminUserInfo()
- var stock_total int64
- var proof_count int64
- var maxNumber int64
- var minNumber int64
- for _, item := range list {
-
- //查询药品信息
- drug, _ := service.GetDrugDetailByDrugId(item.DrugId)
-
- //查询库存
- info, _ := service.GetDrugWareInfoByIdTwo(item.WarehouseInfoId)
- var max_count int64
- var min_count int64
- for _, it := range info {
- max_count += it.StockMaxNumber
- min_count += it.StockMinNumber
- }
-
- //获取最晚的库存数量
- lastInfo, _ := service.GetLastDrugWarehouseInfo(item.DrugId)
- firstInfo, _ := service.GetFirstDrugWarehouseInfo(item.DrugId)
- stock_total = max_count*drug.MinNumber + min_count
- proof_count = item.Count*drug.MinNumber + item.MinCount
- fmt.Println("stock_total", stock_total)
- fmt.Println("proof_count", proof_count)
- //判断 如果库存数量 大于盘点库存,则出库
- if stock_total > proof_count {
- minNumber = (stock_total - proof_count) % drug.MinNumber
- maxNumber = (stock_total - proof_count) / drug.MinNumber
-
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.DrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: ctime,
- Type: 1,
- }
- service.AddSigleDrugWarehouseOut(&warehouseOut)
- warehouse, _ := service.GetLastDrugWarehouseOut(adminUserInfo.CurrentOrgId)
- warehouseOutInfo := models.DrugWarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouse.ID,
- DrugId: item.DrugId,
- Count: maxNumber,
- Price: firstInfo.Price,
- TotalPrice: firstInfo.TotalPrice,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: firstInfo.Manufacturer,
- Dealer: firstInfo.Dealer,
- RetailPrice: firstInfo.RetailPrice,
- RetailTotalPrice: firstInfo.RetailTotalPrice,
- CountUnit: drug.MaxUnit,
- ExpiryDate: firstInfo.ExpiryDate,
- ProductDate: firstInfo.ProductDate,
- Number: firstInfo.Number,
- BatchNumber: firstInfo.BatchNumber,
- IsSys: 0,
- WarehouseInfoId: firstInfo.ID,
- }
-
- drugflow := models.DrugFlow{
- WarehouseOutId: warehouseOut.ID,
- WarehouseOutOrderNumber: warehousing_out_order,
- DrugId: item.DrugId,
- Number: firstInfo.Number,
- ProductDate: firstInfo.ProductDate,
- ExpireDate: firstInfo.ExpiryDate,
- Count: maxNumber,
- Price: firstInfo.Price,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: firstInfo.Manufacturer,
- Dealer: firstInfo.Dealer,
- BatchNumber: firstInfo.BatchNumber,
- MaxUnit: drug.MaxUnit,
- ConsumableType: 2,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- }
- service.CreateDrugWarehouseOutInfo(warehouseOutInfo)
- service.CreateDrugFlowOne(drugflow)
-
- //扣减当前批次号的库存
- var total_count int64
-
- //查询当前批次库存的数量
- warehosueInfoList, _ := service.GetCurrentWarehosueInfo(item.WarehouseInfoId)
- fmt.Println(warehosueInfoList)
- for _, item := range warehosueInfoList {
- total_count += item.StockMaxNumber*drug.MinNumber + item.StockMinNumber
- }
- //判断当前批次库存 和 需要出库的数据
- //出库
- if proof_count <= total_count {
-
- //var total_count_one int64
- //获取当前批次号的库存
- //warehouseinfoOne, _ := service.GetCurrentWarehosueInfoOne(item.WarehouseInfoId)
- //total_count_one = warehouseinfoOne.StockMaxNumber * drug.MinNumber + warehouseinfoOne.StockMinNumber
-
- }
- //报错提示
- if proof_count > total_count {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
- }
- }
-
- //判断 如果库存数量 小于于盘点库存,则入库
- fmt.Println("stock_total2332322323223", stock_total, proof_count)
- if stock_total < proof_count {
-
- maxNumber = (proof_count - stock_total) / drug.MinNumber
- minNumber = (proof_count - stock_total) % drug.MinNumber
- fmt.Println("min_number23233232323223322323", minNumber)
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
- total = total + 1
- fmt.Println("total2323232323232", total)
- warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- warehousing := models.DrugWarehouse{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehousingTime: ctime,
- Type: 1,
- }
- service.AddSigleDrugWarehouse(&warehousing)
- warehouse, _ := service.GetLastDrugWarehouse(adminUserInfo.CurrentOrgId)
- warehouseInfo := models.DrugWarehouseInfo{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehouse.ID,
- DrugId: item.DrugId,
- Number: lastInfo.Number,
- ProductDate: lastInfo.ProductDate,
- ExpiryDate: lastInfo.ExpiryDate,
- WarehousingCount: maxNumber,
- Price: lastInfo.Price,
- TotalPrice: lastInfo.TotalPrice,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: lastInfo.Manufacturer,
- Dealer: lastInfo.Dealer,
- StockMaxNumber: maxNumber,
- StockMinNumber: minNumber,
- RetailTotalPrice: lastInfo.RetailTotalPrice,
- BatchNumber: lastInfo.BatchNumber,
- MaxUnit: drug.MaxUnit,
- MinUnit: drug.MinUnit,
- WarehousingInfoId: item.WarehouseInfoId,
- }
-
- drugflow := models.DrugFlow{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehouse.ID,
- DrugId: item.DrugId,
- Number: lastInfo.Number,
- ProductDate: lastInfo.ProductDate,
- ExpireDate: lastInfo.ExpiryDate,
- Count: maxNumber,
- Price: lastInfo.Price,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: lastInfo.Manufacturer,
- Dealer: lastInfo.Dealer,
- BatchNumber: lastInfo.BatchNumber,
- MaxUnit: drug.MaxUnit,
- MinUnit: drug.MinUnit,
- ConsumableType: 1,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- }
-
- service.CreateDrugWarehouseInfo(warehouseInfo)
- service.CreateDrugFlowOne(drugflow)
-
- }
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryDetail() {
-
- id, _ := this.GetInt64("id")
- detail, err := service.GetDrugInventoryDetail(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *SelfDrugApiController) ModifyInventory() {
-
- id, _ := this.GetInt64("id")
- drug_id, _ := this.GetInt64("drug_id")
- drug_name := this.GetString("drug_name")
- specification_name := this.GetString("specification_name")
- retailPrice := this.GetString("retail_price")
- retail_price, _ := strconv.ParseFloat(retailPrice, 64)
- warehousing_order := this.GetString("warehousing_order")
- number := this.GetString("number")
- manufacturer := this.GetString("manufacturer")
- remark := this.GetString("remark")
- warehousing_unit := this.GetString("warehousing_unit")
- total := this.GetString("total")
- lastPrice := this.GetString("last_price")
- last_price, _ := strconv.ParseFloat(lastPrice, 64)
- count, _ := this.GetInt64("count")
- drug_origin_place := this.GetString("drug_origin_place")
-
- stock_max_number, _ := this.GetInt64("stock_max_number")
- stock_min_number, _ := this.GetInt64("stock_min_number")
- warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
- min_count, _ := this.GetInt64("min_count")
- min_unit := this.GetString("min_unit")
- inventory := models.XtDrugInventory{
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- LastPrice: last_price,
- RetailPrice: retail_price,
- Manufacturer: manufacturer,
- Remark: remark,
- DrugId: drug_id,
- WarehousingOrder: warehousing_order,
- Number: number,
- Total: total,
- DrugOriginPlace: drug_origin_place,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- WarehouseInfoId: warehouse_info_id,
- MinCount: min_count,
- MinUnit: min_unit,
- }
- err := service.ModifyDrugInventory(id, inventory)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
-
- func (this *SelfDrugApiController) DeleteDrugInventory() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteDrugInventory(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryPrintList() {
-
- ids := this.GetString("ids")
-
- idssplit := strings.Split(ids, ",")
- list, err := service.GetDrugInventoryPrintList(idssplit)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryDetailList() {
-
- keyword := this.GetString("keyword")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId, storehouse_id)
- inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- doctorList, _ := service.GetAllDoctorThree(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "doctorList": doctorList,
- "houseList": houseList,
- "inventoryList": inventoryList,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugProofInventory() {
-
- id, _ := this.GetInt64("id")
- warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
- warehousing_unit := this.GetString("warehousing_unit")
- remark := this.GetString("remark")
- proof_count, _ := this.GetInt64("proof_count")
-
- inventory := models.XtDrugInventory{
- WarehouseInfoId: warehouse_info_id,
- ProofCount: proof_count,
- WarehousingUnit: warehousing_unit,
- Remark: remark,
- }
- err := service.UpdateDrugProofInventory(id, &inventory)
- info := models.XtDrugWarehouseInfo{
- StockMaxNumber: proof_count,
- }
- service.UpdateDrugWarehouseInfoById(warehouse_info_id, &info)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
-
- func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
-
- id, _ := this.GetInt64("id")
- list, _ := service.GetDrugWarehouseInfoTotal(id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- //新改造
-
- func (this *SelfDrugApiController) SaveInventoryList() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
-
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- fmt.Println("drug_name", drug_name)
- specification_name := items["specification_name"].(string)
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- max_unit := items["max_unit"].(string)
- if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
- utils.ErrorLog("max_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- min_unit := items["min_unit"].(string)
- if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
- utils.ErrorLog("min_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- drug_id := int64(items["drug_id"].(float64))
-
- min_number := int64(items["min_number"].(float64))
-
- stock_max_number := int64(items["stock_max_number"].(float64))
-
- stock_min_number := int64(items["stock_min_number"].(float64))
-
- last_stock_max_number := int64(items["last_stock_max_number"].(float64))
-
- last_stock_min_number := int64(items["last_stock_min_number"].(float64))
-
- warehousing_order := items["warehousing_order"].(string)
-
- price := items["price"].(float64)
-
- manufacturer_name := items["manufacturer_name"].(string)
-
- batch_number := items["batch_number"].(string)
-
- id := int64(items["id"].(float64))
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- type_id := int64(items["type"].(float64))
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- storehouse_id := int64(items["storehouse_id"].(float64))
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- timeNow := time.Now().Format("2006-01-02")
- locationTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeNow+" 00:00:00", loc)
- var consumable_type int64
- var consumable_count int64
- var ord_total int64
- var new_total int64
- var total int64
- ord_total = stock_max_number*min_number + stock_min_number
- new_total = last_stock_max_number*min_number + last_stock_min_number
- medical, _ := service.GetBaseDrugMedical(drug_id)
-
- //改变库存
- info := models.DrugWarehouseInfo{
- DrugId: drug_id,
- StockMaxNumber: last_stock_max_number,
- StockMinNumber: last_stock_min_number,
- WarehousingCount: last_stock_max_number,
- MaxUnit: max_unit,
- MinUnit: min_unit,
- }
- drugInfo, _ := service.GetCurrentWarehosueInfoOne(id)
-
- if drugInfo.MaxUnit == medical.MaxUnit {
- total = drugInfo.WarehousingCount * medical.MinNumber
- }
- if drugInfo.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- total = drugInfo.WarehousingCount
- }
- //如果库存数据大于盘点数据,则减去数量
- if ord_total > new_total {
- consumable_type = 11
- consumable_count = ord_total - new_total
-
- err = service.ModifyDrugWarehouseInfo(&info, id)
-
- }
- //如果库存数据小于盘点数据,则增加数量
- if ord_total < new_total && new_total <= total {
- consumable_type = 10
- consumable_count = new_total - ord_total
- err = service.ModifyDrugWarehouseInfo(&info, id)
-
- }
-
- if ord_total < new_total && new_total > total {
- consumable_type = 10
- consumable_count = new_total - ord_total
- err = service.ModifyDrugWarehouseInfoSix(&info, id)
-
- }
-
- //查询默认仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(drugInfo.OrgId)
- //查询默认仓库剩余多少库存
- list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, drugInfo.OrgId, drugInfo.DrugId)
- var sum_count int64
- var sum_in_count int64
- for _, it := range list {
- baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- }
- sum_count += it.StockMaxNumber + it.StockMinNumber
- sum_in_count += it.WarehousingCount
- }
- service.UpdateMedicalSumCount(drugInfo.DrugId, sum_count, sum_in_count, drugInfo.OrgId)
-
- //更新剩余库存
- service.UpdateDrugStockCount(drugInfo.DrugId, drugInfo.OrgId, houseConfig.DrugStorehouseOut, sum_count)
- inventory := models.XtDrugInventory{
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: max_unit,
- Count: consumable_count,
- LastPrice: price,
- RetailPrice: 0,
- NewPrice: 0,
- Manufacturer: manufacturer_name,
- Dealer: "",
- Remark: "",
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: "",
- StartTime: locationTime.Unix(),
- Creater: this.GetAdminUserInfo().AdminUser.Id,
- Checker: 0,
- CheckerStatus: 0,
- CheckerTime: 0,
- ExpiryDate: expiry_date,
- ProductDate: 0,
- Number: "",
- BatchNumber: batch_number,
- Total: "",
- DrugOriginPlace: "",
- WarehouseInfoId: id,
- ProofCount: 0,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- MinCount: 0,
- MinUnit: min_unit,
- LastStockMaxNumber: last_stock_max_number,
- LastStockMinNumber: last_stock_min_number,
- InventoryType: consumable_type,
- Type: type_id,
- StorehouseId: storehouse_id,
- }
-
- err = service.CreateDrugInventory(inventory)
-
- flow := models.DrugFlow{
- WarehousingId: id,
- DrugId: drug_id,
- Number: "",
- BatchNumber: batch_number,
- Count: consumable_count,
- UserOrgId: orgId,
- PatientId: 0,
- SystemTime: locationTime.Unix(),
- ConsumableType: consumable_type,
- IsSys: 1,
- WarehousingOrder: warehousing_order,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: manufacturer,
- Dealer: 0,
- Creator: this.GetAdminUserInfo().AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: id,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: expiry_date,
- ProductDate: 0,
- MaxUnit: min_unit,
- MinUnit: min_unit,
- StorehouseId: storehouse_id,
- OverCount: sum_count,
- }
- if ord_total != new_total {
- service.CreateDrugFlowOne(flow)
- }
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
- }
- }
-
- func (this *SelfDrugApiController) GetDamageByDrugId() {
-
- drug_id, _ := this.GetInt64("drug_id")
- warehousing_order := this.GetString("warehouseing_order")
- drug_type, _ := this.GetInt64("type")
- list, err := service.GetDamageByDrugId(drug_id, warehousing_order, drug_type)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetInventoryModeList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, err := service.GetInventoryModeList(orgId)
- manufacturerList, err := service.GetAllManufacturerList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- })
- }
-
- // 库存优化接口
- func (this *SelfDrugApiController) GetStorehouseList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, err := service.GetAllStoreHouseList(orgId)
- manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
- goodType, _ := service.GetAllNewGoodType(orgId)
- patientList, _ := service.GetAllpatientThirty(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取仓库失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "goodTypeList": goodType,
- "patientList": patientList,
- "dealerList": dealerList,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodNewQuery() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- storehouse_id, _ := this.GetInt64("storehouse_id")
- good_type, _ := this.GetInt64("good_type")
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
-
- // 查询该机构所有耗材入库信息
- goodList, _ := service.GetAllGoodListSeven(orgId)
-
- for _, it := range goodList {
- var sum_total int64
- //查询该耗材入库信息
- warehouseinfo, _ := service.GetGoodInformationWarehouseInfo(it.ID, orgId)
- for _, item := range warehouseinfo {
- sum_total += item.StockCount
- }
- service.UpdateGoodInformation(it.ID, orgId, sum_total)
-
- //stockListTwo, _ := service.GetGoodStockCountList(orgId, it.ID)
- //if len(stockListTwo) > 0 {
- // for _, item := range stockListTwo {
- // var over_count int64
- // over_count = item.StockInCount - item.FlushCount
- // service.UpdateGoodListCount(item.UserOrgId, over_count, item.GoodId, item.StorehouseId)
- //
- // }
- //}
- //
- //stockListOne, _ := service.GetGoodStockCountList(orgId, it.ID)
- //if len(stockListOne) > 0 {
- // for _, item := range stockListOne {
- // var over_count int64
- // over_count = item.StockOutCount + item.StockCancelCount
- // service.UpdateGoodListCountOne(item.UserOrgId, over_count, item.GoodId, item.StorehouseId)
- // }
- //}
-
- }
-
- var ids []int64
-
- manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturerList {
- ids = append(ids, it.ID)
- }
-
- stockList, total, err := service.GetGoodStockList(orgId, storehouse_id, good_type, keyword, page, limit, ids)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "stockList": stockList,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodWarehouseOutInfoByIdList() {
-
- good_id, _ := this.GetInt64("good_id")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- start_time := this.GetString("start_first_time")
- end_time := this.GetString("end_first_time")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, total, err := service.GetGoodWarehouseOutInfoByIdList(good_id, limit, page, orgId, startTime, endTime, storehouse_id)
- //flushList, _ := service.GetStockFlushByGoodId(good_id, orgId, startTime, endTime)
-
- //warehouseInfoByList, _ := service.GetGoodWarehouseInfoByList(good_id, orgId, startTime, endTime)
- //cancelStockInfoByList, _ := service.GetGoodCancelStockInfoByList(good_id, orgId, startTime, endTime)
- //warehouseOutByList,_ := service.GetGoodWarehouseOutInfoByIdListTwenty(good_id, limit, page, orgId, startTime, endTime)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- //"warehouseInfoByList":warehouseInfoByList,
- //"cancelStockInfoByList":cancelStockInfoByList,
- //"warehouseOutByList":warehouseOutByList,
- //"flushList":flushList,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodPatientList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
- list, err := service.GetGoodPatientList(orgId, keyword)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetWarehouseOutDetailByPatientId() {
-
- patient_id, _ := this.GetInt64("patient_id")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, total, err := service.GetWarehouseOutDetailByPatientIdOne(orgId, patient_id, startTime, endTime, limit, page)
- outlist, _ := service.GetWarehouseOutDetailByPatientId(orgId, patient_id, startTime, endTime)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "outlist": outlist,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodExpiryDateQuery() {
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
- expiry_type, _ := this.GetInt64("expiry_type")
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- start_time := this.GetString("start_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var endTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- fmt.Scan("parseDateErr", parseDateErr)
- nowtime := recordDate.Unix()
-
- var ids []int64
- var goodIds []int64
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- goodList, _ := service.GetGoodNameByword(orgId, keyword)
- for _, it := range goodList {
- goodIds = append(goodIds, it.ID)
- }
- list, total, err := service.GetGoodExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
- fmt.Println("total233223322332323232323223", total)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "nowtime": nowtime,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodPurchaseStockQuery() {
-
- good_type, _ := this.GetInt64("good_type")
-
- keyword := this.GetString("keyword")
-
- page, _ := this.GetInt64("page")
-
- limit, _ := this.GetInt64("limit")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var goodIds []int64
- infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
- for _, it := range infoList {
- goodIds = append(goodIds, it.GoodId)
- }
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- list, total, err := service.GetGoodPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
- storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
- for _, item := range list {
-
- //获取期初结余数量
- infoList, _ := service.GetStartGoodWarehouseInfoList(item.ID, orgId, startTime)
- for _, it := range infoList {
- item.WarehousingInfoStart = append(item.WarehousingInfoStart, it)
- }
-
- //获取期末结余数量
- warehouseInfoList, _ := service.GetEndGoodWarehouseInfoList(item.ID, orgId, endTime)
- for _, it := range warehouseInfoList {
- item.WarehousingInfoEnd = append(item.WarehousingInfoEnd, it)
- }
-
- //获取期间增加
- goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range goodWarehouseInfoList {
- item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
- }
-
- //获取本期增加
- WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range WarehouseInfoFlowList {
- item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
- }
- //获取本期减少
- reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range reduceWarehouseInfoList {
- item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
- }
-
- //获取期中减少退库
- lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range lowInfo {
- item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
- }
- //
- outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
- for _, it := range outInfo {
- item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
- }
-
- //获取期初结余
- info, _ := service.FindeStartFlowInfo(item.ID, orgId, startTime)
- for _, it := range info {
- item.StartFlowInfo = append(item.StartFlowInfo, it)
- }
- //获取期初结余
- flowOutInfo, _ := service.FindeStartFlowOutInfo(item.ID, orgId, startTime)
- for _, it := range flowOutInfo {
- item.StartOutFlowInfo = append(item.StartOutFlowInfo, it)
- }
-
- //获取期初退库
- cancelInfo, _ := service.FindeStartCancelInfo(item.ID, orgId, startTime)
- for _, it := range cancelInfo {
- item.StartCancelFlowInfo = append(item.StartCancelFlowInfo, it)
- }
-
- //获取期末结余
- flowInfo, _ := service.FindEndStartFlowInfo(item.ID, orgId, endTime)
- for _, it := range flowInfo {
- item.EndFlowInfo = append(item.EndFlowInfo, it)
- }
-
- //获取期末出库
- lowOutInfo, _ := service.FindeEndFLowOutInfo(item.ID, orgId, endTime)
- for _, it := range lowOutInfo {
- item.EndFlowOutInfo = append(item.EndFlowOutInfo, it)
- }
-
- //获取期末退库
- endCancelInfo, _ := service.FindEndCancelInfo(item.ID, orgId, endTime)
- for _, it := range endCancelInfo {
- item.EndCancelFLowInfo = append(item.EndCancelFLowInfo, it)
- }
-
- //期初盘赢
- inventory, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, startTime)
- for _, it := range inventory {
- item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
- }
- //期初盘亏
- stockInventory, _ := service.FindStartStockInventoryLosses(item.ID, orgId, startTime)
- for _, it := range stockInventory {
- item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
- }
-
- //期末盘盈
- inventoryProfit, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, endTime)
- for _, it := range inventoryProfit {
- item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
- }
- //期末盘亏
- inventoryLosses, _ := service.FindStartStockInventoryLosses(item.ID, orgId, endTime)
- for _, it := range inventoryLosses {
- item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
- }
-
- //期中盘盈
- profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
- //期中盘亏
- losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range losses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugWarehouseOutDetailByPatientId() {
-
- patient_id, _ := this.GetInt64("patient_id")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, total, _ := service.GetDrugWarehouseOutDetailByPatientIdOne(patient_id, orgId, startTime, endTime, page, limit)
- outlist, _ := service.GetDrugWarehouseOutDetailByPatientId(patient_id, orgId, startTime, endTime)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "manufacturerList": manufacturerList,
- "outlist": outlist,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugExpiryDateQuery() {
- storehouse_id, _ := this.GetInt64("storehouse_id")
- expiry_type, _ := this.GetInt64("expiry_type")
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- start_time := this.GetString("start_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var endTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- fmt.Scan("parseDateErr", parseDateErr)
- nowtime := recordDate.Unix()
-
- var ids []int64
- var goodIds []int64
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- drugList, _ := service.GetDrugNameByword(orgId, keyword)
- for _, it := range drugList {
- goodIds = append(goodIds, it.ID)
- }
- list, total, err := service.GetDrugExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "nowtime": nowtime,
- "drugTypeList": drugTypeList,
- })
- }
-
- func (this *SelfDrugApiController) GetPurchaseDrugQuery() {
- good_type, _ := this.GetInt64("good_type")
-
- keyword := this.GetString("keyword")
-
- page, _ := this.GetInt64("page")
-
- limit, _ := this.GetInt64("limit")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
-
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var infoIds []int64
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
- for _, it := range infoList {
- infoIds = append(infoIds, it.DrugId)
- }
- manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
- list, total, err := service.GetDrugPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
-
- for _, item := range list {
-
- //获取期初结余入库数量
- startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
- for _, it := range startDrugInfo {
- item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
- }
-
- //获取期初结余出库数量
- flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
- for _, it := range flowOutList {
- item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
- }
-
- //获取期初结余退库数量
- cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
- for _, it := range cancelInfo {
- item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
- }
-
- //获取期末结余入库数量
- drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
- for _, it := range drugwarehouseinfoend {
- item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
- }
-
- //获取期末出库结余
- endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
- for _, it := range endDrugInfo {
- item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
- }
-
- //获取期末退库数量
- flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
- for _, it := range flowCancelInfo {
- item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
- }
-
- //期中增加
- drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
- for _, it := range drugWarehouse {
- item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
- }
-
- //期中减少
- outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- for _, it := range outInfo {
- item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
- }
-
- //期中退库
- cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- for _, it := range cancelstartInfo {
- item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
- }
-
- //获取期初盘盈
- startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
- for _, it := range startProfit {
- item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
- }
- //获取期初盘亏
- startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
- for _, it := range startLosses {
- item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
- }
- //获取期末盘盈
- endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
- for _, it := range endProfit {
- item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
- }
- //获取期末盘亏
- losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
- for _, it := range losses {
- item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
- }
-
- //获取期中盘盈
- profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
-
- //获取期中盘亏
- endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
- for _, it := range endLosses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "drugTypeList": drugTypeList,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugNewQuery() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- storehouse_id, _ := this.GetInt64("storehouse_id")
- good_type, _ := this.GetInt64("good_type")
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var goodIds []int64
- manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
-
- //查询药品库信息
- drug, _ := service.GetBaseDrugName(orgId)
-
- for _, it := range drug {
- var sum_count int64
- var limit_count int64
- drugInfo, _ := service.GetDrugWarehouseInfoName(it.ID, orgId)
- for _, item := range drugInfo {
-
- sum_count += item.StockMaxNumber*it.MinNumber + item.StockMinNumber
- }
- stockInt, _ := strconv.ParseInt(it.DrugStockLimit, 10, 64)
- limit_count = stockInt * it.MinNumber
- service.UpdateDrugById(it.ID, orgId, limit_count, sum_count)
-
- //druglist, _ := service.GetDrugCountMapList(it.ID, orgId)
- //if len(druglist) > 0 {
- // for _, item := range druglist {
- // var over_count int64
- // over_count = item.SumInCount - item.FlushCount
- // service.UpdateDrugStockInCount(item.DrugId, item.StorehouseId, over_count, item.UserOrgId)
- // }
- //}
-
- //druglistOne, _ := service.GetDrugCountMapList(it.ID, orgId)
- //if len(druglistOne) > 0 {
- // for _, item := range druglistOne {
- // var over_count int64
- // over_count = item.SumOutCount + item.SumCancelCount
- // service.UpdateDrugStockInCountOne(item.DrugId, item.StorehouseId, over_count, item.UserOrgId)
- // }
- //}
- }
-
- for _, it := range manufacturerList {
- ids = append(ids, it.ID)
- }
- infoList, _ := service.GetDrugWarehouseInfoByOrgId(orgId, storehouse_id)
- for _, it := range infoList {
- goodIds = append(goodIds, it.DrugId)
- }
-
- countList, total, err := service.GetDrugStockCountList(orgId, storehouse_id, good_type, keyword, page, limit, ids, goodIds, startTime, endTime)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
- return
- }
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "drugTypeList": drugTypeList,
- "countList": countList,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugWarehouseInfoById() {
-
- drug_id, _ := this.GetInt64("drug_id")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- start_time := this.GetString("start_first_time")
- end_time := this.GetString("end_first_time")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, total, err := service.GetDrugWarehouseOutInfoByIdList(drug_id, limit, page, orgId, startTime, endTime, storehouse_id)
- flushList, _ := service.GetDrugFlowFlush(drug_id, orgId, startTime, endTime)
- flushOne, _ := service.GetDrugFlowFlushOne(drug_id, orgId, startTime, endTime)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "flushList": flushList,
- "flushListOne": flushOne,
- })
- }
-
- func (this *SelfDrugApiController) GetSendGoodInformation() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- fmt.Println("orgid", orgId)
- list, _ := service.GetWarehouseOutInfo(10485)
-
- for _, it := range list {
- service.UpdateWarehosueOutInfo(it.ID, it.WarehouseOutTime)
- }
-
- //获取入库数据
- //list, _ := service.GetSendGoodInformation(10265)
- //
- ////project, _ := service.GetHisPrescriptionList(10265)
- //
- //for _, it := range list {
- // service.UpdateGoodFlow(it.ID, it.PackingPrice)
- //}
-
- //for _, it := range list {
- // //查询是否有数据
- // _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
- // //获取总退库数量
- // var cancel_count int64
- // var out_count int64
- // var act_count int64
- // //退库总数量
- // cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
- // for _, item := range cancellist {
- // cancel_count += item.Count
- // }
- // //出库总数量
- // outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
- // for _, item := range outlist {
- // out_count += item.Count
- // }
- //
- // //实际出库总数量
- // actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
- // for _, item := range actlist {
- // act_count += item.Count
- // }
- //
- // if errcode == gorm.ErrRecordNotFound {
- // good := models.XtGoodStockCount{
- // UserOrgId: it.OrgId,
- // GoodId: it.GoodId,
- // StorehouseId: it.StorehouseId,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // StockInCount: it.WarehousingCount,
- // StockOutCount: out_count - cancel_count,
- // StockCancelCount: cancel_count,
- // FlushCount: it.StockCount,
- // StockActOutCount: act_count,
- // }
- // service.CreateGoodCountSix(good)
- // }
- // if errcode == nil {
- // service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
- // }
- //}
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
- }
-
- func (this *SelfDrugApiController) GetDrugInitDetailList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- //获取所有的入库仓库
- list, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
- for _, item := range list {
- //查询该药品该仓库是否有数据
- drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
-
- //查询该仓库该药品的入库数量
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
-
- var sum_in_count int64
- var flush_count int64
- var sum_out_count int64
- var cancel_out_count int64
- //查询入库数量和剩余库存
- infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
- for _, it := range infolist {
- if it.MaxUnit == medical.MaxUnit {
- it.WarehousingCount = it.WarehousingCount * medical.MinNumber
- it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
- }
- sum_in_count += it.WarehousingCount
- flush_count += it.StockMaxNumber + it.StockMinNumber
- }
-
- //获取出库数量
- outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
- for _, it := range outinfolist {
- if it.MaxUnit == medical.MaxUnit {
- it.Count = it.Count * medical.MinNumber
- }
- sum_out_count += it.Count
- }
-
- //获取退库数量
- cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
- for _, it := range cancelinfolist {
- if it.MaxUnit == medical.MaxUnit {
- it.Count = it.Count * medical.MinNumber
- }
- cancel_out_count += it.Count
- }
-
- //新增
- if drug.ID == 0 {
- drugstock := models.XtDrugStockCount{
- UserOrgId: orgId,
- StorehouseId: item.StorehouseId,
- SumInCount: sum_in_count,
- SumOutCount: sum_out_count - cancel_out_count,
- SumCancelCount: cancel_out_count,
- DrugId: item.DrugId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- FlushCount: flush_count,
- SumActOutCount: sum_out_count,
- }
- service.CreateDrugStockCount(drugstock)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
- }
-
- func (this *SelfDrugApiController) GetGoodNewPurchaseStockQuery() {
-
- good_type, _ := this.GetInt64("good_type")
-
- keyword := this.GetString("keyword")
-
- page, _ := this.GetInt64("page")
-
- limit, _ := this.GetInt64("limit")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
-
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var goodIds []int64
- infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
- for _, it := range infoList {
- goodIds = append(goodIds, it.GoodId)
- }
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
-
- if orgId == 10265 {
- //storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
-
- list, total, err := service.GetGoodNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
-
- for _, item := range list {
-
- //获取期初结余
- low, _ := service.GetStartLastFLowTwenty(item.ID, orgId, startTime)
-
- item.GoodStartFlowInfo = low
-
- //获取期末结余
- flow, _ := service.GetEndLastFlowTwenty(item.ID, orgId, endTime)
-
- item.GoodEndFlowInfo = flow
-
- //获取期间增加
- goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
- for _, it := range goodWarehouseInfoList {
- item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
- }
-
- //获取本期增加
- WarehouseInfoFlowList, _ := service.GetAddStartFlowTwenty(item.ID, orgId, startTime, endTime)
- for _, it := range WarehouseInfoFlowList {
- item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
- }
- //获取本期减少
- reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
- for _, it := range reduceWarehouseInfoList {
- item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
- }
-
- //获取期中减少退库
- lowInfo, _ := service.GetStartEndCancelFLowInfoTwenty(item.ID, orgId, startTime, endTime)
- for _, it := range lowInfo {
- item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
- }
- //
- outInfo, _ := service.FindeWarehouseOutInfoTwenty(item.ID, orgId, startTime)
- for _, it := range outInfo {
- item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
- }
-
- //期中盘盈
- profit, _ := service.FindeEndStokInventoryProfitTwenty(item.ID, orgId, startTime, endTime)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
- //期中盘亏
- losses, _ := service.FindeEndStockInventoryLossesTwenty(item.ID, orgId, startTime, endTime)
- for _, it := range losses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- })
- }
-
- if orgId != 10265 {
- list, total, err := service.GetGoodNewPurchaseStockQueryOne(good_type, keyword, page, limit, orgId, ids, goodIds)
- storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
- for _, item := range list {
-
- //获取期初结余
- low, _ := service.GetStartLastFLow(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
-
- item.GoodStartFlowInfo = low
-
- //获取期末结余
- flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime, storeConfig.StorehouseOutInfo)
-
- item.GoodEndFlowInfo = flow
-
- //获取期间增加
- goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
-
- for _, it := range goodWarehouseInfoList {
- item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
- }
-
- //获取本期增加
- WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
-
- for _, it := range WarehouseInfoFlowList {
- item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
- }
- //获取本期减少
- reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range reduceWarehouseInfoList {
- item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
- }
-
- //获取期中减少退库
- lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range lowInfo {
- item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
- }
- //
- outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
- for _, it := range outInfo {
- item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
- }
-
- //期中盘盈
- profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
- //期中盘亏
- losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
- for _, it := range losses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- })
- }
-
- }
-
- func (this *SelfDrugApiController) GetPurchaseNewDrugQuery() {
-
- good_type, _ := this.GetInt64("good_type")
-
- keyword := this.GetString("keyword")
-
- page, _ := this.GetInt64("page")
-
- limit, _ := this.GetInt64("limit")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
-
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var infoIds []int64
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
- for _, it := range infoList {
- infoIds = append(infoIds, it.DrugId)
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- list, total, err := service.GetDrugNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
-
- for _, item := range list {
-
- //获取期初结余
- flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
-
- item.DrugStatFlow = flow
-
- //获取期末结余
- endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
-
- item.DrugEndFlow = endFlow
- //获取期初结余入库数量
- //startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
- //for _, it := range startDrugInfo {
- // item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
- //}
- //
- ////获取期初结余出库数量
- //flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
- //for _, it := range flowOutList {
- // item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
- //}
- //
- ////获取期初结余退库数量
- //cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
- //for _, it := range cancelInfo {
- // item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
- //}
- //
- ////获取期末结余入库数量
- //drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
- //for _, it := range drugwarehouseinfoend {
- // item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
- //}
-
- ////获取期末出库结余
- //endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
- //for _, it := range endDrugInfo {
- // item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
- //}
- //
- ////获取期末退库数量
- //flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
- //for _, it := range flowCancelInfo {
- // item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
- //}
-
- //期中增加
- drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
- for _, it := range drugWarehouse {
- item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
- }
-
- //期中减少
- outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- fmt.Println("putInfo2o2o2oo2o2", outInfo)
- for _, it := range outInfo {
- item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
- }
-
- //期中退库
- cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- for _, it := range cancelstartInfo {
- item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
- }
-
- ////获取期初盘盈
- //startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
- //for _, it := range startProfit {
- // item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
- //}
- ////获取期初盘亏
- //startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
- //for _, it := range startLosses {
- // item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
- //}
- ////获取期末盘盈
- //endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
- //for _, it := range endProfit {
- // item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
- //}
- ////获取期末盘亏
- //losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
- //for _, it := range losses {
- // item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
- //}
-
- //获取期中盘盈
- profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
-
- //获取期中盘亏
- endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
- for _, it := range endLosses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "drugTypeList": drugTypeList,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodOverCount() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetAllStockCount(orgId)
- for _, item := range list {
- flow, _ := service.GetLastStockFlow(item.GoodId)
- service.ModifyStockFlowById(flow.ID, item.FlushCount)
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) GetDrugOverCount() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetAllDrugCount(orgId)
- for _, item := range list {
- service.GetLastDrugFlow(item.DrugId)
- service.ModifyDrugFlowById(item.ID, item.FlushCount)
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryWarehouseInfoList() {
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetDrugInventoryWarehouseInfoList(orgId, storehouse_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- }
-
- func (this *SelfDrugApiController) GetInventoryDetailPrintList() {
- keyword := this.GetString("keyword")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- ids := this.GetString("ids")
- idSplit := strings.Split(ids, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, err := service.GetDrugInventoryDetailMapList(keyword, page, limit, orgId, storehouse_id, idSplit)
- inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- doctorList, _ := service.GetAllDoctorThree(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "doctorList": doctorList,
- "houseList": houseList,
- "inventoryList": inventoryList,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugFlowDetailById() {
-
- drug_id, _ := this.GetInt64("drug_id")
-
- list, _ := service.GetDrugFlowDetailById(drug_id)
-
- drugMedical, _ := service.GetBaseDrugMedical(drug_id)
-
- for index, _ := range list {
- if list[index].ConsumableType == 3 || list[index].ConsumableType == 2 || list[index].ConsumableType == 11 || list[index].ConsumableType == 12 || list[index].ConsumableType == 15 {
- var count int64
- if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
- list[index].Count = list[index].Count * drugMedical.MinNumber
- }
-
- if index == 0 {
- count = list[index].FlushOverCount - list[index].Count
- service.UpdateDrugOverCount(list[index+1].ID, count)
- }
-
- if index >= 1 {
- lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
- count = lastStockFlow.FlushOverCount - list[index].Count
- service.UpdateDrugOverCount(list[index].ID, count)
- }
-
- }
- if list[index].ConsumableType == 7 || list[index].ConsumableType == 4 || list[index].ConsumableType == 1 || list[index].ConsumableType == 10 || list[index].ConsumableType == 13 {
- if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
- list[index].Count = list[index].Count * drugMedical.MinNumber
- }
- if index == 0 {
- var count int64
- count = list[index].OverCount + list[index].Count
- service.UpdateDrugOverCount(list[index+1].ID, count)
- }
-
- if index >= 1 {
- var count int64
- lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
- count = lastStockFlow.FlushOverCount + list[index].Count
- service.UpdateDrugOverCount(list[index].ID, count)
- }
-
- }
-
- }
- }
-
- func (this *SelfDrugApiController) GetPurchaseDrugQueryList() {
-
- good_type, _ := this.GetInt64("good_type")
-
- keyword := this.GetString("keyword")
-
- page, _ := this.GetInt64("page")
-
- limit, _ := this.GetInt64("limit")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
-
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var infoIds []int64
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
- for _, it := range infoList {
- infoIds = append(infoIds, it.DrugId)
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- list, total, err := service.GetDrugNewPurchaseStockQueryList(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
-
- for _, item := range list {
-
- //获取期初结余
- flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
-
- item.DrugStatFlow = flow
-
- //获取期末结余
- endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
-
- item.DrugEndFlow = endFlow
- //获取期初结余入库数量
-
- //期中增加
- drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
- for _, it := range drugWarehouse {
- item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
- }
-
- //期中减少
- outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- for _, it := range outInfo {
- item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
- }
-
- //期中退库
- cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- for _, it := range cancelstartInfo {
- item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
- }
-
- //获取期中盘盈
- profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
-
- //获取期中盘亏
- endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
- for _, it := range endLosses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "drugTypeList": drugTypeList,
- })
- }
|