custom_analysis.go 21 KB

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