self_drug_api_congtroller.go 147KB

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