12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829 |
- 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/models/data_manage/response"
- "eta/eta_api/models/system"
- "eta/eta_api/services/alarm_msg"
- "eta/eta_api/services/data"
- "eta/eta_api/services/data_stat"
- etaTrialService "eta/eta_api/services/eta_trial"
- "eta/eta_api/utils"
- "fmt"
- "os"
- "path/filepath"
- "sort"
- "strconv"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- )
- // MysteelChemicalClassify
- // @Title 钢联化工数据分类
- // @Description 钢联化工分类接口
- // @Success 200 {object} data_manage.BaseFromMysteelChemicalClassifyItems
- // @router /mysteel_chemical/classify [get]
- func (this *EdbInfoController) MysteelChemicalClassify() {
- 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.GetBaseFromMysteelChemicalClassifyByParentId(0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetAllBaseFromMysteelChemicalClassify()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- rootChildMap := make(map[int][]*data_manage.BaseFromMysteelChemicalClassifyItems)
- for _, v := range classifyAll {
- v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId)
- button := data.GetMysteelChemicalOpButton(sysUser, v.SysUserId)
- button.AddButton = false //不管有没有权限,二级分类都是没有添加按钮的
- v.Button = button
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- }
- nodeAll := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
- for k, v := range rootList {
- button := data.GetMysteelChemicalOpButton(sysUser, v.SysUserId)
- rootList[k].Button = button
- rootList[k].UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId)
- if existItems, ok := rootChildMap[v.BaseFromMysteelChemicalClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = nodeAll
- }
- // MysteelChemicalIndexList
- // @Title 钢联化工数据指标列表
- // @Description 钢联化工数据指标列表接口
- // @Success 200 {object} data_manage.BaseFromMysteelChemicalIndexResp
- // @router /mysteel_chemical/index/list [get]
- func (this *EdbInfoController) MysteelChemicalIndexList() {
- 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("BaseFromMysteelChemicalClassifyId")
- if classifyId <= 0 {
- br.Msg = "请选择正确的分类"
- return
- }
- allBaseFromMysteelChemicalIndex, err := data_manage.GetMysteelChemicalIndexByClassifyId(classifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- nodeAll := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
- for _, v := range allBaseFromMysteelChemicalIndex {
- v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.BaseFromMysteelChemicalIndexId)
- button := data.GetMysteelChemicalOpButton(sysUser, v.SysUserId)
- button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
- v.Button = button
- nodeAll = append(nodeAll, v)
- }
- ret := &data_manage.BaseFromMysteelChemicalIndexResp{
- List: nodeAll,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // AddMysteelChemicalClassify
- // @Title 新增分类
- // @Description 新增分类接口
- // @Param request body data_manage.AddBaseFromMysteelChemicalClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /mysteel_chemical/classify/add [post]
- func (this *EdbClassifyController) AddMysteelChemicalClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.AddBaseFromMysteelChemicalClassifyReq
- 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)
- //添加指标
- mysteelChemicalClassifyInfo, err, errMsg := data.AddMysteelChemicalClassify(req.ClassifyName, req.ParentId, req.Level, 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 mysteelChemicalClassifyInfo.ParentId == 0 {
- secondClassifyList := []string{"价格", "供应", "需求", "库存"}
- for _, v := range secondClassifyList {
- _, _, tmpErrMsg := data.AddMysteelChemicalClassify(v, mysteelChemicalClassifyInfo.BaseFromMysteelChemicalClassifyId, mysteelChemicalClassifyInfo.Level, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
- if tmpErrMsg != `` {
- go alarm_msg.SendAlarmMsg("钢联化工-添加一级分类时,默认添加二级分类失败,一级分类名称:"+req.ClassifyName+",二级分类名称:"+v+", Err:"+tmpErrMsg, 3)
- return
- }
- }
- }
- resp := response.AddMysteelChemicalClassifyResp{
- BaseFromMysteelChemicalClassifyId: mysteelChemicalClassifyInfo.BaseFromMysteelChemicalClassifyId,
- UniqueCode: fmt.Sprint(mysteelChemicalClassifyInfo.BaseFromMysteelChemicalClassifyId),
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // EditMysteelChemicalClassify
- // @Title 修改分类
- // @Description 修改分类接口
- // @Param request body data_manage.EditBaseFromMysteelChemicalClassifyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /mysteel_chemical/classify/edit [post]
- func (this *EdbClassifyController) EditMysteelChemicalClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.EditBaseFromMysteelChemicalClassifyReq
- 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.BaseFromMysteelChemicalClassifyId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.EditMysteelChemicalClassify(req.BaseFromMysteelChemicalClassifyId, 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
- }
- // MoveMysteelChemicalClassify
- // @Title 分类移动接口
- // @Description 分类移动接口
- // @Success 200 {object} data_manage.MoveBaseFromMysteelChemicalClassifyReq
- // @router /mysteel_chemical/classify/move [post]
- func (this *EdbClassifyController) MoveMysteelChemicalClassify() {
- 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.MoveBaseFromMysteelChemicalClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromMysteelChemicalClassifyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "分类id小于等于0"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.MoveMysteelChemicalClassify(req.BaseFromMysteelChemicalClassifyId, req.ParentBaseFromMysteelChemicalClassifyId, req.PrevBaseFromMysteelChemicalClassifyId, req.NextBaseFromMysteelChemicalClassifyId, this.SysUser)
- 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 = "移动成功"
- }
- // DeleteMysteelChemicalClassify
- // @Title 删除分类
- // @Description 删除分类接口
- // @Param request body data_manage.DelBaseFromMysteelChemicalClassifyReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /mysteel_chemical/classify/del [post]
- func (this *EdbClassifyController) DeleteMysteelChemicalClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromMysteelChemicalClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromMysteelChemicalClassifyId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.DelMysteelChemicalClassify(req.BaseFromMysteelChemicalClassifyId, 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
- }
- // MysteelChemicalSearch
- // @Title 钢联化工指标查询
- // @Description 钢联化工指标查询
- // @Param BaseFromMysteelChemicalClassifyId query int true "分类id"
- // @Param Keyword query string true "名称关键词"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /mysteel_chemical/search [get]
- func (this *EdbInfoController) MysteelChemicalSearch() {
- 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("BaseFromMysteelChemicalClassifyId")
- var condition string
- var pars []interface{}
- if classifyId > 0 {
- condition += " AND base_from_mysteel_chemical_classify_id=? "
- pars = append(pars, classifyId)
- }
- keyword := this.GetString("Keyword")
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- list, err := data_manage.GetMysteelChemicalIndex(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- classifyIds := make([]int, 0)
- for _, v := range list {
- v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
- if v.BaseFromMysteelChemicalClassifyId > 0 {
- classifyIds = append(classifyIds, v.BaseFromMysteelChemicalClassifyId)
- }
- }
- if len(classifyIds) > 0 {
- // 查询父级分类信息
- classifyList, e := data_manage.GetBaseFromMysteelChemicalClassifyByIds(classifyIds)
- if e != nil {
- br.Msg = "获取目录信息失败"
- br.ErrMsg = "获取失获取目录信息失败,Err:" + err.Error()
- return
- }
- classifyListMap := make(map[int]int, 0)
- for _, v := range classifyList {
- classifyListMap[v.BaseFromMysteelChemicalClassifyId] = v.ParentId
- }
- for _, v := range list {
- v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
- if p, ok := classifyListMap[v.BaseFromMysteelChemicalClassifyId]; ok {
- v.ParentClassifyId = p
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // MysteelChemicalFrequency
- // @Title 钢联化工数据频度
- // @Description 钢联化工数据频度接口
- // @Param BaseFromMysteelChemicalClassifyId query int true "分类id"
- // @Param BaseFromMysteelChemicalIndexId query int true "钢联化工指标id"
- // @Param Keyword query string true "名称关键词"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /mysteel_chemical/frequency [get]
- func (this *EdbInfoController) MysteelChemicalFrequency() {
- 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 condition string
- var pars []interface{}
- var classifyId int
- var frequency string
- // 指定指标
- indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
- if indexId > 0 {
- condition += " AND base_from_mysteel_chemical_index_id = ? "
- pars = append(pars, indexId)
- } else {
- classifyId, _ = this.GetInt("BaseFromMysteelChemicalClassifyId")
- if classifyId <= 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- return
- }
- }
- if classifyId > 0 {
- condition += " AND base_from_mysteel_chemical_classify_id=? "
- pars = append(pars, classifyId)
- }
- if frequency != `` {
- condition += " AND frequency=? "
- pars = append(pars, frequency)
- }
- // 关键词搜索
- keyword := this.GetString("Keyword")
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- edbFrequencyList := make([]string, 0)
- frequencyList, err := data_manage.GetMysteelChemicalFrequency(condition, pars)
- for _, unit := range frequencyList {
- edbFrequencyList = append(edbFrequencyList, unit.Frequency)
- }
- edbFrequencyList = sortEdbFrequency(edbFrequencyList)
- for i, v := range edbFrequencyList {
- frequencyList[i].Frequency = v
- }
- if err != nil {
- br.Msg = "获取频度失败"
- br.ErrMsg = "获取频度失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = frequencyList
- }
- // MysteelChemicalData
- // @Title 获取钢联化工数据
- // @Description 获取钢联化工数据
- // @Param BaseFromMysteelChemicalClassifyId query int true "分类id"
- // @Param BaseFromMysteelChemicalIndexId query int true "钢联化工指标id"
- // @Param Frequency query string true "频度名称"
- // @Param Keyword query string true "名称关键词"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /mysteel_chemical/data [get]
- func (this *EdbInfoController) MysteelChemicalData() {
- 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)
- var condition string
- var pars []interface{}
- var classifyId int
- var frequency string
- // 指定指标
- indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
- if indexId > 0 {
- condition += " AND base_from_mysteel_chemical_index_id = ? "
- pars = append(pars, indexId)
- } else {
- classifyId, _ = this.GetInt("BaseFromMysteelChemicalClassifyId")
- if classifyId <= 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- frequency = this.GetString("Frequency")
- if frequency == "" {
- br.Msg = "请选择频度"
- br.ErrMsg = "请选择频度"
- br.IsSendEmail = false
- return
- }
- }
- if classifyId > 0 {
- condition += " AND base_from_mysteel_chemical_classify_id=? "
- pars = append(pars, classifyId)
- }
- if frequency != `` {
- condition += " AND frequency=? "
- pars = append(pars, frequency)
- }
- // 关键词搜索
- keyword := this.GetString("Keyword")
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- //获取指标
- list, err := data_manage.GetMysteelChemicalIndex(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- for k, v := range list {
- total, err := data_manage.GetMysteelChemicalIndexDataCount(v.IndexCode)
- page := paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := data_manage.GetMysteelChemicalIndexData(v.IndexCode, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if dataList == nil {
- dataList = make([]*data_manage.MysteelChemicalData, 0)
- }
- edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, v.IndexCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标库统计数据失败,Err:" + err.Error()
- return
- }
- if edbInfo == nil {
- list[k].EdbInfoId = 0
- } else {
- list[k].EdbInfoId = edbInfo.EdbInfoId
- }
- list[k].DataList = dataList
- list[k].Paging = page
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // MysteelChemicalExport
- // @Title 导出钢联化工数据
- // @Description 导出钢联化工数据
- // @Param BaseFromMysteelChemicalClassifyId query int true "分类"
- // @Param BaseFromMysteelChemicalIndexId query string true "钢联化工指标id"
- // @Param Keyword query string true "名称关键词"
- // @Success 200 导出成功
- // @router /mysteel_chemical/export/dataList [get]
- func (this *EdbClassifyController) MysteelChemicalExport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- classifyId, _ := this.GetInt("BaseFromMysteelChemicalClassifyId") //分类
- frequency := this.GetString("Frequency")
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- var condition string
- var pars []interface{}
- indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
- if indexId > 0 {
- condition += " AND base_from_mysteel_chemical_index_id = ? "
- pars = append(pars, indexId)
- }
- if classifyId > 0 {
- condition += " AND base_from_mysteel_chemical_classify_id=? "
- pars = append(pars, classifyId)
- }
- if frequency != `` {
- condition += " AND frequency=? "
- pars = append(pars, frequency)
- }
- // 关键词搜索
- keyword := this.GetString("Keyword")
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- var frequencies []string
- frequencieSet := make(map[string]struct{})
- frequencyList, err := data_manage.GetMysteelChemicalFrequency(condition, pars)
- if err != nil {
- br.Msg = "获取频度失败"
- br.ErrMsg = "获取频度失败,Err:" + err.Error()
- return
- }
- for _, v := range frequencyList {
- if _, ok := frequencieSet[v.Frequency]; !ok {
- frequencies = append(frequencies, v.Frequency)
- frequencieSet[v.Frequency] = struct{}{}
- }
- }
- secNameList := make([]*data_manage.MysteelChemicalList, 0)
- for _, frequency := range frequencies {
- //获取指标
- var tmpCondition string
- var tmpPars []interface{}
- if indexId > 0 {
- tmpCondition += " AND base_from_mysteel_chemical_index_id = ? "
- tmpPars = append(pars, indexId)
- }
- if classifyId > 0 {
- tmpCondition += " AND base_from_mysteel_chemical_classify_id=? "
- tmpPars = append(pars, classifyId)
- }
- if frequency != `` {
- tmpCondition += " AND frequency=? "
- tmpPars = append(pars, frequency)
- }
- // 关键词搜索
- keyword := this.GetString("Keyword")
- if keyword != `` {
- tmpCondition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- //获取指标
- secNameList, err = data_manage.GetMysteelChemicalIndex(tmpCondition, tmpPars)
- 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()
- var indexIdList []int
- for _, sv := range secNameList {
- indexIdList = append(indexIdList, sv.Id)
- }
- dataTimeList, err := data_manage.GetBaseFromMysteelChemicalDataTimeByIndexId(indexIdList)
- if err != nil {
- fmt.Println("获取数据时间失败", err.Error())
- return
- }
- //获取分类下指标最大数据量
- setRowIndex := 6
- for rk, dv := range dataTimeList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- }
- for k, sv := range secNameList {
- //获取数据
- dataList, err := data_manage.GetMysteelChemicalIndexDataByCode(sv.IndexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if k == 0 {
- windRow.AddCell().SetValue("钢联")
- secNameRow.AddCell().SetValue("指标名称")
- indexCodeRow.AddCell().SetValue("指标ID")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- }
- if len(dataList) == 0 {
- continue
- }
- secNameRow.AddCell().SetValue(sv.IndexName)
- indexCodeRow.AddCell().SetValue(sv.IndexCode)
- frequencyRow.AddCell().SetValue(sv.FrequencyName)
- unitRow.AddCell().SetValue(sv.UnitName)
- lastModifyDateRow.AddCell().SetValue(sv.UpdateTime)
- dataInfoMap := make(map[string]*data_manage.MysteelChemicalData)
- for _, dv := range dataList {
- dataInfoMap[dv.DataTime] = dv
- }
- for rk, dtv := range dataTimeList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDateCell := row.AddCell()
- tmpData, ok := dataInfoMap[dtv]
- if ok {
- displayDateCell.SetValue(tmpData.InputValue)
- }
- }
- }
- }
- 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 := "上海钢联"
- 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"
- }
- // AddMysteelChemical
- // @Title 新增钢联化工指标
- // @Description 新增钢联化工指标接口
- // @Param request body data_manage.AddEdbClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /mysteel_chemical/add [post]
- func (this *EdbClassifyController) AddMysteelChemical() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.AddBaseFromMysteelChemicalReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- resp := new(response.AddMysteelChemicalIndexInfoResp)
- conf, err := models.GetBusinessConf()
- if err != nil {
- br.Msg = "添加指标失败"
- br.ErrMsg = "获取业务配置失败,Err:" + err.Error()
- return
- }
- // 判断钢联化工的数据刷新方式
- if conf["MySteelDataMethod"] == "api" {
- if len(req.List) > 150 {
- br.Msg = "添加指标失败,指标数量不能超过150条"
- return
- }
- ok, errMsg, err := data.HealthCheckMysteelChemicalApi()
- if err != nil {
- br.Msg = "添加指标失败"
- br.ErrMsg = "钢联化工数据接口异常,Err:" + err.Error()
- return
- }
- if !ok {
- br.Msg = errMsg
- return
- }
- addMySteelList := make([]*data_manage.BaseFromMysteelChemicalIndex, 0)
- for _, v := range req.List {
- if v.IndexCode == "" {
- br.Msg = "请输入指标ID"
- br.IsSendEmail = false
- return
- }
- if v.BaseFromMysteelChemicalClassifyId <= 0 {
- br.Msg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- var updateTime1, updateTime2 string
- if v.UpdateTime != `` {
- updateTimeList := strings.Split(v.UpdateTime, ",")
- updateTime1 = updateTimeList[0]
- if len(updateTimeList) > 1 {
- updateTime2 = updateTimeList[1]
- }
- }
- v.IndexCode = utils.TrimStr(v.IndexCode)
- v.IndexCode = strings.Replace(v.IndexCode, "\t", "", -1)
- addMySteelList = append(addMySteelList, &data_manage.BaseFromMysteelChemicalIndex{
- BaseFromMysteelChemicalClassifyId: v.BaseFromMysteelChemicalClassifyId,
- IndexCode: strings.ToUpper(v.IndexCode),
- IndexName: "",
- Unit: "",
- Frequency: "",
- StartDate: "",
- EndDate: "",
- Describe: "",
- Source: "api",
- TerminalCode: "",
- UpdateWeek: v.UpdateWeek,
- UpdateTime: updateTime1,
- UpdateTime2: updateTime2,
- SysUserId: this.SysUser.AdminId,
- SysUserRealName: this.SysUser.RealName,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- })
- }
- mySteelChemicalIndexInfos, err, errMsg := data.BatchAddMysteelChemicalIndex(addMySteelList, this.Lang)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- return
- }
- if len(mySteelChemicalIndexInfos) > 0 {
- resp.BaseFromMysteelChemicalIndexId = mySteelChemicalIndexInfos[0].BaseFromMysteelChemicalIndexId
- resp.IndexCode = mySteelChemicalIndexInfos[0].IndexCode
- resp.UniqueCode = fmt.Sprint(mySteelChemicalIndexInfos[0].BaseFromMysteelChemicalClassifyId, "_", mySteelChemicalIndexInfos[0].BaseFromMysteelChemicalIndexId)
- }
- for _, v := range mySteelChemicalIndexInfos {
- err = utils.Rc.LPush(utils.CACHE_MYSTEEL_CHEMICAL_ADD_DATA, v.IndexCode)
- if err != nil {
- br.Msg = "添加指标失败" + v.IndexCode
- br.ErrMsg = "添加指标缓存失败" + v.IndexCode + ";Err:" + err.Error()
- return
- }
- }
- } else {
- for i, v := range req.List {
- if v.IndexCode == "" {
- br.Msg = "请输入指标ID"
- br.IsSendEmail = false
- return
- }
- if v.BaseFromMysteelChemicalClassifyId <= 0 {
- br.Msg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- v.IndexCode = utils.TrimStr(v.IndexCode)
- v.IndexCode = strings.Replace(v.IndexCode, "\t", "", -1)
- //添加指标
- mysteelChemicalIndexInfo, err, errMsg := data.AddMysteelChemicalIndex(v.BaseFromMysteelChemicalClassifyId, strings.ToUpper(v.IndexCode), v.UpdateWeek, v.UpdateTime, 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 i == 0 {
- resp.BaseFromMysteelChemicalIndexId = mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId
- resp.IndexCode = mysteelChemicalIndexInfo.IndexCode
- resp.UniqueCode = fmt.Sprint(mysteelChemicalIndexInfo.BaseFromMysteelChemicalClassifyId, "_", mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId)
- }
- }
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- 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
- }
- // EditMysteelChemical
- // @Title 编辑钢联化工指标
- // @Description 新增钢联化工指标接口
- // @Param request body data_manage.AddEdbClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /mysteel_chemical/edit [post]
- func (this *EdbClassifyController) EditMysteelChemical() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.AddBaseFromMysteelChemicalReqItem
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromMysteelChemicalIndexId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- if req.BaseFromMysteelChemicalClassifyId <= 0 {
- br.Msg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- //编辑指标
- mysteelChemicalIndexInfo, err, errMsg := data.EditMysteelChemicalIndex(req.BaseFromMysteelChemicalIndexId, req.BaseFromMysteelChemicalClassifyId, req.UpdateWeek, req.UpdateTime, 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 := response.AddMysteelChemicalIndexInfoResp{
- BaseFromMysteelChemicalIndexId: mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId,
- IndexCode: mysteelChemicalIndexInfo.IndexCode,
- UniqueCode: fmt.Sprint(mysteelChemicalIndexInfo.BaseFromMysteelChemicalClassifyId, "_", mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId),
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // DeleteMysteelChemical
- // @Title 删除指标
- // @Description 删除指标接口
- // @Param request body data_manage.DelBaseFromMysteelChemicalReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /mysteel_chemical/del [post]
- func (this *EdbClassifyController) DeleteMysteelChemical() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromMysteelChemicalReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromMysteelChemicalIndexId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.DelMysteelChemical(req.BaseFromMysteelChemicalIndexId, 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
- }
- // MoveMysteelChemical
- // @Title 指标移动接口
- // @Description 分类移动接口
- // @Success 200 {object} data_manage.MoveBaseFromMysteelChemicalReq
- // @router /mysteel_chemical/move [post]
- func (this *EdbClassifyController) MoveMysteelChemical() {
- 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.MoveBaseFromMysteelChemicalReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromMysteelChemicalIndexId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- br.IsSendEmail = false
- return
- }
- if req.BaseFromMysteelChemicalClassifyId <= 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.MoveMysteelChemical(req.BaseFromMysteelChemicalIndexId, req.BaseFromMysteelChemicalClassifyId, req.PrevBaseFromMysteelChemicalIndexId, req.NextBaseFromMysteelChemicalIndexId, this.SysUser)
- 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 = "移动成功"
- }
- // MysteelChemicalDetail
- // @Title 钢联化工指标详情
- // @Description 钢联化工指标详情接口
- // @Param BaseFromMysteelChemicalIndexId query string true "钢联化工指标id"
- // @Success 200 {object} data_manage.BaseFromMysteelChemicalClassifyItems
- // @router /mysteel_chemical/detail [get]
- func (this *EdbInfoController) MysteelChemicalDetail() {
- 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
- }
- indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
- if indexId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- }
- if item.UpdateTime2 != `` {
- item.UpdateTime = item.UpdateTime + "," + item.UpdateTime2
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = item
- }
- // MysteelChemicalDetail
- // @Title 钢联化工指标详情
- // @Description 钢联化工指标详情接口
- // @Param BaseFromMysteelChemicalIndexId query string true "钢联化工指标id"
- // @Success 200 {object} data_manage.BaseFromMysteelChemicalClassifyItems
- // @router /mysteel_chemical/refresh [get]
- func (this *EdbInfoController) MysteelChemicalRefresh() {
- 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
- }
- // 每次刷新都需要两分钟的等待时间
- setNxKey := utils.CACHE_KEY_MYSTEEL_REFRESH
- if !utils.Rc.SetNX(setNxKey, 1, 2*60*time.Second) {
- br.Msg = "系统正在处理数据生成,请2分钟之后刷新"
- br.IsSendEmail = false
- return
- }
- indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
- if indexId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- }
- if item.MergeFilePath == "" {
- br.Msg = "系统正在处理数据生成,请5分钟之后刷新"
- br.IsSendEmail = false
- return
- }
- go data.CurlRefreshMysteelChemicalData(item.MergeFilePath)
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- br.Data = item
- }
- // NameCheck
- // @Title 重名校验
- // @Description 批量新增
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /mysteel_chemical/name_check [post]
- func (c *EdbInfoController) NameCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req []*data_manage.NameCheckEdbInfoReq
- if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if len(req) == 0 {
- br.Msg = "请选择指标"
- return
- }
- codeMax := 30
- codeLen := len(req)
- if codeLen > codeMax {
- br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
- return
- }
- type NameCheckResult struct {
- EdbCode string
- EdbName string
- Exist bool
- }
- indexNames := make([]string, 0)
- resp := make([]*NameCheckResult, 0)
- for _, v := range req {
- v.EdbCode = strings.TrimSpace(v.EdbCode)
- if v.EdbCode == "" {
- br.Msg = "指标ID不可为空"
- return
- }
- v.EdbName = strings.TrimSpace(v.EdbName)
- if v.EdbName == "" {
- br.Msg = "请输入指标名称"
- return
- }
- indexNames = append(indexNames, v.EdbName)
- resp = append(resp, &NameCheckResult{
- EdbCode: v.EdbCode,
- EdbName: v.EdbName,
- })
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(v.EdbCode, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) <= 0 {
- respItem, err := data.AddEdbData(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, v.EdbCode, v.Frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + v.EdbCode
- return
- }
- }
- }
- // 重名校验
- edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
- return
- }
- nameExists := make(map[string]bool)
- for _, v := range edbList {
- nameExists[v.EdbName] = true
- }
- if len(nameExists) > 0 {
- for _, v := range resp {
- v.Exist = nameExists[v.EdbName]
- }
- }
- br.Data = resp
- br.Msg = "校验成功"
- br.Ret = 200
- br.Success = true
- }
- // BatchAdd
- // @Title 批量新增
- // @Description 批量新增
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /mysteel_chemical/batch_add [post]
- func (this *EdbInfoController) BatchAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_BATCH_ADD_MYSTEEL_CHEMICAL_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- _ = utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req []*data_manage.AddEdbInfoReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if len(req) == 0 {
- br.Msg = "请选择指标"
- return
- }
- if len(req) > 30 {
- br.Msg = "批量添加指标数量不得超过30个"
- return
- }
- for _, v := range req {
- v.EdbCode = strings.TrimSpace(v.EdbCode)
- if v.EdbCode == "" {
- br.Msg = "指标ID不可为空"
- return
- }
- v.EdbName = strings.TrimSpace(v.EdbName)
- if v.EdbName == "" {
- br.Msg = "请输入指标名称"
- return
- }
- v.Frequency = strings.TrimSpace(v.Frequency)
- if v.Frequency == "" {
- br.Msg = "请选择频度"
- return
- }
- v.Unit = strings.TrimSpace(v.Unit)
- if v.Unit == "" {
- br.Msg = "请输入单位"
- return
- }
- if v.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- }
- // 限定同一时间最多批量新增30个指标
- for _, v := range req {
- var r data.MysteelChemicalIndexSource2EdbReq
- r.EdbCode = v.EdbCode
- r.EdbName = v.EdbName
- r.Frequency = v.Frequency
- r.Unit = v.Unit
- r.ClassifyId = v.ClassifyId
- r.AdminId = sysUser.AdminId
- r.AdminRealName = sysUser.RealName
- edbInfo, e, errMsg, skip := data.MysteelChemicalIndexSource2Edb(r, this.Lang)
- if e != nil {
- br.Msg = "操作失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = e.Error()
- return
- }
- if skip {
- continue
- }
- // 试用平台更新用户累计新增指标数
- if utils.BusinessCode == utils.BusinessCodeSandbox {
- go func() {
- adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- if e != nil {
- tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
- utils.FileLog.Info(tips)
- return
- }
- if adminItem.DepartmentName != "ETA试用客户" {
- return
- }
- var ur etaTrialService.EtaTrialUserReq
- ur.Mobile = adminItem.Mobile
- _, _ = etaTrialService.UpdateUserIndexNum(ur)
- }()
- }
- // 新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- }
- br.Msg = "操作成功"
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- }
- // EdbInfoAdd
- // @Title 新增指标接口
- // @Description 新增指标接口
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /mysteel_chemical/edb_info/add [post]
- func (this *EdbInfoController) Add() {
- 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
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req data_manage.AddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- req.EdbCode = strings.Trim(req.EdbCode, " ")
- if req.EdbCode == "" {
- br.Msg = "指标ID不能为空"
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if req.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if req.Unit == "" {
- br.Msg = "单位不能为空"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- var source int
- if tmpInfo != nil {
- source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- } else {
- br.Msg = "指标不存在"
- return
- }
- // 指标入库
- edbInfo, err, errMsg, isSendEmail := data.EdbInfoAdd(source, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, req.StartDate, req.EndDate, sysUser.AdminId, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- // 试用平台更新用户累计新增指标数
- adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取系统用户数据失败,Err:" + e.Error()
- return
- }
- if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
- go func() {
- var r etaTrialService.EtaTrialUserReq
- r.Mobile = adminItem.Mobile
- _, _ = etaTrialService.UpdateUserIndexNum(r)
- }()
- }
- //新增操作日志
- {
- // 添加钢联指标更新日志
- if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
- }
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- // 更新es
- go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
- resp := new(data_manage.AddEdbInfoResp)
- resp.EdbInfoId = edbInfo.EdbInfoId
- resp.UniqueCode = edbInfo.UniqueCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // AddCheck
- // @Title 新增校验
- // @Description 新增校验
- // @Param request body request.BusinessDataBatchAddCheckReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /mysteel_chemical/edb_info/add_check [post]
- func (c *EdbInfoController) AddCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req *data_manage.BatchAddCheckReq
- if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- codeMax := 30
- codeLen := len(req.IndexCodes)
- // 获取指标库已有指标
- existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取自有数据已添加的指标失败, Err: " + e.Error()
- return
- }
- existMap := make(map[string]*data_manage.EdbInfo)
- for _, v := range existsEdb {
- existMap[v.EdbCode] = v
- }
- obj := data_manage.BaseFromMysteelChemicalIndex{}
- if codeLen == 0 {
- br.Msg = "请选择指标"
- return
- }
- if codeLen > codeMax {
- br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
- return
- }
- // 查询选中的指标
- cond := fmt.Sprintf(` AND %s IN (%s)`, data_manage.BaseFromMysteelChemicalIndexCols.IndexCode, utils.GetOrmInReplace(codeLen))
- pars := make([]interface{}, 0)
- pars = append(pars, req.IndexCodes)
- list, e := obj.GeItemsByCondition(cond, pars, 0)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取自有数据原始指标列表失败, Err: " + e.Error()
- return
- }
- if len(list) > codeMax {
- br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
- return
- }
- resp := make([]*data_manage.BaseFromMysteelChemicalIndexItem, 0)
- for _, v := range list {
- if v.EdbInfoId > 0 {
- v.EdbExist = 1
- }
- resp = append(resp, v)
- }
- br.Data = resp
- br.Msg = "校验成功"
- br.Ret = 200
- br.Success = true
- }
- // MysteelChemicalSearch
- // @Title 钢联化工指标查询
- // @Description 钢联化工指标查询
- // @Param BaseFromMysteelChemicalClassifyIds query string true "分类id"
- // @Param Keyword query string true "名称关键词"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /mysteel_chemical/batch_search [get]
- func (this *EdbInfoController) MysteelChemicalBatchSearch() {
- 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
- }
- classifyIdStr := this.GetString("BaseFromMysteelChemicalClassifyIds")
- var condition string
- var pars []interface{}
- classifyIds := strings.Split(classifyIdStr, ",")
- if len(classifyIds) > 0 && classifyIds[0] != `` {
- condition += " AND base_from_mysteel_chemical_classify_id IN (" + utils.GetOrmInReplace(len(classifyIds)) + " ) "
- pars = append(pars, classifyIds)
- }
- keyword := this.GetString("Keyword")
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- if classifyIdStr == `` && keyword == `` {
- var list = make([]*data_manage.MysteelChemicalList, 0)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- return
- }
- list, err := data_manage.GetMysteelChemicalIndex(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- classifyIdInts := make([]int, 0)
- for _, v := range list {
- v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
- if v.BaseFromMysteelChemicalClassifyId > 0 {
- classifyIdInts = append(classifyIdInts, v.BaseFromMysteelChemicalClassifyId)
- }
- }
- if len(classifyIdInts) > 0 {
- // 查询父级分类信息
- classifyList, e := data_manage.GetBaseFromMysteelChemicalClassifyByIds(classifyIdInts)
- if e != nil {
- br.Msg = "获取目录信息失败"
- br.ErrMsg = "获取失获取目录信息失败,Err:" + e.Error()
- return
- }
- classifyListMap := make(map[int]int, 0)
- for _, v := range classifyList {
- classifyListMap[v.BaseFromMysteelChemicalClassifyId] = v.ParentId
- }
- for _, v := range list {
- v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
- if p, ok := classifyListMap[v.BaseFromMysteelChemicalClassifyId]; ok {
- v.ParentClassifyId = p
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
|