self_drug_api_congtroller.go 134KB

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