self_drug_api_congtroller.go 147KB

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