self_drug_api_congtroller.go 134KB

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