self_drug_api_congtroller.go 121KB

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