resource.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. package knowledge
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta_gn/eta_api/models/knowledge"
  6. "eta_gn/eta_api/models/system"
  7. "eta_gn/eta_api/services"
  8. "eta_gn/eta_api/services/alarm_msg"
  9. "eta_gn/eta_api/utils"
  10. "fmt"
  11. "html"
  12. "strconv"
  13. "strings"
  14. "time"
  15. "github.com/go-redis/redis/v8"
  16. "github.com/rdlucklib/rdluck_tools/paging"
  17. "github.com/tealeg/xlsx"
  18. )
  19. func AddResource(req *knowledge.AddReq, sysUser *system.Admin) (item *knowledge.KnowledgeResource, err error, errMsg string) {
  20. var startTime time.Time
  21. var endTime time.Time
  22. if req.StartTime != "" {
  23. if req.ResourceType == knowledge.KnowledgeResourceTypeEvent || req.ResourceType == knowledge.KnowledgeResourceTypePolicy {
  24. startTime, err = time.ParseInLocation(utils.FormatDateTime, req.StartTime, time.Local)
  25. if err != nil { // 如果时间格式不正确,则返回错误信息
  26. errMsg = "开始时间格式不正确"
  27. err = fmt.Errorf("开始时间格式不正确,Err:" + err.Error())
  28. return
  29. }
  30. } else {
  31. startTime, err = time.ParseInLocation(utils.FormatDate, req.StartTime, time.Local)
  32. if err != nil { // 如果时间格式不正确,则返回错误信息
  33. errMsg = "开始时间格式不正确"
  34. err = fmt.Errorf("开始时间格式不正确,Err:" + err.Error())
  35. return
  36. }
  37. }
  38. }
  39. if req.EndTime != "" {
  40. if req.ResourceType == knowledge.KnowledgeResourceTypeEvent || req.ResourceType == knowledge.KnowledgeResourceTypePolicy {
  41. endTime, err = time.ParseInLocation(utils.FormatDateTime, req.EndTime, time.Local)
  42. if err != nil { // 如果时间格式不正确,则返回错误信息
  43. errMsg = "结束时间格式不正确"
  44. err = fmt.Errorf("结束时间格式不正确,Err:" + err.Error())
  45. return
  46. }
  47. }
  48. }
  49. isFile := 0
  50. if req.Content != "" {
  51. e := utils.ContentXssCheck(req.Content)
  52. if e != nil {
  53. errMsg = "存在非法标签"
  54. err = fmt.Errorf("存在非法标签, Err: " + e.Error())
  55. return
  56. }
  57. content, e := services.FilterReportContentBr(req.Content)
  58. if e != nil {
  59. errMsg = "内容去除前后空格失败"
  60. err = fmt.Errorf("内容去除前后空格失败, Err: " + e.Error())
  61. return
  62. }
  63. req.Content = content
  64. /*contentSub, err = services.GetReportContentSub(req.Content)
  65. if err != nil {
  66. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  67. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  68. return
  69. }*/
  70. } else {
  71. if req.FileUrl == "" {
  72. errMsg = "内容或文件不能为空"
  73. err = fmt.Errorf("内容或文件不能为空")
  74. return
  75. }
  76. isFile = 1
  77. }
  78. classifyObj := new(knowledge.KnowledgeClassify)
  79. classifyItem, err := classifyObj.GetClassifyById(req.ClassifyId)
  80. if err != nil {
  81. if utils.IsErrNoRow(err) {
  82. err = fmt.Errorf("分类不存在,Err:" + err.Error())
  83. errMsg = "分类不存在"
  84. return
  85. }
  86. errMsg = "获取分类失败"
  87. err = fmt.Errorf("获取分类失败,Err:" + err.Error())
  88. return
  89. }
  90. if req.ClassifyId != classifyItem.ClassifyId { // 如果传进来的分类id和数据库中查到的分类id不一致,说明传进来的分类id是错误的
  91. errMsg = "错误分类"
  92. err = fmt.Errorf("错误分类")
  93. return
  94. }
  95. // 校验标签
  96. if req.TagId > 0 {
  97. tagObj := new(knowledge.KnowledgeTag)
  98. _, e := tagObj.GetTagById(req.TagId)
  99. if e != nil {
  100. if utils.IsErrNoRow(e) {
  101. err = fmt.Errorf("标签不存在,Err:" + e.Error())
  102. errMsg = "标签不存在"
  103. return
  104. }
  105. err = fmt.Errorf("获取标签失败,Err:" + e.Error())
  106. return
  107. }
  108. }
  109. item = new(knowledge.KnowledgeResource)
  110. item.ClassifyId = req.ClassifyId
  111. item.TagId = req.TagId
  112. item.SourceFrom = req.SourceFrom
  113. item.ResourceType = req.ResourceType
  114. item.Title = req.Title
  115. item.State = 1
  116. item.Content = html.EscapeString(req.Content)
  117. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  118. item.ResourceCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
  119. item.IsFile = isFile
  120. item.FileUrl = req.FileUrl
  121. //todo 内容前5行
  122. //item.ContentSub = html.EscapeString(contentSub)
  123. if !startTime.IsZero() {
  124. item.StartTime = &startTime
  125. } else {
  126. item.StartTime = nil
  127. }
  128. if !endTime.IsZero() {
  129. item.EndTime = &endTime
  130. } else {
  131. item.EndTime = nil
  132. }
  133. item.ModifyTime = time.Now()
  134. item.AdminId = sysUser.AdminId
  135. item.AdminRealName = sysUser.RealName
  136. //item.LastModifyAdminId = sysUser.AdminId
  137. //item.LastModifyAdminName = sysUser.RealName
  138. item.ModifyTime = time.Now()
  139. item.CreateTime = time.Now()
  140. err = item.Add(item)
  141. if err != nil {
  142. errMsg = "保存失败"
  143. err = fmt.Errorf("保存失败,Err:" + err.Error())
  144. return
  145. }
  146. // 保存到es中
  147. err = EsAddOrEditKnowledgeResource(item)
  148. if err != nil {
  149. errMsg = "保存到es失败"
  150. err = fmt.Errorf("保存到es失败,Err:" + err.Error())
  151. return
  152. }
  153. return
  154. }
  155. func EditResource(resourceInfo *knowledge.KnowledgeResource, req knowledge.EditReq, sysUser *system.Admin) (err error, errMsg string) {
  156. errMsg = `保存失败`
  157. var startTime time.Time
  158. var endTime time.Time
  159. if req.StartTime != "" {
  160. if req.ResourceType == knowledge.KnowledgeResourceTypeEvent || req.ResourceType == knowledge.KnowledgeResourceTypePolicy {
  161. startTime, err = time.ParseInLocation(utils.FormatDateTime, req.StartTime, time.Local)
  162. if err != nil { // 如果时间格式不正确,则返回错误信息
  163. errMsg = "开始时间格式不正确"
  164. err = fmt.Errorf("开始时间格式不正确,Err:" + err.Error())
  165. return
  166. }
  167. } else {
  168. startTime, err = time.ParseInLocation(utils.FormatDate, req.StartTime, time.Local)
  169. if err != nil { // 如果时间格式不正确,则返回错误信息
  170. errMsg = "开始时间格式不正确"
  171. err = fmt.Errorf("开始时间格式不正确,Err:" + err.Error())
  172. return
  173. }
  174. }
  175. }
  176. if req.EndTime != "" {
  177. if req.ResourceType == knowledge.KnowledgeResourceTypeEvent || req.ResourceType == knowledge.KnowledgeResourceTypePolicy {
  178. endTime, err = time.ParseInLocation(utils.FormatDateTime, req.EndTime, time.Local)
  179. if err != nil { // 如果时间格式不正确,则返回错误信息
  180. errMsg = "结束时间格式不正确"
  181. err = fmt.Errorf("结束时间格式不正确,Err:" + err.Error())
  182. return
  183. }
  184. }
  185. }
  186. if resourceInfo.IsFile == 0 {
  187. if req.Content == "" {
  188. errMsg = "内容不能为空"
  189. err = fmt.Errorf("内容不能为空")
  190. return
  191. }
  192. } else if resourceInfo.IsFile == 1 {
  193. if req.FileUrl == "" {
  194. errMsg = "文件地址不能为空"
  195. err = fmt.Errorf("文件地址不能为空")
  196. return
  197. }
  198. }
  199. if req.Content != "" {
  200. e := utils.ContentXssCheck(req.Content)
  201. if e != nil {
  202. errMsg = "存在非法标签"
  203. err = fmt.Errorf("存在非法标签, Err: " + e.Error())
  204. return
  205. }
  206. content, e := services.FilterReportContentBr(req.Content)
  207. if e != nil {
  208. errMsg = "内容去除前后空格失败"
  209. err = fmt.Errorf("内容去除前后空格失败, Err: " + e.Error())
  210. return
  211. }
  212. req.Content = content
  213. /*contentSub, err = services.GetReportContentSub(req.Content)
  214. if err != nil {
  215. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  216. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  217. return
  218. }*/
  219. }
  220. classifyObj := new(knowledge.KnowledgeClassify)
  221. classifyItem, err := classifyObj.GetClassifyById(req.ClassifyId)
  222. if err != nil {
  223. if utils.IsErrNoRow(err) {
  224. err = fmt.Errorf("分类不存在,Err:" + err.Error())
  225. errMsg = "分类不存在"
  226. return
  227. }
  228. errMsg = "获取分类失败"
  229. err = fmt.Errorf("获取分类失败,Err:" + err.Error())
  230. return
  231. }
  232. if req.ClassifyId != classifyItem.ClassifyId { // 如果传进来的分类id和数据库中查到的分类id不一致,说明传进来的分类id是错误的
  233. errMsg = "错误分类"
  234. err = fmt.Errorf("错误分类")
  235. return
  236. }
  237. if req.TagId > 0 {
  238. tagObj := new(knowledge.KnowledgeTag)
  239. _, e := tagObj.GetTagById(req.TagId)
  240. if e != nil {
  241. if utils.IsErrNoRow(e) {
  242. err = fmt.Errorf("标签不存在,Err:" + e.Error())
  243. errMsg = "标签不存在"
  244. return
  245. }
  246. err = fmt.Errorf("获取标签失败,Err:" + e.Error())
  247. return
  248. }
  249. }
  250. resourceInfo.ClassifyId = req.ClassifyId
  251. resourceInfo.SourceFrom = req.SourceFrom
  252. resourceInfo.TagId = req.TagId
  253. resourceInfo.Title = req.Title
  254. if req.Content != "" {
  255. resourceInfo.Content = html.EscapeString(req.Content)
  256. }
  257. if !startTime.IsZero() {
  258. resourceInfo.StartTime = &startTime
  259. }
  260. if !endTime.IsZero() {
  261. resourceInfo.EndTime = &endTime
  262. }
  263. resourceInfo.FileUrl = req.FileUrl
  264. //resourceInfo.LastModifyAdminId = sysUser.AdminId
  265. //resourceInfo.LastModifyAdminName = sysUser.RealName
  266. resourceInfo.ModifyTime = time.Now()
  267. updateCols := []string{"ClassifyId", "SourceFrom", "TagId", "Title", "Content", "StartTime", "EndTime", "ModifyTime", "FileUrl"}
  268. // 修改报告的基本信息,以及报告的授权用户
  269. err = resourceInfo.Update(updateCols)
  270. if err != nil {
  271. return
  272. }
  273. err = EsAddOrEditKnowledgeResource(resourceInfo)
  274. if err != nil {
  275. return
  276. }
  277. return
  278. }
  279. // ImportResourceData
  280. // @Description: 数据导入
  281. // @author: Roc
  282. // @datetime 2024-08-01 11:27:21
  283. // @param path string
  284. // @param sysUser *system.Admin
  285. // @return successCount int
  286. // @return failCount int
  287. // @return err error
  288. // @return errMsg string
  289. func ImportResourceData(path string, resourceType int, sysUser *system.Admin) (successCount, failCount int, err error, errMsg string) {
  290. // 错误信息
  291. errMsgList := make([]string, 0)
  292. defer func() {
  293. // 错误信息记录
  294. if len(errMsgList) > 0 {
  295. utils.FileLog.Info("导入失败, errMsgList: %v", strings.Join(errMsgList, "\n"))
  296. }
  297. }()
  298. errMsg = `导入失败`
  299. xlFile, err := xlsx.OpenFile(path)
  300. if err != nil {
  301. fmt.Println(err.Error())
  302. return
  303. }
  304. if len(xlFile.Sheets) <= 0 {
  305. errMsg = "导入模板异常"
  306. err = errors.New(errMsg)
  307. return
  308. }
  309. //导入失败数据
  310. failDataList := make([]*knowledge.KnowledgeImportFail, 0)
  311. var indexDataList []knowledge.ResourceImportData
  312. tagObj := new(knowledge.KnowledgeTag)
  313. // 模板校验,然后处理成标准化格式
  314. for _, sheet := range xlFile.Sheets {
  315. var tmpFailDataList []*knowledge.KnowledgeImportFail
  316. var tmpIndexDataList []knowledge.ResourceImportData
  317. rowList := sheet.Rows
  318. if len(rowList) <= 0 {
  319. errMsg = sheet.Name + "页异常"
  320. err = errors.New(errMsg)
  321. return
  322. }
  323. if resourceType == knowledge.KnowledgeResourceTypeEvent || resourceType == knowledge.KnowledgeResourceTypePolicy {
  324. tmpIndexDataList, tmpFailDataList, err, errMsg = getDataByTemplateEvent(sheet, sysUser.AdminId, resourceType)
  325. } else {
  326. tmpIndexDataList, tmpFailDataList, err, errMsg = getDataByTemplatePoint(sheet, sysUser.AdminId, resourceType)
  327. }
  328. if err != nil {
  329. return
  330. }
  331. fmt.Println("tmpIndexDataList: ", tmpIndexDataList)
  332. for _, v := range tmpFailDataList {
  333. fmt.Println("tmpFailDataList: ", v)
  334. }
  335. indexDataList = append(indexDataList, tmpIndexDataList...)
  336. failDataList = append(failDataList, tmpFailDataList...)
  337. }
  338. if len(indexDataList) <= 0 {
  339. if len(failDataList) > 0 {
  340. errMsg = failDataList[0].Remark
  341. err = errors.New(errMsg)
  342. }
  343. return
  344. }
  345. // 遍历获取所有分类
  346. classifyNames := make([]string, 0)
  347. for _, v := range indexDataList {
  348. if v.ClassifyFirstName != "" {
  349. classifyNames = append(classifyNames, v.ClassifyFirstName)
  350. }
  351. if v.ClassifySecondName != "" {
  352. classifyNames = append(classifyNames, v.ClassifySecondName)
  353. }
  354. if v.ClassifyThirdName != "" {
  355. classifyNames = append(classifyNames, v.ClassifyThirdName)
  356. }
  357. }
  358. fmt.Println(classifyNames)
  359. classifyList, err := knowledge.GetFullClassifyListByName(classifyNames, resourceType)
  360. if err != nil {
  361. err = fmt.Errorf("获取分类数据失败 Err: %s", err.Error())
  362. errMsg = "获取分类数据失败"
  363. return
  364. }
  365. classifyObj := new(knowledge.KnowledgeClassify)
  366. classifyAllList, err := classifyObj.GetAllClassify(resourceType)
  367. if err != nil {
  368. err = fmt.Errorf("获取分类数据失败 Err: %s", err.Error())
  369. errMsg = "获取分类数据失败"
  370. return
  371. }
  372. classifyNameMap := make(map[string]int)
  373. classifyHasChildMap := make(map[int]bool)
  374. for _, v := range classifyAllList {
  375. if v.ParentId > 0 {
  376. classifyHasChildMap[v.ParentId] = true
  377. }
  378. }
  379. for _, v := range classifyList {
  380. name := fmt.Sprintf("%s/%s/%s", v.RootName, v.ParentName, v.ClassifyName)
  381. fmt.Println("name", name)
  382. if v.RootName == "" && v.ParentName == "" { //一级分类
  383. name = fmt.Sprintf("%s/%s/%s", v.ClassifyName, "", "")
  384. if _, ok := classifyHasChildMap[v.ClassifyId]; ok {
  385. continue
  386. }
  387. } else if v.RootName == "" { //二级分类
  388. name = fmt.Sprintf("%s/%s/%s", v.ParentName, v.ClassifyName, "")
  389. if _, ok := classifyHasChildMap[v.ClassifyId]; ok {
  390. continue
  391. }
  392. }
  393. classifyNameMap[name] = v.ClassifyId
  394. }
  395. tagNameMap := make(map[string]int)
  396. tagList, err := tagObj.GetAllTag(resourceType)
  397. for _, v := range tagList {
  398. tagNameMap[v.TagName] = v.TagId
  399. }
  400. for _, v := range indexDataList {
  401. errTip := ""
  402. classifyId := 0
  403. if successCount > 100 {
  404. errTip = "导入数量超过100条"
  405. } else if v.Title == "" {
  406. errTip = "标题未填"
  407. } else if len(v.Title) > 600 {
  408. errTip = "标题过长"
  409. } else if v.Content == "" {
  410. errTip = "正文未填"
  411. } else if v.SourceFrom == "" {
  412. errTip = "来源未填"
  413. } else if v.ClassifyFirstName == "" {
  414. errTip = "分类未填"
  415. } else if v.StartDate == "" || v.StartTime == "" {
  416. if resourceType == knowledge.KnowledgeResourceTypeEvent || resourceType == knowledge.KnowledgeResourceTypePolicy {
  417. errTip = "开始时间未填"
  418. } else if v.StartDate == "" {
  419. errTip = "时间未填"
  420. }
  421. }
  422. if errTip == "" {
  423. // 判断分类是否存在
  424. classifyName := fmt.Sprintf("%s/%s/%s", v.ClassifyFirstName, v.ClassifySecondName, v.ClassifyThirdName)
  425. fmt.Println("classifyName: ", classifyName)
  426. classifyIdTmp, ok := classifyNameMap[classifyName]
  427. if !ok {
  428. errTip = "分类不存在"
  429. }
  430. classifyId = classifyIdTmp
  431. }
  432. if errTip != "" {
  433. failItem := &knowledge.KnowledgeImportFail{
  434. Title: v.Title,
  435. Content: v.Content,
  436. SourceFrom: v.SourceFrom,
  437. ClassifyFirst: v.ClassifyFirstName,
  438. ClassifySecond: v.ClassifySecondName,
  439. ClassifyThird: v.ClassifyThirdName,
  440. ResourceType: resourceType,
  441. StartDate: v.StartDate,
  442. EndDate: v.EndDate,
  443. StartTime: v.StartTime,
  444. EndTime: v.EndTime,
  445. Remark: errTip,
  446. SysUserId: fmt.Sprint(sysUser.AdminId),
  447. CreateTime: time.Now(),
  448. }
  449. failDataList = append(failDataList, failItem)
  450. continue
  451. }
  452. tagId, _ := tagNameMap[v.Tag]
  453. req := new(knowledge.AddReq)
  454. req.Title = v.Title
  455. req.Content = v.Content
  456. req.SourceFrom = v.SourceFrom
  457. req.ClassifyId = classifyId
  458. req.TagId = tagId
  459. req.ResourceType = resourceType
  460. if v.StartDate != "" {
  461. if resourceType == knowledge.KnowledgeResourceTypeEvent || resourceType == knowledge.KnowledgeResourceTypePolicy {
  462. req.StartTime = fmt.Sprintf("%s %s", v.StartDate, v.StartTime)
  463. } else {
  464. req.StartTime = v.StartDate
  465. }
  466. }
  467. if v.EndDate != "" {
  468. if resourceType == knowledge.KnowledgeResourceTypeEvent || resourceType == knowledge.KnowledgeResourceTypePolicy {
  469. req.EndTime = fmt.Sprintf("%s %s", v.EndDate, v.EndTime)
  470. }
  471. }
  472. tmpErr, msg := addExcelResource(req, sysUser)
  473. if tmpErr != nil {
  474. failItem := &knowledge.KnowledgeImportFail{
  475. Title: v.Title,
  476. Content: v.Content,
  477. SourceFrom: v.SourceFrom,
  478. ClassifyFirst: v.ClassifyFirstName,
  479. ClassifySecond: v.ClassifySecondName,
  480. ClassifyThird: v.ClassifyThirdName,
  481. ResourceType: resourceType,
  482. StartDate: v.StartDate,
  483. EndDate: v.EndDate,
  484. StartTime: v.StartTime,
  485. EndTime: v.EndTime,
  486. Remark: "新增事件失败:" + msg,
  487. SysUserId: fmt.Sprint(sysUser.AdminId),
  488. CreateTime: time.Now(),
  489. }
  490. failDataList = append(failDataList, failItem)
  491. continue
  492. } else {
  493. successCount++
  494. }
  495. }
  496. // 失败数量
  497. failCount = len(failDataList)
  498. //fmt.Println("failDataList:", len(failDataList))
  499. if failCount > 0 {
  500. failObj := new(knowledge.KnowledgeImportFail)
  501. //先删除导入失败记录
  502. _ = failObj.Delete(sysUser.AdminId, resourceType)
  503. // 批量添加导入失败记录
  504. err = failObj.MultiAdd(failDataList)
  505. if err != nil {
  506. go alarm_msg.SendAlarmMsg("导入数据 新增失败记录失败,Err:"+err.Error(), 3)
  507. }
  508. {
  509. //错误信息字符串切片,最后作为发送邮件通知使用
  510. failContents := make([]string, 0)
  511. for _, v := range failDataList {
  512. failContents = append(failContents, fmt.Sprint(v.Title, "导入失败:", v.Remark))
  513. }
  514. utils.FileLog.Info("导入数据 存在部分数据导入失败:" + strings.Join(failContents, ";"))
  515. //导入失败的话,最后统一邮件提醒就好啦,不需要每次都去提醒
  516. go alarm_msg.SendAlarmMsg("导入数据 存在部分数据导入失败:"+strings.Join(failContents, ";"), 3)
  517. }
  518. }
  519. return
  520. }
  521. // getDataByTemplateEvent
  522. func getDataByTemplateEvent(sheet *xlsx.Sheet, sysUserId, resourceType int) (indexDataList []knowledge.ResourceImportData, failDataList []*knowledge.KnowledgeImportFail, err error, errMsg string) {
  523. fmt.Println("sheet name: ", sheet.Name)
  524. indexDataList = make([]knowledge.ResourceImportData, 0)
  525. failDataList = make([]*knowledge.KnowledgeImportFail, 0)
  526. //遍历行读取
  527. maxRow := sheet.MaxRow
  528. fmt.Println("maxRow:", maxRow)
  529. // 表头信息
  530. if maxRow <= 3 {
  531. errMsg = "模板异常1"
  532. err = errors.New(errMsg)
  533. return
  534. }
  535. // 表头校验
  536. {
  537. headerRow := sheet.Row(1)
  538. cells := headerRow.Cells
  539. fmt.Println("cells:", len(cells))
  540. if len(cells) < 11 {
  541. errMsg = "导入文件异常,请下载最新导入模板文件"
  542. err = errors.New(errMsg)
  543. return
  544. }
  545. // 循环打印每个单元格
  546. for k, v := range cells {
  547. fmt.Println("第", k, "个单元格", v.Value)
  548. }
  549. templateFail := false
  550. if cells[0].Value != "开始时间" {
  551. templateFail = true
  552. }
  553. if cells[2].Value != "结束时间(非必填)" {
  554. templateFail = true
  555. }
  556. if cells[4].Value != "标题" {
  557. templateFail = true
  558. }
  559. if cells[5].Value != "正文" {
  560. templateFail = true
  561. }
  562. if cells[6].Value != "来源" {
  563. templateFail = true
  564. }
  565. if cells[7].Value != "一级分类" {
  566. templateFail = true
  567. }
  568. if cells[8].Value != "二级分类" {
  569. templateFail = true
  570. }
  571. if cells[9].Value != "三级分类" {
  572. templateFail = true
  573. }
  574. if cells[10].Value != "标签" {
  575. templateFail = true
  576. }
  577. headerRow2 := sheet.Row(2)
  578. cells2 := headerRow2.Cells
  579. for k, v := range cells2 {
  580. fmt.Println("2第", k, "个单元格", v.Value)
  581. }
  582. if len(cells2) < 11 {
  583. templateFail = true
  584. } else {
  585. if cells2[0].Value != "日期" {
  586. templateFail = true
  587. }
  588. if cells2[1].Value != "时间" {
  589. templateFail = true
  590. }
  591. if cells2[2].Value != "日期" {
  592. templateFail = true
  593. }
  594. if cells2[3].Value != "时间" {
  595. templateFail = true
  596. }
  597. }
  598. if templateFail {
  599. fmt.Println("头部信息校验失败")
  600. errMsg = "导入文件异常,请下载最新导入模板文件"
  601. err = errors.New(errMsg)
  602. return
  603. }
  604. }
  605. for i := 3; i < maxRow; i++ {
  606. row := sheet.Row(i)
  607. cells := row.Cells
  608. lenCell := len(cells)
  609. // 过滤空白行
  610. if lenCell <= 0 {
  611. continue
  612. }
  613. var startDateO, endDateO, startTimeO, endTimeO string
  614. var startDate, startTime, endDate, endTime string
  615. var title, content, sourceFrom, classifyName1, classifyName2, classifyName3, tag string
  616. for k, v := range cells {
  617. fmt.Println("数据第行", i, "第", k, "个单元格", v.Value)
  618. if k == 0 {
  619. startDate = strings.TrimSpace(cells[0].Value) //开始时间
  620. startDateO = startDate
  621. } else if k == 1 {
  622. startTime = strings.TrimSpace(cells[1].Value) //开始时间
  623. startTimeO = startTime
  624. } else if k == 2 {
  625. endDate = strings.TrimSpace(cells[2].Value) //结束时间
  626. endDateO = endDate
  627. } else if k == 3 {
  628. endTime = strings.TrimSpace(cells[3].Value) //结束时间
  629. endTimeO = endTime
  630. } else if k == 4 {
  631. title = strings.TrimSpace(cells[4].Value) //标题
  632. } else if k == 5 {
  633. content = strings.TrimSpace(cells[5].Value) //正文
  634. } else if k == 6 {
  635. sourceFrom = strings.TrimSpace(cells[6].Value) //来源
  636. } else if k == 7 {
  637. classifyName1 = strings.TrimSpace(cells[7].Value) //一级分类
  638. } else if k == 8 {
  639. classifyName2 = strings.TrimSpace(cells[8].Value) //二级分类
  640. } else if k == 9 {
  641. classifyName3 = strings.TrimSpace(cells[9].Value) //三级分类
  642. } else if k == 10 {
  643. tag = strings.TrimSpace(cells[10].Value) //标签
  644. }
  645. }
  646. if title == "" && startDate == "" && startTime == "" && endTime == "" && endDate == "" && content == "" && tag == "" && sourceFrom == "" && classifyName1 == "" && classifyName2 == "" && classifyName3 == "" { //过滤空白行
  647. continue
  648. }
  649. fmt.Println("lenCell:", lenCell)
  650. // 校验日期格式
  651. var startDateVal, endDateVal, startTimeVal float64
  652. var tmpErr error
  653. if startDate != "" {
  654. // 判断9:09:14日期格式是否正确
  655. // 判断是否是数字
  656. startDateVal, tmpErr = strconv.ParseFloat(startDate, 64)
  657. if tmpErr == nil {
  658. startDate = xlsx.TimeFromExcelTime(startDateVal, false).Format(utils.FormatDate)
  659. fmt.Println(startDate)
  660. } else {
  661. startDate, tmpErr = getExcelDate(startDate)
  662. if tmpErr != nil {
  663. failDataList = append(failDataList, &knowledge.KnowledgeImportFail{
  664. //Id: 0,
  665. Title: title,
  666. Content: content,
  667. SourceFrom: sourceFrom,
  668. ClassifyFirst: classifyName1,
  669. ClassifySecond: classifyName2,
  670. ClassifyThird: classifyName3,
  671. ResourceType: resourceType,
  672. StartDate: startDateO,
  673. EndDate: endDateO,
  674. StartTime: startTimeO,
  675. EndTime: endTimeO,
  676. Remark: "日期格式异常",
  677. SysUserId: strconv.Itoa(sysUserId),
  678. CreateTime: time.Now(),
  679. })
  680. continue
  681. }
  682. }
  683. if startTime != "" {
  684. // 判断9:09:14日期格式是否正确
  685. startTimeVal, tmpErr = strconv.ParseFloat(startTime, 64)
  686. if tmpErr == nil {
  687. startTimeVal = startDateVal + startTimeVal
  688. startTime = xlsx.TimeFromExcelTime(startTimeVal, false).Format(utils.FormatTime)
  689. fmt.Println(startTime)
  690. } else {
  691. _, tmpErr = time.Parse(utils.FormatDateTime, startDate+" "+startTime)
  692. if tmpErr != nil {
  693. failDataList = append(failDataList, &knowledge.KnowledgeImportFail{
  694. //Id: 0,
  695. Title: title,
  696. Content: content,
  697. SourceFrom: sourceFrom,
  698. ClassifyFirst: classifyName1,
  699. ClassifySecond: classifyName2,
  700. ClassifyThird: classifyName3,
  701. ResourceType: resourceType,
  702. StartDate: startDateO,
  703. EndDate: endDateO,
  704. StartTime: startTimeO,
  705. EndTime: endTimeO,
  706. Remark: "日期格式异常",
  707. SysUserId: strconv.Itoa(sysUserId),
  708. CreateTime: time.Now(),
  709. })
  710. continue
  711. }
  712. }
  713. }
  714. }
  715. if endDate != "" {
  716. endDateVal, tmpErr = strconv.ParseFloat(endDate, 64)
  717. if tmpErr == nil {
  718. endDate = xlsx.TimeFromExcelTime(endDateVal, false).Format(utils.FormatDate)
  719. fmt.Println(endDate)
  720. } else {
  721. endDate, tmpErr = getExcelDate(endDate)
  722. if tmpErr != nil {
  723. failDataList = append(failDataList, &knowledge.KnowledgeImportFail{
  724. //Id: 0,
  725. Title: title,
  726. Content: content,
  727. SourceFrom: sourceFrom,
  728. ClassifyFirst: classifyName1,
  729. ClassifySecond: classifyName2,
  730. ClassifyThird: classifyName3,
  731. ResourceType: resourceType,
  732. StartDate: startDateO,
  733. EndDate: endDateO,
  734. StartTime: startTimeO,
  735. EndTime: endTimeO,
  736. Remark: "日期格式异常",
  737. SysUserId: strconv.Itoa(sysUserId),
  738. CreateTime: time.Now(),
  739. })
  740. continue
  741. }
  742. }
  743. if endTime != "" {
  744. // 判断9:09:14日期格式是否正确
  745. endTimeVal, e := strconv.ParseFloat(endTime, 64)
  746. if e == nil {
  747. endTimeVal = endDateVal + endTimeVal
  748. endTime = xlsx.TimeFromExcelTime(endTimeVal, false).Format(utils.FormatTime)
  749. fmt.Println(endTime)
  750. } else {
  751. _, e = time.Parse(utils.FormatDateTime, endDate+" "+endTime)
  752. if e != nil {
  753. failDataList = append(failDataList, &knowledge.KnowledgeImportFail{
  754. //Id: 0,
  755. Title: title,
  756. Content: content,
  757. SourceFrom: sourceFrom,
  758. ClassifyFirst: classifyName1,
  759. ClassifySecond: classifyName2,
  760. ClassifyThird: classifyName3,
  761. ResourceType: resourceType,
  762. StartDate: startDate,
  763. EndDate: endDate,
  764. StartTime: startTimeO,
  765. EndTime: endTimeO,
  766. Remark: "日期格式异常",
  767. SysUserId: strconv.Itoa(sysUserId),
  768. CreateTime: time.Now(),
  769. })
  770. continue
  771. }
  772. }
  773. }
  774. }
  775. resourceItem := knowledge.ResourceImportData{
  776. Title: title,
  777. StartDate: startDate,
  778. EndDate: endDate,
  779. StartTime: startTime,
  780. EndTime: endTime,
  781. Content: content,
  782. Tag: tag,
  783. SourceFrom: sourceFrom,
  784. ClassifyFirstName: classifyName1,
  785. ClassifySecondName: classifyName2,
  786. ClassifyThirdName: classifyName3,
  787. }
  788. indexDataList = append(indexDataList, resourceItem)
  789. }
  790. return
  791. }
  792. // getDataByTemplatePoint
  793. func getDataByTemplatePoint(sheet *xlsx.Sheet, sysUserId, resourceType int) (indexDataList []knowledge.ResourceImportData, failDataList []*knowledge.KnowledgeImportFail, err error, errMsg string) {
  794. fmt.Println("sheet name: ", sheet.Name)
  795. indexDataList = make([]knowledge.ResourceImportData, 0)
  796. failDataList = make([]*knowledge.KnowledgeImportFail, 0)
  797. //遍历行读取
  798. maxRow := sheet.MaxRow
  799. fmt.Println("maxRow:", maxRow)
  800. // 表头信息
  801. if maxRow <= 3 {
  802. errMsg = "模板异常1"
  803. err = errors.New(errMsg)
  804. return
  805. }
  806. // 表头校验
  807. {
  808. headerRow := sheet.Row(1)
  809. cells := headerRow.Cells
  810. fmt.Println("cells:", len(cells))
  811. if len(cells) < 5 {
  812. errMsg = "导入文件异常,请下载最新导入模板文件"
  813. err = errors.New(errMsg)
  814. return
  815. }
  816. // 循环打印每个单元格
  817. for k, v := range cells {
  818. fmt.Println("第", k, "个单元格", v.Value)
  819. }
  820. templateFail := false
  821. if cells[0].Value != "时间" {
  822. templateFail = true
  823. }
  824. if cells[1].Value != "标题" {
  825. templateFail = true
  826. }
  827. if cells[2].Value != "正文" {
  828. templateFail = true
  829. }
  830. if cells[3].Value != "来源" {
  831. templateFail = true
  832. }
  833. if cells[4].Value != "一级分类" {
  834. templateFail = true
  835. }
  836. if cells[5].Value != "二级分类" {
  837. templateFail = true
  838. }
  839. if cells[6].Value != "三级分类" {
  840. templateFail = true
  841. }
  842. if cells[7].Value != "标签" {
  843. templateFail = true
  844. }
  845. if templateFail {
  846. fmt.Println("头部信息校验失败")
  847. errMsg = "导入文件异常,请下载最新导入模板文件"
  848. err = errors.New(errMsg)
  849. return
  850. }
  851. }
  852. for i := 2; i < maxRow; i++ {
  853. row := sheet.Row(i)
  854. cells := row.Cells
  855. lenCell := len(cells)
  856. // 过滤空白行
  857. if lenCell <= 0 {
  858. continue
  859. }
  860. var startDateO string
  861. var startDate string
  862. var title, content, sourceFrom, classifyName1, classifyName2, classifyName3, tag string
  863. for k, v := range cells {
  864. fmt.Println("数据第行", i, "第", k, "个单元格", v.Value)
  865. if k == 0 {
  866. startDate = strings.TrimSpace(cells[0].Value) //开始时间
  867. startDateO = startDate
  868. } else if k == 1 {
  869. title = strings.TrimSpace(cells[1].Value) //标题
  870. } else if k == 2 {
  871. content = strings.TrimSpace(cells[2].Value) //正文
  872. } else if k == 3 {
  873. sourceFrom = strings.TrimSpace(cells[3].Value) //来源
  874. } else if k == 4 {
  875. classifyName1 = strings.TrimSpace(cells[4].Value) //一级分类
  876. } else if k == 5 {
  877. classifyName2 = strings.TrimSpace(cells[5].Value) //二级分类
  878. } else if k == 6 {
  879. classifyName3 = strings.TrimSpace(cells[6].Value) //三级分类
  880. } else if k == 7 {
  881. tag = strings.TrimSpace(cells[7].Value) //标签
  882. }
  883. }
  884. if title == "" && startDate == "" && content == "" && tag == "" && sourceFrom == "" && classifyName1 == "" && classifyName2 == "" && classifyName3 == "" { //过滤空白行
  885. continue
  886. }
  887. // 校验日期格式
  888. if startDate != "" {
  889. // 判断9:09:14日期格式是否正确
  890. // 判断是否是数字
  891. startDateVal, tmpErr := strconv.ParseFloat(startDate, 64)
  892. if tmpErr == nil {
  893. startDate = xlsx.TimeFromExcelTime(startDateVal, false).Format(utils.FormatDate)
  894. fmt.Println(startDate)
  895. } else {
  896. startDate, tmpErr = getExcelDate(startDate)
  897. if tmpErr != nil {
  898. failDataList = append(failDataList, &knowledge.KnowledgeImportFail{
  899. //Id: 0,
  900. Title: title,
  901. Content: content,
  902. SourceFrom: sourceFrom,
  903. ClassifyFirst: classifyName1,
  904. ClassifySecond: classifyName2,
  905. ClassifyThird: classifyName3,
  906. ResourceType: resourceType,
  907. StartDate: startDateO,
  908. Remark: "日期格式异常",
  909. SysUserId: strconv.Itoa(sysUserId),
  910. CreateTime: time.Now(),
  911. })
  912. continue
  913. }
  914. }
  915. }
  916. resourceItem := knowledge.ResourceImportData{
  917. Title: title,
  918. StartDate: startDate,
  919. Content: content,
  920. Tag: tag,
  921. SourceFrom: sourceFrom,
  922. ClassifyFirstName: classifyName1,
  923. ClassifySecondName: classifyName2,
  924. ClassifyThirdName: classifyName3,
  925. }
  926. indexDataList = append(indexDataList, resourceItem)
  927. }
  928. return
  929. }
  930. func getExcelDate(createDate string) (newCreateDate string, err error) {
  931. if strings.Contains(createDate, "-") {
  932. //如果是带有 - 的普通日期格式文本
  933. _, err = time.Parse("2006-1-2", createDate)
  934. if err == nil {
  935. newCreateDate = createDate
  936. }
  937. } else if strings.Contains(createDate, "/") {
  938. //如果是带有 / 的普通日期格式文本
  939. createDateTime, timeErr := time.Parse("2006/1/2", createDate)
  940. if timeErr != nil {
  941. err = timeErr
  942. } else {
  943. newCreateDate = createDateTime.Format("2006-01-02")
  944. }
  945. } else {
  946. //可能是excel的日期格式
  947. _, tmpErr := strconv.Atoi(createDate)
  948. if tmpErr != nil {
  949. err = tmpErr
  950. } else {
  951. newCreateDate = utils.ConvertToFormatDay(createDate) //录入日期
  952. }
  953. }
  954. return
  955. }
  956. func addExcelResource(req *knowledge.AddReq, sysUser *system.Admin) (err error, errMsg string) {
  957. var startTime time.Time
  958. var endTime time.Time
  959. if req.StartTime != "" {
  960. if req.ResourceType == knowledge.KnowledgeResourceTypeEvent || req.ResourceType == knowledge.KnowledgeResourceTypePolicy {
  961. startTime, err = time.ParseInLocation(utils.FormatDateTime, req.StartTime, time.Local)
  962. if err != nil { // 如果时间格式不正确,则返回错误信息
  963. errMsg = "开始时间格式不正确"
  964. err = fmt.Errorf("开始时间格式不正确,Err:" + err.Error())
  965. return
  966. }
  967. } else {
  968. startTime, err = time.ParseInLocation(utils.FormatDate, req.StartTime, time.Local)
  969. if err != nil { // 如果时间格式不正确,则返回错误信息
  970. errMsg = "开始时间格式不正确"
  971. err = fmt.Errorf("开始时间格式不正确,Err:" + err.Error())
  972. return
  973. }
  974. }
  975. }
  976. if req.EndTime != "" {
  977. if req.ResourceType == knowledge.KnowledgeResourceTypeEvent || req.ResourceType == knowledge.KnowledgeResourceTypePolicy {
  978. endTime, err = time.ParseInLocation(utils.FormatDateTime, req.EndTime, time.Local)
  979. if err != nil { // 如果时间格式不正确,则返回错误信息
  980. errMsg = "结束时间格式不正确"
  981. err = fmt.Errorf("结束时间格式不正确,Err:" + err.Error())
  982. return
  983. }
  984. }
  985. }
  986. item := new(knowledge.KnowledgeResource)
  987. item.ClassifyId = req.ClassifyId
  988. item.TagId = req.TagId
  989. item.SourceFrom = req.SourceFrom
  990. item.ResourceType = req.ResourceType
  991. item.Title = req.Title
  992. item.State = 1
  993. item.Content = html.EscapeString(req.Content)
  994. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  995. item.ResourceCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
  996. //todo 内容前5行
  997. //item.ContentSub = html.EscapeString(contentSub)
  998. if !startTime.IsZero() {
  999. item.StartTime = &startTime
  1000. }
  1001. if !endTime.IsZero() {
  1002. item.EndTime = &endTime
  1003. }
  1004. item.ModifyTime = time.Now()
  1005. item.AdminId = sysUser.AdminId
  1006. item.AdminRealName = sysUser.RealName
  1007. //item.LastModifyAdminId = sysUser.AdminId
  1008. //item.LastModifyAdminName = sysUser.RealName
  1009. item.ModifyTime = time.Now()
  1010. item.CreateTime = time.Now()
  1011. err = item.Add(item)
  1012. if err != nil {
  1013. errMsg = "保存失败"
  1014. err = fmt.Errorf("保存失败,Err:" + err.Error())
  1015. return
  1016. }
  1017. //todo 是否需要保存到es中
  1018. return
  1019. }
  1020. func GetKnowledgeResourceTmpList(dashboardDetailId, adminId int) (resp *knowledge.BiDashboardResourceAddResp, msg string, err error) {
  1021. if dashboardDetailId <= 0 {
  1022. data, er := utils.Rc.RedisBytes(utils.CACHE_KEY_BI_DASHBOARD_PREPARE_RESOURCE + strconv.Itoa(adminId))
  1023. req := new(knowledge.BiDashboardResourceAddReq)
  1024. if er != nil {
  1025. if er == redis.Nil {
  1026. msg = "暂无知识库"
  1027. err = nil
  1028. return
  1029. }
  1030. msg = "获取知识库模板列表失败"
  1031. return
  1032. }
  1033. if err = json.Unmarshal(data, &req); err != nil {
  1034. msg = "获取知识库模板列表失败"
  1035. }
  1036. selectedIds := make([]int, 0)
  1037. for _, item := range req.KnowledgeResourceList {
  1038. selectedIds = append(selectedIds, item.KnowledgeResourceId)
  1039. }
  1040. knowledgeList, er := knowledge.GetKnowledgeResourceByIds(selectedIds)
  1041. if er != nil {
  1042. msg = "获取知识库模板列表失败"
  1043. return
  1044. }
  1045. resp = new(knowledge.BiDashboardResourceAddResp)
  1046. resp.KnowledgeResourceList = toKnowledgeResourceList(knowledgeList)
  1047. } else {
  1048. condition := ` AND bi_dashboard_detail_id = ? `
  1049. pars := []interface{}{dashboardDetailId}
  1050. resourceIds, er := knowledge.GetKnowledgeResourceIdsByCondition(condition, pars)
  1051. if er != nil {
  1052. msg = "获取知识库模板列表失败"
  1053. return
  1054. }
  1055. if len(resourceIds) == 0 {
  1056. msg = "暂无知识库"
  1057. return
  1058. }
  1059. resp = new(knowledge.BiDashboardResourceAddResp)
  1060. knowledgeList, er := knowledge.GetKnowledgeResourceByIds(resourceIds)
  1061. if er != nil {
  1062. msg = "获取知识库模板列表失败"
  1063. return
  1064. }
  1065. resp.BiDashboardDetailId = dashboardDetailId
  1066. resp.KnowledgeResourceList = toKnowledgeResourceList(knowledgeList)
  1067. }
  1068. return
  1069. }
  1070. func GetKnowledgeResourceList(dashboardDetailId int) (resp *knowledge.KnowledgeResourceListResp, msg string, err error) {
  1071. // var startSize int
  1072. // if pageSize <= 0 {
  1073. // pageSize = utils.PageSize20
  1074. // }
  1075. // if currentIndex <= 0 {
  1076. // currentIndex = 1
  1077. // }
  1078. // startSize = utils.StartIndex(currentIndex, pageSize)
  1079. condition := ` AND bi_dashboard_detail_id = ? `
  1080. var pars = []interface{}{dashboardDetailId}
  1081. resourceIds, err := knowledge.GetKnowledgeResourceIdsByCondition(condition, pars)
  1082. if err != nil {
  1083. msg = "获取知识库列表失败"
  1084. return
  1085. }
  1086. if len(resourceIds) == 0 {
  1087. resp = &knowledge.KnowledgeResourceListResp{
  1088. List: make([]*knowledge.KnowledgeResourceList, 0),
  1089. Paging: &paging.PagingItem{},
  1090. }
  1091. return
  1092. }
  1093. knowledgeList, err := knowledge.GetKnowledgeResourceByIds(resourceIds)
  1094. if err != nil {
  1095. msg = "获取知识库列表失败"
  1096. return
  1097. }
  1098. resp = new(knowledge.KnowledgeResourceListResp)
  1099. resp.List = toKnowledgeResourceList(knowledgeList)
  1100. return
  1101. }
  1102. func toKnowledgeResourceList(list []*knowledge.KnowledgeResource) (res []*knowledge.KnowledgeResourceList) {
  1103. for _, item := range list {
  1104. resItem := &knowledge.KnowledgeResourceList{
  1105. KnowledgeResourceId: item.KnowledgeResourceId,
  1106. ResourceType: item.ResourceType,
  1107. ClassifyId: item.ClassifyId,
  1108. Title: item.Title,
  1109. State: item.State,
  1110. ResourceCode: item.ResourceCode,
  1111. AdminId: item.AdminId,
  1112. AdminRealName: item.AdminRealName,
  1113. SourceFrom: item.SourceFrom,
  1114. TagId: item.TagId,
  1115. CreateTime: utils.TimeTransferString(utils.FormatDateTime, item.CreateTime),
  1116. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, item.ModifyTime),
  1117. }
  1118. if item.StartTime != nil {
  1119. resItem.StartTime = utils.TimeTransferString(utils.FormatDateTime, *item.StartTime)
  1120. }
  1121. if item.EndTime != nil {
  1122. resItem.EndTime = utils.TimeTransferString(utils.FormatDateTime, *item.EndTime)
  1123. }
  1124. res = append(res, resItem)
  1125. }
  1126. return
  1127. }