custom_analysis.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. package excel
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. excelModel "eta/eta_api/models/data_manage/excel"
  7. "eta/eta_api/models/data_manage/excel/request"
  8. "eta/eta_api/models/data_manage/excel/response"
  9. "eta/eta_api/services/data/excel"
  10. "eta/eta_api/utils"
  11. "fmt"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // CustomAnalysisController 自定义分析
  17. type CustomAnalysisController struct {
  18. controllers.BaseAuthController
  19. }
  20. // ExcelByName
  21. // @Title 根据excel名称获取表格详情(基础信息+第一页初始化数据)
  22. // @Description 根据excel名称获取表格详情(基础信息+第一页初始化数据)
  23. // @Param ExcelName query string true "搜索关键词"
  24. // @Success 200 {object} response.ExcelListResp
  25. // @router /excel_by_name [get]
  26. func (c *CustomAnalysisController) ExcelByName() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. c.Data["json"] = br
  30. c.ServeJSON()
  31. }()
  32. sysUser := c.SysUser
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. excelName := c.GetString("ExcelName")
  40. if excelName == `` {
  41. br.Msg = "请选择表格"
  42. br.ErrMsg = "ExcelName未传"
  43. br.IsSendEmail = false
  44. return
  45. }
  46. resp := response.FindExcelInfoResp{}
  47. excelName = utils.TrimLRStr(excelName)
  48. // 获取数据详情
  49. excelDetail, err := excelModel.GetNoContentExcelInfoByName(excelName, utils.CUSTOM_ANALYSIS_TABLE)
  50. if err != nil {
  51. if err.Error() == utils.ErrNoRow() {
  52. br.Ret = 200
  53. br.Success = true
  54. br.Msg = "获取成功"
  55. br.Data = resp
  56. return
  57. }
  58. br.Msg = "获取表格事变"
  59. br.ErrMsg = err.Error()
  60. return
  61. }
  62. resp.IsFind = true
  63. resp.ExcelInfo = response.FindExcelInfo{
  64. ExcelInfoId: excelDetail.ExcelInfoId,
  65. Source: excelDetail.Source,
  66. ExcelType: excelDetail.ExcelType,
  67. ExcelName: excelDetail.ExcelName,
  68. UniqueCode: excelDetail.UniqueCode,
  69. ExcelClassifyId: excelDetail.ExcelClassifyId,
  70. SysUserId: excelDetail.SysUserId,
  71. SysUserRealName: excelDetail.SysUserRealName,
  72. ExcelImage: excelDetail.ExcelImage,
  73. FileUrl: excelDetail.FileUrl,
  74. Sort: excelDetail.Sort,
  75. ModifyTime: excelDetail.ModifyTime,
  76. CreateTime: excelDetail.CreateTime,
  77. Button: excel.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source),
  78. }
  79. if excelDetail != nil {
  80. sheetList, err := excelModel.GetAllSheetItemList(excelDetail.ExcelInfoId)
  81. if err != nil {
  82. br.Msg = "获取sheet失败"
  83. br.ErrMsg = "获取sheet失败,err:" + err.Error()
  84. return
  85. }
  86. resp.SheetList = sheetList
  87. }
  88. //resp := response.ExcelListResp{
  89. // Paging: page,
  90. // List: list,
  91. //}
  92. br.Ret = 200
  93. br.Success = true
  94. br.Msg = "获取成功"
  95. br.Data = resp
  96. }
  97. // Add
  98. // @Title 新增表格接口
  99. // @Description 新增表格接口
  100. // @Param request body request.AddExcelInfoReq true "type json string"
  101. // @Success 200 {object} response.AddExcelInfoResp
  102. // @router /add [post]
  103. func (c *CustomAnalysisController) Add() {
  104. br := new(models.BaseResponse).Init()
  105. defer func() {
  106. c.Data["json"] = br
  107. c.ServeJSON()
  108. }()
  109. sysUser := c.SysUser
  110. if sysUser == nil {
  111. br.Msg = "请登录"
  112. br.ErrMsg = "请登录,SysUser Is Empty"
  113. br.Ret = 408
  114. return
  115. }
  116. deleteCache := true
  117. cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  118. defer func() {
  119. if deleteCache {
  120. _ = utils.Rc.Delete(cacheKey)
  121. }
  122. }()
  123. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  124. deleteCache = false
  125. br.Msg = "系统处理中,请稍后重试!"
  126. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  127. return
  128. }
  129. var req request.AddExcelInfoReq
  130. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  131. if err != nil {
  132. br.Msg = "参数解析异常!"
  133. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  134. return
  135. }
  136. req.ExcelName = strings.Trim(req.ExcelName, " ")
  137. if req.ExcelName == "" {
  138. br.Msg = "请填写表格名称!"
  139. br.IsSendEmail = false
  140. return
  141. }
  142. // 获取是否存在该表格名称
  143. {
  144. var condition string
  145. var pars []interface{}
  146. condition += " AND source=? "
  147. pars = append(pars, utils.CUSTOM_ANALYSIS_TABLE)
  148. condition += " AND excel_name=? "
  149. pars = append(pars, req.ExcelName)
  150. count, err := excelModel.GetExcelInfoCountByCondition(condition, pars)
  151. if err != nil {
  152. br.Msg = "判断表格名称是否存在失败"
  153. br.ErrMsg = "判断表格名称是否存在失败,Err:" + err.Error()
  154. return
  155. }
  156. if count > 0 {
  157. br.Msg = "表格名称已存在,请重新填写表格名称"
  158. br.IsSendEmail = false
  159. return
  160. }
  161. }
  162. if req.ExcelClassifyId <= 0 {
  163. br.Msg = "分类参数错误!"
  164. br.IsSendEmail = false
  165. return
  166. }
  167. excelInfo, err, errMsg, isSendEmail := excel.AddCustomAnalysisTable(utils.TrimLRStr(req.ExcelName), req.Content, req.ExcelImage, req.ExcelClassifyId, sysUser)
  168. if err != nil {
  169. br.Msg = "保存失败"
  170. if errMsg != `` {
  171. br.Msg = errMsg
  172. }
  173. br.ErrMsg = "保存失败,Err:" + err.Error()
  174. br.IsSendEmail = isSendEmail
  175. return
  176. }
  177. // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
  178. //if req.Source == 1 {
  179. // go UpdateExcelInfoFileUrl(excelInfo)
  180. //}
  181. //
  182. resp := new(response.AddExcelInfoResp)
  183. resp.ExcelInfoId = excelInfo.ExcelInfoId
  184. resp.UniqueCode = excelInfo.UniqueCode
  185. // 生成excel文件
  186. go excel.UpdateExcelInfoFileUrl(excelInfo)
  187. //新增操作日志
  188. //{
  189. // excelLog := &data_manage.ExcelInfoLog{
  190. // //ExcelInfoLogId: 0,
  191. // ExcelInfoId: excelInfo.ExcelInfoId,
  192. // ExcelName: req.ExcelName,
  193. // ExcelClassifyId: req.ExcelClassifyId,
  194. // SysUserId: sysUser.AdminId,
  195. // SysUserRealName: sysUser.RealName,
  196. // UniqueCode: excelInfo.UniqueCode,
  197. // CreateTime: time.Now(),
  198. // Content: string(c.Ctx.Input.RequestBody),
  199. // Status: "新增表格",
  200. // Method: c.Ctx.Input.URI(),
  201. // }
  202. // go data_manage.AddExcelInfoLog(excelLog)
  203. //}
  204. br.Ret = 200
  205. br.Success = true
  206. br.Msg = "保存成功"
  207. br.Data = resp
  208. br.IsAddLog = false //数据量太大了,不写入日志吧
  209. }
  210. // Save
  211. // @Title 保存表格接口
  212. // @Description 保存表格接口
  213. // @Param request body request.AddExcelInfoReq true "type json string"
  214. // @Success 200 {object} response.AddExcelInfoResp
  215. // @router /save [post]
  216. func (c *CustomAnalysisController) Save() {
  217. br := new(models.BaseResponse).Init()
  218. defer func() {
  219. c.Data["json"] = br
  220. c.ServeJSON()
  221. }()
  222. sysUser := c.SysUser
  223. if sysUser == nil {
  224. br.Msg = "请登录"
  225. br.ErrMsg = "请登录,SysUser Is Empty"
  226. br.Ret = 408
  227. return
  228. }
  229. deleteCache := true
  230. cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  231. defer func() {
  232. if deleteCache {
  233. _ = utils.Rc.Delete(cacheKey)
  234. }
  235. }()
  236. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  237. deleteCache = false
  238. br.Msg = "系统处理中,请稍后重试!"
  239. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  240. return
  241. }
  242. var req request.SaveExcelInfoReq
  243. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  244. if err != nil {
  245. br.Msg = "参数解析异常!"
  246. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  247. return
  248. }
  249. req.ExcelName = strings.Trim(req.ExcelName, " ")
  250. if req.ExcelName == "" {
  251. br.Msg = "请填写表格名称!"
  252. br.IsSendEmail = false
  253. return
  254. }
  255. if req.ExcelInfoId <= 0 {
  256. br.Msg = "请选择excel!"
  257. br.IsSendEmail = false
  258. return
  259. }
  260. if req.ExcelClassifyId <= 0 {
  261. br.Msg = "分类参数错误!"
  262. br.IsSendEmail = false
  263. return
  264. }
  265. excelInfo, err := excelModel.GetExcelInfoById(req.ExcelInfoId)
  266. if err != nil {
  267. br.Msg = "找不到该EXCEL!"
  268. br.ErrMsg = "找不到该EXCEL!err:" + err.Error()
  269. return
  270. }
  271. if excelInfo.Source != utils.CUSTOM_ANALYSIS_TABLE {
  272. br.Msg = "EXCEL异常!"
  273. br.IsSendEmail = false
  274. return
  275. }
  276. err, errMsg, isSendEmail := excel.SaveCustomAnalysisTable(excelInfo, utils.TrimLRStr(req.ExcelName), req.Content, req.ExcelImage, req.ExcelClassifyId, req.OpSheetList)
  277. if err != nil {
  278. br.Msg = "保存失败"
  279. if errMsg != `` {
  280. br.Msg = errMsg
  281. }
  282. br.ErrMsg = "保存失败,Err:" + err.Error()
  283. br.IsSendEmail = isSendEmail
  284. return
  285. }
  286. // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
  287. //if req.Source == 1 {
  288. // go UpdateExcelInfoFileUrl(excelInfo)
  289. //}
  290. //
  291. resp := new(response.AddExcelInfoResp)
  292. resp.ExcelInfoId = excelInfo.ExcelInfoId
  293. resp.UniqueCode = excelInfo.UniqueCode
  294. // 生成excel文件
  295. go excel.UpdateExcelInfoFileUrl(excelInfo)
  296. //新增操作日志
  297. //{
  298. // excelLog := &data_manage.ExcelInfoLog{
  299. // //ExcelInfoLogId: 0,
  300. // ExcelInfoId: excelInfo.ExcelInfoId,
  301. // ExcelName: req.ExcelName,
  302. // ExcelClassifyId: req.ExcelClassifyId,
  303. // SysUserId: sysUser.AdminId,
  304. // SysUserRealName: sysUser.RealName,
  305. // UniqueCode: excelInfo.UniqueCode,
  306. // CreateTime: time.Now(),
  307. // Content: string(c.Ctx.Input.RequestBody),
  308. // Status: "新增表格",
  309. // Method: c.Ctx.Input.URI(),
  310. // }
  311. // go data_manage.AddExcelInfoLog(excelLog)
  312. //}
  313. br.Ret = 200
  314. br.Success = true
  315. br.Msg = "保存成功"
  316. br.Data = resp
  317. br.IsAddLog = false //数据量太大了,不写入日志吧
  318. }
  319. // BaseExcelDetail
  320. // @Title 根据excel名称获取表格详情(基础信息+第一页初始化数据)
  321. // @Description 根据excel名称获取表格详情(基础信息+第一页初始化数据)
  322. // @Param UniqueCode query string true "excel唯一编码"
  323. // @Success 200 {object} response.ExcelListResp
  324. // @router /excel/base [get]
  325. func (c *CustomAnalysisController) BaseExcelDetail() {
  326. br := new(models.BaseResponse).Init()
  327. defer func() {
  328. c.Data["json"] = br
  329. c.ServeJSON()
  330. }()
  331. sysUser := c.SysUser
  332. if sysUser == nil {
  333. br.Msg = "请登录"
  334. br.ErrMsg = "请登录,SysUser Is Empty"
  335. br.Ret = 408
  336. return
  337. }
  338. uniqueCode := c.GetString("UniqueCode")
  339. if uniqueCode == `` {
  340. br.Msg = "请选择表格"
  341. br.ErrMsg = "UniqueCode未传"
  342. br.IsSendEmail = false
  343. return
  344. }
  345. resp := response.FindExcelInfoResp{}
  346. // 获取数据详情
  347. excelDetail, err := excelModel.GetNoContentExcelInfoByUniqueCode(uniqueCode)
  348. if err != nil {
  349. if err.Error() == utils.ErrNoRow() {
  350. br.Ret = 200
  351. br.Success = true
  352. br.Msg = "获取成功"
  353. br.Data = resp
  354. return
  355. }
  356. br.Msg = "获取表格事变"
  357. br.ErrMsg = err.Error()
  358. return
  359. }
  360. resp.IsFind = true
  361. resp.ExcelInfo = response.FindExcelInfo{
  362. ExcelInfoId: excelDetail.ExcelInfoId,
  363. Source: excelDetail.Source,
  364. ExcelType: excelDetail.ExcelType,
  365. ExcelName: excelDetail.ExcelName,
  366. UniqueCode: excelDetail.UniqueCode,
  367. ExcelClassifyId: excelDetail.ExcelClassifyId,
  368. SysUserId: excelDetail.SysUserId,
  369. SysUserRealName: excelDetail.SysUserRealName,
  370. ExcelImage: excelDetail.ExcelImage,
  371. FileUrl: excelDetail.FileUrl,
  372. Sort: excelDetail.Sort,
  373. ModifyTime: excelDetail.ModifyTime,
  374. CreateTime: excelDetail.CreateTime,
  375. Button: excel.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source),
  376. }
  377. if excelDetail != nil {
  378. sheetList, err := excelModel.GetAllSheetItemList(excelDetail.ExcelInfoId)
  379. if err != nil {
  380. br.Msg = "获取sheet失败"
  381. br.ErrMsg = "获取sheet失败,err:" + err.Error()
  382. return
  383. }
  384. if len(sheetList) > 0 {
  385. sheetIdList := make([]int, 0)
  386. for _, v := range sheetList {
  387. sheetIdList = append(sheetIdList, v.ExcelSheetId)
  388. }
  389. // 获取所有sheet的第一页的数据
  390. sheetDataList, err := excelModel.GetSheetDataListBySheetIdListAndPage(sheetIdList, 1)
  391. if err != nil {
  392. br.Msg = "获取sheet中的数据失败"
  393. br.ErrMsg = "获取sheet中的数据失败,err:" + err.Error()
  394. return
  395. }
  396. sheetDataMap := make(map[int]*excelModel.ExcelSheetData)
  397. for _, v := range sheetDataList {
  398. sheetDataMap[v.ExcelSheetId] = v
  399. }
  400. for k, v := range sheetList {
  401. sheetData, ok := sheetDataMap[v.ExcelSheetId]
  402. if !ok {
  403. continue
  404. }
  405. v.Data = sheetData
  406. sheetList[k] = v
  407. }
  408. }
  409. // TODO 合并单元格信息、计算公式
  410. resp.SheetList = sheetList
  411. }
  412. //resp := response.ExcelListResp{
  413. // Paging: page,
  414. // List: list,
  415. //}
  416. br.Ret = 200
  417. br.Success = true
  418. br.Msg = "获取成功"
  419. br.Data = resp
  420. }
  421. // ExcelDataList
  422. // @Title 根据excel名称获取表格详情(基础信息+第一页初始化数据)
  423. // @Description 根据excel名称获取表格详情(基础信息+第一页初始化数据)
  424. // @Param UniqueCode query string true "excel唯一编码"
  425. // @Param Page query int true "页码"
  426. // @Success 200 {object} response.ExcelListResp
  427. // @router /excel/data [get]
  428. func (c *CustomAnalysisController) ExcelDataList() {
  429. br := new(models.BaseResponse).Init()
  430. defer func() {
  431. c.Data["json"] = br
  432. c.ServeJSON()
  433. }()
  434. sysUser := c.SysUser
  435. if sysUser == nil {
  436. br.Msg = "请登录"
  437. br.ErrMsg = "请登录,SysUser Is Empty"
  438. br.Ret = 408
  439. return
  440. }
  441. uniqueCode := c.GetString("UniqueCode")
  442. if uniqueCode == `` {
  443. br.Msg = "请选择表格"
  444. br.ErrMsg = "UniqueCode未传"
  445. br.IsSendEmail = false
  446. return
  447. }
  448. page, _ := c.GetInt("Page")
  449. if page <= 0 {
  450. br.Msg = "页码异常"
  451. br.ErrMsg = "页码异常"
  452. br.IsSendEmail = false
  453. return
  454. }
  455. sheetList := make([]*excelModel.SheetItem, 0)
  456. // 获取数据详情
  457. excelDetail, err := excelModel.GetNoContentExcelInfoByUniqueCode(uniqueCode)
  458. if err != nil {
  459. if err.Error() == utils.ErrNoRow() {
  460. br.Ret = 200
  461. br.Success = true
  462. br.Msg = "获取成功"
  463. br.Data = sheetList
  464. return
  465. }
  466. br.Msg = "获取表格事变"
  467. br.ErrMsg = err.Error()
  468. return
  469. }
  470. if excelDetail.Source != utils.CUSTOM_ANALYSIS_TABLE {
  471. br.Msg = "excel异常"
  472. br.ErrMsg = "excel异常"
  473. br.IsSendEmail = false
  474. return
  475. }
  476. if excelDetail != nil {
  477. sheetList, err = excelModel.GetAllNoConfigSheetItemList(excelDetail.ExcelInfoId)
  478. if err != nil {
  479. br.Msg = "获取sheet失败"
  480. br.ErrMsg = "获取sheet失败,err:" + err.Error()
  481. return
  482. }
  483. if len(sheetList) > 0 {
  484. sheetIdList := make([]int, 0)
  485. for _, v := range sheetList {
  486. sheetIdList = append(sheetIdList, v.ExcelSheetId)
  487. }
  488. // 获取所有sheet的第一页的数据
  489. sheetDataList, err := excelModel.GetSheetDataListBySheetIdListAndPage(sheetIdList, page)
  490. if err != nil {
  491. br.Msg = "获取sheet中的数据失败"
  492. br.ErrMsg = "获取sheet中的数据失败,err:" + err.Error()
  493. return
  494. }
  495. sheetDataMap := make(map[int]*excelModel.ExcelSheetData)
  496. for _, v := range sheetDataList {
  497. sheetDataMap[v.ExcelSheetId] = v
  498. }
  499. for k, v := range sheetList {
  500. sheetData, ok := sheetDataMap[v.ExcelSheetId]
  501. if !ok {
  502. continue
  503. }
  504. v.Data = sheetData
  505. sheetList[k] = v
  506. }
  507. }
  508. // TODO 合并单元格信息、计算公式
  509. }
  510. //resp := response.ExcelListResp{
  511. // Paging: page,
  512. // List: list,
  513. //}
  514. br.Ret = 200
  515. br.Success = true
  516. br.Msg = "获取成功"
  517. br.Data = sheetList
  518. }
  519. // FixTableData ETA1.0.2 自定义分析(生成指标数据修复)
  520. func FixTableData() {
  521. // 获取一级分类
  522. classifyList, err := excelModel.GetExcelClassifyByParentId(0, utils.EXCEL_DEFAULT)
  523. if err != nil && err.Error() != utils.ErrNoRow() {
  524. fmt.Println("数据修复失败,Err:" + err.Error())
  525. return
  526. }
  527. timeTableMap := make(map[int]int)
  528. mixTableMap := make(map[int]int)
  529. for _, v := range classifyList {
  530. // 时间序列表格
  531. classify := &excelModel.ExcelClassify{
  532. //ExcelClassifyId: 0,
  533. ExcelClassifyName: v.ExcelClassifyName,
  534. ParentId: v.ParentId,
  535. Source: utils.TIME_TABLE,
  536. SysUserId: v.SysUserId,
  537. SysUserRealName: v.SysUserRealName,
  538. Level: v.Level,
  539. UniqueCode: utils.MD5(fmt.Sprint(v.UniqueCode, "_", utils.TIME_TABLE)),
  540. Sort: v.Sort,
  541. CreateTime: time.Now(),
  542. ModifyTime: time.Now(),
  543. }
  544. _, err = excelModel.AddExcelClassify(classify)
  545. timeTableMap[v.ExcelClassifyId] = classify.ExcelClassifyId
  546. // 混合表格
  547. classify2 := &excelModel.ExcelClassify{
  548. //ExcelClassifyId: 0,
  549. ExcelClassifyName: v.ExcelClassifyName,
  550. ParentId: v.ParentId,
  551. Source: utils.MIXED_TABLE,
  552. SysUserId: v.SysUserId,
  553. SysUserRealName: v.SysUserRealName,
  554. Level: v.Level,
  555. UniqueCode: utils.MD5(fmt.Sprint(v.UniqueCode, "_", utils.MIXED_TABLE)),
  556. Sort: v.Sort,
  557. CreateTime: time.Now(),
  558. ModifyTime: time.Now(),
  559. }
  560. _, err = excelModel.AddExcelClassify(classify2)
  561. mixTableMap[v.ExcelClassifyId] = classify2.ExcelClassifyId
  562. }
  563. // 修改时间序列表
  564. {
  565. // 获取时间序列表
  566. timeTableExcelList, err := excelModel.GetNoContentExcelInfoAll(utils.TIME_TABLE, 0)
  567. if err != nil && err.Error() != utils.ErrNoRow() {
  568. fmt.Println("获取时间序列表列表失败,Err:" + err.Error())
  569. return
  570. }
  571. for _, v := range timeTableExcelList {
  572. classifyId, ok := timeTableMap[v.ExcelClassifyId]
  573. if !ok {
  574. continue
  575. }
  576. excelModel.UpdateExcelInfoClassifyId(classifyId, v.ExcelInfoId)
  577. }
  578. }
  579. // 修改混合序列表
  580. {
  581. // 获取时间序列表
  582. mixTableExcelList, err := excelModel.GetNoContentExcelInfoAll(utils.MIXED_TABLE, 0)
  583. if err != nil && err.Error() != utils.ErrNoRow() {
  584. fmt.Println("获取时间序列表列表失败,Err:" + err.Error())
  585. return
  586. }
  587. for _, v := range mixTableExcelList {
  588. classifyId, ok := mixTableMap[v.ExcelClassifyId]
  589. if !ok {
  590. continue
  591. }
  592. excelModel.UpdateExcelInfoClassifyId(classifyId, v.ExcelInfoId)
  593. }
  594. }
  595. fmt.Println("完成数据修复")
  596. }
  597. // FixTableDataMapping ETA1.0.2 自定义分析(修复excel与指标的关系)
  598. func FixTableDataMapping() {
  599. // 修改时间序列表
  600. {
  601. // 获取时间序列表
  602. timeTableExcelList, err := excelModel.GetAllExcelInfoBySource(utils.TIME_TABLE)
  603. if err != nil && err.Error() != utils.ErrNoRow() {
  604. fmt.Println("获取时间序列表列表失败,Err:" + err.Error())
  605. return
  606. }
  607. for _, v := range timeTableExcelList {
  608. var tableData request.TableDataReq
  609. err = json.Unmarshal([]byte(v.Content), &tableData)
  610. if err != nil {
  611. fmt.Println(v.ExcelInfoId, "json转结构体失败,Err:"+err.Error())
  612. continue
  613. }
  614. if len(tableData.EdbInfoIdList) > 0 {
  615. excelEdbMappingList := make([]*excelModel.ExcelEdbMapping, 0)
  616. for _, edbInfoId := range tableData.EdbInfoIdList {
  617. excelEdbMappingList = append(excelEdbMappingList, &excelModel.ExcelEdbMapping{
  618. //ExcelEdbMappingId: 0,
  619. ExcelInfoId: v.ExcelInfoId,
  620. Source: v.Source,
  621. EdbInfoId: edbInfoId,
  622. CreateTime: time.Now(),
  623. ModifyTime: time.Now(),
  624. })
  625. }
  626. err = excelModel.AddExcelEdbMappingMulti(excelEdbMappingList)
  627. if err != nil {
  628. fmt.Println(v.ExcelInfoId, "自定义表格关系保存失败,Err:"+err.Error())
  629. continue
  630. }
  631. }
  632. }
  633. }
  634. //// 修改混合序列表
  635. //{
  636. // // 获取时间序列表
  637. // mixTableExcelList, err := excelModel.GetAllExcelInfoBySource(utils.MIXED_TABLE)
  638. // if err != nil && err.Error() != utils.ErrNoRow() {
  639. // fmt.Println("获取时间序列表列表失败,Err:" + err.Error())
  640. // return
  641. // }
  642. //
  643. // for _, excelInfo := range mixTableExcelList {
  644. // var result request.MixedTableReq
  645. // err = json.Unmarshal([]byte(excelInfo.Content), &result)
  646. // if err != nil {
  647. // fmt.Println(excelInfo.ExcelInfoId, "修改混合序列表,json转结构体失败,Err:"+err.Error())
  648. // continue
  649. // }
  650. // newResult, tmpErr := excel.GetMixedTableCellData(result.Data)
  651. // if tmpErr != nil {
  652. // fmt.Println(excelInfo.ExcelInfoId, "获取最新的数据失败,Err:"+err.Error())
  653. // continue
  654. // }
  655. // edbInfoIdList := make([]int, 0)
  656. // edbInfoIdMap := make(map[int]int)
  657. // for _, tmpV := range newResult {
  658. // for _, v := range tmpV {
  659. // if v.EdbInfoId > 0 {
  660. // if _, ok := edbInfoIdMap[v.EdbInfoId]; !ok {
  661. // edbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
  662. // edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  663. // }
  664. // }
  665. // }
  666. // }
  667. //
  668. // if len(edbInfoIdList) > 0 {
  669. // excelEdbMappingList := make([]*excelModel.ExcelEdbMapping, 0)
  670. // for _, edbInfoId := range edbInfoIdList {
  671. // excelEdbMappingList = append(excelEdbMappingList, &excelModel.ExcelEdbMapping{
  672. // //ExcelEdbMappingId: 0,
  673. // ExcelInfoId: excelInfo.ExcelInfoId,
  674. // Source: excelInfo.Source,
  675. // EdbInfoId: edbInfoId,
  676. // CreateTime: time.Now(),
  677. // ModifyTime: time.Now(),
  678. // })
  679. // }
  680. // err = excelModel.AddExcelEdbMappingMulti(excelEdbMappingList)
  681. // if err != nil {
  682. // fmt.Println(excelInfo.ExcelInfoId, "混合表格关系保存失败,Err:"+err.Error())
  683. // continue
  684. // }
  685. // }
  686. //
  687. // }
  688. //
  689. //}
  690. fmt.Println("完成数据修复")
  691. }