self_drug_api_congtroller.go 147KB

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