1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081 |
- /*
- * Copyright (c) 2023. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
- * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
- * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
- * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
- * Vestibulum commodo. Ut rhoncus gravida arcu.
- */
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/models/data_source"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/services/alarm_msg"
- "eta_gn/eta_api/services/data"
- "eta_gn/eta_api/utils"
- "fmt"
- "os"
- "path/filepath"
- "reflect"
- "sort"
- "strconv"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/shopspring/decimal"
- "github.com/tealeg/xlsx"
- )
- // TargetController 手工指标服务(鉴权)
- type TargetController struct {
- BaseAuthController
- }
- // TargetCommonController 手工指标服务(不鉴权)
- type TargetCommonController struct {
- BaseCommonController
- }
- // DataList
- // @Title 获取指标列表
- // @Description 获取指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param StartDate query string true "开始日期"
- // @Param EndDate query string true "结束日期"
- // @Param Frequency query string true "频度"
- // @Param ClassifyId query int true "分类"
- // @Param KeyWord query string true "名称关键词"
- // @Param TradeCode query string true "指标唯一编码"
- // @Success 200 {object} models.DataListResp
- // @router /data/list [get]
- func (this *TargetController) DataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- frequency := this.GetString("Frequency")
- tradeCode := this.GetString("TradeCode")
- classifyId, _ := this.GetInt("ClassifyId") //分类
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND a.SEC_NAME LIKE ? `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
- }
- if startDate != "" {
- condition += ` AND c.DT >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND c.DT <= ? `
- pars = append(pars, endDate)
- }
- if frequency != "" {
- condition += ` AND a.frequency = ? `
- pars = append(pars, frequency)
- }
- if classifyId > 0 {
- condition += ` AND a.classify_id = ? `
- pars = append(pars, classifyId)
- }
- if tradeCode != "" {
- condition += ` AND c.TRADE_CODE = ? `
- pars = append(pars, tradeCode)
- }
- total, err := models.GetDataListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err := models.GetDataList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.DataListResp)
- resp.Paging = page
- if len(list) <= 0 {
- list = make([]*models.DataList, 0)
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // DataAdd
- // @Title 录入数据
- // @Description 录入数据接口
- // @Param request body models.DataAddReq true "type json string"
- // @Success 200 Ret=200 录入成功
- // @router /data/add [post]
- func (this *TargetController) DataAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DataAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.TradeCode == "" {
- br.Msg = "指标编码不可为空!"
- return
- }
- if req.CreateDate == "" {
- br.Msg = "请选择日期"
- return
- }
- item, err := models.GetDataInfo(req.TradeCode, req.CreateDate)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if item != nil {
- br.Msg = "该指标当前日期下,数据已录入"
- return
- }
- edbdata := new(models.Edbdata)
- edbdata.TradeCode = req.TradeCode
- edbdata.Dt = req.CreateDate
- edbdata.Close = req.Close
- edbdata.ModifyTime = time.Now()
- _, err = models.AddEdbdata(edbdata)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- // 添加操作记录
- go func() {
- record := &models.EdbinfoOpRecord{
- TradeCode: edbdata.TradeCode,
- Remark: "更新数据",
- UserId: this.SysUser.AdminId,
- UserName: this.SysUser.RealName,
- CreateTime: time.Now(),
- }
- data.ModifyManualEdbMaxMinDate(edbdata.TradeCode)
- _ = record.Create()
- //将该指标的code加入到 “手工数据导入后刷新” 缓存
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, req.TradeCode)
- if err != nil {
- fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error())
- }
- }
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // DataEdit
- // @Title 编辑数据
- // @Description 编辑数据接口
- // @Param request body models.DataEditReq true "type json string"
- // @Success 200 Ret=200 编辑数据成功
- // @router /data/edit [post]
- func (this *TargetController) DataEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DataEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.TradeCode == "" {
- br.Msg = "指标编码不可为空!"
- return
- }
- if req.CreateDate == "" {
- br.Msg = "请选择日期"
- return
- }
- close := ""
- loc := reflect.ValueOf(req.Close).Kind().String()
- if loc == "string" {
- close = req.Close.(string)
- } else if loc == "int" {
- closeInt := req.Close.(int)
- close = strconv.Itoa(closeInt)
- } else if loc == "float64" {
- close64 := req.Close.(float64)
- close = strconv.FormatFloat(close64, 'g', 30, 64)
- } else {
- close = ""
- }
- edbdata := new(models.Edbdata)
- edbdata.TradeCode = req.TradeCode
- edbdata.Dt = req.CreateDate
- edbdata.Close = close
- edbdata.ModifyTime = time.Now()
- if req.OldCreateDate == "" {
- item, err := models.GetDataInfo(req.TradeCode, req.CreateDate)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if item == nil { //新增
- _, err = models.AddEdbdata(edbdata)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- } else { //修改
- err = models.EditEdbdata(edbdata)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- }
- } else {
- if req.CreateDate == req.OldCreateDate { //修改
- err = models.EditEdbdata(edbdata)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- } else {
- item, err := models.GetDataInfo(req.TradeCode, req.CreateDate)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if item == nil {
- _, err = models.AddEdbdata(edbdata)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- } else {
- err = models.EditEdbdata(edbdata)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- }
- oldItem, err := models.GetDataInfo(req.TradeCode, req.OldCreateDate)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if oldItem != nil {
- record := new(models.EdbdataDeleteRecord)
- record.TradeCode = oldItem.TradeCode
- record.Dt = oldItem.Dt
- record.Close = oldItem.Close
- record.ModifyTime = oldItem.ModifyTime
- record.CreateTime = time.Now()
- record.SysUserId = this.SysUser.AdminId
- _, err = models.AddEdbdataDeleteRecord(record)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "新增删除记录失败,Err:" + err.Error()
- return
- }
- //删除数据
- models.DeleteEdbData(req.TradeCode, req.OldCreateDate)
- }
- }
- }
- // 数据操作完后的最大最小值/指标库更新
- {
- go func() {
- data.ModifyManualEdbMaxMinDate(req.TradeCode)
- //将该指标的code加入到 “手工数据导入后刷新” 缓存
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, req.TradeCode)
- if err != nil {
- fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error())
- }
- }
- }()
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- }
- // BatchDataEdit
- // @Title 批量编辑数据
- // @Description 批量编辑数据接口
- // @Param request body models.BatchDataEditReq true "type json string"
- // @Success 200 Ret=200 编辑数据成功
- // @router /data/batch_edit [post]
- func (this *TargetController) BatchDataEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.BatchDataEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CreateDate == req.OldCreateDate { //修改
- br.Msg = "开始日期与结束日期一致!"
- return
- }
- edbDataEditList := make([]data.EdbDataEdit, 0)
- for _, trade := range req.List {
- if trade.TradeCode == "" {
- br.Msg = "指标编码不可为空!"
- return
- }
- close := ""
- loc := reflect.ValueOf(trade.Close).Kind().String()
- if loc == "string" {
- close = trade.Close.(string)
- } else if loc == "int" {
- closeInt := trade.Close.(int)
- close = strconv.Itoa(closeInt)
- } else if loc == "float64" {
- close64 := trade.Close.(float64)
- close = strconv.FormatFloat(close64, 'g', 30, 64)
- } else {
- close = ""
- }
- edbDataEdit := data.EdbDataEdit{
- OldCreateDate: req.OldCreateDate,
- CreateDate: req.CreateDate,
- TradeCode: trade.TradeCode,
- Close: close,
- }
- edbDataEditList = append(edbDataEditList, edbDataEdit)
- }
- //批量修改
- failEdbDataList, err := data.BatchEdbData(req.OldCreateDate, req.CreateDate, edbDataEditList, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "批量修改失败"
- br.ErrMsg = "批量修改失败:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = failEdbDataList
- br.Msg = "编辑成功"
- }
- // TargetList
- // @Title 指标列表
- // @Description 指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param StartDate query string true "开始日期"
- // @Param EndDate query string true "结束日期"
- // @Param Frequency query string true "频度"
- // @Param ClassifyId query int true "分类"
- // @Param KeyWord query string true "名称关键词"
- // @Success 200 {object} models.TargetListResp
- // @router /target/list [get]
- func (this *TargetController) TargetList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.Ret = 408
- return
- }
- resp := new(models.TargetListResp)
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- frequency := this.GetString("Frequency")
- classifyId, _ := this.GetInt("ClassifyId") //分类
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- userId := sysUser.AdminId
- //超管账号可以查看分类下的所有频度数据
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- userId = 0
- }
- //获取账户所拥有权限的分类id集合
- classifyIdStrList, err := data.GetEdbClassifyListByAdminId(int64(userId))
- if err != nil {
- br.Msg = "获取分类数据失败"
- return
- }
- total := 0
- list := make([]*models.EdbinfoItem, 0)
- //有分类数据权限才查询
- if len(classifyIdStrList) > 0 {
- condition += ` AND a.classify_id in (` + strings.Join(classifyIdStrList, ",") + `) `
- //关键字
- if keyWord != "" {
- condition += ` AND (a.SEC_NAME LIKE '%` + keyWord + `%' or a.TRADE_CODE LIKE '%` + keyWord + `%' )`
- }
- if startDate != "" {
- startDate = startDate + " 00:00:00"
- condition += ` AND a.create_date >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- endDate = endDate + " 23:59:59"
- condition += ` AND a.create_date <= ? `
- pars = append(pars, endDate)
- }
- if frequency != "" {
- condition += ` AND a.frequency = ? `
- pars = append(pars, frequency)
- }
- if classifyId > 0 {
- condition += ` AND a.classify_id = ? `
- pars = append(pars, classifyId)
- }
- mobile := sysUser.Mobile
- total, err = models.GetEdbinfoListCount(condition, pars, mobile, sysUser.RoleType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- tmpList, err := models.GetEdbinfoItemList(condition, pars, startSize, pageSize, mobile, sysUser.RoleType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if len(tmpList) <= 0 {
- list = make([]*models.EdbinfoItem, 0)
- } else {
- list = tmpList
- }
- systemUserMap := make(map[int]string)
- for k, v := range list {
- userName, ok := systemUserMap[v.UserId]
- if ok == false {
- systemUser, _ := system.GetSysAdminById(v.UserId)
- if systemUser != nil {
- userName = systemUser.RealName
- } else {
- userName = `无`
- }
- systemUserMap[v.UserId] = userName
- }
- list[k].UserName = userName
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // TargetAdd
- // @Title 录入指标
- // @Description 录入指标接口
- // @Param request body models.EdbinfoAddReq true "type json string"
- // @Success 200 Ret=200 录入成功
- // @router /target/add [post]
- func (this *TargetController) TargetAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.EdbinfoAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- tradeCode, err := models.GetMaxTradeCode()
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取最大交易编码失败,Err:" + err.Error()
- return
- }
- maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
- if err != nil {
- br.Msg = "数据异常"
- br.ErrMsg = "获取编码信息失败,Err:" + err.Error()
- return
- }
- if maxTradeCode == "" {
- br.Msg = "编码为空,请联系技术"
- br.ErrMsg = "编码为空,请联系技术"
- return
- }
- if req.SecName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- item, err := models.GetEdbinfoBySecName(req.SecName)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if item != nil {
- br.Msg = "指标名称已存在"
- return
- }
- err = models.AddEdbinfo(maxTradeCode, req.SecName, req.Unit, "手动", req.Frequency, req.NoticeTime, req.ClassifyId, sysUser.AdminId, sysUser.RealName)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- err = models.AddEdbinfoUser(maxTradeCode, sysUser.Mobile)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // TargetEdit
- // @Title 编辑指标
- // @Description 编辑指标
- // @Param request body models.EdbinfoEditReq true "type json string"
- // @Success 200 Ret=200 录入成功
- // @router /target/edit [post]
- func (this *TargetController) TargetEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.EdbinfoEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- if req.TradeCode == "" {
- br.Msg = "数据异常"
- br.ErrMsg = "最大编码为空"
- return
- }
- if req.SecName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- item, err := models.GetEdbinfoBySecName(req.SecName)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if item != nil {
- if req.TradeCode != item.TradeCode {
- br.Msg = "指标名称已存在"
- return
- }
- }
- err = models.EditEdbinfo(req.TradeCode, req.SecName, req.Unit, req.Frequency, req.NoticeTime, req.ClassifyId)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "编辑成功"
- }
- // TargetSearch
- // @Title 搜索指标
- // @Description 搜索指标
- // @Param ClassifyId query int true "分类"
- // @Param KeyWord query string true "名称关键词"
- // @Success 200 {object} models.SearchTargetListResp
- // @router /target/search [get]
- func (this *TargetController) TargetSearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.Ret = 408
- return
- }
- classifyId, _ := this.GetInt("ClassifyId")
- keyWord := this.GetString("KeyWord")
- list, err := models.SearchTargetEntry(classifyId, keyWord)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp := new(models.SearchTargetListResp)
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ClassifyList
- // @Title 获取分类
- // @Description 获取分类
- // @Success 200 {object} models.EdbdataClassifyResp
- // @router /classify [get]
- func (this *TargetController) ClassifyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.Ret = 408
- return
- }
- //mobile := sysUser.Mobile
- //var wxUserId int64
- //if mobile != "" {
- // wxUser, err := models.GetUserByMobile(mobile)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取用户信息失败"
- // br.ErrMsg = "获取用户信息失败,err:" + err.Error()
- // return
- // }
- // if wxUser != nil {
- // wxUserId = wxUser.UserId
- // }
- //}
- var wxUserId int64
- wxUserId = int64(sysUser.AdminId)
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- wxUserId = 0
- }
- list, err := models.GetEdbdataClassify(wxUserId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- classifyIdStrList := make([]string, 0)
- for _, classifyList := range list {
- if classifyList.Child != nil {
- for _, classify := range classifyList.Child {
- classifyIdStrList = append(classifyIdStrList, strconv.Itoa(classify.ClassifyId))
- }
- }
- }
- if len(classifyIdStrList) > 0 {
- edbInfoGroupCountList, err := models.GetEdbInfoGroupCountByClassifyIds(strings.Join(classifyIdStrList, ","))
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类下有数据的指标数量失败,Err:" + err.Error()
- return
- }
- edbInfoGroupCountMap := make(map[int]int)
- for _, edbInfoGroupCount := range edbInfoGroupCountList {
- edbInfoGroupCountMap[edbInfoGroupCount.ClassifyId] = edbInfoGroupCount.Count
- }
- for _, classifyList := range list {
- classifyList.UniqueCode = utils.MD5(fmt.Sprint(classifyList.ClassifyId))
- if classifyList.Child != nil {
- for _, classify := range classifyList.Child {
- if total, ok := edbInfoGroupCountMap[classify.ClassifyId]; ok {
- classify.EdbInfoTotal = total
- classify.UniqueCode = utils.MD5(fmt.Sprint(classify.ClassifyId))
- }
- }
- }
- }
- }
- resp := new(models.EdbdataClassifyResp)
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // TemplateDownload
- // @Title 下载模板
- // @Description 下载模板
- // @Success 200 {object} models.EdbdataClassifyResp
- // @Param Source query int false "来源:1:模板1;2:模板2"
- // @router /template [get]
- func (this *TargetCommonController) TemplateDownload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source, _ := this.GetInt("Source")
- switch source {
- case 2:
- this.Ctx.Output.Download("./static/template/导入模板2.xlsx", "数据导入模板2.xlsx")
- default:
- this.Ctx.Output.Download("./static/template/导入模板1.xlsx", "数据导入模板1.xlsx")
- }
- //this.Ctx.Output.Download("./static/数据导入模板.xlsx", "数据导入模板.xlsx")
- br.Ret = 200
- br.Success = true
- br.Msg = "下载成功"
- }
- // TemplateDownload
- // @Title 下载模板
- // @Description 下载模板
- // @Success 200 {object} models.EdbdataClassifyResp
- // @router /template/en [get]
- func (this *TargetCommonController) TemplateDownloadEn() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- this.Ctx.Output.Download("./static/Data Import Template.xlsx", "Data Import Template.xlsx")
- br.Ret = 200
- br.Success = true
- br.Msg = "下载成功"
- }
- // ImportFailListDownload
- // @Title 下载失败列表
- // @Description 下载失败列表
- // @Success 200 {object} models.EdbdataClassifyResp
- // @router /import/failList [get]
- func (this *TargetController) ImportFailListDownload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- item, err := models.GetFailList(sysUser.AdminId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- xlsxFile := xlsx.NewFile()
- SheetName := "导入失败数据"
- if this.Lang == utils.EnLangVersion {
- SheetName = "Import Fail List"
- }
- sheet, err := xlsxFile.AddSheet(SheetName)
- headRow := sheet.AddRow()
- headRow.AddCell().SetValue("品种/Variety")
- headRow.AddCell().SetValue("指标名称/Indicator Name")
- headRow.AddCell().SetValue("指标日期/Indicator Date")
- headRow.AddCell().SetValue("值/Value")
- headRow.AddCell().SetValue("频度/Frequency")
- headRow.AddCell().SetValue("单位/Unit")
- headRow.AddCell().SetValue("备注/Note")
- for _, v := range item {
- row := sheet.AddRow()
- row.AddCell().SetValue(v.ClassifyName)
- row.AddCell().SetValue(v.SecName)
- row.AddCell().SetValue(v.CreateDate)
- row.AddCell().SetString(v.Close)
- row.AddCell().SetValue(v.Frequency)
- row.AddCell().SetValue(v.Unit)
- row.AddCell().SetValue(v.Remark)
- }
- fileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- savePath := "./static/" + fileName
- err = xlsxFile.Save(savePath)
- if err != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败,Err:" + err.Error()
- return
- }
- defer func() {
- os.Remove(savePath)
- }()
- finalFileName := "失败列表.xlsx"
- if this.Lang == utils.EnLangVersion {
- finalFileName = "Failure List.xlsx"
- }
- this.Ctx.Output.Download(savePath, finalFileName)
- }
- // ExportDataList
- // @Title 导出数据
- // @Description 导出数据列表
- // @Param StartDate query string true "开始日期"
- // @Param EndDate query string true "结束日期"
- // @Param Frequency query string true "频度"
- // @Param ClassifyId query int true "分类"
- // @Param KeyWord query string true "名称关键词"
- // @Param TradeCode query string true "指标唯一编码"
- // @Param Mobile query string true "手机号"
- // @Success 200 导出成功
- // @router /export/dataList [get]
- func (this *TargetController) ExportDataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- keyWord := this.GetString("KeyWord")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- frequency := this.GetString("Frequency")
- classifyId, _ := this.GetInt("ClassifyId") //分类
- mobile := this.GetString("Mobile") //分类
- tradeCode := this.GetString("TradeCode") //指标唯一编码
- var condition string
- var pars []interface{}
- // 指标名称
- if keyWord != "" {
- condition += ` AND a.SEC_NAME LIKE '%` + keyWord + `%'`
- }
- //分类ID
- if tradeCode != "" {
- condition += ` AND a.TRADE_CODE = ? `
- pars = append(pars, tradeCode)
- }
- if startDate != "" {
- condition += ` AND c.DT >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND c.DT <= ? `
- pars = append(pars, endDate)
- }
- if frequency != "" {
- condition += ` AND a.frequency = ? `
- pars = append(pars, frequency)
- }
- permissionUserId := sysUser.AdminId
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- permissionUserId = 0
- }
- childClassifyIdList := make([]int, 0)
- // 所属分类
- if classifyId > 0 {
- // 获取有用权限的分类
- classifyList, err := models.GetEdbdataClassify(int64(permissionUserId))
- if err != nil {
- return
- }
- var isParent bool
- for _, v := range classifyList {
- if v.ClassifyId == classifyId {
- isParent = true
- childClassifyIdList = append(childClassifyIdList, v.ClassifyId)
- if v.Child != nil && len(v.Child) > 0 {
- for _, vv := range v.Child {
- childClassifyIdList = append(childClassifyIdList, vv.ClassifyId)
- }
- }
- break
- }
- }
- // 如果是最小级,那么就把自己放进去
- if !isParent {
- childClassifyIdList = append(childClassifyIdList, classifyId)
- }
- }
- // 如果所选分类是一级时,那么是一级下的所有分类;如果是二级时,那么是二级自己本身
- num := len(childClassifyIdList)
- condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
- pars = append(pars, childClassifyIdList)
- if mobile != "" {
- condition += ` AND d.mobile=? `
- pars = append(pars, mobile)
- }
- userId := sysUser.AdminId
- //超管账号可以查看分类下的所有频度数据
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- userId = 0
- }
- //获取账户所拥有权限的分类id集合
- classifyIdStrList, err := data.GetEdbClassifyListByAdminId(int64(userId))
- if err != nil {
- br.Msg = "获取分类数据失败"
- return
- }
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downloadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- var frequencies []string
- if len(childClassifyIdList) > 0 {
- frequencies, err = models.GetEdbDataFrequencyByClassifyIdList(childClassifyIdList)
- if err != nil {
- br.Msg = "查询频度失败"
- br.ErrMsg = "查询频度失败"
- return
- }
- } else if tradeCode != `` {
- manualEdb, err := models.GetEdbinfoByTradeCode(tradeCode)
- if err != nil {
- br.Msg = "查询指标信息失败"
- br.ErrMsg = "查询指标信息失败,err:" + err.Error()
- return
- }
- frequencies = append(frequencies, manualEdb.Frequency)
- } else if keyWord != `` {
- frequencies, err = models.GetEdbDataFrequencyByKeyord(keyWord)
- if err != nil {
- br.Msg = "查询频度失败"
- br.ErrMsg = "查询频度失败"
- return
- }
- } else {
- // 啥也没选的情况下
- frequencies = append(frequencies, `日度`, `周度`, `月度`, `季度`, `半年度`, `年度`)
- }
- fileName := `手工数据`
- if frequencies == nil {
- sheet, err := xlsxFile.AddSheet("无数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("")
- }
- for _, frequency := range frequencies {
- secNameList := make([]*models.EdbdataExportList, 0)
- if len(classifyIdStrList) > 0 {
- newCondition := condition
- newCondition += ` AND a.classify_id in (` + strings.Join(classifyIdStrList, ",") + `) `
- newCondition += ` AND a.frequency = ? `
- pars := append(pars, frequency)
- tmpSecNameList, err := models.GetEdbdataSecName(newCondition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- secNameList = tmpSecNameList
- }
- var sheet *xlsx.Sheet
- if len(secNameList) > 0 {
- sheet, err = xlsxFile.AddSheet(frequency)
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- fileName = secNameList[0].ClassifyName
- } else {
- continue
- }
- //获取指标数据
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("指标名称")
- rowFrequency := sheet.AddRow()
- celFrequency := rowFrequency.AddCell()
- celFrequency.SetValue("频率")
- rowUnit := sheet.AddRow()
- celUnit := rowUnit.AddCell()
- celUnit.SetValue("单位")
- rowModifyDate := sheet.AddRow()
- rowModifyCell := rowModifyDate.AddCell()
- rowModifyCell.SetValue("更新时间")
- dataMap := make(map[string]map[string]*models.EdbdataItem)
- var tradeCodeList []string
- for _, v := range secNameList {
- cellSenName := rowSecName.AddCell()
- cellSenName.SetValue(v.SecName)
- celFrequency := rowFrequency.AddCell()
- celFrequency.SetValue(v.Frequency)
- celUnit := rowUnit.AddCell()
- celUnit.SetValue(v.Unit)
- rowModifyCell := rowModifyDate.AddCell()
- rowModifyCell.SetValue(v.Dt)
- tradeCodeList = append(tradeCodeList, v.TradeCode)
- items, err := models.GetEdbdataAllByTradeCode(v.TradeCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.ErrMsg = "GetEdbdataAllByTradeCode,Err:" + err.Error()
- br.Msg = "获取数据失败"
- return
- }
- for _, item := range items {
- if dataMap[item.TradeCode] == nil {
- dataMap[item.TradeCode] = make(map[string]*models.EdbdataItem)
- }
- dataMap[item.TradeCode][item.Dt] = item
- fmt.Println(item.TradeCode, item.Dt)
- }
- }
- tradeCodeStr := strings.Join(tradeCodeList, "','")
- tradeCodeStr = "'" + tradeCodeStr + "'"
- dateList, err := models.GetEdbdataList(tradeCodeStr)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- for _, n := range dateList {
- rowData := sheet.AddRow()
- celDate := rowData.AddCell()
- celDate.SetValue(n.Dt)
- for _, m := range secNameList {
- celData := rowData.AddCell()
- fmt.Println(m.TradeCode)
- fmt.Println(n.Dt)
- if dataMap[m.TradeCode][n.Dt] != nil {
- celData.SetValue(dataMap[m.TradeCode][n.Dt].Close)
- }
- }
- }
- }
- err = xlsxFile.Save(downloadFilePath)
- if err != nil {
- //有指标无数据时先导出一遍空表
- sheet, err := xlsxFile.AddSheet("无数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("")
- err = xlsxFile.Save(downloadFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- }
- defer func() {
- os.Remove(downloadFilePath)
- }()
- fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
- this.Ctx.Output.Download(downloadFilePath, fileName)
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
- // DataList
- // @Title 导出数据
- // @Description 导出数据列表
- // @Param StartDate query string true "开始日期"
- // @Param EndDate query string true "结束日期"
- // @Param Frequency query string true "频度"
- // @Param ClassifyId query int true "分类"
- // @Param KeyWord query string true "名称关键词"
- // @Param Mobile query string true "手机号"
- // @Success 200 导出成功
- // @router /dataList [get]
- func (this *TargetCommonController) DataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- br.Msg = "成功"
- br.Ret = 200
- }
- // DataDelete
- // @Title 数据删除
- // @Description 数据删除
- // @Param request body models.DataDeleteReq true "type json string"
- // @Success 200 Ret=200 录入成功
- // @router /data/delete [post]
- func (this *TargetController) DataDelete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DataDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- if req.TradeCode == "" {
- br.Msg = "指标编码不可为空"
- br.ErrMsg = "指标编码不可为空"
- return
- }
- if req.CreateDate == "" {
- br.Msg = "数据录入日期不可为空"
- return
- }
- item, err := models.GetDataInfo(req.TradeCode, req.CreateDate)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if item == nil {
- br.Msg = "数据不存在"
- return
- }
- err = models.DataDelete(req.TradeCode, req.CreateDate, item.Close, item.ModifyTime, sysUser.AdminId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // DataCheck
- // @Title 数据删除校验
- // @Description 数据删除校验
- // @Param TradeCode query string true "指标唯一编码"
- // @Param CreateDate query string true "数据录入日期"
- // @Success Ret=200 可删除
- // @router /data/check [get]
- func (this *TargetController) DataCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- tradeCode := this.GetString("TradeCode")
- createDate := this.GetString("CreateDate")
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- if tradeCode == "" {
- br.Msg = "指标编码不可为空"
- return
- }
- if createDate == "" {
- br.Msg = "请选择日期"
- return
- }
- resp := new(models.DataCheckResp)
- item, err := models.GetDataInfo(tradeCode, createDate)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- if item != nil {
- resp.Status = 1
- resp.Close = item.Close
- } else {
- resp.Status = 0
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "检测成功"
- br.Data = resp
- }
- // TargetCheck
- // @Title 指标删除校验
- // @Description 指标删除校验
- // @Param TradeCode query string true "指标唯一编码"
- // @Success Ret=200 可删除
- // @router /target/check [get]
- func (this *TargetController) TargetCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- tradeCode := this.GetString("TradeCode")
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- if tradeCode == "" {
- br.Msg = "指标编码不可为空"
- return
- }
- resp := new(models.DataCheckResp)
- count, err := data_manage.GetEdbInfoCount(utils.DATA_SOURCE_MANUAL, tradeCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- resp.Status = 1
- } else {
- resp.Status = 0
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "指标不存在关联数据,可直接删除"
- br.Data = resp
- }
- // TargetDelete
- // @Title 指标删除
- // @Description 指标删除
- // @Param request body models.TargetDeleteReq true "type json string"
- // @Success Ret=200 删除成功
- // @router /target/delete [post]
- func (this *TargetController) TargetDelete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.TargetDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.TradeCode == "" {
- br.Msg = "指标编码不可为空"
- return
- }
- //判断是否在指标数据导入的过程,如果是在该过程,那么就不允许用户操作
- key := "import:edbinfo:data:" + req.TradeCode
- if utils.Rc.IsExist(key) {
- br.Msg = "该指标正在导入数据中,请稍后操作"
- return
- }
- err = models.TargetDelete(req.TradeCode)
- if err != nil {
- br.Msg = "删除失败"
- br.Msg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "删除成功"
- }
- // GetResearcher
- // @Title 获取研究员
- // @Description 获取研究员
- // @Success 200 {object} models.ResearcherListResp
- // @router /getResearcher [get]
- func (this *TargetController) GetResearcher() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- var err error
- list := make([]*models.Researcher, 0)
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
- sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
- sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- list, err = models.GetResearcherEntry()
- if err != nil {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- } else if sysUser.Role == "hggroup" {
- mobileStr := "'15888577277','15888856487','15158848535','13651627324' "
- list, err = models.GetResearcherEntryByMobile(mobileStr)
- if err != nil {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- } else if sysUser.AdminName == "dfma" {
- list, err = models.GetResearcherEntry()
- if err != nil {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- }
- resp := new(models.ResearcherListResp)
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetTargetItems
- // @Title 获取研究员指标
- // @Description 获取研究员指标
- // @Param Mobile query string true "手机号"
- // @Param ClassifyId query int true "分类id"
- // @Success 200 {object} models.ResearcherListResp
- // @router /getTargetItems [get]
- func (this *TargetController) GetTargetItems() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- mobile := this.GetString("Mobile")
- if mobile == "" {
- mobile = sysUser.Mobile
- }
- classifyId, _ := this.GetInt("ClassifyId")
- items, err := models.GetTargetItems(mobile, classifyId)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- resp := new(models.TargetItemsResp)
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ExportLongzhong
- // @Title 隆众数据下载
- // @Description 隆众数据下载接口
- // @Success 200 {object} models.ResearcherListResp
- // @router /export/longzhong [get]
- func (this *TargetCommonController) ExportLongzhong() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- parentId := 4
- classifyList, err := models.GetEdbdataClassifyByParentId(parentId)
- if err != nil {
- return
- }
- xlsxFile := xlsx.NewFile()
- if err != nil {
- fmt.Println("生成文件失败" + err.Error())
- return
- }
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/static/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- for _, v := range classifyList {
- fmt.Println(v.ClassifyId, v.ClassifyName)
- //获取指标
- secNameList, err := data_source.GetLongzhonginfoByClassifyId(v.ClassifyId)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(secNameList) <= 0 {
- continue
- }
- sheetNew, err := xlsxFile.AddSheet(v.ClassifyName)
- if err != nil {
- fmt.Println("新增Sheet失败", err.Error())
- return
- }
- //sheetNew.SetColWidth()
- //获取指标数据
- windRow := sheetNew.AddRow()
- secNameRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- //获取分类下指标最大数据量
- dataMax, err := data_source.GetLongzhongDataMaxCount(v.ClassifyId)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- for k, sv := range secNameList {
- fmt.Println("line 399:", v.ClassifyId, v.ClassifyName, sv.SecName, sv.Frequency)
- windRow.AddCell().SetValue("Wind")
- secNameRow.AddCell().SetValue("指标名称")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- secNameRow.AddCell().SetValue(sv.SecName)
- frequencyRow.AddCell().SetValue(sv.Frequency)
- unitRow.AddCell().SetValue(sv.Unit)
- lastModifyDateRow.AddCell().SetValue(sv.LastModifyDate)
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- //获取数据
- dataList, err := data_source.GetLongzhongDataById(sv.LongzhonginfoId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := 5 + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := 5 + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DisplayTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetFloat(dv.Close)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- fileName := "隆众石化数据" + time.Now().Format("200601021504") + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
- // ExportLongzhongPrice
- // @Title 隆众价格数据下载
- // @Description 隆众价格数据下载接口
- // @Success 200 {object} models.ResearcherListResp
- // @router /export/longzhong/price [get]
- func (this *TargetCommonController) ExportLongzhongPrice() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyList, err := models.GetLzPriceClassify()
- if err != nil {
- return
- }
- xlsxFile := xlsx.NewFile()
- if err != nil {
- fmt.Println("生成文件失败" + err.Error())
- return
- }
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/static/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- for _, v := range classifyList {
- //获取指标
- secNameList, err := models.GetLongzhongpriceinfoByClassifyName(v.ProductName)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(secNameList) <= 0 {
- continue
- }
- sheetNew, err := xlsxFile.AddSheet(v.ProductName)
- if err != nil {
- fmt.Println("新增Sheet失败", err.Error())
- return
- }
- //获取指标数据
- windRow := sheetNew.AddRow()
- secNameRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- marketRow := sheetNew.AddRow()
- manufactureRow := sheetNew.AddRow()
- standardRow := sheetNew.AddRow() //规格
- modelNameRow := sheetNew.AddRow() //规格型号
- titleRow := sheetNew.AddRow()
- //获取分类下指标最大数据量
- dataMax, err := models.GetLongzhongPriceDataMaxCount(v.ProductName)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- for k, sv := range secNameList {
- fmt.Println("line 399:", v.ProductName, sv.InfoTypeRemark, sv.AreaName)
- windRow.AddCell().SetString("Wind")
- secNameRow.AddCell().SetValue("分类")
- frequencyRow.AddCell().SetValue("价格类型")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("地区")
- marketRow.AddCell().SetValue("市场名称")
- manufactureRow.AddCell().SetValue("厂家名称")
- standardRow.AddCell().SetValue("规格")
- modelNameRow.AddCell().SetValue("规格型号")
- secNameRow.AddCell().SetValue(sv.InfoTypeRemark)
- frequencyRow.AddCell().SetValue(sv.PriceType)
- unitRow.AddCell().SetValue(sv.Unit)
- lastModifyDateRow.AddCell().SetValue(sv.AreaName)
- marketRow.AddCell().SetValue(sv.MarketName)
- manufactureRow.AddCell().SetValue(sv.ManufactureName)
- standardRow.AddCell().SetValue(sv.Standard)
- modelNameRow.AddCell().SetValue(sv.ModelName)
- windRow.AddCell()
- windRow.AddCell()
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- marketRow.AddCell()
- manufactureRow.AddCell()
- standardRow.AddCell()
- modelNameRow.AddCell()
- secNameRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- marketRow.AddCell()
- manufactureRow.AddCell()
- standardRow.AddCell()
- modelNameRow.AddCell()
- secNameRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- marketRow.AddCell()
- manufactureRow.AddCell()
- standardRow.AddCell()
- modelNameRow.AddCell()
- titleRow.AddCell().SetValue("价格日期")
- titleRow.AddCell().SetValue("价格")
- titleRow.AddCell().SetValue("低端价格")
- titleRow.AddCell().SetValue("高端价格")
- titleRow.AddCell()
- min := k * 5
- sheetNew.SetColWidth(min, min, 15)
- //获取数据
- dataList, err := models.GetLongzhongPriceDataById(sv.LongzhongpriceinfoId)
- if err != nil {
- fmt.Println("GetLongzhongDataById Err:" + err.Error())
- return
- }
- rowStart := 10
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := rowStart + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := rowStart + rk
- row := sheetNew.Row(rowIndex)
- priceDate, _ := time.Parse(utils.FormatDate, dv.PriceDate)
- row.AddCell().SetDate(priceDate)
- row.AddCell().SetFloat(dv.Price)
- row.AddCell().SetFloat(dv.LowPrice)
- row.AddCell().SetFloat(dv.HighPrice)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- fileName := "隆众价格数据" + time.Now().Format("200601021504") + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
- // ExportLongzhongSurvey
- // @Title 隆众调研数据下载
- // @Description 隆众调研数据下载接口
- // @Success 200 {object} models.ResearcherListResp
- // @router /export/longzhong/survey [get]
- func (this *TargetCommonController) ExportLongzhongSurvey() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyList, err := models.GetLzSurveyClassify()
- if err != nil {
- return
- }
- xlsxFile := xlsx.NewFile()
- if err != nil {
- fmt.Println("生成文件失败" + err.Error())
- return
- }
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/static/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- for _, v := range classifyList {
- //获取指标
- secNameList, err := models.GetLongzhongSurveyProductByClassifyName(v.ProductName)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(secNameList) <= 0 {
- continue
- }
- sheetNew, err := xlsxFile.AddSheet(v.ProductName)
- if err != nil {
- fmt.Println("新增Sheet失败", err.Error())
- return
- }
- //sheetNew.SetColWidth()
- //获取指标数据
- windRow := sheetNew.AddRow()
- secNameRow := sheetNew.AddRow()
- indexCodeRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- //获取分类下指标最大数据量
- dataMax, err := data_source.GetLongzhongSurveyDataMaxCount(v.ProductName)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- setRowIndex := 6
- for k, sv := range secNameList {
- windRow.AddCell().SetValue("隆众")
- secNameRow.AddCell().SetValue("指标名称")
- indexCodeRow.AddCell().SetValue("指标ID")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- secNameRow.AddCell().SetValue(sv.SampleName + sv.BreedName + sv.Custom + sv.QuotaName)
- indexCodeRow.AddCell().SetValue(sv.LzCode)
- if sv.Frequency == 1 {
- frequencyRow.AddCell().SetValue("日度")
- } else if sv.Frequency == 2 {
- frequencyRow.AddCell().SetValue("周度")
- } else if sv.Frequency == 3 {
- frequencyRow.AddCell().SetValue("月度")
- } else if sv.Frequency == 4 {
- frequencyRow.AddCell().SetValue("季度")
- } else if sv.Frequency == 5 {
- frequencyRow.AddCell().SetValue("年度")
- } else if sv.Frequency == 99 {
- frequencyRow.AddCell().SetValue("无固定频率")
- }
- unitRow.AddCell().SetValue(sv.UnitName)
- lastModifyDateRow.AddCell().SetValue(sv.EndDate)
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- indexCodeRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- //获取数据
- dataList, err := data_source.GetLongzhongSurveyDataById(sv.SurveyProductId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := setRowIndex + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetFloat(dv.InputValue)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- fileName := "隆众调研数据" + time.Now().Format("200601021504") + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
- // TargetUnitList
- // @Title 指标列表
- // @Description 指标列表接口
- // @Success 200 {object} []string
- // @router /target/unit_list [get]
- func (this *TargetController) TargetUnitList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.Ret = 408
- return
- }
- list, err := models.GetEdbUnitList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- edbUnitList := make([]string, 0)
- for _, unit := range list {
- edbUnitList = append(edbUnitList, unit.Unit)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = edbUnitList
- }
- // TargetFrequencyList
- // @Title 指标频度列表
- // @Description 指标频度列表接口
- // @Param ClassifyId query int true "分类"
- // @Success 200 {object} []string
- // @router /target/frequency_list [get]
- func (this *TargetController) TargetFrequencyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.Ret = 408
- return
- }
- classifyId, _ := this.GetInt("ClassifyId") //分类
- if classifyId <= 0 {
- br.Msg = "分类ID必传"
- return
- }
- userId := sysUser.AdminId
- //超管账号可以查看分类下的所有频度数据
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- userId = 0
- }
- list, err := models.GetEdbFrequencyList(classifyId, userId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- edbFrequencyList := make([]string, 0)
- for _, unit := range list {
- edbFrequencyList = append(edbFrequencyList, unit.Frequency)
- }
- edbFrequencyList = sortEdbFrequency(edbFrequencyList)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = edbFrequencyList
- }
- func sortEdbFrequency(frequencyList []string) (newFrequencyList []string) {
- var frequencyMap1 = map[string]int{
- "日度": 1,
- "周度": 2,
- "旬度": 3,
- "月度": 4,
- "季度": 5,
- "半年度": 6,
- "年度": 7,
- }
- var frequencyMap2 = map[int]string{
- 1: "日度",
- 2: "周度",
- 3: "旬度",
- 4: "月度",
- 5: "季度",
- 6: "半年度",
- 7: "年度",
- }
- idList := make([]int, 0)
- for _, frequency := range frequencyList {
- idList = append(idList, frequencyMap1[frequency])
- }
- sort.Ints(idList)
- for _, id := range idList {
- newFrequencyList = append(newFrequencyList, frequencyMap2[id])
- }
- return
- }
- // TargetItemList
- // @Title 获取研究员指标
- // @Description 获取研究员指标
- // @Param Frequency query string false "频度;枚举值:日度、周度、旬度、月度、季度、半年度、年度"
- // @Param Keyword query string false "关键字搜索"
- // @Param TradeCode query string false "指标唯一编码"
- // @Param ClassifyId query int false "分类id"
- // @Param EdbShowType query string true "指标展示类型:0,1,2; 0:不管有没有数据,指标都展示出来, 1:只展示有数据的指标, 2:只展示没有数据的指标"
- // @Success 200 {object} models.TargetItemListResp
- // @router /target/item_list [get]
- func (this *TargetController) TargetItemList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- //频度
- frequency := this.GetString("Frequency")
- //关键字
- keyword := this.GetString("Keyword")
- //指标编码
- tradeCode := this.GetString("TradeCode")
- userId := sysUser.AdminId
- //超管账号可以查看分类下的所有频度数据
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- userId = 0
- }
- //获取账户所拥有权限的分类id集合
- classifyIdStrList, err := data.GetEdbClassifyListByAdminId(int64(userId))
- if err != nil {
- br.Msg = "获取分类数据失败"
- return
- }
- classifyId, _ := this.GetInt("ClassifyId")
- edbShowType, _ := this.GetInt("EdbShowType")
- list, err := models.GetTargetItemList(classifyId, edbShowType, frequency, keyword, tradeCode, classifyIdStrList)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- edbTradeCodeList := make([]string, 0)
- //频度数据
- frequencyMap := make(map[string]int)
- for _, edb := range list {
- edbTradeCodeList = append(edbTradeCodeList, edb.TradeCode)
- frequencyMap[edb.Frequency] = 0
- }
- frequencyList := make([]string, 0)
- for k := range frequencyMap {
- frequencyList = append(frequencyList, k)
- }
- frequencyList = sortEdbFrequency(frequencyList)
- if len(edbTradeCodeList) > 0 {
- edbTradeCodeStr := `"` + strings.Join(edbTradeCodeList, `","`) + `"`
- edbDataList, err := models.GetEdbDataListByCodes(edbTradeCodeStr)
- if err != nil {
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- edbDataMap := make(map[string][]*models.Edbdata, 0)
- for _, edbData := range edbDataList {
- if _, ok := edbDataMap[edbData.TradeCode]; ok {
- edbDataMap[edbData.TradeCode] = append(edbDataMap[edbData.TradeCode], edbData)
- } else {
- tmpEdbDataList := make([]*models.Edbdata, 0)
- tmpEdbDataList = append(tmpEdbDataList, edbData)
- edbDataMap[edbData.TradeCode] = tmpEdbDataList
- }
- }
- //nowWeek := time.Now().Weekday().String() //当前周几
- myYear := time.Now().Year() //当前年份
- myMonth := time.Now().Format("01") //当前月份
- //当前周的周一与周日
- nowWeekFirstDay := utils.GetNowWeekMonday()
- nowWeekLastDay := utils.GetNowWeekLastDay()
- //当前月的一号与最后一天
- nowMonthFirstDay := utils.GetNowMonthFirstDay()
- nowMonthLastDay := utils.GetNowMonthLastDay()
- //当前季度的第一天与最后一天
- nowQuarterFirstDay := utils.GetNowQuarterFirstDay()
- nowQuarterLastDay := utils.GetNowQuarterLastDay()
- //当前半年的第一天与最后一天
- nowHalfYearFirstDay := utils.GetNowHalfYearFirstDay()
- nowHalfYearLastDay := utils.GetNowHalfYearLastDay()
- // 当前年的第一天与最后一天
- nowYearFirstDay := utils.GetNowYearFirstDay()
- nowYearLastDay := utils.GetNowYearLastDay()
- for _, edb := range list {
- edb.Status = "未完成"
- if dataList, ok := edbDataMap[edb.TradeCode]; ok {
- edb.DataList = dataList
- dataDtTime, _ := time.ParseInLocation(utils.FormatDate, dataList[0].Dt, time.Now().Location()) //最近的一条数据时间
- switch edb.Frequency {
- case "日度":
- if time.Now().After(dataDtTime.AddDate(0, 0, 1)) {
- edb.ModifyDate = time.Now().Format(utils.FormatDate)
- } else {
- edb.ModifyDate = dataDtTime.AddDate(0, 0, 1).Format(utils.FormatDate)
- edb.Status = "完成"
- }
- case "周度":
- //if edb.NoticeTime != "" {
- // noticeArr := strings.Split(edb.NoticeTime, " ")
- // noticeWeek := noticeArr[0]
- // addDay := 0
- //
- // if nowWeek == "Sunday" {
- // if noticeWeek == "周日" {
- // addDay = 0
- // } else if noticeWeek == "周一" {
- // addDay = 1
- // } else if noticeWeek == "周二" {
- // addDay = 2
- // } else if noticeWeek == "周三" {
- // addDay = 3
- // } else if noticeWeek == "周四" {
- // addDay = 4
- // } else if noticeWeek == "周五" {
- // addDay = 5
- // } else if noticeWeek == "周六" {
- // addDay = 6
- // } else {
- // addDay = 0
- // }
- // } else if nowWeek == "Monday" {
- // if noticeWeek == "周日" {
- // addDay = 6
- // } else if noticeWeek == "周一" {
- // addDay = 0
- // } else if noticeWeek == "周二" {
- // addDay = 1
- // } else if noticeWeek == "周三" {
- // addDay = 2
- // } else if noticeWeek == "周四" {
- // addDay = 3
- // } else if noticeWeek == "周五" {
- // addDay = 4
- // } else if noticeWeek == "周六" {
- // addDay = 5
- // } else {
- // addDay = 0
- // }
- // } else if nowWeek == "Tuesday" {
- // if noticeWeek == "周日" {
- // addDay = 5
- // } else if noticeWeek == "周一" {
- // addDay = 6
- // } else if noticeWeek == "周二" {
- // addDay = 0
- // } else if noticeWeek == "周三" {
- // addDay = 1
- // } else if noticeWeek == "周四" {
- // addDay = 2
- // } else if noticeWeek == "周五" {
- // addDay = 3
- // } else if noticeWeek == "周六" {
- // addDay = 4
- // } else {
- // addDay = 0
- // }
- // } else if nowWeek == "Wednesday" {
- // if noticeWeek == "周日" {
- // addDay = 4
- // } else if noticeWeek == "周一" {
- // addDay = 5
- // } else if noticeWeek == "周二" {
- // addDay = 6
- // } else if noticeWeek == "周三" {
- // addDay = 0
- // } else if noticeWeek == "周四" {
- // addDay = 1
- // } else if noticeWeek == "周五" {
- // addDay = 2
- // } else if noticeWeek == "周六" {
- // addDay = 3
- // } else {
- // addDay = 0
- // }
- // } else if nowWeek == "Thursday" {
- // if noticeWeek == "周日" {
- // addDay = 3
- // } else if noticeWeek == "周一" {
- // addDay = 4
- // } else if noticeWeek == "周二" {
- // addDay = 5
- // } else if noticeWeek == "周三" {
- // addDay = 6
- // } else if noticeWeek == "周四" {
- // addDay = 0
- // } else if noticeWeek == "周五" {
- // addDay = 1
- // } else if noticeWeek == "周六" {
- // addDay = 2
- // } else {
- // addDay = 0
- // }
- // } else if nowWeek == "Friday" {
- // if noticeWeek == "周日" {
- // addDay = 2
- // } else if noticeWeek == "周一" {
- // addDay = 3
- // } else if noticeWeek == "周二" {
- // addDay = 4
- // } else if noticeWeek == "周三" {
- // addDay = 5
- // } else if noticeWeek == "周四" {
- // addDay = 6
- // } else if noticeWeek == "周五" {
- // addDay = 0
- // } else if noticeWeek == "周六" {
- // addDay = 1
- // } else {
- // addDay = 0
- // }
- // } else if nowWeek == "Saturday" {
- // if noticeWeek == "周日" {
- // addDay = 1
- // } else if noticeWeek == "周一" {
- // addDay = 2
- // } else if noticeWeek == "周二" {
- // addDay = 3
- // } else if noticeWeek == "周三" {
- // addDay = 4
- // } else if noticeWeek == "周四" {
- // addDay = 5
- // } else if noticeWeek == "周五" {
- // addDay = 6
- // } else if noticeWeek == "周六" {
- // addDay = 0
- // } else {
- // addDay = 0
- // }
- // }
- //
- // modifyDate := time.Now().AddDate(0, 0, addDay)
- // if modifyDate.After(dataDtTime.AddDate(0, 0, 1)) {
- // edb.ModifyDate = modifyDate.Format(utils.FormatDate)
- // } else {
- // edb.ModifyDate = modifyDate.AddDate(0, 0, 7).Format(utils.FormatDate)
- // edb.Status = "完成"
- // }
- //} else {
- // if startWeekDay.Unix() <= dataDtTime.Unix() {
- // edb.ModifyDate = endWeekDay.AddDate(0, 0, 7).Format(utils.FormatDate)
- // edb.Status = "完成"
- // } else {
- // edb.ModifyDate = endWeekDay.Format(utils.FormatDate)
- // }
- //}
- modifyDate := nowWeekLastDay //下次更新日期
- if edb.NoticeTime != "" {
- addDay := 7
- noticeArr := strings.Split(edb.NoticeTime, " ")
- noticeWeek := noticeArr[0]
- switch noticeWeek {
- case "周一":
- addDay = 1
- case "周二":
- addDay = 2
- case "周三":
- addDay = 3
- case "周四":
- addDay = 4
- case "周五":
- addDay = 5
- case "周六":
- addDay = 6
- case "周日":
- addDay = 7
- }
- modifyDate = modifyDate.AddDate(0, 0, addDay-7)
- }
- if nowWeekFirstDay.Before(dataDtTime) {
- edb.ModifyDate = modifyDate.AddDate(0, 0, 7).Format(utils.FormatDate)
- edb.Status = "完成"
- } else {
- edb.ModifyDate = modifyDate.Format(utils.FormatDate)
- }
- case "月度":
- addDay := 0
- modifyDate := nowMonthLastDay //下次更新日期
- if edb.NoticeTime != "" {
- strArr := strings.Split(edb.NoticeTime, "日")
- tmpAddDay, tmpErr := strconv.Atoi(strArr[0])
- if tmpErr != nil {
- continue
- }
- addDay = tmpAddDay - 1
- modifyDate = nowMonthFirstDay.AddDate(0, 0, addDay)
- }
- if nowMonthFirstDay.Before(dataDtTime) {
- if int(time.Now().Month()) != int(nowMonthFirstDay.Month()) {
- edb.ModifyDate = nowMonthLastDay.Format(utils.FormatDate)
- } else {
- month := nowMonthLastDay.Month() + 1
- edb.ModifyDate = time.Date(nowMonthLastDay.Year(), month, 1, 0, 0, 0, 0, modifyDate.Location()).AddDate(0, 1, -1).Format(utils.FormatDate)
- }
- edb.Status = "完成"
- } else {
- edb.ModifyDate = modifyDate.Format(utils.FormatDate)
- }
- case "季度":
- //每季度更新数据时间
- if nowQuarterFirstDay.After(dataDtTime) {
- edb.ModifyDate = nowQuarterLastDay.Format(utils.FormatDate)
- } else {
- edb.ModifyDate = nowQuarterLastDay.AddDate(0, 3, 0).Format(utils.FormatDate)
- edb.Status = "完成"
- }
- case "半年度":
- //每半年度更新数据时间
- if nowHalfYearFirstDay.After(dataDtTime) {
- edb.ModifyDate = nowHalfYearLastDay.Format(utils.FormatDate)
- } else {
- month := nowHalfYearLastDay.Month() + 1
- edb.ModifyDate = time.Date(nowMonthLastDay.Year(), month, 1, 0, 0, 0, 0, nowHalfYearLastDay.Location()).AddDate(0, 6, -1).Format(utils.FormatDate)
- edb.Status = "完成"
- }
- case "年度":
- //每年度更新数据时间
- if nowYearFirstDay.After(dataDtTime) {
- edb.ModifyDate = nowYearLastDay.Format(utils.FormatDate)
- } else {
- edb.ModifyDate = nowYearLastDay.AddDate(1, 0, 0).Format(utils.FormatDate)
- edb.Status = "完成"
- }
- }
- } else {
- edb.DataList = make([]*models.Edbdata, 0)
- switch edb.Frequency {
- case "日度":
- edb.ModifyDate = time.Now().Format(utils.FormatDate)
- case "周度":
- modifyDate := nowWeekLastDay //下次更新日期
- if edb.NoticeTime != "" {
- addDay := 7
- noticeArr := strings.Split(edb.NoticeTime, " ")
- noticeWeek := noticeArr[0]
- switch noticeWeek {
- case "周一":
- addDay = 1
- case "周二":
- addDay = 2
- case "周三":
- addDay = 3
- case "周四":
- addDay = 4
- case "周五":
- addDay = 5
- case "周六":
- addDay = 6
- case "周日":
- addDay = 7
- }
- modifyDate = modifyDate.AddDate(0, 0, addDay-7)
- }
- edb.ModifyDate = modifyDate.Format(utils.FormatDate)
- case "月度":
- if edb.NoticeTime != "" {
- var modifyDateStr string
- strArr := strings.Split(edb.NoticeTime, "日")
- modifyDateStr = strconv.Itoa(myYear) + "-" + myMonth + "-" + strArr[0]
- edb.ModifyDate = modifyDateStr
- } else {
- edb.ModifyDate = nowMonthFirstDay.AddDate(0, 1, -1).Format(utils.FormatDate)
- }
- case "季度":
- edb.ModifyDate = utils.GetNowQuarterLastDay().Format(utils.FormatDate)
- case "半年度":
- edb.ModifyDate = utils.GetNowHalfYearLastDay().Format(utils.FormatDate)
- case "年度":
- edb.ModifyDate = utils.GetNowYearLastDay().Format(utils.FormatDate)
- }
- }
- }
- }
- resp := models.TargetItemListResp{
- List: list,
- FrequencyList: frequencyList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- //br.Data = resp
- br.Data = resp
- }
- // TargetItemNameList
- // @Title 获取研究员指标
- // @Description 获取研究员指标
- // @Param Frequency query string false "频度;枚举值:日度、周度、月度、季度、半年度、年度"
- // @Param Keyword query string false "关键字搜索"
- // @Param TradeCode query string false "指标唯一编码"
- // @Param ClassifyId query int false "分类id"
- // @Param EdbShowType query string true "指标展示类型:0,1,2; 0:不管有没有数据,指标都展示出来, 1:只展示有数据的指标, 2:只展示没有数据的指标"
- // @Success 200 {object} models.TargetItemListResp
- // @router /target/item_name_list [get]
- func (this *TargetController) TargetItemNameList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- //频度
- frequency := this.GetString("Frequency")
- //关键字
- keyword := this.GetString("Keyword")
- //指标编码
- tradeCode := this.GetString("TradeCode")
- userId := sysUser.AdminId
- //超管账号可以查看分类下的所有频度数据
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- userId = 0
- }
- //获取账户所拥有权限的分类id集合
- classifyIdStrList, err := data.GetEdbClassifyListByAdminId(int64(userId))
- if err != nil {
- br.Msg = "获取分类数据失败"
- return
- }
- classifyId, _ := this.GetInt("ClassifyId")
- edbShowType, _ := this.GetInt("EdbShowType")
- list, err := models.GetTargetItemList(classifyId, edbShowType, frequency, keyword, tradeCode, classifyIdStrList)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- resp := models.TargetItemListResp{
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- //br.Data = resp
- br.Data = resp
- }
- // BatchDataDeleteByDate
- // @Title 根据日期批量删除指标的数据
- // @Description 根据日期批量删除指标的数据接口
- // @Param request body models.BatchDataDeleteReq true "type json string"
- // @Success 200 Ret=200 删除数据成功
- // @router /data/batch_delete_by_date [post]
- func (this *TargetController) BatchDataDeleteByDate() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.BatchDataDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if len(req.TradeCodeList) <= 0 {
- br.Msg = "至少传入一个指标编码!"
- return
- }
- if req.CreateDate == "" {
- br.Msg = "请选择日期"
- return
- }
- TradeCodeStr := `"` + strings.Join(req.TradeCodeList, `","`) + `"`
- //删除数据
- err = models.BatchDeleteEdbDataByDate(TradeCodeStr, req.CreateDate, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "删除失败!"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // BatchDataDeleteByTradeCode
- // @Title 批量删除指标的数据
- // @Description 批量删除指标的数据接口
- // @Param request body models.TargetDeleteReq true "type json string"
- // @Success 200 Ret=200 删除数据成功
- // @router /data/batch_delete [post]
- func (this *TargetController) BatchDataDeleteByTradeCode() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.TargetDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.TradeCode == "" {
- br.Msg = "指标编码不可为空"
- return
- }
- //删除数据
- err = models.BatchDeleteEdbData(req.TradeCode, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "删除失败!"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // EdbTemplateDownload
- // @Title 下载指标导入模板
- // @Description 下载指标导入模板
- // @router /target/template [get]
- func (this *TargetCommonController) EdbTemplateDownload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- this.Ctx.Output.Download("./static/指标导入模板.xlsx", "指标导入模板.xlsx")
- br.Ret = 200
- br.Success = true
- br.Msg = "下载成功"
- }
- // ImportTarget
- // @Title 导入指标
- // @Description 导入指标接口
- // @Success 200 Ret=200 导入成功
- // @router /target/import [post]
- func (this *TargetController) ImportTarget() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- file, _, err := this.GetFile("ImportTargetFile")
- if err != nil {
- br.Msg = "获取文件失败"
- br.ErrMsg = "获取文件失败,Err:" + err.Error()
- return
- }
- path := "./static/手工指标数据导入_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- defer func() {
- file.Close()
- os.Remove(path)
- }()
- err = this.SaveToFile("ImportTargetFile", path)
- if err != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败,Err:" + err.Error()
- return
- }
- xlFile, err := xlsx.OpenFile(path)
- if err != nil {
- fmt.Println(err.Error())
- br.Msg = "excel打开失败"
- br.ErrMsg = "excel打开失败,Err:" + err.Error()
- return
- }
- //分类map
- classifyMap := make(map[string]*models.EdbdataClassify)
- //获取当前账号拥有的所有分类权限
- userId := sysUser.AdminId
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- userId = 0
- }
- classifyList, err := models.GetEdbdataClassify(int64(userId))
- for _, classify := range classifyList {
- if classify.Child != nil {
- for _, child := range classify.Child {
- classifyMap[child.ClassifyName] = child
- }
- }
- }
- failDatas := make([]*models.EdbImportFail, 0)
- // 遍历sheet页读取
- for _, sheet := range xlFile.Sheets {
- fmt.Println("sheet name: ", sheet.Name)
- //遍历行读取
- maxRow := sheet.MaxRow
- fmt.Println("maxRow:", maxRow)
- fmt.Println("maxRow")
- for i := 0; i < maxRow; i++ {
- if i > 1 {
- row := sheet.Row(i)
- cells := row.Cells
- if len(cells) >= 4 {
- cell1 := cells[0].Value //指标名称
- secName := strings.Trim(cell1, " ")
- if secName == "" { //过滤空白行
- continue
- }
- cell2 := cells[1].Value
- frequency := strings.Trim(cell2, " ") //频度
- classifyName := cells[2].Value //分类
- classifyName = strings.Trim(classifyName, " ")
- unit := cells[3].Value //单位
- unit = strings.Trim(unit, " ")
- //获取分类
- classify, ok := classifyMap[classifyName]
- if !ok {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "分类不存在",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- }
- tradeCode, err := models.GetMaxTradeCode()
- if err != nil {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "获取数据失败",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- //br.Msg = "获取数据失败"
- //br.ErrMsg = "获取最大交易编码失败,Err:" + err.Error()
- //return
- }
- if tradeCode == "" {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "数据异常",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- }
- maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
- if err != nil {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "数据异常",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- //br.Msg = "数据异常"
- //br.ErrMsg = "获取编码信息失败,Err:" + err.Error()
- //return
- }
- if maxTradeCode == "" {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "编码为空,请联系技术",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- //br.Msg = "编码为空,请联系技术"
- //br.ErrMsg = "编码为空,请联系技术"
- //return
- }
- if secName == "" {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "指标名称不能为空",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- //br.Msg = "指标名称不能为空"
- //return
- }
- item, err := models.GetEdbinfoBySecName(secName)
- if err != nil && err.Error() != utils.ErrNoRow() {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "获取信息失败",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- //br.Msg = "获取信息失败!"
- //br.ErrMsg = "获取信息失败,Err:" + err.Error()
- //return
- }
- //存在该指标,那么退出当前循环,进入下一循环
- if item != nil {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "指标已存在",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- }
- err = models.AddEdbinfo(maxTradeCode, secName, unit, "手动", frequency, "", classify.ClassifyId, sysUser.AdminId, sysUser.RealName)
- if err != nil {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "导入失败",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- //br.Msg = "导入失败"
- //br.ErrMsg = "导入失败,Err:" + err.Error()
- //return
- }
- err = models.AddEdbinfoUser(maxTradeCode, sysUser.Mobile)
- if err != nil {
- failItem := &models.EdbImportFail{
- ClassifyName: classifyName,
- Frequency: frequency,
- SecName: secName,
- Unit: unit,
- Remark: "创建账号关系失败",
- SysUserId: strconv.Itoa(sysUser.AdminId),
- }
- failDatas = append(failDatas, failItem)
- continue
- //br.Msg = "导入失败"
- //br.ErrMsg = "导入失败,Err:" + err.Error()
- //return
- }
- }
- }
- }
- }
- resp := new(models.EdbdataImportResp)
- if len(failDatas) > 0 {
- //先删除导入失败记录
- _ = models.DelEdbImportFail(sysUser.AdminId)
- //错误信息字符串切片,最后作为发送邮件通知使用
- failContents := make([]string, 0)
- for _, v := range failDatas {
- failContents = append(failContents, fmt.Sprint(v.SecName, "导入失败:", v.Remark))
- err = models.AddEdbImportFail(v)
- if err != nil {
- go alarm_msg.SendAlarmMsg("导入数据 新增失败记录失败,Err:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入指标 新增失败记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
- }
- }
- //导入失败的话,最后统一邮件提醒就好啦,不需要每次都去提醒
- go alarm_msg.SendAlarmMsg("导入数据 存在部分数据导入失败,Err:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入指标 存在部分数据导入失败:"+strings.Join(failContents, ";"), utils.EmailSendToUsers)
- resp.Status = 1
- resp.Msg = "存在部分导入失败"
- } else {
- resp.Status = 0
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "导入成功"
- br.Data = resp
- }
- // ImportTargetFailListDownload
- // @Title 下载指标数据导入失败列表
- // @Description 下载指标数据导入失败列表
- // @router /import_target/failList [get]
- func (this *TargetController) ImportTargetFailListDownload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- item, err := models.GetEdbImportFailList(sysUser.AdminId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- xlsxFile := xlsx.NewFile()
- sheet, err := xlsxFile.AddSheet("导入失败数据")
- headRow := sheet.AddRow()
- headRow.AddCell().SetValue("指标名称")
- headRow.AddCell().SetValue("频度")
- headRow.AddCell().SetValue("品种分类")
- headRow.AddCell().SetValue("单位")
- headRow.AddCell().SetValue("备注")
- for _, v := range item {
- row := sheet.AddRow()
- row.AddCell().SetValue(v.SecName)
- row.AddCell().SetValue(v.Frequency)
- row.AddCell().SetValue(v.ClassifyName)
- row.AddCell().SetValue(v.Unit)
- row.AddCell().SetValue(v.Remark)
- }
- fileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- savePath := "./static/" + fileName
- err = xlsxFile.Save(savePath)
- if err != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败,Err:" + err.Error()
- return
- }
- defer func() {
- os.Remove(savePath)
- }()
- this.Ctx.Output.Download(savePath, "失败列表.xlsx")
- }
- // ExcelDataAdd
- // @Title 复制EXCEL数据保存
- // @Description 复制EXCEL数据保存
- // @Param request body models.ExcelStyleReq true "type json string"
- // @Success 200
- // @router /target/excel_style/add [post]
- func (this *TargetController) ExcelDataAdd() {
- br := new(models.BaseResponse).Init()
- var err error
- errs := make([]string, 0)
- defer func() {
- if len(errs) > 0 {
- go alarm_msg.SendAlarmMsg("新增复制EXCEL数据 新增或修改数据失败,Err:"+strings.Join(errs, ","), 3)
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- //频度
- //frequency := this.GetString("Frequency")
- //
- //关键字
- //keyword := this.GetString("Keyword")
- //指标编码
- //tradeCode := this.GetString("TradeCode")
- //
- //userId := sysUser.AdminId
- //超管账号可以查看分类下的所有频度数据
- //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- // userId = 0
- //}
- //
- //list, err := models.GetExcelData()
- //if err != nil {
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // br.Msg = "获取失败"
- // return
- //}
- var req data_manage.ExcelStyleReq
- err = json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //指标map
- targetMap := make(map[string]*models.Edbinfo)
- var cellDataList []map[string]interface{}
- var dataList [][]map[string]interface{}
- //var configList []map[string]interface{}
- for _, item := range req.CellData {
- v := item.(map[string]interface{})
- cellDataList = append(cellDataList, v)
- }
- valueIndex := 0
- var secNameList []string
- var frequencyList []string
- var unitList []string
- var dateList []string
- dateValueMap := make(map[string]map[int]string)
- //取到所有数据
- for i := range req.Data {
- //取到一行
- if i > 4 {
- //先拿下日期列表
- if req.Data[i] == nil || req.Data[i][0] == nil {
- continue
- }
- //fmt.Println("i:", i)
- //fmt.Println(req.Data[i])
- //fmt.Println(req.Data[i][0])
- dateMap := req.Data[i][0].(map[string]interface{})
- _, ok := dateMap["m"]
- if ok {
- dateList = append(dateList, dateMap["m"].(string))
- //fmt.Println("dateList:", dateList)
- } else {
- continue
- }
- }
- for j, dataArr := range req.Data[i] {
- //每一列
- if dataArr == nil {
- continue
- }
- dataMap := dataArr.(map[string]interface{})
- if dataList == nil {
- dataList = make([][]map[string]interface{}, len(req.Data))
- }
- if dataList[i] == nil {
- dataList[i] = make([]map[string]interface{}, len(req.Data[i]))
- }
- dataList[i][j] = dataMap
- //fmt.Println("dataMap", dataMap["m"])
- v, _ := dataMap["m"]
- //指标名称列表
- if v == "指标名称" {
- for nameIndex := 1; nameIndex < len(req.Data[i]); nameIndex++ {
- if req.Data[i][nameIndex] == nil {
- break
- }
- secNameMap := req.Data[i][nameIndex].(map[string]interface{})
- secName, _ := secNameMap["m"]
- if secName == nil {
- continue
- }
- secNameList = append(secNameList, secNameMap["m"].(string))
- //fmt.Println("secName:", secNameList)
- }
- }
- //频度列表
- if v == "频度" {
- for nameIndex := 1; nameIndex < len(req.Data[i]); nameIndex++ {
- if req.Data[i][nameIndex] == nil {
- break
- }
- frequencyMap := req.Data[i][nameIndex].(map[string]interface{})
- frequency, _ := frequencyMap["m"]
- if frequency == nil {
- continue
- }
- frequencyList = append(frequencyList, frequencyMap["m"].(string))
- //fmt.Println("frequencyList:", frequencyList)
- }
- }
- //单位列表
- if v == "单位" {
- for nameIndex := 1; nameIndex < len(req.Data[i]); nameIndex++ {
- if req.Data[i][nameIndex] == nil {
- break
- }
- unitMap := req.Data[i][nameIndex].(map[string]interface{})
- unit, _ := unitMap["m"]
- if unit == nil {
- continue
- }
- unitList = append(unitList, unitMap["m"].(string))
- //fmt.Println("unitList:", unitList)
- }
- }
- //数据列表
- //var valueList []string
- valueListMap := make(map[int]string)
- if i > 4 {
- for index := 1; index < len(req.Data[i]); index++ {
- if req.Data[i][index] == nil {
- continue
- }
- valueMap := req.Data[i][index].(map[string]interface{})
- value, _ := valueMap["m"]
- if value == nil {
- continue
- }
- valueListMap[index] = valueMap["m"].(string)
- // 09-27 千位分隔符时用 "m" 取字符串存数据库会把逗号当小数点,现在换用 "v" 直接取数字再转为字符串,看看会不会有问题
- if ct, ok := valueMap["ct"].(map[string]interface{}); ok {
- fa, _ := ct["fa"]
- if fa == "#,##0.000" {
- value = valueMap["v"]
- floatValue := valueMap["v"].(float64)
- valueListMap[index] = strconv.FormatFloat(floatValue, 'f', -1, 64)
- }
- }
- //valueList = append(valueList, valueMap["m"].(string))
- //fmt.Println("valueList:", valueList)
- }
- dateMap := req.Data[i][0].(map[string]interface{})
- date := dateMap["m"].(string)
- dateValueMap[date] = valueListMap
- }
- }
- //firstCell := req.Data[i][0]
- //if firstCell == nil {
- // continue
- //}
- //dataMap := firstCell.(map[string]interface{})
- //if dataList == nil {
- // dataList = make([][]map[string]interface{}, len(req.Data[i]))
- //}
- //if dataList[i] == nil {
- // dataList[i] = make([]map[string]interface{}, len(req.Data[i]))
- //}
- //dataList[i][0] = dataMap
- //fmt.Println("dataMap", dataMap["m"])
- //v, _ := dataMap["m"]
- ////指标名称
- //if v == "指标名称" {
- // secNameMap := req.Data[i][1].(map[string]interface{})
- // secName = secNameMap["m"].(string)
- // fmt.Println("secName:", secName)
- //}
- ////频度
- //if v == "频度" {
- // frequencyMap := req.Data[i][1].(map[string]interface{})
- // frequency = frequencyMap["m"].(string)
- // fmt.Println("frequency:", frequency)
- //}
- ////单位
- //if v == "单位" {
- // unitMap := req.Data[i][1].(map[string]interface{})
- // unit = unitMap["m"].(string)
- // fmt.Println("unit:", unit)
- //}
- //
- ////日期
- //dateMap := req.Data[i][1].(map[string]interface{})
- //createDate = dateMap["m"].(string)
- //
- ////值
- //valueMap := req.Data[i][valueIndex].(map[string]interface{})
- //closeVal = valueMap["m"].(string)
- //新增指标
- //errMsg := services.AddEdbItem(secName, unit, frequency, req.ClassifyId, sysUser)
- //if errMsg == "" {
- // br.Msg = "新增指标异常!"
- // br.ErrMsg = errMsg
- // return
- //}
- valueIndex++
- }
- //var excelId int64
- //保存EXCEL样式
- //{
- // cellData, err := json.Marshal(cellDataList)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- // config, err := json.Marshal(req.Config)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- // datas, err := json.Marshal(dataList)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- // excelItem := data_manage.ExcelStyle{
- // CellData: string(cellData),
- // Config: string(config),
- // Data: string(datas),
- // }
- // excelId, err = models.AddExcelData(&excelItem)
- // if err != nil {
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // br.Msg = "获取失败"
- // return
- // }
- //
- // //判断映射表是否已经存在
- // count, err := data_manage.GetExcelEdbdataMappingCount(req.ClassifyId, target.TradeCode, frequency)
- // if err != nil {
- // br.ErrMsg = "GetExcelEdbdataMappingCount,Err:" + err.Error()
- // br.Msg = "新增映射表失败"
- // return
- // }
- // mappingItem := data_manage.ExcelEdbdataMapping{
- // ExcelId: excelId,
- // ClassifyId: req.ClassifyId,
- // Frequency: frequency,
- // TradeCode: target.TradeCode,
- // CreateTime: time.Now(),
- // }
- // if count == 0{
- // //新增
- // err := data_manage.AddExcelEdbdataMapping(&mappingItem)
- // if err != nil {
- // br.ErrMsg = "AddExcelEdbdataMapping,Err:" + err.Error()
- // br.Msg = "新增映射表失败"
- // return
- // }
- // }
- //}
- // 所有的指标数据map
- edbCodeDataMap := make(map[string]map[string]string)
- addEdbTradeMap := make(map[string]bool)
- updateEdbTradeMap := make(map[string]bool)
- updateDataTradeMap := make(map[string]bool)
- defer func() {
- go func(addEdbTradeMap, updateEdbTradeMap, updateDataTradeMap map[string]bool) {
- addRecordList := make([]*models.EdbinfoOpRecord, 0)
- for tradeCode := range addEdbTradeMap {
- addRecordList = append(addRecordList, &models.EdbinfoOpRecord{
- TradeCode: tradeCode,
- Remark: "创建指标",
- UserId: sysUser.AdminId,
- UserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- }
- for tradeCode := range updateEdbTradeMap {
- addRecordList = append(addRecordList, &models.EdbinfoOpRecord{
- TradeCode: tradeCode,
- Remark: "编辑指标",
- UserId: sysUser.AdminId,
- UserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- }
- for tradeCode := range updateDataTradeMap {
- addRecordList = append(addRecordList, &models.EdbinfoOpRecord{
- TradeCode: tradeCode,
- Remark: "更新数据",
- UserId: sysUser.AdminId,
- UserName: sysUser.RealName,
- CreateTime: time.Now(),
- })
- }
- if len(addRecordList) > 0 {
- obj := models.EdbinfoOpRecord{}
- _ = obj.MulCreate(addRecordList)
- }
- //将该指标的code加入到 “手工数据导入后刷新” 缓存
- if utils.Re == nil {
- for tradeCode := range updateDataTradeMap {
- // 更新手工数据的最大最小值
- data.ModifyManualEdbMaxMinDate(tradeCode)
- //将该指标的code加入到 “手工数据导入后刷新” 缓存
- err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, tradeCode)
- if err != nil {
- fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error())
- }
- }
- }
- }(addEdbTradeMap, updateEdbTradeMap, updateDataTradeMap)
- }()
- //超管账号可以查看分类下的所有频度数据
- userId := sysUser.AdminId
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- userId = 0
- }
- //获取账户所拥有权限的分类id集合
- classifyIdList, err := data.GetUserManualClassifyIdList(userId)
- if err != nil {
- br.Msg = "获取分类数据失败"
- br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
- return
- }
- if !utils.InArrayByInt(classifyIdList, req.ClassifyId) {
- br.Msg = "无权访问"
- br.ErrMsg = "无权访问"
- br.IsSendEmail = false
- return
- }
- //操作指标,新增指标及数据等
- {
- for i := 0; i < len(secNameList); i++ {
- //fmt.Println("len(secNameList):", len(secNameList))
- secName := secNameList[i]
- frequency := frequencyList[i]
- //防止填了指标名称后没填单位报错
- if len(unitList) < len(secNameList) {
- br.Msg = "单位填写异常!"
- br.ErrMsg = "单位填写异常!"
- return
- }
- unit := unitList[i]
- for j, s := range dateList {
- var closeVal string
- //valueList, ok := dateValueMap[s]
- valueMap, ok := dateValueMap[s]
- //fmt.Println("valueMap:", valueMap)
- if ok {
- createDate := dateList[j]
- //if i < len(valueList) {
- // closeVal = valueList[i]
- //} else {
- // continue
- //}
- closeVal, ok = valueMap[i+1]
- target, ok2 := targetMap[secName]
- if !ok2 {
- tmpTarget, err := models.GetTargetBySecName(secName)
- if err != nil {
- //如果是找不到该指标,那么新增指标
- if err.Error() == utils.ErrNoRow() {
- //if frequency == "" {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "新增指标失败,频度字段为空"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // continue
- //}
- //if unit == "" {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "新增指标失败,单位字段为空"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // continue
- //}
- tmpErr := data.AddEdbInfo(secName, unit, frequency, "", sysUser.Mobile, req.ClassifyId, sysUser.AdminId, sysUser.RealName)
- if tmpErr != nil {
- //fmt.Println("AddEdbInfo err:", err.Error())
- utils.FileLogData.Error("AddEdbInfo err :%s", tmpErr.Error())
- continue
- }
- tmpTarget, tmpErr := models.GetTargetBySecName(secName)
- target = tmpTarget
- targetMap[secName] = target
- // 指标新增
- addEdbTradeMap[target.TradeCode] = true
- } else {
- fmt.Println("导入数据 获取指标:Err:" + err.Error())
- }
- } else {
- target = tmpTarget
- targetMap[secName] = target
- }
- }
- // 没有该分类品种权限的话,那么就过滤
- if !utils.InArrayByInt(classifyIdList, target.ClassifyId) {
- continue
- }
- // 指标信息变更,需要更新
- if frequency != target.Frequency || unit != target.Unit || req.ClassifyId != target.ClassifyId {
- fmt.Println("更新指标频度或单位")
- err = models.ModifyEdbinfo(target.TradeCode, unit, frequency, req.ClassifyId)
- if err != nil {
- fmt.Println("EditEdbinfo err:", err.Error())
- return
- }
- // 指标信息变更
- if _, isAdd := addEdbTradeMap[target.TradeCode]; !isAdd {
- updateEdbTradeMap[target.TradeCode] = true
- }
- }
- //判断指标数据是否已经存在
- tmpDataMap, ok2 := edbCodeDataMap[target.TradeCode]
- if !ok2 {
- tmpDataMap = make(map[string]string)
- targetDataList, tmpErr := models.GetTargetsDataList(target.TradeCode)
- if tmpErr != nil {
- err = tmpErr
- }
- for _, tmpData := range targetDataList {
- tmpDataMap[tmpData.Dt] = tmpData.Close
- }
- edbCodeDataMap[target.TradeCode] = tmpDataMap
- }
- //判断数据是否已经存在
- tmpVal, ok3 := tmpDataMap[createDate]
- //数据已存在,进行更新操作
- if ok3 {
- if closeVal != "" {
- // 库里面的数据
- tmpValDecimal, tmpErr := decimal.NewFromString(tmpVal)
- if tmpErr != nil {
- fmt.Println("tmpVal Parse err:", tmpErr.Error())
- err = tmpErr
- continue
- }
- // 用户填写的数据
- closeValDecimal, tmpErr := decimal.NewFromString(closeVal)
- if tmpErr != nil {
- fmt.Println("closeVal Parse err:", tmpErr.Error())
- err = tmpErr
- continue
- }
- if !tmpValDecimal.Equal(closeValDecimal) {
- fmt.Println("更新数值")
- err = models.ModifyTargetsDataByImport(target.TradeCode, createDate, closeVal)
- if err != nil {
- fmt.Println("ModifyTargetsDataByImport err:", err.Error())
- errs = append(errs, err.Error())
- //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 修改数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
- }
- // 指标数据变更
- updateDataTradeMap[target.TradeCode] = true
- }
- } else {
- fmt.Println("删除数值")
- err = models.DeleteTargetsDataByImport(target.TradeCode, createDate)
- if err != nil {
- fmt.Println("DeleteTargetsDataByImport err:", err.Error())
- errs = append(errs, err.Error())
- //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 修改数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
- }
- // 指标数据变更
- updateDataTradeMap[target.TradeCode] = true
- }
- } else { //数据不存在,进行新增操作
- if target.TradeCode != "" && createDate != "" && closeVal != "" {
- fmt.Println("新增")
- models.AddTargetsDataByImport(target.TradeCode, createDate, closeVal)
- if err != nil {
- fmt.Println("AddTargetsDataByImport err:", err.Error())
- errs = append(errs, err.Error())
- //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 新增数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
- }
- tmpDataMap[createDate] = closeVal
- edbCodeDataMap[target.TradeCode] = tmpDataMap
- // 指标数据变更
- updateDataTradeMap[target.TradeCode] = true
- }
- }
- //保存关联表
- //{
- // //判断映射表是否已经存在
- // count, err := data_manage.GetExcelEdbdataMappingCount(req.ClassifyId, target.TradeCode, frequency)
- // if err != nil {
- // br.ErrMsg = "GetExcelEdbdataMappingCount,Err:" + err.Error()
- // br.Msg = "新增映射表失败"
- // return
- // }
- // mappingItem := data_manage.ExcelEdbdataMapping{
- // ExcelId: excelId,
- // ClassifyId: req.ClassifyId,
- // Frequency: frequency,
- // TradeCode: target.TradeCode,
- // CreateTime: time.Now(),
- // }
- // if count == 0{
- // //新增
- // err := data_manage.AddExcelEdbdataMapping(&mappingItem)
- // if err != nil {
- // br.ErrMsg = "AddExcelEdbdataMapping,Err:" + err.Error()
- // br.Msg = "新增映射表失败"
- // return
- // }
- // }
- //}
- }
- }
- }
- }
- //resp := models.TargetItemListResp{
- // List: list,
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- //br.Data = resp
- //br.Data = list
- }
- // ExcelDataEdit
- // @Title 在线Excel编辑
- // @Description 在线Excel编辑
- // @Param ClassifyId query string false "指标唯一编码"
- // @Param TradeCode query string false "指标唯一编码"
- // @Param Frequency query string true "频度"
- // @Success 200
- // @router /target/excel_style/edit [get]
- func (this *TargetController) ExcelDataEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- //指标编码
- //tradeCode := this.GetString("TradeCode")
- classifyId, _ := this.GetInt("ClassifyId")
- frequency := this.GetString("Frequency")
- excelId, err := data_manage.GetExcelEdbdataMappingByTradeCode(classifyId, frequency)
- if err != nil {
- br.Msg = "查找关联表失败"
- br.ErrMsg = "GetExcelEdbdataMappingByTradeCode,Err:" + err.Error()
- return
- }
- item, err := data_manage.GetExcelStyleById(*excelId)
- if err != nil {
- br.Msg = "查找样式失败"
- br.ErrMsg = "GetExcelStyleById,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- //br.Data = resp
- br.Data = item
- }
- //// ImportData
- //// @Title 导入数据
- //// @Description 导入数据
- //// @Param EntryFile query file true "文件"
- //// @Success 200 Ret=200 录入成功
- //// @router /import/data [post]
- //func (c *ManualEdbController) ImportData() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // c.Data["json"] = br
- // c.ServeJSON()
- // }()
- // sysUser := c.SysUser
- // if sysUser == nil {
- // br.Msg = "请重新登录"
- // return
- // }
- // file, _, err := c.GetFile("EntryFile")
- // if err != nil {
- // br.Msg = "获取文件失败"
- // br.ErrMsg = "获取文件失败,Err:" + err.Error()
- // return
- // }
- // path := "./static/数据导入_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- // defer file.Close()
- // err = c.SaveToFile("EntryFile", path)
- // if err != nil {
- // br.Msg = "文件保存失败"
- // br.ErrMsg = "文件保存失败,Err:" + err.Error()
- // return
- // }
- // if utils.RunMode == "debug" {
- // defer os.Remove(path)
- // }
- // xlFile, err := xlsx.OpenFile(path)
- // if err != nil {
- // fmt.Println(err.Error())
- // return
- // }
- //
- // //超管账号可以查看分类下的所有频度数据
- // userId := sysUser.AdminId
- // if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- // userId = 0
- // }
- // //获取账户所拥有权限的分类id集合
- // classifyNameStrList, edbDataClassifyMap, err := data.GetEdbClassifyNameListByAdminId(int64(userId))
- // if err != nil {
- // br.Msg = "获取分类数据失败"
- // return
- // }
- //
- // //导入成功数量
- // successCount := 0
- // //导入失败数据
- // failDatas := make([]*models.EdbdataImportFail, 0)
- //
- // //指标map
- // targetMap := make(map[string]*models.Edbinfo)
- // defer func() {
- // for _, target := range targetMap {
- // //结束后,清除掉对应的缓存
- // key := "import:edbinfo:data:" + target.TradeCode
- // utils.Rc.Delete(key)
- //
- // //将该指标的code加入到 “手工数据导入后刷新” 缓存
- // if utils.Re == nil {
- // err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, target.TradeCode)
- // if err != nil {
- // fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error())
- // }
- // }
- // }
- // }()
- //
- // // 所有的指标数据map
- // edbCodeDataMap := make(map[string]map[string]string)
- //
- // // 遍历sheet页读取
- // for _, sheet := range xlFile.Sheets {
- // fmt.Println("sheet name: ", sheet.Name)
- // //遍历行读取
- // maxRow := sheet.MaxRow
- // fmt.Println("maxRow:", maxRow)
- // fmt.Println("maxRow")
- // for i := 0; i < maxRow; i++ {
- // if i == 1 {
- // row := sheet.Row(i)
- // cells := row.Cells
- // if len(cells) < 6 {
- // br.ErrMsg = "导入文件异常,请下载最新导入模板文件"
- // br.Msg = "导入文件异常,请下载最新导入模板文件"
- // return
- // }
- // templateFail := false
- // if cells[0].Value != "品种分类" && cells[0].Value != "Species Category" {
- // templateFail = true
- // }
- // if cells[1].Value != "录入日期" && cells[1].Value != "Input Date" {
- // templateFail = true
- // }
- // if cells[2].Value != "指标名称" && cells[2].Value != "Indicator Name Indicator Name" {
- // templateFail = true
- // }
- // if cells[3].Value != "值" && cells[3].Value != "Value" {
- // templateFail = true
- // }
- // if cells[4].Value != "频度" && cells[4].Value != "Frequency" {
- // templateFail = true
- // }
- // if cells[5].Value != "单位" && cells[5].Value != "Unit" {
- // templateFail = true
- // }
- // if templateFail {
- // br.ErrMsg = "导入文件异常,请下载最新导入模板文件"
- // br.Msg = "导入文件异常,请下载最新导入模板文件"
- // return
- // }
- // }
- // if i > 1 {
- // row := sheet.Row(i)
- // cells := row.Cells
- // if len(cells) >= 6 {
- // classifyName := cells[0].Value //分类
- // if classifyName == "" { //过滤空白行
- // continue
- // }
- // cell1 := cells[1].Value
- // //createDate := utils.ConvertToFormatDay(cell1) //录入日期
- // createDate := cell1
- // cell2 := cells[2].Value //指标名称
- // secName := utils.TrimStr(cell2)
- // frequency := cells[4].Value //频度
- // unit := cells[5].Value //单位
- //
- // closeVal := cells[3].Value //值
- // if strings.Contains(closeVal, "#N/A") {
- // continue
- // }
- //
- // //校验表格中的日期格式
- // if strings.Contains(createDate, "-") {
- // //如果是带有 - 的普通日期格式文本
- // _, timeErr := time.Parse("2006-1-2", createDate)
- // if timeErr != nil {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "日期格式异常"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
- // continue
- // }
- // } else if strings.Contains(createDate, "/") {
- // //如果是带有 / 的普通日期格式文本
- // createDateTime, timeErr := time.Parse("2006/1/2", createDate)
- // if timeErr != nil {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "日期格式异常"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
- // continue
- // }
- // createDate = createDateTime.Format("2006-01-02")
- // } else {
- // //可能是excel的日期格式
- // _, tmpErr := strconv.Atoi(createDate)
- // if tmpErr != nil {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "日期格式异常"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
- // continue
- // }
- // createDate = utils.ConvertToFormatDay(createDate) //录入日期
- // }
- //
- // closeValFloat, err := cells[3].Float() //值
- //
- // if err != nil {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = cells[3].Value
- // failItem.Remark = "值类型异常"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // continue
- // }
- // newDecimal := decimal.NewFromFloat(closeValFloat)
- // newDecimal.Round(4)
- // closeVal = newDecimal.String()
- // if strings.Contains(closeVal, "#N/A") {
- // continue
- // }
- // //closeVal := closeValFloat.
- //
- // //判断指标,类型,等数据是否正常
- // classifyName = strings.Trim(classifyName, " ")
- // frequency = utils.TrimStr(frequency)
- // unit = utils.TrimStr(unit)
- //
- // // 成功数量超过20个指标,那就不导入了
- // if len(targetMap) >= 150 {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "导入指标数量过多"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
- // continue
- // }
- //
- // if !strings.Contains(strings.Join(classifyNameStrList, ","), classifyName) {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "没有该品种分类权限"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // continue
- // }
- // //fmt.Println(classifyName, createDate, secName, closeVal)
- //
- // //获取指标分类信息
- // classify, ok := edbDataClassifyMap[classifyName]
- // if !ok {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "指标分类不存在"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
- // continue
- // }
- //
- // //判断指标是否存在
- // target, ok := targetMap[secName]
- // if !ok {
- // tmpTarget, err := models.GetTargetBySecName(secName)
- // if err != nil {
- // //如果是找不到该指标,那么新增指标
- // if err.Error() == utils.ErrNoRow() {
- // if frequency == "" {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "新增指标失败,频度字段为空"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // continue
- // }
- // if unit == "" {
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "新增指标失败,单位字段为空"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // continue
- // }
- // tmpErr := data.AddEdbInfo(secName, unit, frequency, "", sysUser.Mobile, classify.ClassifyId, sysUser.AdminId)
- // if tmpErr != nil {
- // fmt.Println("line 158")
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "新增指标失败"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // continue
- // }
- // tmpTarget, tmpErr := models.GetTargetBySecName(secName)
- // target = tmpTarget
- // targetMap[secName] = target
- // } else {
- // fmt.Println("导入数据 获取指标:Err:" + err.Error())
- // }
- // } else {
- // target = tmpTarget
- // targetMap[secName] = target
- // }
- //
- // //设置10分钟缓存,不允许其他地方删除
- // key := "import:edbinfo:data:" + target.TradeCode
- // utils.Rc.SetNX(key, 1, time.Second*600)
- // }
- //
- // if target == nil {
- // fmt.Println("指标不存在")
- // failItem := new(models.EdbdataImportFail)
- // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
- // failItem.ClassifyName = classifyName
- // failItem.CreateDate = createDate
- // failItem.SecName = secName
- // failItem.Close = closeVal
- // failItem.Remark = "指标不存在"
- // failItem.Frequency = frequency
- // failItem.Unit = unit
- // failDatas = append(failDatas, failItem)
- // continue
- // }
- //
- // //更新指标信息
- // updateCols := make([]string, 0)
- // //更新指标分类
- // if target.ClassifyId <= 0 && classify.ClassifyId > 0 {
- // target.ClassifyId = classify.ClassifyId
- // updateCols = append(updateCols, "ClassifyId")
- // }
- // if target.Frequency != frequency {
- // target.Frequency = frequency
- // target.NoticeTime = ""
- // updateCols = append(updateCols, "Frequency", "NoticeTime")
- // }
- // if target.Unit != unit {
- // target.Unit = unit
- // updateCols = append(updateCols, "Unit")
- // }
- // if len(updateCols) > 0 {
- // _ = target.Update(updateCols)
- // }
- //
- // // 判断指标数据列表是否已经存在
- // tmpDataMap, ok := edbCodeDataMap[target.TradeCode]
- // if !ok {
- // tmpDataMap = make(map[string]string)
- // dataList, tmpErr := models.GetTargetsDataList(target.TradeCode)
- // if tmpErr != nil {
- // go alarm_msg.SendAlarmMsg("导入数据"+target.TradeCode+" 获取指标的数据失败,Err:"+err.Error(), 3)
- // }
- // for _, tmpData := range dataList {
- // tmpDataMap[tmpData.Dt] = tmpData.Close
- // }
- // edbCodeDataMap[target.TradeCode] = tmpDataMap
- // }
- //
- // //判断数据是否已经存在
- // tmpVal, ok := tmpDataMap[createDate]
- // //数据已存在,进行更新操作
- // if ok {
- // if tmpVal != closeVal {
- // err = models.ModifyTargetsDataByImport(target.TradeCode, createDate, closeVal)
- // if err != nil {
- // go alarm_msg.SendAlarmMsg("导入数据 修改数据失败,Err:"+err.Error(), 3)
- // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 修改数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
- // }
- // }
- // } else { //数据不存在,进行新增操作
- // if target.TradeCode != "" && createDate != "" && closeVal != "" {
- // models.AddTargetsDataByImport(target.TradeCode, createDate, closeVal)
- // if err != nil {
- // go alarm_msg.SendAlarmMsg("导入数据 新增数据失败,Err:"+err.Error(), 3)
- // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 新增数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
- // }
- // tmpDataMap[createDate] = closeVal
- // edbCodeDataMap[target.TradeCode] = tmpDataMap
- // }
- // }
- // successCount++
- // } else {
- // //br.ErrMsg = "请填写导入内容"
- // //br.Msg = "请填写导入内容"
- // //return
- // }
- // }
- // }
- // }
- // resp := models.EdbdataImportResp{
- // SuccessCount: successCount,
- // FailCount: len(failDatas),
- // }
- // fmt.Println("failDatas:", len(failDatas))
- // if len(failDatas) > 0 {
- // //先删除导入失败记录
- // _ = models.DelEdbDataImportFail(sysUser.AdminId)
- // //错误信息字符串切片,最后作为发送邮件通知使用
- // failContents := make([]string, 0)
- // for _, v := range failDatas {
- // failContents = append(failContents, fmt.Sprint(v.SecName, "导入失败:", v.Remark))
- // err = models.AddEdbdataImportFail(v)
- // if err != nil {
- // go alarm_msg.SendAlarmMsg("导入数据 新增失败记录失败,Err:"+err.Error(), 3)
- // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 新增失败记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
- // }
- // }
- // //导入失败的话,最后统一邮件提醒就好啦,不需要每次都去提醒
- // go alarm_msg.SendAlarmMsg("导入数据 存在部分数据导入失败:"+strings.Join(failContents, ";"), 3)
- // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 存在部分数据导入失败:"+strings.Join(failContents, ";"), utils.EmailSendToUsers)
- //
- // if successCount == 0 {
- // resp.Status = -1
- // resp.Msg = "导入失败"
- // } else {
- // resp.Status = 1
- // resp.Msg = "存在部分导入失败"
- // }
- // } else {
- // resp.Status = 0
- // }
- // br.Msg = "导入成功"
- // br.Ret = 200
- // br.Success = true
- // br.Data = resp
- //}
|