12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "reflect"
- "strconv"
- "strings"
- "time"
- )
-
- type SelfDrugApiController struct {
- BaseAuthAPIController
- }
-
- func SelfDrugRouters() {
-
- beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
- beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
- beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
- beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
- beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
- beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
- beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
- beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
- beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
- beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
- beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
- beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
- beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
- beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
- beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
- beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
- beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
- beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
- beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
- beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
- beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
- beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
- beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
- beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
- beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
- beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
- beego.Router("/api/drug/getallmedicallist", &SelfDrugApiController{}, "Get:GetAllMedicalList")
- beego.Router("/api/drug/getstandname", &SelfDrugApiController{}, "Get:GetStandName")
- beego.Router("/api/drug/getrullerlist", &SelfDrugApiController{}, "Get:GetRullerList")
- beego.Router("/api/drug/deleteDrugNamebyid", &SelfDrugApiController{}, "Get:DeleteDrugNameById")
- beego.Router("/api/drug/getpatientdetail", &SelfDrugApiController{}, "Get:GetPatientDetail")
- //beego.Router("/api/drug/getpatientdetail",&SelfDrugApiController{},"Get:ToPatientDetail")
- beego.Router("/api/drug/getselfstockquery", &SelfDrugApiController{}, "Get:GetSelfStockQuery")
- beego.Router("/api/drug/postsearchdrugwarehouselist", &SelfDrugApiController{}, "Get:PostSearchDrugWarehouseList")
- beego.Router("/api/drug/savedrugpriceone", &SelfDrugApiController{}, "Post:SaveDrugPrice")
- beego.Router("/api/drug/drugpricelist", &SelfDrugApiController{}, "Get:GetDrugPriceList")
- beego.Router("/api/drug/savecheckdrugprice", &SelfDrugApiController{}, "Get:SaveCheckDrugPrice")
- beego.Router("/api/drug/savedrugdamageone", &SelfDrugApiController{}, "Post:SaveDrugDamage")
- beego.Router("/api/drug/getdrugdamagelist", &SelfDrugApiController{}, "Get:GetDrugDamageList")
- beego.Router("/api/drug/savedrugdamageprice", &SelfDrugApiController{}, "Get:SaveDrugDamagePrice")
- beego.Router("/api/drug/getdrugmodifyprice", &SelfDrugApiController{}, "Get:GetDrugModifyPrice")
- beego.Router("/api/drug/modifydrugprice", &SelfDrugApiController{}, "Get:ModifyDrugPrice")
- beego.Router("/api/drug/getmodifypriceprint", &SelfDrugApiController{}, "Get:GetModifyPricePrint")
- beego.Router("/api/drug/getdrugdamagedetail", &SelfDrugApiController{}, "Get:GetDrugDamageDetail")
- beego.Router("/api/drug/modifydrugdamage", &SelfDrugApiController{}, "Get:ModifyDrugDamage")
- beego.Router("/api/drug/deletedrugdamage", &SelfDrugApiController{}, "Get:DeleteDrugDamage")
- beego.Router("/api/drug/getdrugdamageprint", &SelfDrugApiController{}, "Get:GetDrugDamagePrint")
- beego.Router("/api/drug/warehouseinfobyid", &SelfDrugApiController{}, "Get:GetWarehoseInfoById")
- beego.Router("/api/drug/savedruginventory", &SelfDrugApiController{}, "Post:SaveDrugInventory")
- beego.Router("/api/drug/getdruginventorylist", &SelfDrugApiController{}, "Get:GetDrugInventoryList")
- beego.Router("/api/drug/savedrugcheckinventory", &SelfDrugApiController{}, "Get:SaveDrugCheckInventory")
- beego.Router("/api/drug/getdruginventorydetail", &SelfDrugApiController{}, "Get:GetDrugInventoryDetail")
- beego.Router("/api/drug/modifyinventory", &SelfDrugApiController{}, "Get:ModifyInventory")
- beego.Router("/api/drug/deletedruginventory", &SelfDrugApiController{}, "Get:DeleteDrugInventory")
- beego.Router("/api/drug/getdruginventoryprintlist", &SelfDrugApiController{}, "Get:GetDrugInventoryPrintList")
- beego.Router("/api/drug/getinventorydetaillist", &SelfDrugApiController{}, "Get:GetDrugInventoryDetailList")
- beego.Router("/api/drug/savedrugproofinventory", &SelfDrugApiController{}, "Get:SaveDrugProofInventory")
- beego.Router("/api/drug/getdrugwarehouseinfototal", &StockManagerApiController{}, "Get:GetDrugWarehouseInfoTotal")
-
- beego.Router("/api/drug/saveinentorylist", &SelfDrugApiController{}, "Post:SaveInventoryList")
-
- beego.Router("/api/drug/getdamagebydrugid", &SelfDrugApiController{}, "Get:GetDamageByDrugId")
-
- beego.Router("/api/drug/getinventorymodelist", &SelfDrugApiController{}, "Get:GetInventoryModeList")
-
- //耗材库存优化接口
- beego.Router("/api/drug/getstorehouselist", &SelfDrugApiController{}, "Get:GetStorehouseList")
- beego.Router("/api/drug/getgoodnewquery", &SelfDrugApiController{}, "Get:GetGoodNewQuery")
- beego.Router("/api/drug/getgoodwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetGoodWarehouseOutInfoByIdList")
- beego.Router("/api/good/getgoodpatientlist", &SelfDrugApiController{}, "Get:GetGoodPatientList")
- beego.Router("/api/good/getwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetWarehouseOutDetailByPatientId")
- beego.Router("/api/good/getgoodexpirydatequery", &SelfDrugApiController{}, "Get:GetGoodExpiryDateQuery")
- beego.Router("/api/good/getpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodPurchaseStockQuery")
-
- //药品库存优化接口
- beego.Router("/api/good/getdrugwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetDrugWarehouseOutDetailByPatientId")
- beego.Router("/api/drug/getdrugexpirydatequery", &SelfDrugApiController{}, "Get:GetDrugExpiryDateQuery")
- beego.Router("/api/drug/getpurchasedrugquery", &SelfDrugApiController{}, "Get:GetPurchaseDrugQuery")
- beego.Router("/api/drug/getdrugnewquery", &SelfDrugApiController{}, "Get:GetDrugNewQuery")
- beego.Router("/api/drug/getdrugwarehouseoutinfobyid", &SelfDrugApiController{}, "Get:GetDrugWarehouseInfoById")
-
- //耗材脚本
- beego.Router("/api/stock/tosendgoodinfomation", &SelfDrugApiController{}, "Get:GetSendGoodInformation")
- //药品脚本
- beego.Router("/api/drug/getdruginitdatalist", &SelfDrugApiController{}, "Get:GetDrugInitDetailList")
-
- //新数据
- beego.Router("/api/stock/getnewpurchasestockquery", &SelfDrugApiController{}, "Get:GetGoodNewPurchaseStockQuery")
- beego.Router("/api/stock/getpurchasenewdrugquery", &SelfDrugApiController{}, "Get:GetPurchaseNewDrugQuery")
- beego.Router("/api/stock/getgoodovercount", &SelfDrugApiController{}, "Get:GetGoodOverCount")
- beego.Router("/api/stock/getdrugovercount", &SelfDrugApiController{}, "Get:GetDrugOverCount")
-
- beego.Router("/api/stock/getdruginfolist", &SelfDrugApiController{}, "Get:GetDrugInventoryWarehouseInfoList")
- }
-
- func (this *SelfDrugApiController) GetCurrentPatient() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- patient, err := service.GetCurrentPatient(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (this *SelfDrugApiController) GetAllDrugName() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- //查询药品库是否开启
- //configStock, _ := service.GetDrugStockConfig(orgId)
- //if configStock.IsOpen == 1 {
- //
- //}
-
- drugName, err := service.GetAllDrugName(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugName": drugName,
- })
-
- }
-
- func (this *SelfDrugApiController) SaveDrugName() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- drug_name := this.GetString("drug_name")
- id, _ := this.GetInt64("id")
- //fmt.Println("drug_name", drug_name)
- drugName := models.XtDrugName{
- UserOrgId: orgId,
- DrugName: drug_name,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- DrugId: id,
- }
- _, errcode := service.GetDrugName(drug_name, orgId)
- if errcode == gorm.ErrRecordNotFound {
- err := service.SaveDrugName(&drugName)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugName": drugName,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- }
-
- func (this *SelfDrugApiController) GetDrugNameList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- list, err := service.GetDrugNameList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetRulleName() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- id, _ := this.GetInt64("id")
- drugId, _ := service.GetDrugId(id)
- rullerList, err := service.GetRulleList(orgId, drugId.DrugId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerList": rullerList,
- })
- }
-
- func (this *SelfDrugApiController) GetUnitByBaseId() {
-
- id, _ := this.GetInt64("id")
- baseList, err := service.GetUnitByBaseId(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "baseList": baseList,
- })
- }
-
- func (this *SelfDrugApiController) SaveRulleName() {
- drug_name := this.GetString("drug_name")
- drug_spec := this.GetString("drug_spec")
- drug_stock_limit := this.GetString("drug_stock_limit")
- drug_name_id, _ := this.GetInt64("drug_name_id")
- drug_id, _ := this.GetInt64("drug_id")
- price, _ := this.GetInt64("price")
- prices := strconv.FormatInt(price, 10)
- durg_price, _ := strconv.ParseFloat(prices, 64)
- unit := this.GetString("unit")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
- drugSpecName := models.XtStandName{
- DrugName: drug_name,
- DrugSpec: drug_spec,
- DrugStockLimit: drug_stock_limit,
- DrugNameId: drug_name_id,
- Price: durg_price,
- MinUnit: unit,
- UserOrgId: orgId,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- DrugId: drug_id,
- }
-
- //查询该机构下药品规格名称是否存在
- _, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
-
- if errcode == gorm.ErrRecordNotFound {
- err := service.SaveRulleName(&drugSpecName)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "RullerName": drugSpecName,
- })
- } else if errcode == nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
- return
- }
-
- }
-
- func (this *SelfDrugApiController) EditRullerName() {
-
- id, _ := this.GetInt64("id")
- rullerDetail, err := service.GetRullerNameDetail(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerDetail": rullerDetail,
- })
- }
-
- func (this *SelfDrugApiController) UpdatedRullerName() {
-
- id, _ := this.GetInt64("id")
- drug_name := this.GetString("drug_name")
- drug_stock_limit := this.GetString("drug_stock_limit")
- price, _ := this.GetInt64("price")
- prices := strconv.FormatInt(price, 10)
- durg_price, _ := strconv.ParseFloat(prices, 64)
-
- drug_spec := this.GetString("drug_spec")
- unit := this.GetString("unit")
- drug_name_id, _ := this.GetInt64("drug_name_id")
- drug_id, _ := this.GetInt64("drug_id")
-
- RullerName := models.XtStandName{
- DrugName: drug_name,
- DrugStockLimit: drug_stock_limit,
- Price: durg_price,
- DrugSpec: drug_spec,
- MinUnit: unit,
- DrugNameId: drug_name_id,
- DrugId: drug_id,
- }
- _, errcode := service.GetIsExit(drug_name, drug_spec, id)
- if errcode == gorm.ErrRecordNotFound {
- err := service.UpdatedRullerName(id, &RullerName)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "RullerName": RullerName,
- })
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- }
-
- func (this *SelfDrugApiController) GetAllDrugNameList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- rullerName, err := service.GetAllDrugNameList(orgId)
-
- list, err := service.GetMedicalDrugNameList(orgId)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerName": rullerName,
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetRullerListByDrugName() {
-
- id := this.GetString("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- fmt.Println("orgid", orgId)
- drugName, err := service.GetRullerListByDrugName(id, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugName": drugName,
- })
- }
-
- func (this *SelfDrugApiController) SaveSelfMedicines() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- patient_id := int64(dataBody["patient_id"].(float64))
- medicineData, _ := dataBody["medicineData"].([]interface{})
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- for _, item := range medicineData {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- drug_name_id := int64(items["drug_name_id"].(float64))
- drug_spec := items["drug_spec"].(string)
- min_unit := items["min_unit"].(string)
- drug_id := int64(items["drug_id"].(float64))
- //根据drug_id
- drugMedical, _ := service.GetBaseDrugMedical(drug_name_id)
- medical := models.XtSelfMedical{
- DrugName: drug_name,
- DrugNameId: drug_name_id,
- DrugSpec: drug_spec,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- UserOrgId: orgId,
- PatientId: patient_id,
- MinUnit: min_unit,
- ExecutionFrequency: drugMedical.ExecutionFrequency,
- PrescribingNumber: drugMedical.PrescribingNumber,
- DeliveryWay: drugMedical.DeliveryWay,
- SingleDose: drugMedical.SingleDose,
- DrugId: drug_id,
- }
- //查询同个病人同个药品同个规格是否已存在
- _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
-
- if errcode == gorm.ErrRecordNotFound {
- err := service.CreateSelfMedical(&medical)
- fmt.Println(err)
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgid := adminUserInfo.CurrentOrgId
- //fmt.Println(orgid)
- appId := adminUserInfo.CurrentAppId
- staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "staff": staff,
- })
- }
-
- func (this *SelfDrugApiController) SaveStock() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- fmt.Println("start_time", start_time)
- admin_user_id, _ := this.GetInt64("admin_user_id")
- fmt.Println("admin_user_id", admin_user_id)
- patient_id, _ := this.GetInt64("patient_id")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- stocks, _ := dataBody["stocks"].([]interface{})
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- for _, item := range stocks {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- fmt.Println("drug_name", drug_name)
- drug_name_id := int64(items["drug_name_id"].(float64))
- fmt.Println("parient_id", drug_name_id)
- drug_spec := items["drug_spec"].(string)
- store_number := items["store_number"].(string)
- fmt.Println("store_number", store_number)
- storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
- remarks := items["remarks"].(string)
- min_unit := items["min_unit"].(string)
- medic_id := int64(items["id"].(float64))
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
- number = number + total
- warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
-
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- stock := models.XtSelfStock{
- DrugName: drug_name,
- DrugNameId: drug_name_id,
- DrugSpec: drug_spec,
- StoreNumber: storeNumber,
- Remarks: remarks,
- AdminUserId: admin_user_id,
- StorckTime: theTime.Unix(),
- CreatedTime: time.Now().Unix(),
- Status: 1,
- UserOrgId: orgId,
- StockInNumber: warehousing_in_order,
- PatientId: patient_id,
- MinUnit: min_unit,
- StorageMode: 1,
- MedicId: medic_id,
- }
- err := service.CreateStock(&stock)
- fmt.Println("err", err)
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) SaveOutStock() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- admin_user_id, _ := this.GetInt64("admin_user_id")
- patient_id, _ := this.GetInt64("patient_id")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- outStocks, _ := dataBody["outStocks"].([]interface{})
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- for _, item := range outStocks {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- drug_name_id := int64(items["drug_name_id"].(float64))
- drug_spec := items["drug_spec"].(string)
- outstore_number := items["outstore_number"].(string)
- outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
- remarks := items["remarks"].(string)
- medic_id := int64(items["id"].(float64))
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- fmt.Println(remarks)
- fmt.Println(items)
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- stock := models.XtSelfOutStock{
- DrugName: drug_name,
- DrugNameId: drug_name_id,
- DrugSpec: drug_spec,
- OutstoreNumber: outStoreNumber,
- Remarks: remarks,
- AdminUserId: admin_user_id,
- StorckTime: theTime.Unix(),
- CreatedTime: time.Now().Unix(),
- Status: 1,
- UserOrgId: orgId,
- StockOutNumber: warehousing_out_order,
- PatientId: patient_id,
- ExitMode: 1,
- MedicId: medic_id,
- }
- err := service.CreateOutStock(&stock)
- fmt.Println("err", err)
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) DeleteDrugById() {
- id, _ := this.GetInt64("id")
- drug_name := this.GetString("drug_name")
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
-
- if errcode == gorm.ErrRecordNotFound {
- service.DeleteDrugName(id)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- }
-
- func (this *SelfDrugApiController) SaveRadio() {
-
- radio, _ := this.GetInt64("radio")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- drugSet := models.XtDrugSet{
- DrugStart: radio,
- UserOrgId: orgId,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- }
- _, errcode := service.GetDrugSetByUserOrgId(orgId)
- if errcode == gorm.ErrRecordNotFound {
- err := service.SaveRadio(&drugSet)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugSet": drugSet,
- })
- } else if errcode == nil {
- err := service.UpdateDrugSet(&drugSet, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugSet": drugSet,
- })
- }
-
- }
-
- func (this *SelfDrugApiController) DeleteDrugStand() {
-
- id, _ := this.GetInt64("id")
- name := this.GetString("name")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- _, errcode := service.GetMedicalsByName(orgId, name)
- if errcode == gorm.ErrRecordNotFound {
- err := service.DeleteDrugStand(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- } else if errcode == nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- }
-
- func (this *SelfDrugApiController) GetStockList() {
-
- patientid, _ := this.GetInt64("id")
- start_time := this.GetString("start_time")
- fmt.Println("开始时间", start_time)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- startimeUnix := theTime.Unix()
- keyword := this.GetString("keyword")
- fmt.Println("keyword", keyword)
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- //获取
- medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
- //统计总数量
- stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
- //统计出库数量
- outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
-
- //统计该病人时间段内出库条数
- outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "medicalList": medicalList,
- "stocklist": stocklist,
- "outStocklist": outStocklist,
- "outList": outList,
- })
- }
-
- func (this *SelfDrugApiController) DeleteDrugName() {
-
- drug_name := this.GetString("drugname")
- patient_id, _ := this.GetInt64("patientid")
-
- //查询该药品是否出库
- stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
- if len(stocklist) == 0 {
- //删除该药品
- service.DeleteDrugStockNumber(drug_name, patient_id)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- }
-
- func (this *SelfDrugApiController) GetDrugDetail() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- drug_name := this.GetString("drug_name")
- drug_spec := this.GetString("drug_spec")
- start_time := this.GetString("start_time")
- startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- end_time := this.GetString("end_time")
- endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- patient_id, _ := this.GetInt64("patient_id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- //查询入库明细
- stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
-
- //查询出库明细
- outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stockDetail": stockDetail,
- "outStockDetail": outStockDetail,
- })
- }
-
- func (this *SelfDrugApiController) GetAllPatientStockList() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- drug_name := this.GetString("drug_name")
- drug_spec := this.GetString("drug_spec")
- start_time := this.GetString("start_time")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- startUnix := theTime.Unix()
- end_time := this.GetString("end_time")
- endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- endTimeUnix := endTimes.Unix()
- keywords := this.GetString("search_input")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- //入库
- stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
-
- //出库
- outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stocklist": stocklist,
- "outStockList": outStockList,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugDataByPatientId() {
-
- patient_id, _ := this.GetInt64("patient_id")
- fmt.Println("patient_id", patient_id)
- medicalList, err := service.GetDrugDataByPatientId(patient_id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "medicalList": medicalList,
- })
- }
-
- func (this *SelfDrugApiController) GetSelfMedicalList() {
-
- patient_id, _ := this.GetInt64("patient_id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
- privateDrugConfig, _ := service.GetDrugSetByUserOrgId(orgId)
- drugList, _ := service.GetAllBaseDrugLibList(orgId)
- privateDrugList, _ := service.GetPrivateDrugList(patient_id, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "base_drug_config": drugStockConfig,
- "private_drug_config": privateDrugConfig,
- "base_drug_list": drugList,
- "private_drug_list": privateDrugList,
- })
- ////查询是否开启药品库
- //config, _ := service.GetDruckStockConfig(orgId)
- //
- //fmt.Println("--------------------------",config.IsOpen)
- ////开启
- //if config.IsOpen == 1 {
- // //查询该机构下的药品库
- // drugName, _ := service.GetAllDrugName(orgId)
- //
- // //查询该机构是否开启自备药
- // medical, _ := service.GetSetSelfMedical(orgId)
- // fmt.Println("medical+++++++++++++++++",medical.DrugStart)
- // //开启
- // if medical.DrugStart == 1 {
- // list, err := service.GetSelfMedicalList(patient_id)
- // if err != nil {
- // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- // return
- // }
- // this.ServeSuccessJSON(map[string]interface{}{
- // "medicalList": list,
- // "drugName": drugName,
- // })
- // } else {
- // this.ServeSuccessJSON(map[string]interface{}{
- // "drugName": drugName,
- // })
- // }
- //}
- }
-
- func (this *SelfDrugApiController) GetDrugDescByDrugName() {
-
- drug_name := this.GetString("drug_name")
- patient_id, _ := this.GetInt64("patient_id")
- way, _ := this.GetInt64("way")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- drug_id, _ := this.GetInt64("id")
- //从基础库查询
- if way == 1 {
- //查询基础库数据
- medcal, err := service.GetBaseMedcal(drug_name, orgId)
- //统计入库数量
- countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
-
- //统计出库数量
- countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugspec": medcal,
- "countInfo": countInfo,
- "countout": countout,
- })
- }
- //从自备药库查询
- if way == 2 {
- drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugspec": drugspec,
- })
- }
-
- }
-
- func (this *SelfDrugApiController) GetDrugSet() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- drugSet, err := service.GetDrugSet(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugSet": drugSet,
- })
-
- }
-
- func (this *SelfDrugApiController) GetAllMedicalList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- list, err := service.GetAllMedicalList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "drugName": list,
- })
- }
-
- func (this *SelfDrugApiController) GetStandName() {
-
- name := this.GetString("name")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- rullerlist, err := service.GetRulleName(orgId, name)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerlist": rullerlist,
- })
- }
-
- func (this *SelfDrugApiController) GetRullerList() {
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- rullerList, err := service.GetRulleList(orgId, id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "rullerlist": rullerList,
- })
- }
-
- func (this *SelfDrugApiController) DeleteDrugNameById() {
-
- id, _ := this.GetInt64("id")
- drug_name := this.GetString("drug_name")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
-
- if errcode == gorm.ErrRecordNotFound {
- service.DeleteDrugNameById(id)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- }
-
- func (this *SelfDrugApiController) GetPatientDetail() {
-
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- patientDetail, err := service.GetPatientDetail(id, adminUserInfo.CurrentOrgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patientDetail": patientDetail,
- })
- }
-
- //func (this *SelfDrugApiController) ToPatientDetail() {
- //
- // keyword := this.GetString("keyword")
- // adminUser := this.GetAdminUserInfo()
- // orgId := adminUser.CurrentOrgId
- // patient, err := service.ToSeachPatient(keyword, orgId)
- // if err != nil {
- // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- // return
- // }
- // this.ServeSuccessJSON(map[string]interface{}{
- // "patient": patient,
- // })
- //}
-
- func (this *SelfDrugApiController) GetSelfStockQuery() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- type_name, _ := this.GetInt64("type_name")
- keywords := this.GetString("keywords")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- startUnix := theTime.Unix()
- end_time := this.GetString("end_time")
- endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- endTimeUnix := endTimes.Unix()
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- //统计入库数量
- stockQuery, total, err := service.GetSelfStockQuery(type_name, keywords, startUnix, endTimeUnix, orgId, limit, page)
- //统计出库数量
- stockOutQuery, err := service.GetSelfOutStockQuery(startUnix, endTimeUnix, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stockQuery": stockQuery,
- "total": total,
- "stockOutQuery": stockOutQuery,
- })
- }
-
- func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
-
- keyword := this.GetString("keyword")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, err := service.PostSearchDrugWarehouseList(keyword, orgId, storehouse_id)
- manufacturerList, err := service.GetAllManufacturerList(orgId)
- dealerList, err := service.GetAllDealerList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugPrice() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
- fmt.Println("999939433443", tableData)
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
-
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_name := items["drug_name"].(string)
- fmt.Println("drug_aname23232323232", drug_name)
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number := items["number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
- utils.ErrorLog("new_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- drugAdjust := models.XtDrugAdjustPrice{
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- LastPrice: last_price,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- Number: number,
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- }
-
- err := service.CreateDrugPrice(drugAdjust)
- fmt.Println(err)
- }
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) GetDrugPriceList() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- list, total, err := service.GetDrugPriceList(startTime, endTime, orgId, keyword, limit, page)
- doctorList, err := service.GetAllDoctorThree(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "doctorList": doctorList,
- })
- }
-
- func (this *SelfDrugApiController) SaveCheckDrugPrice() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- adjustPrice := models.XtDrugAdjustPrice{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err = service.UpdateDrugAdjuestPrice(ids, adjustPrice)
- fmt.Println("err", err)
- list, _ := service.GetDrugAdjuestPrice(ids)
- for _, item := range list {
- drug := models.BaseDrugLib{
- RetailPrice: item.NewPrice,
- LastPrice: item.NewPrice,
- }
- service.UpdateBaseDrugOne(drug, item.DrugId)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "adjustPrice": adjustPrice,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugDamage() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
- fmt.Println("999939433443", tableData)
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number := items["number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
- utils.ErrorLog("new_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
- utils.ErrorLog("warehousing_info_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_info_id := int64(items["warehousing_info_id"].(float64))
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
-
- if items["drug_origin_place"] == nil || reflect.TypeOf(items["drug_origin_place"]).String() != "string" {
- utils.ErrorLog("drug_origin_place")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_origin_place := items["drug_origin_place"].(string)
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- if items["stock_max_number"] == nil || reflect.TypeOf(items["stock_max_number"]).String() != "float64" {
- utils.ErrorLog("stock_max_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stock_max_number := int64(items["stock_max_number"].(float64))
-
- if items["stock_min_number"] == nil || reflect.TypeOf(items["stock_min_number"]).String() != "float64" {
- utils.ErrorLog("stock_min_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stock_min_number := int64(items["stock_min_number"].(float64))
-
- if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
- utils.ErrorLog("total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- total := items["total"].(string)
- drugDamage := models.XtDrugDamage{
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- LastPrice: last_price,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- Number: number,
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- ExpiryDate: expiry_date,
- ProductDate: product_date,
- WarehousingInfoId: warehousing_info_id,
- DrugOriginPlace: drug_origin_place,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- Total: total,
- }
-
- err := service.CreateDrugDamage(drugDamage)
- fmt.Println(err)
- }
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- }
-
- func (this *SelfDrugApiController) GetDrugDamageList() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
-
- list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page, storehouse_id)
-
- damagelist, _ := service.GetDrugDamageByOrgId(orgId)
- doctorList, err := service.GetAllDoctorThree(orgId)
-
- houseList, _ := service.GetAllStoreHouseList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "damagelist": damagelist,
- "doctorList": doctorList,
- "houseList": houseList,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugDamagePrice() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- damage := models.XtDrugDamage{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err = service.UpdateDrugDamage(ids, damage)
- fmt.Println(err)
- list, _ := service.GetDrugDamage(ids)
- ctime := time.Now().Unix()
- adminUserInfo := this.GetAdminUserInfo()
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var manufacturer_id int64
- var dealer_id int64
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.DrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: time.Now().Unix(),
- Type: 1,
- }
- service.AddSigleDrugWarehouseOut(&warehouseOut)
- for _, item := range list {
- for _, it := range manufacturerList {
- if item.Manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
-
- for _, its := range dealerList {
- if its.DealerName == item.Dealer {
- dealer_id = its.ID
- }
- }
-
- warehouseOutInfo := models.XtDrugWarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- DrugId: item.DrugId,
- Count: item.Count,
- Price: item.RetailPrice,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- RetailPrice: item.RetailPrice,
- CountUnit: item.WarehousingUnit,
- ExpiryDate: item.ExpiryDate,
- ProductDate: item.ProductDate,
- Number: item.Number,
- BatchNumber: item.BatchNumber,
- IsSys: 0,
- WarehouseInfoId: item.WarehousingInfoId,
- }
-
- drugflow := models.DrugFlow{
- WarehouseOutId: warehouseOut.ID,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- DrugId: item.DrugId,
- Number: item.Number,
- ProductDate: item.ProductDate,
- ExpireDate: item.ExpiryDate,
- Count: item.Count,
- Price: item.RetailPrice,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- BatchNumber: item.BatchNumber,
- MaxUnit: item.WarehousingUnit,
- ConsumableType: 5,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- }
- service.CreateWareHouseOutInfo(&warehouseOutInfo)
- service.CreateDrugFlowOne(drugflow)
-
- info, _ := service.GetDrugByWarehouseInfo(item.WarehousingInfoId)
- //扣减库存
- warehouseInfo := models.XtDrugWarehouseInfo{
- StockMaxNumber: info.StockMaxNumber - info.StockMaxNumber,
- }
- service.UpdateDrugWarehouseingInfo(item.WarehousingInfoId, warehouseInfo)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "damage": damage,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugModifyPrice() {
-
- id, _ := this.GetInt64("id")
- detail, err := service.GetDrugModifyPrice(id)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *SelfDrugApiController) ModifyDrugPrice() {
-
- drug_name := this.GetString("drug_name")
- specification_name := this.GetString("specification_name")
- warehousing_unit := this.GetString("warehousing_unit")
- manufacturer := this.GetString("manufacturer")
- number := this.GetString("number")
- retailPrice := this.GetString("retail_price")
- retail_price, _ := strconv.ParseFloat(retailPrice, 64)
- newPrice := this.GetString("new_price")
- new_price, _ := strconv.ParseFloat(newPrice, 64)
- count, _ := this.GetInt64("count")
- remark := this.GetString("remark")
- id, _ := this.GetInt64("id")
- drug_id, _ := this.GetInt64("drug_id")
- adjustPrice := models.XtDrugAdjustPrice{
- DrugName: drug_name,
- Count: count,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Remark: remark,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Manufacturer: manufacturer,
- Number: number,
- DrugId: drug_id,
- }
- err := service.ModifyDrugPrice(id, adjustPrice)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "adjustPrice": adjustPrice,
- })
- }
-
- func (this *SelfDrugApiController) GetModifyPricePrint() {
-
- ids := this.GetString("ids")
- idsSplit := strings.Split(ids, ",")
- list, err := service.GetModifyPricePrint(idsSplit)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugDamageDetail() {
-
- id, _ := this.GetInt64("id")
- detail, _ := service.GetDrugDamageDetail(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *SelfDrugApiController) ModifyDrugDamage() {
-
- id, _ := this.GetInt64("id")
- drug_id, _ := this.GetInt64("drug_id")
- drug_name := this.GetString("drug_name")
- drug_origin_place := this.GetString("drug_origin_place")
- lastPrice := this.GetString("last_price")
- last_price, _ := strconv.ParseFloat(lastPrice, 64)
- newPrice := this.GetString("new_price")
- new_price, _ := strconv.ParseFloat(newPrice, 64)
- manufacturer := this.GetString("manufacturer")
- number := this.GetString("number")
- retailPrice := this.GetString("retail_price")
- retail_price, _ := strconv.ParseFloat(retailPrice, 64)
- remark := this.GetString("remark")
- count, _ := this.GetInt64("count")
- warehousing_unit := this.GetString("warehousing_unit")
- stock_max_number, _ := this.GetInt64("stock_max_number")
- stock_min_number, _ := this.GetInt64("stock_min_number")
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- damage := models.XtDrugDamage{
- DrugName: drug_name,
- SpecificationName: "",
- WarehousingUnit: warehousing_unit,
- Count: count,
- LastPrice: last_price,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: "",
- Remark: remark,
- DrugId: drug_id,
- Number: number,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- WarehousingInfoId: warehousing_info_id,
- DrugOriginPlace: drug_origin_place,
- }
- err := service.ModifyDrugDamage(id, damage)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "damage": damage,
- })
- }
-
- func (this *SelfDrugApiController) DeleteDrugDamage() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteDrugDamage(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- }
-
- func (this *SelfDrugApiController) GetDrugDamagePrint() {
-
- idsSplit := this.GetString("ids")
- ids := strings.Split(idsSplit, ",")
- list, _ := service.GetDrugDamagePrint(ids)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetWarehoseInfoById() {
-
- id, _ := this.GetInt64("id")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- list, _ := service.GetWarehoseInfoById(id, storehouse_id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugInventory() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
- fmt.Println("999939433443", tableData)
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
-
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
- utils.ErrorLog("new_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- numbers := items["number"].(string)
-
- if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
- utils.ErrorLog("warehouse_info_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
-
- if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
- utils.ErrorLog("total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- total := items["total"].(string)
-
- drug_origin_place := items["drug_origin_place"].(string)
-
- min_count := int64(items["min_count"].(float64))
- min_unit := items["min_unit"].(string)
- inventory := models.XtDrugInventory{
-
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- LastPrice: last_price,
- RetailPrice: retail_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: "",
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- ExpiryDate: expiry_date,
- ProductDate: product_date,
- Number: numbers,
- //BatchNumber: batch_number,
- Total: total,
- WarehouseInfoId: warehouse_info_id,
- DrugOriginPlace: drug_origin_place,
- MinUnit: min_unit,
- MinCount: min_count,
- }
- err = service.CreateDrugInventory(inventory)
- fmt.Println(err)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "msg",
- })
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryList() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- list, total, err := service.GetDrugInventoryList(keyword, page, limit, orgId, startTime, endTime)
-
- doctorList, _ := service.GetAllDoctorThree(orgId)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "doctorList": doctorList,
- "houseList": houseList,
- "houseConfig": houseConfig,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugCheckInventory() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- inventory := models.XtDrugInventory{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err = service.UpdateDrugInventory(ids, inventory)
- fmt.Println(err)
-
- list, _ := service.GetDrugInventoryListByIds(ids)
-
- adminUserInfo := this.GetAdminUserInfo()
- var stock_total int64
- var proof_count int64
- var maxNumber int64
- var minNumber int64
- for _, item := range list {
-
- //查询药品信息
- drug, _ := service.GetDrugDetailByDrugId(item.DrugId)
-
- //查询库存
- info, _ := service.GetDrugWareInfoByIdTwo(item.WarehouseInfoId)
- var max_count int64
- var min_count int64
- for _, it := range info {
- max_count += it.StockMaxNumber
- min_count += it.StockMinNumber
- }
-
- //获取最晚的库存数量
- lastInfo, _ := service.GetLastDrugWarehouseInfo(item.DrugId)
- firstInfo, _ := service.GetFirstDrugWarehouseInfo(item.DrugId)
- stock_total = max_count*drug.MinNumber + min_count
- proof_count = item.Count*drug.MinNumber + item.MinCount
- fmt.Println("stock_total", stock_total)
- fmt.Println("proof_count", proof_count)
- //判断 如果库存数量 大于盘点库存,则出库
- if stock_total > proof_count {
- minNumber = (stock_total - proof_count) % drug.MinNumber
- maxNumber = (stock_total - proof_count) / drug.MinNumber
-
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.DrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: ctime,
- Type: 1,
- }
- service.AddSigleDrugWarehouseOut(&warehouseOut)
- warehouse, _ := service.GetLastDrugWarehouseOut(adminUserInfo.CurrentOrgId)
- warehouseOutInfo := models.DrugWarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouse.ID,
- DrugId: item.DrugId,
- Count: maxNumber,
- Price: firstInfo.Price,
- TotalPrice: firstInfo.TotalPrice,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: firstInfo.Manufacturer,
- Dealer: firstInfo.Dealer,
- RetailPrice: firstInfo.RetailPrice,
- RetailTotalPrice: firstInfo.RetailTotalPrice,
- CountUnit: drug.MaxUnit,
- ExpiryDate: firstInfo.ExpiryDate,
- ProductDate: firstInfo.ProductDate,
- Number: firstInfo.Number,
- BatchNumber: firstInfo.BatchNumber,
- IsSys: 0,
- WarehouseInfoId: firstInfo.ID,
- }
-
- drugflow := models.DrugFlow{
- WarehouseOutId: warehouseOut.ID,
- WarehouseOutOrderNumber: warehousing_out_order,
- DrugId: item.DrugId,
- Number: firstInfo.Number,
- ProductDate: firstInfo.ProductDate,
- ExpireDate: firstInfo.ExpiryDate,
- Count: maxNumber,
- Price: firstInfo.Price,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: firstInfo.Manufacturer,
- Dealer: firstInfo.Dealer,
- BatchNumber: firstInfo.BatchNumber,
- MaxUnit: drug.MaxUnit,
- ConsumableType: 2,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- }
- service.CreateDrugWarehouseOutInfo(warehouseOutInfo)
- service.CreateDrugFlowOne(drugflow)
-
- //扣减当前批次号的库存
- var total_count int64
-
- //查询当前批次库存的数量
- warehosueInfoList, _ := service.GetCurrentWarehosueInfo(item.WarehouseInfoId)
- fmt.Println(warehosueInfoList)
- for _, item := range warehosueInfoList {
- total_count += item.StockMaxNumber*drug.MinNumber + item.StockMinNumber
- }
- //判断当前批次库存 和 需要出库的数据
- //出库
- if proof_count <= total_count {
-
- //var total_count_one int64
- //获取当前批次号的库存
- //warehouseinfoOne, _ := service.GetCurrentWarehosueInfoOne(item.WarehouseInfoId)
- //total_count_one = warehouseinfoOne.StockMaxNumber * drug.MinNumber + warehouseinfoOne.StockMinNumber
-
- }
- //报错提示
- if proof_count > total_count {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
- }
- }
-
- //判断 如果库存数量 小于于盘点库存,则入库
- fmt.Println("stock_total2332322323223", stock_total, proof_count)
- if stock_total < proof_count {
-
- maxNumber = (proof_count - stock_total) / drug.MinNumber
- minNumber = (proof_count - stock_total) % drug.MinNumber
- fmt.Println("min_number23233232323223322323", minNumber)
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
- total = total + 1
- fmt.Println("total2323232323232", total)
- warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- warehousing := models.DrugWarehouse{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehousingTime: ctime,
- Type: 1,
- }
- service.AddSigleDrugWarehouse(&warehousing)
- warehouse, _ := service.GetLastDrugWarehouse(adminUserInfo.CurrentOrgId)
- warehouseInfo := models.DrugWarehouseInfo{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehouse.ID,
- DrugId: item.DrugId,
- Number: lastInfo.Number,
- ProductDate: lastInfo.ProductDate,
- ExpiryDate: lastInfo.ExpiryDate,
- WarehousingCount: maxNumber,
- Price: lastInfo.Price,
- TotalPrice: lastInfo.TotalPrice,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: lastInfo.Manufacturer,
- Dealer: lastInfo.Dealer,
- StockMaxNumber: maxNumber,
- StockMinNumber: minNumber,
- RetailTotalPrice: lastInfo.RetailTotalPrice,
- BatchNumber: lastInfo.BatchNumber,
- MaxUnit: drug.MaxUnit,
- MinUnit: drug.MinUnit,
- WarehousingInfoId: item.WarehouseInfoId,
- }
-
- drugflow := models.DrugFlow{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehouse.ID,
- DrugId: item.DrugId,
- Number: lastInfo.Number,
- ProductDate: lastInfo.ProductDate,
- ExpireDate: lastInfo.ExpiryDate,
- Count: maxNumber,
- Price: lastInfo.Price,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: lastInfo.Manufacturer,
- Dealer: lastInfo.Dealer,
- BatchNumber: lastInfo.BatchNumber,
- MaxUnit: drug.MaxUnit,
- MinUnit: drug.MinUnit,
- ConsumableType: 1,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- }
-
- service.CreateDrugWarehouseInfo(warehouseInfo)
- service.CreateDrugFlowOne(drugflow)
-
- }
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryDetail() {
-
- id, _ := this.GetInt64("id")
- detail, err := service.GetDrugInventoryDetail(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *SelfDrugApiController) ModifyInventory() {
-
- id, _ := this.GetInt64("id")
- drug_id, _ := this.GetInt64("drug_id")
- drug_name := this.GetString("drug_name")
- specification_name := this.GetString("specification_name")
- retailPrice := this.GetString("retail_price")
- retail_price, _ := strconv.ParseFloat(retailPrice, 64)
- warehousing_order := this.GetString("warehousing_order")
- number := this.GetString("number")
- manufacturer := this.GetString("manufacturer")
- remark := this.GetString("remark")
- warehousing_unit := this.GetString("warehousing_unit")
- total := this.GetString("total")
- lastPrice := this.GetString("last_price")
- last_price, _ := strconv.ParseFloat(lastPrice, 64)
- count, _ := this.GetInt64("count")
- drug_origin_place := this.GetString("drug_origin_place")
-
- stock_max_number, _ := this.GetInt64("stock_max_number")
- stock_min_number, _ := this.GetInt64("stock_min_number")
- warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
- min_count, _ := this.GetInt64("min_count")
- min_unit := this.GetString("min_unit")
- inventory := models.XtDrugInventory{
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- LastPrice: last_price,
- RetailPrice: retail_price,
- Manufacturer: manufacturer,
- Remark: remark,
- DrugId: drug_id,
- WarehousingOrder: warehousing_order,
- Number: number,
- Total: total,
- DrugOriginPlace: drug_origin_place,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- WarehouseInfoId: warehouse_info_id,
- MinCount: min_count,
- MinUnit: min_unit,
- }
- err := service.ModifyDrugInventory(id, inventory)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
-
- func (this *SelfDrugApiController) DeleteDrugInventory() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteDrugInventory(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryPrintList() {
-
- ids := this.GetString("ids")
-
- idssplit := strings.Split(ids, ",")
- list, err := service.GetDrugInventoryPrintList(idssplit)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryDetailList() {
-
- keyword := this.GetString("keyword")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, err := service.GetDrugInventoryDetailList(keyword, page, limit, orgId, storehouse_id)
- inventoryList, _, _ := service.GetDrugInventoryDetailListTwo(keyword, page, limit, orgId, storehouse_id)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- doctorList, _ := service.GetAllDoctorThree(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "doctorList": doctorList,
- "houseList": houseList,
- "inventoryList": inventoryList,
- })
- }
-
- func (this *SelfDrugApiController) SaveDrugProofInventory() {
-
- id, _ := this.GetInt64("id")
- warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
- warehousing_unit := this.GetString("warehousing_unit")
- remark := this.GetString("remark")
- proof_count, _ := this.GetInt64("proof_count")
-
- inventory := models.XtDrugInventory{
- WarehouseInfoId: warehouse_info_id,
- ProofCount: proof_count,
- WarehousingUnit: warehousing_unit,
- Remark: remark,
- }
- err := service.UpdateDrugProofInventory(id, &inventory)
- info := models.XtDrugWarehouseInfo{
- StockMaxNumber: proof_count,
- }
- service.UpdateDrugWarehouseInfoById(warehouse_info_id, &info)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
-
- func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
-
- id, _ := this.GetInt64("id")
- list, _ := service.GetDrugWarehouseInfoTotal(id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- //新改造
-
- func (this *SelfDrugApiController) SaveInventoryList() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
-
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
- drug_name := items["drug_name"].(string)
- if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- fmt.Println("drug_name", drug_name)
- specification_name := items["specification_name"].(string)
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- max_unit := items["max_unit"].(string)
- if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
- utils.ErrorLog("max_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- min_unit := items["min_unit"].(string)
- if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
- utils.ErrorLog("min_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- drug_id := int64(items["drug_id"].(float64))
-
- min_number := int64(items["min_number"].(float64))
-
- stock_max_number := int64(items["stock_max_number"].(float64))
-
- stock_min_number := int64(items["stock_min_number"].(float64))
-
- last_stock_max_number := int64(items["last_stock_max_number"].(float64))
-
- last_stock_min_number := int64(items["last_stock_min_number"].(float64))
-
- warehousing_order := items["warehousing_order"].(string)
-
- price := items["price"].(float64)
-
- manufacturer_name := items["manufacturer_name"].(string)
-
- batch_number := items["batch_number"].(string)
-
- id := int64(items["id"].(float64))
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- type_id := int64(items["type"].(float64))
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- storehouse_id := int64(items["storehouse_id"].(float64))
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- timeNow := time.Now().Format("2006-01-02")
- locationTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeNow+" 00:00:00", loc)
- var consumable_type int64
- var consumable_count int64
- var ord_total int64
- var new_total int64
- var total int64
- ord_total = stock_max_number*min_number + stock_min_number
- new_total = last_stock_max_number*min_number + last_stock_min_number
- medical, _ := service.GetBaseDrugMedical(drug_id)
-
- //改变库存
- info := models.DrugWarehouseInfo{
- DrugId: drug_id,
- StockMaxNumber: last_stock_max_number,
- StockMinNumber: last_stock_min_number,
- WarehousingCount: last_stock_max_number,
- MaxUnit: max_unit,
- MinUnit: min_unit,
- }
- drugInfo, _ := service.GetCurrentWarehosueInfoOne(id)
-
- if drugInfo.MaxUnit == medical.MaxUnit {
- total = drugInfo.WarehousingCount * medical.MinNumber
- }
- if drugInfo.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- total = drugInfo.WarehousingCount
- }
- //如果库存数据大于盘点数据,则减去数量
- if ord_total > new_total {
- consumable_type = 11
- consumable_count = ord_total - new_total
-
- err = service.ModifyDrugWarehouseInfo(&info, id)
-
- }
- //如果库存数据小于盘点数据,则增加数量
- if ord_total < new_total && new_total <= total {
- consumable_type = 10
- consumable_count = new_total - ord_total
- err = service.ModifyDrugWarehouseInfo(&info, id)
-
- }
-
- if ord_total < new_total && new_total > total {
- consumable_type = 10
- consumable_count = new_total - ord_total
- err = service.ModifyDrugWarehouseInfoSix(&info, id)
-
- }
-
- //查询默认仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(drugInfo.OrgId)
- //查询默认仓库剩余多少库存
- list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, drugInfo.OrgId, drugInfo.DrugId)
- var sum_count int64
- var sum_in_count int64
- for _, it := range list {
- baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- }
- sum_count += it.StockMaxNumber + it.StockMinNumber
- sum_in_count += it.WarehousingCount
- }
- service.UpdateMedicalSumCount(drugInfo.DrugId, sum_count, sum_in_count, drugInfo.OrgId)
-
- //更新剩余库存
- service.UpdateDrugStockCount(drugInfo.DrugId, drugInfo.OrgId, houseConfig.DrugStorehouseOut, sum_count)
- inventory := models.XtDrugInventory{
- DrugName: drug_name,
- SpecificationName: specification_name,
- WarehousingUnit: max_unit,
- Count: consumable_count,
- LastPrice: price,
- RetailPrice: 0,
- NewPrice: 0,
- Manufacturer: manufacturer_name,
- Dealer: "",
- Remark: "",
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: "",
- StartTime: locationTime.Unix(),
- Creater: this.GetAdminUserInfo().AdminUser.Id,
- Checker: 0,
- CheckerStatus: 0,
- CheckerTime: 0,
- ExpiryDate: expiry_date,
- ProductDate: 0,
- Number: "",
- BatchNumber: batch_number,
- Total: "",
- DrugOriginPlace: "",
- WarehouseInfoId: id,
- ProofCount: 0,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- MinCount: 0,
- MinUnit: min_unit,
- LastStockMaxNumber: last_stock_max_number,
- LastStockMinNumber: last_stock_min_number,
- InventoryType: consumable_type,
- Type: type_id,
- StorehouseId: storehouse_id,
- }
-
- err = service.CreateDrugInventory(inventory)
-
- flow := models.DrugFlow{
- WarehousingId: id,
- DrugId: drug_id,
- Number: "",
- BatchNumber: batch_number,
- Count: consumable_count,
- UserOrgId: orgId,
- PatientId: 0,
- SystemTime: locationTime.Unix(),
- ConsumableType: consumable_type,
- IsSys: 1,
- WarehousingOrder: warehousing_order,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: manufacturer,
- Dealer: 0,
- Creator: this.GetAdminUserInfo().AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: id,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: expiry_date,
- ProductDate: 0,
- MaxUnit: min_unit,
- MinUnit: min_unit,
- StorehouseId: storehouse_id,
- OverCount: sum_count,
- }
- if ord_total != new_total {
- service.CreateDrugFlowOne(flow)
- }
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
- }
- }
-
- func (this *SelfDrugApiController) GetDamageByDrugId() {
-
- drug_id, _ := this.GetInt64("drug_id")
- warehousing_order := this.GetString("warehouseing_order")
- drug_type, _ := this.GetInt64("type")
- list, err := service.GetDamageByDrugId(drug_id, warehousing_order, drug_type)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetInventoryModeList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, err := service.GetInventoryModeList(orgId)
- manufacturerList, err := service.GetAllManufacturerList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- })
- }
-
- //库存优化接口
- func (this *SelfDrugApiController) GetStorehouseList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, err := service.GetAllStoreHouseList(orgId)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- goodType, _ := service.GetAllGoodType(orgId)
- patientList, _ := service.GetAllpatient(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取仓库失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "goodTypeList": goodType,
- "patientList": patientList,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodNewQuery() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- storehouse_id, _ := this.GetInt64("storehouse_id")
- good_type, _ := this.GetInt64("good_type")
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
-
- // 查询该机构所有耗材入库信息
- goodList, _ := service.GetAllGoodListSeven(orgId)
-
- for _, it := range goodList {
- var sum_total int64
- //查询该耗材入库信息
- warehouseinfo, _ := service.GetGoodInformationWarehouseInfo(it.ID, orgId)
- for _, item := range warehouseinfo {
- sum_total += item.StockCount
- }
- service.UpdateGoodInformation(it.ID, orgId, sum_total)
- }
-
- var ids []int64
- var goodIds []int64
- manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturerList {
- ids = append(ids, it.ID)
- }
- infoList, _ := service.GetGoodWarehouseInfoByOrgId(orgId, storehouse_id)
- for _, it := range infoList {
- goodIds = append(goodIds, it.GoodId)
- }
-
- stockList, total, err := service.GetGoodStockList(orgId, storehouse_id, good_type, keyword, page, limit, ids)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "stockList": stockList,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodWarehouseOutInfoByIdList() {
-
- good_id, _ := this.GetInt64("good_id")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- start_time := this.GetString("start_first_time")
- end_time := this.GetString("end_first_time")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, total, err := service.GetGoodWarehouseOutInfoByIdList(good_id, limit, page, orgId, startTime, endTime, storehouse_id)
- //flushList, _ := service.GetStockFlushByGoodId(good_id, orgId, startTime, endTime)
-
- //warehouseInfoByList, _ := service.GetGoodWarehouseInfoByList(good_id, orgId, startTime, endTime)
- //cancelStockInfoByList, _ := service.GetGoodCancelStockInfoByList(good_id, orgId, startTime, endTime)
- //warehouseOutByList,_ := service.GetGoodWarehouseOutInfoByIdListTwenty(good_id, limit, page, orgId, startTime, endTime)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- //"warehouseInfoByList":warehouseInfoByList,
- //"cancelStockInfoByList":cancelStockInfoByList,
- //"warehouseOutByList":warehouseOutByList,
- //"flushList":flushList,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodPatientList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
- list, err := service.GetGoodPatientList(orgId, keyword)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *SelfDrugApiController) GetWarehouseOutDetailByPatientId() {
-
- patient_id, _ := this.GetInt64("patient_id")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, total, err := service.GetWarehouseOutDetailByPatientIdOne(orgId, patient_id, startTime, endTime, limit, page)
- outlist, _ := service.GetWarehouseOutDetailByPatientId(orgId, patient_id, startTime, endTime)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "outlist": outlist,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodExpiryDateQuery() {
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
- expiry_type, _ := this.GetInt64("expiry_type")
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- start_time := this.GetString("start_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var endTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- fmt.Scan("parseDateErr", parseDateErr)
- nowtime := recordDate.Unix()
-
- var ids []int64
- var goodIds []int64
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- goodList, _ := service.GetGoodNameByword(orgId, keyword)
- for _, it := range goodList {
- goodIds = append(goodIds, it.ID)
- }
- list, total, err := service.GetGoodExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
- fmt.Println("total233223322332323232323223", total)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "nowtime": nowtime,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodPurchaseStockQuery() {
-
- good_type, _ := this.GetInt64("good_type")
-
- keyword := this.GetString("keyword")
-
- page, _ := this.GetInt64("page")
-
- limit, _ := this.GetInt64("limit")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var goodIds []int64
- infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
- for _, it := range infoList {
- goodIds = append(goodIds, it.GoodId)
- }
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- list, total, err := service.GetGoodPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
- for _, item := range list {
-
- //获取期初结余数量
- infoList, _ := service.GetStartGoodWarehouseInfoList(item.ID, orgId, startTime)
- for _, it := range infoList {
- item.WarehousingInfoStart = append(item.WarehousingInfoStart, it)
- }
-
- //获取期末结余数量
- warehouseInfoList, _ := service.GetEndGoodWarehouseInfoList(item.ID, orgId, endTime)
- for _, it := range warehouseInfoList {
- item.WarehousingInfoEnd = append(item.WarehousingInfoEnd, it)
- }
-
- //获取期间增加
- goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime)
- for _, it := range goodWarehouseInfoList {
- item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
- }
-
- //获取本期增加
- WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime)
- for _, it := range WarehouseInfoFlowList {
- item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
- }
- //获取本期减少
- reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime)
- for _, it := range reduceWarehouseInfoList {
- item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
- }
-
- //获取期中减少退库
- lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime)
- for _, it := range lowInfo {
- item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
- }
- //
- outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime)
- for _, it := range outInfo {
- item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
- }
-
- //获取期初结余
- info, _ := service.FindeStartFlowInfo(item.ID, orgId, startTime)
- for _, it := range info {
- item.StartFlowInfo = append(item.StartFlowInfo, it)
- }
- //获取期初结余
- flowOutInfo, _ := service.FindeStartFlowOutInfo(item.ID, orgId, startTime)
- for _, it := range flowOutInfo {
- item.StartOutFlowInfo = append(item.StartOutFlowInfo, it)
- }
-
- //获取期初退库
- cancelInfo, _ := service.FindeStartCancelInfo(item.ID, orgId, startTime)
- for _, it := range cancelInfo {
- item.StartCancelFlowInfo = append(item.StartCancelFlowInfo, it)
- }
-
- //获取期末结余
- flowInfo, _ := service.FindEndStartFlowInfo(item.ID, orgId, endTime)
- for _, it := range flowInfo {
- item.EndFlowInfo = append(item.EndFlowInfo, it)
- }
-
- //获取期末出库
- lowOutInfo, _ := service.FindeEndFLowOutInfo(item.ID, orgId, endTime)
- for _, it := range lowOutInfo {
- item.EndFlowOutInfo = append(item.EndFlowOutInfo, it)
- }
-
- //获取期末退库
- endCancelInfo, _ := service.FindEndCancelInfo(item.ID, orgId, endTime)
- for _, it := range endCancelInfo {
- item.EndCancelFLowInfo = append(item.EndCancelFLowInfo, it)
- }
-
- //期初盘赢
- inventory, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, startTime)
- for _, it := range inventory {
- item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
- }
- //期初盘亏
- stockInventory, _ := service.FindStartStockInventoryLosses(item.ID, orgId, startTime)
- for _, it := range stockInventory {
- item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
- }
-
- //期末盘盈
- inventoryProfit, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, endTime)
- for _, it := range inventoryProfit {
- item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
- }
- //期末盘亏
- inventoryLosses, _ := service.FindStartStockInventoryLosses(item.ID, orgId, endTime)
- for _, it := range inventoryLosses {
- item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
- }
-
- //期中盘盈
- profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
- //期中盘亏
- losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime)
- for _, it := range losses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugWarehouseOutDetailByPatientId() {
-
- patient_id, _ := this.GetInt64("patient_id")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, total, _ := service.GetDrugWarehouseOutDetailByPatientIdOne(patient_id, orgId, startTime, endTime, page, limit)
- outlist, _ := service.GetDrugWarehouseOutDetailByPatientId(patient_id, orgId, startTime, endTime)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "manufacturerList": manufacturerList,
- "outlist": outlist,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugExpiryDateQuery() {
- storehouse_id, _ := this.GetInt64("storehouse_id")
- expiry_type, _ := this.GetInt64("expiry_type")
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- start_time := this.GetString("start_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var endTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- fmt.Scan("parseDateErr", parseDateErr)
- nowtime := recordDate.Unix()
-
- var ids []int64
- var goodIds []int64
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- drugList, _ := service.GetDrugNameByword(orgId, keyword)
- for _, it := range drugList {
- goodIds = append(goodIds, it.ID)
- }
- list, total, err := service.GetDrugExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "nowtime": nowtime,
- "drugTypeList": drugTypeList,
- })
- }
-
- func (this *SelfDrugApiController) GetPurchaseDrugQuery() {
- good_type, _ := this.GetInt64("good_type")
-
- keyword := this.GetString("keyword")
-
- page, _ := this.GetInt64("page")
-
- limit, _ := this.GetInt64("limit")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
-
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var infoIds []int64
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
- for _, it := range infoList {
- infoIds = append(infoIds, it.DrugId)
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- list, total, err := service.GetDrugPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
-
- for _, item := range list {
-
- //获取期初结余入库数量
- startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
- for _, it := range startDrugInfo {
- item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
- }
-
- //获取期初结余出库数量
- flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
- for _, it := range flowOutList {
- item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
- }
-
- //获取期初结余退库数量
- cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
- for _, it := range cancelInfo {
- item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
- }
-
- //获取期末结余入库数量
- drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
- for _, it := range drugwarehouseinfoend {
- item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
- }
-
- //获取期末出库结余
- endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
- for _, it := range endDrugInfo {
- item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
- }
-
- //获取期末退库数量
- flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
- for _, it := range flowCancelInfo {
- item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
- }
-
- //期中增加
- drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
- for _, it := range drugWarehouse {
- item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
- }
-
- //期中减少
- outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- for _, it := range outInfo {
- item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
- }
-
- //期中退库
- cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- for _, it := range cancelstartInfo {
- item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
- }
-
- //获取期初盘盈
- startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
- for _, it := range startProfit {
- item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
- }
- //获取期初盘亏
- startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
- for _, it := range startLosses {
- item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
- }
- //获取期末盘盈
- endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
- for _, it := range endProfit {
- item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
- }
- //获取期末盘亏
- losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
- for _, it := range losses {
- item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
- }
-
- //获取期中盘盈
- profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
-
- //获取期中盘亏
- endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
- for _, it := range endLosses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "drugTypeList": drugTypeList,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugNewQuery() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- storehouse_id, _ := this.GetInt64("storehouse_id")
- good_type, _ := this.GetInt64("good_type")
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var goodIds []int64
- manufacturerList, _ := service.GetManufacturerListByKeyword(orgId, keyword)
-
- //查询药品库信息
- drug, _ := service.GetBaseDrugName(orgId)
-
- for _, it := range drug {
- var sum_count int64
- var limit_count int64
- drugInfo, _ := service.GetDrugWarehouseInfoName(it.ID, orgId)
- for _, item := range drugInfo {
-
- sum_count += item.StockMaxNumber*it.MinNumber + item.StockMinNumber
- }
- stockInt, _ := strconv.ParseInt(it.DrugStockLimit, 10, 64)
- limit_count = stockInt * it.MinNumber
- service.UpdateDrugById(it.ID, orgId, limit_count, sum_count)
- }
-
- for _, it := range manufacturerList {
- ids = append(ids, it.ID)
- }
- infoList, _ := service.GetDrugWarehouseInfoByOrgId(orgId, storehouse_id)
- for _, it := range infoList {
- goodIds = append(goodIds, it.DrugId)
- }
- //list, total, err := service.GetDrugNewQuery(orgId, storehouse_id, good_type, keyword, page, limit, ids, goodIds, startTime, endTime)
-
- countList, total, err := service.GetDrugStockCountList(orgId, storehouse_id, good_type, keyword, page, limit, ids, goodIds, startTime, endTime)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查询信息失败")
- return
- }
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- //"list": list,
- "drugTypeList": drugTypeList,
- "countList": countList,
- })
- }
-
- func (this *SelfDrugApiController) GetDrugWarehouseInfoById() {
-
- drug_id, _ := this.GetInt64("drug_id")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- start_time := this.GetString("start_first_time")
- end_time := this.GetString("end_first_time")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, total, err := service.GetDrugWarehouseOutInfoByIdList(drug_id, limit, page, orgId, startTime, endTime, storehouse_id)
- flushList, _ := service.GetDrugFlowFlush(drug_id, orgId, startTime, endTime)
- flushOne, _ := service.GetDrugFlowFlushOne(drug_id, orgId, startTime, endTime)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取查寻出库信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "list": list,
- "flushList": flushList,
- "flushListOne": flushOne,
- })
- }
-
- func (this *SelfDrugApiController) GetSendGoodInformation() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- //获取入库数据
- list, _ := service.GetSendGoodInformation(orgId)
- for _, it := range list {
- //查询是否有数据
- _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
- //获取总退库数量
- var cancel_count int64
- var out_count int64
- var act_count int64
- //退库总数量
- cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
- for _, item := range cancellist {
- cancel_count += item.Count
- }
- //出库总数量
- outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
- for _, item := range outlist {
- out_count += item.Count
- }
-
- //实际出库总数量
- actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
- for _, item := range actlist {
- act_count += item.Count
- }
-
- if errcode == gorm.ErrRecordNotFound {
- good := models.XtGoodStockCount{
- UserOrgId: it.OrgId,
- GoodId: it.GoodId,
- StorehouseId: it.StorehouseId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- StockInCount: it.WarehousingCount,
- StockOutCount: out_count - cancel_count,
- StockCancelCount: cancel_count,
- FlushCount: it.StockCount,
- StockActOutCount: act_count,
- }
- service.CreateGoodCountSix(good)
- }
- if errcode == nil {
- service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
- }
-
- func (this *SelfDrugApiController) GetDrugInitDetailList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- //获取所有的入库仓库
- list, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
- for _, item := range list {
- //查询该药品该仓库是否有数据
- drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
-
- //查询该仓库该药品的入库数量
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
-
- var sum_in_count int64
- var flush_count int64
- var sum_out_count int64
- var cancel_out_count int64
- //查询入库数量和剩余库存
- infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
- for _, it := range infolist {
- if it.MaxUnit == medical.MaxUnit {
- it.WarehousingCount = it.WarehousingCount * medical.MinNumber
- it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
- }
- sum_in_count += it.WarehousingCount
- flush_count += it.StockMaxNumber + it.StockMinNumber
- }
-
- //获取出库数量
- outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
- for _, it := range outinfolist {
- if it.MaxUnit == medical.MaxUnit {
- it.Count = it.Count * medical.MinNumber
- }
- sum_out_count += it.Count
- }
-
- //获取退库数量
- cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
- for _, it := range cancelinfolist {
- if it.MaxUnit == medical.MaxUnit {
- it.Count = it.Count * medical.MinNumber
- }
- cancel_out_count += it.Count
- }
-
- //新增
- if drug.ID == 0 {
- drugstock := models.XtDrugStockCount{
- UserOrgId: orgId,
- StorehouseId: item.StorehouseId,
- SumInCount: sum_in_count,
- SumOutCount: sum_out_count - cancel_out_count,
- SumCancelCount: cancel_out_count,
- DrugId: item.DrugId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- FlushCount: flush_count,
- SumActOutCount: sum_out_count,
- }
- service.CreateDrugStockCount(drugstock)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
- }
-
- func (this *SelfDrugApiController) GetGoodNewPurchaseStockQuery() {
-
- good_type, _ := this.GetInt64("good_type")
-
- keyword := this.GetString("keyword")
-
- page, _ := this.GetInt64("page")
-
- limit, _ := this.GetInt64("limit")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
-
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var goodIds []int64
- infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
- for _, it := range infoList {
- goodIds = append(goodIds, it.GoodId)
- }
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- list, total, err := service.GetGoodNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, ids, goodIds)
-
- for _, item := range list {
-
- //获取期初结余
- low, _ := service.GetStartLastFLow(item.ID, orgId, startTime)
-
- item.GoodStartFlowInfo = low
-
- //获取期末结余
- flow, _ := service.GetEndLastFlow(item.ID, orgId, endTime)
-
- item.GoodEndFlowInfo = flow
-
- //获取期初结余数量
- //infoList, _ := service.GetStartGoodWarehouseInfoList(item.ID, orgId, startTime)
- //for _, it := range infoList {
- // item.WarehousingInfoStart = append(item.WarehousingInfoStart, it)
- //}
- //
- ////获取期末结余数量
- //warehouseInfoList, _ := service.GetEndGoodWarehouseInfoList(item.ID, orgId, endTime)
- //for _, it := range warehouseInfoList {
- // item.WarehousingInfoEnd = append(item.WarehousingInfoEnd, it)
- //}
-
- //获取期间增加
- goodWarehouseInfoList, _ := service.GetAddGoodWarehouseInfoList(item.ID, orgId, startTime, endTime)
- for _, it := range goodWarehouseInfoList {
- item.WarehousingInfoOne = append(item.WarehousingInfoOne, it)
- }
-
- //获取本期增加
- WarehouseInfoFlowList, _ := service.GetAddStartFlow(item.ID, orgId, startTime, endTime)
- for _, it := range WarehouseInfoFlowList {
- item.StartFlowWarehouseInfo = append(item.StartFlowWarehouseInfo, it)
- }
- //获取本期减少
- reduceWarehouseInfoList, _ := service.GetReduceWarehouseInfoList(item.ID, orgId, startTime, endTime)
- for _, it := range reduceWarehouseInfoList {
- item.WarehouseOutInfoStart = append(item.WarehouseOutInfoStart, it)
- }
-
- //获取期中减少退库
- lowInfo, _ := service.GetStartEndCancelFLowInfo(item.ID, orgId, startTime, endTime)
- for _, it := range lowInfo {
- item.StartEndCancelFLowInfo = append(item.StartEndCancelFLowInfo, it)
- }
- //
- outInfo, _ := service.FindeWarehouseOutInfo(item.ID, orgId, startTime)
- for _, it := range outInfo {
- item.WarehouseOutInfoEnd = append(item.WarehouseOutInfoEnd, it)
- }
-
- ////获取期初结余
- //info, _ := service.FindeStartFlowInfo(item.ID, orgId, startTime)
- //for _, it := range info {
- // item.StartFlowInfo = append(item.StartFlowInfo, it)
- //}
- ////获取期初结余
- //flowOutInfo, _ := service.FindeStartFlowOutInfo(item.ID, orgId, startTime)
- //for _, it := range flowOutInfo {
- // item.StartOutFlowInfo = append(item.StartOutFlowInfo, it)
- //}
- //
- ////获取期初退库
- //cancelInfo, _ := service.FindeStartCancelInfo(item.ID, orgId, startTime)
- //for _, it := range cancelInfo {
- // item.StartCancelFlowInfo = append(item.StartCancelFlowInfo, it)
- //}
-
- ////获取期末结余
- //flowInfo, _ := service.FindEndStartFlowInfo(item.ID, orgId, endTime)
- //for _, it := range flowInfo {
- // item.EndFlowInfo = append(item.EndFlowInfo, it)
- //}
- //
- ////获取期末出库
- //lowOutInfo, _ := service.FindeEndFLowOutInfo(item.ID, orgId, endTime)
- //for _, it := range lowOutInfo {
- // item.EndFlowOutInfo = append(item.EndFlowOutInfo, it)
- //}
- //
- ////获取期末退库
- //endCancelInfo, _ := service.FindEndCancelInfo(item.ID, orgId, endTime)
- //for _, it := range endCancelInfo {
- // item.EndCancelFLowInfo = append(item.EndCancelFLowInfo, it)
- //}
-
- ////期初盘赢
- //inventory, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, startTime)
- //for _, it := range inventory {
- // item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
- //}
- ////期初盘亏
- //stockInventory, _ := service.FindStartStockInventoryLosses(item.ID, orgId, startTime)
- //for _, it := range stockInventory {
- // item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
- //}
-
- ////期末盘盈
- //inventoryProfit, _ := service.FindeStartStockInventoryProfit(item.ID, orgId, endTime)
- //for _, it := range inventoryProfit {
- // item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
- //}
- ////期末盘亏
- //inventoryLosses, _ := service.FindStartStockInventoryLosses(item.ID, orgId, endTime)
- //for _, it := range inventoryLosses {
- // item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
- //}
-
- //期中盘盈
- profit, _ := service.FindeEndStokInventoryProfit(item.ID, orgId, startTime, endTime)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
- //期中盘亏
- losses, _ := service.FindeEndStockInventoryLosses(item.ID, orgId, startTime, endTime)
- for _, it := range losses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- })
- }
-
- func (this *SelfDrugApiController) GetPurchaseNewDrugQuery() {
-
- good_type, _ := this.GetInt64("good_type")
-
- keyword := this.GetString("keyword")
-
- page, _ := this.GetInt64("page")
-
- limit, _ := this.GetInt64("limit")
-
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
-
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var ids []int64
- var infoIds []int64
-
- manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
- for _, it := range manufacturers {
- ids = append(ids, it.ID)
- }
- infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
- for _, it := range infoList {
- infoIds = append(infoIds, it.DrugId)
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- list, total, err := service.GetDrugNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
-
- for _, item := range list {
-
- //获取期初结余
- flow, _ := service.GetDrugStartFlow(item.ID, orgId, startTime)
-
- item.DrugStatFlow = flow
-
- //获取期末结余
- endFlow, _ := service.GetDrugEndFlow(item.ID, orgId, endTime)
-
- item.DrugEndFlow = endFlow
- //获取期初结余入库数量
- //startDrugInfo, _ := service.GetDrugWarehouseInfoStart(item.ID, orgId, startTime)
- //for _, it := range startDrugInfo {
- // item.DrugWarehouseInfoStart = append(item.DrugWarehouseInfoStart, it)
- //}
- //
- ////获取期初结余出库数量
- //flowOutList, _ := service.GetDrugFlowOut(item.ID, orgId, startTime)
- //for _, it := range flowOutList {
- // item.DrugWarehouseOutInfoStart = append(item.DrugWarehouseOutInfoStart, it)
- //}
- //
- ////获取期初结余退库数量
- //cancelInfo, _ := service.GetStartDrugFlowCancelInfo(item.ID, orgId, startTime)
- //for _, it := range cancelInfo {
- // item.WareStartStockCancelInfo = append(item.WareStartStockCancelInfo, it)
- //}
- //
- ////获取期末结余入库数量
- //drugwarehouseinfoend, _ := service.DrugWarehouseInfoEnd(item.ID, orgId, endTime)
- //for _, it := range drugwarehouseinfoend {
- // item.DrugWarehouseInfoEnd = append(item.DrugWarehouseInfoEnd, it)
- //}
-
- ////获取期末出库结余
- //endDrugInfo, _ := service.DrugWarehouseOutInfoEnd(item.ID, orgId, endTime)
- //for _, it := range endDrugInfo {
- // item.DrugWarehouseOutInfoEnd = append(item.DrugWarehouseOutInfoEnd, it)
- //}
- //
- ////获取期末退库数量
- //flowCancelInfo, _ := service.GetEndDrugFlowCancelInfo(item.ID, orgId, endTime)
- //for _, it := range flowCancelInfo {
- // item.WareEndStockCancelInfo = append(item.WareEndStockCancelInfo, it)
- //}
-
- //期中增加
- drugWarehouse, _ := service.GetDrugWarehouseStartEnd(item.ID, orgId, startTime, endTime)
- for _, it := range drugWarehouse {
- item.DrugWarehouseInfoStartEnd = append(item.DrugWarehouseInfoStartEnd, it)
- }
-
- //期中减少
- outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- for _, it := range outInfo {
- item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
- }
-
- //期中退库
- cancelstartInfo, _ := service.FindStartEndDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
- for _, it := range cancelstartInfo {
- item.WareStartEndStockCancelInfo = append(item.WareStartEndStockCancelInfo, it)
- }
-
- ////获取期初盘盈
- //startProfit, _ := service.GetDrugFlowStartProfit(item.ID, orgId, startTime)
- //for _, it := range startProfit {
- // item.WareStartStockInventoryProfit = append(item.WareStartStockInventoryProfit, it)
- //}
- ////获取期初盘亏
- //startLosses, _ := service.GetDrugFlowStartLosses(item.ID, orgId, startTime)
- //for _, it := range startLosses {
- // item.WareStartStockInventoryLosses = append(item.WareStartStockInventoryLosses, it)
- //}
- ////获取期末盘盈
- //endProfit, _ := service.GetDrugFlowEndProfit(item.ID, orgId, endTime)
- //for _, it := range endProfit {
- // item.WareEndStockInventoryProfit = append(item.WareEndStockInventoryProfit, it)
- //}
- ////获取期末盘亏
- //losses, _ := service.GetDrugFlowEndLosses(item.ID, orgId, endTime)
- //for _, it := range losses {
- // item.WareEndStockInventoryLosses = append(item.WareEndStockInventoryLosses, it)
- //}
-
- //获取期中盘盈
- profit, _ := service.GetDrugFlowStartEndProfit(item.ID, orgId, startTime, endTime)
- for _, it := range profit {
- item.WareStartEndStockInventoryProfit = append(item.WareStartEndStockInventoryProfit, it)
- }
-
- //获取期中盘亏
- endLosses, _ := service.GetDrugFlowStartEndLosses(item.ID, orgId, startTime, endTime)
- for _, it := range endLosses {
- item.WareStartEndStockInventoryLosses = append(item.WareStartEndStockInventoryLosses, it)
- }
- }
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取患者信息失败")
- return
- }
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "total": total,
- "drugTypeList": drugTypeList,
- })
- }
-
- func (this *SelfDrugApiController) GetGoodOverCount() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetAllStockCount(orgId)
- for _, item := range list {
- flow, _ := service.GetLastStockFlow(item.GoodId)
- service.ModifyStockFlowById(flow.ID, item.FlushCount)
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) GetDrugOverCount() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetAllDrugCount(orgId)
- for _, item := range list {
- service.GetLastDrugFlow(item.DrugId)
- service.ModifyDrugFlowById(item.ID, item.FlushCount)
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *SelfDrugApiController) GetDrugInventoryWarehouseInfoList() {
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetDrugInventoryWarehouseInfoList(orgId, storehouse_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- }
|