self_drug_api_congtroller.go 137KB

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