self_drug_api_congtroller.go 146KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type SelfDrugApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func SelfDrugRouters() {
  20. beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
  21. beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
  22. beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
  23. beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
  24. beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
  25. beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
  26. beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
  27. beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
  28. beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
  29. beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
  30. beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
  31. beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
  32. beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
  33. beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
  34. beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
  35. beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
  36. beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
  37. beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
  38. beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
  39. beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
  40. beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
  41. beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
  42. beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
  43. beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
  44. beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
  45. beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
  46. beego.Router("/api/drug/getallmedicallist", &SelfDrugApiController{}, "Get:GetAllMedicalList")
  47. beego.Router("/api/drug/getstandname", &SelfDrugApiController{}, "Get:GetStandName")
  48. beego.Router("/api/drug/getrullerlist", &SelfDrugApiController{}, "Get:GetRullerList")
  49. beego.Router("/api/drug/deleteDrugNamebyid", &SelfDrugApiController{}, "Get:DeleteDrugNameById")
  50. beego.Router("/api/drug/getpatientdetail", &SelfDrugApiController{}, "Get:GetPatientDetail")
  51. //beego.Router("/api/drug/getpatientdetail",&SelfDrugApiController{},"Get:ToPatientDetail")
  52. beego.Router("/api/drug/getselfstockquery", &SelfDrugApiController{}, "Get:GetSelfStockQuery")
  53. beego.Router("/api/drug/postsearchdrugwarehouselist", &SelfDrugApiController{}, "Get:PostSearchDrugWarehouseList")
  54. beego.Router("/api/drug/savedrugpriceone", &SelfDrugApiController{}, "Post:SaveDrugPrice")
  55. beego.Router("/api/drug/drugpricelist", &SelfDrugApiController{}, "Get:GetDrugPriceList")
  56. beego.Router("/api/drug/savecheckdrugprice", &SelfDrugApiController{}, "Get:SaveCheckDrugPrice")
  57. beego.Router("/api/drug/savedrugdamageone", &SelfDrugApiController{}, "Post:SaveDrugDamage")
  58. beego.Router("/api/drug/getdrugdamagelist", &SelfDrugApiController{}, "Get:GetDrugDamageList")
  59. beego.Router("/api/drug/savedrugdamageprice", &SelfDrugApiController{}, "Get:SaveDrugDamagePrice")
  60. beego.Router("/api/drug/getdrugmodifyprice", &SelfDrugApiController{}, "Get:GetDrugModifyPrice")
  61. beego.Router("/api/drug/modifydrugprice", &SelfDrugApiController{}, "Get:ModifyDrugPrice")
  62. beego.Router("/api/drug/getmodifypriceprint", &SelfDrugApiController{}, "Get:GetModifyPricePrint")
  63. beego.Router("/api/drug/getdrugdamagedetail", &SelfDrugApiController{}, "Get:GetDrugDamageDetail")
  64. beego.Router("/api/drug/modifydrugdamage", &SelfDrugApiController{}, "Get:ModifyDrugDamage")
  65. beego.Router("/api/drug/deletedrugdamage", &SelfDrugApiController{}, "Get:DeleteDrugDamage")
  66. beego.Router("/api/drug/getdrugdamageprint", &SelfDrugApiController{}, "Get:GetDrugDamagePrint")
  67. beego.Router("/api/drug/warehouseinfobyid", &SelfDrugApiController{}, "Get:GetWarehoseInfoById")
  68. beego.Router("/api/drug/savedruginventory", &SelfDrugApiController{}, "Post:SaveDrugInventory")
  69. beego.Router("/api/drug/getdruginventorylist", &SelfDrugApiController{}, "Get:GetDrugInventoryList")
  70. beego.Router("/api/drug/savedrugcheckinventory", &SelfDrugApiController{}, "Get:SaveDrugCheckInventory")
  71. beego.Router("/api/drug/getdruginventorydetail", &SelfDrugApiController{}, "Get:GetDrugInventoryDetail")
  72. beego.Router("/api/drug/modifyinventory", &SelfDrugApiController{}, "Get:ModifyInventory")
  73. beego.Router("/api/drug/deletedruginventory", &SelfDrugApiController{}, "Get:DeleteDrugInventory")
  74. beego.Router("/api/drug/getdruginventoryprintlist", &SelfDrugApiController{}, "Get:GetDrugInventoryPrintList")
  75. beego.Router("/api/drug/getinventorydetaillist", &SelfDrugApiController{}, "Get:GetDrugInventoryDetailList")
  76. beego.Router("/api/drug/getinventorydetailprintlist", &SelfDrugApiController{}, "Get:GetInventoryDetailPrintList")
  77. beego.Router("/api/drug/savedrugproofinventory", &SelfDrugApiController{}, "Get:SaveDrugProofInventory")
  78. beego.Router("/api/drug/getdrugwarehouseinfototal", &StockManagerApiController{}, "Get:GetDrugWarehouseInfoTotal")
  79. beego.Router("/api/drug/saveinentorylist", &SelfDrugApiController{}, "Post:SaveInventoryList")
  80. beego.Router("/api/drug/getdamagebydrugid", &SelfDrugApiController{}, "Get:GetDamageByDrugId")
  81. beego.Router("/api/drug/getinventorymodelist", &SelfDrugApiController{}, "Get:GetInventoryModeList")
  82. //耗材库存优化接口
  83. beego.Router("/api/drug/getstorehouselist", &SelfDrugApiController{}, "Get:GetStorehouseList")
  84. beego.Router("/api/drug/getgoodnewquery", &SelfDrugApiController{}, "Get:GetGoodNewQuery")
  85. beego.Router("/api/drug/getgoodwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetGoodWarehouseOutInfoByIdList")
  86. beego.Router("/api/good/getgoodpatientlist", &SelfDrugApiController{}, "Get:GetGoodPatientList")
  87. beego.Router("/api/good/getwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetWarehouseOutDetailByPatientId")
  88. beego.Router("/api/good/getgoodexpirydatequery", &SelfDrugApiController{}, "Get:GetGoodExpiryDateQuery")
  89. beego.Router("/api/good/getpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodPurchaseStockQuery")
  90. //药品库存优化接口
  91. beego.Router("/api/good/getdrugwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetDrugWarehouseOutDetailByPatientId")
  92. beego.Router("/api/drug/getdrugexpirydatequery", &SelfDrugApiController{}, "Get:GetDrugExpiryDateQuery")
  93. beego.Router("/api/drug/getpurchasedrugquery", &SelfDrugApiController{}, "Get:GetPurchaseDrugQuery")
  94. beego.Router("/api/drug/getdrugnewquery", &SelfDrugApiController{}, "Get:GetDrugNewQuery")
  95. beego.Router("/api/drug/getdrugwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetDrugWarehouseInfoById")
  96. //耗材脚本
  97. beego.Router("/api/stock/tosendgoodinfomation", &SelfDrugApiController{}, "Get:GetSendGoodInformation")
  98. //药品脚本
  99. beego.Router("/api/drug/getdruginitdatalist", &SelfDrugApiController{}, "Get:GetDrugInitDetailList")
  100. //新数据
  101. beego.Router("/api/stock/getnewpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodNewPurchaseStockQuery")
  102. beego.Router("/api/stock/getpurchasenewdrugquery", &SelfDrugApiController{}, "Get:GetPurchaseNewDrugQuery")
  103. beego.Router("/api/stock/getgoodovercount", &SelfDrugApiController{}, "Get:GetGoodOverCount")
  104. beego.Router("/api/stock/getdrugovercount", &SelfDrugApiController{}, "Get:GetDrugOverCount")
  105. beego.Router("/api/stock/getdruginfolist", &SelfDrugApiController{}, "Get:GetDrugInventoryWarehouseInfoList")
  106. beego.Router("/api/drug/getdrugflowdetailbyid", &SelfDrugApiController{}, "Get:GetDrugFlowDetailById")
  107. //康允新版本
  108. beego.Router("/api/stock/getpurchaseDrugQueryList", &SelfDrugApiController{}, "Get:GetPurchaseDrugQueryList")
  109. 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. list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId, storehouse_id)
  2136. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  2137. houseList, _ := service.GetAllStoreHouseList(orgId)
  2138. doctorList, _ := service.GetAllDoctorThree(orgId)
  2139. if err != nil {
  2140. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2141. return
  2142. }
  2143. this.ServeSuccessJSON(map[string]interface{}{
  2144. "total": total,
  2145. "list": list,
  2146. "doctorList": doctorList,
  2147. "houseList": houseList,
  2148. "inventoryList": inventoryList,
  2149. })
  2150. }
  2151. func (this *SelfDrugApiController) SaveDrugProofInventory() {
  2152. id, _ := this.GetInt64("id")
  2153. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2154. warehousing_unit := this.GetString("warehousing_unit")
  2155. remark := this.GetString("remark")
  2156. proof_count, _ := this.GetInt64("proof_count")
  2157. inventory := models.XtDrugInventory{
  2158. WarehouseInfoId: warehouse_info_id,
  2159. ProofCount: proof_count,
  2160. WarehousingUnit: warehousing_unit,
  2161. Remark: remark,
  2162. }
  2163. err := service.UpdateDrugProofInventory(id, &inventory)
  2164. info := models.XtDrugWarehouseInfo{
  2165. StockMaxNumber: proof_count,
  2166. }
  2167. service.UpdateDrugWarehouseInfoById(warehouse_info_id, &info)
  2168. if err != nil {
  2169. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2170. return
  2171. }
  2172. this.ServeSuccessJSON(map[string]interface{}{
  2173. "inventory": inventory,
  2174. })
  2175. }
  2176. func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
  2177. id, _ := this.GetInt64("id")
  2178. list, _ := service.GetDrugWarehouseInfoTotal(id)
  2179. this.ServeSuccessJSON(map[string]interface{}{
  2180. "list": list,
  2181. })
  2182. }
  2183. //新改造
  2184. func (this *SelfDrugApiController) SaveInventoryList() {
  2185. dataBody := make(map[string]interface{}, 0)
  2186. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2187. fmt.Println(err)
  2188. tableData, _ := dataBody["tableData"].([]interface{})
  2189. if len(tableData) > 0 {
  2190. for _, item := range tableData {
  2191. items := item.(map[string]interface{})
  2192. drug_name := items["drug_name"].(string)
  2193. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  2194. utils.ErrorLog("drug_name")
  2195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2196. return
  2197. }
  2198. fmt.Println("drug_name", drug_name)
  2199. specification_name := items["specification_name"].(string)
  2200. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  2201. utils.ErrorLog("specification_name")
  2202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2203. return
  2204. }
  2205. max_unit := items["max_unit"].(string)
  2206. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  2207. utils.ErrorLog("max_unit")
  2208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2209. return
  2210. }
  2211. min_unit := items["min_unit"].(string)
  2212. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  2213. utils.ErrorLog("min_unit")
  2214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2215. return
  2216. }
  2217. drug_id := int64(items["drug_id"].(float64))
  2218. min_number := int64(items["min_number"].(float64))
  2219. stock_max_number := int64(items["stock_max_number"].(float64))
  2220. stock_min_number := int64(items["stock_min_number"].(float64))
  2221. last_stock_max_number := int64(items["last_stock_max_number"].(float64))
  2222. last_stock_min_number := int64(items["last_stock_min_number"].(float64))
  2223. warehousing_order := items["warehousing_order"].(string)
  2224. price := items["price"].(float64)
  2225. manufacturer_name := items["manufacturer_name"].(string)
  2226. batch_number := items["batch_number"].(string)
  2227. id := int64(items["id"].(float64))
  2228. orgId := this.GetAdminUserInfo().CurrentOrgId
  2229. type_id := int64(items["type"].(float64))
  2230. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  2231. utils.ErrorLog("expiry_date")
  2232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2233. return
  2234. }
  2235. expiry_date := int64(items["expiry_date"].(float64))
  2236. manufacturer := int64(items["manufacturer"].(float64))
  2237. storehouse_id := int64(items["storehouse_id"].(float64))
  2238. timeLayout := "2006-01-02"
  2239. loc, _ := time.LoadLocation("Local")
  2240. timeNow := time.Now().Format("2006-01-02")
  2241. locationTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeNow+" 00:00:00", loc)
  2242. var consumable_type int64
  2243. var consumable_count int64
  2244. var ord_total int64
  2245. var new_total int64
  2246. var total int64
  2247. ord_total = stock_max_number*min_number + stock_min_number
  2248. new_total = last_stock_max_number*min_number + last_stock_min_number
  2249. medical, _ := service.GetBaseDrugMedical(drug_id)
  2250. //改变库存
  2251. info := models.DrugWarehouseInfo{
  2252. DrugId: drug_id,
  2253. StockMaxNumber: last_stock_max_number,
  2254. StockMinNumber: last_stock_min_number,
  2255. WarehousingCount: last_stock_max_number,
  2256. MaxUnit: max_unit,
  2257. MinUnit: min_unit,
  2258. }
  2259. drugInfo, _ := service.GetCurrentWarehosueInfoOne(id)
  2260. if drugInfo.MaxUnit == medical.MaxUnit {
  2261. total = drugInfo.WarehousingCount * medical.MinNumber
  2262. }
  2263. if drugInfo.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2264. total = drugInfo.WarehousingCount
  2265. }
  2266. //如果库存数据大于盘点数据,则减去数量
  2267. if ord_total > new_total {
  2268. consumable_type = 11
  2269. consumable_count = ord_total - new_total
  2270. err = service.ModifyDrugWarehouseInfo(&info, id)
  2271. }
  2272. //如果库存数据小于盘点数据,则增加数量
  2273. if ord_total < new_total && new_total <= total {
  2274. consumable_type = 10
  2275. consumable_count = new_total - ord_total
  2276. err = service.ModifyDrugWarehouseInfo(&info, id)
  2277. }
  2278. if ord_total < new_total && new_total > total {
  2279. consumable_type = 10
  2280. consumable_count = new_total - ord_total
  2281. err = service.ModifyDrugWarehouseInfoSix(&info, id)
  2282. }
  2283. //查询默认仓库
  2284. houseConfig, _ := service.GetAllStoreHouseConfig(drugInfo.OrgId)
  2285. //查询默认仓库剩余多少库存
  2286. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, drugInfo.OrgId, drugInfo.DrugId)
  2287. var sum_count int64
  2288. var sum_in_count int64
  2289. for _, it := range list {
  2290. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2291. if it.MaxUnit == baseDrug.MaxUnit {
  2292. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2293. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2294. }
  2295. sum_count += it.StockMaxNumber + it.StockMinNumber
  2296. sum_in_count += it.WarehousingCount
  2297. }
  2298. service.UpdateMedicalSumCount(drugInfo.DrugId, sum_count, sum_in_count, drugInfo.OrgId)
  2299. //更新剩余库存
  2300. service.UpdateDrugStockCount(drugInfo.DrugId, drugInfo.OrgId, houseConfig.DrugStorehouseOut, sum_count)
  2301. inventory := models.XtDrugInventory{
  2302. DrugName: drug_name,
  2303. SpecificationName: specification_name,
  2304. WarehousingUnit: max_unit,
  2305. Count: consumable_count,
  2306. LastPrice: price,
  2307. RetailPrice: 0,
  2308. NewPrice: 0,
  2309. Manufacturer: manufacturer_name,
  2310. Dealer: "",
  2311. Remark: "",
  2312. DrugId: drug_id,
  2313. UserOrgId: orgId,
  2314. Ctime: time.Now().Unix(),
  2315. Mtime: 0,
  2316. Status: 1,
  2317. WarehousingOrder: warehousing_order,
  2318. LicenseNumber: "",
  2319. StartTime: locationTime.Unix(),
  2320. Creater: this.GetAdminUserInfo().AdminUser.Id,
  2321. Checker: 0,
  2322. CheckerStatus: 0,
  2323. CheckerTime: 0,
  2324. ExpiryDate: expiry_date,
  2325. ProductDate: 0,
  2326. Number: "",
  2327. BatchNumber: batch_number,
  2328. Total: "",
  2329. DrugOriginPlace: "",
  2330. WarehouseInfoId: id,
  2331. ProofCount: 0,
  2332. StockMaxNumber: stock_max_number,
  2333. StockMinNumber: stock_min_number,
  2334. MinCount: 0,
  2335. MinUnit: min_unit,
  2336. LastStockMaxNumber: last_stock_max_number,
  2337. LastStockMinNumber: last_stock_min_number,
  2338. InventoryType: consumable_type,
  2339. Type: type_id,
  2340. StorehouseId: storehouse_id,
  2341. }
  2342. err = service.CreateDrugInventory(inventory)
  2343. flow := models.DrugFlow{
  2344. WarehousingId: id,
  2345. DrugId: drug_id,
  2346. Number: "",
  2347. BatchNumber: batch_number,
  2348. Count: consumable_count,
  2349. UserOrgId: orgId,
  2350. PatientId: 0,
  2351. SystemTime: locationTime.Unix(),
  2352. ConsumableType: consumable_type,
  2353. IsSys: 1,
  2354. WarehousingOrder: warehousing_order,
  2355. WarehouseOutId: 0,
  2356. WarehouseOutOrderNumber: "",
  2357. IsEdit: 0,
  2358. CancelStockId: 0,
  2359. CancelOrderNumber: "",
  2360. Manufacturer: manufacturer,
  2361. Dealer: 0,
  2362. Creator: this.GetAdminUserInfo().AdminUser.Id,
  2363. UpdateCreator: 0,
  2364. Status: 1,
  2365. Ctime: time.Now().Unix(),
  2366. Mtime: 0,
  2367. Price: price,
  2368. WarehousingDetailId: id,
  2369. WarehouseOutDetailId: 0,
  2370. CancelOutDetailId: 0,
  2371. ExpireDate: expiry_date,
  2372. ProductDate: 0,
  2373. MaxUnit: min_unit,
  2374. MinUnit: min_unit,
  2375. StorehouseId: storehouse_id,
  2376. OverCount: sum_count,
  2377. }
  2378. if ord_total != new_total {
  2379. service.CreateDrugFlowOne(flow)
  2380. }
  2381. if err != nil {
  2382. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2383. return
  2384. }
  2385. this.ServeSuccessJSON(map[string]interface{}{
  2386. "inventory": inventory,
  2387. })
  2388. }
  2389. }
  2390. }
  2391. func (this *SelfDrugApiController) GetDamageByDrugId() {
  2392. drug_id, _ := this.GetInt64("drug_id")
  2393. warehousing_order := this.GetString("warehouseing_order")
  2394. drug_type, _ := this.GetInt64("type")
  2395. list, err := service.GetDamageByDrugId(drug_id, warehousing_order, drug_type)
  2396. if err != nil {
  2397. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2398. return
  2399. }
  2400. this.ServeSuccessJSON(map[string]interface{}{
  2401. "list": list,
  2402. })
  2403. }
  2404. func (this *SelfDrugApiController) GetInventoryModeList() {
  2405. orgId := this.GetAdminUserInfo().CurrentOrgId
  2406. list, err := service.GetInventoryModeList(orgId)
  2407. manufacturerList, err := service.GetAllManufacturerList(orgId)
  2408. if err != nil {
  2409. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2410. return
  2411. }
  2412. this.ServeSuccessJSON(map[string]interface{}{
  2413. "list": list,
  2414. "manufacturerList": manufacturerList,
  2415. })
  2416. }
  2417. // 库存优化接口
  2418. func (this *SelfDrugApiController) GetStorehouseList() {
  2419. orgId := this.GetAdminUserInfo().CurrentOrgId
  2420. list, err := service.GetAllStoreHouseList(orgId)
  2421. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  2422. goodType, _ := service.GetAllNewGoodType(orgId)
  2423. patientList, _ := service.GetAllpatientThirty(orgId)
  2424. dealerList, _ := service.GetAllDealerList(orgId)
  2425. if err != nil {
  2426. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取仓库失败")
  2427. return
  2428. }
  2429. this.ServeSuccessJSON(map[string]interface{}{
  2430. "list": list,
  2431. "manufacturerList": manufacturerList,
  2432. "goodTypeList": goodType,
  2433. "patientList": patientList,
  2434. "dealerList": dealerList,
  2435. })
  2436. }
  2437. func (this *SelfDrugApiController) GetGoodNewQuery() {
  2438. orgId := this.GetAdminUserInfo().CurrentOrgId
  2439. storehouse_id, _ := this.GetInt64("storehouse_id")
  2440. good_type, _ := this.GetInt64("good_type")
  2441. keyword := this.GetString("keyword")
  2442. page, _ := this.GetInt64("page")
  2443. limit, _ := this.GetInt64("limit")
  2444. // 查询该机构所有耗材入库信息
  2445. goodList, _ := service.GetAllGoodListSeven(orgId)
  2446. for _, it := range goodList {
  2447. var sum_total int64
  2448. //查询该耗材入库信息
  2449. warehouseinfo, _ := service.GetGoodInformationWarehouseInfo(it.ID, orgId)
  2450. for _, item := range warehouseinfo {
  2451. sum_total += item.StockCount
  2452. }
  2453. service.UpdateGoodInformation(it.ID, orgId, sum_total)
  2454. //stockListTwo, _ := service.GetGoodStockCountList(orgId, it.ID)
  2455. //if len(stockListTwo) > 0 {
  2456. // for _, item := range stockListTwo {
  2457. // var over_count int64
  2458. // over_count = item.StockInCount - item.FlushCount
  2459. // service.UpdateGoodListCount(item.UserOrgId, over_count, item.GoodId, item.StorehouseId)
  2460. //
  2461. // }
  2462. //}
  2463. //
  2464. //stockListOne, _ := service.GetGoodStockCountList(orgId, it.ID)
  2465. //if len(stockListOne) > 0 {
  2466. // for _, item := range stockListOne {
  2467. // var over_count int64
  2468. // over_count = item.StockOutCount + item.StockCancelCount
  2469. // service.UpdateGoodListCountOne(item.UserOrgId, over_count, item.GoodId, item.StorehouseId)
  2470. // }
  2471. //}
  2472. }
  2473. var ids []int64
  2474. manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2475. for _, it := range manufacturerList {
  2476. ids = append(ids, it.ID)
  2477. }
  2478. stockList, total, err := service.GetGoodStockList(orgId, storehouse_id, good_type, keyword, page, limit, ids)
  2479. if err != nil {
  2480. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
  2481. return
  2482. }
  2483. this.ServeSuccessJSON(map[string]interface{}{
  2484. "total": total,
  2485. "stockList": stockList,
  2486. })
  2487. }
  2488. func (this *SelfDrugApiController) GetGoodWarehouseOutInfoByIdList() {
  2489. good_id, _ := this.GetInt64("good_id")
  2490. limit, _ := this.GetInt64("limit")
  2491. page, _ := this.GetInt64("page")
  2492. start_time := this.GetString("start_first_time")
  2493. end_time := this.GetString("end_first_time")
  2494. storehouse_id, _ := this.GetInt64("storehouse_id")
  2495. orgId := this.GetAdminUserInfo().CurrentOrgId
  2496. timeLayout := "2006-01-02"
  2497. loc, _ := time.LoadLocation("Local")
  2498. var startTime int64
  2499. if len(start_time) > 0 {
  2500. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2501. if err != nil {
  2502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2503. return
  2504. }
  2505. startTime = theTime.Unix()
  2506. }
  2507. var endTime int64
  2508. if len(end_time) > 0 {
  2509. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2510. if err != nil {
  2511. utils.ErrorLog(err.Error())
  2512. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2513. return
  2514. }
  2515. endTime = theTime.Unix()
  2516. }
  2517. list, total, err := service.GetGoodWarehouseOutInfoByIdList(good_id, limit, page, orgId, startTime, endTime, storehouse_id)
  2518. //flushList, _ := service.GetStockFlushByGoodId(good_id, orgId, startTime, endTime)
  2519. //warehouseInfoByList, _ := service.GetGoodWarehouseInfoByList(good_id, orgId, startTime, endTime)
  2520. //cancelStockInfoByList, _ := service.GetGoodCancelStockInfoByList(good_id, orgId, startTime, endTime)
  2521. //warehouseOutByList,_ := service.GetGoodWarehouseOutInfoByIdListTwenty(good_id, limit, page, orgId, startTime, endTime)
  2522. if err != nil {
  2523. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
  2524. return
  2525. }
  2526. this.ServeSuccessJSON(map[string]interface{}{
  2527. "total": total,
  2528. "list": list,
  2529. //"warehouseInfoByList":warehouseInfoByList,
  2530. //"cancelStockInfoByList":cancelStockInfoByList,
  2531. //"warehouseOutByList":warehouseOutByList,
  2532. //"flushList":flushList,
  2533. })
  2534. }
  2535. func (this *SelfDrugApiController) GetGoodPatientList() {
  2536. orgId := this.GetAdminUserInfo().CurrentOrgId
  2537. keyword := this.GetString("keyword")
  2538. list, err := service.GetGoodPatientList(orgId, keyword)
  2539. if err != nil {
  2540. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2541. return
  2542. }
  2543. this.ServeSuccessJSON(map[string]interface{}{
  2544. "list": list,
  2545. })
  2546. }
  2547. func (this *SelfDrugApiController) GetWarehouseOutDetailByPatientId() {
  2548. patient_id, _ := this.GetInt64("patient_id")
  2549. start_time := this.GetString("start_time")
  2550. end_time := this.GetString("end_time")
  2551. limit, _ := this.GetInt64("limit")
  2552. page, _ := this.GetInt64("page")
  2553. orgId := this.GetAdminUserInfo().CurrentOrgId
  2554. timeLayout := "2006-01-02"
  2555. loc, _ := time.LoadLocation("Local")
  2556. var startTime int64
  2557. if len(start_time) > 0 {
  2558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2559. if err != nil {
  2560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2561. return
  2562. }
  2563. startTime = theTime.Unix()
  2564. }
  2565. var endTime int64
  2566. if len(end_time) > 0 {
  2567. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2568. if err != nil {
  2569. utils.ErrorLog(err.Error())
  2570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2571. return
  2572. }
  2573. endTime = theTime.Unix()
  2574. }
  2575. list, total, err := service.GetWarehouseOutDetailByPatientIdOne(orgId, patient_id, startTime, endTime, limit, page)
  2576. outlist, _ := service.GetWarehouseOutDetailByPatientId(orgId, patient_id, startTime, endTime)
  2577. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2578. if err != nil {
  2579. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2580. return
  2581. }
  2582. this.ServeSuccessJSON(map[string]interface{}{
  2583. "list": list,
  2584. "manufacturerList": manufacturerList,
  2585. "total": total,
  2586. "outlist": outlist,
  2587. })
  2588. }
  2589. func (this *SelfDrugApiController) GetGoodExpiryDateQuery() {
  2590. storehouse_id, _ := this.GetInt64("storehouse_id")
  2591. expiry_type, _ := this.GetInt64("expiry_type")
  2592. keyword := this.GetString("keyword")
  2593. page, _ := this.GetInt64("page")
  2594. limit, _ := this.GetInt64("limit")
  2595. orgId := this.GetAdminUserInfo().CurrentOrgId
  2596. start_time := this.GetString("start_time")
  2597. timeLayout := "2006-01-02"
  2598. loc, _ := time.LoadLocation("Local")
  2599. var endTime int64
  2600. if len(start_time) > 0 {
  2601. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2602. if err != nil {
  2603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2604. return
  2605. }
  2606. endTime = theTime.Unix()
  2607. }
  2608. recordDateStr := time.Now().Format("2006-01-02")
  2609. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2610. fmt.Scan("parseDateErr", parseDateErr)
  2611. nowtime := recordDate.Unix()
  2612. var ids []int64
  2613. var goodIds []int64
  2614. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2615. for _, it := range manufacturers {
  2616. ids = append(ids, it.ID)
  2617. }
  2618. goodList, _ := service.GetGoodNameByword(orgId, keyword)
  2619. for _, it := range goodList {
  2620. goodIds = append(goodIds, it.ID)
  2621. }
  2622. list, total, err := service.GetGoodExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2623. fmt.Println("total233223322332323232323223", total)
  2624. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2625. if err != nil {
  2626. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2627. return
  2628. }
  2629. this.ServeSuccessJSON(map[string]interface{}{
  2630. "list": list,
  2631. "manufacturerList": manufacturerList,
  2632. "total": total,
  2633. "nowtime": nowtime,
  2634. })
  2635. }
  2636. func (this *SelfDrugApiController) GetGoodPurchaseStockQuery() {
  2637. good_type, _ := this.GetInt64("good_type")
  2638. keyword := this.GetString("keyword")
  2639. page, _ := this.GetInt64("page")
  2640. limit, _ := this.GetInt64("limit")
  2641. start_time := this.GetString("start_time")
  2642. end_time := this.GetString("end_time")
  2643. orgId := this.GetAdminUserInfo().CurrentOrgId
  2644. timeLayout := "2006-01-02"
  2645. loc, _ := time.LoadLocation("Local")
  2646. var startTime int64
  2647. if len(start_time) > 0 {
  2648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2649. if err != nil {
  2650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2651. return
  2652. }
  2653. startTime = theTime.Unix()
  2654. }
  2655. var endTime int64
  2656. if len(end_time) > 0 {
  2657. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2658. if err != nil {
  2659. utils.ErrorLog(err.Error())
  2660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2661. return
  2662. }
  2663. endTime = theTime.Unix()
  2664. }
  2665. var ids []int64
  2666. var goodIds []int64
  2667. infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  2668. for _, it := range infoList {
  2669. goodIds = append(goodIds, it.GoodId)
  2670. }
  2671. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2672. for _, it := range manufacturers {
  2673. ids = append(ids, it.ID)
  2674. }
  2675. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2676. list, total, err := service.GetGoodPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
  2677. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2678. for _, item := range list {
  2679. //获取期初结余数量
  2680. infoList, _ := service.GetStartGoodWarehouseInfoList(item.ID, orgId, startTime)
  2681. for _, it := range infoList {
  2682. item.WarehousingInfoStart = append(item.WarehousingInfoStart, it)
  2683. }
  2684. //获取期末结余数量
  2685. warehouseInfoList, _ := service.GetEndGoodWarehouseInfoList(item.ID, orgId, endTime)
  2686. for _, it := range warehouseInfoList {
  2687. item.WarehousingInfoEnd = append(item.WarehousingInfoEnd, it)
  2688. }
  2689. //获取期间增加
  2690. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2691. for _, it := range goodWarehouseInfoList {
  2692. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  2693. }
  2694. //获取本期增加
  2695. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2696. for _, it := range WarehouseInfoFlowList {
  2697. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  2698. }
  2699. //获取本期减少
  2700. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2701. for _, it := range reduceWarehouseInfoList {
  2702. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  2703. }
  2704. //获取期中减少退库
  2705. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2706. for _, it := range lowInfo {
  2707. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  2708. }
  2709. //
  2710. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  2711. for _, it := range outInfo {
  2712. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  2713. }
  2714. //获取期初结余
  2715. info, _ := service.FindeStartFlowInfo(item.ID, orgId, startTime)
  2716. for _, it := range info {
  2717. item.StartFlowInfo = append(item.StartFlowInfo, it)
  2718. }
  2719. //获取期初结余
  2720. flowOutInfo, _ := service.FindeStartFlowOutInfo(item.ID, orgId, startTime)
  2721. for _, it := range flowOutInfo {
  2722. item.StartOutFlowInfo = append(item.StartOutFlowInfo, it)
  2723. }
  2724. //获取期初退库
  2725. cancelInfo, _ := service.FindeStartCancelInfo(item.ID, orgId, startTime)
  2726. for _, it := range cancelInfo {
  2727. item.StartCancelFlowInfo = append(item.StartCancelFlowInfo, it)
  2728. }
  2729. //获取期末结余
  2730. flowInfo, _ := service.FindEndStartFlowInfo(item.ID, orgId, endTime)
  2731. for _, it := range flowInfo {
  2732. item.EndFlowInfo = append(item.EndFlowInfo, it)
  2733. }
  2734. //获取期末出库
  2735. lowOutInfo, _ := service.FindeEndFLowOutInfo(item.ID, orgId, endTime)
  2736. for _, it := range lowOutInfo {
  2737. item.EndFlowOutInfo = append(item.EndFlowOutInfo, it)
  2738. }
  2739. //获取期末退库
  2740. endCancelInfo, _ := service.FindEndCancelInfo(item.ID, orgId, endTime)
  2741. for _, it := range endCancelInfo {
  2742. item.EndCancelFLowInfo = append(item.EndCancelFLowInfo, it)
  2743. }
  2744. //期初盘赢
  2745. inventory, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, startTime)
  2746. for _, it := range inventory {
  2747. item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  2748. }
  2749. //期初盘亏
  2750. stockInventory, _ := service.FindStartStockInventoryLosses(item.ID, orgId, startTime)
  2751. for _, it := range stockInventory {
  2752. item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  2753. }
  2754. //期末盘盈
  2755. inventoryProfit, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, endTime)
  2756. for _, it := range inventoryProfit {
  2757. item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  2758. }
  2759. //期末盘亏
  2760. inventoryLosses, _ := service.FindStartStockInventoryLosses(item.ID, orgId, endTime)
  2761. for _, it := range inventoryLosses {
  2762. item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  2763. }
  2764. //期中盘盈
  2765. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2766. for _, it := range profit {
  2767. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  2768. }
  2769. //期中盘亏
  2770. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2771. for _, it := range losses {
  2772. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  2773. }
  2774. }
  2775. if err != nil {
  2776. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2777. return
  2778. }
  2779. this.ServeSuccessJSON(map[string]interface{}{
  2780. "list": list,
  2781. "manufacturerList": manufacturerList,
  2782. "total": total,
  2783. })
  2784. }
  2785. func (this *SelfDrugApiController) GetDrugWarehouseOutDetailByPatientId() {
  2786. patient_id, _ := this.GetInt64("patient_id")
  2787. start_time := this.GetString("start_time")
  2788. end_time := this.GetString("end_time")
  2789. orgId := this.GetAdminUserInfo().CurrentOrgId
  2790. limit, _ := this.GetInt64("limit")
  2791. page, _ := this.GetInt64("page")
  2792. timeLayout := "2006-01-02"
  2793. loc, _ := time.LoadLocation("Local")
  2794. var startTime int64
  2795. if len(start_time) > 0 {
  2796. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2797. if err != nil {
  2798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2799. return
  2800. }
  2801. startTime = theTime.Unix()
  2802. }
  2803. var endTime int64
  2804. if len(end_time) > 0 {
  2805. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2806. if err != nil {
  2807. utils.ErrorLog(err.Error())
  2808. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2809. return
  2810. }
  2811. endTime = theTime.Unix()
  2812. }
  2813. list, total, _ := service.GetDrugWarehouseOutDetailByPatientIdOne(patient_id, orgId, startTime, endTime, page, limit)
  2814. outlist, _ := service.GetDrugWarehouseOutDetailByPatientId(patient_id, orgId, startTime, endTime)
  2815. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2816. this.ServeSuccessJSON(map[string]interface{}{
  2817. "list": list,
  2818. "total": total,
  2819. "manufacturerList": manufacturerList,
  2820. "outlist": outlist,
  2821. })
  2822. }
  2823. func (this *SelfDrugApiController) GetDrugExpiryDateQuery() {
  2824. storehouse_id, _ := this.GetInt64("storehouse_id")
  2825. expiry_type, _ := this.GetInt64("expiry_type")
  2826. keyword := this.GetString("keyword")
  2827. page, _ := this.GetInt64("page")
  2828. limit, _ := this.GetInt64("limit")
  2829. orgId := this.GetAdminUserInfo().CurrentOrgId
  2830. start_time := this.GetString("start_time")
  2831. timeLayout := "2006-01-02"
  2832. loc, _ := time.LoadLocation("Local")
  2833. var endTime int64
  2834. if len(start_time) > 0 {
  2835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2836. if err != nil {
  2837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2838. return
  2839. }
  2840. endTime = theTime.Unix()
  2841. }
  2842. recordDateStr := time.Now().Format("2006-01-02")
  2843. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2844. fmt.Scan("parseDateErr", parseDateErr)
  2845. nowtime := recordDate.Unix()
  2846. var ids []int64
  2847. var goodIds []int64
  2848. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2849. for _, it := range manufacturers {
  2850. ids = append(ids, it.ID)
  2851. }
  2852. drugList, _ := service.GetDrugNameByword(orgId, keyword)
  2853. for _, it := range drugList {
  2854. goodIds = append(goodIds, it.ID)
  2855. }
  2856. list, total, err := service.GetDrugExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2857. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2858. var drugType = "药品类型"
  2859. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2860. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  2861. if err != nil {
  2862. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2863. return
  2864. }
  2865. this.ServeSuccessJSON(map[string]interface{}{
  2866. "list": list,
  2867. "manufacturerList": manufacturerList,
  2868. "total": total,
  2869. "nowtime": nowtime,
  2870. "drugTypeList": drugTypeList,
  2871. })
  2872. }
  2873. func (this *SelfDrugApiController) GetPurchaseDrugQuery() {
  2874. good_type, _ := this.GetInt64("good_type")
  2875. keyword := this.GetString("keyword")
  2876. page, _ := this.GetInt64("page")
  2877. limit, _ := this.GetInt64("limit")
  2878. start_time := this.GetString("start_time")
  2879. end_time := this.GetString("end_time")
  2880. orgId := this.GetAdminUserInfo().CurrentOrgId
  2881. timeLayout := "2006-01-02"
  2882. loc, _ := time.LoadLocation("Local")
  2883. var startTime int64
  2884. if len(start_time) > 0 {
  2885. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2886. if err != nil {
  2887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2888. return
  2889. }
  2890. startTime = theTime.Unix()
  2891. }
  2892. var endTime int64
  2893. if len(end_time) > 0 {
  2894. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2895. if err != nil {
  2896. utils.ErrorLog(err.Error())
  2897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2898. return
  2899. }
  2900. endTime = theTime.Unix()
  2901. }
  2902. var ids []int64
  2903. var infoIds []int64
  2904. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2905. for _, it := range manufacturers {
  2906. ids = append(ids, it.ID)
  2907. }
  2908. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  2909. for _, it := range infoList {
  2910. infoIds = append(infoIds, it.DrugId)
  2911. }
  2912. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  2913. list, total, err := service.GetDrugPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  2914. for _, item := range list {
  2915. //获取期初结余入库数量
  2916. startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
  2917. for _, it := range startDrugInfo {
  2918. item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
  2919. }
  2920. //获取期初结余出库数量
  2921. flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
  2922. for _, it := range flowOutList {
  2923. item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
  2924. }
  2925. //获取期初结余退库数量
  2926. cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
  2927. for _, it := range cancelInfo {
  2928. item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
  2929. }
  2930. //获取期末结余入库数量
  2931. drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
  2932. for _, it := range drugwarehouseinfoend {
  2933. item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
  2934. }
  2935. //获取期末出库结余
  2936. endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
  2937. for _, it := range endDrugInfo {
  2938. item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
  2939. }
  2940. //获取期末退库数量
  2941. flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
  2942. for _, it := range flowCancelInfo {
  2943. item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
  2944. }
  2945. //期中增加
  2946. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  2947. for _, it := range drugWarehouse {
  2948. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  2949. }
  2950. //期中减少
  2951. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  2952. for _, it := range outInfo {
  2953. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  2954. }
  2955. //期中退库
  2956. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  2957. for _, it := range cancelstartInfo {
  2958. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  2959. }
  2960. //获取期初盘盈
  2961. startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
  2962. for _, it := range startProfit {
  2963. item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  2964. }
  2965. //获取期初盘亏
  2966. startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
  2967. for _, it := range startLosses {
  2968. item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  2969. }
  2970. //获取期末盘盈
  2971. endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
  2972. for _, it := range endProfit {
  2973. item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  2974. }
  2975. //获取期末盘亏
  2976. losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
  2977. for _, it := range losses {
  2978. item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  2979. }
  2980. //获取期中盘盈
  2981. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  2982. for _, it := range profit {
  2983. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  2984. }
  2985. //获取期中盘亏
  2986. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  2987. for _, it := range endLosses {
  2988. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  2989. }
  2990. }
  2991. if err != nil {
  2992. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2993. return
  2994. }
  2995. var drugType = "药品类型"
  2996. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2997. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  2998. this.ServeSuccessJSON(map[string]interface{}{
  2999. "list": list,
  3000. "manufacturerList": manufacturerList,
  3001. "total": total,
  3002. "drugTypeList": drugTypeList,
  3003. })
  3004. }
  3005. func (this *SelfDrugApiController) GetDrugNewQuery() {
  3006. orgId := this.GetAdminUserInfo().CurrentOrgId
  3007. storehouse_id, _ := this.GetInt64("storehouse_id")
  3008. good_type, _ := this.GetInt64("good_type")
  3009. keyword := this.GetString("keyword")
  3010. page, _ := this.GetInt64("page")
  3011. limit, _ := this.GetInt64("limit")
  3012. start_time := this.GetString("start_time")
  3013. end_time := this.GetString("end_time")
  3014. timeLayout := "2006-01-02"
  3015. loc, _ := time.LoadLocation("Local")
  3016. var startTime int64
  3017. if len(start_time) > 0 {
  3018. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3019. if err != nil {
  3020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3021. return
  3022. }
  3023. startTime = theTime.Unix()
  3024. }
  3025. var endTime int64
  3026. if len(end_time) > 0 {
  3027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3028. if err != nil {
  3029. utils.ErrorLog(err.Error())
  3030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3031. return
  3032. }
  3033. endTime = theTime.Unix()
  3034. }
  3035. var ids []int64
  3036. var goodIds []int64
  3037. manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3038. //查询药品库信息
  3039. drug, _ := service.GetBaseDrugName(orgId)
  3040. for _, it := range drug {
  3041. var sum_count int64
  3042. var limit_count int64
  3043. drugInfo, _ := service.GetDrugWarehouseInfoName(it.ID, orgId)
  3044. for _, item := range drugInfo {
  3045. sum_count += item.StockMaxNumber*it.MinNumber + item.StockMinNumber
  3046. }
  3047. stockInt, _ := strconv.ParseInt(it.DrugStockLimit, 10, 64)
  3048. limit_count = stockInt * it.MinNumber
  3049. service.UpdateDrugById(it.ID, orgId, limit_count, sum_count)
  3050. //druglist, _ := service.GetDrugCountMapList(it.ID, orgId)
  3051. //if len(druglist) > 0 {
  3052. // for _, item := range druglist {
  3053. // var over_count int64
  3054. // over_count = item.SumInCount - item.FlushCount
  3055. // service.UpdateDrugStockInCount(item.DrugId, item.StorehouseId, over_count, item.UserOrgId)
  3056. // }
  3057. //}
  3058. //druglistOne, _ := service.GetDrugCountMapList(it.ID, orgId)
  3059. //if len(druglistOne) > 0 {
  3060. // for _, item := range druglistOne {
  3061. // var over_count int64
  3062. // over_count = item.SumOutCount + item.SumCancelCount
  3063. // service.UpdateDrugStockInCountOne(item.DrugId, item.StorehouseId, over_count, item.UserOrgId)
  3064. // }
  3065. //}
  3066. }
  3067. for _, it := range manufacturerList {
  3068. ids = append(ids, it.ID)
  3069. }
  3070. infoList, _ := service.GetDrugWarehouseInfoByOrgId(orgId, storehouse_id)
  3071. for _, it := range infoList {
  3072. goodIds = append(goodIds, it.DrugId)
  3073. }
  3074. countList, total, err := service.GetDrugStockCountList(orgId, storehouse_id, good_type, keyword, page, limit, ids, goodIds, startTime, endTime)
  3075. if err != nil {
  3076. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
  3077. return
  3078. }
  3079. var drugType = "药品类型"
  3080. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3081. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3082. this.ServeSuccessJSON(map[string]interface{}{
  3083. "total": total,
  3084. "drugTypeList": drugTypeList,
  3085. "countList": countList,
  3086. })
  3087. }
  3088. func (this *SelfDrugApiController) GetDrugWarehouseInfoById() {
  3089. drug_id, _ := this.GetInt64("drug_id")
  3090. limit, _ := this.GetInt64("limit")
  3091. page, _ := this.GetInt64("page")
  3092. start_time := this.GetString("start_first_time")
  3093. end_time := this.GetString("end_first_time")
  3094. storehouse_id, _ := this.GetInt64("storehouse_id")
  3095. orgId := this.GetAdminUserInfo().CurrentOrgId
  3096. timeLayout := "2006-01-02"
  3097. loc, _ := time.LoadLocation("Local")
  3098. var startTime int64
  3099. if len(start_time) > 0 {
  3100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3101. if err != nil {
  3102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3103. return
  3104. }
  3105. startTime = theTime.Unix()
  3106. }
  3107. var endTime int64
  3108. if len(end_time) > 0 {
  3109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3110. if err != nil {
  3111. utils.ErrorLog(err.Error())
  3112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3113. return
  3114. }
  3115. endTime = theTime.Unix()
  3116. }
  3117. list, total, err := service.GetDrugWarehouseOutInfoByIdList(drug_id, limit, page, orgId, startTime, endTime, storehouse_id)
  3118. flushList, _ := service.GetDrugFlowFlush(drug_id, orgId, startTime, endTime)
  3119. flushOne, _ := service.GetDrugFlowFlushOne(drug_id, orgId, startTime, endTime)
  3120. if err != nil {
  3121. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
  3122. return
  3123. }
  3124. this.ServeSuccessJSON(map[string]interface{}{
  3125. "total": total,
  3126. "list": list,
  3127. "flushList": flushList,
  3128. "flushListOne": flushOne,
  3129. })
  3130. }
  3131. func (this *SelfDrugApiController) GetSendGoodInformation() {
  3132. orgId := this.GetAdminUserInfo().CurrentOrgId
  3133. fmt.Println("orgid", orgId)
  3134. list, _ := service.GetWarehouseOutInfo(10485)
  3135. for _, it := range list {
  3136. service.UpdateWarehosueOutInfo(it.ID, it.WarehouseOutTime)
  3137. }
  3138. //获取入库数据
  3139. //list, _ := service.GetSendGoodInformation(10265)
  3140. //
  3141. ////project, _ := service.GetHisPrescriptionList(10265)
  3142. //
  3143. //for _, it := range list {
  3144. // service.UpdateGoodFlow(it.ID, it.PackingPrice)
  3145. //}
  3146. //for _, it := range list {
  3147. // //查询是否有数据
  3148. // _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
  3149. // //获取总退库数量
  3150. // var cancel_count int64
  3151. // var out_count int64
  3152. // var act_count int64
  3153. // //退库总数量
  3154. // cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
  3155. // for _, item := range cancellist {
  3156. // cancel_count += item.Count
  3157. // }
  3158. // //出库总数量
  3159. // outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  3160. // for _, item := range outlist {
  3161. // out_count += item.Count
  3162. // }
  3163. //
  3164. // //实际出库总数量
  3165. // actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  3166. // for _, item := range actlist {
  3167. // act_count += item.Count
  3168. // }
  3169. //
  3170. // if errcode == gorm.ErrRecordNotFound {
  3171. // good := models.XtGoodStockCount{
  3172. // UserOrgId: it.OrgId,
  3173. // GoodId: it.GoodId,
  3174. // StorehouseId: it.StorehouseId,
  3175. // Status: 1,
  3176. // Ctime: time.Now().Unix(),
  3177. // Mtime: 0,
  3178. // StockInCount: it.WarehousingCount,
  3179. // StockOutCount: out_count - cancel_count,
  3180. // StockCancelCount: cancel_count,
  3181. // FlushCount: it.StockCount,
  3182. // StockActOutCount: act_count,
  3183. // }
  3184. // service.CreateGoodCountSix(good)
  3185. // }
  3186. // if errcode == nil {
  3187. // service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
  3188. // }
  3189. //}
  3190. this.ServeSuccessJSON(map[string]interface{}{
  3191. "msg": "1",
  3192. })
  3193. }
  3194. func (this *SelfDrugApiController) GetDrugInitDetailList() {
  3195. orgId := this.GetAdminUserInfo().CurrentOrgId
  3196. //获取所有的入库仓库
  3197. list, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
  3198. for _, item := range list {
  3199. //查询该药品该仓库是否有数据
  3200. drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
  3201. //查询该仓库该药品的入库数量
  3202. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  3203. var sum_in_count int64
  3204. var flush_count int64
  3205. var sum_out_count int64
  3206. var cancel_out_count int64
  3207. //查询入库数量和剩余库存
  3208. infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
  3209. for _, it := range infolist {
  3210. if it.MaxUnit == medical.MaxUnit {
  3211. it.WarehousingCount = it.WarehousingCount * medical.MinNumber
  3212. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  3213. }
  3214. sum_in_count += it.WarehousingCount
  3215. flush_count += it.StockMaxNumber + it.StockMinNumber
  3216. }
  3217. //获取出库数量
  3218. outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
  3219. for _, it := range outinfolist {
  3220. if it.MaxUnit == medical.MaxUnit {
  3221. it.Count = it.Count * medical.MinNumber
  3222. }
  3223. sum_out_count += it.Count
  3224. }
  3225. //获取退库数量
  3226. cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
  3227. for _, it := range cancelinfolist {
  3228. if it.MaxUnit == medical.MaxUnit {
  3229. it.Count = it.Count * medical.MinNumber
  3230. }
  3231. cancel_out_count += it.Count
  3232. }
  3233. //新增
  3234. if drug.ID == 0 {
  3235. drugstock := models.XtDrugStockCount{
  3236. UserOrgId: orgId,
  3237. StorehouseId: item.StorehouseId,
  3238. SumInCount: sum_in_count,
  3239. SumOutCount: sum_out_count - cancel_out_count,
  3240. SumCancelCount: cancel_out_count,
  3241. DrugId: item.DrugId,
  3242. Ctime: time.Now().Unix(),
  3243. Mtime: 0,
  3244. Status: 1,
  3245. FlushCount: flush_count,
  3246. SumActOutCount: sum_out_count,
  3247. }
  3248. service.CreateDrugStockCount(drugstock)
  3249. }
  3250. }
  3251. this.ServeSuccessJSON(map[string]interface{}{
  3252. "msg": "1",
  3253. })
  3254. }
  3255. func (this *SelfDrugApiController) GetGoodNewPurchaseStockQuery() {
  3256. good_type, _ := this.GetInt64("good_type")
  3257. keyword := this.GetString("keyword")
  3258. page, _ := this.GetInt64("page")
  3259. limit, _ := this.GetInt64("limit")
  3260. start_time := this.GetString("start_time")
  3261. end_time := this.GetString("end_time")
  3262. orgId := this.GetAdminUserInfo().CurrentOrgId
  3263. timeLayout := "2006-01-02"
  3264. loc, _ := time.LoadLocation("Local")
  3265. var startTime int64
  3266. if len(start_time) > 0 {
  3267. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3268. if err != nil {
  3269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3270. return
  3271. }
  3272. startTime = theTime.Unix()
  3273. }
  3274. var endTime int64
  3275. if len(end_time) > 0 {
  3276. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3277. if err != nil {
  3278. utils.ErrorLog(err.Error())
  3279. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3280. return
  3281. }
  3282. endTime = theTime.Unix()
  3283. }
  3284. var ids []int64
  3285. var goodIds []int64
  3286. infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  3287. for _, it := range infoList {
  3288. goodIds = append(goodIds, it.GoodId)
  3289. }
  3290. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3291. for _, it := range manufacturers {
  3292. ids = append(ids, it.ID)
  3293. }
  3294. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  3295. if orgId == 10265 {
  3296. //storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3297. list, total, err := service.GetGoodNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
  3298. for _, item := range list {
  3299. //获取期初结余
  3300. low, _ := service.GetStartLastFLowTwenty(item.ID, orgId, startTime)
  3301. item.GoodStartFlowInfo = low
  3302. //获取期末结余
  3303. flow, _ := service.GetEndLastFlowTwenty(item.ID, orgId, endTime)
  3304. item.GoodEndFlowInfo = flow
  3305. //获取期间增加
  3306. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
  3307. for _, it := range goodWarehouseInfoList {
  3308. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3309. }
  3310. //获取本期增加
  3311. WarehouseInfoFlowList, _ := service.GetAddStartFlowTwenty(item.ID, orgId, startTime, endTime)
  3312. for _, it := range WarehouseInfoFlowList {
  3313. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3314. }
  3315. //获取本期减少
  3316. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
  3317. for _, it := range reduceWarehouseInfoList {
  3318. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3319. }
  3320. //获取期中减少退库
  3321. lowInfo, _ := service.GetStartEndCancelFLowInfoTwenty(item.ID, orgId, startTime, endTime)
  3322. for _, it := range lowInfo {
  3323. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3324. }
  3325. //
  3326. outInfo, _ := service.FindeWarehouseOutInfoTwenty(item.ID, orgId, startTime)
  3327. for _, it := range outInfo {
  3328. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3329. }
  3330. //期中盘盈
  3331. profit, _ := service.FindeEndStokInventoryProfitTwenty(item.ID, orgId, startTime, endTime)
  3332. for _, it := range profit {
  3333. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3334. }
  3335. //期中盘亏
  3336. losses, _ := service.FindeEndStockInventoryLossesTwenty(item.ID, orgId, startTime, endTime)
  3337. for _, it := range losses {
  3338. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3339. }
  3340. }
  3341. if err != nil {
  3342. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3343. return
  3344. }
  3345. this.ServeSuccessJSON(map[string]interface{}{
  3346. "list": list,
  3347. "manufacturerList": manufacturerList,
  3348. "total": total,
  3349. })
  3350. }
  3351. if orgId != 10265 {
  3352. list, total, err := service.GetGoodNewPurchaseStockQueryOne(good_type, keyword, page, limit, orgId, ids, goodIds)
  3353. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3354. for _, item := range list {
  3355. //获取期初结余
  3356. low, _ := service.GetStartLastFLow(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3357. item.GoodStartFlowInfo = low
  3358. //获取期末结余
  3359. flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime, storeConfig.StorehouseOutInfo)
  3360. item.GoodEndFlowInfo = flow
  3361. //获取期间增加
  3362. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3363. for _, it := range goodWarehouseInfoList {
  3364. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3365. }
  3366. //获取本期增加
  3367. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3368. for _, it := range WarehouseInfoFlowList {
  3369. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3370. }
  3371. //获取本期减少
  3372. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3373. for _, it := range reduceWarehouseInfoList {
  3374. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3375. }
  3376. //获取期中减少退库
  3377. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3378. for _, it := range lowInfo {
  3379. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3380. }
  3381. //
  3382. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3383. for _, it := range outInfo {
  3384. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3385. }
  3386. //期中盘盈
  3387. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3388. for _, it := range profit {
  3389. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3390. }
  3391. //期中盘亏
  3392. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3393. for _, it := range losses {
  3394. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3395. }
  3396. }
  3397. if err != nil {
  3398. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3399. return
  3400. }
  3401. this.ServeSuccessJSON(map[string]interface{}{
  3402. "list": list,
  3403. "manufacturerList": manufacturerList,
  3404. "total": total,
  3405. })
  3406. }
  3407. }
  3408. func (this *SelfDrugApiController) GetPurchaseNewDrugQuery() {
  3409. good_type, _ := this.GetInt64("good_type")
  3410. keyword := this.GetString("keyword")
  3411. page, _ := this.GetInt64("page")
  3412. limit, _ := this.GetInt64("limit")
  3413. start_time := this.GetString("start_time")
  3414. end_time := this.GetString("end_time")
  3415. orgId := this.GetAdminUserInfo().CurrentOrgId
  3416. timeLayout := "2006-01-02"
  3417. loc, _ := time.LoadLocation("Local")
  3418. var startTime int64
  3419. if len(start_time) > 0 {
  3420. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3421. if err != nil {
  3422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3423. return
  3424. }
  3425. startTime = theTime.Unix()
  3426. }
  3427. var endTime int64
  3428. if len(end_time) > 0 {
  3429. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3430. if err != nil {
  3431. utils.ErrorLog(err.Error())
  3432. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3433. return
  3434. }
  3435. endTime = theTime.Unix()
  3436. }
  3437. var ids []int64
  3438. var infoIds []int64
  3439. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3440. for _, it := range manufacturers {
  3441. ids = append(ids, it.ID)
  3442. }
  3443. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  3444. for _, it := range infoList {
  3445. infoIds = append(infoIds, it.DrugId)
  3446. }
  3447. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3448. list, total, err := service.GetDrugNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  3449. for _, item := range list {
  3450. //获取期初结余
  3451. flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
  3452. item.DrugStatFlow = flow
  3453. //获取期末结余
  3454. endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
  3455. item.DrugEndFlow = endFlow
  3456. //获取期初结余入库数量
  3457. //startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
  3458. //for _, it := range startDrugInfo {
  3459. // item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
  3460. //}
  3461. //
  3462. ////获取期初结余出库数量
  3463. //flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
  3464. //for _, it := range flowOutList {
  3465. // item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
  3466. //}
  3467. //
  3468. ////获取期初结余退库数量
  3469. //cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
  3470. //for _, it := range cancelInfo {
  3471. // item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
  3472. //}
  3473. //
  3474. ////获取期末结余入库数量
  3475. //drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
  3476. //for _, it := range drugwarehouseinfoend {
  3477. // item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
  3478. //}
  3479. ////获取期末出库结余
  3480. //endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
  3481. //for _, it := range endDrugInfo {
  3482. // item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
  3483. //}
  3484. //
  3485. ////获取期末退库数量
  3486. //flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
  3487. //for _, it := range flowCancelInfo {
  3488. // item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
  3489. //}
  3490. //期中增加
  3491. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  3492. for _, it := range drugWarehouse {
  3493. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  3494. }
  3495. //期中减少
  3496. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3497. fmt.Println("putInfo2o2o2oo2o2", outInfo)
  3498. for _, it := range outInfo {
  3499. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  3500. }
  3501. //期中退库
  3502. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3503. for _, it := range cancelstartInfo {
  3504. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  3505. }
  3506. ////获取期初盘盈
  3507. //startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
  3508. //for _, it := range startProfit {
  3509. // item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  3510. //}
  3511. ////获取期初盘亏
  3512. //startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
  3513. //for _, it := range startLosses {
  3514. // item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  3515. //}
  3516. ////获取期末盘盈
  3517. //endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
  3518. //for _, it := range endProfit {
  3519. // item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  3520. //}
  3521. ////获取期末盘亏
  3522. //losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
  3523. //for _, it := range losses {
  3524. // item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  3525. //}
  3526. //获取期中盘盈
  3527. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  3528. for _, it := range profit {
  3529. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3530. }
  3531. //获取期中盘亏
  3532. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  3533. for _, it := range endLosses {
  3534. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3535. }
  3536. }
  3537. if err != nil {
  3538. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3539. return
  3540. }
  3541. var drugType = "药品类型"
  3542. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3543. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3544. this.ServeSuccessJSON(map[string]interface{}{
  3545. "list": list,
  3546. "manufacturerList": manufacturerList,
  3547. "total": total,
  3548. "drugTypeList": drugTypeList,
  3549. })
  3550. }
  3551. func (this *SelfDrugApiController) GetGoodOverCount() {
  3552. orgId := this.GetAdminUserInfo().CurrentOrgId
  3553. list, _ := service.GetAllStockCount(orgId)
  3554. for _, item := range list {
  3555. flow, _ := service.GetLastStockFlow(item.GoodId)
  3556. service.ModifyStockFlowById(flow.ID, item.FlushCount)
  3557. }
  3558. returnData := make(map[string]interface{}, 0)
  3559. returnData["msg"] = "ok"
  3560. this.ServeSuccessJSON(returnData)
  3561. return
  3562. }
  3563. func (this *SelfDrugApiController) GetDrugOverCount() {
  3564. orgId := this.GetAdminUserInfo().CurrentOrgId
  3565. list, _ := service.GetAllDrugCount(orgId)
  3566. for _, item := range list {
  3567. service.GetLastDrugFlow(item.DrugId)
  3568. service.ModifyDrugFlowById(item.ID, item.FlushCount)
  3569. }
  3570. returnData := make(map[string]interface{}, 0)
  3571. returnData["msg"] = "ok"
  3572. this.ServeSuccessJSON(returnData)
  3573. return
  3574. }
  3575. func (this *SelfDrugApiController) GetDrugInventoryWarehouseInfoList() {
  3576. storehouse_id, _ := this.GetInt64("storehouse_id")
  3577. orgId := this.GetAdminUserInfo().CurrentOrgId
  3578. list, _ := service.GetDrugInventoryWarehouseInfoList(orgId, storehouse_id)
  3579. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3580. dealerList, _ := service.GetAllDealerList(orgId)
  3581. this.ServeSuccessJSON(map[string]interface{}{
  3582. "list": list,
  3583. "manufacturerList": manufacturerList,
  3584. "dealerList": dealerList,
  3585. })
  3586. }
  3587. func (this *SelfDrugApiController) GetInventoryDetailPrintList() {
  3588. keyword := this.GetString("keyword")
  3589. limit, _ := this.GetInt64("limit")
  3590. page, _ := this.GetInt64("page")
  3591. storehouse_id, _ := this.GetInt64("storehouse_id")
  3592. ids := this.GetString("ids")
  3593. idSplit := strings.Split(ids, ",")
  3594. orgId := this.GetAdminUserInfo().CurrentOrgId
  3595. list, total, err := service.GetDrugInventoryDetailMapList(keyword, page, limit, orgId, storehouse_id, idSplit)
  3596. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  3597. houseList, _ := service.GetAllStoreHouseList(orgId)
  3598. doctorList, _ := service.GetAllDoctorThree(orgId)
  3599. if err != nil {
  3600. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  3601. return
  3602. }
  3603. this.ServeSuccessJSON(map[string]interface{}{
  3604. "total": total,
  3605. "list": list,
  3606. "doctorList": doctorList,
  3607. "houseList": houseList,
  3608. "inventoryList": inventoryList,
  3609. })
  3610. }
  3611. func (this *SelfDrugApiController) GetDrugFlowDetailById() {
  3612. drug_id, _ := this.GetInt64("drug_id")
  3613. list, _ := service.GetDrugFlowDetailById(drug_id)
  3614. drugMedical, _ := service.GetBaseDrugMedical(drug_id)
  3615. for index, _ := range list {
  3616. if list[index].ConsumableType == 3 || list[index].ConsumableType == 2 || list[index].ConsumableType == 11 || list[index].ConsumableType == 12 || list[index].ConsumableType == 15 {
  3617. var count int64
  3618. if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
  3619. list[index].Count = list[index].Count * drugMedical.MinNumber
  3620. }
  3621. if index == 0 {
  3622. count = list[index].FlushOverCount - list[index].Count
  3623. service.UpdateDrugOverCount(list[index+1].ID, count)
  3624. }
  3625. if index >= 1 {
  3626. lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
  3627. count = lastStockFlow.FlushOverCount - list[index].Count
  3628. service.UpdateDrugOverCount(list[index].ID, count)
  3629. }
  3630. }
  3631. if list[index].ConsumableType == 7 || list[index].ConsumableType == 4 || list[index].ConsumableType == 1 || list[index].ConsumableType == 10 || list[index].ConsumableType == 13 {
  3632. if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
  3633. list[index].Count = list[index].Count * drugMedical.MinNumber
  3634. }
  3635. if index == 0 {
  3636. var count int64
  3637. count = list[index].OverCount + list[index].Count
  3638. service.UpdateDrugOverCount(list[index+1].ID, count)
  3639. }
  3640. if index >= 1 {
  3641. var count int64
  3642. lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
  3643. count = lastStockFlow.FlushOverCount + list[index].Count
  3644. service.UpdateDrugOverCount(list[index].ID, count)
  3645. }
  3646. }
  3647. }
  3648. }
  3649. func (this *SelfDrugApiController) GetPurchaseDrugQueryList() {
  3650. good_type, _ := this.GetInt64("good_type")
  3651. keyword := this.GetString("keyword")
  3652. page, _ := this.GetInt64("page")
  3653. limit, _ := this.GetInt64("limit")
  3654. start_time := this.GetString("start_time")
  3655. end_time := this.GetString("end_time")
  3656. orgId := this.GetAdminUserInfo().CurrentOrgId
  3657. timeLayout := "2006-01-02"
  3658. loc, _ := time.LoadLocation("Local")
  3659. var startTime int64
  3660. if len(start_time) > 0 {
  3661. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3662. if err != nil {
  3663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3664. return
  3665. }
  3666. startTime = theTime.Unix()
  3667. }
  3668. var endTime int64
  3669. if len(end_time) > 0 {
  3670. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3671. if err != nil {
  3672. utils.ErrorLog(err.Error())
  3673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3674. return
  3675. }
  3676. endTime = theTime.Unix()
  3677. }
  3678. var ids []int64
  3679. var infoIds []int64
  3680. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3681. for _, it := range manufacturers {
  3682. ids = append(ids, it.ID)
  3683. }
  3684. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  3685. for _, it := range infoList {
  3686. infoIds = append(infoIds, it.DrugId)
  3687. }
  3688. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3689. list, total, err := service.GetDrugNewPurchaseStockQueryList(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  3690. for _, item := range list {
  3691. //获取期初结余
  3692. flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
  3693. item.DrugStatFlow = flow
  3694. //获取期末结余
  3695. endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
  3696. item.DrugEndFlow = endFlow
  3697. //获取期初结余入库数量
  3698. //期中增加
  3699. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  3700. for _, it := range drugWarehouse {
  3701. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  3702. }
  3703. //期中减少
  3704. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3705. for _, it := range outInfo {
  3706. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  3707. }
  3708. //期中退库
  3709. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3710. for _, it := range cancelstartInfo {
  3711. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  3712. }
  3713. //获取期中盘盈
  3714. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  3715. for _, it := range profit {
  3716. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3717. }
  3718. //获取期中盘亏
  3719. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  3720. for _, it := range endLosses {
  3721. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3722. }
  3723. }
  3724. if err != nil {
  3725. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3726. return
  3727. }
  3728. var drugType = "药品类型"
  3729. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3730. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3731. this.ServeSuccessJSON(map[string]interface{}{
  3732. "list": list,
  3733. "manufacturerList": manufacturerList,
  3734. "total": total,
  3735. "drugTypeList": drugTypeList,
  3736. })
  3737. }
  3738. func (this *SelfDrugApiController) GetPurchaseStockQueryList() {
  3739. good_type, _ := this.GetInt64("good_type")
  3740. keyword := this.GetString("keyword")
  3741. page, _ := this.GetInt64("page")
  3742. limit, _ := this.GetInt64("limit")
  3743. start_time := this.GetString("start_time")
  3744. end_time := this.GetString("end_time")
  3745. orgId := this.GetAdminUserInfo().CurrentOrgId
  3746. timeLayout := "2006-01-02"
  3747. loc, _ := time.LoadLocation("Local")
  3748. var startTime int64
  3749. if len(start_time) > 0 {
  3750. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3751. if err != nil {
  3752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3753. return
  3754. }
  3755. startTime = theTime.Unix()
  3756. }
  3757. var endTime int64
  3758. if len(end_time) > 0 {
  3759. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3760. if err != nil {
  3761. utils.ErrorLog(err.Error())
  3762. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3763. return
  3764. }
  3765. endTime = theTime.Unix()
  3766. }
  3767. var ids []int64
  3768. var goodIds []int64
  3769. infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  3770. for _, it := range infoList {
  3771. goodIds = append(goodIds, it.GoodId)
  3772. }
  3773. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3774. for _, it := range manufacturers {
  3775. ids = append(ids, it.ID)
  3776. }
  3777. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  3778. list, total, err := service.GetPurchaseStockQueryList(good_type, keyword, page, limit, orgId, ids, goodIds)
  3779. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3780. for _, item := range list {
  3781. //获取期初结余
  3782. low, _ := service.GetStartLastFLow(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3783. item.GoodStartFlowInfo = low
  3784. //获取期末结余
  3785. flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime, storeConfig.StorehouseOutInfo)
  3786. item.GoodEndFlowInfo = flow
  3787. //获取期间增加
  3788. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3789. for _, it := range goodWarehouseInfoList {
  3790. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3791. }
  3792. //获取本期增加
  3793. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3794. for _, it := range WarehouseInfoFlowList {
  3795. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3796. }
  3797. //获取本期减少
  3798. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3799. for _, it := range reduceWarehouseInfoList {
  3800. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3801. }
  3802. //获取期中减少退库
  3803. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3804. for _, it := range lowInfo {
  3805. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3806. }
  3807. //
  3808. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3809. for _, it := range outInfo {
  3810. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3811. }
  3812. //期中盘盈
  3813. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3814. for _, it := range profit {
  3815. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3816. }
  3817. //期中盘亏
  3818. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3819. for _, it := range losses {
  3820. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3821. }
  3822. }
  3823. if err != nil {
  3824. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3825. return
  3826. }
  3827. this.ServeSuccessJSON(map[string]interface{}{
  3828. "list": list,
  3829. "manufacturerList": manufacturerList,
  3830. "total": total,
  3831. })
  3832. }