12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797 |
- package controllers
- import (
- "Medical_ERP/common/actions"
- "Medical_ERP/common/global"
- _ "Medical_ERP/common/response"
- "Medical_ERP/dto"
- "Medical_ERP/models"
- "Medical_ERP/services"
- "Medical_ERP/utils"
- "baliance.com/gooxml/color"
- "baliance.com/gooxml/document"
- "baliance.com/gooxml/measurement"
- "baliance.com/gooxml/schema/soo/wml"
- "errors"
- "fmt"
- context2 "github.com/beego/beego/v2/adapter/context"
- "github.com/beego/beego/v2/core/logs"
- "github.com/boombuler/barcode"
- "github.com/boombuler/barcode/code128"
- "github.com/ser163/png2j"
- "github.com/signintech/gopdf"
- "github.com/xuri/excelize/v2"
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
- "image/jpeg"
- "log"
- "path"
- "strings"
- _ "image/jpeg"
- "image/png"
- "os"
- "time"
- )
- type StockTemplateController struct {
- BaseController
- }
- // StockTemplateIn 入库
- // @Summary 入库
- // @Description 入库
- // @Tags 库存
- // @Param body body dto.StockTemplateInInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateIn() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateInInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- reqData.State = models.StateStockRefundIn
- err := s.StockTemplateIn(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "入库成功")
- }
- // StockTemplateInScanCode 扫码入库
- // @Summary 扫码入库
- // @Description 扫码入库
- // @Tags 库存
- // @Param body body dto.StockTemplateInInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateInScanCode() {
- s := services.StockTemplate{}
- reqData := dto.BatchStockTemplateInInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- reqData.State = models.StateStockIn
- err := s.StockTemplateInScanCode(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(nil, "扫码入库成功")
- }
- // StockTemplateInEdit 修改入库
- // @Summary 修改入库
- // @Description 修改入库
- // @Tags 库存
- // @Param body body dto.StockTemplateInEditReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateInEdit() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateInEditReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- err := s.StockTemplateInEdit(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "修改入库信息成功")
- }
- // StockTemplateInDelete 删除入库
- // @Summary 删除入库
- // @Description 删除入库
- // @Tags 库存
- // @Param body body dto.StockTemplateInDeleteReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateInDelete() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateInDeleteReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- err := s.StockTemplateInDelete(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "删除入库信息成功")
- }
- // BatchStockTemplateIn 批量入库
- // @Summary 批量入库
- // @Description 批量入库
- // @Tags 库存
- // @Param body body dto.BatchStockTemplateInInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) BatchStockTemplateIn() {
- s := services.StockTemplate{}
- reqData := dto.BatchStockTemplateInInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- reqData.State = models.StateStockIn
- err := s.BatchStockTemplateIn(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(nil, "入库成功")
- }
- // StockTemplateRefundIn 退货入库
- // @Summary 退货入库
- // @Description 退货入库
- // @Tags 库存
- // @Param body body dto.StockTemplateInInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateRefundIn() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateInInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- reqData.State = models.StateStockRefundIn
- err := s.StockTemplateIn(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "入库成功")
- }
- // StockTemplateRefundInScanCode 扫码退货入库
- // @Summary 扫码入库
- // @Description 扫码入库
- // @Tags 库存
- // @Param body body dto.StockTemplateInInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateRefundInScanCode() {
- s := services.StockTemplate{}
- reqData := dto.BatchStockTemplateInInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- reqData.State = models.StateStockRefundIn
- err := s.StockTemplateInScanCode(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(nil, "扫码退货入库成功")
- }
- // BatchStockTemplateRefundIn 批量退货入库
- // @Summary 批量退货入库
- // @Description 批量退货入库
- // @Tags 库存
- // @Param body body dto.BatchStockTemplateInInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) BatchStockTemplateRefundIn() {
- s := services.StockTemplate{}
- reqData := dto.BatchStockTemplateInInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- reqData.State = models.StateStockRefundIn
- err := s.BatchStockTemplateIn(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(nil, "入库成功")
- }
- // StockTemplateOut 出库
- // @Summary 出库
- // @Description 出库
- // @Tags 库存
- // @Param body body dto.StockTemplateOutInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/out [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateOut() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateOutInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- reqData.State = models.StateStockOut
- err := s.StockTemplateOut(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "出库成功")
- }
- // StockTemplateOutScanCode 扫码出库
- // @Summary 扫码出库
- // @Description 扫码出库
- // @Tags 库存
- // @Param body body dto.StockTemplateOutInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/out [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateOutScanCode() {
- s := services.StockTemplate{}
- reqData := dto.BatchStockTemplateOutInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- logs.Debug("【扫码出库】请求信息 %v", reqData)
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- reqData.State = models.StateStockOut
- err := s.StockTemplateOutScanCode(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(nil, "扫码出库成功")
- }
- // StockTemplateOutEdit 修改入库
- // @Summary 修改入库
- // @Description 修改入库
- // @Tags 库存
- // @Param body body dto.StockTemplateOutEditReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateOutEdit() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateOutEditReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- err := s.StockTemplateOutEdit(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "修改出库信息成功")
- }
- // StockTemplateOutDelete 删除入库
- // @Summary 删除入库
- // @Description 删除入库
- // @Tags 库存
- // @Param body body dto.StockTemplateOutDeleteReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/in [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateOutDelete() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateOutDeleteReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- err := s.StockTemplateOutDelete(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "删除出库信息成功")
- }
- // BatchStockTemplateOut 批量出库
- // @Summary 批量出库
- // @Description 批量出库
- // @Tags 库存
- // @Param body body dto.StockTemplateOutInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/out [post]
- // @Security Bearer
- func (c StockTemplateController) BatchStockTemplateOut() {
- s := services.StockTemplate{}
- reqData := dto.BatchStockTemplateOutInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- reqData.State = models.StateStockOut
- err := s.BatchStockTemplateOut(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(nil, "出库成功")
- }
- // StockTemplateRefundOut 退货/报废出库
- // @Summary 退货/报废出库
- // @Description 退货/报废出库
- // @Tags 库存
- // @Param body body dto.StockTemplateOutInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/out [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateRefundOut() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateOutInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- if reqData.State != models.StateStockRefundOut && reqData.State != models.StateStockScrapOut {
- err := errors.New("出库状态错误")
- c.Error(500, err, err.Error())
- return
- }
- err := s.StockTemplateOut(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "退货(报废)出库成功")
- }
- // StockTemplateOutScanRefundCode 扫码退货/报废出库
- // @Summary 扫码退货/报废出库
- // @Description 扫码退货/报废出库
- // @Tags 库存
- // @Param body body dto.StockTemplateOutInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/out [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateRefundOutScanCode() {
- s := services.StockTemplate{}
- reqData := dto.BatchStockTemplateOutInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- if reqData.State != models.StateStockRefundOut && reqData.State != models.StateStockScrapOut {
- err := errors.New("出库状态错误")
- c.Error(500, err, err.Error())
- return
- }
- err := s.StockTemplateOutScanCode(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(nil, "扫码退货(报废)出库成功")
- }
- // BatchStockTemplateRefundOut 批量退货/报废出库
- // @Summary 批量退货/报废出库
- // @Description 批量退货/报废出库
- // @Tags 库存
- // @Param body body dto.StockTemplateOutInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/out [post]
- // @Security Bearer
- func (c StockTemplateController) BatchStockTemplateRefundOut() {
- s := services.StockTemplate{}
- reqData := dto.BatchStockTemplateOutInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- if reqData.State != models.StateStockRefundOut && reqData.State != models.StateStockScrapOut {
- err := errors.New("出库状态错误")
- c.Error(500, err, err.Error())
- return
- }
- err := s.BatchStockTemplateOut(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(nil, "退货(报废)出库成功")
- }
- // StockTemplateInList 入库列表
- // @Summary 入库列表
- // @Description 入库列表
- // @Tags 库存
- // @Param body body dto.StockTemplateInPageReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/in/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateInList() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateInPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, count, err := s.StockTemplateInList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
- }
- // StockTemplateOutList 出库列表
- // @Summary 出库列表
- // @Description 出库列表
- // @Tags 库存
- // @Param body body dto.StockTemplateOutPageReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/out/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateOutList() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateOutPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, count, err := s.StockTemplateOutList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
- }
- // StockTemplateInventoryList 收发记录
- // @Summary 收发记录
- // @Description 收发记录
- // @Tags 库存
- // @Param body body dto.StockTemplateInventoryPageReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock/inventory/list [post]
- // @Security Bearer—
- func (c StockTemplateController) StockTemplateInventoryList() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateInventoryPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, count, err := s.StockTemplateInventoryList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
- }
- // StockTemplateInventoryExcel 收发登记表
- // @Summary 收发登记表
- // @Description 收发登记表
- // @Tags 库存
- // @Param body body dto.StockTemplateInventoryExcelReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/inventory/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateInventoryExcel(reqData dto.StockTemplateInventoryExcelReq) {
- s := services.StockTemplate{}
- deptId := beegouser.GetDeptId(c.Ctx)
- models.InitBasicData(deptId)
- medicineInfo, _, err := s.GetMedicineInfo(deptId, map[string]interface{}{
- "product_id": reqData.ProductID,
- "enterprise_id": reqData.EnterpriseID,
- "spec_id": reqData.SpecId,
- "batch_number": reqData.BatchNumber,
- })
- if err != nil {
- c.Error(global.BadRequest, err, "药品信息不存在")
- return
- }
- var productName, specName, unitName, dosageFormName string
- if id, ok := medicineInfo[models.FieldProductID]; ok {
- productName = models.Read_Product_Get(utils.ToInt(id))
- }
- if id, ok := medicineInfo[models.FieldSpecID]; ok {
- specName = models.Read_Spec_Get(utils.ToInt(id))
- }
- if id, ok := medicineInfo[models.FieldUnitID]; ok {
- unitName = models.Read_Unit_Get(utils.ToInt(id))
- }
- if id, ok := medicineInfo[models.FieldDosageFormID]; ok {
- dosageFormName = models.Read_DosageForm_Get(utils.ToInt(id))
- }
- list, err := s.StockTemplateInventoryExcel(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- f := excelize.NewFile() // 设置单元格的值
- StyleTitle, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
- })
- f.MergeCell("Sheet1", "A1", "O1")
- f.SetRowStyle("Sheet1", 1, 1, StyleTitle)
- f.SetRowHeight("Sheet1", 1, 50)
- var interval string
- if len(reqData.StartDate) > 0 && len(reqData.EndDate) > 0 {
- interval = fmt.Sprintf("%s至%s", reqData.StartDate, reqData.EndDate)
- }
- f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%s收发登记表", interval))
- StyleLittleTitle, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, Family: "宋体"},
- })
- f.SetCellValue("Sheet1", "K2", fmt.Sprintf("制品名称:%s", productName))
- f.SetCellValue("Sheet1", "K3", fmt.Sprintf("剂型:%s 规格:%s 单位:%s", dosageFormName, specName, unitName))
- f.SetRowStyle("Sheet1", 2, 3, StyleLittleTitle)
- // 这里设置表头
- f.MergeCell("Sheet1", "A4", "A5")
- f.SetCellValue("Sheet1", "A4", "日期")
- f.MergeCell("Sheet1", "B4", "B5")
- f.SetCellValue("Sheet1", "B4", "购货/发货单位")
- f.MergeCell("Sheet1", "C4", "C5")
- f.SetCellValue("Sheet1", "C4", "生产企业")
- f.MergeCell("Sheet1", "D4", "D5")
- f.SetCellValue("Sheet1", "D4", "批准文号")
- f.MergeCell("Sheet1", "E4", "E5")
- f.SetCellValue("Sheet1", "E4", "批签发合格证编号")
- f.MergeCell("Sheet1", "F4", "H4")
- f.SetCellValue("Sheet1", "F4", "收入")
- f.SetCellValue("Sheet1", "F5", "数量")
- f.SetCellValue("Sheet1", "G5", "批号")
- f.SetCellValue("Sheet1", "H5", "失效日期")
- f.MergeCell("Sheet1", "I4", "K4")
- f.SetCellValue("Sheet1", "I4", "支出")
- f.SetCellValue("Sheet1", "I5", "数量")
- f.SetCellValue("Sheet1", "J5", "批号")
- f.SetCellValue("Sheet1", "K5", "失效日期")
- f.MergeCell("Sheet1", "L4", "N4")
- f.SetCellValue("Sheet1", "L4", "结余")
- f.SetCellValue("Sheet1", "L5", "数量")
- f.SetCellValue("Sheet1", "M5", "批号")
- f.SetCellValue("Sheet1", "N5", "失效日期")
- f.MergeCell("Sheet1", "O4", "O5")
- f.SetCellValue("Sheet1", "O4", "经办人签字")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "B", 10)
- f.SetColWidth("Sheet1", "B", "C", 14)
- f.SetColWidth("Sheet1", "C", "F", 12)
- f.SetColWidth("Sheet1", "F", "G", 8)
- f.SetColWidth("Sheet1", "G", "I", 12)
- f.SetColWidth("Sheet1", "I", "J", 8)
- f.SetColWidth("Sheet1", "J", "L", 12)
- f.SetColWidth("Sheet1", "L", "M", 8)
- f.SetColWidth("Sheet1", "M", "O", 12)
- f.SetColWidth("Sheet1", "O", "P", 12)
- line := 5
- // 循环写入数据
- for _, v := range list {
- line++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v["date"])
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v[models.FieldEnterpriseName])
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v[models.FieldApprovalNumber])
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldQualificationNumber])
- if utils.ToInt(v["stock_in_id"]) > 0 {
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v["forwarding_unit"])
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), utils.ToInt(v["total_in"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v[models.FieldApprovalNumber])
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToDate(v[models.FieldExpiryDate]))
- }
- if utils.ToInt(v["stock_out_id"]) > 0 {
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v["receiving_unit"])
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), utils.ToInt(v["total_out"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v[models.FieldApprovalNumber])
- f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), utils.ToDate(v[models.FieldExpiryDate]))
- }
- f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), utils.ToInt(v["balance"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), v[models.FieldApprovalNumber])
- f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), utils.ToDate(v[models.FieldExpiryDate]))
- f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), v["operator"])
- }
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line+1), "保管单位:"+beegouser.GetDeptName(c.Ctx))
- f.SetRowStyle("Sheet1", line+1, line+1, StyleLittleTitle)
- Style1, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 13, Family: "宋体", Bold: true},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.SetCellStyle("Sheet1", "A4", "O5", Style1)
- Style2, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.SetCellStyle("Sheet1", "A6", fmt.Sprintf("O%d", line), Style2)
- filename := "收发登记表" + time.Now().Format("20060102150405") + ".xlsx"
- // 保存文件
- if err := f.SaveAs("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- func (c StockTemplateController) StockTemplateInventoryPdf(reqData dto.StockTemplateInventoryExcelReq) {
- s := services.StockTemplate{}
- deptId := beegouser.GetDeptId(c.Ctx)
- models.InitBasicData(deptId)
- medicineInfo, _, err := s.GetMedicineInfo(deptId, map[string]interface{}{
- "product_id": reqData.ProductID,
- "enterprise_id": reqData.EnterpriseID,
- "spec_id": reqData.SpecId,
- "batch_number": reqData.BatchNumber,
- })
- if err != nil {
- c.Error(global.BadRequest, err, "药品信息不存在")
- return
- }
- var productName, specName, unitName, dosageFormName string
- if id, ok := medicineInfo[models.FieldProductID]; ok {
- productName = models.Read_Product_Get(utils.ToInt(id))
- }
- if id, ok := medicineInfo[models.FieldSpecID]; ok {
- specName = models.Read_Spec_Get(utils.ToInt(id))
- }
- if id, ok := medicineInfo[models.FieldUnitID]; ok {
- unitName = models.Read_Unit_Get(utils.ToInt(id))
- }
- if id, ok := medicineInfo[models.FieldDosageFormID]; ok {
- dosageFormName = models.Read_DosageForm_Get(utils.ToInt(id))
- }
- list, err := s.StockTemplateInventoryExcel(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- //cols := []float64{20, 24, 20, 18, 20, 12, 22, 20, 12, 22, 20, 12, 22, 20, 15}
- cols := []float64{58, 73, 59, 53, 53, 35, 65, 59, 40}
- cols1 := []float64{58, 73, 59, 53, 53, 35, 65, 59, 35, 65, 59, 35, 65, 59, 40}
- rows := [][]string{}
- for _, row := range list {
- temp := []string{}
- temp = append(temp, fmt.Sprintf("%v", row["date"]))
- if utils.ToInt(row["stock_in_id"]) > 0 {
- temp = append(temp, fmt.Sprintf("%s", row["forwarding_unit"]))
- } else if utils.ToInt(row["stock_out_id"]) > 0 {
- temp = append(temp, fmt.Sprintf("%s", row["receiving_unit"]))
- }
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
- if row[models.FieldApprovalNumber] != nil {
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
- } else {
- temp = append(temp, "")
- }
- if row[models.FieldQualificationNumber] != nil {
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldQualificationNumber]))
- } else {
- temp = append(temp, "")
- }
- if utils.ToInt(row["stock_in_id"]) > 0 {
- temp = append(temp, fmt.Sprintf("%d", row["total_in"]))
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
- temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
- } else {
- temp = append(temp, "")
- temp = append(temp, "")
- temp = append(temp, "")
- }
- if utils.ToInt(row["stock_out_id"]) > 0 {
- temp = append(temp, fmt.Sprintf("%d", row["total_out"]))
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
- temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
- } else {
- temp = append(temp, "")
- temp = append(temp, "")
- temp = append(temp, "")
- }
- temp = append(temp, fmt.Sprintf("%d", row["balance"]))
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
- temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
- temp = append(temp, fmt.Sprintf("%s", row["operator"]))
- rows = append(rows, temp)
- }
- pdf := &gopdf.GoPdf{}
- pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 841.89, H: 595.28}})
- pdf.SetMarginTop(20)
- pdf.SetMarginBottom(40)
- pdf.AddPage()
- pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
- pdf.SetFont("simsun", "", 22)
- titleStr := "收发登记表"
- titleWd, _ := pdf.MeasureTextWidth(titleStr)
- pdf.SetX((842 / 2) - (titleWd / 2))
- pdf.SetY(70)
- pdf.Text(titleStr)
- pdf.SetFont("simsun", "", 10)
- x := 20.
- for i := 0; i < 9; i++ {
- x += cols1[i]
- }
- pdf.SetXY(x, 90)
- pdf.Text(fmt.Sprintf("制品名称:%s 编号", productName))
- pdf.SetXY(x, 110)
- pdf.Text(fmt.Sprintf("剂型:%s 规格:%s 单位:%s", dosageFormName, specName, unitName))
- curx := 16.
- header := []string{"日期", "购货/发货单位", "生产企业", "批准文号", "批签发合格证编号", "收入", "支出", "结余", "经办人签字"}
- h := 50.0
- pdf.SetFont("simsun", "", 11)
- x = curx
- y := 116.
- pdf.SetXY(curx, y)
- for i := 0; i < len(header); i++ {
- utils.RectFillColorMultiCell(pdf, header[i], 11, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- if header[i] == "收入" || header[i] == "支出" || header[i] == "结余" {
- utils.RectFillColorMultiCell(pdf, header[i], 11, x, y, cols[5]+cols[6]+cols[7], h/2, 0, 0, 0, gopdf.Center, gopdf.Middle)
- utils.RectFillColorMultiCell(pdf, "数量", 11, x, y+h/2, cols[5], h/2, 0, 0, 0, gopdf.Center, gopdf.Middle)
- utils.RectFillColorMultiCell(pdf, "批号", 11, x+cols[5], y+h/2, cols[6], h/2, 0, 0, 0, gopdf.Center, gopdf.Middle)
- utils.RectFillColorMultiCell(pdf, "效期", 11, x+cols[5]+cols[6], y+h/2, cols[7], h/2, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += cols[5] + cols[6] + cols[7]
- } else {
- x += cols[i]
- }
- }
- pdf.SetFont("simsun", "", 10)
- y += h
- pdf.SetXY(curx, y)
- h = 20.0
- for _, row := range rows {
- y = pdf.GetY()
- x = curx
- height := h
- for j, txt := range row {
- lineTexts, _ := pdf.SplitText(txt, cols1[j])
- if len(lineTexts) > 1 {
- lineTexts, _ = pdf.SplitText(txt, cols1[j]-4)
- lineHt := h * float64(len(lineTexts)) * 0.8
- if lineHt > height {
- height = lineHt
- }
- }
- }
- for i, txt := range row {
- width := cols1[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y+height, height)
- }
- filename := "收发登记表" + time.Now().Format("20060102150405") + ".pdf"
- // 保存文件
- if err := pdf.WritePdf("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- func (c StockTemplateController) StockTemplateInventoryExport() {
- reqData := dto.StockTemplateInventoryExcelReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- if reqData.Type == "excel" {
- c.StockTemplateInventoryExcel(reqData)
- }
- if reqData.Type == "pdf" {
- c.StockTemplateInventoryPdf(reqData)
- }
- }
- func (c StockTemplateController) TransportRecordWord(reqData models.TransportRecord) {
- s := services.StockTemplate{}
- deptId := beegouser.GetDeptId(c.Ctx)
- list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- doc := document.New()
- // 获取文档的默认页面设置
- doc.BodySection().SetPageMargins(
- 0.3*measurement.Inch,
- 0.4*measurement.Inch,
- 0.5*measurement.Inch,
- 0.3*measurement.Inch,
- 1*measurement.Inch,
- 0.4*measurement.Inch,
- 0.1*measurement.Inch)
- ftr := doc.AddFooter()
- para := ftr.AddParagraph()
- //para.Properties().AddTabStop(0.1*measurement.Inch, wml.ST_TabJcCenter, wml.ST_TabTlcNone)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run := para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddTab()
- run.AddText("第 ")
- run.AddFieldWithFormatting(document.FieldCurrentPage, "", false)
- run.AddText(" 页 / 共 ")
- run.AddFieldWithFormatting(document.FieldNumberOfPages, "", false)
- run.AddText(" 页")
- //doc.BodySection().SetFooter(ftr, wml.ST_HdrFtrDefault)
- para = doc.AddParagraph()
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetBold(true)
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(14)
- para.Properties().Spacing().SetLineSpacing(18*measurement.Point, wml.ST_LineSpacingRuleAuto)
- run.AddText("表3-4 运输记录表")
- para = doc.AddParagraph()
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(12)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- para.Properties().Spacing().SetLineSpacing(30*measurement.Point, wml.ST_LineSpacingRuleAuto)
- run.AddText("(各级通用)")
- para = doc.AddParagraph()
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- para.Properties().SetAlignment(wml.ST_JcLeft)
- para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
- run.AddText("运输工具: □冷藏车 □运输车 □普通车辆 □无 □其他")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- para = doc.AddParagraph()
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- para.Properties().SetAlignment(wml.ST_JcLeft)
- para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
- run.AddText("冷藏工具: □冷藏车 □车载冷藏箱 □冷藏箱或冷藏包 □其他")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- para = doc.AddParagraph()
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- para.Properties().SetAlignment(wml.ST_JcLeft)
- para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
- run.AddText("配送方式: □本级配送(车牌号:")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(") □下级自运(车牌号:")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(")")
- // --------------------运输情况
- para = doc.AddParagraph()
- para.Properties().SetAlignment(wml.ST_JcLeft)
- run = para.AddRun()
- run.Properties().SetBold(true)
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("运输情况:")
- table := doc.AddTable()
- table.Properties().SetLayout(wml.ST_TblLayoutTypeFixed)
- table.Properties().SetWidthPercent(100)
- look := table.Properties().TableLook()
- look.SetFirstColumn(true)
- look.SetFirstRow(true)
- look.SetHorizontalBanding(true)
- // width of the page
- // with thick borers
- borders := table.Properties().Borders()
- //borders.SetBottom(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
- //borders.SetLeft(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
- //borders.SetRight(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
- //borders.SetTop(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
- borders.SetAll(wml.ST_BorderSingle, color.Auto, measurement.Zero)
- //borders.SetInsideVertical(wml.ST_BorderSingle, color.Auto, measurement.Zero)
- row := table.AddRow()
- row.Properties().SetHeight(0.35*measurement.Inch, wml.ST_HeightRuleExact)
- cell := row.AddCell()
- cell.Properties().SetWidthPercent(15)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(9)
- run.AddText("品名")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(12)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(9)
- run.AddText("生产企业")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(9)
- run.AddText("批准文号")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(15)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(9)
- run.AddText("批签发合格编号")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(13)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(9)
- run.AddText("规格(剂/支或粒)")
- //cell = row.AddCell()
- //cell.Properties().SetWidth(0.5 * measurement.Inch)
- //para = cell.AddParagraph()
- //cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- //para.Properties().SetAlignment(wml.ST_JcCenter)
- //run = para.AddRun()
- //run.Properties().SetFontFamily("宋体")
- //run.Properties().SetSize(8)
- //run.AddText("生产日期")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(12)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(9)
- run.AddText("批号")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(9)
- run.AddText("失效日期")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(6)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(9)
- run.AddText("数量")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(6)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(9)
- run.AddText("单位")
- models.InitBasicData(deptId)
- for _, medicineInfo := range list {
- row = table.AddRow()
- row.Properties().SetHeight(0.3*measurement.Inch, wml.ST_HeightRuleAtLeast)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(15)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- productName := models.Read_Product_Get(utils.ToInt(medicineInfo[models.FieldProductID]))
- run.AddText(productName)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(12)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- enterpriseName := models.Read_Enterprise_Get(utils.ToInt(medicineInfo[models.FieldEnterpriseID]))
- run.AddText(enterpriseName)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- run.AddText(medicineInfo[models.FieldApprovalNumber].(string))
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(15)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- if medicineInfo[models.FieldQualificationNumber] != nil {
- run.AddText(medicineInfo[models.FieldQualificationNumber].(string))
- }
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(13)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- specName := models.Read_Spec_Get(utils.ToInt(medicineInfo[models.FieldSpecID]))
- run.AddText(specName)
- //cell = row.AddCell()
- //cell.Properties().SetWidth(0.5 * measurement.Inch)
- //para = cell.AddParagraph()
- //cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- //para.Properties().SetAlignment(wml.ST_JcCenter)
- //run = para.AddRun()
- //run.Properties().SetFontFamily("宋体")
- //run.Properties().SetSize(8)
- //run.AddText("生产日期")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(12)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- run.AddText(medicineInfo[models.FieldBatchNumber].(string))
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- run.AddText(utils.ToDate(medicineInfo[models.FieldExpiryDate]))
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(6)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- run.AddText(fmt.Sprintf("%d", utils.ToInt(medicineInfo["quantity"])))
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(6)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- unitName := models.Read_Unit_Get(utils.ToInt(medicineInfo[models.FieldUnitID]))
- run.AddText(unitName)
- }
- if len(list) < 11 {
- for i := 0; i < 11-len(list); i++ {
- row = table.AddRow()
- row.Properties().SetHeight(0.3*measurement.Inch, wml.ST_HeightRuleAtLeast)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(15)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(12)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(15)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(13)
- //cell = row.AddCell()
- //cell.Properties().SetWidth(0.5 * measurement.Inch)
- //para = cell.AddParagraph()
- //cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- //para.Properties().SetAlignment(wml.ST_JcCenter)
- //run = para.AddRun()
- //run.Properties().SetFontFamily("宋体")
- //run.Properties().SetSize(8)
- //run.AddText("生产日期")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(12)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(6)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(6)
- }
- }
- // --------------------运输温度记录
- para = doc.AddParagraph()
- para.Properties().Spacing().SetLineSpacing(25*measurement.Point, wml.ST_LineSpacingRuleAtLeast)
- para.Properties().SetAlignment(wml.ST_JcLeft)
- run = para.AddRun()
- run.Properties().SetBold(true)
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("运输温度记录:")
- table = doc.InsertTableAfter(para)
- table.Properties().SetWidthPercent(100)
- table.Properties().SetAlignment(wml.ST_JcTableCenter)
- table.Properties().SetLayout(wml.ST_TblLayoutTypeAutofit)
- look = table.Properties().TableLook()
- look.SetFirstColumn(true)
- look.SetFirstRow(true)
- look.SetHorizontalBanding(true)
- borders = table.Properties().Borders()
- borders.SetBottom(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
- borders.SetLeft(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
- borders.SetRight(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
- borders.SetTop(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
- borders.SetInsideHorizontal(wml.ST_BorderSingle, color.Auto, measurement.Zero)
- borders.SetInsideVertical(wml.ST_BorderSingle, color.Auto, measurement.Zero)
- //-----------------项目名称
- row = table.AddRow()
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.AddText("")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(38)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("日期/时间")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(19)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(8)
- run.AddText("储存温度")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(17)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("冰排状态")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(16)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("环境温度")
- //------------------启运
- row = table.AddRow()
- row.Properties().SetHeight(0.4*measurement.Inch, wml.ST_HeightRuleAtLeast)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("启运")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(38)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("年")
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("月")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("日")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("时")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("分")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(19)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("℃")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(17)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run.AddText("")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(16)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("℃")
- //------------------途中
- row = table.AddRow()
- row.Properties().SetHeight(0.8*measurement.Inch, wml.ST_HeightRuleAtLeast)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("途中")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(38)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("年")
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("月")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("日")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("时")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("分")
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("年")
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("月")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("日")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("时")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("分")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(19)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("℃")
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("℃")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(17)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetSize(5)
- run.AddText("————————")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(16)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("℃")
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("℃")
- //------------------到达
- row = table.AddRow()
- row.Properties().SetHeight(0.4*measurement.Inch, wml.ST_HeightRuleAtLeast)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(10)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("到达")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(38)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("年")
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("月")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("日")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("时")
- run = para.AddRun()
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("分")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(19)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("℃")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(17)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run.AddText("")
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(16)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcCenter)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("℃")
- para = doc.AddParagraph()
- para.Properties().Spacing().SetLineSpacing(25*measurement.Point, wml.ST_LineSpacingRuleExact)
- para.Properties().SetAlignment(wml.ST_JcLeft)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("启运至到达行驶里程数:")
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(" ")
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("千米。")
- table3 := doc.AddTable()
- table3.Properties().SetLayout(wml.ST_TblLayoutTypeFixed)
- table3.Properties().SetWidthPercent(100)
- look.SetFirstColumn(true)
- look.SetFirstRow(true)
- look.SetHorizontalBanding(true)
- look = table3.Properties().TableLook()
- borders3 := table3.Properties().Borders()
- borders3.SetAll(wml.ST_BorderUnset, color.Auto, measurement.Zero)
- row = table3.AddRow()
- row.Properties().SetHeight(0.36*measurement.Inch, wml.ST_HeightRuleExact)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(50)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcLeft)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("发货单位:")
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(beegouser.GetDeptName(c.Ctx))
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(50)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcLeft)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("发货人签名:")
- run = para.AddRun()
- run.Properties().SetSize(5)
- run.AddText("________________________________________________________________")
- row = table3.AddRow()
- row.Properties().SetHeight(0.36*measurement.Inch, wml.ST_HeightRuleExact)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(50)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcLeft)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("收货单位:")
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText(reqData.ReceivingUnit)
- run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
- cell = row.AddCell()
- cell.Properties().SetWidthPercent(50)
- para = cell.AddParagraph()
- cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
- para.Properties().SetAlignment(wml.ST_JcLeft)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("收货人签名:")
- run = para.AddRun()
- run.Properties().SetSize(5)
- run.AddText("________________________________________________________________")
- para = doc.AddParagraph()
- para.Properties().SetAlignment(wml.ST_JcLeft)
- run = para.AddRun()
- run.Properties().SetFontFamily("宋体")
- run.Properties().SetSize(10)
- run.AddText("填表说明:本表供冷链配送企业、疾病预防控制机构、接种单位冷链运输时填写;出入库单号为单位编码+年月日+2位流水号;运输超过6小时需记录途中温度,间隔不超过6小时;使用无自动温度显示的冰排保冷设备时,只在启运和达到时填写冰排状态(冻结、冰水混合物、完全融化)。")
- doc.BodySection().SetFooter(ftr, wml.ST_HdrFtrDefault)
- filename := "运输记录表" + time.Now().Format("20060102150405") + ".docx"
- // 保存文件
- if err := doc.SaveToFile("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- // 保存为PDF文件
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- func getImageBytes(filePath string) []byte {
- b, err := os.ReadFile(filePath)
- if err != nil {
- panic(err)
- }
- return b
- }
- func (c StockTemplateController) TransportRecordPdf(reqData models.TransportRecord) {
- s := services.StockTemplate{}
- imgSvc := services.MedicineImg{}
- barcodeServ := services.Barcode{}
- deptId := beegouser.GetDeptId(c.Ctx)
- p := actions.GetPermissionFromContext(c.Ctx)
- rootId, err := imgSvc.GetRootID((*context2.Context)(c.Ctx), p.DeptId)
- if err != nil {
- c.Error(global.BadRequest, err, err.Error())
- return
- }
- list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- reqData.DeptID = deptId
- reqData.DeptName = beegouser.GetDeptName(c.Ctx)
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(deptId)
- code, err := barcodeServ.Insert(reqData)
- if err != nil {
- err = errors.New("生成条码失败")
- c.Error(500, err, err.Error())
- return
- }
- cs, _ := code128.Encode(code)
- // 创建一个要输出数据的文件
- imgPath := "ofile/img/" + code + ".png"
- file, _ := os.Create(imgPath)
- defer file.Close()
- // 设置图片像素大小
- qrCode, _ := barcode.Scale(cs, 205, 50)
- // 将code128的条形码编码为png图片
- png.Encode(file, qrCode)
- cols := []float64{83, 50, 55, 72, 72, 50, 66, 50, 27, 30}
- header := []string{"品种", "生产企业", "批准文号", "批签发合格编号", "规格(剂/支或粒)", "生产日期", "批号", "失效日期", "数量", "单位"}
- rows := [][]string{}
- imgList := []string{}
- for _, row := range list {
- temp := []string{}
- product := utils.ToString(row[models.FieldProductName])
- enterprise := utils.ToString(row[models.FieldEnterpriseName])
- spec := utils.ToString(row[models.FieldSpecName])
- batchNumber := utils.ToString(row[models.FieldBatchNumber])
- temp = append(temp, product)
- temp = append(temp, fmt.Sprintf("%s", enterprise))
- temp = append(temp, utils.ToString(row[models.FieldApprovalNumber]))
- temp = append(temp, utils.ToString(row[models.FieldQualificationNumber]))
- temp = append(temp, spec)
- temp = append(temp, utils.ToString(row[models.FieldProducedDate]))
- temp = append(temp, batchNumber)
- temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
- temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
- temp = append(temp, utils.ToString(row[models.FieldUnitName]))
- rows = append(rows, temp)
- // 获取药品信息图片
- img, err := imgSvc.Get(deptId, rootId, product, enterprise, spec, batchNumber)
- if err == nil && img.Img != "" {
- imgList = append(imgList, img.Img)
- }
- }
- if len(list) < 11 {
- for i := 0; i < 11-len(list); i++ {
- rows = append(rows, []string{"", "", "", "", "", "", "", "", "", ""})
- }
- }
- pdf := &gopdf.GoPdf{}
- pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
- pdf.SetMarginTop(40)
- pdf.SetMarginBottom(40)
- pdf.AddPage()
- pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
- pdf.SetMargins(2, 5, 5, 5)
- pdf.SetFont("simsun", "", 10)
- pdf.SetX(20)
- pdf.SetY(20)
- pdf.Text("[扫码入库]")
- pdf.SetX(20)
- pdf.SetY(32)
- pdf.Text("NO:" + code)
- imgPath2 := "ofile/img/" + code + ".jpg"
- png2j.Con2jpg(imgPath, imgPath2)
- pdf.Image(imgPath2, -5, 35, &gopdf.Rect{W: 175, H: 30})
- titleStr := "表3-4 运输记录表"
- pdf.SetFont("simsun", "", 22)
- textw, _ := pdf.MeasureTextWidth(titleStr)
- pdf.SetX((595 / 2) - (textw / 2))
- pdf.SetY(40)
- pdf.Text(titleStr)
- pdf.SetFont("simsun", "", 16)
- titleStr = "(各级通用)"
- textw, _ = pdf.MeasureTextWidth(titleStr)
- pdf.SetX((595 / 2) - (textw / 2))
- pdf.SetY(60)
- pdf.Text(titleStr)
- pdf.SetFont("simsun", "", 10)
- curx, y := 20., pdf.GetY()
- y += 35
- pdf.SetXY(curx, y)
- pdf.Text("运输工具: □冷藏车 □运输车 □普通车辆 □无 □其他")
- y += 16
- pdf.SetXY(curx, y)
- pdf.Text("冷藏工具: □冷藏车 □车载冷藏箱 □冷藏箱或冷藏包 □其他")
- y += 16
- pdf.SetXY(curx, y)
- pdf.Text("配送方式: □本级配送(车牌号:_______) □下级自运(车牌号:_______)")
- y += 20
- pdf.SetXY(curx, y)
- pdf.Text("运输情况:")
- y += 6
- pdf.SetXY(curx, y)
- h := 20.0
- x := curx
- pdf.SetFont("simsun", "", 9)
- for i := 0; i < len(header); i++ {
- utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += cols[i]
- }
- y += h
- pdf.SetXY(curx, y)
- pdf.SetFont("simsun", "", 8)
- for _, row := range rows {
- curx, y = pdf.GetX(), pdf.GetY()
- x = curx
- height := h
- for i, txt := range row {
- lineTexts, _ := pdf.SplitText(txt, cols[i])
- //lineHt := h * float64(len(lineTexts))
- if len(lineTexts) > 1 {
- lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
- lineHt := h * float64(len(lineTexts)) * 0.6
- if lineHt > height {
- height = lineHt
- }
- }
- }
- for i, txt := range row {
- width := cols[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y+height, height)
- pdf.SetX(curx)
- }
- pdf.SetFont("simsun", "", 9)
- y = pdf.GetY()
- y += 20
- pdf.SetNewY(y, 20)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- pdf.Text("运输温度记录:")
- header2 := []string{"", "日期/时间", "储存温度", "冰排状态", "环境温度"}
- cols2 := []float64{55, 210, 105, 94, 91}
- y = pdf.GetY()
- y += 5
- h = 35.0
- pdf.SetNewY(y, h)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- y = pdf.GetY()
- pdf.SetX(curx)
- x = curx
- for i := 0; i < len(header2); i++ {
- utils.RectFillColorMultiCell(pdf, header2[i], 9, x, y, cols2[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += cols2[i]
- }
- y += h
- pdf.SetNewY(y, h)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- row2 := [][]string{
- {"启运", "______年___月___日___时___分", "________℃", "", "________℃"},
- {"途中", "______年___月___日___时___分", "________℃", "————", "________℃"},
- {"到达", "______年___月___日___时___分", "________℃", "", "________℃"},
- }
- for j, row := range row2 {
- curx, y = pdf.GetX(), pdf.GetY()
- x = curx
- pdf.SetTextColor(0, 0, 0)
- height := h
- if j == 1 {
- height = height * 2
- }
- for i, txt := range row {
- width := cols2[i]
- txtWd, _ := pdf.MeasureTextWidth(txt)
- txtX := x + (width-txtWd)/2
- pdf.SetLineWidth(0.8)
- pdf.SetFillColor(255, 255, 255) //setup fill color
- pdf.SetLineType("") // 线条样式
- pdf.RectFromUpperLeftWithStyle(x, y, width, height, "FD")
- if j == 1 {
- if i == 1 || i == 2 || i == 4 {
- txtY := y + height/5*2
- pdf.SetXY(txtX, txtY)
- pdf.Text(txt)
- txtY = y + height/5*4
- pdf.SetXY(txtX, txtY)
- pdf.Text(txt)
- } else {
- txtY := y + height/5*3
- pdf.SetXY(txtX, txtY)
- pdf.Text(txt)
- }
- } else {
- txtY := y + height/3*2
- pdf.SetXY(txtX, txtY)
- pdf.Text(txt)
- }
- x += width
- }
- pdf.SetNewY(y+height, height)
- if pdf.GetY() < 30 || pdf.GetY() > 810 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- }
- y = pdf.GetY()
- y += 20
- pdf.SetNewY(y, 20)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- pdf.SetFont("simsun", "", 10)
- pdf.Text("启运至到达行驶里程数:_________千米")
- y = pdf.GetY()
- y += 25
- pdf.SetNewY(y, 25)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- y = pdf.GetY()
- pdf.Text("发货单位:")
- txtWd, _ := pdf.MeasureTextWidth("发货单位:")
- pdf.SetLineWidth(0.8)
- pdf.SetXY(curx+txtWd, y)
- pdf.Text(beegouser.GetDeptName(c.Ctx))
- pdf.Line(60, y+3, 207, y+3)
- pdf.SetXY(300, y)
- pdf.Text("发货人签名:")
- txtWd, _ = pdf.MeasureTextWidth("发货人签名:")
- pdf.Line(348, y+3, 495, y+3)
- y = pdf.GetY()
- y += 25
- pdf.SetNewY(y, 25)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- y = pdf.GetY()
- pdf.Text("收货单位:")
- txtWd, _ = pdf.MeasureTextWidth("收货单位:")
- pdf.SetXY(curx+txtWd, y)
- pdf.Text(reqData.ReceivingUnit)
- pdf.Line(60, y+3, 207, y+3)
- pdf.SetXY(300, y)
- pdf.Text("收货人签名:")
- txtWd, _ = pdf.MeasureTextWidth("收货人签名:")
- pdf.Line(348, y+3, 495, y+3)
- y = pdf.GetY()
- y += 20
- pdf.SetNewY(y, 20)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- pdf.SetCharSpacing(0.5)
- txt := "填表说明:本表供冷链配送企业、疾病预防控制机构、接种单位冷链运输时填写;出入库单号为单位编码+年月日+2位流水号;运输超过6小时需记录途中温度,间隔不超过6小时;使用无自动温度显示的冰排保冷设备时,只在启运和达到时填写冰排状态(冻结、冰水混合物、完全融化)。"
- pdf.MultiCell(&gopdf.Rect{W: 555, H: 50}, txt)
- //imgList = append(imgList,
- // "https://godownoss.coldbaozhida.com/UpImage/17115067977062dc7f-0354-4e70-aefe-3423338b44be.jpg",
- // "https://godownoss.coldbaozhida.com/UpImage/17115068019adbd486-993e-48c5-8155-c2c30265638a.jpg",
- //)
- for _, v := range imgList {
- urlList := strings.Split(strings.Trim(v, ","), ",")
- for _, url := range urlList {
- pdf.AddPage()
- imgH, errImg := utils.GetImage(url)
- if errImg != nil {
- err = errors.New("获取图片失败")
- c.Error(500, err, err.Error())
- return
- }
- imgWidth := float64(imgH.Bounds().Dx())
- imgHeight := float64(imgH.Bounds().Dy())
- W, H := imgWidth, imgHeight
- if imgWidth >= imgHeight && imgWidth > 555 {
- W = 555
- H = 555 * float64(imgHeight) / float64(imgWidth)
- }
- if imgWidth < imgHeight && imgWidth > 760 {
- W = 760 * float64(imgWidth) / float64(imgHeight)
- H = 760
- if W > 555 {
- H = 555 * 760 / W
- W = 555
- }
- }
- if strings.Contains(url, ".png") {
- err = pdf.ImageFrom(imgH, (595-W)/2, (840-H)/2, &gopdf.Rect{W: W, H: H})
- if err != nil {
- err = errors.New("写入图片失败")
- c.Error(500, err, err.Error())
- return
- }
- } else {
- fileName := "./ofile/" + path.Base(url)
- f, _ := os.Create(fileName)
- defer f.Close()
- defer func() {
- os.Remove(fileName)
- }()
- jpeg.Encode(f, imgH, &jpeg.Options{100})
- err = pdf.Image(fileName, (595-W)/2, (840-H)/2, &gopdf.Rect{W: W, H: H})
- if err != nil {
- err = errors.New("写入图片失败")
- c.Error(500, err, err.Error())
- return
- }
- }
- }
- }
- for i := 0; i < pdf.GetNumberOfPages(); i++ {
- }
- filename := "运输记录表" + time.Now().Format("20060102150405") + ".pdf"
- // 保存文件
- if err = pdf.WritePdf("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- os.Remove(imgPath)
- os.Remove(imgPath2)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- // TransportRecordExport 运输记录表
- // @Summary 收发登记表word
- // @Description 收发登记表word
- // @Tags 库存
- // @Param body body dto.TransportRecordWordReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/inventory/list [post]
- // @Security Bearer
- func (c StockTemplateController) TransportRecordExport() {
- reqData := models.TransportRecord{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- models.InitBasicData(deptId)
- if reqData.Type == "pdf" {
- c.TransportRecordPdf(reqData)
- }
- if reqData.Type == "word" {
- c.TransportRecordWord(reqData)
- }
- }
- // TransportRecordExport 运输记录表
- // @Summary 收发登记表word
- // @Description 收发登记表word
- // @Tags 库存
- // @Param body body dto.TransportRecordWordReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/inventory/list [post]
- // @Security Bearer
- func (c StockTemplateController) TransportRecordExportList() {
- s := services.StockTemplate{}
- reqData := models.TransportRecord{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- models.InitBasicData(deptId)
- list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, 0, 0, 0, "查询成功")
- }
- // StockUnitList 获取收货单位,发货单位,收发单位
- // @Summary 获取收货单位,发货单位,收发单位
- // @Description 获取收货单位,发货单位,收发单位
- // @Tags 库存
- // @Param body body dto.StockUnitListReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock/unit/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockUnitList() {
- s := services.StockTemplate{}
- reqData := dto.StockUnitListReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, err := s.StockUnitList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, 0, 0, 0, "查询成功")
- }
- // StockOperatorList 获取收货单位,发货单位,收发单位
- // @Summary 获取收货单位,发货单位,收发单位
- // @Description 获取收货单位,发货单位,收发单位
- // @Tags 库存
- // @Param body body dto.StockOperatorListReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock/unit/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockOperatorList() {
- s := services.StockTemplate{}
- reqData := dto.StockOperatorListReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, err := s.StockOperatorList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, 0, 0, 0, "查询成功")
- }
- // StockInquiryList 库存查询
- // @Summary 库存查询-每个商品、生产企业、规格、批号数量
- // @Description 库存查询
- // @Tags 库存
- // @Param body body dto.StockStatListReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock/inquiry/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockInquiryList() {
- s := services.StockTemplate{}
- reqData := dto.StockStatListReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, cnt, err := s.StockInquiryList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(cnt), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
- }
- // StockInquiryExcel 导出库存信息表
- // @Summary 库存信息表-每个商品、生产企业、规格、批号数量
- // @Description 库存信息表
- // @Tags 库存
- // @Param body body dto.StockStatListReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock/stat/excel [post]
- // @Security Bearer
- func (c StockTemplateController) StockInquiryExcel() {
- s := services.StockTemplate{}
- reqData := dto.StockStatListReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, err := s.StockInquiryExcel(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- f := excelize.NewFile() // 设置单元格的值
- StyleTitle, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
- })
- f.MergeCell("Sheet1", "A1", "K1")
- f.SetRowStyle("Sheet1", 1, 1, StyleTitle)
- f.SetRowHeight("Sheet1", 1, 50)
- f.SetCellValue("Sheet1", "A1", fmt.Sprintf("库存信息表(%s)", time.Now().Format("2006-01-02 15:04:05")))
- // 这里设置表头
- f.SetCellValue("Sheet1", "A2", "品名")
- f.SetCellValue("Sheet1", "B2", "生产企业")
- f.SetCellValue("Sheet1", "C2", "规格")
- f.SetCellValue("Sheet1", "D2", "剂型")
- f.SetCellValue("Sheet1", "E2", "单位")
- f.SetCellValue("Sheet1", "F2", "数量")
- f.SetCellValue("Sheet1", "G2", "单价")
- //f.SetCellValue("Sheet1", "H2", "销售单价")
- f.SetCellValue("Sheet1", "H2", "批号")
- f.SetCellValue("Sheet1", "I2", "失效日期")
- f.SetCellValue("Sheet1", "J2", "批准文号")
- f.SetCellValue("Sheet1", "K2", "批签发编号")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "A", 20)
- f.SetColWidth("Sheet1", "B", "C", 15)
- f.SetColWidth("Sheet1", "D", "F", 12)
- f.SetColWidth("Sheet1", "F", "G", 10)
- f.SetColWidth("Sheet1", "G", "I", 15)
- f.SetColWidth("Sheet1", "I", "J", 12)
- f.SetColWidth("Sheet1", "J", "K", 15)
- line := 2
- // 循环写入数据
- for _, v := range list {
- line++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v[models.FieldProductName])
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v[models.FieldEnterpriseName])
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v[models.FieldSpecName])
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v[models.FieldDosageFormName])
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldUnitName])
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v["balance"])
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), utils.ToFloat64(v["unit_price"]))
- //f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToFloat64(v["sales_unit_price"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v["batch_number"])
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v[models.FieldExpiryDate])
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v["approval_number"])
- f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v["qualification_number"])
- }
- Style1, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, Family: "宋体", Bold: true},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.SetCellStyle("Sheet1", "A2", "K2", Style1)
- Style2, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("K%d", line), Style2)
- filename := "库存信息表" + time.Now().Format("20060102150405") + ".xlsx"
- // 保存文件
- if err := f.SaveAs("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- // StockStat 库存统计
- // @Summary 库存查询-每个商品数量(不区别生产企业)
- // @Description 库存查询
- // @Tags 库存
- // @Param body body dto.StockStatListReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock/stat [post]
- // @Security Bearer
- func (c StockTemplateController) StockStat() {
- s := services.StockTemplate{}
- reqData := dto.StockStatReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, cnt, err := s.StockStat(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(cnt), 0, 0, "查询成功")
- }
- // StockHomeStat 首页出入库信息统计
- // @Summary 首页出入库信息统计
- // @Description 首页出入库信息统计
- // @Tags 库存
- // @Param body body dto.StockStatListReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock/stat [post]
- // @Security Bearer
- func (c StockTemplateController) StockHomeStat() {
- s := services.StockTemplate{}
- deptId := beegouser.GetDeptId(c.Ctx)
- list, cnt, err := s.StockHomeStat(deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(cnt), 0, 0, "查询成功")
- }
- // StockTemplateInScanBarCode 扫条码入库
- // @Summary 扫条码入库
- // @Description 扫条码入库
- // @Tags 库存
- // @Param body body dto.StockTemplateOutInsertReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /stock-template/out [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateInScanBarCode() {
- s := services.StockTemplate{}
- reqData := dto.BatchStockTemplateOutInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- err := s.StockTemplateOutScanCode(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(nil, "扫码出库成功")
- }
- func (c StockTemplateController) GetTransportRecordBarCodeInfo() {
- barcodeSvc := services.Barcode{}
- s := services.StockTemplate{}
- //if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- // c.Error(global.ParseFormErr, err, err.Error())
- // return
- //}
- codeStr := c.GetString("code")
- reqData := dto.GetBarCodeInfoReq{Code: codeStr}
- var code models.Barcode
- //数据权限检查
- err := barcodeSvc.Get(&reqData, &code)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- list, err := s.StockTemplateTransportRecordWord2(&code.Data, code.Data.DeptID)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- for _, v := range list {
- v["forwardingUnit"] = code.Data.DeptName
- }
- c.OK(list, "查询成功")
- }
- func (c StockTemplateController) StockRefundOutTransportRecordPdf(reqData models.TransportRecord) {
- s := services.StockTemplate{}
- imgSvc := services.MedicineImg{}
- barcodeServ := services.Barcode{}
- deptId := beegouser.GetDeptId(c.Ctx)
- p := actions.GetPermissionFromContext(c.Ctx)
- rootId, err := imgSvc.GetRootID((*context2.Context)(c.Ctx), p.DeptId)
- if err != nil {
- c.Error(global.BadRequest, err, err.Error())
- return
- }
- list, err := s.StockRefundOutTransportRecordPdf(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- reqData.DeptID = deptId
- reqData.DeptName = beegouser.GetDeptName(c.Ctx)
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(deptId)
- code, err := barcodeServ.Insert(reqData)
- if err != nil {
- err = errors.New("生成条码失败")
- c.Error(500, err, err.Error())
- return
- }
- cs, _ := code128.Encode(code)
- // 创建一个要输出数据的文件
- imgPath := "ofile/img/" + code + ".png"
- file, _ := os.Create(imgPath)
- defer file.Close()
- // 设置图片像素大小
- qrCode, _ := barcode.Scale(cs, 205, 50)
- // 将code128的条形码编码为png图片
- png.Encode(file, qrCode)
- cols := []float64{83, 50, 55, 72, 72, 50, 66, 50, 27, 30}
- header := []string{"品种", "生产企业", "批准文号", "批签发合格编号", "规格(剂/支或粒)", "生产日期", "批号", "失效日期", "数量", "单位"}
- rows := [][]string{}
- imgList := []string{}
- for _, row := range list {
- temp := []string{}
- product := utils.ToString(row[models.FieldProductName])
- enterprise := utils.ToString(row[models.FieldEnterpriseName])
- spec := utils.ToString(row[models.FieldSpecName])
- batchNumber := utils.ToString(row[models.FieldBatchNumber])
- temp = append(temp, product)
- temp = append(temp, fmt.Sprintf("%s", enterprise))
- temp = append(temp, utils.ToString(row[models.FieldApprovalNumber]))
- temp = append(temp, utils.ToString(row[models.FieldQualificationNumber]))
- temp = append(temp, spec)
- temp = append(temp, utils.ToString(row[models.FieldProducedDate]))
- temp = append(temp, batchNumber)
- temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
- temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
- temp = append(temp, utils.ToString(row[models.FieldUnitName]))
- rows = append(rows, temp)
- // 获取药品信息图片
- img, err := imgSvc.Get(deptId, rootId, product, enterprise, spec, batchNumber)
- if err == nil && img.Img != "" {
- log.Println("==============", img.Img)
- imgList = append(imgList, img.Img)
- }
- }
- pdf := &gopdf.GoPdf{}
- pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
- pdf.SetMarginTop(40)
- pdf.SetMarginBottom(40)
- pdf.AddPage()
- pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
- pdf.SetMargins(2, 5, 5, 5)
- pdf.SetFont("simsun", "", 10)
- //pdf.SetX(20)
- //pdf.SetY(20)
- //pdf.Text("[退货出库]")
- pdf.SetX(420)
- pdf.SetY(60)
- pdf.Text(code)
- imgPath2 := "ofile/img/" + code + ".jpg"
- png2j.Con2jpg(imgPath, imgPath2)
- pdf.Image(imgPath2, 390, 15, &gopdf.Rect{W: 200, H: 35})
- titleStr := "退货出库运输温度记录表"
- pdf.SetFont("simsun", "", 22)
- textw, _ := pdf.MeasureTextWidth(titleStr)
- pdf.SetX((595 / 2) - (textw / 2) - 50)
- pdf.SetY(40)
- pdf.Text(titleStr)
- pdf.SetFont("simsun", "", 10)
- // 第一行
- curx, y := 20., pdf.GetY()
- y += 35
- pdf.SetXY(curx, y)
- pdf.Text("出/入库日期:")
- txtWd, _ := pdf.MeasureTextWidth("出/入库日期:")
- pdf.SetXY(curx+txtWd, y)
- pdf.Text(reqData.Date)
- pdf.Line(curx+txtWd, y+3, curx+txtWd+110, y+3)
- curx = 230
- pdf.SetXY(curx, y)
- pdf.Text("出/入库单号:")
- txtWd, _ = pdf.MeasureTextWidth("出/入库单号:")
- pdf.SetXY(curx+txtWd, y)
- pdf.Text(code)
- pdf.Line(curx+txtWd, y+3, curx+txtWd+130, y+3)
- // 第二行
- curx, y = 20., pdf.GetY()
- y += 25
- pdf.SetXY(curx, y)
- pdf.Text("运输工具:(1)冷藏车")
- txtWd, _ = pdf.MeasureTextWidth("运输工具:(1)冷藏车")
- pdf.SetXY(curx+txtWd, y)
- //pdf.Text(reqData.Date)
- pdf.Line(curx+txtWd, y+3, curx+txtWd+110, y+3)
- curx = 230
- pdf.SetXY(curx, y)
- pdf.Text("(2)运输车")
- txtWd, _ = pdf.MeasureTextWidth("(2)运输车")
- pdf.SetXY(curx+txtWd, y)
- //pdf.Text(code)
- pdf.Line(curx+txtWd+2, y+3, curx+txtWd+130, y+3)
- curx = 410
- pdf.SetXY(curx, y)
- pdf.Text("(3)其他")
- txtWd, _ = pdf.MeasureTextWidth("(3)其他")
- pdf.SetXY(curx+txtWd, y)
- //pdf.Text(code)
- pdf.Line(curx+txtWd+2, y+3, curx+txtWd+130, y+3)
- // 第三行
- curx, y = 20., pdf.GetY()
- y += 25
- pdf.SetXY(curx, y)
- pdf.Text("冷藏方式:(1)冷藏车")
- txtWd, _ = pdf.MeasureTextWidth("运输工具:(1)冷藏车")
- pdf.SetXY(curx+txtWd, y)
- //pdf.Text(reqData.Date)
- pdf.Line(curx+txtWd, y+3, curx+txtWd+110, y+3)
- curx = 230
- pdf.SetXY(curx, y)
- pdf.Text("(2)冷藏箱")
- txtWd, _ = pdf.MeasureTextWidth("(2)冷藏箱")
- pdf.SetXY(curx+txtWd, y)
- //pdf.Text(code)
- pdf.Line(curx+txtWd, y+3, curx+txtWd+130, y+3)
- curx = 410
- pdf.SetXY(curx, y)
- pdf.Text("(3)其他")
- txtWd, _ = pdf.MeasureTextWidth("(3)其他")
- pdf.SetXY(curx+txtWd, y)
- //pdf.Text(code)
- pdf.Line(curx+txtWd, y+3, curx+txtWd+130, y+3)
- curx = 20
- y += 20
- pdf.SetXY(curx, y)
- pdf.Text("运输情况:")
- y += 6
- pdf.SetXY(curx, y)
- h := 20.0
- x := curx
- pdf.SetFont("simsun", "", 9)
- for i := 0; i < len(header); i++ {
- utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += cols[i]
- }
- y += h
- pdf.SetXY(curx, y)
- pdf.SetFont("simsun", "", 8)
- for _, row := range rows {
- curx, y = pdf.GetX(), pdf.GetY()
- x = curx
- height := h
- for i, txt := range row {
- lineTexts, _ := pdf.SplitText(txt, cols[i])
- //lineHt := h * float64(len(lineTexts))
- if len(lineTexts) > 1 {
- lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
- lineHt := h * float64(len(lineTexts)) * 0.6
- if lineHt > height {
- height = lineHt
- }
- }
- }
- for i, txt := range row {
- width := cols[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y+height, height)
- pdf.SetX(curx)
- }
- pdf.SetFont("simsun", "", 9)
- y = pdf.GetY()
- y += 20
- pdf.SetNewY(y, 20)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- pdf.SetFont("simsun", "", 10)
- pdf.Text("运输温度记录:")
- header2 := []string{"项目", "日期/时间", "储存温度", "冰排状态", "环境温度"}
- cols2 := []float64{55, 210, 105, 94, 91}
- y = pdf.GetY()
- y += 5
- h = 35.0
- pdf.SetNewY(y, h)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- y = pdf.GetY()
- pdf.SetX(curx)
- x = curx
- pdf.SetFont("simsun", "", 9)
- for i := 0; i < len(header2); i++ {
- utils.RectFillColorMultiCell(pdf, header2[i], 9, x, y, cols2[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += cols2[i]
- }
- y += h
- pdf.SetNewY(y, h)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- pdf.SetFont("simsun", "", 9)
- row2 := [][]string{
- {"启运", "______年___月___日___时___分", "________℃", "", "________℃"},
- {"途中", "______年___月___日___时___分", "________℃", "————", "________℃"},
- {"到达", "______年___月___日___时___分", "________℃", "", "________℃"},
- }
- for j, row := range row2 {
- curx, y = pdf.GetX(), pdf.GetY()
- x = curx
- pdf.SetTextColor(0, 0, 0)
- height := h
- if j == 1 {
- height = height * 2
- }
- for i, txt := range row {
- width := cols2[i]
- txtWd, _ := pdf.MeasureTextWidth(txt)
- txtX := x + (width-txtWd)/2
- pdf.SetLineWidth(0.8)
- pdf.SetFillColor(255, 255, 255) //setup fill color
- pdf.SetLineType("") // 线条样式
- pdf.RectFromUpperLeftWithStyle(x, y, width, height, "FD")
- if j == 1 {
- if i == 1 || i == 2 || i == 4 {
- txtY := y + height/5*2
- pdf.SetXY(txtX, txtY)
- pdf.Text(txt)
- txtY = y + height/5*4
- pdf.SetXY(txtX, txtY)
- pdf.Text(txt)
- } else {
- txtY := y + height/5*3
- pdf.SetXY(txtX, txtY)
- pdf.Text(txt)
- }
- } else {
- txtY := y + height/3*2
- pdf.SetXY(txtX, txtY)
- pdf.Text(txt)
- }
- x += width
- }
- pdf.SetNewY(y+height, height)
- if pdf.GetY() < 30 || pdf.GetY() > 810 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- }
- y = pdf.GetY()
- y += 20
- pdf.SetNewY(y, 20)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- pdf.SetFont("simsun", "", 10)
- pdf.Text("启运至到达行驶里程数:_________千米")
- y = pdf.GetY()
- y += 25
- pdf.SetNewY(y, 25)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- y = pdf.GetY()
- pdf.Text("发货单位:")
- txtWd, _ = pdf.MeasureTextWidth("发货单位:")
- pdf.SetLineWidth(0.8)
- pdf.SetXY(curx+txtWd, y)
- pdf.Text(beegouser.GetDeptName(c.Ctx))
- pdf.Line(60, y+3, 207, y+3)
- pdf.SetXY(300, y)
- pdf.Text("发货人签名:")
- txtWd, _ = pdf.MeasureTextWidth("发货人签名:")
- pdf.Line(348, y+3, 495, y+3)
- y = pdf.GetY()
- y += 25
- pdf.SetNewY(y, 25)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- y = pdf.GetY()
- pdf.Text("收货单位:")
- txtWd, _ = pdf.MeasureTextWidth("收货单位:")
- pdf.SetXY(curx+txtWd, y)
- pdf.Text(reqData.ReceivingUnit)
- pdf.Line(60, y+3, 207, y+3)
- pdf.SetXY(300, y)
- pdf.Text("收货人签名:")
- txtWd, _ = pdf.MeasureTextWidth("收货人签名:")
- pdf.Line(348, y+3, 495, y+3)
- y = pdf.GetY()
- y += 20
- pdf.SetNewY(y, 20)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- pdf.SetX(curx)
- pdf.SetCharSpacing(0.5)
- txt := "填表说明:本表供冷链配送企业、疾病预防控制机构、接种单位冷链运输时填写;出入库单号为单位编码+年月日+2位流水号;运输超过6小时需记录途中温度,间隔不超过6小时;使用无自动温度显示的冰排保冷设备时,只在启运和达到时填写冰排状态(冻结、冰水混合物、完全融化)。"
- pdf.MultiCell(&gopdf.Rect{W: 555, H: 50}, txt)
- //imgList = append(imgList,
- // "https://godownoss.coldbaozhida.com/UpImage/17115067977062dc7f-0354-4e70-aefe-3423338b44be.jpg",
- // "https://godownoss.coldbaozhida.com/UpImage/17115068019adbd486-993e-48c5-8155-c2c30265638a.jpg",
- //)
- for _, v := range imgList {
- urlList := strings.Split(strings.Trim(v, ","), ",")
- for _, url := range urlList {
- pdf.AddPage()
- imgH, errImg := utils.GetImage(url)
- if errImg != nil {
- err = errors.New("获取图片失败")
- c.Error(500, err, err.Error())
- return
- }
- imgWidth := float64(imgH.Bounds().Dx())
- imgHeight := float64(imgH.Bounds().Dy())
- W, H := imgWidth, imgHeight
- if imgWidth >= imgHeight && imgWidth > 555 {
- W = 555
- H = 555 * float64(imgHeight) / float64(imgWidth)
- }
- if imgWidth < imgHeight && imgWidth > 760 {
- W = 760 * float64(imgWidth) / float64(imgHeight)
- H = 760
- if W > 555 {
- H = 555 * 760 / W
- W = 555
- }
- }
- if strings.Contains(url, ".png") {
- err = pdf.ImageFrom(imgH, (595-W)/2, (840-H)/2, &gopdf.Rect{W: W, H: H})
- if err != nil {
- err = errors.New("写入图片失败")
- c.Error(500, err, err.Error())
- return
- }
- } else {
- fileName := "./ofile/" + path.Base(url)
- f, _ := os.Create(fileName)
- defer f.Close()
- defer func() {
- os.Remove(fileName)
- }()
- jpeg.Encode(f, imgH, &jpeg.Options{100})
- err = pdf.Image(fileName, (595-W)/2, (840-H)/2, &gopdf.Rect{W: W, H: H})
- if err != nil {
- err = errors.New("写入图片失败")
- c.Error(500, err, err.Error())
- return
- }
- }
- }
- }
- for i := 0; i < pdf.GetNumberOfPages(); i++ {
- }
- filename := "退货出库运输温度记录表" + time.Now().Format("20060102150405") + ".pdf"
- // 保存文件
- if err = pdf.WritePdf("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- os.Remove(imgPath)
- os.Remove(imgPath2)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- // StockRefundOutTransportRecordExport 退货出库运输登记表
- // @Summary 退货出库运输登记表
- // @Description 退货出库运输登记表
- // @Tags 库存
- // @Param body body dto.TransportRecordWordReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/inventory/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockRefundOutTransportRecordExport() {
- reqData := models.TransportRecord{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- models.InitBasicData(deptId)
- if reqData.Type == "pdf" {
- c.StockRefundOutTransportRecordPdf(reqData)
- }
- }
- // TransportRecordExport 运输记录表
- // @Summary 收发登记表word
- // @Description 收发登记表word
- // @Tags 库存
- // @Param body body dto.TransportRecordWordReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/inventory/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockRefundOutTransportRecordExportList() {
- s := services.StockTemplate{}
- reqData := models.TransportRecord{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- models.InitBasicData(deptId)
- list, err := s.StockRefundOutTransportRecordPdf(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, 0, 0, 0, "查询成功")
- }
- func (c StockTemplateController) GetRefundOutBarCodeInfo() {
- barcodeSvc := services.Barcode{}
- s := services.StockTemplate{}
- //if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- // c.Error(global.ParseFormErr, err, err.Error())
- // return
- //}
- codeStr := c.GetString("code")
- reqData := dto.GetBarCodeInfoReq{Code: codeStr}
- var code models.Barcode
- //数据权限检查
- err := barcodeSvc.Get(&reqData, &code)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- list, err := s.GetRefundOutBarCodeInfo(&code.Data, code.Data.DeptID)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- for _, v := range list {
- v["forwardingUnit"] = code.Data.DeptName
- }
- c.OK(list, "查询成功")
- }
- // StockTemplateInList 入库列表
- // @Summary 入库列表
- // @Description 入库列表
- // @Tags 库存
- // @Param body body dto.StockTemplateInPageReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/in/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateRefundInList() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateInPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, count, err := s.StockTemplateRefundInList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
- }
- // StockTemplateOutList 出库列表
- // @Summary 出库列表
- // @Description 出库列表
- // @Tags 库存
- // @Param body body dto.StockTemplateOutPageReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/out/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockTemplateRefundOutList() {
- s := services.StockTemplate{}
- reqData := dto.StockTemplateOutPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, count, err := s.StockTemplateRefundOutList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
- }
- // StockRefundOutExport 退货出库单
- // @Summary 退货出库运输登记表
- // @Description 退货出库运输登记表
- // @Tags 库存
- // @Param body body dto.StockRefundOutExport true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/inventory/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockRefundOutExport() {
- reqData := dto.StockRefundOutExport{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- models.InitBasicData(deptId)
- s := services.StockTemplate{}
- barcodeServ := services.Barcode{}
- list, err := s.StockRefundOutPdf(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- reqData.DeptId = deptId
- reqData.DeptName = beegouser.GetDeptName(c.Ctx)
- code, err := barcodeServ.InsertRefundOut(reqData)
- if err != nil {
- err = errors.New("生成条码失败")
- c.Error(500, err, err.Error())
- return
- }
- cs, _ := code128.Encode(code)
- // 创建一个要输出数据的文件
- imgPath := "ofile/img/" + code + ".png"
- file, _ := os.Create(imgPath)
- defer file.Close()
- // 设置图片像素大小
- qrCode, _ := barcode.Scale(cs, 205, 50)
- // 将code128的条形码编码为png图片
- png.Encode(file, qrCode)
- cols := []float64{160, 140, 45, 70, 70, 105, 105, 105}
- header := []string{"品种", "生产企业", "单位", "单价", "数量", "金额", "批号", "有效期"}
- rows := [][]string{}
- var totalMoney float64
- for _, row := range list {
- temp := []string{}
- product := utils.ToString(row[models.FieldProductName])
- enterprise := utils.ToString(row[models.FieldEnterpriseName])
- batchNumber := utils.ToString(row[models.FieldBatchNumber])
- temp = append(temp, product)
- temp = append(temp, fmt.Sprintf("%s", enterprise))
- temp = append(temp, utils.ToString(row[models.FieldUnitName]))
- temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["unit_price"])))
- temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
- temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["money"])))
- temp = append(temp, batchNumber)
- temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
- rows = append(rows, temp)
- totalMoney += utils.ToFloat64(row["money"])
- }
- pdf := &gopdf.GoPdf{}
- pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 841.89, H: 595.28}})
- pdf.SetMarginTop(40)
- pdf.SetMarginBottom(40)
- pdf.AddPage()
- pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
- pdf.SetMargins(2, 5, 5, 5)
- pdf.SetFont("simsun", "", 12)
- //pdf.SetX(20)
- //pdf.SetY(20)
- //pdf.Text("[退货出库]")
- pdf.SetX(668)
- pdf.SetY(60)
- pdf.Text(code)
- imgPath2 := "ofile/img/" + code + ".jpg"
- png2j.Con2jpg(imgPath, imgPath2)
- pdf.Image(imgPath2, 640, 15, &gopdf.Rect{W: 200, H: 35})
- titleStr := reqData.DeptName + "退货单"
- pdf.SetFont("simsun", "", 25)
- textw, _ := pdf.MeasureTextWidth(titleStr)
- pdf.SetX((840 / 2) - (textw / 2))
- pdf.SetY(40)
- pdf.Text(titleStr)
- pdf.SetFont("simsun", "", 12)
- // 第一行
- curx, y := 30., pdf.GetY()
- y += 40
- pdf.SetXY(curx, y)
- pdf.Text("开票日期:" + time.Now().Format("2006-01-02"))
- // 第二行
- curx, y = 30., pdf.GetY()
- y += 20
- pdf.SetXY(curx, y)
- pdf.Text("退货原因:" + reqData.Reason)
- curx = 20
- y += 10
- pdf.SetXY(curx, y)
- h := 20.0
- x := curx
- pdf.SetFont("simsun", "", 10)
- for i := 0; i < len(header); i++ {
- utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += cols[i]
- }
- y += h
- pdf.SetXY(curx, y)
- pdf.SetFont("simsun", "", 10)
- for _, row := range rows {
- curx, y = pdf.GetX(), pdf.GetY()
- x = curx
- height := h
- for i, txt := range row {
- lineTexts, _ := pdf.SplitText(txt, cols[i])
- //lineHt := h * float64(len(lineTexts))
- if len(lineTexts) > 1 {
- lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
- lineHt := h * float64(len(lineTexts)) * 0.6
- if lineHt > height {
- height = lineHt
- }
- }
- }
- for i, txt := range row {
- width := cols[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y+height, height)
- pdf.SetX(curx)
- }
- curx, y = pdf.GetX(), pdf.GetY()
- x = curx
- cols2 := []float64{160, 140, 45, 70, 70, 105, 210}
- row2 := []string{"", "", "", "", "合计:", fmt.Sprintf("%.02f", totalMoney), utils.AmountConvert(totalMoney, true)}
- for i, txt := range row2 {
- width := cols2[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetFont("simsun", "", 12)
- // 第一行
- curx, y = 30., pdf.GetY()
- y += 25
- pdf.SetXY(curx, y)
- pdf.Text("制 单 人:" + beegouser.GetUserName(c.Ctx))
- curx = 265
- pdf.SetXY(curx, y)
- pdf.Text("经 办 人:")
- curx = 565
- pdf.SetXY(curx, y)
- pdf.Text("科室负责人:")
- // 第二行
- curx, y = 30., pdf.GetY()
- y += 30
- pdf.SetXY(curx, y)
- pdf.Text("分管主任:")
- curx = 265
- pdf.SetXY(curx, y)
- pdf.Text("财务部负责人:")
- curx = 565
- pdf.SetXY(curx, y)
- pdf.Text("单位负责人:")
- filename := titleStr + time.Now().Format("20060102150405") + ".pdf"
- // 保存文件
- if err = pdf.WritePdf("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- // StockScrapOutExport 报废出库单
- // @Summary 报废出库单
- // @Description 报废出库单
- // @Tags 库存
- // @Param body body dto.StockRefundOutExport true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/inventory/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockScrapOutExport() {
- reqData := dto.StockRefundOutExport{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- models.InitBasicData(deptId)
- s := services.StockTemplate{}
- list, err := s.StockRefundOutPdf(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- reqData.DeptId = deptId
- reqData.DeptName = beegouser.GetDeptName(c.Ctx)
- cols := []float64{160, 140, 45, 70, 70, 105, 105, 105}
- header := []string{"品种", "生产企业", "单位", "单价", "数量", "金额", "批号", "有效期"}
- rows := [][]string{}
- var totalMoney float64
- for _, row := range list {
- temp := []string{}
- product := utils.ToString(row[models.FieldProductName])
- enterprise := utils.ToString(row[models.FieldEnterpriseName])
- batchNumber := utils.ToString(row[models.FieldBatchNumber])
- temp = append(temp, product)
- temp = append(temp, fmt.Sprintf("%s", enterprise))
- temp = append(temp, utils.ToString(row[models.FieldUnitName]))
- temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["unit_price"])))
- temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
- temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["money"])))
- temp = append(temp, batchNumber)
- temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
- rows = append(rows, temp)
- totalMoney += utils.ToFloat64(row["money"])
- }
- pdf := &gopdf.GoPdf{}
- pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 841.89, H: 595.28}})
- pdf.SetMarginTop(40)
- pdf.SetMarginBottom(40)
- pdf.AddPage()
- pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
- pdf.SetMargins(2, 5, 5, 5)
- pdf.SetFont("simsun", "", 12)
- titleStr := reqData.DeptName + "报废出库单"
- pdf.SetFont("simsun", "", 25)
- textw, _ := pdf.MeasureTextWidth(titleStr)
- pdf.SetX((840 / 2) - (textw / 2))
- pdf.SetY(40)
- pdf.Text(titleStr)
- pdf.SetFont("simsun", "", 12)
- // 第一行
- curx, y := 30., pdf.GetY()
- y += 40
- pdf.SetXY(curx, y)
- pdf.Text("开票日期:" + time.Now().Format("2006-01-02"))
- // 第二行
- curx, y = 30., pdf.GetY()
- y += 20
- pdf.SetXY(curx, y)
- pdf.Text("报废原因:" + reqData.Reason)
- curx = 20
- y += 10
- pdf.SetXY(curx, y)
- h := 20.0
- x := curx
- pdf.SetFont("simsun", "", 10)
- for i := 0; i < len(header); i++ {
- utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += cols[i]
- }
- y += h
- pdf.SetXY(curx, y)
- pdf.SetFont("simsun", "", 10)
- for _, row := range rows {
- curx, y = pdf.GetX(), pdf.GetY()
- x = curx
- height := h
- for i, txt := range row {
- lineTexts, _ := pdf.SplitText(txt, cols[i])
- //lineHt := h * float64(len(lineTexts))
- if len(lineTexts) > 1 {
- lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
- lineHt := h * float64(len(lineTexts)) * 0.6
- if lineHt > height {
- height = lineHt
- }
- }
- }
- for i, txt := range row {
- width := cols[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y+height, height)
- pdf.SetX(curx)
- }
- curx, y = pdf.GetX(), pdf.GetY()
- x = curx
- cols2 := []float64{160, 140, 45, 70, 70, 105, 210}
- row2 := []string{"", "", "", "", "合计:", fmt.Sprintf("%.02f", totalMoney), utils.AmountConvert(totalMoney, true)}
- for i, txt := range row2 {
- width := cols2[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetFont("simsun", "", 12)
- // 第一行
- curx, y = 30., pdf.GetY()
- y += 25
- pdf.SetXY(curx, y)
- pdf.Text("制 单 人:" + beegouser.GetUserName(c.Ctx))
- curx = 265
- pdf.SetXY(curx, y)
- pdf.Text("经 办 人:")
- curx = 565
- pdf.SetXY(curx, y)
- pdf.Text("科室负责人:")
- // 第二行
- curx, y = 30., pdf.GetY()
- y += 30
- pdf.SetXY(curx, y)
- pdf.Text("分管主任:")
- curx = 265
- pdf.SetXY(curx, y)
- pdf.Text("财务部负责人:")
- curx = 565
- pdf.SetXY(curx, y)
- pdf.Text("单位负责人:")
- filename := titleStr + time.Now().Format("20060102150405") + ".pdf"
- // 保存文件
- if err = pdf.WritePdf("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- // TransportRecordExport 运输记录表
- // @Summary 收发登记表word
- // @Description 收发登记表word
- // @Tags 库存
- // @Param body body dto.TransportRecordWordReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /stock-template/inventory/list [post]
- // @Security Bearer
- func (c StockTemplateController) StockOutExport() {
- reqData := models.TransportRecord{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- models.InitBasicData(deptId)
- s := services.StockTemplate{}
- barcodeServ := services.Barcode{}
- list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- reqData.DeptID = deptId
- reqData.DeptName = beegouser.GetDeptName(c.Ctx)
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(deptId)
- code, err := barcodeServ.Insert(reqData)
- if err != nil {
- err = errors.New("生成条码失败")
- c.Error(500, err, err.Error())
- return
- }
- cs, _ := code128.Encode(code)
- // 创建一个要输出数据的文件
- imgPath := "ofile/img/" + code + ".png"
- file, _ := os.Create(imgPath)
- defer file.Close()
- // 设置图片像素大小
- qrCode, _ := barcode.Scale(cs, 205, 50)
- // 将code128的条形码编码为png图片
- png.Encode(file, qrCode)
- cols := []float64{100, 80, 85, 70, 70, 30, 35, 35, 50}
- header := []string{"品种", "生产企业", "规格", "批号", "有效期", "单位", "数量", "单价", "总价"}
- rows := [][]string{}
- var totalMoney float64
- var totalQuantity int
- for _, row := range list {
- temp := []string{}
- product := utils.ToString(row[models.FieldProductName])
- enterprise := utils.ToString(row[models.FieldEnterpriseName])
- spec := utils.ToString(row[models.FieldSpecName])
- batchNumber := utils.ToString(row[models.FieldBatchNumber])
- temp = append(temp, product)
- temp = append(temp, fmt.Sprintf("%s", enterprise))
- temp = append(temp, spec)
- temp = append(temp, batchNumber)
- temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
- temp = append(temp, utils.ToString(row[models.FieldUnitName]))
- temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
- temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["unit_price"])))
- temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["money"])))
- totalMoney += utils.ToFloat64(row["money"])
- totalQuantity += utils.ToInt(row["quantity"])
- rows = append(rows, temp)
- }
- pdf := &gopdf.GoPdf{}
- pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
- pdf.SetMarginTop(40)
- pdf.SetMarginBottom(40)
- pdf.AddPage()
- pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
- pdf.SetMargins(2, 5, 5, 5)
- pdf.SetFont("simsun", "", 10)
- //pdf.SetX(20)
- //pdf.SetY(20)
- //pdf.Text("[退货出库]")
- pdf.SetX(420)
- pdf.SetY(60)
- pdf.Text(code)
- imgPath2 := "ofile/img/" + code + ".jpg"
- png2j.Con2jpg(imgPath, imgPath2)
- pdf.Image(imgPath2, 390, 15, &gopdf.Rect{W: 200, H: 35})
- titleStr := reqData.DeptName + "出库单"
- pdf.SetFont("simsun", "", 22)
- textw, _ := pdf.MeasureTextWidth(titleStr)
- pdf.SetX((595 / 2) - (textw / 2) - 50)
- pdf.SetY(40)
- pdf.Text(titleStr)
- pdf.SetFont("simsun", "", 10)
- // 第一行
- curx, y := 20., pdf.GetY()
- y += 60
- pdf.SetXY(curx, y)
- pdf.Text("收货单位:" + reqData.ReceivingUnit)
- curx = 220
- pdf.SetXY(curx, y)
- pdf.Text("收货人/电话:")
- curx = 330
- pdf.SetXY(curx, y)
- pdf.Text("日期:" + reqData.Date)
- curx = 430
- pdf.SetXY(curx, y)
- pdf.Text("单据:" + code)
- curx = 20
- y += 10
- pdf.SetXY(curx, y)
- h := 20.0
- x := curx
- pdf.SetFont("simsun", "", 9)
- for i := 0; i < len(header); i++ {
- utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += cols[i]
- }
- y += h
- pdf.SetXY(curx, y)
- pdf.SetFont("simsun", "", 8)
- for _, row := range rows {
- curx, y = pdf.GetX(), pdf.GetY()
- x = curx
- height := h
- for i, txt := range row {
- lineTexts, _ := pdf.SplitText(txt, cols[i])
- //lineHt := h * float64(len(lineTexts))
- if len(lineTexts) > 1 {
- lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
- lineHt := h * float64(len(lineTexts)) * 0.6
- if lineHt > height {
- height = lineHt
- }
- }
- }
- for i, txt := range row {
- width := cols[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y+height, height)
- pdf.SetX(curx)
- }
- curx, y = 20, pdf.GetY()
- x = curx
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- rows2 := []string{"金额(大写)", utils.AmountConvert(totalMoney, true), fmt.Sprintf("%.1f", totalMoney)}
- cols2 := [3]float64{}
- cols2[0] = cols[0]
- cols2[1] = cols[1] + cols[2] + cols[3]
- cols2[2] = cols[4] + cols[5] + cols[6] + cols[7] + cols[8]
- for i, txt := range rows2 {
- width := cols2[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y, 20)
- pdf.SetX(curx)
- curx, y = 20, pdf.GetY()
- y += 20
- x = curx
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- rows3 := []string{"数量", fmt.Sprintf("%d", totalQuantity)}
- cols3 := [2]float64{}
- cols3[0] = cols[0]
- cols3[1] = cols[1] + cols[2] + cols[3] + cols[4] + cols[5] + cols[6] + cols[7] + cols[8]
- for i, txt := range rows3 {
- width := cols3[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y, 20)
- pdf.SetX(curx)
- curx, y = 20, pdf.GetY()
- y += 20
- x = curx
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- rows4 := []string{"备注:"}
- cols4 := [1]float64{}
- cols4[0] = cols[0] + cols[1] + cols[2] + cols[3] + cols[4] + cols[5] + cols[6] + cols[7] + cols[8]
- for i, txt := range rows4 {
- width := cols4[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Left, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y, 20)
- if pdf.GetY() < 30 {
- pdf.SetY(30)
- }
- y = pdf.GetY()
- pdf.SetX(curx)
- y += 40
- pdf.SetFont("simsun", "", 10)
- curx = 40
- pdf.SetXY(curx, y)
- pdf.Text("主管:")
- curx = 200
- pdf.SetXY(curx, y)
- pdf.Text("制单:")
- curx = 400
- pdf.SetXY(curx, y)
- pdf.Text("库管:")
- filename := titleStr + time.Now().Format("20060102150405") + ".pdf"
- // 保存文件
- if err = pdf.WritePdf("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- os.Remove(imgPath)
- os.Remove(imgPath2)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
|