self_drug_api_congtroller.go 131KB

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