self_drug_api_congtroller.go 135KB

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