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. if len(tableData) > 0 {
  1606. for _, item := range tableData {
  1607. items := item.(map[string]interface{})
  1608. drug_name := items["drug_name"].(string)
  1609. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1610. utils.ErrorLog("drug_name")
  1611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1612. return
  1613. }
  1614. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1615. utils.ErrorLog("retail_price")
  1616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1617. return
  1618. }
  1619. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1620. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1621. utils.ErrorLog("warehousing_order")
  1622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1623. return
  1624. }
  1625. warehousing_order := items["warehousing_order"].(string)
  1626. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1627. utils.ErrorLog("dealer")
  1628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1629. return
  1630. }
  1631. dealer := items["dealer"].(string)
  1632. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1633. utils.ErrorLog("manufacturer")
  1634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1635. return
  1636. }
  1637. manufacturer := items["manufacturer"].(string)
  1638. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1639. utils.ErrorLog("specification_name")
  1640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. specification_name := items["specification_name"].(string)
  1644. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1645. utils.ErrorLog("remark")
  1646. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1647. return
  1648. }
  1649. remark := items["remark"].(string)
  1650. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1651. utils.ErrorLog("warehousing_unit")
  1652. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. warehousing_unit := items["warehousing_unit"].(string)
  1656. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1657. utils.ErrorLog("last_price")
  1658. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1659. return
  1660. }
  1661. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1662. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1663. utils.ErrorLog("count")
  1664. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1665. return
  1666. }
  1667. count := int64(items["count"].(float64))
  1668. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1669. utils.ErrorLog("new_price")
  1670. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1671. return
  1672. }
  1673. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1674. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1675. utils.ErrorLog("drug_id")
  1676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1677. return
  1678. }
  1679. drug_id := int64(items["drug_id"].(float64))
  1680. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1681. utils.ErrorLog("start_time")
  1682. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1683. return
  1684. }
  1685. var startTime int64
  1686. start_time := items["start_time"].(string)
  1687. if len(start_time) > 0 {
  1688. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1689. if err != nil {
  1690. fmt.Println(err)
  1691. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1692. return
  1693. }
  1694. startTime = theTime.Unix()
  1695. }
  1696. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  1697. utils.ErrorLog("product_date")
  1698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1699. return
  1700. }
  1701. product_date := int64(items["product_date"].(float64))
  1702. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  1703. utils.ErrorLog("expiry_date")
  1704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1705. return
  1706. }
  1707. expiry_date := int64(items["expiry_date"].(float64))
  1708. orgId := this.GetAdminUserInfo().CurrentOrgId
  1709. Creater := this.GetAdminUserInfo().AdminUser.Id
  1710. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1711. utils.ErrorLog("number")
  1712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1713. return
  1714. }
  1715. numbers := items["number"].(string)
  1716. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1717. utils.ErrorLog("warehouse_info_id")
  1718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1719. return
  1720. }
  1721. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1722. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
  1723. utils.ErrorLog("total")
  1724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1725. return
  1726. }
  1727. total := items["total"].(string)
  1728. drug_origin_place := items["drug_origin_place"].(string)
  1729. min_count := int64(items["min_count"].(float64))
  1730. min_unit := items["min_unit"].(string)
  1731. inventory := models.XtDrugInventory{
  1732. DrugName: drug_name,
  1733. SpecificationName: specification_name,
  1734. WarehousingUnit: warehousing_unit,
  1735. Count: count,
  1736. LastPrice: last_price,
  1737. RetailPrice: retail_price,
  1738. NewPrice: new_price,
  1739. Manufacturer: manufacturer,
  1740. Dealer: dealer,
  1741. Remark: remark,
  1742. DrugId: drug_id,
  1743. UserOrgId: orgId,
  1744. Ctime: time.Now().Unix(),
  1745. Mtime: 0,
  1746. Status: 1,
  1747. WarehousingOrder: warehousing_order,
  1748. LicenseNumber: "",
  1749. StartTime: startTime,
  1750. Creater: Creater,
  1751. Checker: 0,
  1752. CheckerStatus: 2,
  1753. CheckerTime: 0,
  1754. ExpiryDate: expiry_date,
  1755. ProductDate: product_date,
  1756. Number: numbers,
  1757. //BatchNumber: batch_number,
  1758. Total: total,
  1759. WarehouseInfoId: warehouse_info_id,
  1760. DrugOriginPlace: drug_origin_place,
  1761. MinUnit: min_unit,
  1762. MinCount: min_count,
  1763. }
  1764. err = service.CreateDrugInventory(inventory)
  1765. fmt.Println(err)
  1766. }
  1767. }
  1768. this.ServeSuccessJSON(map[string]interface{}{
  1769. "msg": "msg",
  1770. })
  1771. }
  1772. func (this *SelfDrugApiController) GetDrugInventoryList() {
  1773. timeLayout := "2006-01-02"
  1774. loc, _ := time.LoadLocation("Local")
  1775. dataBody := make(map[string]interface{}, 0)
  1776. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1777. fmt.Println(err)
  1778. orgId := this.GetAdminUserInfo().CurrentOrgId
  1779. keyword := this.GetString("keyword")
  1780. start_time := this.GetString("start_time")
  1781. end_time := this.GetString("end_time")
  1782. var startTime int64
  1783. if len(start_time) > 0 {
  1784. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1785. if err != nil {
  1786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1787. return
  1788. }
  1789. startTime = theTime.Unix()
  1790. }
  1791. var endTime int64
  1792. if len(end_time) > 0 {
  1793. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1794. if err != nil {
  1795. utils.ErrorLog(err.Error())
  1796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1797. return
  1798. }
  1799. endTime = theTime.Unix()
  1800. }
  1801. limit, _ := this.GetInt64("limit")
  1802. page, _ := this.GetInt64("page")
  1803. list, total, err := service.GetDrugInventoryList(keyword, page, limit, orgId, startTime, endTime)
  1804. doctorList, _ := service.GetAllDoctorThree(orgId)
  1805. houseList, _ := service.GetAllStoreHouseList(orgId)
  1806. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1807. if err != nil {
  1808. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1809. return
  1810. }
  1811. this.ServeSuccessJSON(map[string]interface{}{
  1812. "total": total,
  1813. "list": list,
  1814. "doctorList": doctorList,
  1815. "houseList": houseList,
  1816. "houseConfig": houseConfig,
  1817. })
  1818. }
  1819. func (this *SelfDrugApiController) SaveDrugCheckInventory() {
  1820. timeLayout := "2006-01-02"
  1821. loc, _ := time.LoadLocation("Local")
  1822. dataBody := make(map[string]interface{}, 0)
  1823. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1824. fmt.Println(err)
  1825. idstr := this.GetString("ids")
  1826. ids := strings.Split(idstr, ",")
  1827. check_time := this.GetString("check_time")
  1828. var checkTime int64
  1829. if len(check_time) > 0 {
  1830. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1831. if err != nil {
  1832. fmt.Println(err)
  1833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1834. return
  1835. }
  1836. checkTime = theTime.Unix()
  1837. }
  1838. checker, _ := this.GetInt64("checker")
  1839. inventory := models.XtDrugInventory{
  1840. Checker: checker,
  1841. CheckerStatus: 1,
  1842. CheckerTime: checkTime,
  1843. }
  1844. err = service.UpdateDrugInventory(ids, inventory)
  1845. fmt.Println(err)
  1846. list, _ := service.GetDrugInventoryListByIds(ids)
  1847. adminUserInfo := this.GetAdminUserInfo()
  1848. var stock_total int64
  1849. var proof_count int64
  1850. var maxNumber int64
  1851. var minNumber int64
  1852. for _, item := range list {
  1853. //查询药品信息
  1854. drug, _ := service.GetDrugDetailByDrugId(item.DrugId)
  1855. //查询库存
  1856. info, _ := service.GetDrugWareInfoByIdTwo(item.WarehouseInfoId)
  1857. var max_count int64
  1858. var min_count int64
  1859. for _, it := range info {
  1860. max_count += it.StockMaxNumber
  1861. min_count += it.StockMinNumber
  1862. }
  1863. //获取最晚的库存数量
  1864. lastInfo, _ := service.GetLastDrugWarehouseInfo(item.DrugId)
  1865. firstInfo, _ := service.GetFirstDrugWarehouseInfo(item.DrugId)
  1866. stock_total = max_count*drug.MinNumber + min_count
  1867. proof_count = item.Count*drug.MinNumber + item.MinCount
  1868. fmt.Println("stock_total", stock_total)
  1869. fmt.Println("proof_count", proof_count)
  1870. //判断 如果库存数量 大于盘点库存,则出库
  1871. if stock_total > proof_count {
  1872. minNumber = (stock_total - proof_count) % drug.MinNumber
  1873. maxNumber = (stock_total - proof_count) / drug.MinNumber
  1874. ctime := time.Now().Unix()
  1875. timeStr := time.Now().Format("2006-01-02")
  1876. timeArr := strings.Split(timeStr, "-")
  1877. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1878. total = total + 1
  1879. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1880. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1881. number = number + total
  1882. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1883. operation_time := time.Now().Unix()
  1884. creater := adminUserInfo.AdminUser.Id
  1885. warehouseOut := models.DrugWarehouseOut{
  1886. WarehouseOutOrderNumber: warehousing_out_order,
  1887. OperationTime: operation_time,
  1888. OrgId: adminUserInfo.CurrentOrgId,
  1889. Creater: creater,
  1890. Ctime: ctime,
  1891. Status: 1,
  1892. WarehouseOutTime: ctime,
  1893. Type: 1,
  1894. }
  1895. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1896. warehouse, _ := service.GetLastDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1897. warehouseOutInfo := models.DrugWarehouseOutInfo{
  1898. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1899. WarehouseOutId: warehouse.ID,
  1900. DrugId: item.DrugId,
  1901. Count: maxNumber,
  1902. Price: firstInfo.Price,
  1903. TotalPrice: firstInfo.TotalPrice,
  1904. Status: 1,
  1905. Ctime: ctime,
  1906. Remark: item.Remark,
  1907. OrgId: adminUserInfo.CurrentOrgId,
  1908. Type: 1,
  1909. Manufacturer: firstInfo.Manufacturer,
  1910. Dealer: firstInfo.Dealer,
  1911. RetailPrice: firstInfo.RetailPrice,
  1912. RetailTotalPrice: firstInfo.RetailTotalPrice,
  1913. CountUnit: drug.MaxUnit,
  1914. ExpiryDate: firstInfo.ExpiryDate,
  1915. ProductDate: firstInfo.ProductDate,
  1916. Number: firstInfo.Number,
  1917. BatchNumber: firstInfo.BatchNumber,
  1918. IsSys: 0,
  1919. WarehouseInfoId: firstInfo.ID,
  1920. }
  1921. drugflow := models.DrugFlow{
  1922. WarehouseOutId: warehouseOut.ID,
  1923. WarehouseOutOrderNumber: warehousing_out_order,
  1924. DrugId: item.DrugId,
  1925. Number: firstInfo.Number,
  1926. ProductDate: firstInfo.ProductDate,
  1927. ExpireDate: firstInfo.ExpiryDate,
  1928. Count: maxNumber,
  1929. Price: firstInfo.Price,
  1930. Status: 1,
  1931. Ctime: ctime,
  1932. UserOrgId: adminUserInfo.CurrentOrgId,
  1933. Manufacturer: firstInfo.Manufacturer,
  1934. Dealer: firstInfo.Dealer,
  1935. BatchNumber: firstInfo.BatchNumber,
  1936. MaxUnit: drug.MaxUnit,
  1937. ConsumableType: 2,
  1938. IsEdit: 1,
  1939. Creator: adminUserInfo.AdminUser.Id,
  1940. IsSys: 0,
  1941. }
  1942. service.CreateDrugWarehouseOutInfo(warehouseOutInfo)
  1943. service.CreateDrugFlowOne(drugflow)
  1944. //扣减当前批次号的库存
  1945. var total_count int64
  1946. //查询当前批次库存的数量
  1947. warehosueInfoList, _ := service.GetCurrentWarehosueInfo(item.WarehouseInfoId)
  1948. fmt.Println(warehosueInfoList)
  1949. for _, item := range warehosueInfoList {
  1950. total_count += item.StockMaxNumber*drug.MinNumber + item.StockMinNumber
  1951. }
  1952. //判断当前批次库存 和 需要出库的数据
  1953. //出库
  1954. if proof_count <= total_count {
  1955. //var total_count_one int64
  1956. //获取当前批次号的库存
  1957. //warehouseinfoOne, _ := service.GetCurrentWarehosueInfoOne(item.WarehouseInfoId)
  1958. //total_count_one = warehouseinfoOne.StockMaxNumber * drug.MinNumber + warehouseinfoOne.StockMinNumber
  1959. }
  1960. //报错提示
  1961. if proof_count > total_count {
  1962. this.ServeSuccessJSON(map[string]interface{}{
  1963. "msg": "1",
  1964. })
  1965. }
  1966. }
  1967. //判断 如果库存数量 小于于盘点库存,则入库
  1968. fmt.Println("stock_total2332322323223", stock_total, proof_count)
  1969. if stock_total < proof_count {
  1970. maxNumber = (proof_count - stock_total) / drug.MinNumber
  1971. minNumber = (proof_count - stock_total) % drug.MinNumber
  1972. fmt.Println("min_number23233232323223322323", minNumber)
  1973. ctime := time.Now().Unix()
  1974. timeStr := time.Now().Format("2006-01-02")
  1975. timeArr := strings.Split(timeStr, "-")
  1976. total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
  1977. total = total + 1
  1978. fmt.Println("total2323232323232", total)
  1979. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1980. operation_time := time.Now().Unix()
  1981. creater := adminUserInfo.AdminUser.Id
  1982. warehousing := models.DrugWarehouse{
  1983. WarehousingOrder: warehousing_order,
  1984. OperationTime: operation_time,
  1985. OrgId: adminUserInfo.CurrentOrgId,
  1986. Creater: creater,
  1987. Ctime: ctime,
  1988. Status: 1,
  1989. WarehousingTime: ctime,
  1990. Type: 1,
  1991. }
  1992. service.AddSigleDrugWarehouse(&warehousing)
  1993. warehouse, _ := service.GetLastDrugWarehouse(adminUserInfo.CurrentOrgId)
  1994. warehouseInfo := models.DrugWarehouseInfo{
  1995. WarehousingOrder: warehousing.WarehousingOrder,
  1996. WarehousingId: warehouse.ID,
  1997. DrugId: item.DrugId,
  1998. Number: lastInfo.Number,
  1999. ProductDate: lastInfo.ProductDate,
  2000. ExpiryDate: lastInfo.ExpiryDate,
  2001. WarehousingCount: maxNumber,
  2002. Price: lastInfo.Price,
  2003. TotalPrice: lastInfo.TotalPrice,
  2004. Status: 1,
  2005. Ctime: ctime,
  2006. Remark: item.Remark,
  2007. OrgId: adminUserInfo.CurrentOrgId,
  2008. Type: 1,
  2009. Manufacturer: lastInfo.Manufacturer,
  2010. Dealer: lastInfo.Dealer,
  2011. StockMaxNumber: maxNumber,
  2012. StockMinNumber: minNumber,
  2013. RetailTotalPrice: lastInfo.RetailTotalPrice,
  2014. BatchNumber: lastInfo.BatchNumber,
  2015. MaxUnit: drug.MaxUnit,
  2016. MinUnit: drug.MinUnit,
  2017. WarehousingInfoId: item.WarehouseInfoId,
  2018. }
  2019. drugflow := models.DrugFlow{
  2020. WarehousingOrder: warehousing.WarehousingOrder,
  2021. WarehousingId: warehouse.ID,
  2022. DrugId: item.DrugId,
  2023. Number: lastInfo.Number,
  2024. ProductDate: lastInfo.ProductDate,
  2025. ExpireDate: lastInfo.ExpiryDate,
  2026. Count: maxNumber,
  2027. Price: lastInfo.Price,
  2028. Status: 1,
  2029. Ctime: ctime,
  2030. UserOrgId: adminUserInfo.CurrentOrgId,
  2031. Manufacturer: lastInfo.Manufacturer,
  2032. Dealer: lastInfo.Dealer,
  2033. BatchNumber: lastInfo.BatchNumber,
  2034. MaxUnit: drug.MaxUnit,
  2035. MinUnit: drug.MinUnit,
  2036. ConsumableType: 1,
  2037. IsEdit: 1,
  2038. Creator: adminUserInfo.AdminUser.Id,
  2039. IsSys: 0,
  2040. }
  2041. service.CreateDrugWarehouseInfo(warehouseInfo)
  2042. service.CreateDrugFlowOne(drugflow)
  2043. }
  2044. }
  2045. returnData := make(map[string]interface{}, 0)
  2046. returnData["msg"] = "ok"
  2047. this.ServeSuccessJSON(returnData)
  2048. }
  2049. func (this *SelfDrugApiController) GetDrugInventoryDetail() {
  2050. id, _ := this.GetInt64("id")
  2051. detail, err := service.GetDrugInventoryDetail(id)
  2052. if err != nil {
  2053. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2054. return
  2055. }
  2056. this.ServeSuccessJSON(map[string]interface{}{
  2057. "detail": detail,
  2058. })
  2059. }
  2060. func (this *SelfDrugApiController) ModifyInventory() {
  2061. id, _ := this.GetInt64("id")
  2062. drug_id, _ := this.GetInt64("drug_id")
  2063. drug_name := this.GetString("drug_name")
  2064. specification_name := this.GetString("specification_name")
  2065. retailPrice := this.GetString("retail_price")
  2066. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  2067. warehousing_order := this.GetString("warehousing_order")
  2068. number := this.GetString("number")
  2069. manufacturer := this.GetString("manufacturer")
  2070. remark := this.GetString("remark")
  2071. warehousing_unit := this.GetString("warehousing_unit")
  2072. total := this.GetString("total")
  2073. lastPrice := this.GetString("last_price")
  2074. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  2075. count, _ := this.GetInt64("count")
  2076. drug_origin_place := this.GetString("drug_origin_place")
  2077. stock_max_number, _ := this.GetInt64("stock_max_number")
  2078. stock_min_number, _ := this.GetInt64("stock_min_number")
  2079. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2080. min_count, _ := this.GetInt64("min_count")
  2081. min_unit := this.GetString("min_unit")
  2082. inventory := models.XtDrugInventory{
  2083. DrugName: drug_name,
  2084. SpecificationName: specification_name,
  2085. WarehousingUnit: warehousing_unit,
  2086. Count: count,
  2087. LastPrice: last_price,
  2088. RetailPrice: retail_price,
  2089. Manufacturer: manufacturer,
  2090. Remark: remark,
  2091. DrugId: drug_id,
  2092. WarehousingOrder: warehousing_order,
  2093. Number: number,
  2094. Total: total,
  2095. DrugOriginPlace: drug_origin_place,
  2096. StockMaxNumber: stock_max_number,
  2097. StockMinNumber: stock_min_number,
  2098. WarehouseInfoId: warehouse_info_id,
  2099. MinCount: min_count,
  2100. MinUnit: min_unit,
  2101. }
  2102. err := service.ModifyDrugInventory(id, inventory)
  2103. if err != nil {
  2104. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2105. return
  2106. }
  2107. this.ServeSuccessJSON(map[string]interface{}{
  2108. "inventory": inventory,
  2109. })
  2110. }
  2111. func (this *SelfDrugApiController) DeleteDrugInventory() {
  2112. id, _ := this.GetInt64("id")
  2113. err := service.DeleteDrugInventory(id)
  2114. fmt.Println(err)
  2115. returnData := make(map[string]interface{}, 0)
  2116. returnData["msg"] = "ok"
  2117. this.ServeSuccessJSON(returnData)
  2118. }
  2119. func (this *SelfDrugApiController) GetDrugInventoryPrintList() {
  2120. ids := this.GetString("ids")
  2121. idssplit := strings.Split(ids, ",")
  2122. list, err := service.GetDrugInventoryPrintList(idssplit)
  2123. if err != nil {
  2124. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2125. return
  2126. }
  2127. this.ServeSuccessJSON(map[string]interface{}{
  2128. "list": list,
  2129. })
  2130. }
  2131. func (this *SelfDrugApiController) GetDrugInventoryDetailList() {
  2132. keyword := this.GetString("keyword")
  2133. limit, _ := this.GetInt64("limit")
  2134. page, _ := this.GetInt64("page")
  2135. storehouse_id, _ := this.GetInt64("storehouse_id")
  2136. orgId := this.GetAdminUserInfo().CurrentOrgId
  2137. appId := this.GetAdminUserInfo().CurrentAppId
  2138. list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId, storehouse_id)
  2139. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  2140. houseList, _ := service.GetAllStoreHouseList(orgId)
  2141. doctorList, _ := service.GetAllDoctorListSix(orgId, appId)
  2142. if err != nil {
  2143. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2144. return
  2145. }
  2146. this.ServeSuccessJSON(map[string]interface{}{
  2147. "total": total,
  2148. "list": list,
  2149. "doctorList": doctorList,
  2150. "houseList": houseList,
  2151. "inventoryList": inventoryList,
  2152. })
  2153. }
  2154. func (this *SelfDrugApiController) SaveDrugProofInventory() {
  2155. id, _ := this.GetInt64("id")
  2156. warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
  2157. warehousing_unit := this.GetString("warehousing_unit")
  2158. remark := this.GetString("remark")
  2159. proof_count, _ := this.GetInt64("proof_count")
  2160. inventory := models.XtDrugInventory{
  2161. WarehouseInfoId: warehouse_info_id,
  2162. ProofCount: proof_count,
  2163. WarehousingUnit: warehousing_unit,
  2164. Remark: remark,
  2165. }
  2166. err := service.UpdateDrugProofInventory(id, &inventory)
  2167. info := models.XtDrugWarehouseInfo{
  2168. StockMaxNumber: proof_count,
  2169. }
  2170. service.UpdateDrugWarehouseInfoById(warehouse_info_id, &info)
  2171. if err != nil {
  2172. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2173. return
  2174. }
  2175. this.ServeSuccessJSON(map[string]interface{}{
  2176. "inventory": inventory,
  2177. })
  2178. }
  2179. func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
  2180. id, _ := this.GetInt64("id")
  2181. list, _ := service.GetDrugWarehouseInfoTotal(id)
  2182. this.ServeSuccessJSON(map[string]interface{}{
  2183. "list": list,
  2184. })
  2185. }
  2186. //新改造
  2187. func (this *SelfDrugApiController) SaveInventoryList() {
  2188. dataBody := make(map[string]interface{}, 0)
  2189. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2190. fmt.Println(err)
  2191. tableData, _ := dataBody["tableData"].([]interface{})
  2192. if len(tableData) > 0 {
  2193. for _, item := range tableData {
  2194. items := item.(map[string]interface{})
  2195. drug_name := items["drug_name"].(string)
  2196. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  2197. utils.ErrorLog("drug_name")
  2198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2199. return
  2200. }
  2201. fmt.Println("drug_name", drug_name)
  2202. specification_name := items["specification_name"].(string)
  2203. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  2204. utils.ErrorLog("specification_name")
  2205. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2206. return
  2207. }
  2208. max_unit := items["max_unit"].(string)
  2209. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  2210. utils.ErrorLog("max_unit")
  2211. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2212. return
  2213. }
  2214. min_unit := items["min_unit"].(string)
  2215. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  2216. utils.ErrorLog("min_unit")
  2217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2218. return
  2219. }
  2220. drug_id := int64(items["drug_id"].(float64))
  2221. min_number := int64(items["min_number"].(float64))
  2222. stock_max_number := int64(items["stock_max_number"].(float64))
  2223. stock_min_number := int64(items["stock_min_number"].(float64))
  2224. last_stock_max_number := int64(items["last_stock_max_number"].(float64))
  2225. last_stock_min_number := int64(items["last_stock_min_number"].(float64))
  2226. warehousing_order := items["warehousing_order"].(string)
  2227. price := items["price"].(float64)
  2228. manufacturer_name := items["manufacturer_name"].(string)
  2229. batch_number := items["batch_number"].(string)
  2230. id := int64(items["id"].(float64))
  2231. orgId := this.GetAdminUserInfo().CurrentOrgId
  2232. type_id := int64(items["type"].(float64))
  2233. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  2234. utils.ErrorLog("expiry_date")
  2235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2236. return
  2237. }
  2238. expiry_date := int64(items["expiry_date"].(float64))
  2239. manufacturer := int64(items["manufacturer"].(float64))
  2240. storehouse_id := int64(items["storehouse_id"].(float64))
  2241. timeLayout := "2006-01-02"
  2242. loc, _ := time.LoadLocation("Local")
  2243. timeNow := time.Now().Format("2006-01-02")
  2244. locationTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeNow+" 00:00:00", loc)
  2245. var consumable_type int64
  2246. var consumable_count int64
  2247. var ord_total int64
  2248. var new_total int64
  2249. var total int64
  2250. ord_total = stock_max_number*min_number + stock_min_number
  2251. new_total = last_stock_max_number*min_number + last_stock_min_number
  2252. medical, _ := service.GetBaseDrugMedical(drug_id)
  2253. //改变库存
  2254. info := models.DrugWarehouseInfo{
  2255. DrugId: drug_id,
  2256. StockMaxNumber: last_stock_max_number,
  2257. StockMinNumber: last_stock_min_number,
  2258. WarehousingCount: last_stock_max_number,
  2259. MaxUnit: max_unit,
  2260. MinUnit: min_unit,
  2261. }
  2262. drugInfo, _ := service.GetCurrentWarehosueInfoOne(id)
  2263. if drugInfo.MaxUnit == medical.MaxUnit {
  2264. total = drugInfo.WarehousingCount * medical.MinNumber
  2265. }
  2266. if drugInfo.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2267. total = drugInfo.WarehousingCount
  2268. }
  2269. //如果库存数据大于盘点数据,则减去数量
  2270. if ord_total > new_total {
  2271. consumable_type = 11
  2272. consumable_count = ord_total - new_total
  2273. err = service.ModifyDrugWarehouseInfo(&info, id)
  2274. }
  2275. //如果库存数据小于盘点数据,则增加数量
  2276. if ord_total < new_total && new_total <= total {
  2277. consumable_type = 10
  2278. consumable_count = new_total - ord_total
  2279. err = service.ModifyDrugWarehouseInfo(&info, id)
  2280. }
  2281. if ord_total < new_total && new_total > total {
  2282. consumable_type = 10
  2283. consumable_count = new_total - ord_total
  2284. err = service.ModifyDrugWarehouseInfoSix(&info, id)
  2285. }
  2286. //查询默认仓库
  2287. houseConfig, _ := service.GetAllStoreHouseConfig(drugInfo.OrgId)
  2288. //查询默认仓库剩余多少库存
  2289. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, drugInfo.OrgId, drugInfo.DrugId)
  2290. var sum_count int64
  2291. var sum_in_count int64
  2292. for _, it := range list {
  2293. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2294. if it.MaxUnit == baseDrug.MaxUnit {
  2295. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2296. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2297. }
  2298. sum_count += it.StockMaxNumber + it.StockMinNumber
  2299. sum_in_count += it.WarehousingCount
  2300. }
  2301. service.UpdateMedicalSumCount(drugInfo.DrugId, sum_count, sum_in_count, drugInfo.OrgId)
  2302. //更新剩余库存
  2303. service.UpdateDrugStockCount(drugInfo.DrugId, drugInfo.OrgId, houseConfig.DrugStorehouseOut, sum_count)
  2304. inventory := models.XtDrugInventory{
  2305. DrugName: drug_name,
  2306. SpecificationName: specification_name,
  2307. WarehousingUnit: max_unit,
  2308. Count: consumable_count,
  2309. LastPrice: price,
  2310. RetailPrice: 0,
  2311. NewPrice: 0,
  2312. Manufacturer: manufacturer_name,
  2313. Dealer: "",
  2314. Remark: "",
  2315. DrugId: drug_id,
  2316. UserOrgId: orgId,
  2317. Ctime: time.Now().Unix(),
  2318. Mtime: 0,
  2319. Status: 1,
  2320. WarehousingOrder: warehousing_order,
  2321. LicenseNumber: "",
  2322. StartTime: locationTime.Unix(),
  2323. Creater: this.GetAdminUserInfo().AdminUser.Id,
  2324. Checker: 0,
  2325. CheckerStatus: 0,
  2326. CheckerTime: 0,
  2327. ExpiryDate: expiry_date,
  2328. ProductDate: 0,
  2329. Number: "",
  2330. BatchNumber: batch_number,
  2331. Total: "",
  2332. DrugOriginPlace: "",
  2333. WarehouseInfoId: id,
  2334. ProofCount: 0,
  2335. StockMaxNumber: stock_max_number,
  2336. StockMinNumber: stock_min_number,
  2337. MinCount: 0,
  2338. MinUnit: min_unit,
  2339. LastStockMaxNumber: last_stock_max_number,
  2340. LastStockMinNumber: last_stock_min_number,
  2341. InventoryType: consumable_type,
  2342. Type: type_id,
  2343. StorehouseId: storehouse_id,
  2344. }
  2345. err = service.CreateDrugInventory(inventory)
  2346. flow := models.DrugFlow{
  2347. WarehousingId: id,
  2348. DrugId: drug_id,
  2349. Number: "",
  2350. BatchNumber: batch_number,
  2351. Count: consumable_count,
  2352. UserOrgId: orgId,
  2353. PatientId: 0,
  2354. SystemTime: locationTime.Unix(),
  2355. ConsumableType: consumable_type,
  2356. IsSys: 1,
  2357. WarehousingOrder: warehousing_order,
  2358. WarehouseOutId: 0,
  2359. WarehouseOutOrderNumber: "",
  2360. IsEdit: 0,
  2361. CancelStockId: 0,
  2362. CancelOrderNumber: "",
  2363. Manufacturer: manufacturer,
  2364. Dealer: 0,
  2365. Creator: this.GetAdminUserInfo().AdminUser.Id,
  2366. UpdateCreator: 0,
  2367. Status: 1,
  2368. Ctime: time.Now().Unix(),
  2369. Mtime: 0,
  2370. Price: price,
  2371. WarehousingDetailId: id,
  2372. WarehouseOutDetailId: 0,
  2373. CancelOutDetailId: 0,
  2374. ExpireDate: expiry_date,
  2375. ProductDate: 0,
  2376. MaxUnit: min_unit,
  2377. MinUnit: min_unit,
  2378. StorehouseId: storehouse_id,
  2379. OverCount: sum_count,
  2380. }
  2381. if ord_total != new_total {
  2382. service.CreateDrugFlowOne(flow)
  2383. }
  2384. if err != nil {
  2385. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2386. return
  2387. }
  2388. this.ServeSuccessJSON(map[string]interface{}{
  2389. "inventory": inventory,
  2390. })
  2391. }
  2392. }
  2393. }
  2394. func (this *SelfDrugApiController) GetDamageByDrugId() {
  2395. drug_id, _ := this.GetInt64("drug_id")
  2396. warehousing_order := this.GetString("warehouseing_order")
  2397. drug_type, _ := this.GetInt64("type")
  2398. list, err := service.GetDamageByDrugId(drug_id, warehousing_order, drug_type)
  2399. if err != nil {
  2400. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2401. return
  2402. }
  2403. this.ServeSuccessJSON(map[string]interface{}{
  2404. "list": list,
  2405. })
  2406. }
  2407. func (this *SelfDrugApiController) GetInventoryModeList() {
  2408. orgId := this.GetAdminUserInfo().CurrentOrgId
  2409. list, err := service.GetInventoryModeList(orgId)
  2410. manufacturerList, err := service.GetAllManufacturerList(orgId)
  2411. if err != nil {
  2412. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  2413. return
  2414. }
  2415. this.ServeSuccessJSON(map[string]interface{}{
  2416. "list": list,
  2417. "manufacturerList": manufacturerList,
  2418. })
  2419. }
  2420. // 库存优化接口
  2421. func (this *SelfDrugApiController) GetStorehouseList() {
  2422. orgId := this.GetAdminUserInfo().CurrentOrgId
  2423. list, err := service.GetAllStoreHouseList(orgId)
  2424. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  2425. goodType, _ := service.GetAllNewGoodType(orgId)
  2426. patientList, _ := service.GetAllpatientThirty(orgId)
  2427. dealerList, _ := service.GetAllDealerList(orgId)
  2428. if err != nil {
  2429. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取仓库失败")
  2430. return
  2431. }
  2432. this.ServeSuccessJSON(map[string]interface{}{
  2433. "list": list,
  2434. "manufacturerList": manufacturerList,
  2435. "goodTypeList": goodType,
  2436. "patientList": patientList,
  2437. "dealerList": dealerList,
  2438. })
  2439. }
  2440. func (this *SelfDrugApiController) GetGoodNewQuery() {
  2441. orgId := this.GetAdminUserInfo().CurrentOrgId
  2442. storehouse_id, _ := this.GetInt64("storehouse_id")
  2443. good_type, _ := this.GetInt64("good_type")
  2444. keyword := this.GetString("keyword")
  2445. page, _ := this.GetInt64("page")
  2446. limit, _ := this.GetInt64("limit")
  2447. // 查询该机构所有耗材入库信息
  2448. //goodList, _ := service.GetAllGoodListSeven(orgId)
  2449. //
  2450. //for _, it := range goodList {
  2451. // var sum_total int64
  2452. // //查询该耗材入库信息
  2453. // warehouseinfo, _ := service.GetGoodInformationWarehouseInfo(it.ID, orgId)
  2454. // for _, item := range warehouseinfo {
  2455. // sum_total += item.StockCount
  2456. // }
  2457. // service.UpdateGoodInformation(it.ID, orgId, sum_total)
  2458. //}
  2459. var ids []int64
  2460. if len(keyword) > 0 {
  2461. manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2462. for _, it := range manufacturerList {
  2463. ids = append(ids, it.ID)
  2464. }
  2465. }
  2466. stockList, total, err := service.GetGoodStockList(orgId, storehouse_id, good_type, keyword, page, limit, ids)
  2467. if err != nil {
  2468. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
  2469. return
  2470. }
  2471. this.ServeSuccessJSON(map[string]interface{}{
  2472. "total": total,
  2473. "stockList": stockList,
  2474. })
  2475. }
  2476. func (this *SelfDrugApiController) GetGoodWarehouseOutInfoByIdList() {
  2477. good_id, _ := this.GetInt64("good_id")
  2478. limit, _ := this.GetInt64("limit")
  2479. page, _ := this.GetInt64("page")
  2480. start_time := this.GetString("start_first_time")
  2481. end_time := this.GetString("end_first_time")
  2482. storehouse_id, _ := this.GetInt64("storehouse_id")
  2483. orgId := this.GetAdminUserInfo().CurrentOrgId
  2484. timeLayout := "2006-01-02"
  2485. loc, _ := time.LoadLocation("Local")
  2486. var startTime int64
  2487. if len(start_time) > 0 {
  2488. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2489. if err != nil {
  2490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2491. return
  2492. }
  2493. startTime = theTime.Unix()
  2494. }
  2495. var endTime int64
  2496. if len(end_time) > 0 {
  2497. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2498. if err != nil {
  2499. utils.ErrorLog(err.Error())
  2500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2501. return
  2502. }
  2503. endTime = theTime.Unix()
  2504. }
  2505. list, total, err := service.GetGoodWarehouseOutInfoByIdList(good_id, limit, page, orgId, startTime, endTime, storehouse_id)
  2506. //flushList, _ := service.GetStockFlushByGoodId(good_id, orgId, startTime, endTime)
  2507. //warehouseInfoByList, _ := service.GetGoodWarehouseInfoByList(good_id, orgId, startTime, endTime)
  2508. //cancelStockInfoByList, _ := service.GetGoodCancelStockInfoByList(good_id, orgId, startTime, endTime)
  2509. //warehouseOutByList,_ := service.GetGoodWarehouseOutInfoByIdListTwenty(good_id, limit, page, orgId, startTime, endTime)
  2510. if err != nil {
  2511. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
  2512. return
  2513. }
  2514. this.ServeSuccessJSON(map[string]interface{}{
  2515. "total": total,
  2516. "list": list,
  2517. //"warehouseInfoByList":warehouseInfoByList,
  2518. //"cancelStockInfoByList":cancelStockInfoByList,
  2519. //"warehouseOutByList":warehouseOutByList,
  2520. //"flushList":flushList,
  2521. })
  2522. }
  2523. func (this *SelfDrugApiController) GetGoodPatientList() {
  2524. orgId := this.GetAdminUserInfo().CurrentOrgId
  2525. keyword := this.GetString("keyword")
  2526. list, err := service.GetGoodPatientList(orgId, keyword)
  2527. if err != nil {
  2528. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2529. return
  2530. }
  2531. this.ServeSuccessJSON(map[string]interface{}{
  2532. "list": list,
  2533. })
  2534. }
  2535. func (this *SelfDrugApiController) GetWarehouseOutDetailByPatientId() {
  2536. patient_id, _ := this.GetInt64("patient_id")
  2537. start_time := this.GetString("start_time")
  2538. end_time := this.GetString("end_time")
  2539. limit, _ := this.GetInt64("limit")
  2540. page, _ := this.GetInt64("page")
  2541. orgId := this.GetAdminUserInfo().CurrentOrgId
  2542. timeLayout := "2006-01-02"
  2543. loc, _ := time.LoadLocation("Local")
  2544. var startTime int64
  2545. if len(start_time) > 0 {
  2546. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2547. if err != nil {
  2548. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2549. return
  2550. }
  2551. startTime = theTime.Unix()
  2552. }
  2553. var endTime int64
  2554. if len(end_time) > 0 {
  2555. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2556. if err != nil {
  2557. utils.ErrorLog(err.Error())
  2558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2559. return
  2560. }
  2561. endTime = theTime.Unix()
  2562. }
  2563. list, total, err := service.GetWarehouseOutDetailByPatientIdOne(orgId, patient_id, startTime, endTime, limit, page)
  2564. outlist, _ := service.GetWarehouseOutDetailByPatientId(orgId, patient_id, startTime, endTime)
  2565. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2566. if err != nil {
  2567. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2568. return
  2569. }
  2570. this.ServeSuccessJSON(map[string]interface{}{
  2571. "list": list,
  2572. "manufacturerList": manufacturerList,
  2573. "total": total,
  2574. "outlist": outlist,
  2575. })
  2576. }
  2577. func (this *SelfDrugApiController) GetGoodExpiryDateQuery() {
  2578. storehouse_id, _ := this.GetInt64("storehouse_id")
  2579. expiry_type, _ := this.GetInt64("expiry_type")
  2580. keyword := this.GetString("keyword")
  2581. page, _ := this.GetInt64("page")
  2582. limit, _ := this.GetInt64("limit")
  2583. orgId := this.GetAdminUserInfo().CurrentOrgId
  2584. start_time := this.GetString("start_time")
  2585. timeLayout := "2006-01-02"
  2586. loc, _ := time.LoadLocation("Local")
  2587. var endTime int64
  2588. if len(start_time) > 0 {
  2589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2590. if err != nil {
  2591. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2592. return
  2593. }
  2594. endTime = theTime.Unix()
  2595. }
  2596. recordDateStr := time.Now().Format("2006-01-02")
  2597. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2598. fmt.Scan("parseDateErr", parseDateErr)
  2599. nowtime := recordDate.Unix()
  2600. var ids []int64
  2601. var goodIds []int64
  2602. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2603. for _, it := range manufacturers {
  2604. ids = append(ids, it.ID)
  2605. }
  2606. goodList, _ := service.GetGoodNameByword(orgId, keyword)
  2607. for _, it := range goodList {
  2608. goodIds = append(goodIds, it.ID)
  2609. }
  2610. list, total, err := service.GetGoodExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2611. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2612. if err != nil {
  2613. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2614. return
  2615. }
  2616. this.ServeSuccessJSON(map[string]interface{}{
  2617. "list": list,
  2618. "manufacturerList": manufacturerList,
  2619. "total": total,
  2620. "nowtime": nowtime,
  2621. })
  2622. }
  2623. func (this *SelfDrugApiController) GetGoodPurchaseStockQuery() {
  2624. good_type, _ := this.GetInt64("good_type")
  2625. keyword := this.GetString("keyword")
  2626. page, _ := this.GetInt64("page")
  2627. limit, _ := this.GetInt64("limit")
  2628. start_time := this.GetString("start_time")
  2629. end_time := this.GetString("end_time")
  2630. orgId := this.GetAdminUserInfo().CurrentOrgId
  2631. timeLayout := "2006-01-02"
  2632. loc, _ := time.LoadLocation("Local")
  2633. var startTime int64
  2634. if len(start_time) > 0 {
  2635. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2636. if err != nil {
  2637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2638. return
  2639. }
  2640. startTime = theTime.Unix()
  2641. }
  2642. var endTime int64
  2643. if len(end_time) > 0 {
  2644. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2645. if err != nil {
  2646. utils.ErrorLog(err.Error())
  2647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2648. return
  2649. }
  2650. endTime = theTime.Unix()
  2651. }
  2652. var ids []int64
  2653. var goodIds []int64
  2654. infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  2655. for _, it := range infoList {
  2656. goodIds = append(goodIds, it.GoodId)
  2657. }
  2658. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2659. for _, it := range manufacturers {
  2660. ids = append(ids, it.ID)
  2661. }
  2662. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2663. list, total, err := service.GetGoodPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
  2664. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2665. for _, item := range list {
  2666. //获取期初结余数量
  2667. infoList, _ := service.GetStartGoodWarehouseInfoList(item.ID, orgId, startTime)
  2668. for _, it := range infoList {
  2669. item.WarehousingInfoStart = append(item.WarehousingInfoStart, it)
  2670. }
  2671. //获取期末结余数量
  2672. warehouseInfoList, _ := service.GetEndGoodWarehouseInfoList(item.ID, orgId, endTime)
  2673. for _, it := range warehouseInfoList {
  2674. item.WarehousingInfoEnd = append(item.WarehousingInfoEnd, it)
  2675. }
  2676. //获取期间增加
  2677. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2678. for _, it := range goodWarehouseInfoList {
  2679. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  2680. }
  2681. //获取本期增加
  2682. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2683. for _, it := range WarehouseInfoFlowList {
  2684. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  2685. }
  2686. //获取本期减少
  2687. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2688. for _, it := range reduceWarehouseInfoList {
  2689. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  2690. }
  2691. //获取期中减少退库
  2692. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2693. for _, it := range lowInfo {
  2694. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  2695. }
  2696. //
  2697. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  2698. for _, it := range outInfo {
  2699. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  2700. }
  2701. //获取期初结余
  2702. info, _ := service.FindeStartFlowInfo(item.ID, orgId, startTime)
  2703. for _, it := range info {
  2704. item.StartFlowInfo = append(item.StartFlowInfo, it)
  2705. }
  2706. //获取期初结余
  2707. flowOutInfo, _ := service.FindeStartFlowOutInfo(item.ID, orgId, startTime)
  2708. for _, it := range flowOutInfo {
  2709. item.StartOutFlowInfo = append(item.StartOutFlowInfo, it)
  2710. }
  2711. //获取期初退库
  2712. cancelInfo, _ := service.FindeStartCancelInfo(item.ID, orgId, startTime)
  2713. for _, it := range cancelInfo {
  2714. item.StartCancelFlowInfo = append(item.StartCancelFlowInfo, it)
  2715. }
  2716. //获取期末结余
  2717. flowInfo, _ := service.FindEndStartFlowInfo(item.ID, orgId, endTime)
  2718. for _, it := range flowInfo {
  2719. item.EndFlowInfo = append(item.EndFlowInfo, it)
  2720. }
  2721. //获取期末出库
  2722. lowOutInfo, _ := service.FindeEndFLowOutInfo(item.ID, orgId, endTime)
  2723. for _, it := range lowOutInfo {
  2724. item.EndFlowOutInfo = append(item.EndFlowOutInfo, it)
  2725. }
  2726. //获取期末退库
  2727. endCancelInfo, _ := service.FindEndCancelInfo(item.ID, orgId, endTime)
  2728. for _, it := range endCancelInfo {
  2729. item.EndCancelFLowInfo = append(item.EndCancelFLowInfo, it)
  2730. }
  2731. //期初盘赢
  2732. inventory, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, startTime)
  2733. for _, it := range inventory {
  2734. item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  2735. }
  2736. //期初盘亏
  2737. stockInventory, _ := service.FindStartStockInventoryLosses(item.ID, orgId, startTime)
  2738. for _, it := range stockInventory {
  2739. item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  2740. }
  2741. //期末盘盈
  2742. inventoryProfit, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, endTime)
  2743. for _, it := range inventoryProfit {
  2744. item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  2745. }
  2746. //期末盘亏
  2747. inventoryLosses, _ := service.FindStartStockInventoryLosses(item.ID, orgId, endTime)
  2748. for _, it := range inventoryLosses {
  2749. item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  2750. }
  2751. //期中盘盈
  2752. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2753. for _, it := range profit {
  2754. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  2755. }
  2756. //期中盘亏
  2757. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  2758. for _, it := range losses {
  2759. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  2760. }
  2761. }
  2762. if err != nil {
  2763. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2764. return
  2765. }
  2766. this.ServeSuccessJSON(map[string]interface{}{
  2767. "list": list,
  2768. "manufacturerList": manufacturerList,
  2769. "total": total,
  2770. })
  2771. }
  2772. func (this *SelfDrugApiController) GetDrugWarehouseOutDetailByPatientId() {
  2773. patient_id, _ := this.GetInt64("patient_id")
  2774. start_time := this.GetString("start_time")
  2775. end_time := this.GetString("end_time")
  2776. orgId := this.GetAdminUserInfo().CurrentOrgId
  2777. limit, _ := this.GetInt64("limit")
  2778. page, _ := this.GetInt64("page")
  2779. timeLayout := "2006-01-02"
  2780. loc, _ := time.LoadLocation("Local")
  2781. var startTime int64
  2782. if len(start_time) > 0 {
  2783. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2784. if err != nil {
  2785. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2786. return
  2787. }
  2788. startTime = theTime.Unix()
  2789. }
  2790. var endTime int64
  2791. if len(end_time) > 0 {
  2792. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2793. if err != nil {
  2794. utils.ErrorLog(err.Error())
  2795. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2796. return
  2797. }
  2798. endTime = theTime.Unix()
  2799. }
  2800. list, total, _ := service.GetDrugWarehouseOutDetailByPatientIdOne(patient_id, orgId, startTime, endTime, page, limit)
  2801. outlist, _ := service.GetDrugWarehouseOutDetailByPatientId(patient_id, orgId, startTime, endTime)
  2802. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2803. this.ServeSuccessJSON(map[string]interface{}{
  2804. "list": list,
  2805. "total": total,
  2806. "manufacturerList": manufacturerList,
  2807. "outlist": outlist,
  2808. })
  2809. }
  2810. func (this *SelfDrugApiController) GetDrugExpiryDateQuery() {
  2811. storehouse_id, _ := this.GetInt64("storehouse_id")
  2812. expiry_type, _ := this.GetInt64("expiry_type")
  2813. keyword := this.GetString("keyword")
  2814. page, _ := this.GetInt64("page")
  2815. limit, _ := this.GetInt64("limit")
  2816. orgId := this.GetAdminUserInfo().CurrentOrgId
  2817. start_time := this.GetString("start_time")
  2818. timeLayout := "2006-01-02"
  2819. loc, _ := time.LoadLocation("Local")
  2820. var endTime int64
  2821. if len(start_time) > 0 {
  2822. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2823. if err != nil {
  2824. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2825. return
  2826. }
  2827. endTime = theTime.Unix()
  2828. }
  2829. recordDateStr := time.Now().Format("2006-01-02")
  2830. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2831. fmt.Scan("parseDateErr", parseDateErr)
  2832. nowtime := recordDate.Unix()
  2833. var ids []int64
  2834. var goodIds []int64
  2835. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2836. for _, it := range manufacturers {
  2837. ids = append(ids, it.ID)
  2838. }
  2839. drugList, _ := service.GetDrugNameByword(orgId, keyword)
  2840. for _, it := range drugList {
  2841. goodIds = append(goodIds, it.ID)
  2842. }
  2843. list, total, err := service.GetDrugExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
  2844. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2845. var drugType = "药品类型"
  2846. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2847. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  2848. if err != nil {
  2849. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2850. return
  2851. }
  2852. this.ServeSuccessJSON(map[string]interface{}{
  2853. "list": list,
  2854. "manufacturerList": manufacturerList,
  2855. "total": total,
  2856. "nowtime": nowtime,
  2857. "drugTypeList": drugTypeList,
  2858. })
  2859. }
  2860. func (this *SelfDrugApiController) GetPurchaseDrugQuery() {
  2861. good_type, _ := this.GetInt64("good_type")
  2862. keyword := this.GetString("keyword")
  2863. page, _ := this.GetInt64("page")
  2864. limit, _ := this.GetInt64("limit")
  2865. start_time := this.GetString("start_time")
  2866. end_time := this.GetString("end_time")
  2867. orgId := this.GetAdminUserInfo().CurrentOrgId
  2868. timeLayout := "2006-01-02"
  2869. loc, _ := time.LoadLocation("Local")
  2870. var startTime int64
  2871. if len(start_time) > 0 {
  2872. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2873. if err != nil {
  2874. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2875. return
  2876. }
  2877. startTime = theTime.Unix()
  2878. }
  2879. var endTime int64
  2880. if len(end_time) > 0 {
  2881. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2882. if err != nil {
  2883. utils.ErrorLog(err.Error())
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2885. return
  2886. }
  2887. endTime = theTime.Unix()
  2888. }
  2889. var ids []int64
  2890. var infoIds []int64
  2891. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  2892. for _, it := range manufacturers {
  2893. ids = append(ids, it.ID)
  2894. }
  2895. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  2896. for _, it := range infoList {
  2897. infoIds = append(infoIds, it.DrugId)
  2898. }
  2899. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  2900. list, total, err := service.GetDrugPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  2901. for _, item := range list {
  2902. //获取期初结余入库数量
  2903. startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
  2904. for _, it := range startDrugInfo {
  2905. item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
  2906. }
  2907. //获取期初结余出库数量
  2908. flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
  2909. for _, it := range flowOutList {
  2910. item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
  2911. }
  2912. //获取期初结余退库数量
  2913. cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
  2914. for _, it := range cancelInfo {
  2915. item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
  2916. }
  2917. //获取期末结余入库数量
  2918. drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
  2919. for _, it := range drugwarehouseinfoend {
  2920. item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
  2921. }
  2922. //获取期末出库结余
  2923. endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
  2924. for _, it := range endDrugInfo {
  2925. item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
  2926. }
  2927. //获取期末退库数量
  2928. flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
  2929. for _, it := range flowCancelInfo {
  2930. item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
  2931. }
  2932. //期中增加
  2933. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  2934. for _, it := range drugWarehouse {
  2935. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  2936. }
  2937. //期中减少
  2938. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  2939. for _, it := range outInfo {
  2940. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  2941. }
  2942. //期中退库
  2943. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  2944. for _, it := range cancelstartInfo {
  2945. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  2946. }
  2947. //获取期初盘盈
  2948. startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
  2949. for _, it := range startProfit {
  2950. item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
  2951. }
  2952. //获取期初盘亏
  2953. startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
  2954. for _, it := range startLosses {
  2955. item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
  2956. }
  2957. //获取期末盘盈
  2958. endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
  2959. for _, it := range endProfit {
  2960. item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
  2961. }
  2962. //获取期末盘亏
  2963. losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
  2964. for _, it := range losses {
  2965. item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
  2966. }
  2967. //获取期中盘盈
  2968. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  2969. for _, it := range profit {
  2970. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  2971. }
  2972. //获取期中盘亏
  2973. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  2974. for _, it := range endLosses {
  2975. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  2976. }
  2977. }
  2978. if err != nil {
  2979. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  2980. return
  2981. }
  2982. var drugType = "药品类型"
  2983. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2984. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  2985. this.ServeSuccessJSON(map[string]interface{}{
  2986. "list": list,
  2987. "manufacturerList": manufacturerList,
  2988. "total": total,
  2989. "drugTypeList": drugTypeList,
  2990. })
  2991. }
  2992. func (this *SelfDrugApiController) GetDrugNewQuery() {
  2993. orgId := this.GetAdminUserInfo().CurrentOrgId
  2994. storehouse_id, _ := this.GetInt64("storehouse_id")
  2995. good_type, _ := this.GetInt64("good_type")
  2996. keyword := this.GetString("keyword")
  2997. page, _ := this.GetInt64("page")
  2998. limit, _ := this.GetInt64("limit")
  2999. start_time := this.GetString("start_time")
  3000. end_time := this.GetString("end_time")
  3001. timeLayout := "2006-01-02"
  3002. loc, _ := time.LoadLocation("Local")
  3003. var startTime int64
  3004. if len(start_time) > 0 {
  3005. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3006. if err != nil {
  3007. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3008. return
  3009. }
  3010. startTime = theTime.Unix()
  3011. }
  3012. var endTime int64
  3013. if len(end_time) > 0 {
  3014. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3015. if err != nil {
  3016. utils.ErrorLog(err.Error())
  3017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3018. return
  3019. }
  3020. endTime = theTime.Unix()
  3021. }
  3022. var ids []int64
  3023. var goodIds []int64
  3024. if len(keyword) > 0 {
  3025. manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3026. for _, it := range manufacturerList {
  3027. ids = append(ids, it.ID)
  3028. }
  3029. }
  3030. //查询药品库信息
  3031. //drug, _ := service.GetBaseDrugName(orgId)
  3032. //
  3033. //for _, it := range drug {
  3034. // var sum_count int64
  3035. // var limit_count int64
  3036. // drugInfo, _ := service.GetDrugWarehouseInfoName(it.ID, orgId)
  3037. // for _, item := range drugInfo {
  3038. //
  3039. // sum_count += item.StockMaxNumber*it.MinNumber + item.StockMinNumber
  3040. // }
  3041. // stockInt, _ := strconv.ParseInt(it.DrugStockLimit, 10, 64)
  3042. // limit_count = stockInt * it.MinNumber
  3043. // service.UpdateDrugById(it.ID, orgId, limit_count, sum_count)
  3044. //}
  3045. if storehouse_id > 0 {
  3046. infoList, _ := service.GetDrugWarehouseInfoByOrgId(orgId, storehouse_id)
  3047. for _, it := range infoList {
  3048. goodIds = append(goodIds, it.DrugId)
  3049. }
  3050. }
  3051. countList, total, err := service.GetDrugStockCountList(orgId, storehouse_id, good_type, keyword, page, limit, ids, goodIds, startTime, endTime)
  3052. if err != nil {
  3053. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
  3054. return
  3055. }
  3056. var drugType = "药品类型"
  3057. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3058. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3059. this.ServeSuccessJSON(map[string]interface{}{
  3060. "total": total,
  3061. "drugTypeList": drugTypeList,
  3062. "countList": countList,
  3063. })
  3064. }
  3065. func (this *SelfDrugApiController) GetDrugWarehouseInfoById() {
  3066. drug_id, _ := this.GetInt64("drug_id")
  3067. limit, _ := this.GetInt64("limit")
  3068. page, _ := this.GetInt64("page")
  3069. start_time := this.GetString("start_first_time")
  3070. end_time := this.GetString("end_first_time")
  3071. storehouse_id, _ := this.GetInt64("storehouse_id")
  3072. orgId := this.GetAdminUserInfo().CurrentOrgId
  3073. timeLayout := "2006-01-02"
  3074. loc, _ := time.LoadLocation("Local")
  3075. var startTime int64
  3076. if len(start_time) > 0 {
  3077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3078. if err != nil {
  3079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3080. return
  3081. }
  3082. startTime = theTime.Unix()
  3083. }
  3084. var endTime int64
  3085. if len(end_time) > 0 {
  3086. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3087. if err != nil {
  3088. utils.ErrorLog(err.Error())
  3089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3090. return
  3091. }
  3092. endTime = theTime.Unix()
  3093. }
  3094. list, total, err := service.GetDrugWarehouseOutInfoByIdList(drug_id, limit, page, orgId, startTime, endTime, storehouse_id)
  3095. flushList, _ := service.GetDrugFlowFlush(drug_id, orgId, startTime, endTime)
  3096. flushOne, _ := service.GetDrugFlowFlushOne(drug_id, orgId, startTime, endTime)
  3097. if err != nil {
  3098. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
  3099. return
  3100. }
  3101. this.ServeSuccessJSON(map[string]interface{}{
  3102. "total": total,
  3103. "list": list,
  3104. "flushList": flushList,
  3105. "flushListOne": flushOne,
  3106. })
  3107. }
  3108. func (this *SelfDrugApiController) GetSendGoodInformation() {
  3109. orgId := this.GetAdminUserInfo().CurrentOrgId
  3110. fmt.Println("orgid", orgId)
  3111. list, _ := service.GetWarehouseOutInfo(10485)
  3112. for _, it := range list {
  3113. service.UpdateWarehosueOutInfo(it.ID, it.WarehouseOutTime)
  3114. }
  3115. //获取入库数据
  3116. //list, _ := service.GetSendGoodInformation(10265)
  3117. //
  3118. ////project, _ := service.GetHisPrescriptionList(10265)
  3119. //
  3120. //for _, it := range list {
  3121. // service.UpdateGoodFlow(it.ID, it.PackingPrice)
  3122. //}
  3123. //for _, it := range list {
  3124. // //查询是否有数据
  3125. // _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
  3126. // //获取总退库数量
  3127. // var cancel_count int64
  3128. // var out_count int64
  3129. // var act_count int64
  3130. // //退库总数量
  3131. // cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
  3132. // for _, item := range cancellist {
  3133. // cancel_count += item.Count
  3134. // }
  3135. // //出库总数量
  3136. // outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  3137. // for _, item := range outlist {
  3138. // out_count += item.Count
  3139. // }
  3140. //
  3141. // //实际出库总数量
  3142. // actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  3143. // for _, item := range actlist {
  3144. // act_count += item.Count
  3145. // }
  3146. //
  3147. // if errcode == gorm.ErrRecordNotFound {
  3148. // good := models.XtGoodStockCount{
  3149. // UserOrgId: it.OrgId,
  3150. // GoodId: it.GoodId,
  3151. // StorehouseId: it.StorehouseId,
  3152. // Status: 1,
  3153. // Ctime: time.Now().Unix(),
  3154. // Mtime: 0,
  3155. // StockInCount: it.WarehousingCount,
  3156. // StockOutCount: out_count - cancel_count,
  3157. // StockCancelCount: cancel_count,
  3158. // FlushCount: it.StockCount,
  3159. // StockActOutCount: act_count,
  3160. // }
  3161. // service.CreateGoodCountSix(good)
  3162. // }
  3163. // if errcode == nil {
  3164. // service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
  3165. // }
  3166. //}
  3167. this.ServeSuccessJSON(map[string]interface{}{
  3168. "msg": "1",
  3169. })
  3170. }
  3171. func (this *SelfDrugApiController) GetDrugInitDetailList() {
  3172. orgId := this.GetAdminUserInfo().CurrentOrgId
  3173. //获取所有的入库仓库
  3174. list, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
  3175. for _, item := range list {
  3176. //查询该药品该仓库是否有数据
  3177. drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
  3178. //查询该仓库该药品的入库数量
  3179. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  3180. var sum_in_count int64
  3181. var flush_count int64
  3182. var sum_out_count int64
  3183. var cancel_out_count int64
  3184. //查询入库数量和剩余库存
  3185. infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
  3186. for _, it := range infolist {
  3187. if it.MaxUnit == medical.MaxUnit {
  3188. it.WarehousingCount = it.WarehousingCount * medical.MinNumber
  3189. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  3190. }
  3191. sum_in_count += it.WarehousingCount
  3192. flush_count += it.StockMaxNumber + it.StockMinNumber
  3193. }
  3194. //获取出库数量
  3195. outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
  3196. for _, it := range outinfolist {
  3197. if it.MaxUnit == medical.MaxUnit {
  3198. it.Count = it.Count * medical.MinNumber
  3199. }
  3200. sum_out_count += it.Count
  3201. }
  3202. //获取退库数量
  3203. cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
  3204. for _, it := range cancelinfolist {
  3205. if it.MaxUnit == medical.MaxUnit {
  3206. it.Count = it.Count * medical.MinNumber
  3207. }
  3208. cancel_out_count += it.Count
  3209. }
  3210. //新增
  3211. if drug.ID == 0 {
  3212. drugstock := models.XtDrugStockCount{
  3213. UserOrgId: orgId,
  3214. StorehouseId: item.StorehouseId,
  3215. SumInCount: sum_in_count,
  3216. SumOutCount: sum_out_count - cancel_out_count,
  3217. SumCancelCount: cancel_out_count,
  3218. DrugId: item.DrugId,
  3219. Ctime: time.Now().Unix(),
  3220. Mtime: 0,
  3221. Status: 1,
  3222. FlushCount: flush_count,
  3223. SumActOutCount: sum_out_count,
  3224. }
  3225. service.CreateDrugStockCount(drugstock)
  3226. }
  3227. }
  3228. this.ServeSuccessJSON(map[string]interface{}{
  3229. "msg": "1",
  3230. })
  3231. }
  3232. func (this *SelfDrugApiController) GetGoodNewPurchaseStockQuery() {
  3233. good_type, _ := this.GetInt64("good_type")
  3234. keyword := this.GetString("keyword")
  3235. page, _ := this.GetInt64("page")
  3236. limit, _ := this.GetInt64("limit")
  3237. start_time := this.GetString("start_time")
  3238. end_time := this.GetString("end_time")
  3239. orgId := this.GetAdminUserInfo().CurrentOrgId
  3240. timeLayout := "2006-01-02"
  3241. loc, _ := time.LoadLocation("Local")
  3242. var startTime int64
  3243. if len(start_time) > 0 {
  3244. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3245. if err != nil {
  3246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3247. return
  3248. }
  3249. startTime = theTime.Unix()
  3250. }
  3251. var endTime int64
  3252. if len(end_time) > 0 {
  3253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3254. if err != nil {
  3255. utils.ErrorLog(err.Error())
  3256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3257. return
  3258. }
  3259. endTime = theTime.Unix()
  3260. }
  3261. var ids []int64
  3262. var goodIds []int64
  3263. //infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  3264. //for _, it := range infoList {
  3265. // goodIds = append(goodIds, it.GoodId)
  3266. //}
  3267. if len(keyword) > 0 {
  3268. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3269. for _, it := range manufacturers {
  3270. ids = append(ids, it.ID)
  3271. }
  3272. }
  3273. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  3274. if orgId == 10265 {
  3275. //storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3276. list, total, err := service.GetGoodNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
  3277. for _, item := range list {
  3278. //获取期初结余
  3279. low, _ := service.GetStartLastFLowTwenty(item.ID, orgId, startTime)
  3280. item.GoodStartFlowInfo = low
  3281. //获取期末结余
  3282. flow, _ := service.GetEndLastFlowTwenty(item.ID, orgId, endTime)
  3283. item.GoodEndFlowInfo = flow
  3284. //获取期间增加
  3285. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
  3286. for _, it := range goodWarehouseInfoList {
  3287. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3288. }
  3289. //获取本期增加
  3290. WarehouseInfoFlowList, _ := service.GetAddStartFlowTwenty(item.ID, orgId, startTime, endTime)
  3291. for _, it := range WarehouseInfoFlowList {
  3292. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3293. }
  3294. //获取本期减少
  3295. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoListTwenty(item.ID, orgId, startTime, endTime)
  3296. for _, it := range reduceWarehouseInfoList {
  3297. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3298. }
  3299. //获取期中减少退库
  3300. lowInfo, _ := service.GetStartEndCancelFLowInfoTwenty(item.ID, orgId, startTime, endTime)
  3301. for _, it := range lowInfo {
  3302. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3303. }
  3304. //
  3305. outInfo, _ := service.FindeWarehouseOutInfoTwenty(item.ID, orgId, startTime)
  3306. for _, it := range outInfo {
  3307. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3308. }
  3309. //期中盘盈
  3310. profit, _ := service.FindeEndStokInventoryProfitTwenty(item.ID, orgId, startTime, endTime)
  3311. for _, it := range profit {
  3312. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3313. }
  3314. //期中盘亏
  3315. losses, _ := service.FindeEndStockInventoryLossesTwenty(item.ID, orgId, startTime, endTime)
  3316. for _, it := range losses {
  3317. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3318. }
  3319. }
  3320. if err != nil {
  3321. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3322. return
  3323. }
  3324. this.ServeSuccessJSON(map[string]interface{}{
  3325. "list": list,
  3326. "manufacturerList": manufacturerList,
  3327. "total": total,
  3328. })
  3329. }
  3330. if orgId != 10265 {
  3331. list, total, err := service.GetGoodNewPurchaseStockQueryOne(good_type, keyword, page, limit, orgId, ids, goodIds)
  3332. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3333. for _, item := range list {
  3334. //获取期初结余
  3335. low, _ := service.GetStartLastFLow(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3336. item.GoodStartFlowInfo = low
  3337. //获取期末结余
  3338. flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime, storeConfig.StorehouseOutInfo)
  3339. item.GoodEndFlowInfo = flow
  3340. //获取期间增加
  3341. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3342. for _, it := range goodWarehouseInfoList {
  3343. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3344. }
  3345. //获取本期增加
  3346. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3347. for _, it := range WarehouseInfoFlowList {
  3348. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3349. }
  3350. //获取本期减少
  3351. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3352. for _, it := range reduceWarehouseInfoList {
  3353. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3354. }
  3355. //获取期中减少退库
  3356. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3357. for _, it := range lowInfo {
  3358. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3359. }
  3360. //
  3361. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3362. for _, it := range outInfo {
  3363. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3364. }
  3365. //期中盘盈
  3366. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3367. for _, it := range profit {
  3368. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3369. }
  3370. //期中盘亏
  3371. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3372. for _, it := range losses {
  3373. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3374. }
  3375. //获取期初结余
  3376. balanceList, _ := service.GetInitBalanceList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3377. for _, it := range balanceList {
  3378. item.StWarehousingInfoTwo = append(item.StWarehousingInfoTwo, it)
  3379. }
  3380. //期间减少
  3381. banceOutList, _ := service.GetInitOutBanceList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3382. for _, it := range banceOutList {
  3383. item.WarehouseOutInfoTenty = append(item.WarehouseOutInfoTenty, it)
  3384. }
  3385. //期间盘盈
  3386. infoFlow, _ := service.GetInitInfoFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3387. for _, it := range infoFlow {
  3388. item.WareStartInStockFlow = append(item.WareStartInStockFlow, it)
  3389. }
  3390. //期间盘亏
  3391. outInfoFlow, _ := service.GetInitOutInfoFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3392. for _, it := range outInfoFlow {
  3393. item.WareStartOutStockFlow = append(item.WareStartOutStockFlow, it)
  3394. }
  3395. }
  3396. if err != nil {
  3397. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3398. return
  3399. }
  3400. this.ServeSuccessJSON(map[string]interface{}{
  3401. "list": list,
  3402. "manufacturerList": manufacturerList,
  3403. "total": total,
  3404. })
  3405. }
  3406. }
  3407. func (this *SelfDrugApiController) GetPurchaseNewDrugQuery() {
  3408. good_type, _ := this.GetInt64("good_type")
  3409. keyword := this.GetString("keyword")
  3410. page, _ := this.GetInt64("page")
  3411. limit, _ := this.GetInt64("limit")
  3412. start_time := this.GetString("start_time")
  3413. end_time := this.GetString("end_time")
  3414. orgId := this.GetAdminUserInfo().CurrentOrgId
  3415. timeLayout := "2006-01-02"
  3416. loc, _ := time.LoadLocation("Local")
  3417. var startTime int64
  3418. if len(start_time) > 0 {
  3419. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3420. if err != nil {
  3421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3422. return
  3423. }
  3424. startTime = theTime.Unix()
  3425. }
  3426. var endTime int64
  3427. if len(end_time) > 0 {
  3428. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3429. if err != nil {
  3430. utils.ErrorLog(err.Error())
  3431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3432. return
  3433. }
  3434. endTime = theTime.Unix()
  3435. }
  3436. var ids []int64
  3437. var infoIds []int64
  3438. if len(keyword) > 0 {
  3439. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3440. for _, it := range manufacturers {
  3441. ids = append(ids, it.ID)
  3442. }
  3443. }
  3444. //infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  3445. //for _, it := range infoList {
  3446. // infoIds = append(infoIds, it.DrugId)
  3447. //}
  3448. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3449. list, total, err := service.GetDrugNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  3450. for _, item := range list {
  3451. //获取期初结余
  3452. flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
  3453. item.DrugStatFlow = flow
  3454. //获取期末结余
  3455. endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
  3456. item.DrugEndFlow = endFlow
  3457. //期中增加
  3458. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  3459. for _, it := range drugWarehouse {
  3460. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  3461. }
  3462. //期中减少
  3463. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3464. for _, it := range outInfo {
  3465. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  3466. }
  3467. //期中退库
  3468. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3469. for _, it := range cancelstartInfo {
  3470. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  3471. }
  3472. //获取期中盘盈
  3473. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  3474. for _, it := range profit {
  3475. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3476. }
  3477. //获取期中盘亏
  3478. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  3479. for _, it := range endLosses {
  3480. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3481. }
  3482. if orgId != 10215 && orgId != 10265 {
  3483. //获取入库
  3484. infoFLow, _ := service.GetNewDrugFlowInWarehouseInfo(item.ID, orgId, startTime)
  3485. for _, it := range infoFLow {
  3486. item.NewDrugFlowInWarehouseInfo = append(item.NewDrugFlowInWarehouseInfo, it)
  3487. }
  3488. //获取盘盈
  3489. infoProfitFlow, _ := service.GetNewDrugFlowPofitWarehouseInfo(item.ID, orgId, startTime)
  3490. for _, it := range infoProfitFlow {
  3491. item.NewDrugFlowPofitWarehouseInfo = append(item.NewDrugFlowPofitWarehouseInfo, it)
  3492. }
  3493. //获取出库
  3494. infoOutFlow, _ := service.GetNewDrugFlowOutWarehouseInfo(item.ID, orgId, startTime)
  3495. for _, it := range infoOutFlow {
  3496. item.NewDrugFlowOutWarehouseInfo = append(item.NewDrugFlowOutWarehouseInfo, it)
  3497. }
  3498. //获取退库
  3499. infoCacelFlow, _ := service.GetNewDrugFlowCacelWarehouseInfo(item.ID, orgId, startTime)
  3500. for _, it := range infoCacelFlow {
  3501. item.NewDrugFlowNoCancelWarehouseInfo = append(item.NewDrugFlowNoCancelWarehouseInfo, it)
  3502. }
  3503. //获取盘亏
  3504. infoNoPofitFlow, _ := service.GetNewDrugFlowNoPofitWarehouseInfo(item.ID, orgId, startTime)
  3505. for _, it := range infoNoPofitFlow {
  3506. item.NewDrugFlowNoPofitWarehouseInfo = append(item.NewDrugFlowNoPofitWarehouseInfo, it)
  3507. }
  3508. }
  3509. }
  3510. if err != nil {
  3511. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3512. return
  3513. }
  3514. var drugType = "药品类型"
  3515. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3516. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3517. this.ServeSuccessJSON(map[string]interface{}{
  3518. "list": list,
  3519. "manufacturerList": manufacturerList,
  3520. "total": total,
  3521. "drugTypeList": drugTypeList,
  3522. })
  3523. }
  3524. func (this *SelfDrugApiController) GetGoodOverCount() {
  3525. orgId := this.GetAdminUserInfo().CurrentOrgId
  3526. list, _ := service.GetAllStockCount(orgId)
  3527. for _, item := range list {
  3528. flow, _ := service.GetLastStockFlow(item.GoodId)
  3529. service.ModifyStockFlowById(flow.ID, item.FlushCount)
  3530. }
  3531. returnData := make(map[string]interface{}, 0)
  3532. returnData["msg"] = "ok"
  3533. this.ServeSuccessJSON(returnData)
  3534. return
  3535. }
  3536. func (this *SelfDrugApiController) GetDrugOverCount() {
  3537. orgId := this.GetAdminUserInfo().CurrentOrgId
  3538. list, _ := service.GetAllDrugCount(orgId)
  3539. for _, item := range list {
  3540. service.GetLastDrugFlow(item.DrugId)
  3541. service.ModifyDrugFlowById(item.ID, item.FlushCount)
  3542. }
  3543. returnData := make(map[string]interface{}, 0)
  3544. returnData["msg"] = "ok"
  3545. this.ServeSuccessJSON(returnData)
  3546. return
  3547. }
  3548. func (this *SelfDrugApiController) GetDrugInventoryWarehouseInfoList() {
  3549. storehouse_id, _ := this.GetInt64("storehouse_id")
  3550. orgId := this.GetAdminUserInfo().CurrentOrgId
  3551. list, _ := service.GetDrugInventoryWarehouseInfoList(orgId, storehouse_id)
  3552. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3553. dealerList, _ := service.GetAllDealerList(orgId)
  3554. this.ServeSuccessJSON(map[string]interface{}{
  3555. "list": list,
  3556. "manufacturerList": manufacturerList,
  3557. "dealerList": dealerList,
  3558. })
  3559. }
  3560. func (this *SelfDrugApiController) GetInventoryDetailPrintList() {
  3561. keyword := this.GetString("keyword")
  3562. limit, _ := this.GetInt64("limit")
  3563. page, _ := this.GetInt64("page")
  3564. storehouse_id, _ := this.GetInt64("storehouse_id")
  3565. ids := this.GetString("ids")
  3566. idSplit := strings.Split(ids, ",")
  3567. orgId := this.GetAdminUserInfo().CurrentOrgId
  3568. list, total, err := service.GetDrugInventoryDetailMapList(keyword, page, limit, orgId, storehouse_id, idSplit)
  3569. inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
  3570. houseList, _ := service.GetAllStoreHouseList(orgId)
  3571. doctorList, _ := service.GetAllDoctorThree(orgId)
  3572. if err != nil {
  3573. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  3574. return
  3575. }
  3576. this.ServeSuccessJSON(map[string]interface{}{
  3577. "total": total,
  3578. "list": list,
  3579. "doctorList": doctorList,
  3580. "houseList": houseList,
  3581. "inventoryList": inventoryList,
  3582. })
  3583. }
  3584. func (this *SelfDrugApiController) GetDrugFlowDetailById() {
  3585. drug_id, _ := this.GetInt64("drug_id")
  3586. orgId := this.GetAdminUserInfo().CurrentOrgId
  3587. list, _ := service.GetDrugFlowDetailById(drug_id, orgId)
  3588. drugMedical, _ := service.GetBaseDrugMedical(drug_id)
  3589. for index, _ := range list {
  3590. if list[index].ConsumableType == 3 || list[index].ConsumableType == 2 || list[index].ConsumableType == 11 || list[index].ConsumableType == 12 || list[index].ConsumableType == 15 {
  3591. var count int64
  3592. if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
  3593. list[index].Count = list[index].Count * drugMedical.MinNumber
  3594. }
  3595. if index == 0 {
  3596. count = list[index].FlushOverCount - list[index].Count
  3597. service.UpdateDrugOverCount(list[index+1].ID, count)
  3598. }
  3599. if index >= 1 {
  3600. lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
  3601. count = lastStockFlow.FlushOverCount - list[index].Count
  3602. service.UpdateDrugOverCount(list[index].ID, count)
  3603. }
  3604. }
  3605. if list[index].ConsumableType == 7 || list[index].ConsumableType == 4 || list[index].ConsumableType == 1 || list[index].ConsumableType == 10 || list[index].ConsumableType == 13 {
  3606. if list[index].MaxUnit == drugMedical.MaxUnit && list[index].MaxUnit != list[index].MinUnit {
  3607. list[index].Count = list[index].Count * drugMedical.MinNumber
  3608. }
  3609. if index == 0 {
  3610. var count int64
  3611. count = list[index].FlushOverCount + list[index].Count
  3612. service.UpdateDrugOverCount(list[index+1].ID, count)
  3613. }
  3614. if index >= 1 {
  3615. var count int64
  3616. lastStockFlow, _ := service.GetLastDrugOverCount(list[index-1].ID)
  3617. count = lastStockFlow.FlushOverCount + list[index].Count
  3618. service.UpdateDrugOverCount(list[index].ID, count)
  3619. }
  3620. }
  3621. }
  3622. }
  3623. func (this *SelfDrugApiController) GetPurchaseDrugQueryList() {
  3624. good_type, _ := this.GetInt64("good_type")
  3625. keyword := this.GetString("keyword")
  3626. page, _ := this.GetInt64("page")
  3627. limit, _ := this.GetInt64("limit")
  3628. start_time := this.GetString("start_time")
  3629. end_time := this.GetString("end_time")
  3630. orgId := this.GetAdminUserInfo().CurrentOrgId
  3631. timeLayout := "2006-01-02"
  3632. loc, _ := time.LoadLocation("Local")
  3633. var startTime int64
  3634. if len(start_time) > 0 {
  3635. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3636. if err != nil {
  3637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3638. return
  3639. }
  3640. startTime = theTime.Unix()
  3641. }
  3642. var endTime int64
  3643. if len(end_time) > 0 {
  3644. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3645. if err != nil {
  3646. utils.ErrorLog(err.Error())
  3647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3648. return
  3649. }
  3650. endTime = theTime.Unix()
  3651. }
  3652. var ids []int64
  3653. var infoIds []int64
  3654. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3655. for _, it := range manufacturers {
  3656. ids = append(ids, it.ID)
  3657. }
  3658. infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
  3659. for _, it := range infoList {
  3660. infoIds = append(infoIds, it.DrugId)
  3661. }
  3662. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3663. list, total, err := service.GetDrugNewPurchaseStockQueryList(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
  3664. for _, item := range list {
  3665. //获取期初结余
  3666. flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
  3667. item.DrugStatFlow = flow
  3668. //获取期末结余
  3669. endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
  3670. item.DrugEndFlow = endFlow
  3671. //获取期初结余入库数量
  3672. //期中增加
  3673. drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
  3674. for _, it := range drugWarehouse {
  3675. item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
  3676. }
  3677. //期中减少
  3678. outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3679. for _, it := range outInfo {
  3680. item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
  3681. }
  3682. //期中退库
  3683. cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
  3684. for _, it := range cancelstartInfo {
  3685. item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
  3686. }
  3687. //获取期中盘盈
  3688. profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
  3689. for _, it := range profit {
  3690. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3691. }
  3692. //获取期中盘亏
  3693. endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
  3694. for _, it := range endLosses {
  3695. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3696. }
  3697. }
  3698. if err != nil {
  3699. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3700. return
  3701. }
  3702. var drugType = "药品类型"
  3703. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3704. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3705. this.ServeSuccessJSON(map[string]interface{}{
  3706. "list": list,
  3707. "manufacturerList": manufacturerList,
  3708. "total": total,
  3709. "drugTypeList": drugTypeList,
  3710. })
  3711. }
  3712. func (this *SelfDrugApiController) GetPurchaseStockQueryList() {
  3713. good_type, _ := this.GetInt64("good_type")
  3714. keyword := this.GetString("keyword")
  3715. page, _ := this.GetInt64("page")
  3716. limit, _ := this.GetInt64("limit")
  3717. start_time := this.GetString("start_time")
  3718. end_time := this.GetString("end_time")
  3719. orgId := this.GetAdminUserInfo().CurrentOrgId
  3720. timeLayout := "2006-01-02"
  3721. loc, _ := time.LoadLocation("Local")
  3722. var startTime int64
  3723. if len(start_time) > 0 {
  3724. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3725. if err != nil {
  3726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3727. return
  3728. }
  3729. startTime = theTime.Unix()
  3730. }
  3731. var endTime int64
  3732. if len(end_time) > 0 {
  3733. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3734. if err != nil {
  3735. utils.ErrorLog(err.Error())
  3736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3737. return
  3738. }
  3739. endTime = theTime.Unix()
  3740. }
  3741. var ids []int64
  3742. var goodIds []int64
  3743. infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
  3744. for _, it := range infoList {
  3745. goodIds = append(goodIds, it.GoodId)
  3746. }
  3747. manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
  3748. for _, it := range manufacturers {
  3749. ids = append(ids, it.ID)
  3750. }
  3751. manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
  3752. list, total, err := service.GetPurchaseStockQueryList(good_type, keyword, page, limit, orgId, ids, goodIds)
  3753. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3754. for _, item := range list {
  3755. //获取期初结余
  3756. low, _ := service.GetStartLastFLow(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3757. item.GoodStartFlowInfo = low
  3758. //获取期末结余
  3759. flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime, storeConfig.StorehouseOutInfo)
  3760. item.GoodEndFlowInfo = flow
  3761. //获取期间增加
  3762. goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3763. for _, it := range goodWarehouseInfoList {
  3764. item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
  3765. }
  3766. //获取本期增加
  3767. WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3768. for _, it := range WarehouseInfoFlowList {
  3769. item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
  3770. }
  3771. //获取本期减少
  3772. reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3773. for _, it := range reduceWarehouseInfoList {
  3774. item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
  3775. }
  3776. //获取期中减少退库
  3777. lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3778. for _, it := range lowInfo {
  3779. item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
  3780. }
  3781. //
  3782. outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3783. for _, it := range outInfo {
  3784. item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
  3785. }
  3786. //期中盘盈
  3787. profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3788. for _, it := range profit {
  3789. item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
  3790. }
  3791. //期中盘亏
  3792. losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime, storeConfig.StorehouseOutInfo)
  3793. for _, it := range losses {
  3794. item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
  3795. }
  3796. //获取期初结余
  3797. //service.GetNewOverInCount(item.ID, orgId, startTime, storeConfig.StorehouseOutInfo)
  3798. }
  3799. if err != nil {
  3800. this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
  3801. return
  3802. }
  3803. this.ServeSuccessJSON(map[string]interface{}{
  3804. "list": list,
  3805. "manufacturerList": manufacturerList,
  3806. "total": total,
  3807. })
  3808. }
  3809. func (this *SelfDrugApiController) GetCheckDrugBatchList() {
  3810. drug_id, _ := this.GetInt64("drug_id")
  3811. orgId := this.GetAdminUserInfo().CurrentOrgId
  3812. advicelist, _ := service.GetHisAdviceGroupList(drug_id, orgId)
  3813. outInfo, _ := service.GetDrugWarehousOutInfo(drug_id, orgId)
  3814. outInfoOne, _ := service.GetDrugWarehousOutInfoOne(drug_id, orgId)
  3815. baseDrugList, _ := service.GetDrugByGoodId(drug_id)
  3816. drugflow, _ := service.GetCheckDrugFlow(drug_id, orgId)
  3817. this.ServeSuccessJSON(map[string]interface{}{
  3818. "advicelist": advicelist,
  3819. "outInfo": outInfo,
  3820. "outInfoOne": outInfoOne,
  3821. "baseDrugList": baseDrugList,
  3822. "drugflow": drugflow,
  3823. })
  3824. }
  3825. func (this *SelfDrugApiController) GetCheckGoodBatchList() {
  3826. id, _ := this.GetInt64("id")
  3827. orgId := this.GetAdminUserInfo().CurrentOrgId
  3828. projectList, _ := service.GetCheckGoodBatchList(id, orgId)
  3829. warehouseList, _ := service.GetCheckGoodWarehouseList(id, orgId)
  3830. this.ServeSuccessJSON(map[string]interface{}{
  3831. "projectList": projectList,
  3832. "warehouseList": warehouseList,
  3833. })
  3834. }
  3835. func (this *SelfDrugApiController) GetDrugPatientName() {
  3836. drug_id, _ := this.GetInt64("drug_id")
  3837. sys_record_time, _ := this.GetInt64("sys_record_time")
  3838. orgId := this.GetAdminUserInfo().CurrentOrgId
  3839. advicelist, _ := service.GetHisAdviceListBySysRrecordTime(drug_id, sys_record_time, orgId)
  3840. outInfor, _ := service.GetDrugWarehouseOutInfoBySysRecordTime(drug_id, sys_record_time, orgId)
  3841. patients, _ := service.GetAllpatient(orgId)
  3842. this.ServeSuccessJSON(map[string]interface{}{
  3843. "advicelist": advicelist,
  3844. "outInfor": outInfor,
  3845. "patients": patients,
  3846. })
  3847. }