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