12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_manage/request"
- "eta/eta_api/services/alarm_msg"
- "eta/eta_api/services/data"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- "os"
- "path/filepath"
- "strings"
- "time"
- )
- // @Title 有色数据分类
- // @Description 有色数据分类接口
- // @Success 200 {object} data_manage.SmmClassify
- // @router /smm/classify [get]
- func (this *EdbInfoController) SmmClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- rootList, err := data_manage.GetBaseFromSmmClassifyByParentId(0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetAllBaseFromSmmClassify()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- /*baseFromSmmIndexMap := make(map[int][]*data_manage.BaseFromSmmClassifyItems)
- allBaseFromSmmIndex, err := data_manage.GetSmmIndexAll()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- for _, v := range allBaseFromSmmIndex {
- baseFromSmmIndexMap[v.ClassifyId] = append(baseFromSmmIndexMap[v.ClassifyId], v)
- }*/
- rootChildMap := make(map[int][]*data_manage.BaseFromSmmClassifyItems)
- for _, v := range classifyAll {
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- /*if existItems, ok := baseFromSmmIndexMap[v.ClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.BaseFromSmmClassifyItems, 0)
- v.Children = items
- }*/
- }
- var ret data_manage.BaseFromSmmClassifyResp
- nodeAll := make([]*data_manage.BaseFromSmmClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.ClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.BaseFromSmmClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- //查询未分类的指标列表
- initClassify := &data_manage.BaseFromSmmClassifyItems{
- ClassifyId: 0,
- BaseFromSmmIndexId: 0,
- ClassifyName: "未分类",
- ClassifyNameEn: "Unclassified",
- ParentId: 0,
- Level: 1,
- Sort: 0,
- Children: nil,
- }
- /*initIndexList, err := data_manage.GetBaseFromSmmIndexByClassifyId(initClassify.ClassifyId)
- if err != nil {
- br.Msg = "获取未分类指标失败"
- br.ErrMsg = "获取未分类指标失败,Err:" + err.Error()
- return
- }
- for _, v := range initIndexList {
- tmp := &data_manage.BaseFromSmmClassifyItems{
- ClassifyId: v.ClassifyId,
- BaseFromSmmIndexId: v.BaseFromSmmIndexId,
- BaseFromSmmIndexCode: v.IndexCode,
- ClassifyName: v.IndexName,
- ParentId: 0,
- Level: 0,
- Sort: 0,
- Children: nil,
- }
- initClassify.Children = append(initClassify.Children, tmp)
- }*/
- finalList := make([]*data_manage.BaseFromSmmClassifyItems, 0)
- finalList = append(finalList, initClassify)
- finalList = append(finalList, nodeAll...)
- ret.List = finalList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // SmmIndexList
- // @Title 有色数据指标
- // @Description 有色数据指标列表接口
- // @Success 200 {object} data_manage.SmmClassify
- // @router /smm/index/list [get]
- func (this *EdbInfoController) SmmIndexList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- classifyId, _ := this.GetInt("ClassifyId", 0)
- list := make([]*data_manage.BaseFromSmmClassifyItems, 0)
- indexList, err := data_manage.GetBaseFromSmmIndexByClassifyId(classifyId)
- if err != nil {
- br.Msg = "获取未分类指标失败"
- br.ErrMsg = "获取未分类指标失败,Err:" + err.Error()
- return
- }
- for _, v := range indexList {
- tmp := &data_manage.BaseFromSmmClassifyItems{
- ClassifyId: v.ClassifyId,
- BaseFromSmmIndexId: v.BaseFromSmmIndexId,
- BaseFromSmmIndexCode: v.IndexCode,
- ClassifyName: v.IndexName,
- ParentId: 0,
- Level: 0,
- Sort: 0,
- Children: nil,
- }
- list = append(list, tmp)
- }
- var ret data_manage.BaseFromSmmClassifyResp
- ret.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // SmmClassifyName
- // @Title 有色数据分类名称查询
- // @Description 有色数据分类名称查询接口
- // @Success 200 {object} data_manage.SmmClassify
- // @router /smm/classify/name [get]
- func (this *EdbInfoController) SmmClassifyName() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- rootList, err := data_manage.GetBaseFromSmmClassifyByParentId(0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetAllBaseFromSmmClassify()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- rootChildMap := make(map[int][]*data_manage.BaseFromSmmClassifyNameItems)
- for _, v := range classifyAll {
- tmp := &data_manage.BaseFromSmmClassifyNameItems{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- Children: nil,
- }
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], tmp)
- }
- var ret data_manage.BaseFromSmmClassifyNameResp
- nodeAll := make([]*data_manage.BaseFromSmmClassifyNameItems, 0)
- for _, v := range rootList {
- tmp := &data_manage.BaseFromSmmClassifyNameItems{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- Children: nil,
- }
- if existItems, ok := rootChildMap[v.ClassifyId]; ok {
- tmp.Children = existItems
- } else {
- items := make([]*data_manage.BaseFromSmmClassifyNameItems, 0)
- tmp.Children = items
- }
- nodeAll = append(nodeAll, tmp)
- }
- ret.List = nodeAll
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // AddSmmClassify
- // @Title 新增分类
- // @Description 新增分类接口
- // @Param request body data_manage.AddBaseFromSmmClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /smm/classify/add [post]
- func (this *EdbInfoController) AddSmmClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.AddBaseFromSmmClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- req.ClassifyName = utils.TrimStr(req.ClassifyName)
- req.ClassifyName = strings.Replace(req.ClassifyName, "/t", "", -1)
- //添加指标
- smmClassifyInfo, err, errMsg := data.AddSmmClassify(req.ClassifyName, req.ParentId, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- // 如果是添加一级分类,那么默认加上 价格、供应、需求、库存 四个二级分类
- if smmClassifyInfo.ParentId == 0 {
- secondClassifyList := []string{"价格", "供应", "需求", "库存"}
- for _, v := range secondClassifyList {
- _, _, tmpErrMsg := data.AddSmmClassify(v, smmClassifyInfo.ClassifyId, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
- if tmpErrMsg != `` {
- go alarm_msg.SendAlarmMsg("SMM原始数据-添加一级分类时,默认添加二级分类失败,一级分类名称:"+req.ClassifyName+",二级分类名称:"+v+", Err:"+tmpErrMsg, 3)
- return
- }
- }
- }
- resp := data_manage.AddSmmClassifyResp{
- ClassifyId: smmClassifyInfo.ClassifyId,
- //UniqueCode: fmt.Sprint(SmmClassifyInfo.BaseFromSmmClassifyId),
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // EditSmmClassify
- // @Title 修改分类
- // @Description 修改分类接口
- // @Param request body data_manage.EditBaseFromMysteelChemicalClassifyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /smm/classify/edit [post]
- func (this *EdbInfoController) EditSmmClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.EditBaseFromSmmClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.EditSmmClassify(req.ClassifyId, req.ClassifyName, this.Lang, this.SysUser)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 有色数据频度
- // @Description 有色数据频度接口
- // @Param ClassifyId query string true "分类Id"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /smm/frequency [get]
- func (this *EdbInfoController) SmmFrequency() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- return
- }
- frequencyList, err := data_manage.GetSmmFrequencyByClassifyId(classifyId)
- if err != nil {
- br.Msg = "获取频度失败"
- br.ErrMsg = "获取频度失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = frequencyList
- }
- // MoveSmmClassify
- // @Title 分类移动接口
- // @Description 分类移动接口
- // @Success 200 {object} data_manage.MoveBaseFromMysteelChemicalClassifyReq
- // @router /smm/classify/move [post]
- func (this *EdbInfoController) MoveSmmClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.MoveBaseFromSmmClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "分类id小于等于0"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.MoveSmmClassify(req.ClassifyId, req.ParentId, req.PrevClassifyId, req.NextClassifyId)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "移动成功"
- }
- // DeleteSmmClassify
- // @Title 删除分类
- // @Description 删除分类接口
- // @Param request body data_manage.DelBaseFromSmmClassifyReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /smm/classify/del [post]
- func (this *EdbInfoController) DeleteSmmClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromSmmClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.DelSmmClassify(req.ClassifyId, this.SysUser)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Msg = "删除成功"
- br.Success = true
- br.IsAddLog = true
- }
- // MoveSmmData
- // @Title SMM指标移动接口
- // @Description SMM指标移动接口
- // @Success 200 {object} data_manage.MoveBaseFromSmmReq
- // @router /smm/move [post]
- func (this *EdbInfoController) MoveSmmData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.MoveBaseFromSmmReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromSmmIndexId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.MoveSmmData2(req.BaseFromSmmIndexId, req.ClassifyId, req.PrevBaseFromSmmIndexId, req.NextBaseFromSmmIndexId)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "移动成功"
- }
- // EditSmm
- // @Title 编辑有色指标
- // @Description 编辑有色指标接口
- // @Param request body data_manage.AddEdbClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /smm/edit [post]
- func (this *EdbInfoController) EditSmm() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.EditBaseFromSmmReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromSmmIndexId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- //编辑指标
- smmIndexInfo, err, errMsg := data.EditSmmIndex(req.BaseFromSmmIndexId, req.ClassifyId, this.SysUser)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- resp := data_manage.EditSmmIndexInfoResp{
- BaseFromSmmIndexId: smmIndexInfo.BaseFromSmmIndexId,
- IndexCode: smmIndexInfo.IndexCode,
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 获取钢联数据
- // @Description 获取钢联数据接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query string true "分类id"
- // @Param Frequency query string true "频度名称"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /smm/data [get]
- func (this *EdbInfoController) SmmData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- return
- }
- frequency := this.GetString("Frequency")
- if frequency == "" {
- br.Msg = "请选择频度"
- br.ErrMsg = "请选择频度"
- return
- }
- //获取指标
- var condition string
- var pars []interface{}
- if classifyId >= 0 {
- condition += ` AND classify_id=? `
- pars = append(pars, classifyId)
- }
- if frequency != "" {
- condition += ` AND frequency=? `
- pars = append(pars, frequency)
- }
- smmList, err := data_manage.GetSmmIndex(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resultList := make([]*data_manage.SmmIndexList, 0)
- for _, v := range smmList {
- product := new(data_manage.SmmIndexList)
- product.BaseFromSmmIndexId = v.BaseFromSmmIndexId
- product.Unit = v.Unit
- product.IndexCode = v.IndexCode
- product.IndexName = v.IndexName
- product.Frequency = v.Frequency
- product.ModifyTime = v.ModifyTime
- total, err := data_manage.GetSmmIndexDataCount(v.IndexCode)
- page := paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := data_manage.GetSmmIndexData(v.IndexCode, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if dataList == nil {
- dataList = make([]*data_manage.SmmIndexData, 0)
- }
- product.DataList = dataList
- product.Paging = page
- resultList = append(resultList, product)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resultList
- }
- // SmmSearchList
- // @Title SMM模糊搜索
- // @Description SMM模糊搜索
- // @Param Keyword query string ture "关键字搜索"
- // @Success 200 {object} models.BaseResponse
- // @router /smm/search_list [get]
- func (this *EdbInfoController) SmmSearchList() {
- 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")
- list, err := data_manage.GetSmmItemList(keyword)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- classifyIds := make([]int, 0)
- for _, v := range list {
- if v.ClassifyId > 0 {
- classifyIds = append(classifyIds, v.ClassifyId)
- }
- }
- if len(classifyIds) > 0 {
- // 查询父级分类信息
- classifyList, e := data_manage.GetBaseFromSmmClassifyByIds(classifyIds)
- if e != nil {
- br.Msg = "获取目录信息失败"
- br.ErrMsg = "获取失获取目录信息失败,Err:" + err.Error()
- return
- }
- classifyListMap := make(map[int]int, 0)
- for _, v := range classifyList {
- classifyListMap[v.ClassifyId] = v.ParentId
- }
- for _, v := range list {
- if p, ok := classifyListMap[v.ClassifyId]; ok {
- v.ParentClassifyId = p
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // SmmSingleData
- // @Title 获取Smm数据
- // @Description 获取smm单条数据接口
- // @Param IndexCode query string true "指标唯一编码"
- // @Success 200 {object} models.BaseResponse
- // @router /smm/single_data [get]
- func (this *EdbInfoController) SmmSingleData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- indexCode := this.GetString("IndexCode")
- indexInfo, err := data_manage.GetBaseFromSmmIndexByIndexCode(indexCode)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- dataList, err := data_manage.GetSmmIndexDataByCode(indexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- var ret data_manage.SmmSingleDataResp
- ret.ClassifyId = indexInfo.ClassifyId
- ret.BaseFromSmmIndexId = indexInfo.BaseFromSmmIndexId
- ret.IndexCode = indexInfo.IndexCode
- ret.IndexName = indexInfo.IndexName
- ret.Frequency = indexInfo.Frequency
- ret.Interface = indexInfo.Interface
- ret.Name = indexInfo.Name
- ret.StartTime = indexInfo.StartTime
- ret.FinishTime = indexInfo.FinishTime
- ret.ApiStartTime = indexInfo.ApiStartTime
- ret.ApiUpdateTime = indexInfo.ApiUpdateTime
- ret.CreateTime = indexInfo.CreateTime.Format(utils.FormatDateTime)
- ret.ModifyTime = indexInfo.ModifyTime.Format(utils.FormatDateTime)
- ret.Unit = indexInfo.Unit
- ret.Data = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // DeleteSmmData
- // @Title 删除指标
- // @Description 删除指标接口
- // @Param request body data_manage.DelBaseFromSmmReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /smm/del [post]
- func (this *EdbInfoController) DeleteSmmData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromSmmReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromSmmIndexId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.DelSmmData(req.BaseFromSmmIndexId)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Msg = "删除成功"
- br.Success = true
- br.IsAddLog = true
- }
- // ResetSmmData
- // @Title 指标数据清除分类
- // @Description 指标数据清除分类
- // @Param request body data_manage.DelBaseFromSmmReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /smm/reset [post]
- func (this *EdbInfoController) ResetSmmData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromSmmReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromSmmIndexId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.ResetSmmData(req.BaseFromSmmIndexId)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Msg = "操作成功"
- br.Success = true
- br.IsAddLog = true
- }
- // ExportSmmList
- // @Title 导出Smm数据
- // @Description 导出Smm数据
- // @Param IndexName query string false "名称关键词"
- // @Param IndexCode query string false "指标唯一编码"
- // @Param ClassifyId query string true "分类"
- // @Param Frequency query string true "频度"
- // @Param UnitName query string false "单位"
- // @Param ModifyTime query string false "更新时间"
- // @Success 200 导出成功
- // @router /export/smmList [get]
- func (this *EdbInfoController) ExportSmmList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- //typeName := this.GetString("TypeName") //分类
- //frequency := this.GetString("Frequency")
- indexCode := this.GetString("IndexCode") //指标唯一编码
- classifyId, _ := this.GetInt("ClassifyId")
- secNameList := make([]*models.EdbdataExportList, 0)
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if classifyId >= 0 && indexCode == "" {
- frequencies, err := data_manage.GetSmmFrequency(classifyId)
- if err != nil {
- fmt.Println("GetSmmFrequency err:", err.Error())
- utils.FileLog.Info("GetSmmFrequency err:" + err.Error())
- return
- }
- for _, frequency := range frequencies {
- //获取指标
- var pars []interface{}
- pars = append(pars, classifyId)
- pars = append(pars, frequency)
- condition := " AND classify_id=? AND frequency=? "
- secNameList, err := data_manage.GetSmmIndex(condition, pars)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(secNameList) <= 0 {
- fmt.Println("secNameList长度为0")
- return
- }
- sheetNew, err := xlsxFile.AddSheet(*frequency)
- 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_manage.GetSmmDataMaxCount(classifyId)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- fmt.Println("dataMax:", dataMax)
- setRowIndex := 6
- for k, sv := range secNameList {
- //获取数据
- dataList, err := data_manage.GetSmmIndexDataByCode(sv.IndexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(dataList) > 0 {
- windRow.AddCell().SetValue("Smm")
- secNameRow.AddCell().SetValue("指标名称")
- indexCodeRow.AddCell().SetValue("指标ID")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- secNameRow.AddCell().SetValue(sv.IndexName)
- indexCodeRow.AddCell().SetValue(sv.IndexCode)
- frequencyRow.AddCell().SetValue(sv.Frequency)
- unitRow.AddCell().SetValue(sv.Unit)
- lastModifyDateRow.AddCell().SetValue(sv.ModifyTime)
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- indexCodeRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- 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().SetValue(dv.Value)
- 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()
- }
- }
- }
- }
- }
- }
- } else {
- frequencies, err := data_manage.GetSmmFrequencyByCode(indexCode)
- if err != nil {
- fmt.Println("GetSmmFrequencyByCode err:", err.Error())
- utils.FileLog.Info("GetSmmFrequencyByCode err:" + err.Error())
- return
- }
- for _, frequency := range frequencies {
- //获取数据
- dataList, err := data_manage.GetSmmIndexDataByCode(indexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(dataList) > 0 {
- name := this.GetString("IndexName")
- unit := this.GetString("UnitName")
- modifyTime := this.GetString("ModifyTime")
- sheet, err := xlsxFile.AddSheet(*frequency)
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- //获取指标数据
- windRow := sheet.AddRow()
- windRow.AddCell().SetValue("Smm")
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("指标名称")
- cellSenName := rowSecName.AddCell()
- cellSenName.SetValue(name)
- indexCodeRow := sheet.AddRow()
- indexCodeRow.AddCell().SetValue("指标ID")
- indexCodeRow.AddCell().SetValue(indexCode)
- rowFrequency := sheet.AddRow()
- celFrequency := rowFrequency.AddCell()
- celFrequency.SetValue("频率")
- cellFrequency := rowFrequency.AddCell()
- cellFrequency.SetValue(frequency)
- rowUnit := sheet.AddRow()
- celUnit := rowUnit.AddCell()
- celUnit.SetValue("单位")
- cellUnit := rowUnit.AddCell()
- cellUnit.SetValue(unit)
- rowModifyDate := sheet.AddRow()
- rowModifyCell := rowModifyDate.AddCell()
- rowModifyCell.SetValue("更新时间")
- rowModifyCell = rowModifyDate.AddCell()
- rowModifyCell.SetValue(modifyTime)
- dataMax, err := data_manage.GetSmmIndexDataCount(indexCode)
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := 6 + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := 6 + rk
- row := sheet.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().SetValue(dv.Value)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- }
- }
- err := xlsxFile.Save(downLoadnFilePath)
- 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(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- }
- fileName := `Smm数据`
- if len(secNameList) > 0 {
- fileName = secNameList[0].ClassifyName
- }
- fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
|