scene.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "html/template"
  6. "io"
  7. "os"
  8. "sort"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "go-common/app/admin/ep/melloi/conf"
  13. "go-common/app/admin/ep/melloi/model"
  14. "go-common/library/log"
  15. )
  16. // QueryDraft Query Draft
  17. func (s *Service) QueryDraft(scene *model.Scene) (*model.QueryDraft, error) {
  18. return s.dao.QueryDraft(scene)
  19. }
  20. // UpdateScene Update Scene
  21. func (s *Service) UpdateScene(scene *model.Scene) (fusing int, err error) {
  22. scriptIDList := make([]int, len(scene.Scripts))
  23. for index, script := range scene.Scripts {
  24. scriptIDList[index] = script.ID
  25. }
  26. fusing, err = s.dao.UpdateScene(scene, scriptIDList)
  27. return
  28. }
  29. // AddScene Add Scene
  30. func (s *Service) AddScene(scene *model.Scene) (id int, err error) {
  31. id, err = s.dao.AddScene(scene)
  32. return
  33. }
  34. // QueryAPI Query API
  35. func (s *Service) QueryAPI(scene *model.Scene) (*model.QueryAPIs, error) {
  36. return s.dao.QueryAPI(scene)
  37. }
  38. // AddConfig Add Config
  39. func (s *Service) AddConfig(script *model.Script) error {
  40. return s.dao.AddConfig(script)
  41. }
  42. // QueryTree Query Tree
  43. func (s *Service) QueryTree(script *model.Script) (*model.ShowTree, error) {
  44. return s.dao.QueryTree(script)
  45. }
  46. // QueryScenesByPage Query Scene By Page
  47. func (s *Service) QueryScenesByPage(c context.Context, sessionID string, qsrq *model.QuerySceneRequest) (rsp *model.QuerySceneResponse, err error) {
  48. // 获取服务树节点
  49. var (
  50. treeNodes []string
  51. treeNodesd []string
  52. )
  53. if treeNodesd, err = s.QueryUserRoleNode(c, sessionID); err != nil {
  54. log.Error("QueryUserRoleNode err (%v):", err)
  55. }
  56. treeNodes = append(treeNodesd, "")
  57. if ExistsInSlice(qsrq.Executor, conf.Conf.Melloi.Executor) {
  58. if rsp, err = s.dao.QueryScenesByPageWhiteName(&qsrq.Scene, qsrq.PageNum, qsrq.PageSize); err != nil {
  59. return
  60. }
  61. } else {
  62. if rsp, err = s.dao.QueryScenesByPage(&qsrq.Scene, qsrq.PageNum, qsrq.PageSize, treeNodes); err != nil {
  63. return
  64. }
  65. }
  66. return
  67. }
  68. //AddAndExecuScene AddSceneAuto add scene auto
  69. func (s *Service) AddAndExecuScene(c context.Context, scene model.Scene, cookie string) (resp model.DoPtestResp, err error) {
  70. var (
  71. buff *template.Template
  72. file *os.File
  73. scrThreadGroup model.ScrThreadGroup
  74. fileName string
  75. testNames []string
  76. testNameNicks []string
  77. loadTimes []int
  78. scripts []*model.Script
  79. jmeterLog string
  80. resJtl string
  81. sceneID int
  82. threadGroup string
  83. )
  84. // id 不是0 ,说明是输入接口创建的场景,根据sceneID 查询到接口列表,再根据接口列表生成jmx
  85. // 不是前端 quick-start 页的批量选择,走如下逻辑
  86. if scene.ID != 0 && !scene.IsBatch {
  87. script := model.Script{SceneID: scene.ID}
  88. if scripts, err = s.dao.QueryScripts(&script, 1, 200); err != nil {
  89. log.Error("s.dao.QueryScripts err :(%v)", err)
  90. return
  91. }
  92. scene.Scripts = scripts
  93. }
  94. if scene.IsDebug {
  95. for _, script := range scene.Scripts {
  96. script.ThreadsSum = 1
  97. script.Loops = 5
  98. script.TestName = script.TestName + "_perf_debug"
  99. }
  100. scene.SceneName = scene.SceneName + "_perf_debug"
  101. }
  102. // 非 quick-start 页面的批量选择,走如下逻辑,即 quick-start 页面的批量选择,不生成 scene.jmx 文件
  103. sceneSuffix := strconv.FormatInt(time.Now().Unix(), 10)
  104. if !scene.IsBatch {
  105. scrThreadGroup.Scripts = scene.Scripts
  106. if threadGroup, err = s.GetThreadGroup(scrThreadGroup); err != nil {
  107. log.Error("s.dao.GetThreadGroup (%v)", err)
  108. return
  109. }
  110. scene.ThreadGroup = unescaped(threadGroup)
  111. if buff, err = template.ParseFiles(s.c.Jmeter.JmeterSceneTmp); err != nil {
  112. log.Error("file is not exists (%v)", err)
  113. return
  114. }
  115. scene.ScriptPath = "/data/jmeter-log/" + scene.Department + "/" + scene.Project + "/" + scene.APP + "/" + "scene" + "/" + sceneSuffix + "/"
  116. if err = os.MkdirAll(scene.ScriptPath, 0755); err != nil {
  117. log.Error("Create SavePath Err (%v)", err)
  118. return
  119. }
  120. // 创建脚本文件 脚本路径+场景名+后缀.jmx
  121. if file, err = os.Create(scene.ScriptPath + sceneSuffix + ".jmx"); err != nil {
  122. log.Error("os.Create file err :(%v)", err)
  123. return
  124. }
  125. defer file.Close()
  126. buff = buff.Funcs(template.FuncMap{"unescaped": unescaped})
  127. buff.Execute(io.Writer(file), scene)
  128. fileName = file.Name()
  129. jmeterLog = scene.ScriptPath + "jmg" + sceneSuffix
  130. resJtl = scene.ScriptPath + "jtl" + sceneSuffix
  131. }
  132. scene.JmeterLog = jmeterLog
  133. scene.JmeterFilePath = fileName
  134. scene.ResJtl = resJtl
  135. sceneID = scene.ID
  136. // 批量选择脚本执行场景压测,则走如下逻辑,写 script 表
  137. if scene.ID == 0 || scene.IsBatch {
  138. //前端传入的scene 有 scripts , sceneId 没有传,走如下逻辑,写入scene 表
  139. if !scene.IsBatch {
  140. scene.SceneType = 1
  141. if sceneID, err = s.AddScene(&scene); err != nil {
  142. log.Error("s.AddScene err :(%v)", err)
  143. return
  144. }
  145. scene.ID = sceneID
  146. }
  147. for _, script := range scene.Scripts {
  148. script.IsSave = true
  149. script.SceneID = sceneID
  150. script.ID = 0
  151. script.TestType = model.SCENE_SCRIPT_TYPE
  152. //脚本落库
  153. if resp, err = s.AddAndExcuScript(c, script, "", &scene, false, true); err != nil {
  154. log.Error("s.AddAndExcuScript err :(%v)", err)
  155. return
  156. }
  157. script.ID = resp.ScriptID
  158. scripts = append(scripts, script)
  159. }
  160. scene.Scripts = scripts
  161. }
  162. // 有id,需要更新数据库
  163. if scene.ID != 0 && !scene.IsDebug {
  164. if _, err = s.UpdateScene(&scene); err != nil {
  165. log.Error("s.UpdateScene error :(%v)", err)
  166. return
  167. }
  168. }
  169. //获取 testNames testNameNicks loadTimes
  170. for _, script := range scene.Scripts {
  171. testNames = append(testNames, script.TestName)
  172. testNameNicks = append(testNameNicks, script.TestName+sceneSuffix)
  173. loadTimes = append(loadTimes, script.LoadTime)
  174. }
  175. sort.Ints(loadTimes)
  176. //执行压测
  177. if scene.IsExecute && len(scene.Scripts) > 0 {
  178. ptestParam := model.DoPtestParam{
  179. TestNames: testNames,
  180. SceneName: scene.SceneName,
  181. UserName: scene.UserName,
  182. LoadTime: loadTimes[len(loadTimes)-1],
  183. FileName: fileName,
  184. Upload: false,
  185. ProjectName: scene.SceneName,
  186. JmeterLog: scene.JmeterLog,
  187. ResJtl: scene.ResJtl,
  188. Department: scene.Department,
  189. Project: scene.Project,
  190. APP: scene.APP,
  191. ScriptID: 0,
  192. DockerSum: 1,
  193. TestNameNick: SliceToString(testNameNicks, ","),
  194. TestNameNicks: testNameNicks,
  195. Scripts: scene.Scripts,
  196. SceneID: sceneID,
  197. Type: model.PROTOCOL_SCENE, // 场景
  198. IsDebug: scene.IsDebug,
  199. Cookie: cookie,
  200. Fusing: scene.Fusing,
  201. }
  202. if resp, err = s.DoPtest(c, ptestParam); err != nil {
  203. log.Error("s.DoPtest err :(%v)", err)
  204. return
  205. }
  206. //临时写法
  207. resp.ScriptID = sceneID
  208. }
  209. return
  210. }
  211. // SaveScene Save Scene
  212. func (s *Service) SaveScene(scene *model.Scene) error {
  213. return s.dao.SaveScene(scene)
  214. }
  215. // SaveOrder Save Order
  216. func (s *Service) SaveOrder(req model.SaveOrderReq, scene *model.Scene) error {
  217. var (
  218. flag = 1
  219. length = len(req.GroupOrderList)
  220. index = length - 1
  221. bak int
  222. )
  223. if scene.SceneType == 1 {
  224. for i := 0; i < length; i++ {
  225. bak = req.GroupOrderList[i].GroupID
  226. req.GroupOrderList[i].GroupID = flag
  227. //防止越界
  228. if i == index {
  229. break
  230. }
  231. if bak != req.GroupOrderList[i+1].GroupID {
  232. flag++
  233. }
  234. }
  235. } else {
  236. for i := 0; i < length; i++ {
  237. bak = req.GroupOrderList[i].RunOrder
  238. req.GroupOrderList[i].RunOrder = flag
  239. //防止越界
  240. if i == index {
  241. break
  242. }
  243. if bak != req.GroupOrderList[i+1].RunOrder {
  244. flag++
  245. }
  246. }
  247. }
  248. return s.dao.SaveOrder(req.GroupOrderList, scene)
  249. }
  250. // QueryRelation Query Relation
  251. func (s *Service) QueryRelation(script *model.Script) (*model.QueryRelation, error) {
  252. var (
  253. groupId int
  254. err error
  255. )
  256. if _, groupId, err = s.dao.QueryGroupId(script); err != nil {
  257. log.Error("s.dao.QueryGroupId err :(%v)", err)
  258. return nil, err
  259. }
  260. return s.dao.QueryRelation(groupId, script)
  261. }
  262. // DeleteAPI Delete API
  263. func (s *Service) DeleteAPI(script *model.Script) error {
  264. return s.dao.DeleteAPI(script)
  265. }
  266. // DoScenePtest Do Scene Ptest
  267. func (s *Service) DoScenePtest(c context.Context, ptestScene model.DoPtestSceneParam, addPtest bool, cookie string) (resp model.DoPtestResp, err error) {
  268. var (
  269. scenes []*model.Scene
  270. scripts []*model.Script
  271. )
  272. scene := model.Scene{ID: ptestScene.SceneID}
  273. if scenes, err = s.dao.QueryScenes(&scene, 1, 1); err != nil {
  274. log.Error("s.dao.QueryScenes err :(%v)", err)
  275. return
  276. }
  277. script := model.Script{SceneID: ptestScene.SceneID}
  278. if scripts, err = s.dao.QueryScripts(&script, 1, 300); err != nil {
  279. log.Error("s.dao.QueryScripts err :(%v)", err)
  280. return
  281. }
  282. scenes[0].Scripts = scripts
  283. if len(scenes) > 0 {
  284. sceneInfo := GetSceneInfo(scenes[0])
  285. ptestParam := model.DoPtestParam{
  286. TestNames: sceneInfo.TestNames,
  287. SceneName: sceneInfo.SceneName,
  288. UserName: ptestScene.UserName,
  289. LoadTime: sceneInfo.MaxLoadTime,
  290. FileName: scenes[0].JmeterFilePath,
  291. Upload: false,
  292. ProjectName: sceneInfo.SceneName,
  293. ResJtl: sceneInfo.ResJtl,
  294. JmeterLog: sceneInfo.JmeterLog,
  295. Department: scenes[0].Department,
  296. Project: scenes[0].Project,
  297. APP: scenes[0].APP,
  298. ScriptID: 0,
  299. DockerSum: 1,
  300. TestNameNick: SliceToString(sceneInfo.TestNameNicks, ","),
  301. TestNameNicks: sceneInfo.TestNameNicks,
  302. Scripts: sceneInfo.Scripts,
  303. SceneID: ptestScene.SceneID,
  304. Type: model.PROTOCOL_SCENE, // 场景
  305. AddPtest: addPtest,
  306. Cookie: cookie,
  307. }
  308. return s.DoPtest(c, ptestParam)
  309. }
  310. return
  311. }
  312. //DoScenePtestBatch dosceneptest batch
  313. func (s *Service) DoScenePtestBatch(c context.Context, ptestScenes model.DoPtestSceneParams, cookie string) (err error) {
  314. for _, SceneID := range ptestScenes.SceneIDs {
  315. ptestScene := model.DoPtestSceneParam{SceneID: SceneID, UserName: ptestScenes.UserName}
  316. go s.DoScenePtest(context.TODO(), ptestScene, false, cookie)
  317. }
  318. return
  319. }
  320. //GetSceneInfo get sceneInfo
  321. func GetSceneInfo(scene *model.Scene) (sceneInfo model.SceneInfo) {
  322. var (
  323. loadTimes []int
  324. testNames []string
  325. testNameNicks []string
  326. scripts []*model.Script
  327. )
  328. if scene == nil {
  329. return
  330. }
  331. sceneSuffix := strconv.FormatInt(time.Now().Unix(), 10)
  332. for _, script := range scene.Scripts {
  333. loadTimes = append(loadTimes, script.LoadTime)
  334. testNames = append(testNames, script.TestName)
  335. testNameNicks = append(testNameNicks, script.TestName+sceneSuffix)
  336. scripts = append(scripts, script)
  337. }
  338. sort.Ints(loadTimes)
  339. sceneInfo = model.SceneInfo{
  340. MaxLoadTime: loadTimes[len(loadTimes)-1],
  341. JmeterLog: scene.JmeterLog + sceneSuffix,
  342. ResJtl: scene.ResJtl + sceneSuffix,
  343. LoadTimes: loadTimes,
  344. TestNames: testNames,
  345. TestNameNicks: testNameNicks,
  346. SceneName: scene.SceneName,
  347. Scripts: scripts,
  348. }
  349. return
  350. }
  351. // QueryExistAPI Query Exist API
  352. func (s *Service) QueryExistAPI(c context.Context, sessionID string, req *model.APIInfoRequest) (res *model.APIInfoList, err error) {
  353. // 获取服务树节点
  354. var (
  355. treeNodes []string
  356. treeNodesd []string
  357. )
  358. if treeNodesd, err = s.QueryUserRoleNode(c, sessionID); err != nil {
  359. log.Error("QueryUserRoleNode err (%v):", err)
  360. }
  361. treeNodes = append(treeNodesd, "")
  362. if res, err = s.dao.QueryExistAPI(&req.Script, req.PageNum, req.PageSize, req.SceneID, treeNodes); err != nil {
  363. return
  364. }
  365. for _, script := range res.ScriptList {
  366. if script.APIHeader != "" {
  367. if err = json.Unmarshal([]byte(script.APIHeader), &script.Headers); err != nil {
  368. log.Error("get script header err : (%v),scriptId:(%d)", err, script.ID)
  369. }
  370. }
  371. if script.ArgumentString != "" {
  372. if err = json.Unmarshal([]byte(script.ArgumentString), &script.ArgumentsMap); err != nil {
  373. log.Error("get script argument err: (%v), scriptId:(%d)", err, script.ID)
  374. }
  375. }
  376. if script.OutputParams != "" {
  377. if err = json.Unmarshal([]byte(script.OutputParams), &script.OutputParamsMap); err != nil {
  378. log.Error("get script OutputParams err: (%v),scriptId:(%d)", err, script.ID)
  379. }
  380. }
  381. }
  382. return
  383. }
  384. // QueryPreview Query Preview
  385. func (s *Service) QueryPreview(req *model.Script) (preRes *model.PreviewInfoList, err error) {
  386. var (
  387. list *model.GroupList
  388. preList *model.PreviewList
  389. preResd model.PreviewInfoList
  390. )
  391. if list, err = s.dao.QueryGroup(req.SceneID); err != nil {
  392. return
  393. }
  394. for i := 0; i < len(list.GroupList); i++ {
  395. // 或者使用var preInfo = &model.PreviewInfo{}
  396. preInfo := new(model.PreviewInfo)
  397. groupId := list.GroupList[i].GroupID
  398. threadsSum := list.GroupList[i].ThreadsSum
  399. loadTime := list.GroupList[i].LoadTime
  400. readyTime := list.GroupList[i].ReadyTime
  401. if preList, err = s.dao.QueryPreview(req.SceneID, groupId); err != nil {
  402. return
  403. }
  404. preInfo.GroupID = groupId
  405. preInfo.ThreadsSum = threadsSum
  406. preInfo.LoadTime = loadTime
  407. preInfo.ReadyTime = readyTime
  408. preInfo.InfoList = preList.PreList
  409. preResd.PreviewInfoList = append(preResd.PreviewInfoList, preInfo)
  410. preRes = &preResd
  411. }
  412. return
  413. }
  414. // QueryParams Query Params
  415. func (s *Service) QueryParams(req *model.Script) (res *model.UsefulParamsList, tempRes *model.UsefulParamsList, err error) {
  416. //var paramList []string
  417. var (
  418. uParam *model.UsefulParams
  419. )
  420. res = &model.UsefulParamsList{}
  421. if tempRes, err = s.dao.QueryUsefulParams(req.SceneID); err != nil {
  422. return
  423. }
  424. if len(tempRes.ParamsList) > 0 {
  425. for _, tempParam := range tempRes.ParamsList {
  426. if strings.Contains(tempParam.OutputParams, ",") {
  427. tempParamList := strings.Split(tempParam.OutputParams, ",")
  428. for _, param := range tempParamList {
  429. uParam = &model.UsefulParams{}
  430. uParam.OutputParams = strings.Split(strings.Split(param, "\":\"")[0], "\"")[1]
  431. res.ParamsList = append(res.ParamsList, uParam)
  432. }
  433. } else {
  434. uParam = &model.UsefulParams{}
  435. uParam.OutputParams = strings.Split(strings.Split(tempParam.OutputParams, "\":\"")[0], "\"")[1]
  436. res.ParamsList = append(res.ParamsList, uParam)
  437. }
  438. }
  439. } else {
  440. // 赋值空数组
  441. res.ParamsList = []*model.UsefulParams{}
  442. }
  443. return
  444. }
  445. // UpdateBindScene Update Bind Scene
  446. func (s *Service) UpdateBindScene(bindScene *model.BindScene) (err error) {
  447. return s.dao.UpdateBindScene(bindScene)
  448. }
  449. // QueryDrawRelation Query Draw Relation
  450. func (s *Service) QueryDrawRelation(scene *model.Scene) (res model.DrawRelationList, tempRes *model.SaveOrderReq, err error) {
  451. var (
  452. //relationList model.DrawRelationList
  453. edges []*model.Edge
  454. edge *model.Edge
  455. tempEdge *model.Edge
  456. //nodes []*model.Node
  457. node *model.Node
  458. )
  459. if tempRes, err = s.dao.QueryDrawRelation(scene); err != nil {
  460. return
  461. }
  462. for k := 0; k < len(tempRes.GroupOrderList); k++ {
  463. node = &model.Node{}
  464. node.ID = tempRes.GroupOrderList[k].ID
  465. node.Name = tempRes.GroupOrderList[k].TestName
  466. res.Nodes = append(res.Nodes, node)
  467. }
  468. for i := 0; i < len(tempRes.GroupOrderList)-1; i++ {
  469. edge = &model.Edge{}
  470. tempEdge = &model.Edge{}
  471. if tempRes.GroupOrderList[i].GroupID == tempRes.GroupOrderList[i+1].GroupID && tempRes.GroupOrderList[i].RunOrder == tempRes.GroupOrderList[i+1].RunOrder {
  472. edge.Source = tempRes.GroupOrderList[i].TestName
  473. edges = append(edges, edge)
  474. if len(edges) > 0 {
  475. //edges[i+1].Source =
  476. tempEdge.Source = edges[i-1].Source
  477. tempEdge.Target = tempRes.GroupOrderList[i+1].TestName
  478. edges = append(edges, tempEdge)
  479. }
  480. } else if tempRes.GroupOrderList[i].GroupID == tempRes.GroupOrderList[i+1].GroupID && tempRes.GroupOrderList[i].RunOrder != tempRes.GroupOrderList[i+1].RunOrder {
  481. edge.Source = tempRes.GroupOrderList[i].TestName
  482. edge.Target = tempRes.GroupOrderList[i+1].TestName
  483. edges = append(edges, edge)
  484. } else if tempRes.GroupOrderList[i].GroupID != tempRes.GroupOrderList[i+1].GroupID {
  485. edge.Source = tempRes.GroupOrderList[i].TestName
  486. edges = append(edges, edge)
  487. }
  488. }
  489. for j := 0; j < len(edges); j++ {
  490. if edges[j].Target != "" {
  491. //relationList.Edges = append(relationList.Edges, edges[j])
  492. res.Edges = append(res.Edges, edges[j])
  493. }
  494. }
  495. return
  496. }
  497. // DeleteDraft Delete Draft
  498. func (s *Service) DeleteDraft(scene *model.Scene) error {
  499. return s.dao.DeleteDraft(scene)
  500. }
  501. // QueryConfig Query Config
  502. func (s *Service) QueryConfig(script *model.Script) (*model.GroupInfo, error) {
  503. return s.dao.QueryConfig(script)
  504. }
  505. // DeleteScene Delete Scene
  506. func (s *Service) DeleteScene(scene *model.Scene) error {
  507. return s.dao.DeleteScene(scene)
  508. }
  509. //CopyScene copy scene
  510. func (s *Service) CopyScene(c context.Context, scene *model.Scene, cookie string) (addScene model.AddScene, err error) {
  511. var (
  512. scripts []*model.Script
  513. scenes []*model.Scene
  514. sceneID int
  515. resp model.DoPtestResp
  516. )
  517. script := model.Script{SceneID: scene.ID}
  518. scened := model.Scene{ID: scene.ID}
  519. //先根据 scene.ID 查询 scenes 和 scripts
  520. if scenes, err = s.dao.QueryScenes(&scened, 1, 10); err != nil {
  521. log.Error("s.dao.QueryScenes err :(%v)", err)
  522. return
  523. }
  524. if scripts, err = s.dao.QueryScripts(&script, 1, 200); err != nil {
  525. log.Error("s.dao.QueryScripts err :(%v)", err)
  526. return
  527. }
  528. if len(scenes) != 0 {
  529. scenes[0].ID = 0
  530. scenes[0].UserName = scene.UserName
  531. scenes[0].SceneName = scene.SceneName
  532. //将新的scene 写入 数据库,并返回 sceneID
  533. if sceneID, err = s.dao.AddScene(scenes[0]); err != nil {
  534. log.Error("s.dao.AddScene err :(%v)", err)
  535. return
  536. }
  537. // 将新的 script 写入 script 表
  538. for _, sctd := range scripts {
  539. sctd.SceneID = sceneID
  540. sctd.ID = 0
  541. if _, _, _, err = s.dao.AddScript(sctd); err != nil {
  542. return
  543. }
  544. }
  545. sce := model.Scene{
  546. APP: scenes[0].APP,
  547. Department: scenes[0].Department,
  548. Project: scenes[0].Project,
  549. ID: sceneID,
  550. IsDebug: false,
  551. IsExecute: false,
  552. UserName: scene.UserName,
  553. SceneName: scene.SceneName,
  554. }
  555. if resp, err = s.AddAndExecuScene(c, sce, cookie); err != nil {
  556. log.Error("s.AddAndExecuScene err :(%v), (%v)", err, resp)
  557. return
  558. }
  559. addScene.SceneID = sceneID
  560. addScene.UserName = scene.UserName
  561. }
  562. return
  563. }
  564. // QueryFusing Query Fusing
  565. func (s *Service) QueryFusing(script *model.Script) (res *model.FusingInfoList, err error) {
  566. res, err = s.dao.QueryFusing(script)
  567. for i := 0; i < len(res.FusingList)-1; i++ {
  568. if res.FusingList[i] != res.FusingList[i+1] {
  569. res.SetNull = true
  570. return
  571. }
  572. }
  573. return
  574. }