1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880 |
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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(), "查询成功")
- }
- // GetStockInquiry 单个产品库存查询
- // @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) GetStockInquiry() {
- s := services.StockTemplate{}
- reqData := dto.GetStockStatReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- res, err := s.GetStockInquiry(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(res, "查询成功")
- }
- // 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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 {
- err = errors.New("解析表单数据异常")
- 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
- }
- transportRecordWordMap := make(map[string][]map[string]interface{})
- for _, row := range list {
- receiving_unit := utils.ToString(row["receiving_unit"])
- if _, ok := transportRecordWordMap[receiving_unit]; !ok {
- list2 := make([]map[string]interface{}, 0)
- list2 = append(list2, row)
- transportRecordWordMap[receiving_unit] = list2
- }else {
- transportRecordWordMap[receiving_unit] = append(transportRecordWordMap[receiving_unit], row)
- }
- }
- reqData.DeptID = deptId
- reqData.DeptName = beegouser.GetDeptName(c.Ctx)
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(deptId)
- pdf := &gopdf.GoPdf{}
- pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
- pdf.SetMarginTop(40)
- pdf.SetMarginBottom(40)
- titleStr := reqData.DeptName + "出库单"
- for receiving_unit, list3 := range transportRecordWordMap {
- reqData.ReceivingUnit = receiving_unit
- var code string
- 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 list3 {
- 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.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})
- defer func() {
- os.Remove(imgPath)
- os.Remove(imgPath2)
- }()
- 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)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
|