self_drug_api_congtroller.go 143KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type SelfDrugApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func SelfDrugRouters() {
  20. beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
  21. beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
  22. beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
  23. beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
  24. beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
  25. beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
  26. beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
  27. beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
  28. beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
  29. beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
  30. beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
  31. beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
  32. beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
  33. beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
  34. beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
  35. beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
  36. beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
  37. beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
  38. beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
  39. beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
  40. beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
  41. beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
  42. beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
  43. beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
  44. beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
  45. beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
  46. beego.Router("/api/drug/getallmedicallist", &SelfDrugApiController{}, "Get:GetAllMedicalList")
  47. beego.Router("/api/drug/getstandname", &SelfDrugApiController{}, "Get:GetStandName")
  48. beego.Router("/api/drug/getrullerlist", &SelfDrugApiController{}, "Get:GetRullerList")
  49. beego.Router("/api/drug/deleteDrugNamebyid", &SelfDrugApiController{}, "Get:DeleteDrugNameById")
  50. beego.Router("/api/drug/getpatientdetail", &SelfDrugApiController{}, "Get:GetPatientDetail")
  51. //beego.Router("/api/drug/getpatientdetail",&SelfDrugApiController{},"Get:ToPatientDetail")
  52. beego.Router("/api/drug/getselfstockquery", &SelfDrugApiController{}, "Get:GetSelfStockQuery")
  53. beego.Router("/api/drug/postsearchdrugwarehouselist", &SelfDrugApiController{}, "Get:PostSearchDrugWarehouseList")
  54. beego.Router("/api/drug/savedrugpriceone", &SelfDrugApiController{}, "Post:SaveDrugPrice")
  55. beego.Router("/api/drug/drugpricelist", &SelfDrugApiController{}, "Get:GetDrugPriceList")
  56. beego.Router("/api/drug/savecheckdrugprice", &SelfDrugApiController{}, "Get:SaveCheckDrugPrice")
  57. beego.Router("/api/drug/savedrugdamageone", &SelfDrugApiController{}, "Post:SaveDrugDamage")
  58. beego.Router("/api/drug/getdrugdamagelist", &SelfDrugApiController{}, "Get:GetDrugDamageList")
  59. beego.Router("/api/drug/savedrugdamageprice", &SelfDrugApiController{}, "Get:SaveDrugDamagePrice")
  60. beego.Router("/api/drug/getdrugmodifyprice", &SelfDrugApiController{}, "Get:GetDrugModifyPrice")
  61. beego.Router("/api/drug/modifydrugprice", &SelfDrugApiController{}, "Get:ModifyDrugPrice")
  62. beego.Router("/api/drug/getmodifypriceprint", &SelfDrugApiController{}, "Get:GetModifyPricePrint")
  63. beego.Router("/api/drug/getdrugdamagedetail", &SelfDrugApiController{}, "Get:GetDrugDamageDetail")
  64. beego.Router("/api/drug/modifydrugdamage", &SelfDrugApiController{}, "Get:ModifyDrugDamage")
  65. beego.Router("/api/drug/deletedrugdamage", &SelfDrugApiController{}, "Get:DeleteDrugDamage")
  66. beego.Router("/api/drug/getdrugdamageprint", &SelfDrugApiController{}, "Get:GetDrugDamagePrint")
  67. beego.Router("/api/drug/warehouseinfobyid", &SelfDrugApiController{}, "Get:GetWarehoseInfoById")
  68. beego.Router("/api/drug/savedruginventory", &SelfDrugApiController{}, "Post:SaveDrugInventory")
  69. beego.Router("/api/drug/getdruginventorylist", &SelfDrugApiController{}, "Get:GetDrugInventoryList")
  70. beego.Router("/api/drug/savedrugcheckinventory", &SelfDrugApiController{}, "Get:SaveDrugCheckInventory")
  71. beego.Router("/api/drug/getdruginventorydetail", &SelfDrugApiController{}, "Get:GetDrugInventoryDetail")
  72. beego.Router("/api/drug/modifyinventory", &SelfDrugApiController{}, "Get:ModifyInventory")
  73. beego.Router("/api/drug/deletedruginventory", &SelfDrugApiController{}, "Get:DeleteDrugInventory")
  74. beego.Router("/api/drug/getdruginventoryprintlist", &SelfDrugApiController{}, "Get:GetDrugInventoryPrintList")
  75. beego.Router("/api/drug/getinventorydetaillist", &SelfDrugApiController{}, "Get:GetDrugInventoryDetailList")
  76. beego.Router("/api/drug/getinventorydetailprintlist", &SelfDrugApiController{}, "Get:GetInventoryDetailPrintList")
  77. beego.Router("/api/drug/savedrugproofinventory", &SelfDrugApiController{}, "Get:SaveDrugProofInventory")
  78. beego.Router("/api/drug/getdrugwarehouseinfototal", &StockManagerApiController{}, "Get:GetDrugWarehouseInfoTotal")
  79. beego.Router("/api/drug/saveinentorylist", &SelfDrugApiController{}, "Post:SaveInventoryList")
  80. beego.Router("/api/drug/getdamagebydrugid", &SelfDrugApiController{}, "Get:GetDamageByDrugId")
  81. beego.Router("/api/drug/getinventorymodelist", &SelfDrugApiController{}, "Get:GetInventoryModeList")
  82. //耗材库存优化接口
  83. beego.Router("/api/drug/getstorehouselist", &SelfDrugApiController{}, "Get:GetStorehouseList")
  84. beego.Router("/api/drug/getgoodnewquery", &SelfDrugApiController{}, "Get:GetGoodNewQuery")
  85. beego.Router("/api/drug/getgoodwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetGoodWarehouseOutInfoByIdList")
  86. beego.Router("/api/good/getgoodpatientlist", &SelfDrugApiController{}, "Get:GetGoodPatientList")
  87. beego.Router("/api/good/getwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetWarehouseOutDetailByPatientId")
  88. beego.Router("/api/good/getgoodexpirydatequery", &SelfDrugApiController{}, "Get:GetGoodExpiryDateQuery")
  89. beego.Router("/api/good/getpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodPurchaseStockQuery")
  90. //药品库存优化接口
  91. beego.Router("/api/good/getdrugwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetDrugWarehouseOutDetailByPatientId")
  92. beego.Router("/api/drug/getdrugexpirydatequery", &SelfDrugApiController{}, "Get:GetDrugExpiryDateQuery")
  93. beego.Router("/api/drug/getpurchasedrugquery", &SelfDrugApiController{}, "Get:GetPurchaseDrugQuery")
  94. beego.Router("/api/drug/getdrugnewquery", &SelfDrugApiController{}, "Get:GetDrugNewQuery")
  95. beego.Router("/api/drug/getdrugwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetDrugWarehouseInfoById")
  96. //耗材脚本
  97. beego.Router("/api/stock/tosendgoodinfomation", &SelfDrugApiController{}, "Get:GetSendGoodInformation")
  98. //药品脚本
  99. beego.Router("/api/drug/getdruginitdatalist", &SelfDrugApiController{}, "Get:GetDrugInitDetailList")
  100. //新数据
  101. beego.Router("/api/stock/getnewpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodNewPurchaseStockQuery")
  102. beego.Router("/api/stock/getpurchasenewdrugquery", &SelfDrugApiController{}, "Get:GetPurchaseNewDrugQuery")
  103. beego.Router("/api/stock/getgoodovercount", &SelfDrugApiController{}, "Get:GetGoodOverCount")
  104. beego.Router("/api/stock/getdrugovercount", &SelfDrugApiController{}, "Get:GetDrugOverCount")
  105. beego.Router("/api/stock/getdruginfolist", &SelfDrugApiController{}, "Get:GetDrugInventoryWarehouseInfoList")
  106. beego.Router("/api/drug/getdrugflowdetailbyid", &SelfDrugApiController{}, "Get:GetDrugFlowDetailById")
  107. //康允新版本
  108. beego.Router("/api/stock/getpurchaseDrugQueryList", &SelfDrugApiController{}, "Get:GetPurchaseDrugQueryList")
  109. }
  110. func (this *SelfDrugApiController) GetCurrentPatient() {
  111. adminUserInfo := this.GetAdminUserInfo()
  112. orgId := adminUserInfo.CurrentOrgId
  113. patient, err := service.GetCurrentPatient(orgId)
  114. if err != nil {
  115. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  116. return
  117. }
  118. this.ServeSuccessJSON(map[string]interface{}{
  119. "patient": patient,
  120. })
  121. }
  122. func (this *SelfDrugApiController) GetAllDrugName() {
  123. adminUserInfo := this.GetAdminUserInfo()
  124. orgId := adminUserInfo.CurrentOrgId
  125. //查询药品库是否开启
  126. //configStock, _ := service.GetDrugStockConfig(orgId)
  127. //if configStock.IsOpen == 1 {
  128. //
  129. //}
  130. drugName, err := service.GetAllDrugName(orgId)
  131. if err != nil {
  132. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
  133. return
  134. }
  135. this.ServeSuccessJSON(map[string]interface{}{
  136. "drugName": drugName,
  137. })
  138. }
  139. func (this *SelfDrugApiController) SaveDrugName() {
  140. adminUserInfo := this.GetAdminUserInfo()
  141. orgId := adminUserInfo.CurrentOrgId
  142. drug_name := this.GetString("drug_name")
  143. id, _ := this.GetInt64("id")
  144. //fmt.Println("drug_name", drug_name)
  145. drugName := models.XtDrugName{
  146. UserOrgId: orgId,
  147. DrugName: drug_name,
  148. Status: 1,
  149. CreatedTime: time.Now().Unix(),
  150. DrugId: id,
  151. }
  152. _, errcode := service.GetDrugName(drug_name, orgId)
  153. if errcode == gorm.ErrRecordNotFound {
  154. err := service.SaveDrugName(&drugName)
  155. if err != nil {
  156. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  157. return
  158. }
  159. this.ServeSuccessJSON(map[string]interface{}{
  160. "drugName": drugName,
  161. })
  162. } else {
  163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  164. return
  165. }
  166. }
  167. func (this *SelfDrugApiController) GetDrugNameList() {
  168. adminUserInfo := this.GetAdminUserInfo()
  169. orgId := adminUserInfo.CurrentOrgId
  170. list, err := service.GetDrugNameList(orgId)
  171. if err != nil {
  172. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  173. return
  174. }
  175. this.ServeSuccessJSON(map[string]interface{}{
  176. "list": list,
  177. })
  178. }
  179. func (this *SelfDrugApiController) GetRulleName() {
  180. adminUserInfo := this.GetAdminUserInfo()
  181. orgId := adminUserInfo.CurrentOrgId
  182. id, _ := this.GetInt64("id")
  183. drugId, _ := service.GetDrugId(id)
  184. rullerList, err := service.GetRulleList(orgId, drugId.DrugId)
  185. if err != nil {
  186. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  187. return
  188. }
  189. this.ServeSuccessJSON(map[string]interface{}{
  190. "rullerList": rullerList,
  191. })
  192. }
  193. func (this *SelfDrugApiController) GetUnitByBaseId() {
  194. id, _ := this.GetInt64("id")
  195. baseList, err := service.GetUnitByBaseId(id)
  196. if err != nil {
  197. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  198. return
  199. }
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "baseList": baseList,
  202. })
  203. }
  204. func (this *SelfDrugApiController) SaveRulleName() {
  205. drug_name := this.GetString("drug_name")
  206. drug_spec := this.GetString("drug_spec")
  207. drug_stock_limit := this.GetString("drug_stock_limit")
  208. drug_name_id, _ := this.GetInt64("drug_name_id")
  209. drug_id, _ := this.GetInt64("drug_id")
  210. price, _ := this.GetInt64("price")
  211. prices := strconv.FormatInt(price, 10)
  212. durg_price, _ := strconv.ParseFloat(prices, 64)
  213. unit := this.GetString("unit")
  214. adminUserInfo := this.GetAdminUserInfo()
  215. orgId := adminUserInfo.CurrentOrgId
  216. fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
  217. drugSpecName := models.XtStandName{
  218. DrugName: drug_name,
  219. DrugSpec: drug_spec,
  220. DrugStockLimit: drug_stock_limit,
  221. DrugNameId: drug_name_id,
  222. Price: durg_price,
  223. MinUnit: unit,
  224. UserOrgId: orgId,
  225. Status: 1,
  226. CreatedTime: time.Now().Unix(),
  227. DrugId: drug_id,
  228. }
  229. //查询该机构下药品规格名称是否存在
  230. _, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
  231. if errcode == gorm.ErrRecordNotFound {
  232. err := service.SaveRulleName(&drugSpecName)
  233. if err != nil {
  234. this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
  235. return
  236. }
  237. this.ServeSuccessJSON(map[string]interface{}{
  238. "RullerName": drugSpecName,
  239. })
  240. } else if errcode == nil {
  241. this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
  242. return
  243. }
  244. }
  245. func (this *SelfDrugApiController) EditRullerName() {
  246. id, _ := this.GetInt64("id")
  247. rullerDetail, err := service.GetRullerNameDetail(id)
  248. if err != nil {
  249. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  250. return
  251. }
  252. this.ServeSuccessJSON(map[string]interface{}{
  253. "rullerDetail": rullerDetail,
  254. })
  255. }
  256. func (this *SelfDrugApiController) UpdatedRullerName() {
  257. id, _ := this.GetInt64("id")
  258. drug_name := this.GetString("drug_name")
  259. drug_stock_limit := this.GetString("drug_stock_limit")
  260. price, _ := this.GetInt64("price")
  261. prices := strconv.FormatInt(price, 10)
  262. durg_price, _ := strconv.ParseFloat(prices, 64)
  263. drug_spec := this.GetString("drug_spec")
  264. unit := this.GetString("unit")
  265. drug_name_id, _ := this.GetInt64("drug_name_id")
  266. drug_id, _ := this.GetInt64("drug_id")
  267. RullerName := models.XtStandName{
  268. DrugName: drug_name,
  269. DrugStockLimit: drug_stock_limit,
  270. Price: durg_price,
  271. DrugSpec: drug_spec,
  272. MinUnit: unit,
  273. DrugNameId: drug_name_id,
  274. DrugId: drug_id,
  275. }
  276. _, errcode := service.GetIsExit(drug_name, drug_spec, id)
  277. if errcode == gorm.ErrRecordNotFound {
  278. err := service.UpdatedRullerName(id, &RullerName)
  279. if err != nil {
  280. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  281. return
  282. }
  283. this.ServeSuccessJSON(map[string]interface{}{
  284. "RullerName": RullerName,
  285. })
  286. } else if errcode == nil {
  287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  288. return
  289. }
  290. }
  291. func (this *SelfDrugApiController) GetAllDrugNameList() {
  292. adminUserInfo := this.GetAdminUserInfo()
  293. orgId := adminUserInfo.CurrentOrgId
  294. rullerName, err := service.GetAllDrugNameList(orgId)
  295. list, err := service.GetMedicalDrugNameList(orgId)
  296. if err != nil {
  297. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  298. return
  299. }
  300. this.ServeSuccessJSON(map[string]interface{}{
  301. "rullerName": rullerName,
  302. "list": list,
  303. })
  304. }
  305. func (this *SelfDrugApiController) GetRullerListByDrugName() {
  306. id := this.GetString("id")
  307. adminUserInfo := this.GetAdminUserInfo()
  308. orgId := adminUserInfo.CurrentOrgId
  309. fmt.Println("orgid", orgId)
  310. drugName, err := service.GetRullerListByDrugName(id, orgId)
  311. if err != nil {
  312. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  313. return
  314. }
  315. this.ServeSuccessJSON(map[string]interface{}{
  316. "drugName": drugName,
  317. })
  318. }
  319. func (this *SelfDrugApiController) SaveSelfMedicines() {
  320. dataBody := make(map[string]interface{}, 0)
  321. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  322. fmt.Println(err)
  323. patient_id := int64(dataBody["patient_id"].(float64))
  324. medicineData, _ := dataBody["medicineData"].([]interface{})
  325. adminUserInfo := this.GetAdminUserInfo()
  326. orgId := adminUserInfo.CurrentOrgId
  327. for _, item := range medicineData {
  328. items := item.(map[string]interface{})
  329. drug_name := items["drug_name"].(string)
  330. drug_name_id := int64(items["drug_name_id"].(float64))
  331. drug_spec := items["drug_spec"].(string)
  332. min_unit := items["min_unit"].(string)
  333. drug_id := int64(items["drug_id"].(float64))
  334. //根据drug_id
  335. drugMedical, _ := service.GetBaseDrugMedical(drug_name_id)
  336. medical := models.XtSelfMedical{
  337. DrugName: drug_name,
  338. DrugNameId: drug_name_id,
  339. DrugSpec: drug_spec,
  340. CreatedTime: time.Now().Unix(),
  341. Status: 1,
  342. UserOrgId: orgId,
  343. PatientId: patient_id,
  344. MinUnit: min_unit,
  345. ExecutionFrequency: drugMedical.ExecutionFrequency,
  346. PrescribingNumber: drugMedical.PrescribingNumber,
  347. DeliveryWay: drugMedical.DeliveryWay,
  348. SingleDose: drugMedical.SingleDose,
  349. DrugId: drug_id,
  350. }
  351. //查询同个病人同个药品同个规格是否已存在
  352. _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
  353. if errcode == gorm.ErrRecordNotFound {
  354. err := service.CreateSelfMedical(&medical)
  355. fmt.Println(err)
  356. } else if errcode == nil {
  357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  358. return
  359. }
  360. }
  361. returnData := make(map[string]interface{}, 0)
  362. returnData["msg"] = "ok"
  363. this.ServeSuccessJSON(returnData)
  364. return
  365. }
  366. func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
  367. adminUserInfo := this.GetAdminUserInfo()
  368. orgid := adminUserInfo.CurrentOrgId
  369. //fmt.Println(orgid)
  370. appId := adminUserInfo.CurrentAppId
  371. staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
  372. if err != nil {
  373. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  374. return
  375. }
  376. this.ServeSuccessJSON(map[string]interface{}{
  377. "staff": staff,
  378. })
  379. }
  380. func (this *SelfDrugApiController) SaveStock() {
  381. timeLayout := "2006-01-02"
  382. loc, _ := time.LoadLocation("Local")
  383. start_time := this.GetString("start_time")
  384. fmt.Println("start_time", start_time)
  385. admin_user_id, _ := this.GetInt64("admin_user_id")
  386. fmt.Println("admin_user_id", admin_user_id)
  387. patient_id, _ := this.GetInt64("patient_id")
  388. dataBody := make(map[string]interface{}, 0)
  389. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  390. fmt.Println(err)
  391. stocks, _ := dataBody["stocks"].([]interface{})
  392. adminUserInfo := this.GetAdminUserInfo()
  393. orgId := adminUserInfo.CurrentOrgId
  394. for _, item := range stocks {
  395. items := item.(map[string]interface{})
  396. drug_name := items["drug_name"].(string)
  397. fmt.Println("drug_name", drug_name)
  398. drug_name_id := int64(items["drug_name_id"].(float64))
  399. fmt.Println("parient_id", drug_name_id)
  400. drug_spec := items["drug_spec"].(string)
  401. store_number := items["store_number"].(string)
  402. fmt.Println("store_number", store_number)
  403. storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
  404. remarks := items["remarks"].(string)
  405. min_unit := items["min_unit"].(string)
  406. medic_id := int64(items["id"].(float64))
  407. timeStr := time.Now().Format("2006-01-02")
  408. timeArr := strings.Split(timeStr, "-")
  409. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  410. total = total + 1
  411. warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  412. number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
  413. number = number + total
  414. warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
  415. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  416. stock := models.XtSelfStock{
  417. DrugName: drug_name,
  418. DrugNameId: drug_name_id,
  419. DrugSpec: drug_spec,
  420. StoreNumber: storeNumber,
  421. Remarks: remarks,
  422. AdminUserId: admin_user_id,
  423. StorckTime: theTime.Unix(),
  424. CreatedTime: time.Now().Unix(),
  425. Status: 1,
  426. UserOrgId: orgId,
  427. StockInNumber: warehousing_in_order,
  428. PatientId: patient_id,
  429. MinUnit: min_unit,
  430. StorageMode: 1,
  431. MedicId: medic_id,
  432. }
  433. err := service.CreateStock(&stock)
  434. fmt.Println("err", err)
  435. }
  436. returnData := make(map[string]interface{}, 0)
  437. returnData["msg"] = "ok"
  438. this.ServeSuccessJSON(returnData)
  439. return
  440. }
  441. func (this *SelfDrugApiController) SaveOutStock() {
  442. timeLayout := "2006-01-02"
  443. loc, _ := time.LoadLocation("Local")
  444. start_time := this.GetString("start_time")
  445. admin_user_id, _ := this.GetInt64("admin_user_id")
  446. patient_id, _ := this.GetInt64("patient_id")
  447. dataBody := make(map[string]interface{}, 0)
  448. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  449. fmt.Println(err)
  450. outStocks, _ := dataBody["outStocks"].([]interface{})
  451. adminUserInfo := this.GetAdminUserInfo()
  452. orgId := adminUserInfo.CurrentOrgId
  453. for _, item := range outStocks {
  454. items := item.(map[string]interface{})
  455. drug_name := items["drug_name"].(string)
  456. drug_name_id := int64(items["drug_name_id"].(float64))
  457. drug_spec := items["drug_spec"].(string)
  458. outstore_number := items["outstore_number"].(string)
  459. outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
  460. remarks := items["remarks"].(string)
  461. medic_id := int64(items["id"].(float64))
  462. timeStr := time.Now().Format("2006-01-02")
  463. timeArr := strings.Split(timeStr, "-")
  464. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  465. total = total + 1
  466. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  467. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  468. number = number + total
  469. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  470. fmt.Println(remarks)
  471. fmt.Println(items)
  472. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  473. stock := models.XtSelfOutStock{
  474. DrugName: drug_name,
  475. DrugNameId: drug_name_id,
  476. DrugSpec: drug_spec,
  477. OutstoreNumber: outStoreNumber,
  478. Remarks: remarks,
  479. AdminUserId: admin_user_id,
  480. StorckTime: theTime.Unix(),
  481. CreatedTime: time.Now().Unix(),
  482. Status: 1,
  483. UserOrgId: orgId,
  484. StockOutNumber: warehousing_out_order,
  485. PatientId: patient_id,
  486. ExitMode: 1,
  487. MedicId: medic_id,
  488. }
  489. err := service.CreateOutStock(&stock)
  490. fmt.Println("err", err)
  491. }
  492. returnData := make(map[string]interface{}, 0)
  493. returnData["msg"] = "ok"
  494. this.ServeSuccessJSON(returnData)
  495. return
  496. }
  497. func (this *SelfDrugApiController) DeleteDrugById() {
  498. id, _ := this.GetInt64("id")
  499. drug_name := this.GetString("drug_name")
  500. adminUserInfo := this.GetAdminUserInfo()
  501. orgId := adminUserInfo.CurrentOrgId
  502. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  503. if errcode == gorm.ErrRecordNotFound {
  504. service.DeleteDrugName(id)
  505. returnData := make(map[string]interface{}, 0)
  506. returnData["msg"] = "ok"
  507. this.ServeSuccessJSON(returnData)
  508. } else if errcode == nil {
  509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  510. return
  511. }
  512. }
  513. func (this *SelfDrugApiController) SaveRadio() {
  514. radio, _ := this.GetInt64("radio")
  515. adminUserInfo := this.GetAdminUserInfo()
  516. orgId := adminUserInfo.CurrentOrgId
  517. drugSet := models.XtDrugSet{
  518. DrugStart: radio,
  519. UserOrgId: orgId,
  520. Status: 1,
  521. CreatedTime: time.Now().Unix(),
  522. }
  523. _, errcode := service.GetDrugSetByUserOrgId(orgId)
  524. if errcode == gorm.ErrRecordNotFound {
  525. err := service.SaveRadio(&drugSet)
  526. if err != nil {
  527. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  528. return
  529. }
  530. this.ServeSuccessJSON(map[string]interface{}{
  531. "drugSet": drugSet,
  532. })
  533. } else if errcode == nil {
  534. err := service.UpdateDrugSet(&drugSet, orgId)
  535. if err != nil {
  536. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  537. return
  538. }
  539. this.ServeSuccessJSON(map[string]interface{}{
  540. "drugSet": drugSet,
  541. })
  542. }
  543. }
  544. func (this *SelfDrugApiController) DeleteDrugStand() {
  545. id, _ := this.GetInt64("id")
  546. name := this.GetString("name")
  547. adminUserInfo := this.GetAdminUserInfo()
  548. orgId := adminUserInfo.CurrentOrgId
  549. _, errcode := service.GetMedicalsByName(orgId, name)
  550. if errcode == gorm.ErrRecordNotFound {
  551. err := service.DeleteDrugStand(id)
  552. fmt.Println(err)
  553. returnData := make(map[string]interface{}, 0)
  554. returnData["msg"] = "ok"
  555. this.ServeSuccessJSON(returnData)
  556. } else if errcode == nil {
  557. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  558. return
  559. }
  560. }
  561. func (this *SelfDrugApiController) GetStockList() {
  562. patientid, _ := this.GetInt64("id")
  563. start_time := this.GetString("start_time")
  564. fmt.Println("开始时间", start_time)
  565. timeLayout := "2006-01-02"
  566. loc, _ := time.LoadLocation("Local")
  567. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  568. startimeUnix := theTime.Unix()
  569. keyword := this.GetString("keyword")
  570. fmt.Println("keyword", keyword)
  571. adminUserInfo := this.GetAdminUserInfo()
  572. orgId := adminUserInfo.CurrentOrgId
  573. //获取
  574. medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
  575. //统计总数量
  576. stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
  577. //统计出库数量
  578. outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
  579. //统计该病人时间段内出库条数
  580. outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
  581. if err != nil {
  582. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  583. return
  584. }
  585. this.ServeSuccessJSON(map[string]interface{}{
  586. "medicalList": medicalList,
  587. "stocklist": stocklist,
  588. "outStocklist": outStocklist,
  589. "outList": outList,
  590. })
  591. }
  592. func (this *SelfDrugApiController) DeleteDrugName() {
  593. drug_name := this.GetString("drugname")
  594. patient_id, _ := this.GetInt64("patientid")
  595. //查询该药品是否出库
  596. stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
  597. if len(stocklist) == 0 {
  598. //删除该药品
  599. service.DeleteDrugStockNumber(drug_name, patient_id)
  600. returnData := make(map[string]interface{}, 0)
  601. returnData["msg"] = "ok"
  602. this.ServeSuccessJSON(returnData)
  603. } else {
  604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  605. return
  606. }
  607. }
  608. func (this *SelfDrugApiController) GetDrugDetail() {
  609. timeLayout := "2006-01-02"
  610. loc, _ := time.LoadLocation("Local")
  611. drug_name := this.GetString("drug_name")
  612. drug_spec := this.GetString("drug_spec")
  613. start_time := this.GetString("start_time")
  614. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  615. end_time := this.GetString("end_time")
  616. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  617. patient_id, _ := this.GetInt64("patient_id")
  618. adminUserInfo := this.GetAdminUserInfo()
  619. orgId := adminUserInfo.CurrentOrgId
  620. //查询入库明细
  621. stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  622. //查询出库明细
  623. outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  624. if err != nil {
  625. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  626. return
  627. }
  628. this.ServeSuccessJSON(map[string]interface{}{
  629. "stockDetail": stockDetail,
  630. "outStockDetail": outStockDetail,
  631. })
  632. }
  633. func (this *SelfDrugApiController) GetAllPatientStockList() {
  634. timeLayout := "2006-01-02"
  635. loc, _ := time.LoadLocation("Local")
  636. drug_name := this.GetString("drug_name")
  637. drug_spec := this.GetString("drug_spec")
  638. start_time := this.GetString("start_time")
  639. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  640. startUnix := theTime.Unix()
  641. end_time := this.GetString("end_time")
  642. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  643. endTimeUnix := endTimes.Unix()
  644. keywords := this.GetString("search_input")
  645. adminUserInfo := this.GetAdminUserInfo()
  646. orgId := adminUserInfo.CurrentOrgId
  647. //入库
  648. stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  649. //出库
  650. outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  651. if err != nil {
  652. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  653. return
  654. }
  655. this.ServeSuccessJSON(map[string]interface{}{
  656. "stocklist": stocklist,
  657. "outStockList": outStockList,
  658. })
  659. }
  660. func (this *SelfDrugApiController) GetDrugDataByPatientId() {
  661. patient_id, _ := this.GetInt64("patient_id")
  662. fmt.Println("patient_id", patient_id)
  663. medicalList, err := service.GetDrugDataByPatientId(patient_id)
  664. if err != nil {
  665. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  666. return
  667. }
  668. this.ServeSuccessJSON(map[string]interface{}{
  669. "medicalList": medicalList,
  670. })
  671. }
  672. func (this *SelfDrugApiController) GetSelfMedicalList() {
  673. patient_id, _ := this.GetInt64("patient_id")
  674. adminUserInfo := this.GetAdminUserInfo()
  675. orgId := adminUserInfo.CurrentOrgId
  676. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  677. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(orgId)
  678. drugList, _ := service.GetAllBaseDrugLibList(orgId)
  679. privateDrugList, _ := service.GetPrivateDrugList(patient_id, orgId)
  680. this.ServeSuccessJSON(map[string]interface{}{
  681. "base_drug_config": drugStockConfig,
  682. "private_drug_config": privateDrugConfig,
  683. "base_drug_list": drugList,
  684. "private_drug_list": privateDrugList,
  685. })
  686. ////查询是否开启药品库
  687. //config, _ := service.GetDruckStockConfig(orgId)
  688. //
  689. //fmt.Println("--------------------------",config.IsOpen)
  690. ////开启
  691. //if config.IsOpen == 1 {
  692. // //查询该机构下的药品库
  693. // drugName, _ := service.GetAllDrugName(orgId)
  694. //
  695. // //查询该机构是否开启自备药
  696. // medical, _ := service.GetSetSelfMedical(orgId)
  697. // fmt.Println("medical+++++++++++++++++",medical.DrugStart)
  698. // //开启
  699. // if medical.DrugStart == 1 {
  700. // list, err := service.GetSelfMedicalList(patient_id)
  701. // if err != nil {
  702. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  703. // return
  704. // }
  705. // this.ServeSuccessJSON(map[string]interface{}{
  706. // "medicalList": list,
  707. // "drugName": drugName,
  708. // })
  709. // } else {
  710. // this.ServeSuccessJSON(map[string]interface{}{
  711. // "drugName": drugName,
  712. // })
  713. // }
  714. //}
  715. }
  716. func (this *SelfDrugApiController) GetDrugDescByDrugName() {
  717. drug_name := this.GetString("drug_name")
  718. patient_id, _ := this.GetInt64("patient_id")
  719. way, _ := this.GetInt64("way")
  720. adminUserInfo := this.GetAdminUserInfo()
  721. orgId := adminUserInfo.CurrentOrgId
  722. drug_id, _ := this.GetInt64("id")
  723. //从基础库查询
  724. if way == 1 {
  725. //查询基础库数据
  726. medcal, err := service.GetBaseMedcal(drug_name, orgId)
  727. //统计入库数量
  728. countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
  729. //统计出库数量
  730. countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
  731. if err != nil {
  732. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  733. return
  734. }
  735. this.ServeSuccessJSON(map[string]interface{}{
  736. "drugspec": medcal,
  737. "countInfo": countInfo,
  738. "countout": countout,
  739. })
  740. }
  741. //从自备药库查询
  742. if way == 2 {
  743. drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
  744. if err != nil {
  745. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  746. return
  747. }
  748. this.ServeSuccessJSON(map[string]interface{}{
  749. "drugspec": drugspec,
  750. })
  751. }
  752. }
  753. func (this *SelfDrugApiController) GetDrugSet() {
  754. adminUserInfo := this.GetAdminUserInfo()
  755. orgId := adminUserInfo.CurrentOrgId
  756. drugSet, err := service.GetDrugSet(orgId)
  757. if err != nil {
  758. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  759. return
  760. }
  761. this.ServeSuccessJSON(map[string]interface{}{
  762. "drugSet": drugSet,
  763. })
  764. }
  765. func (this *SelfDrugApiController) GetAllMedicalList() {
  766. adminUserInfo := this.GetAdminUserInfo()
  767. orgId := adminUserInfo.CurrentOrgId
  768. list, err := service.GetAllMedicalList(orgId)
  769. if err != nil {
  770. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  771. return
  772. }
  773. this.ServeSuccessJSON(map[string]interface{}{
  774. "drugName": list,
  775. })
  776. }
  777. func (this *SelfDrugApiController) GetStandName() {
  778. name := this.GetString("name")
  779. adminUserInfo := this.GetAdminUserInfo()
  780. orgId := adminUserInfo.CurrentOrgId
  781. rullerlist, err := service.GetRulleName(orgId, name)
  782. if err != nil {
  783. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  784. return
  785. }
  786. this.ServeSuccessJSON(map[string]interface{}{
  787. "rullerlist": rullerlist,
  788. })
  789. }
  790. func (this *SelfDrugApiController) GetRullerList() {
  791. id, _ := this.GetInt64("id")
  792. adminUserInfo := this.GetAdminUserInfo()
  793. orgId := adminUserInfo.CurrentOrgId
  794. rullerList, err := service.GetRulleList(orgId, id)
  795. if err != nil {
  796. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  797. return
  798. }
  799. this.ServeSuccessJSON(map[string]interface{}{
  800. "rullerlist": rullerList,
  801. })
  802. }
  803. func (this *SelfDrugApiController) DeleteDrugNameById() {
  804. id, _ := this.GetInt64("id")
  805. drug_name := this.GetString("drug_name")
  806. adminUserInfo := this.GetAdminUserInfo()
  807. orgId := adminUserInfo.CurrentOrgId
  808. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  809. if errcode == gorm.ErrRecordNotFound {
  810. service.DeleteDrugNameById(id)
  811. returnData := make(map[string]interface{}, 0)
  812. returnData["msg"] = "ok"
  813. this.ServeSuccessJSON(returnData)
  814. } else if errcode == nil {
  815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  816. return
  817. }
  818. }
  819. func (this *SelfDrugApiController) GetPatientDetail() {
  820. id, _ := this.GetInt64("id")
  821. adminUserInfo := this.GetAdminUserInfo()
  822. patientDetail, err := service.GetPatientDetail(id, adminUserInfo.CurrentOrgId)
  823. if err != nil {
  824. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  825. return
  826. }
  827. this.ServeSuccessJSON(map[string]interface{}{
  828. "patientDetail": patientDetail,
  829. })
  830. }
  831. //func (this *SelfDrugApiController) ToPatientDetail() {
  832. //
  833. // keyword := this.GetString("keyword")
  834. // adminUser := this.GetAdminUserInfo()
  835. // orgId := adminUser.CurrentOrgId
  836. // patient, err := service.ToSeachPatient(keyword, orgId)
  837. // if err != nil {
  838. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  839. // return
  840. // }
  841. // this.ServeSuccessJSON(map[string]interface{}{
  842. // "patient": patient,
  843. // })
  844. //}
  845. func (this *SelfDrugApiController) GetSelfStockQuery() {
  846. adminUserInfo := this.GetAdminUserInfo()
  847. orgId := adminUserInfo.CurrentOrgId
  848. type_name, _ := this.GetInt64("type_name")
  849. keywords := this.GetString("keywords")
  850. timeLayout := "2006-01-02"
  851. loc, _ := time.LoadLocation("Local")
  852. start_time := this.GetString("start_time")
  853. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  854. startUnix := theTime.Unix()
  855. end_time := this.GetString("end_time")
  856. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  857. endTimeUnix := endTimes.Unix()
  858. page, _ := this.GetInt64("page")
  859. limit, _ := this.GetInt64("limit")
  860. //统计入库数量
  861. stockQuery, total, err := service.GetSelfStockQuery(type_name, keywords, startUnix, endTimeUnix, orgId, limit, page)
  862. //统计出库数量
  863. stockOutQuery, err := service.GetSelfOutStockQuery(startUnix, endTimeUnix, orgId)
  864. if err != nil {
  865. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  866. return
  867. }
  868. this.ServeSuccessJSON(map[string]interface{}{
  869. "stockQuery": stockQuery,
  870. "total": total,
  871. "stockOutQuery": stockOutQuery,
  872. })
  873. }
  874. func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
  875. keyword := this.GetString("keyword")
  876. storehouse_id, _ := this.GetInt64("storehouse_id")
  877. orgId := this.GetAdminUserInfo().CurrentOrgId
  878. list, err := service.PostSearchDrugWarehouseList(keyword, orgId, storehouse_id)
  879. manufacturerList, err := service.GetAllManufacturerList(orgId)
  880. dealerList, err := service.GetAllDealerList(orgId)
  881. if err != nil {
  882. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  883. return
  884. }
  885. this.ServeSuccessJSON(map[string]interface{}{
  886. "list": list,
  887. "manufacturerList": manufacturerList,
  888. "dealerList": dealerList,
  889. })
  890. }
  891. func (this *SelfDrugApiController) SaveDrugPrice() {
  892. timeLayout := "2006-01-02"
  893. loc, _ := time.LoadLocation("Local")
  894. dataBody := make(map[string]interface{}, 0)
  895. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  896. fmt.Println(err)
  897. tableData, _ := dataBody["tableData"].([]interface{})
  898. fmt.Println("999939433443", tableData)
  899. if len(tableData) > 0 {
  900. for _, item := range tableData {
  901. items := item.(map[string]interface{})
  902. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  903. utils.ErrorLog("drug_name")
  904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  905. return
  906. }
  907. drug_name := items["drug_name"].(string)
  908. fmt.Println("drug_aname23232323232", drug_name)
  909. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  910. utils.ErrorLog("drug_name")
  911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  912. return
  913. }
  914. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  915. utils.ErrorLog("retail_price")
  916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  917. return
  918. }
  919. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  920. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  921. utils.ErrorLog("warehousing_order")
  922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  923. return
  924. }
  925. warehousing_order := items["warehousing_order"].(string)
  926. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  927. utils.ErrorLog("number")
  928. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  929. return
  930. }
  931. number := items["number"].(string)
  932. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  933. utils.ErrorLog("dealer")
  934. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  935. return
  936. }
  937. dealer := items["dealer"].(string)
  938. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  939. utils.ErrorLog("manufacturer")
  940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  941. return
  942. }
  943. manufacturer := items["manufacturer"].(string)
  944. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  945. utils.ErrorLog("specification_name")
  946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  947. return
  948. }
  949. specification_name := items["specification_name"].(string)
  950. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  951. utils.ErrorLog("remark")
  952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  953. return
  954. }
  955. remark := items["remark"].(string)
  956. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  957. utils.ErrorLog("warehousing_unit")
  958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  959. return
  960. }
  961. warehousing_unit := items["warehousing_unit"].(string)
  962. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  963. utils.ErrorLog("last_price")
  964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  965. return
  966. }
  967. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  968. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  969. utils.ErrorLog("new_price")
  970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  971. return
  972. }
  973. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  974. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  975. utils.ErrorLog("drug_id")
  976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  977. return
  978. }
  979. drug_id := int64(items["drug_id"].(float64))
  980. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  981. utils.ErrorLog("start_time")
  982. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  983. return
  984. }
  985. var startTime int64
  986. start_time := items["start_time"].(string)
  987. if len(start_time) > 0 {
  988. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  989. if err != nil {
  990. fmt.Println(err)
  991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  992. return
  993. }
  994. startTime = theTime.Unix()
  995. }
  996. orgId := this.GetAdminUserInfo().CurrentOrgId
  997. Creater := this.GetAdminUserInfo().AdminUser.Id
  998. drugAdjust := models.XtDrugAdjustPrice{
  999. DrugName: drug_name,
  1000. SpecificationName: specification_name,
  1001. WarehousingUnit: warehousing_unit,
  1002. LastPrice: last_price,
  1003. RetailPrice: retail_price,
  1004. NewPrice: new_price,
  1005. Manufacturer: manufacturer,
  1006. Dealer: dealer,
  1007. Remark: remark,
  1008. DrugId: drug_id,
  1009. UserOrgId: orgId,
  1010. Ctime: time.Now().Unix(),
  1011. Mtime: 0,
  1012. Status: 1,
  1013. WarehousingOrder: warehousing_order,
  1014. Number: number,
  1015. StartTime: startTime,
  1016. Creater: Creater,
  1017. Checker: 0,
  1018. CheckerStatus: 2,
  1019. CheckerTime: 0,
  1020. }
  1021. err := service.CreateDrugPrice(drugAdjust)
  1022. fmt.Println(err)
  1023. }
  1024. }
  1025. returnData := make(map[string]interface{}, 0)
  1026. returnData["msg"] = "ok"
  1027. this.ServeSuccessJSON(returnData)
  1028. return
  1029. }
  1030. func (this *SelfDrugApiController) GetDrugPriceList() {
  1031. timeLayout := "2006-01-02"
  1032. loc, _ := time.LoadLocation("Local")
  1033. dataBody := make(map[string]interface{}, 0)
  1034. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1035. fmt.Println(err)
  1036. orgId := this.GetAdminUserInfo().CurrentOrgId
  1037. keyword := this.GetString("keyword")
  1038. start_time := this.GetString("start_time")
  1039. end_time := this.GetString("end_time")
  1040. var startTime int64
  1041. if len(start_time) > 0 {
  1042. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1043. if err != nil {
  1044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1045. return
  1046. }
  1047. startTime = theTime.Unix()
  1048. }
  1049. var endTime int64
  1050. if len(end_time) > 0 {
  1051. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1052. if err != nil {
  1053. utils.ErrorLog(err.Error())
  1054. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1055. return
  1056. }
  1057. endTime = theTime.Unix()
  1058. }
  1059. limit, _ := this.GetInt64("limit")
  1060. page, _ := this.GetInt64("page")
  1061. list, total, err := service.GetDrugPriceList(startTime, endTime, orgId, keyword, limit, page)
  1062. doctorList, err := service.GetAllDoctorThree(orgId)
  1063. if err != nil {
  1064. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1065. return
  1066. }
  1067. this.ServeSuccessJSON(map[string]interface{}{
  1068. "total": total,
  1069. "list": list,
  1070. "doctorList": doctorList,
  1071. })
  1072. }
  1073. func (this *SelfDrugApiController) SaveCheckDrugPrice() {
  1074. timeLayout := "2006-01-02"
  1075. loc, _ := time.LoadLocation("Local")
  1076. dataBody := make(map[string]interface{}, 0)
  1077. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1078. fmt.Println(err)
  1079. idstr := this.GetString("ids")
  1080. ids := strings.Split(idstr, ",")
  1081. check_time := this.GetString("check_time")
  1082. var checkTime int64
  1083. if len(check_time) > 0 {
  1084. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1085. if err != nil {
  1086. fmt.Println(err)
  1087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1088. return
  1089. }
  1090. checkTime = theTime.Unix()
  1091. }
  1092. checker, _ := this.GetInt64("checker")
  1093. adjustPrice := models.XtDrugAdjustPrice{
  1094. Checker: checker,
  1095. CheckerStatus: 1,
  1096. CheckerTime: checkTime,
  1097. }
  1098. err = service.UpdateDrugAdjuestPrice(ids, adjustPrice)
  1099. fmt.Println("err", err)
  1100. list, _ := service.GetDrugAdjuestPrice(ids)
  1101. for _, item := range list {
  1102. drug := models.BaseDrugLib{
  1103. RetailPrice: item.NewPrice,
  1104. LastPrice: item.NewPrice,
  1105. }
  1106. service.UpdateBaseDrugOne(drug, item.DrugId)
  1107. }
  1108. this.ServeSuccessJSON(map[string]interface{}{
  1109. "adjustPrice": adjustPrice,
  1110. })
  1111. }
  1112. func (this *SelfDrugApiController) SaveDrugDamage() {
  1113. timeLayout := "2006-01-02"
  1114. loc, _ := time.LoadLocation("Local")
  1115. dataBody := make(map[string]interface{}, 0)
  1116. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1117. fmt.Println(err)
  1118. tableData, _ := dataBody["tableData"].([]interface{})
  1119. fmt.Println("999939433443", tableData)
  1120. if len(tableData) > 0 {
  1121. for _, item := range tableData {
  1122. items := item.(map[string]interface{})
  1123. drug_name := items["drug_name"].(string)
  1124. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1125. utils.ErrorLog("drug_name")
  1126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1127. return
  1128. }
  1129. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1130. utils.ErrorLog("retail_price")
  1131. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1132. return
  1133. }
  1134. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1135. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1136. utils.ErrorLog("warehousing_order")
  1137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1138. return
  1139. }
  1140. warehousing_order := items["warehousing_order"].(string)
  1141. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1142. utils.ErrorLog("number")
  1143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1144. return
  1145. }
  1146. number := items["number"].(string)
  1147. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1148. utils.ErrorLog("dealer")
  1149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1150. return
  1151. }
  1152. dealer := items["dealer"].(string)
  1153. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1154. utils.ErrorLog("manufacturer")
  1155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1156. return
  1157. }
  1158. manufacturer := items["manufacturer"].(string)
  1159. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1160. utils.ErrorLog("specification_name")
  1161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1162. return
  1163. }
  1164. specification_name := items["specification_name"].(string)
  1165. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1166. utils.ErrorLog("remark")
  1167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1168. return
  1169. }
  1170. remark := items["remark"].(string)
  1171. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1172. utils.ErrorLog("warehousing_unit")
  1173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1174. return
  1175. }
  1176. warehousing_unit := items["warehousing_unit"].(string)
  1177. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1178. utils.ErrorLog("last_price")
  1179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1183. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1184. utils.ErrorLog("count")
  1185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1186. return
  1187. }
  1188. count := int64(items["count"].(float64))
  1189. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1190. utils.ErrorLog("new_price")
  1191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1192. return
  1193. }
  1194. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1195. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1196. utils.ErrorLog("drug_id")
  1197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1198. return
  1199. }
  1200. drug_id := int64(items["drug_id"].(float64))
  1201. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1202. utils.ErrorLog("start_time")
  1203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1204. return
  1205. }
  1206. var startTime int64
  1207. start_time := items["start_time"].(string)
  1208. if len(start_time) > 0 {
  1209. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1210. if err != nil {
  1211. fmt.Println(err)
  1212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1213. return
  1214. }
  1215. startTime = theTime.Unix()
  1216. }
  1217. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  1218. utils.ErrorLog("warehousing_info_id")
  1219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1220. return
  1221. }
  1222. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  1223. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1224. utils.ErrorLog("expiry_date")
  1225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1226. return
  1227. }
  1228. expiry_date := int64(items["expiry_date"].(float64))
  1229. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1230. utils.ErrorLog("product_date")
  1231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1232. return
  1233. }
  1234. product_date := int64(items["product_date"].(float64))
  1235. if items["drug_origin_place"] == nil || reflect.TypeOf(items["drug_origin_place"]).String() != "string" {
  1236. utils.ErrorLog("drug_origin_place")
  1237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1238. return
  1239. }
  1240. drug_origin_place := items["drug_origin_place"].(string)
  1241. orgId := this.GetAdminUserInfo().CurrentOrgId
  1242. Creater := this.GetAdminUserInfo().AdminUser.Id
  1243. if items["stock_max_number"] == nil || reflect.TypeOf(items["stock_max_number"]).String() != "float64" {
  1244. utils.ErrorLog("stock_max_number")
  1245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1246. return
  1247. }
  1248. stock_max_number := int64(items["stock_max_number"].(float64))
  1249. if items["stock_min_number"] == nil || reflect.TypeOf(items["stock_min_number"]).String() != "float64" {
  1250. utils.ErrorLog("stock_min_number")
  1251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1252. return
  1253. }
  1254. stock_min_number := int64(items["stock_min_number"].(float64))
  1255. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1256. utils.ErrorLog("total")
  1257. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1258. return
  1259. }
  1260. total := items["total"].(string)
  1261. drugDamage := models.XtDrugDamage{
  1262. DrugName: drug_name,
  1263. SpecificationName: specification_name,
  1264. WarehousingUnit: warehousing_unit,
  1265. Count: count,
  1266. LastPrice: last_price,
  1267. RetailPrice: retail_price,
  1268. NewPrice: new_price,
  1269. Manufacturer: manufacturer,
  1270. Dealer: dealer,
  1271. Remark: remark,
  1272. DrugId: drug_id,
  1273. UserOrgId: orgId,
  1274. Ctime: time.Now().Unix(),
  1275. Mtime: 0,
  1276. Status: 1,
  1277. WarehousingOrder: warehousing_order,
  1278. Number: number,
  1279. StartTime: startTime,
  1280. Creater: Creater,
  1281. Checker: 0,
  1282. CheckerStatus: 2,
  1283. CheckerTime: 0,
  1284. ExpiryDate: expiry_date,
  1285. ProductDate: product_date,
  1286. WarehousingInfoId: warehousing_info_id,
  1287. DrugOriginPlace: drug_origin_place,
  1288. StockMaxNumber: stock_max_number,
  1289. StockMinNumber: stock_min_number,
  1290. Total: total,
  1291. }
  1292. err := service.CreateDrugDamage(drugDamage)
  1293. fmt.Println(err)
  1294. }
  1295. }
  1296. returnData := make(map[string]interface{}, 0)
  1297. returnData["msg"] = "ok"
  1298. this.ServeSuccessJSON(returnData)
  1299. }
  1300. func (this *SelfDrugApiController) GetDrugDamageList() {
  1301. timeLayout := "2006-01-02"
  1302. loc, _ := time.LoadLocation("Local")
  1303. dataBody := make(map[string]interface{}, 0)
  1304. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1305. fmt.Println(err)
  1306. orgId := this.GetAdminUserInfo().CurrentOrgId
  1307. keyword := this.GetString("keyword")
  1308. start_time := this.GetString("start_time")
  1309. end_time := this.GetString("end_time")
  1310. storehouse_id, _ := this.GetInt64("storehouse_id")
  1311. var startTime int64
  1312. if len(start_time) > 0 {
  1313. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1314. if err != nil {
  1315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1316. return
  1317. }
  1318. startTime = theTime.Unix()
  1319. }
  1320. var endTime int64
  1321. if len(end_time) > 0 {
  1322. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1323. if err != nil {
  1324. utils.ErrorLog(err.Error())
  1325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. endTime = theTime.Unix()
  1329. }
  1330. limit, _ := this.GetInt64("limit")
  1331. page, _ := this.GetInt64("page")
  1332. list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page, storehouse_id)
  1333. damagelist, _ := service.GetDrugDamageByOrgId(orgId)
  1334. doctorList, err := service.GetAllDoctorThree(orgId)
  1335. houseList, _ := service.GetAllStoreHouseList(orgId)
  1336. if err != nil {
  1337. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1338. return
  1339. }
  1340. this.ServeSuccessJSON(map[string]interface{}{
  1341. "total": total,
  1342. "list": list,
  1343. "damagelist": damagelist,
  1344. "doctorList": doctorList,
  1345. "houseList": houseList,
  1346. })
  1347. }
  1348. func (this *SelfDrugApiController) SaveDrugDamagePrice() {
  1349. timeLayout := "2006-01-02"
  1350. loc, _ := time.LoadLocation("Local")
  1351. dataBody := make(map[string]interface{}, 0)
  1352. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1353. fmt.Println(err)
  1354. idstr := this.GetString("ids")
  1355. ids := strings.Split(idstr, ",")
  1356. check_time := this.GetString("check_time")
  1357. var checkTime int64
  1358. if len(check_time) > 0 {
  1359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1360. if err != nil {
  1361. fmt.Println(err)
  1362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1363. return
  1364. }
  1365. checkTime = theTime.Unix()
  1366. }
  1367. checker, _ := this.GetInt64("checker")
  1368. damage := models.XtDrugDamage{
  1369. Checker: checker,
  1370. CheckerStatus: 1,
  1371. CheckerTime: checkTime,
  1372. }
  1373. err = service.UpdateDrugDamage(ids, damage)
  1374. fmt.Println(err)
  1375. list, _ := service.GetDrugDamage(ids)
  1376. ctime := time.Now().Unix()
  1377. adminUserInfo := this.GetAdminUserInfo()
  1378. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1379. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  1380. var manufacturer_id int64
  1381. var dealer_id int64
  1382. timeStr := time.Now().Format("2006-01-02")
  1383. timeArr := strings.Split(timeStr, "-")
  1384. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1385. total = total + 1
  1386. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1387. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1388. number = number + total
  1389. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1390. operation_time := time.Now().Unix()
  1391. creater := adminUserInfo.AdminUser.Id
  1392. warehouseOut := models.DrugWarehouseOut{
  1393. WarehouseOutOrderNumber: warehousing_out_order,
  1394. OperationTime: operation_time,
  1395. OrgId: adminUserInfo.CurrentOrgId,
  1396. Creater: creater,
  1397. Ctime: ctime,
  1398. Status: 1,
  1399. WarehouseOutTime: time.Now().Unix(),
  1400. Type: 1,
  1401. }
  1402. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1403. for _, item := range list {
  1404. for _, it := range manufacturerList {
  1405. if item.Manufacturer == it.ManufacturerName {
  1406. manufacturer_id = it.ID
  1407. }
  1408. }
  1409. for _, its := range dealerList {
  1410. if its.DealerName == item.Dealer {
  1411. dealer_id = its.ID
  1412. }
  1413. }
  1414. warehouseOutInfo := models.XtDrugWarehouseOutInfo{
  1415. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1416. WarehouseOutId: warehouseOut.ID,
  1417. DrugId: item.DrugId,
  1418. Count: item.Count,
  1419. Price: item.RetailPrice,
  1420. Status: 1,
  1421. Ctime: ctime,
  1422. Remark: item.Remark,
  1423. OrgId: adminUserInfo.CurrentOrgId,
  1424. Type: 1,
  1425. Manufacturer: manufacturer_id,
  1426. Dealer: dealer_id,
  1427. RetailPrice: item.RetailPrice,
  1428. CountUnit: item.WarehousingUnit,
  1429. ExpiryDate: item.ExpiryDate,
  1430. ProductDate: item.ProductDate,
  1431. Number: item.Number,
  1432. BatchNumber: item.BatchNumber,
  1433. IsSys: 0,
  1434. WarehouseInfoId: item.WarehousingInfoId,
  1435. }
  1436. drugflow := models.DrugFlow{
  1437. WarehouseOutId: warehouseOut.ID,
  1438. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1439. DrugId: item.DrugId,
  1440. Number: item.Number,
  1441. ProductDate: item.ProductDate,
  1442. ExpireDate: item.ExpiryDate,
  1443. Count: item.Count,
  1444. Price: item.RetailPrice,
  1445. Status: 1,
  1446. Ctime: ctime,
  1447. UserOrgId: adminUserInfo.CurrentOrgId,
  1448. Manufacturer: manufacturer_id,
  1449. Dealer: dealer_id,
  1450. BatchNumber: item.BatchNumber,
  1451. MaxUnit: item.WarehousingUnit,
  1452. ConsumableType: 5,
  1453. IsEdit: 1,
  1454. Creator: adminUserInfo.AdminUser.Id,
  1455. IsSys: 0,
  1456. }
  1457. service.CreateWareHouseOutInfo(&warehouseOutInfo)
  1458. service.CreateDrugFlowOne(drugflow)
  1459. info, _ := service.GetDrugByWarehouseInfo(item.WarehousingInfoId)
  1460. //扣减库存
  1461. warehouseInfo := models.XtDrugWarehouseInfo{
  1462. StockMaxNumber: info.StockMaxNumber - info.StockMaxNumber,
  1463. }
  1464. service.UpdateDrugWarehouseingInfo(item.WarehousingInfoId, warehouseInfo)
  1465. }
  1466. this.ServeSuccessJSON(map[string]interface{}{
  1467. "damage": damage,
  1468. })
  1469. }
  1470. func (this *SelfDrugApiController) GetDrugModifyPrice() {
  1471. id, _ := this.GetInt64("id")
  1472. detail, err := service.GetDrugModifyPrice(id)
  1473. fmt.Println(err)
  1474. this.ServeSuccessJSON(map[string]interface{}{
  1475. "detail": detail,
  1476. })
  1477. }
  1478. func (this *SelfDrugApiController) ModifyDrugPrice() {
  1479. drug_name := this.GetString("drug_name")
  1480. specification_name := this.GetString("specification_name")
  1481. warehousing_unit := this.GetString("warehousing_unit")
  1482. manufacturer := this.GetString("manufacturer")
  1483. number := this.GetString("number")
  1484. retailPrice := this.GetString("retail_price")
  1485. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1486. newPrice := this.GetString("new_price")
  1487. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1488. count, _ := this.GetInt64("count")
  1489. remark := this.GetString("remark")
  1490. id, _ := this.GetInt64("id")
  1491. drug_id, _ := this.GetInt64("drug_id")
  1492. adjustPrice := models.XtDrugAdjustPrice{
  1493. DrugName: drug_name,
  1494. Count: count,
  1495. RetailPrice: retail_price,
  1496. NewPrice: new_price,
  1497. Remark: remark,
  1498. SpecificationName: specification_name,
  1499. WarehousingUnit: warehousing_unit,
  1500. Manufacturer: manufacturer,
  1501. Number: number,
  1502. DrugId: drug_id,
  1503. }
  1504. err := service.ModifyDrugPrice(id, adjustPrice)
  1505. fmt.Println(err)
  1506. this.ServeSuccessJSON(map[string]interface{}{
  1507. "adjustPrice": adjustPrice,
  1508. })
  1509. }
  1510. func (this *SelfDrugApiController) GetModifyPricePrint() {
  1511. ids := this.GetString("ids")
  1512. idsSplit := strings.Split(ids, ",")
  1513. list, err := service.GetModifyPricePrint(idsSplit)
  1514. fmt.Println(err)
  1515. this.ServeSuccessJSON(map[string]interface{}{
  1516. "list": list,
  1517. })
  1518. }
  1519. func (this *SelfDrugApiController) GetDrugDamageDetail() {
  1520. id, _ := this.GetInt64("id")
  1521. detail, _ := service.GetDrugDamageDetail(id)
  1522. this.ServeSuccessJSON(map[string]interface{}{
  1523. "detail": detail,
  1524. })
  1525. }
  1526. func (this *SelfDrugApiController) ModifyDrugDamage() {
  1527. id, _ := this.GetInt64("id")
  1528. drug_id, _ := this.GetInt64("drug_id")
  1529. drug_name := this.GetString("drug_name")
  1530. drug_origin_place := this.GetString("drug_origin_place")
  1531. lastPrice := this.GetString("last_price")
  1532. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  1533. newPrice := this.GetString("new_price")
  1534. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1535. manufacturer := this.GetString("manufacturer")
  1536. number := this.GetString("number")
  1537. retailPrice := this.GetString("retail_price")
  1538. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1539. remark := this.GetString("remark")
  1540. count, _ := this.GetInt64("count")
  1541. warehousing_unit := this.GetString("warehousing_unit")
  1542. stock_max_number, _ := this.GetInt64("stock_max_number")
  1543. stock_min_number, _ := this.GetInt64("stock_min_number")
  1544. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  1545. damage := models.XtDrugDamage{
  1546. DrugName: drug_name,
  1547. SpecificationName: "",
  1548. WarehousingUnit: warehousing_unit,
  1549. Count: count,
  1550. LastPrice: last_price,
  1551. RetailPrice: retail_price,
  1552. NewPrice: new_price,
  1553. Manufacturer: manufacturer,
  1554. Dealer: "",
  1555. Remark: remark,
  1556. DrugId: drug_id,
  1557. Number: number,
  1558. StockMaxNumber: stock_max_number,
  1559. StockMinNumber: stock_min_number,
  1560. WarehousingInfoId: warehousing_info_id,
  1561. DrugOriginPlace: drug_origin_place,
  1562. }
  1563. err := service.ModifyDrugDamage(id, damage)
  1564. fmt.Println(err)
  1565. this.ServeSuccessJSON(map[string]interface{}{
  1566. "damage": damage,
  1567. })
  1568. }
  1569. func (this *SelfDrugApiController) DeleteDrugDamage() {
  1570. id, _ := this.GetInt64("id")
  1571. err := service.DeleteDrugDamage(id)
  1572. fmt.Println(err)
  1573. returnData := make(map[string]interface{}, 0)
  1574. returnData["msg"] = "ok"
  1575. this.ServeSuccessJSON(returnData)
  1576. }
  1577. func (this *SelfDrugApiController) GetDrugDamagePrint() {
  1578. idsSplit := this.GetString("ids")
  1579. ids := strings.Split(idsSplit, ",")
  1580. list, _ := service.GetDrugDamagePrint(ids)
  1581. this.ServeSuccessJSON(map[string]interface{}{
  1582. "list": list,
  1583. })
  1584. }
  1585. func (this *SelfDrugApiController) GetWarehoseInfoById() {
  1586. id, _ := this.GetInt64("id")
  1587. storehouse_id, _ := this.GetInt64("storehouse_id")
  1588. orgId := this.GetAdminUserInfo().CurrentOrgId
  1589. list, _ := service.GetWarehoseInfoById(id, storehouse_id, orgId)
  1590. this.ServeSuccessJSON(map[string]interface{}{
  1591. "list": list,
  1592. })
  1593. }
  1594. func (this *SelfDrugApiController) SaveDrugInventory() {
  1595. timeLayout := "2006-01-02"
  1596. loc, _ := time.LoadLocation("Local")
  1597. dataBody := make(map[string]interface{}, 0)
  1598. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1599. fmt.Println(err)
  1600. tableData, _ := dataBody["tableData"].([]interface{})
  1601. fmt.Println("999939433443", tableData)
  1602. if len(tableData) > 0 {
  1603. for _, item := range tableData {
  1604. items := item.(map[string]interface{})
  1605. drug_name := items["drug_name"].(string)
  1606. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1607. utils.ErrorLog("drug_name")
  1608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1609. return
  1610. }
  1611. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1612. utils.ErrorLog("retail_price")
  1613. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1614. return
  1615. }
  1616. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1617. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1618. utils.ErrorLog("warehousing_order")
  1619. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1620. return
  1621. }
  1622. warehousing_order := items["warehousing_order"].(string)
  1623. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1624. utils.ErrorLog("dealer")
  1625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1626. return
  1627. }
  1628. dealer := items["dealer"].(string)
  1629. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1630. utils.ErrorLog("manufacturer")
  1631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1632. return
  1633. }
  1634. manufacturer := items["manufacturer"].(string)
  1635. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1636. utils.ErrorLog("specification_name")
  1637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. specification_name := items["specification_name"].(string)
  1641. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1642. utils.ErrorLog("remark")
  1643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. return
  1645. }
  1646. remark := items["remark"].(string)
  1647. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1648. utils.ErrorLog("warehousing_unit")
  1649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1650. return
  1651. }
  1652. warehousing_unit := items["warehousing_unit"].(string)
  1653. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1654. utils.ErrorLog("last_price")
  1655. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1659. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1660. utils.ErrorLog("count")
  1661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1662. return
  1663. }
  1664. count := int64(items["count"].(float64))
  1665. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1666. utils.ErrorLog("new_price")
  1667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1668. return
  1669. }
  1670. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1671. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1672. utils.ErrorLog("drug_id")
  1673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1674. return
  1675. }
  1676. drug_id := int64(items["drug_id"].(float64))
  1677. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1678. utils.ErrorLog("start_time")
  1679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1680. return
  1681. }
  1682. var startTime int64
  1683. start_time := items["start_time"].(string)
  1684. if len(start_time) > 0 {
  1685. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1686. if err != nil {
  1687. fmt.Println(err)
  1688. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1689. return
  1690. }
  1691. startTime = theTime.Unix()
  1692. }
  1693. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1694. utils.ErrorLog("product_date")
  1695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1696. return
  1697. }
  1698. product_date := int64(items["product_date"].(float64))
  1699. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1700. utils.ErrorLog("expiry_date")
  1701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1702. return
  1703. }
  1704. expiry_date := int64(items["expiry_date"].(float64))
  1705. orgId := this.GetAdminUserInfo().CurrentOrgId
  1706. Creater := this.GetAdminUserInfo().AdminUser.Id
  1707. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1708. utils.ErrorLog("number")
  1709. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1710. return
  1711. }
  1712. numbers := items["number"].(string)
  1713. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1714. utils.ErrorLog("warehouse_info_id")
  1715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1716. return
  1717. }
  1718. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1719. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1720. utils.ErrorLog("total")
  1721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1722. return
  1723. }
  1724. total := items["total"].(string)
  1725. drug_origin_place := items["drug_origin_place"].(string)
  1726. min_count := int64(items["min_count"].(float64))
  1727. min_unit := items["min_unit"].(string)
  1728. inventory := models.XtDrugInventory{
  1729. DrugName: drug_name,
  1730. SpecificationName: specification_name,
  1731. WarehousingUnit: warehousing_unit,
  1732. Count: count,
  1733. LastPrice: last_price,
  1734. RetailPrice: retail_price,
  1735. NewPrice: new_price,
  1736. Manufacturer: manufacturer,
  1737. Dealer: dealer,
  1738. Remark: remark,
  1739. DrugId: drug_id,
  1740. UserOrgId: orgId,
  1741. Ctime: time.Now().Unix(),
  1742. Mtime: 0,
  1743. Status: 1,
  1744. WarehousingOrder: warehousing_order,
  1745. LicenseNumber: "",
  1746. StartTime: startTime,
  1747. Creater: Creater,
  1748. Checker: 0,
  1749. CheckerStatus: 2,
  1750. CheckerTime: 0,
  1751. ExpiryDate: expiry_date,
  1752. ProductDate: product_date,
  1753. Number: numbers,
  1754. //BatchNumber: batch_number,
  1755. Total: total,
  1756. WarehouseInfoId: warehouse_info_id,
  1757. DrugOriginPlace: drug_origin_place,
  1758. MinUnit: min_unit,
  1759. MinCount: min_count,
  1760. }
  1761. err = service.CreateDrugInventory(inventory)
  1762. fmt.Println(err)
  1763. }
  1764. }
  1765. this.ServeSuccessJSON(map[string]interface{}{
  1766. "msg": "msg",
  1767. })
  1768. }
  1769. func (this *SelfDrugApiController) GetDrugInventoryList() {
  1770. timeLayout := "2006-01-02"
  1771. loc, _ := time.LoadLocation("Local")
  1772. dataBody := make(map[string]interface{}, 0)
  1773. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1774. fmt.Println(err)
  1775. orgId := this.GetAdminUserInfo().CurrentOrgId
  1776. keyword := this.GetString("keyword")
  1777. start_time := this.GetString("start_time")
  1778. end_time := this.GetString("end_time")
  1779. var startTime int64
  1780. if len(start_time) > 0 {
  1781. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1782. if err != nil {
  1783. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1784. return
  1785. }
  1786. startTime = theTime.Unix()
  1787. }
  1788. var endTime int64
  1789. if len(end_time) > 0 {
  1790. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1791. if err != nil {
  1792. utils.ErrorLog(err.Error())
  1793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1794. return
  1795. }
  1796. endTime = theTime.Unix()
  1797. }
  1798. limit, _ := this.GetInt64("limit")
  1799. page, _ := this.GetInt64("page")
  1800. list, total, err := service.GetDrugInventoryList(keyword, page, limit, orgId, startTime, endTime)
  1801. doctorList, _ := service.GetAllDoctorThree(orgId)
  1802. houseList, _ := service.GetAllStoreHouseList(orgId)
  1803. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1804. if err != nil {
  1805. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1806. return
  1807. }
  1808. this.ServeSuccessJSON(map[string]interface{}{
  1809. "total": total,
  1810. "list": list,
  1811. "doctorList": doctorList,
  1812. "houseList": houseList,
  1813. "houseConfig": houseConfig,
  1814. })
  1815. }
  1816. func (this *SelfDrugApiController) SaveDrugCheckInventory() {
  1817. timeLayout := "2006-01-02"
  1818. loc, _ := time.LoadLocation("Local")
  1819. dataBody := make(map[string]interface{}, 0)
  1820. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1821. fmt.Println(err)
  1822. idstr := this.GetString("ids")
  1823. ids := strings.Split(idstr, ",")
  1824. check_time := this.GetString("check_time")
  1825. var checkTime int64
  1826. if len(check_time) > 0 {
  1827. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1828. if err != nil {
  1829. fmt.Println(err)
  1830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1831. return
  1832. }
  1833. checkTime = theTime.Unix()
  1834. }
  1835. checker, _ := this.GetInt64("checker")
  1836. inventory := models.XtDrugInventory{
  1837. Checker: checker,
  1838. CheckerStatus: 1,
  1839. CheckerTime: checkTime,
  1840. }
  1841. err = service.UpdateDrugInventory(ids, inventory)
  1842. fmt.Println(err)
  1843. list, _ := service.GetDrugInventoryListByIds(ids)
  1844. adminUserInfo := this.GetAdminUserInfo()
  1845. var stock_total int64
  1846. var proof_count int64
  1847. var maxNumber int64
  1848. var minNumber int64
  1849. for _, item := range list {
  1850. //查询药品信息
  1851. drug, _ := service.GetDrugDetailByDrugId(item.DrugId)
  1852. //查询库存
  1853. info, _ := service.GetDrugWareInfoByIdTwo(item.WarehouseInfoId)
  1854. var max_count int64
  1855. var min_count int64
  1856. for _, it := range info {
  1857. max_count += it.StockMaxNumber
  1858. min_count += it.StockMinNumber
  1859. }
  1860. //获取最晚的库存数量
  1861. lastInfo, _ := service.GetLastDrugWarehouseInfo(item.DrugId)
  1862. firstInfo, _ := service.GetFirstDrugWarehouseInfo(item.DrugId)
  1863. stock_total = max_count*drug.MinNumber + min_count
  1864. proof_count = item.Count*drug.MinNumber + item.MinCount
  1865. fmt.Println("stock_total", stock_total)
  1866. fmt.Println("proof_count", proof_count)
  1867. //判断 如果库存数量 大于盘点库存,则出库
  1868. if stock_total > proof_count {
  1869. minNumber = (stock_total - proof_count) % drug.MinNumber
  1870. maxNumber = (stock_total - proof_count) / drug.MinNumber
  1871. ctime := time.Now().Unix()
  1872. timeStr := time.Now().Format("2006-01-02")
  1873. timeArr := strings.Split(timeStr, "-")
  1874. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1875. total = total + 1
  1876. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1877. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1878. number = number + total
  1879. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1880. operation_time := time.Now().Unix()
  1881. creater := adminUserInfo.AdminUser.Id
  1882. warehouseOut := models.DrugWarehouseOut{
  1883. WarehouseOutOrderNumber: warehousing_out_order,
  1884. OperationTime: operation_time,
  1885. OrgId: adminUserInfo.CurrentOrgId,
  1886. Creater: creater,
  1887. Ctime: ctime,
  1888. Status: 1,
  1889. WarehouseOutTime: ctime,
  1890. Type: 1,
  1891. }
  1892. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1893. warehouse, _ := service.GetLastDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1894. warehouseOutInfo := models.DrugWarehouseOutInfo{
  1895. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1896. WarehouseOutId: warehouse.ID,
  1897. DrugId: item.DrugId,
  1898. Count: maxNumber,
  1899. Price: firstInfo.Price,
  1900. TotalPrice: firstInfo.TotalPrice,
  1901. Status: 1,
  1902. Ctime: ctime,
  1903. Remark: item.Remark,
  1904. OrgId: adminUserInfo.CurrentOrgId,
  1905. Type: 1,
  1906. Manufacturer: firstInfo.Manufacturer,
  1907. Dealer: firstInfo.Dealer,
  1908. RetailPrice: firstInfo.RetailPrice,
  1909. RetailTotalPrice: firstInfo.RetailTotalPrice,
  1910. CountUnit: drug.MaxUnit,
  1911. ExpiryDate: firstInfo.ExpiryDate,
  1912. ProductDate: firstInfo.ProductDate,
  1913. Number: firstInfo.Number,
  1914. BatchNumber: firstInfo.BatchNumber,
  1915. IsSys: 0,
  1916. WarehouseInfoId: firstInfo.ID,
  1917. }
  1918. drugflow := models.DrugFlow{
  1919. WarehouseOutId: warehouseOut.ID,
  1920. WarehouseOutOrderNumber: warehousing_out_order,
  1921. DrugId: item.DrugId,
  1922. Number: firstInfo.Number,
  1923. ProductDate: firstInfo.ProductDate,
  1924. ExpireDate: firstInfo.ExpiryDate,
  1925. Count: maxNumber,
  1926. Price: firstInfo.Price,
  1927. Status: 1,
  1928. Ctime: ctime,
  1929. UserOrgId: adminUserInfo.CurrentOrgId,
  1930. Manufacturer: firstInfo.Manufacturer,
  1931. Dealer: firstInfo.Dealer,
  1932. BatchNumber: firstInfo.BatchNumber,
  1933. MaxUnit: drug.MaxUnit,
  1934. ConsumableType: 2,
  1935. IsEdit: 1,
  1936. Creator: adminUserInfo.AdminUser.Id,
  1937. IsSys: 0,
  1938. }
  1939. service.CreateDrugWarehouseOutInfo(warehouseOutInfo)
  1940. service.CreateDrugFlowOne(drugflow)
  1941. //扣减当前批次号的库存
  1942. var total_count int64
  1943. //查询当前批次库存的数量
  1944. warehosueInfoList, _ := service.GetCurrentWarehosueInfo(item.WarehouseInfoId)
  1945. fmt.Println(warehosueInfoList)
  1946. for _, item := range warehosueInfoList {
  1947. total_count += item.StockMaxNumber*drug.MinNumber + item.StockMinNumber
  1948. }
  1949. //判断当前批次库存 和 需要出库的数据
  1950. //出库
  1951. if proof_count <= total_count {
  1952. //var total_count_one int64
  1953. //获取当前批次号的库存
  1954. //warehouseinfoOne, _ := service.GetCurrentWarehosueInfoOne(item.WarehouseInfoId)
  1955. //total_count_one = warehouseinfoOne.StockMaxNumber * drug.MinNumber + warehouseinfoOne.StockMinNumber
  1956. }
  1957. //报错提示
  1958. if proof_count > total_count {
  1959. this.ServeSuccessJSON(map[string]interface{}{
  1960. "msg": "1",
  1961. })
  1962. }
  1963. }
  1964. //判断 如果库存数量 小于于盘点库存,则入库
  1965. fmt.Println("stock_total2332322323223", stock_total, proof_count)
  1966. if stock_total < proof_count {
  1967. maxNumber = (proof_count - stock_total) / drug.MinNumber
  1968. minNumber = (proof_count - stock_total) % drug.MinNumber
  1969. fmt.Println("min_number23233232323223322323", minNumber)
  1970. ctime := time.Now().Unix()
  1971. timeStr := time.Now().Format("2006-01-02")
  1972. timeArr := strings.Split(timeStr, "-")
  1973. total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
  1974. total = total + 1
  1975. fmt.Println("total2323232323232", total)
  1976. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1977. operation_time := time.Now().Unix()
  1978. creater := adminUserInfo.AdminUser.Id
  1979. warehousing := models.DrugWarehouse{
  1980. WarehousingOrder: warehousing_order,
  1981. OperationTime: operation_time,
  1982. OrgId: adminUserInfo.CurrentOrgId,
  1983. Creater: creater,
  1984. Ctime: ctime,
  1985. Status: 1,
  1986. WarehousingTime: ctime,
  1987. Type: 1,
  1988. }
  1989. service.AddSigleDrugWarehouse(&warehousing)
  1990. warehouse, _ := service.GetLastDrugWarehouse(adminUserInfo.CurrentOrgId)
  1991. warehouseInfo := models.DrugWarehouseInfo{
  1992. WarehousingOrder: warehousing.WarehousingOrder,
  1993. WarehousingId: warehouse.ID,
  1994. DrugId: item.DrugId,
  1995. Number: lastInfo.Number,
  1996. ProductDate: lastInfo.ProductDate,
  1997. ExpiryDate: lastInfo.ExpiryDate,
  1998. WarehousingCount: maxNumber,
  1999. Price: lastInfo.Price,
  2000. TotalPrice: lastInfo.TotalPrice,
  2001. Status: 1,
  2002. Ctime: ctime,
  2003. Remark: item.Remark,
  2004. OrgId: adminUserInfo.CurrentOrgId,
  2005. Type: 1,
  2006. Manufacturer: lastInfo.Manufacturer,
  2007. Dealer: lastInfo.Dealer,
  2008. StockMaxNumber: maxNumber,
  2009. StockMinNumber: minNumber,
  2010. RetailTotalPrice: lastInfo.RetailTotalPrice,
  2011. BatchNumber: lastInfo.BatchNumber,
  2012. MaxUnit: drug.MaxUnit,
  2013. MinUnit: drug.MinUnit,
  2014. WarehousingInfoId: item.WarehouseInfoId,
  2015. }
  2016. drugflow := models.DrugFlow{
  2017. WarehousingOrder: warehousing.WarehousingOrder,
  2018. WarehousingId: warehouse.ID,
  2019. DrugId: item.DrugId,
  2020. Number: lastInfo.Number,
  2021. ProductDate: lastInfo.ProductDate,
  2022. ExpireDate: lastInfo.ExpiryDate,
  2023. Count: maxNumber,
  2024. Price: lastInfo.Price,
  2025. Status: 1,
  2026. Ctime: ctime,
  2027. UserOrgId: adminUserInfo.CurrentOrgId,
  2028. Manufacturer: lastInfo.Manufacturer,
  2029. Dealer: lastInfo.Dealer,
  2030. BatchNumber: lastInfo.BatchNumber,
  2031. MaxUnit: drug.MaxUnit,
  2032. MinUnit: drug.MinUnit,
  2033. ConsumableType: 1,
  2034. IsEdit: 1,
  2035. Creator: adminUserInfo.AdminUser.Id,
  2036. IsSys: 0,
  2037. }
  2038. service.CreateDrugWarehouseInfo(warehouseInfo)
  2039. service.CreateDrugFlowOne(drugflow)
  2040. }
  2041. }
  2042. returnData := make(map[string]interface{}, 0)
  2043. returnData["msg"] = "ok"
  2044. this.ServeSuccessJSON(returnData)
  2045. }
  2046. func (this *SelfDrugApiController) GetDrugInventoryDetail() {
  2047. id, _ := this.GetInt64("id")
  2048. detail, err := service.GetDrugInventoryDetail(id)
  2049. if err != nil {
  2050. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2051. return
  2052. }
  2053. this.ServeSuccessJSON(map[string]interface{}{
  2054. "detail": detail,
  2055. })
  2056. }
  2057. func (this *SelfDrugApiController) ModifyInventory() {
  2058. id, _ := this.GetInt64("id")
  2059. drug_id, _ := this.GetInt64("drug_id")
  2060. drug_name := this.GetString("drug_name")
  2061. specification_name := this.GetString("specification_name")
  2062. retailPrice := this.GetString("retail_price")
  2063. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  2064. warehousing_order := this.GetString("warehousing_order")
  2065. number := this.GetString("number")
  2066. manufacturer := this.GetString("manufacturer")
  2067. remark := this.GetString("remark")
  2068. warehousing_unit := this.GetString("warehousing_unit")
  2069. total := this.GetString("total")
  2070. lastPrice := this.GetString("last_price")
  2071. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  2072. count, _ := this.GetInt64("count")
  2073. drug_origin_place := this.GetString("drug_origin_place")
  2074. stock_max_number, _ := this.GetInt64("stock_max_number")
  2075. stock_min_number, _ := this.GetInt64("stock_min_number")
  2076. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2077. min_count, _ := this.GetInt64("min_count")
  2078. min_unit := this.GetString("min_unit")
  2079. inventory := models.XtDrugInventory{
  2080. DrugName: drug_name,
  2081. SpecificationName: specification_name,
  2082. WarehousingUnit: warehousing_unit,
  2083. Count: count,
  2084. LastPrice: last_price,
  2085. RetailPrice: retail_price,
  2086. Manufacturer: manufacturer,
  2087. Remark: remark,
  2088. DrugId: drug_id,
  2089. WarehousingOrder: warehousing_order,
  2090. Number: number,
  2091. Total: total,
  2092. DrugOriginPlace: drug_origin_place,
  2093. StockMaxNumber: stock_max_number,
  2094. StockMinNumber: stock_min_number,
  2095. WarehouseInfoId: warehouse_info_id,
  2096. MinCount: min_count,
  2097. MinUnit: min_unit,
  2098. }
  2099. err := service.ModifyDrugInventory(id, inventory)
  2100. if err != nil {
  2101. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2102. return
  2103. }
  2104. this.ServeSuccessJSON(map[string]interface{}{
  2105. "inventory": inventory,
  2106. })
  2107. }
  2108. func (this *SelfDrugApiController) DeleteDrugInventory() {
  2109. id, _ := this.GetInt64("id")
  2110. err := service.DeleteDrugInventory(id)
  2111. fmt.Println(err)
  2112. returnData := make(map[string]interface{}, 0)
  2113. returnData["msg"] = "ok"
  2114. this.ServeSuccessJSON(returnData)
  2115. }
  2116. func (this *SelfDrugApiController) GetDrugInventoryPrintList() {
  2117. ids := this.GetString("ids")
  2118. idssplit := strings.Split(ids, ",")
  2119. list, err := service.GetDrugInventoryPrintList(idssplit)
  2120. if err != nil {
  2121. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2122. return
  2123. }
  2124. this.ServeSuccessJSON(map[string]interface{}{
  2125. "list": list,
  2126. })
  2127. }
  2128. func (this *SelfDrugApiController) GetDrugInventoryDetailList() {
  2129. keyword := this.GetString("keyword")
  2130. limit, _ := this.GetInt64("limit")
  2131. page, _ := this.GetInt64("page")
  2132. storehouse_id, _ := this.GetInt64("storehouse_id")
  2133. orgId := this.GetAdminUserInfo().CurrentOrgId
  2134. list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId, storehouse_id)
  2135. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  2136. houseList, _ := service.GetAllStoreHouseList(orgId)
  2137. doctorList, _ := service.GetAllDoctorThree(orgId)
  2138. if err != nil {
  2139. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2140. return
  2141. }
  2142. this.ServeSuccessJSON(map[string]interface{}{
  2143. "total": total,
  2144. "list": list,
  2145. "doctorList": doctorList,
  2146. "houseList": houseList,
  2147. "inventoryList": inventoryList,
  2148. })
  2149. }
  2150. func (this *SelfDrugApiController) SaveDrugProofInventory() {
  2151. id, _ := this.GetInt64("id")
  2152. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2153. warehousing_unit := this.GetString("warehousing_unit")
  2154. remark := this.GetString("remark")
  2155. proof_count, _ := this.GetInt64("proof_count")
  2156. inventory := models.XtDrugInventory{
  2157. WarehouseInfoId: warehouse_info_id,
  2158. ProofCount: proof_count,
  2159. WarehousingUnit: warehousing_unit,
  2160. Remark: remark,
  2161. }
  2162. err := service.UpdateDrugProofInventory(id, &inventory)
  2163. info := models.XtDrugWarehouseInfo{
  2164. StockMaxNumber: proof_count,
  2165. }
  2166. service.UpdateDrugWarehouseInfoById(warehouse_info_id, &info)
  2167. if err != nil {
  2168. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2169. return
  2170. }
  2171. this.ServeSuccessJSON(map[string]interface{}{
  2172. "inventory": inventory,
  2173. })
  2174. }
  2175. func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
  2176. id, _ := this.GetInt64("id")
  2177. list, _ := service.GetDrugWarehouseInfoTotal(id)
  2178. this.ServeSuccessJSON(map[string]interface{}{
  2179. "list": list,
  2180. })
  2181. }
  2182. //新改造
  2183. func (this *SelfDrugApiController) SaveInventoryList() {
  2184. dataBody := make(map[string]interface{}, 0)
  2185. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2186. fmt.Println(err)
  2187. tableData, _ := dataBody["tableData"].([]interface{})
  2188. if len(tableData) > 0 {
  2189. for _, item := range tableData {
  2190. items := item.(map[string]interface{})
  2191. drug_name := items["drug_name"].(string)
  2192. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  2193. utils.ErrorLog("drug_name")
  2194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2195. return
  2196. }
  2197. fmt.Println("drug_name", drug_name)
  2198. specification_name := items["specification_name"].(string)
  2199. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  2200. utils.ErrorLog("specification_name")
  2201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2202. return
  2203. }
  2204. max_unit := items["max_unit"].(string)
  2205. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  2206. utils.ErrorLog("max_unit")
  2207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2208. return
  2209. }
  2210. min_unit := items["min_unit"].(string)
  2211. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  2212. utils.ErrorLog("min_unit")
  2213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2214. return
  2215. }
  2216. drug_id := int64(items["drug_id"].(float64))
  2217. min_number := int64(items["min_number"].(float64))
  2218. stock_max_number := int64(items["stock_max_number"].(float64))
  2219. stock_min_number := int64(items["stock_min_number"].(float64))
  2220. last_stock_max_number := int64(items["last_stock_max_number"].(float64))
  2221. last_stock_min_number := int64(items["last_stock_min_number"].(float64))
  2222. warehousing_order := items["warehousing_order"].(string)
  2223. price := items["price"].(float64)
  2224. manufacturer_name := items["manufacturer_name"].(string)
  2225. batch_number := items["batch_number"].(string)
  2226. id := int64(items["id"].(float64))
  2227. orgId := this.GetAdminUserInfo().CurrentOrgId
  2228. type_id := int64(items["type"].(float64))
  2229. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  2230. utils.ErrorLog("expiry_date")
  2231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2232. return
  2233. }
  2234. expiry_date := int64(items["expiry_date"].(float64))
  2235. manufacturer := int64(items["manufacturer"].(float64))
  2236. storehouse_id := int64(items["storehouse_id"].(float64))
  2237. timeLayout := "2006-01-02"
  2238. loc, _ := time.LoadLocation("Local")
  2239. timeNow := time.Now().Format("2006-01-02")
  2240. locationTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeNow+" 00:00:00", loc)
  2241. var consumable_type int64
  2242. var consumable_count int64
  2243. var ord_total int64
  2244. var new_total int64
  2245. var total int64
  2246. ord_total = stock_max_number*min_number + stock_min_number
  2247. new_total = last_stock_max_number*min_number + last_stock_min_number
  2248. medical, _ := service.GetBaseDrugMedical(drug_id)
  2249. //改变库存
  2250. info := models.DrugWarehouseInfo{
  2251. DrugId: drug_id,
  2252. StockMaxNumber: last_stock_max_number,
  2253. StockMinNumber: last_stock_min_number,
  2254. WarehousingCount: last_stock_max_number,
  2255. MaxUnit: max_unit,
  2256. MinUnit: min_unit,
  2257. }
  2258. drugInfo, _ := service.GetCurrentWarehosueInfoOne(id)
  2259. if drugInfo.MaxUnit == medical.MaxUnit {
  2260. total = drugInfo.WarehousingCount * medical.MinNumber
  2261. }
  2262. if drugInfo.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2263. total = drugInfo.WarehousingCount
  2264. }
  2265. //如果库存数据大于盘点数据,则减去数量
  2266. if ord_total > new_total {
  2267. consumable_type = 11
  2268. consumable_count = ord_total - new_total
  2269. err = service.ModifyDrugWarehouseInfo(&info, id)
  2270. }
  2271. //如果库存数据小于盘点数据,则增加数量
  2272. if ord_total < new_total && new_total <= total {
  2273. consumable_type = 10
  2274. consumable_count = new_total - ord_total
  2275. err = service.ModifyDrugWarehouseInfo(&info, id)
  2276. }
  2277. if ord_total < new_total && new_total > total {
  2278. consumable_type = 10
  2279. consumable_count = new_total - ord_total
  2280. err = service.ModifyDrugWarehouseInfoSix(&info, id)
  2281. }
  2282. //查询默认仓库
  2283. houseConfig, _ := service.GetAllStoreHouseConfig(drugInfo.OrgId)
  2284. //查询默认仓库剩余多少库存
  2285. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, drugInfo.OrgId, drugInfo.DrugId)
  2286. var sum_count int64
  2287. var sum_in_count int64
  2288. for _, it := range list {
  2289. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2290. if it.MaxUnit == baseDrug.MaxUnit {
  2291. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2292. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2293. }
  2294. sum_count += it.StockMaxNumber + it.StockMinNumber
  2295. sum_in_count += it.WarehousingCount
  2296. }
  2297. service.UpdateMedicalSumCount(drugInfo.DrugId, sum_count, sum_in_count, drugInfo.OrgId)
  2298. //更新剩余库存
  2299. service.UpdateDrugStockCount(drugInfo.DrugId, drugInfo.OrgId, houseConfig.DrugStorehouseOut, sum_count)
  2300. inventory := models.XtDrugInventory{
  2301. DrugName: drug_name,
  2302. SpecificationName: specification_name,
  2303. WarehousingUnit: max_unit,
  2304. Count: consumable_count,
  2305. LastPrice: price,
  2306. RetailPrice: 0,
  2307. NewPrice: 0,
  2308. Manufacturer: manufacturer_name,
  2309. Dealer: "",
  2310. Remark: "",
  2311. DrugId: drug_id,
  2312. UserOrgId: orgId,
  2313. Ctime: time.Now().Unix(),
  2314. Mtime: 0,
  2315. Status: 1,
  2316. WarehousingOrder: warehousing_order,
  2317. LicenseNumber: "",
  2318. StartTime: locationTime.Unix(),
  2319. Creater: this.GetAdminUserInfo().AdminUser.Id,
  2320. Checker: 0,
  2321. CheckerStatus: 0,
  2322. CheckerTime: 0,
  2323. ExpiryDate: expiry_date,
  2324. ProductDate: 0,
  2325. Number: "",
  2326. BatchNumber: batch_number,
  2327. Total: "",
  2328. DrugOriginPlace: "",
  2329. WarehouseInfoId: id,
  2330. ProofCount: 0,
  2331. StockMaxNumber: stock_max_number,
  2332. StockMinNumber: stock_min_number,
  2333. MinCount: 0,
  2334. MinUnit: min_unit,
  2335. LastStockMaxNumber: last_stock_max_number,
  2336. LastStockMinNumber: last_stock_min_number,
  2337. InventoryType: consumable_type,
  2338. Type: type_id,
  2339. StorehouseId: storehouse_id,
  2340. }
  2341. err = service.CreateDrugInventory(inventory)
  2342. flow := models.DrugFlow{
  2343. WarehousingId: id,
  2344. DrugId: drug_id,
  2345. Number: "",
  2346. BatchNumber: batch_number,
  2347. Count: consumable_count,
  2348. UserOrgId: orgId,
  2349. PatientId: 0,
  2350. SystemTime: locationTime.Unix(),
  2351. ConsumableType: consumable_type,
  2352. IsSys: 1,
  2353. WarehousingOrder: warehousing_order,
  2354. WarehouseOutId: 0,
  2355. WarehouseOutOrderNumber: "",
  2356. IsEdit: 0,
  2357. CancelStockId: 0,
  2358. CancelOrderNumber: "",
  2359. Manufacturer: manufacturer,
  2360. Dealer: 0,
  2361. Creator: this.GetAdminUserInfo().AdminUser.Id,
  2362. UpdateCreator: 0,
  2363. Status: 1,
  2364. Ctime: time.Now().Unix(),
  2365. Mtime: 0,
  2366. Price: price,
  2367. WarehousingDetailId: id,
  2368. WarehouseOutDetailId: 0,
  2369. CancelOutDetailId: 0,
  2370. ExpireDate: expiry_date,
  2371. ProductDate: 0,
  2372. MaxUnit: min_unit,
  2373. MinUnit: min_unit,
  2374. StorehouseId: storehouse_id,
  2375. OverCount: sum_count,
  2376. }
  2377. if ord_total != new_total {
  2378. service.CreateDrugFlowOne(flow)
  2379. }
  2380. if err != nil {
  2381. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2382. return
  2383. }
  2384. this.ServeSuccessJSON(map[string]interface{}{
  2385. "inventory": inventory,
  2386. })
  2387. }
  2388. }
  2389. }
  2390. func (this *SelfDrugApiController) GetDamageByDrugId() {
  2391. drug_id, _ := this.GetInt64("drug_id")
  2392. warehousing_order := this.GetString("warehouseing_order")
  2393. drug_type, _ := this.GetInt64("type")
  2394. list, err := service.GetDamageByDrugId(drug_id, warehousing_order, drug_type)
  2395. if err != nil {
  2396. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2397. return
  2398. }
  2399. this.ServeSuccessJSON(map[string]interface{}{
  2400. "list": list,
  2401. })
  2402. }
  2403. func (this *SelfDrugApiController) GetInventoryModeList() {
  2404. orgId := this.GetAdminUserInfo().CurrentOrgId
  2405. list, err := service.GetInventoryModeList(orgId)
  2406. manufacturerList, err := service.GetAllManufacturerList(orgId)
  2407. if err != nil {
  2408. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2409. return
  2410. }
  2411. this.ServeSuccessJSON(map[string]interface{}{
  2412. "list": list,
  2413. "manufacturerList": manufacturerList,
  2414. })
  2415. }
  2416. // 库存优化接口
  2417. func (this *SelfDrugApiController) GetStorehouseList() {
  2418. orgId := this.GetAdminUserInfo().CurrentOrgId
  2419. list, err := service.GetAllStoreHouseList(orgId)
  2420. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  2421. goodType, _ := service.GetAllNewGoodType(orgId)
  2422. patientList, _ := service.GetAllpatientThirty(orgId)
  2423. dealerList, _ := service.GetAllDealerList(orgId)
  2424. if err != nil {
  2425. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取仓库失败")
  2426. return
  2427. }
  2428. this.ServeSuccessJSON(map[string]interface{}{
  2429. "list": list,
  2430. "manufacturerList": manufacturerList,
  2431. "goodTypeList": goodType,
  2432. "patientList": patientList,
  2433. "dealerList": dealerList,
  2434. })
  2435. }
  2436. func (this *SelfDrugApiController) GetGoodNewQuery() {
  2437. orgId := this.GetAdminUserInfo().CurrentOrgId
  2438. storehouse_id, _ := this.GetInt64("storehouse_id")
  2439. good_type, _ := this.GetInt64("good_type")
  2440. keyword := this.GetString("keyword")
  2441. page, _ := this.GetInt64("page")
  2442. limit, _ := this.GetInt64("limit")
  2443. // 查询该机构所有耗材入库信息
  2444. goodList, _ := service.GetAllGoodListSeven(orgId)
  2445. for _, it := range goodList {
  2446. var sum_total int64
  2447. //查询该耗材入库信息
  2448. warehouseinfo, _ := service.GetGoodInformationWarehouseInfo(it.ID, orgId)
  2449. for _, item := range warehouseinfo {
  2450. sum_total += item.StockCount
  2451. }
  2452. service.UpdateGoodInformation(it.ID, orgId, sum_total)
  2453. //stockListTwo, _ := service.GetGoodStockCountList(orgId, it.ID)
  2454. //if len(stockListTwo) > 0 {
  2455. // for _, item := range stockListTwo {
  2456. // var over_count int64
  2457. // over_count = item.StockInCount - item.FlushCount
  2458. // service.UpdateGoodListCount(item.UserOrgId, over_count, item.GoodId, item.StorehouseId)
  2459. //
  2460. // }
  2461. //}
  2462. //
  2463. //stockListOne, _ := service.GetGoodStockCountList(orgId, it.ID)
  2464. //if len(stockListOne) > 0 {
  2465. // for _, item := range stockListOne {
  2466. // var over_count int64
  2467. // over_count = item.StockOutCount + item.StockCancelCount
  2468. // service.UpdateGoodListCountOne(item.UserOrgId, over_count, item.GoodId, item.StorehouseId)
  2469. // }
  2470. //}
  2471. }
  2472. var ids []int64
  2473. manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2474. for _, it := range manufacturerList {
  2475. ids = append(ids, it.ID)
  2476. }
  2477. stockList, total, err := service.GetGoodStockList(orgId, storehouse_id, good_type, keyword, page, limit, ids)
  2478. if err != nil {
  2479. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
  2480. return
  2481. }
  2482. this.ServeSuccessJSON(map[string]interface{}{
  2483. "total": total,
  2484. "stockList": stockList,
  2485. })
  2486. }
  2487. func (this *SelfDrugApiController) GetGoodWarehouseOutInfoByIdList() {
  2488. good_id, _ := this.GetInt64("good_id")
  2489. limit, _ := this.GetInt64("limit")
  2490. page, _ := this.GetInt64("page")
  2491. start_time := this.GetString("start_first_time")
  2492. end_time := this.GetString("end_first_time")
  2493. storehouse_id, _ := this.GetInt64("storehouse_id")
  2494. orgId := this.GetAdminUserInfo().CurrentOrgId
  2495. timeLayout := "2006-01-02"
  2496. loc, _ := time.LoadLocation("Local")
  2497. var startTime int64
  2498. if len(start_time) > 0 {
  2499. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2500. if err != nil {
  2501. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2502. return
  2503. }
  2504. startTime = theTime.Unix()
  2505. }
  2506. var endTime int64
  2507. if len(end_time) > 0 {
  2508. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2509. if err != nil {
  2510. utils.ErrorLog(err.Error())
  2511. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2512. return
  2513. }
  2514. endTime = theTime.Unix()
  2515. }
  2516. list, total, err := service.GetGoodWarehouseOutInfoByIdList(good_id, limit, page, orgId, startTime, endTime, storehouse_id)
  2517. //flushList, _ := service.GetStockFlushByGoodId(good_id, orgId, startTime, endTime)
  2518. //warehouseInfoByList, _ := service.GetGoodWarehouseInfoByList(good_id, orgId, startTime, endTime)
  2519. //cancelStockInfoByList, _ := service.GetGoodCancelStockInfoByList(good_id, orgId, startTime, endTime)
  2520. //warehouseOutByList,_ := service.GetGoodWarehouseOutInfoByIdListTwenty(good_id, limit, page, orgId, startTime, endTime)
  2521. if err != nil {
  2522. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
  2523. return
  2524. }
  2525. this.ServeSuccessJSON(map[string]interface{}{
  2526. "total": total,
  2527. "list": list,
  2528. //"warehouseInfoByList":warehouseInfoByList,
  2529. //"cancelStockInfoByList":cancelStockInfoByList,
  2530. //"warehouseOutByList":warehouseOutByList,
  2531. //"flushList":flushList,
  2532. })
  2533. }
  2534. func (this *SelfDrugApiController) GetGoodPatientList() {
  2535. orgId := this.GetAdminUserInfo().CurrentOrgId
  2536. keyword := this.GetString("keyword")
  2537. list, err := service.GetGoodPatientList(orgId, keyword)
  2538. if err != nil {
  2539. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2540. return
  2541. }
  2542. this.ServeSuccessJSON(map[string]interface{}{
  2543. "list": list,
  2544. })
  2545. }
  2546. func (this *SelfDrugApiController) GetWarehouseOutDetailByPatientId() {
  2547. patient_id, _ := this.GetInt64("patient_id")
  2548. start_time := this.GetString("start_time")
  2549. end_time := this.GetString("end_time")
  2550. limit, _ := this.GetInt64("limit")
  2551. page, _ := this.GetInt64("page")
  2552. orgId := this.GetAdminUserInfo().CurrentOrgId
  2553. timeLayout := "2006-01-02"
  2554. loc, _ := time.LoadLocation("Local")
  2555. var startTime int64
  2556. if len(start_time) > 0 {
  2557. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2558. if err != nil {
  2559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2560. return
  2561. }
  2562. startTime = theTime.Unix()
  2563. }
  2564. var endTime int64
  2565. if len(end_time) > 0 {
  2566. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2567. if err != nil {
  2568. utils.ErrorLog(err.Error())
  2569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2570. return
  2571. }
  2572. endTime = theTime.Unix()
  2573. }
  2574. list, total, err := service.GetWarehouseOutDetailByPatientIdOne(orgId, patient_id, startTime, endTime, limit, page)
  2575. outlist, _ := service.GetWarehouseOutDetailByPatientId(orgId, patient_id, startTime, endTime)
  2576. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2577. if err != nil {
  2578. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2579. return
  2580. }
  2581. this.ServeSuccessJSON(map[string]interface{}{
  2582. "list": list,
  2583. "manufacturerList": manufacturerList,
  2584. "total": total,
  2585. "outlist": outlist,
  2586. })
  2587. }
  2588. func (this *SelfDrugApiController) GetGoodExpiryDateQuery() {
  2589. storehouse_id, _ := this.GetInt64("storehouse_id")
  2590. expiry_type, _ := this.GetInt64("expiry_type")
  2591. keyword := this.GetString("keyword")
  2592. page, _ := this.GetInt64("page")
  2593. limit, _ := this.GetInt64("limit")
  2594. orgId := this.GetAdminUserInfo().CurrentOrgId
  2595. start_time := this.GetString("start_time")
  2596. timeLayout := "2006-01-02"
  2597. loc, _ := time.LoadLocation("Local")
  2598. var endTime int64
  2599. if len(start_time) > 0 {
  2600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2601. if err != nil {
  2602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2603. return
  2604. }
  2605. endTime = theTime.Unix()
  2606. }
  2607. recordDateStr := time.Now().Format("2006-01-02")
  2608. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2609. fmt.Scan("parseDateErr", parseDateErr)
  2610. nowtime := recordDate.Unix()
  2611. var ids []int64
  2612. var goodIds []int64
  2613. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2614. for _, it := range manufacturers {
  2615. ids = append(ids, it.ID)
  2616. }
  2617. goodList, _ := service.GetGoodNameByword(orgId, keyword)
  2618. for _, it := range goodList {
  2619. goodIds = append(goodIds, it.ID)
  2620. }
  2621. list, total, err := service.GetGoodExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2622. fmt.Println("total233223322332323232323223", total)
  2623. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2624. if err != nil {
  2625. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2626. return
  2627. }
  2628. this.ServeSuccessJSON(map[string]interface{}{
  2629. "list": list,
  2630. "manufacturerList": manufacturerList,
  2631. "total": total,
  2632. "nowtime": nowtime,
  2633. })
  2634. }
  2635. func (this *SelfDrugApiController) GetGoodPurchaseStockQuery() {
  2636. good_type, _ := this.GetInt64("good_type")
  2637. keyword := this.GetString("keyword")
  2638. page, _ := this.GetInt64("page")
  2639. limit, _ := this.GetInt64("limit")
  2640. start_time := this.GetString("start_time")
  2641. end_time := this.GetString("end_time")
  2642. orgId := this.GetAdminUserInfo().CurrentOrgId
  2643. timeLayout := "2006-01-02"
  2644. loc, _ := time.LoadLocation("Local")
  2645. var startTime int64
  2646. if len(start_time) > 0 {
  2647. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2648. if err != nil {
  2649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2650. return
  2651. }
  2652. startTime = theTime.Unix()
  2653. }
  2654. var endTime int64
  2655. if len(end_time) > 0 {
  2656. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2657. if err != nil {
  2658. utils.ErrorLog(err.Error())
  2659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2660. return
  2661. }
  2662. endTime = theTime.Unix()
  2663. }
  2664. var ids []int64
  2665. var goodIds []int64
  2666. infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  2667. for _, it := range infoList {
  2668. goodIds = append(goodIds, it.GoodId)
  2669. }
  2670. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2671. for _, it := range manufacturers {
  2672. ids = append(ids, it.ID)
  2673. }
  2674. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2675. list, total, err := service.GetGoodPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
  2676. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2677. for _, item := range list {
  2678. //获取期初结余数量
  2679. infoList, _ := service.GetStartGoodWarehouseInfoList(item.ID, orgId, startTime)
  2680. for _, it := range infoList {
  2681. item.WarehousingInfoStart = append(item.WarehousingInfoStart, it)
  2682. }
  2683. //获取期末结余数量
  2684. warehouseInfoList, _ := service.GetEndGoodWarehouseInfoList(item.ID, orgId, endTime)
  2685. for _, it := range warehouseInfoList {
  2686. item.WarehousingInfoEnd = append(item.WarehousingInfoEnd, it)
  2687. }
  2688. //获取期间增加
  2689. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2690. for _, it := range goodWarehouseInfoList {
  2691. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  2692. }
  2693. //获取本期增加
  2694. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2695. for _, it := range WarehouseInfoFlowList {
  2696. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  2697. }
  2698. //获取本期减少
  2699. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2700. for _, it := range reduceWarehouseInfoList {
  2701. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  2702. }
  2703. //获取期中减少退库
  2704. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2705. for _, it := range lowInfo {
  2706. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  2707. }
  2708. //
  2709. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  2710. for _, it := range outInfo {
  2711. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  2712. }
  2713. //获取期初结余
  2714. info, _ := service.FindeStartFlowInfo(item.ID, orgId, startTime)
  2715. for _, it := range info {
  2716. item.StartFlowInfo = append(item.StartFlowInfo, it)
  2717. }
  2718. //获取期初结余
  2719. flowOutInfo, _ := service.FindeStartFlowOutInfo(item.ID, orgId, startTime)
  2720. for _, it := range flowOutInfo {
  2721. item.StartOutFlowInfo = append(item.StartOutFlowInfo, it)
  2722. }
  2723. //获取期初退库
  2724. cancelInfo, _ := service.FindeStartCancelInfo(item.ID, orgId, startTime)
  2725. for _, it := range cancelInfo {
  2726. item.StartCancelFlowInfo = append(item.StartCancelFlowInfo, it)
  2727. }
  2728. //获取期末结余
  2729. flowInfo, _ := service.FindEndStartFlowInfo(item.ID, orgId, endTime)
  2730. for _, it := range flowInfo {
  2731. item.EndFlowInfo = append(item.EndFlowInfo, it)
  2732. }
  2733. //获取期末出库
  2734. lowOutInfo, _ := service.FindeEndFLowOutInfo(item.ID, orgId, endTime)
  2735. for _, it := range lowOutInfo {
  2736. item.EndFlowOutInfo = append(item.EndFlowOutInfo, it)
  2737. }
  2738. //获取期末退库
  2739. endCancelInfo, _ := service.FindEndCancelInfo(item.ID, orgId, endTime)
  2740. for _, it := range endCancelInfo {
  2741. item.EndCancelFLowInfo = append(item.EndCancelFLowInfo, it)
  2742. }
  2743. //期初盘赢
  2744. inventory, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, startTime)
  2745. for _, it := range inventory {
  2746. item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  2747. }
  2748. //期初盘亏
  2749. stockInventory, _ := service.FindStartStockInventoryLosses(item.ID, orgId, startTime)
  2750. for _, it := range stockInventory {
  2751. item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  2752. }
  2753. //期末盘盈
  2754. inventoryProfit, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, endTime)
  2755. for _, it := range inventoryProfit {
  2756. item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  2757. }
  2758. //期末盘亏
  2759. inventoryLosses, _ := service.FindStartStockInventoryLosses(item.ID, orgId, endTime)
  2760. for _, it := range inventoryLosses {
  2761. item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  2762. }
  2763. //期中盘盈
  2764. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2765. for _, it := range profit {
  2766. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  2767. }
  2768. //期中盘亏
  2769. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2770. for _, it := range losses {
  2771. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  2772. }
  2773. }
  2774. if err != nil {
  2775. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2776. return
  2777. }
  2778. this.ServeSuccessJSON(map[string]interface{}{
  2779. "list": list,
  2780. "manufacturerList": manufacturerList,
  2781. "total": total,
  2782. })
  2783. }
  2784. func (this *SelfDrugApiController) GetDrugWarehouseOutDetailByPatientId() {
  2785. patient_id, _ := this.GetInt64("patient_id")
  2786. start_time := this.GetString("start_time")
  2787. end_time := this.GetString("end_time")
  2788. orgId := this.GetAdminUserInfo().CurrentOrgId
  2789. limit, _ := this.GetInt64("limit")
  2790. page, _ := this.GetInt64("page")
  2791. timeLayout := "2006-01-02"
  2792. loc, _ := time.LoadLocation("Local")
  2793. var startTime int64
  2794. if len(start_time) > 0 {
  2795. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2796. if err != nil {
  2797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2798. return
  2799. }
  2800. startTime = theTime.Unix()
  2801. }
  2802. var endTime int64
  2803. if len(end_time) > 0 {
  2804. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2805. if err != nil {
  2806. utils.ErrorLog(err.Error())
  2807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. endTime = theTime.Unix()
  2811. }
  2812. list, total, _ := service.GetDrugWarehouseOutDetailByPatientIdOne(patient_id, orgId, startTime, endTime, page, limit)
  2813. outlist, _ := service.GetDrugWarehouseOutDetailByPatientId(patient_id, orgId, startTime, endTime)
  2814. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2815. this.ServeSuccessJSON(map[string]interface{}{
  2816. "list": list,
  2817. "total": total,
  2818. "manufacturerList": manufacturerList,
  2819. "outlist": outlist,
  2820. })
  2821. }
  2822. func (this *SelfDrugApiController) GetDrugExpiryDateQuery() {
  2823. storehouse_id, _ := this.GetInt64("storehouse_id")
  2824. expiry_type, _ := this.GetInt64("expiry_type")
  2825. keyword := this.GetString("keyword")
  2826. page, _ := this.GetInt64("page")
  2827. limit, _ := this.GetInt64("limit")
  2828. orgId := this.GetAdminUserInfo().CurrentOrgId
  2829. start_time := this.GetString("start_time")
  2830. timeLayout := "2006-01-02"
  2831. loc, _ := time.LoadLocation("Local")
  2832. var endTime int64
  2833. if len(start_time) > 0 {
  2834. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2835. if err != nil {
  2836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2837. return
  2838. }
  2839. endTime = theTime.Unix()
  2840. }
  2841. recordDateStr := time.Now().Format("2006-01-02")
  2842. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2843. fmt.Scan("parseDateErr", parseDateErr)
  2844. nowtime := recordDate.Unix()
  2845. var ids []int64
  2846. var goodIds []int64
  2847. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2848. for _, it := range manufacturers {
  2849. ids = append(ids, it.ID)
  2850. }
  2851. drugList, _ := service.GetDrugNameByword(orgId, keyword)
  2852. for _, it := range drugList {
  2853. goodIds = append(goodIds, it.ID)
  2854. }
  2855. list, total, err := service.GetDrugExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2856. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2857. var drugType = "药品类型"
  2858. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2859. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  2860. if err != nil {
  2861. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2862. return
  2863. }
  2864. this.ServeSuccessJSON(map[string]interface{}{
  2865. "list": list,
  2866. "manufacturerList": manufacturerList,
  2867. "total": total,
  2868. "nowtime": nowtime,
  2869. "drugTypeList": drugTypeList,
  2870. })
  2871. }
  2872. func (this *SelfDrugApiController) GetPurchaseDrugQuery() {
  2873. good_type, _ := this.GetInt64("good_type")
  2874. keyword := this.GetString("keyword")
  2875. page, _ := this.GetInt64("page")
  2876. limit, _ := this.GetInt64("limit")
  2877. start_time := this.GetString("start_time")
  2878. end_time := this.GetString("end_time")
  2879. orgId := this.GetAdminUserInfo().CurrentOrgId
  2880. timeLayout := "2006-01-02"
  2881. loc, _ := time.LoadLocation("Local")
  2882. var startTime int64
  2883. if len(start_time) > 0 {
  2884. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2885. if err != nil {
  2886. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2887. return
  2888. }
  2889. startTime = theTime.Unix()
  2890. }
  2891. var endTime int64
  2892. if len(end_time) > 0 {
  2893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2894. if err != nil {
  2895. utils.ErrorLog(err.Error())
  2896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2897. return
  2898. }
  2899. endTime = theTime.Unix()
  2900. }
  2901. var ids []int64
  2902. var infoIds []int64
  2903. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2904. for _, it := range manufacturers {
  2905. ids = append(ids, it.ID)
  2906. }
  2907. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  2908. for _, it := range infoList {
  2909. infoIds = append(infoIds, it.DrugId)
  2910. }
  2911. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  2912. list, total, err := service.GetDrugPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  2913. for _, item := range list {
  2914. //获取期初结余入库数量
  2915. startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
  2916. for _, it := range startDrugInfo {
  2917. item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
  2918. }
  2919. //获取期初结余出库数量
  2920. flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
  2921. for _, it := range flowOutList {
  2922. item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
  2923. }
  2924. //获取期初结余退库数量
  2925. cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
  2926. for _, it := range cancelInfo {
  2927. item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
  2928. }
  2929. //获取期末结余入库数量
  2930. drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
  2931. for _, it := range drugwarehouseinfoend {
  2932. item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
  2933. }
  2934. //获取期末出库结余
  2935. endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
  2936. for _, it := range endDrugInfo {
  2937. item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
  2938. }
  2939. //获取期末退库数量
  2940. flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
  2941. for _, it := range flowCancelInfo {
  2942. item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
  2943. }
  2944. //期中增加
  2945. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  2946. for _, it := range drugWarehouse {
  2947. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  2948. }
  2949. //期中减少
  2950. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  2951. for _, it := range outInfo {
  2952. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  2953. }
  2954. //期中退库
  2955. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  2956. for _, it := range cancelstartInfo {
  2957. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  2958. }
  2959. //获取期初盘盈
  2960. startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
  2961. for _, it := range startProfit {
  2962. item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  2963. }
  2964. //获取期初盘亏
  2965. startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
  2966. for _, it := range startLosses {
  2967. item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  2968. }
  2969. //获取期末盘盈
  2970. endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
  2971. for _, it := range endProfit {
  2972. item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  2973. }
  2974. //获取期末盘亏
  2975. losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
  2976. for _, it := range losses {
  2977. item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  2978. }
  2979. //获取期中盘盈
  2980. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  2981. for _, it := range profit {
  2982. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  2983. }
  2984. //获取期中盘亏
  2985. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  2986. for _, it := range endLosses {
  2987. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  2988. }
  2989. }
  2990. if err != nil {
  2991. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2992. return
  2993. }
  2994. var drugType = "药品类型"
  2995. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2996. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  2997. this.ServeSuccessJSON(map[string]interface{}{
  2998. "list": list,
  2999. "manufacturerList": manufacturerList,
  3000. "total": total,
  3001. "drugTypeList": drugTypeList,
  3002. })
  3003. }
  3004. func (this *SelfDrugApiController) GetDrugNewQuery() {
  3005. orgId := this.GetAdminUserInfo().CurrentOrgId
  3006. storehouse_id, _ := this.GetInt64("storehouse_id")
  3007. good_type, _ := this.GetInt64("good_type")
  3008. keyword := this.GetString("keyword")
  3009. page, _ := this.GetInt64("page")
  3010. limit, _ := this.GetInt64("limit")
  3011. start_time := this.GetString("start_time")
  3012. end_time := this.GetString("end_time")
  3013. timeLayout := "2006-01-02"
  3014. loc, _ := time.LoadLocation("Local")
  3015. var startTime int64
  3016. if len(start_time) > 0 {
  3017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3018. if err != nil {
  3019. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3020. return
  3021. }
  3022. startTime = theTime.Unix()
  3023. }
  3024. var endTime int64
  3025. if len(end_time) > 0 {
  3026. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3027. if err != nil {
  3028. utils.ErrorLog(err.Error())
  3029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3030. return
  3031. }
  3032. endTime = theTime.Unix()
  3033. }
  3034. var ids []int64
  3035. var goodIds []int64
  3036. manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3037. //查询药品库信息
  3038. drug, _ := service.GetBaseDrugName(orgId)
  3039. for _, it := range drug {
  3040. var sum_count int64
  3041. var limit_count int64
  3042. drugInfo, _ := service.GetDrugWarehouseInfoName(it.ID, orgId)
  3043. for _, item := range drugInfo {
  3044. sum_count += item.StockMaxNumber*it.MinNumber + item.StockMinNumber
  3045. }
  3046. stockInt, _ := strconv.ParseInt(it.DrugStockLimit, 10, 64)
  3047. limit_count = stockInt * it.MinNumber
  3048. service.UpdateDrugById(it.ID, orgId, limit_count, sum_count)
  3049. //druglist, _ := service.GetDrugCountMapList(it.ID, orgId)
  3050. //if len(druglist) > 0 {
  3051. // for _, item := range druglist {
  3052. // var over_count int64
  3053. // over_count = item.SumInCount - item.FlushCount
  3054. // service.UpdateDrugStockInCount(item.DrugId, item.StorehouseId, over_count, item.UserOrgId)
  3055. // }
  3056. //}
  3057. //druglistOne, _ := service.GetDrugCountMapList(it.ID, orgId)
  3058. //if len(druglistOne) > 0 {
  3059. // for _, item := range druglistOne {
  3060. // var over_count int64
  3061. // over_count = item.SumOutCount + item.SumCancelCount
  3062. // service.UpdateDrugStockInCountOne(item.DrugId, item.StorehouseId, over_count, item.UserOrgId)
  3063. // }
  3064. //}
  3065. }
  3066. for _, it := range manufacturerList {
  3067. ids = append(ids, it.ID)
  3068. }
  3069. infoList, _ := service.GetDrugWarehouseInfoByOrgId(orgId, storehouse_id)
  3070. for _, it := range infoList {
  3071. goodIds = append(goodIds, it.DrugId)
  3072. }
  3073. countList, total, err := service.GetDrugStockCountList(orgId, storehouse_id, good_type, keyword, page, limit, ids, goodIds, startTime, endTime)
  3074. if err != nil {
  3075. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
  3076. return
  3077. }
  3078. var drugType = "药品类型"
  3079. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3080. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3081. this.ServeSuccessJSON(map[string]interface{}{
  3082. "total": total,
  3083. "drugTypeList": drugTypeList,
  3084. "countList": countList,
  3085. })
  3086. }
  3087. func (this *SelfDrugApiController) GetDrugWarehouseInfoById() {
  3088. drug_id, _ := this.GetInt64("drug_id")
  3089. limit, _ := this.GetInt64("limit")
  3090. page, _ := this.GetInt64("page")
  3091. start_time := this.GetString("start_first_time")
  3092. end_time := this.GetString("end_first_time")
  3093. storehouse_id, _ := this.GetInt64("storehouse_id")
  3094. orgId := this.GetAdminUserInfo().CurrentOrgId
  3095. timeLayout := "2006-01-02"
  3096. loc, _ := time.LoadLocation("Local")
  3097. var startTime int64
  3098. if len(start_time) > 0 {
  3099. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3100. if err != nil {
  3101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3102. return
  3103. }
  3104. startTime = theTime.Unix()
  3105. }
  3106. var endTime int64
  3107. if len(end_time) > 0 {
  3108. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3109. if err != nil {
  3110. utils.ErrorLog(err.Error())
  3111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3112. return
  3113. }
  3114. endTime = theTime.Unix()
  3115. }
  3116. list, total, err := service.GetDrugWarehouseOutInfoByIdList(drug_id, limit, page, orgId, startTime, endTime, storehouse_id)
  3117. flushList, _ := service.GetDrugFlowFlush(drug_id, orgId, startTime, endTime)
  3118. flushOne, _ := service.GetDrugFlowFlushOne(drug_id, orgId, startTime, endTime)
  3119. if err != nil {
  3120. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
  3121. return
  3122. }
  3123. this.ServeSuccessJSON(map[string]interface{}{
  3124. "total": total,
  3125. "list": list,
  3126. "flushList": flushList,
  3127. "flushListOne": flushOne,
  3128. })
  3129. }
  3130. func (this *SelfDrugApiController) GetSendGoodInformation() {
  3131. orgId := this.GetAdminUserInfo().CurrentOrgId
  3132. fmt.Println("orgid", orgId)
  3133. list, _ := service.GetWarehouseOutInfo(10485)
  3134. for _, it := range list {
  3135. service.UpdateWarehosueOutInfo(it.ID, it.WarehouseOutTime)
  3136. }
  3137. //获取入库数据
  3138. //list, _ := service.GetSendGoodInformation(10265)
  3139. //
  3140. ////project, _ := service.GetHisPrescriptionList(10265)
  3141. //
  3142. //for _, it := range list {
  3143. // service.UpdateGoodFlow(it.ID, it.PackingPrice)
  3144. //}
  3145. //for _, it := range list {
  3146. // //查询是否有数据
  3147. // _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
  3148. // //获取总退库数量
  3149. // var cancel_count int64
  3150. // var out_count int64
  3151. // var act_count int64
  3152. // //退库总数量
  3153. // cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
  3154. // for _, item := range cancellist {
  3155. // cancel_count += item.Count
  3156. // }
  3157. // //出库总数量
  3158. // outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  3159. // for _, item := range outlist {
  3160. // out_count += item.Count
  3161. // }
  3162. //
  3163. // //实际出库总数量
  3164. // actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  3165. // for _, item := range actlist {
  3166. // act_count += item.Count
  3167. // }
  3168. //
  3169. // if errcode == gorm.ErrRecordNotFound {
  3170. // good := models.XtGoodStockCount{
  3171. // UserOrgId: it.OrgId,
  3172. // GoodId: it.GoodId,
  3173. // StorehouseId: it.StorehouseId,
  3174. // Status: 1,
  3175. // Ctime: time.Now().Unix(),
  3176. // Mtime: 0,
  3177. // StockInCount: it.WarehousingCount,
  3178. // StockOutCount: out_count - cancel_count,
  3179. // StockCancelCount: cancel_count,
  3180. // FlushCount: it.StockCount,
  3181. // StockActOutCount: act_count,
  3182. // }
  3183. // service.CreateGoodCountSix(good)
  3184. // }
  3185. // if errcode == nil {
  3186. // service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
  3187. // }
  3188. //}
  3189. this.ServeSuccessJSON(map[string]interface{}{
  3190. "msg": "1",
  3191. })
  3192. }
  3193. func (this *SelfDrugApiController) GetDrugInitDetailList() {
  3194. orgId := this.GetAdminUserInfo().CurrentOrgId
  3195. //获取所有的入库仓库
  3196. list, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
  3197. for _, item := range list {
  3198. //查询该药品该仓库是否有数据
  3199. drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
  3200. //查询该仓库该药品的入库数量
  3201. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  3202. var sum_in_count int64
  3203. var flush_count int64
  3204. var sum_out_count int64
  3205. var cancel_out_count int64
  3206. //查询入库数量和剩余库存
  3207. infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
  3208. for _, it := range infolist {
  3209. if it.MaxUnit == medical.MaxUnit {
  3210. it.WarehousingCount = it.WarehousingCount * medical.MinNumber
  3211. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  3212. }
  3213. sum_in_count += it.WarehousingCount
  3214. flush_count += it.StockMaxNumber + it.StockMinNumber
  3215. }
  3216. //获取出库数量
  3217. outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
  3218. for _, it := range outinfolist {
  3219. if it.MaxUnit == medical.MaxUnit {
  3220. it.Count = it.Count * medical.MinNumber
  3221. }
  3222. sum_out_count += it.Count
  3223. }
  3224. //获取退库数量
  3225. cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
  3226. for _, it := range cancelinfolist {
  3227. if it.MaxUnit == medical.MaxUnit {
  3228. it.Count = it.Count * medical.MinNumber
  3229. }
  3230. cancel_out_count += it.Count
  3231. }
  3232. //新增
  3233. if drug.ID == 0 {
  3234. drugstock := models.XtDrugStockCount{
  3235. UserOrgId: orgId,
  3236. StorehouseId: item.StorehouseId,
  3237. SumInCount: sum_in_count,
  3238. SumOutCount: sum_out_count - cancel_out_count,
  3239. SumCancelCount: cancel_out_count,
  3240. DrugId: item.DrugId,
  3241. Ctime: time.Now().Unix(),
  3242. Mtime: 0,
  3243. Status: 1,
  3244. FlushCount: flush_count,
  3245. SumActOutCount: sum_out_count,
  3246. }
  3247. service.CreateDrugStockCount(drugstock)
  3248. }
  3249. }
  3250. this.ServeSuccessJSON(map[string]interface{}{
  3251. "msg": "1",
  3252. })
  3253. }
  3254. func (this *SelfDrugApiController) GetGoodNewPurchaseStockQuery() {
  3255. good_type, _ := this.GetInt64("good_type")
  3256. keyword := this.GetString("keyword")
  3257. page, _ := this.GetInt64("page")
  3258. limit, _ := this.GetInt64("limit")
  3259. start_time := this.GetString("start_time")
  3260. end_time := this.GetString("end_time")
  3261. orgId := this.GetAdminUserInfo().CurrentOrgId
  3262. timeLayout := "2006-01-02"
  3263. loc, _ := time.LoadLocation("Local")
  3264. var startTime int64
  3265. if len(start_time) > 0 {
  3266. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3267. if err != nil {
  3268. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3269. return
  3270. }
  3271. startTime = theTime.Unix()
  3272. }
  3273. var endTime int64
  3274. if len(end_time) > 0 {
  3275. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3276. if err != nil {
  3277. utils.ErrorLog(err.Error())
  3278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3279. return
  3280. }
  3281. endTime = theTime.Unix()
  3282. }
  3283. var ids []int64
  3284. var goodIds []int64
  3285. infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  3286. for _, it := range infoList {
  3287. goodIds = append(goodIds, it.GoodId)
  3288. }
  3289. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3290. for _, it := range manufacturers {
  3291. ids = append(ids, it.ID)
  3292. }
  3293. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  3294. if orgId == 10265 {
  3295. //storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3296. list, total, err := service.GetGoodNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
  3297. for _, item := range list {
  3298. //获取期初结余
  3299. low, _ := service.GetStartLastFLowTwenty(item.ID, orgId, startTime)
  3300. item.GoodStartFlowInfo = low
  3301. //获取期末结余
  3302. flow, _ := service.GetEndLastFlowTwenty(item.ID, orgId, endTime)
  3303. item.GoodEndFlowInfo = flow
  3304. //获取期间增加
  3305. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
  3306. for _, it := range goodWarehouseInfoList {
  3307. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3308. }
  3309. //获取本期增加
  3310. WarehouseInfoFlowList, _ := service.GetAddStartFlowTwenty(item.ID, orgId, startTime, endTime)
  3311. for _, it := range WarehouseInfoFlowList {
  3312. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3313. }
  3314. //获取本期减少
  3315. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
  3316. for _, it := range reduceWarehouseInfoList {
  3317. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3318. }
  3319. //获取期中减少退库
  3320. lowInfo, _ := service.GetStartEndCancelFLowInfoTwenty(item.ID, orgId, startTime, endTime)
  3321. for _, it := range lowInfo {
  3322. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3323. }
  3324. //
  3325. outInfo, _ := service.FindeWarehouseOutInfoTwenty(item.ID, orgId, startTime)
  3326. for _, it := range outInfo {
  3327. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3328. }
  3329. //期中盘盈
  3330. profit, _ := service.FindeEndStokInventoryProfitTwenty(item.ID, orgId, startTime, endTime)
  3331. for _, it := range profit {
  3332. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3333. }
  3334. //期中盘亏
  3335. losses, _ := service.FindeEndStockInventoryLossesTwenty(item.ID, orgId, startTime, endTime)
  3336. for _, it := range losses {
  3337. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3338. }
  3339. }
  3340. if err != nil {
  3341. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3342. return
  3343. }
  3344. this.ServeSuccessJSON(map[string]interface{}{
  3345. "list": list,
  3346. "manufacturerList": manufacturerList,
  3347. "total": total,
  3348. })
  3349. }
  3350. if orgId != 10265 {
  3351. list, total, err := service.GetGoodNewPurchaseStockQueryOne(good_type, keyword, page, limit, orgId, ids, goodIds)
  3352. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3353. for _, item := range list {
  3354. //获取期初结余
  3355. low, _ := service.GetStartLastFLow(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3356. item.GoodStartFlowInfo = low
  3357. //获取期末结余
  3358. flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime, storeConfig.StorehouseOutInfo)
  3359. item.GoodEndFlowInfo = flow
  3360. //获取期间增加
  3361. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3362. for _, it := range goodWarehouseInfoList {
  3363. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3364. }
  3365. //获取本期增加
  3366. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3367. for _, it := range WarehouseInfoFlowList {
  3368. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3369. }
  3370. //获取本期减少
  3371. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3372. for _, it := range reduceWarehouseInfoList {
  3373. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3374. }
  3375. //获取期中减少退库
  3376. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3377. for _, it := range lowInfo {
  3378. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3379. }
  3380. //
  3381. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3382. for _, it := range outInfo {
  3383. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3384. }
  3385. //期中盘盈
  3386. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3387. for _, it := range profit {
  3388. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3389. }
  3390. //期中盘亏
  3391. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3392. for _, it := range losses {
  3393. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3394. }
  3395. }
  3396. if err != nil {
  3397. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3398. return
  3399. }
  3400. this.ServeSuccessJSON(map[string]interface{}{
  3401. "list": list,
  3402. "manufacturerList": manufacturerList,
  3403. "total": total,
  3404. })
  3405. }
  3406. }
  3407. func (this *SelfDrugApiController) GetPurchaseNewDrugQuery() {
  3408. good_type, _ := this.GetInt64("good_type")
  3409. keyword := this.GetString("keyword")
  3410. page, _ := this.GetInt64("page")
  3411. limit, _ := this.GetInt64("limit")
  3412. start_time := this.GetString("start_time")
  3413. end_time := this.GetString("end_time")
  3414. orgId := this.GetAdminUserInfo().CurrentOrgId
  3415. timeLayout := "2006-01-02"
  3416. loc, _ := time.LoadLocation("Local")
  3417. var startTime int64
  3418. if len(start_time) > 0 {
  3419. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3420. if err != nil {
  3421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3422. return
  3423. }
  3424. startTime = theTime.Unix()
  3425. }
  3426. var endTime int64
  3427. if len(end_time) > 0 {
  3428. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3429. if err != nil {
  3430. utils.ErrorLog(err.Error())
  3431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3432. return
  3433. }
  3434. endTime = theTime.Unix()
  3435. }
  3436. var ids []int64
  3437. var infoIds []int64
  3438. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3439. for _, it := range manufacturers {
  3440. ids = append(ids, it.ID)
  3441. }
  3442. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  3443. for _, it := range infoList {
  3444. infoIds = append(infoIds, it.DrugId)
  3445. }
  3446. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3447. list, total, err := service.GetDrugNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  3448. for _, item := range list {
  3449. //获取期初结余
  3450. flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
  3451. item.DrugStatFlow = flow
  3452. //获取期末结余
  3453. endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
  3454. item.DrugEndFlow = endFlow
  3455. //获取期初结余入库数量
  3456. //startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
  3457. //for _, it := range startDrugInfo {
  3458. // item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
  3459. //}
  3460. //
  3461. ////获取期初结余出库数量
  3462. //flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
  3463. //for _, it := range flowOutList {
  3464. // item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
  3465. //}
  3466. //
  3467. ////获取期初结余退库数量
  3468. //cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
  3469. //for _, it := range cancelInfo {
  3470. // item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
  3471. //}
  3472. //
  3473. ////获取期末结余入库数量
  3474. //drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
  3475. //for _, it := range drugwarehouseinfoend {
  3476. // item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
  3477. //}
  3478. ////获取期末出库结余
  3479. //endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
  3480. //for _, it := range endDrugInfo {
  3481. // item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
  3482. //}
  3483. //
  3484. ////获取期末退库数量
  3485. //flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
  3486. //for _, it := range flowCancelInfo {
  3487. // item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
  3488. //}
  3489. //期中增加
  3490. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  3491. for _, it := range drugWarehouse {
  3492. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  3493. }
  3494. //期中减少
  3495. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3496. fmt.Println("putInfo2o2o2oo2o2", outInfo)
  3497. for _, it := range outInfo {
  3498. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  3499. }
  3500. //期中退库
  3501. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3502. for _, it := range cancelstartInfo {
  3503. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  3504. }
  3505. ////获取期初盘盈
  3506. //startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
  3507. //for _, it := range startProfit {
  3508. // item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  3509. //}
  3510. ////获取期初盘亏
  3511. //startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
  3512. //for _, it := range startLosses {
  3513. // item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  3514. //}
  3515. ////获取期末盘盈
  3516. //endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
  3517. //for _, it := range endProfit {
  3518. // item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  3519. //}
  3520. ////获取期末盘亏
  3521. //losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
  3522. //for _, it := range losses {
  3523. // item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  3524. //}
  3525. //获取期中盘盈
  3526. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  3527. for _, it := range profit {
  3528. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3529. }
  3530. //获取期中盘亏
  3531. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  3532. for _, it := range endLosses {
  3533. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3534. }
  3535. }
  3536. if err != nil {
  3537. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3538. return
  3539. }
  3540. var drugType = "药品类型"
  3541. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3542. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3543. this.ServeSuccessJSON(map[string]interface{}{
  3544. "list": list,
  3545. "manufacturerList": manufacturerList,
  3546. "total": total,
  3547. "drugTypeList": drugTypeList,
  3548. })
  3549. }
  3550. func (this *SelfDrugApiController) GetGoodOverCount() {
  3551. orgId := this.GetAdminUserInfo().CurrentOrgId
  3552. list, _ := service.GetAllStockCount(orgId)
  3553. for _, item := range list {
  3554. flow, _ := service.GetLastStockFlow(item.GoodId)
  3555. service.ModifyStockFlowById(flow.ID, item.FlushCount)
  3556. }
  3557. returnData := make(map[string]interface{}, 0)
  3558. returnData["msg"] = "ok"
  3559. this.ServeSuccessJSON(returnData)
  3560. return
  3561. }
  3562. func (this *SelfDrugApiController) GetDrugOverCount() {
  3563. orgId := this.GetAdminUserInfo().CurrentOrgId
  3564. list, _ := service.GetAllDrugCount(orgId)
  3565. for _, item := range list {
  3566. service.GetLastDrugFlow(item.DrugId)
  3567. service.ModifyDrugFlowById(item.ID, item.FlushCount)
  3568. }
  3569. returnData := make(map[string]interface{}, 0)
  3570. returnData["msg"] = "ok"
  3571. this.ServeSuccessJSON(returnData)
  3572. return
  3573. }
  3574. func (this *SelfDrugApiController) GetDrugInventoryWarehouseInfoList() {
  3575. storehouse_id, _ := this.GetInt64("storehouse_id")
  3576. orgId := this.GetAdminUserInfo().CurrentOrgId
  3577. list, _ := service.GetDrugInventoryWarehouseInfoList(orgId, storehouse_id)
  3578. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3579. dealerList, _ := service.GetAllDealerList(orgId)
  3580. this.ServeSuccessJSON(map[string]interface{}{
  3581. "list": list,
  3582. "manufacturerList": manufacturerList,
  3583. "dealerList": dealerList,
  3584. })
  3585. }
  3586. func (this *SelfDrugApiController) GetInventoryDetailPrintList() {
  3587. keyword := this.GetString("keyword")
  3588. limit, _ := this.GetInt64("limit")
  3589. page, _ := this.GetInt64("page")
  3590. storehouse_id, _ := this.GetInt64("storehouse_id")
  3591. ids := this.GetString("ids")
  3592. idSplit := strings.Split(ids, ",")
  3593. orgId := this.GetAdminUserInfo().CurrentOrgId
  3594. list, total, err := service.GetDrugInventoryDetailMapList(keyword, page, limit, orgId, storehouse_id, idSplit)
  3595. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  3596. houseList, _ := service.GetAllStoreHouseList(orgId)
  3597. doctorList, _ := service.GetAllDoctorThree(orgId)
  3598. if err != nil {
  3599. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  3600. return
  3601. }
  3602. this.ServeSuccessJSON(map[string]interface{}{
  3603. "total": total,
  3604. "list": list,
  3605. "doctorList": doctorList,
  3606. "houseList": houseList,
  3607. "inventoryList": inventoryList,
  3608. })
  3609. }
  3610. func (this *SelfDrugApiController) GetDrugFlowDetailById() {
  3611. drug_id, _ := this.GetInt64("drug_id")
  3612. list, _ := service.GetDrugFlowDetailById(drug_id)
  3613. drugMedical, _ := service.GetBaseDrugMedical(drug_id)
  3614. for index, _ := range list {
  3615. if list[index].ConsumableType == 3 || list[index].ConsumableType == 2 || list[index].ConsumableType == 11 || list[index].ConsumableType == 12 || list[index].ConsumableType == 15 {
  3616. var count int64
  3617. if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
  3618. list[index].Count = list[index].Count * drugMedical.MinNumber
  3619. }
  3620. if index == 0 {
  3621. count = list[index].FlushOverCount - list[index].Count
  3622. service.UpdateDrugOverCount(list[index+1].ID, count)
  3623. }
  3624. if index >= 1 {
  3625. lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
  3626. count = lastStockFlow.FlushOverCount - list[index].Count
  3627. service.UpdateDrugOverCount(list[index].ID, count)
  3628. }
  3629. }
  3630. if list[index].ConsumableType == 7 || list[index].ConsumableType == 4 || list[index].ConsumableType == 1 || list[index].ConsumableType == 10 || list[index].ConsumableType == 13 {
  3631. if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
  3632. list[index].Count = list[index].Count * drugMedical.MinNumber
  3633. }
  3634. if index == 0 {
  3635. var count int64
  3636. count = list[index].OverCount + list[index].Count
  3637. service.UpdateDrugOverCount(list[index+1].ID, count)
  3638. }
  3639. if index >= 1 {
  3640. var count int64
  3641. lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
  3642. count = lastStockFlow.FlushOverCount + list[index].Count
  3643. service.UpdateDrugOverCount(list[index].ID, count)
  3644. }
  3645. }
  3646. }
  3647. }
  3648. func (this *SelfDrugApiController) GetPurchaseDrugQueryList() {
  3649. good_type, _ := this.GetInt64("good_type")
  3650. keyword := this.GetString("keyword")
  3651. page, _ := this.GetInt64("page")
  3652. limit, _ := this.GetInt64("limit")
  3653. start_time := this.GetString("start_time")
  3654. end_time := this.GetString("end_time")
  3655. orgId := this.GetAdminUserInfo().CurrentOrgId
  3656. timeLayout := "2006-01-02"
  3657. loc, _ := time.LoadLocation("Local")
  3658. var startTime int64
  3659. if len(start_time) > 0 {
  3660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3661. if err != nil {
  3662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3663. return
  3664. }
  3665. startTime = theTime.Unix()
  3666. }
  3667. var endTime int64
  3668. if len(end_time) > 0 {
  3669. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3670. if err != nil {
  3671. utils.ErrorLog(err.Error())
  3672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3673. return
  3674. }
  3675. endTime = theTime.Unix()
  3676. }
  3677. var ids []int64
  3678. var infoIds []int64
  3679. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3680. for _, it := range manufacturers {
  3681. ids = append(ids, it.ID)
  3682. }
  3683. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  3684. for _, it := range infoList {
  3685. infoIds = append(infoIds, it.DrugId)
  3686. }
  3687. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3688. list, total, err := service.GetDrugNewPurchaseStockQueryList(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  3689. for _, item := range list {
  3690. //获取期初结余
  3691. flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
  3692. item.DrugStatFlow = flow
  3693. //获取期末结余
  3694. endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
  3695. item.DrugEndFlow = endFlow
  3696. //获取期初结余入库数量
  3697. //期中增加
  3698. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  3699. for _, it := range drugWarehouse {
  3700. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  3701. }
  3702. //期中减少
  3703. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3704. for _, it := range outInfo {
  3705. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  3706. }
  3707. //期中退库
  3708. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3709. for _, it := range cancelstartInfo {
  3710. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  3711. }
  3712. //获取期中盘盈
  3713. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  3714. for _, it := range profit {
  3715. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3716. }
  3717. //获取期中盘亏
  3718. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  3719. for _, it := range endLosses {
  3720. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3721. }
  3722. }
  3723. if err != nil {
  3724. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3725. return
  3726. }
  3727. var drugType = "药品类型"
  3728. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3729. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3730. this.ServeSuccessJSON(map[string]interface{}{
  3731. "list": list,
  3732. "manufacturerList": manufacturerList,
  3733. "total": total,
  3734. "drugTypeList": drugTypeList,
  3735. })
  3736. }