self_drug_api_congtroller.go 147KB

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