sandbox.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. package sandbox
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hz_eta_api/models"
  7. "hongze/hz_eta_api/models/company"
  8. "hongze/hz_eta_api/models/sandbox"
  9. "hongze/hz_eta_api/models/sandbox/request"
  10. "hongze/hz_eta_api/models/system"
  11. "hongze/hz_eta_api/utils"
  12. "strconv"
  13. "time"
  14. )
  15. // AddSandbox 新增沙盘
  16. func AddSandbox(req request.AddAndEditSandbox, opUserId int, opUserName string) (sandboxInfo *sandbox.Sandbox, err error) {
  17. // 获取产品权限详情
  18. chartPermissionInfo, err := company.GetChartPermissionListById(req.ChartPermissionId)
  19. if err != nil {
  20. return
  21. }
  22. //沙盘主表信息
  23. sandboxInfo = &sandbox.Sandbox{
  24. Name: utils.TrimStr(req.Name),
  25. ChartPermissionId: req.ChartPermissionId,
  26. ChartPermissionName: chartPermissionInfo.PermissionName,
  27. CurrVersion: 1,
  28. Code: GenerateCode(),
  29. Content: req.Content,
  30. PicUrl: utils.TrimStr(req.PicUrl),
  31. OpUserId: opUserId,
  32. OpUserName: opUserName,
  33. IsDelete: 0,
  34. ModifyTime: time.Now(),
  35. CreateTime: time.Now(),
  36. }
  37. //沙盘版本表信息
  38. sandboxVersionInfo := &sandbox.SandboxVersion{
  39. Name: sandboxInfo.Name,
  40. ChartPermissionId: sandboxInfo.ChartPermissionId,
  41. ChartPermissionName: sandboxInfo.ChartPermissionName,
  42. CurrVersion: sandboxInfo.CurrVersion,
  43. Content: sandboxInfo.Content,
  44. PicUrl: sandboxInfo.PicUrl,
  45. OpUserId: sandboxInfo.OpUserId,
  46. OpUserName: sandboxInfo.OpUserName,
  47. VersionCode: GenerateVersionCode(sandboxInfo.SandboxId, sandboxInfo.CurrVersion),
  48. IsDelete: sandboxInfo.IsDelete,
  49. CreateTime: sandboxInfo.CreateTime,
  50. }
  51. //沙盘草稿表信息
  52. sandboxDraftInfo := &sandbox.SandboxDraft{
  53. Name: sandboxInfo.Name,
  54. ChartPermissionId: sandboxInfo.ChartPermissionId,
  55. ChartPermissionName: sandboxInfo.ChartPermissionName,
  56. CurrVersion: sandboxInfo.CurrVersion,
  57. Content: sandboxInfo.Content,
  58. OpUserId: sandboxInfo.OpUserId,
  59. OpUserName: sandboxInfo.OpUserName,
  60. CreateTime: sandboxInfo.CreateTime,
  61. }
  62. //新增沙盘
  63. err = sandbox.AddNewSandbox(sandboxInfo, sandboxVersionInfo, sandboxDraftInfo)
  64. return
  65. }
  66. // UpdateSandbox 更新沙盘
  67. func UpdateSandbox(req request.AddAndEditSandbox, opUserId int, opUserName string) (sandboxInfo *sandbox.Sandbox, err error, errMsg string) {
  68. // 获取沙盘版本信息
  69. sandboxVersion, err := sandbox.GetSandboxVersionBySandboxVersionCode(req.SandboxVersionCode)
  70. if err != nil {
  71. if err.Error() == utils.ErrNoRow() {
  72. errMsg = "找不到该版本"
  73. err = errors.New(errMsg)
  74. }
  75. return
  76. }
  77. // 获取沙盘主表信息
  78. sandboxInfo, err = sandbox.GetSandboxById(sandboxVersion.SandboxId)
  79. if err != nil {
  80. if err.Error() == utils.ErrNoRow() {
  81. errMsg = "找不到该沙盘"
  82. err = errors.New(errMsg)
  83. }
  84. return
  85. }
  86. //沙盘名称是否更改校验
  87. var isUpdateName, isUpdateContent bool
  88. if sandboxInfo.Name != utils.TrimStr(req.Name) {
  89. isUpdateName = true
  90. }
  91. // 沙盘内容md5比对,不一致则代表有做更改
  92. //if utils.MD5(sandboxInfo.Content) != utils.MD5(req.Content) {
  93. // isUpdateContent = true
  94. //}
  95. if checkoutContent(sandboxInfo.Content, req.Content) {
  96. isUpdateContent = true
  97. }
  98. //如果沙盘名称和沙盘内容都没有做过修改,那么就不做保存
  99. if isUpdateName == false && isUpdateContent == false {
  100. return
  101. }
  102. // 获取产品权限详情
  103. chartPermissionInfo, err := company.GetChartPermissionListById(req.ChartPermissionId)
  104. if err != nil {
  105. return
  106. }
  107. //如果只更新了沙盘名称,那么只去修改最新版本的沙盘名称,而不去累计版本
  108. if isUpdateName == true && isUpdateContent == false {
  109. sandboxInfo.Name = utils.TrimStr(req.Name)
  110. sandboxInfo.ChartPermissionId = req.ChartPermissionId
  111. sandboxInfo.ChartPermissionName = chartPermissionInfo.PermissionName
  112. sandboxInfo.Content = req.Content
  113. sandboxInfo.PicUrl = utils.TrimStr(req.PicUrl)
  114. sandboxInfo.OpUserId = opUserId
  115. sandboxInfo.OpUserName = opUserName
  116. sandboxInfo.ModifyTime = time.Now()
  117. var updateSandboxColumn = []string{"Name", "ChartPermissionId", "ChartPermissionName", "PicUrl", "OpUserId", "OpUserName", "ModifyTime"}
  118. //沙盘版本表信息
  119. sandboxVersionInfo, tmpErr := sandbox.GetSandboxVersionBySandbox2VersionId(sandboxInfo.SandboxId, sandboxInfo.CurrVersion)
  120. if tmpErr != nil {
  121. err = tmpErr
  122. return
  123. }
  124. sandboxVersionInfo.Name = sandboxInfo.Name
  125. sandboxVersionInfo.ChartPermissionId = sandboxInfo.ChartPermissionId
  126. sandboxVersionInfo.ChartPermissionName = sandboxInfo.ChartPermissionName
  127. sandboxVersionInfo.PicUrl = sandboxInfo.PicUrl
  128. sandboxVersionInfo.OpUserId = sandboxInfo.OpUserId
  129. sandboxVersionInfo.OpUserName = sandboxInfo.OpUserName
  130. var updateSandboxVersionColumn = []string{"Name", "ChartPermissionId", "ChartPermissionName", "PicUrl", "OpUserId", "OpUserName"}
  131. //沙盘草稿表信息
  132. sandboxDraftInfo := &sandbox.SandboxDraft{
  133. Name: sandboxInfo.Name,
  134. ChartPermissionId: sandboxInfo.ChartPermissionId,
  135. ChartPermissionName: sandboxInfo.ChartPermissionName,
  136. CurrVersion: sandboxInfo.CurrVersion,
  137. Content: sandboxInfo.Content,
  138. OpUserId: sandboxInfo.OpUserId,
  139. OpUserName: sandboxInfo.OpUserName,
  140. CreateTime: time.Now(),
  141. }
  142. //修改沙盘
  143. err = sandbox.UpdateSandboxName(sandboxInfo, sandboxVersionInfo, sandboxDraftInfo, updateSandboxColumn, updateSandboxVersionColumn)
  144. } else {
  145. sandboxInfo.Name = utils.TrimStr(req.Name)
  146. sandboxInfo.ChartPermissionId = req.ChartPermissionId
  147. sandboxInfo.ChartPermissionName = chartPermissionInfo.PermissionName
  148. sandboxInfo.CurrVersion = sandboxInfo.CurrVersion + 1
  149. sandboxInfo.Content = req.Content
  150. sandboxInfo.PicUrl = utils.TrimStr(req.PicUrl)
  151. sandboxInfo.OpUserId = opUserId
  152. sandboxInfo.OpUserName = opUserName
  153. sandboxInfo.ModifyTime = time.Now()
  154. var updateSandbox = []string{"Name", "ChartPermissionId", "ChartPermissionName", "CurrVersion", "Content", "PicUrl", "OpUserId", "OpUserName", "ModifyTime"}
  155. //沙盘版本表信息
  156. sandboxVersionInfo := &sandbox.SandboxVersion{
  157. Name: sandboxInfo.Name,
  158. ChartPermissionId: sandboxInfo.ChartPermissionId,
  159. ChartPermissionName: sandboxInfo.ChartPermissionName,
  160. CurrVersion: sandboxInfo.CurrVersion,
  161. Content: sandboxInfo.Content,
  162. SvgData: req.SvgData,
  163. PicUrl: sandboxInfo.PicUrl,
  164. OpUserId: sandboxInfo.OpUserId,
  165. OpUserName: sandboxInfo.OpUserName,
  166. VersionCode: GenerateVersionCode(sandboxInfo.SandboxId, sandboxInfo.CurrVersion),
  167. IsDelete: sandboxInfo.IsDelete,
  168. CreateTime: time.Now(),
  169. }
  170. //沙盘草稿表信息
  171. sandboxDraftInfo := &sandbox.SandboxDraft{
  172. Name: sandboxInfo.Name,
  173. ChartPermissionId: sandboxInfo.ChartPermissionId,
  174. ChartPermissionName: sandboxInfo.ChartPermissionName,
  175. CurrVersion: sandboxInfo.CurrVersion,
  176. Content: sandboxInfo.Content,
  177. OpUserId: sandboxInfo.OpUserId,
  178. OpUserName: sandboxInfo.OpUserName,
  179. CreateTime: time.Now(),
  180. }
  181. //修改沙盘
  182. err = sandbox.UpdateSandbox(sandboxInfo, updateSandbox, sandboxVersionInfo, sandboxDraftInfo)
  183. }
  184. return
  185. }
  186. // AddSandboxDraft 新增沙盘草稿
  187. func AddSandboxDraft(sandboxId int, req request.AddAndEditSandbox, opUserId int, opUserName string) (sandboxDraftInfo *sandbox.SandboxDraft, err error) {
  188. //获取最近一条草稿箱的数据
  189. lastSandboxDraft, err := sandbox.GetLastSandboxDraftById(sandboxId)
  190. if err != nil && err.Error() != utils.ErrNoRow() {
  191. return
  192. }
  193. //如果最近一条沙盘草稿数据不为空的话,那么需要校验下最近一次的图表数据是否与提交的这次一致
  194. if lastSandboxDraft != nil {
  195. //沙盘名称是否更改校验
  196. var isUpdateName, isUpdateContent bool
  197. if lastSandboxDraft.Name != utils.TrimStr(req.Name) {
  198. isUpdateName = true
  199. }
  200. // 沙盘内容md5比对,不一致则代表有做更改
  201. //if utils.MD5(lastSandboxDraft.Content) != utils.MD5(req.Content) {
  202. // isUpdateContent = true
  203. //}
  204. if checkoutContent(lastSandboxDraft.Content, req.Content) {
  205. isUpdateContent = true
  206. }
  207. //如果沙盘名称和沙盘内容都没有做过修改,那么就不做保存
  208. if isUpdateName == false && isUpdateContent == false {
  209. return
  210. }
  211. }
  212. // 获取产品权限详情
  213. chartPermissionInfo, err := company.GetChartPermissionListById(req.ChartPermissionId)
  214. if err != nil {
  215. return
  216. }
  217. //沙盘草稿表信息
  218. sandboxDraftInfo = &sandbox.SandboxDraft{
  219. SandboxId: sandboxId,
  220. Name: utils.TrimStr(req.Name),
  221. ChartPermissionId: req.ChartPermissionId,
  222. ChartPermissionName: chartPermissionInfo.PermissionName,
  223. Content: req.Content,
  224. OpUserId: opUserId,
  225. OpUserName: opUserName,
  226. CreateTime: time.Now(),
  227. }
  228. //新增沙盘草稿
  229. err = sandbox.AddSandboxDraft(sandboxDraftInfo)
  230. return
  231. }
  232. // UpdateSandboxEditMark 更新沙盘当前更新状态
  233. // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
  234. func UpdateSandboxEditMark(sandboxId, nowUserId, status int, nowUserName string) (ret models.MarkReportResp, err error) {
  235. //更新标记key
  236. key := fmt.Sprint(`crm:sandbox:edit:`, sandboxId)
  237. opUserId, e := utils.Rc.RedisInt(key)
  238. var opUser models.MarkReportItem
  239. if e != nil {
  240. opUserInfoStr, tErr := utils.Rc.RedisString(key)
  241. if tErr == nil {
  242. tErr = json.Unmarshal([]byte(opUserInfoStr), &opUser)
  243. if tErr == nil {
  244. opUserId = opUser.AdminId
  245. }
  246. }
  247. }
  248. if opUserId > 0 && opUserId != nowUserId {
  249. editor := opUser.Editor
  250. if editor == "" {
  251. //查询账号的用户姓名
  252. otherInfo, e := system.GetSysAdminById(opUserId)
  253. if e != nil {
  254. err = fmt.Errorf("查询其他编辑者信息失败")
  255. return
  256. }
  257. editor = otherInfo.RealName
  258. }
  259. ret.Status = 1
  260. ret.Msg = fmt.Sprintf("当前%s正在编辑中", editor)
  261. ret.Editor = editor
  262. return
  263. }
  264. if status == 1 {
  265. nowUser := &models.MarkReportItem{AdminId: nowUserId, Editor: nowUserName}
  266. bt, e := json.Marshal(nowUser)
  267. if e != nil {
  268. err = fmt.Errorf("格式化编辑者信息失败")
  269. return
  270. }
  271. if opUserId > 0 {
  272. utils.Rc.Do("SETEX", key, int64(300), string(bt)) //3分钟缓存
  273. } else {
  274. utils.Rc.SetNX(key, string(bt), time.Second*60*5) //3分钟缓存
  275. }
  276. } else if status == 0 {
  277. //清除编辑缓存
  278. _ = utils.Rc.Delete(key)
  279. }
  280. return
  281. }
  282. // ResetDraftToLastVersion 重置沙盘草稿至最新版本
  283. func ResetDraftToLastVersion(sandboxId, opUserId int, opUserName string) (sandboxDraftInfo *sandbox.SandboxDraft, err error) {
  284. // 获取沙盘主表信息
  285. sandboxInfo, err := sandbox.GetSandboxById(sandboxId)
  286. if err != nil {
  287. return
  288. }
  289. //沙盘草稿表信息
  290. sandboxDraftInfo = &sandbox.SandboxDraft{
  291. SandboxId: sandboxInfo.SandboxId,
  292. Name: sandboxInfo.Name,
  293. ChartPermissionId: sandboxInfo.ChartPermissionId,
  294. ChartPermissionName: sandboxInfo.ChartPermissionName,
  295. Content: sandboxInfo.Content,
  296. OpUserId: opUserId,
  297. OpUserName: opUserName,
  298. CreateTime: time.Now(),
  299. }
  300. //新增沙盘草稿
  301. err = sandbox.AddSandboxDraft(sandboxDraftInfo)
  302. return
  303. }
  304. // DeleteSandbox 删除沙盘
  305. func DeleteSandbox(sandboxId int) (err error) {
  306. // 获取沙盘主表信息
  307. sandboxInfo, err := sandbox.GetSandboxById(sandboxId)
  308. if err != nil {
  309. return
  310. }
  311. sandboxInfo.IsDelete = 1
  312. var updateSandboxColumn = []string{"IsDelete"}
  313. err = sandboxInfo.Update(updateSandboxColumn)
  314. return
  315. }
  316. // DeleteSandboxVersion 删除沙盘版本
  317. func DeleteSandboxVersion(sandboxVersionCode string, opUserId int) (err error, errMsg string) {
  318. // 获取沙盘版本信息
  319. sandboxVersion, err := sandbox.GetSandboxVersionBySandboxVersionCode(sandboxVersionCode)
  320. if err != nil {
  321. if err.Error() == utils.ErrNoRow() {
  322. errMsg = "找不到该版本"
  323. err = errors.New(errMsg)
  324. }
  325. return
  326. }
  327. /*key := fmt.Sprint(`crm:sandbox:edit:`, sandboxVersion.SandboxId)
  328. nowOpUserId, _ := utils.Rc.RedisInt(key)
  329. //如果当前有人操作,且获取当前操作人不是本人,那么不允许删除
  330. if nowOpUserId > 0 && nowOpUserId != opUserId {
  331. errMsg = "当前有其他人正在编辑,不允许删除该沙盘"
  332. err = errors.New(errMsg)
  333. return
  334. }*/
  335. markStatus, err := UpdateSandboxEditMark(sandboxVersion.SandboxId, opUserId, 2, "")
  336. if err != nil {
  337. errMsg = "查询标记状态失败"
  338. err = errors.New("查询标记状态失败,Err:" + err.Error())
  339. return
  340. }
  341. if markStatus.Status == 1 {
  342. errMsg = fmt.Sprintf("当前%s正在编辑,不允许删除该沙盘", markStatus.Editor)
  343. err = errors.New(errMsg)
  344. return
  345. }
  346. // 获取沙盘主表信息
  347. sandboxInfo, err := sandbox.GetSandboxById(sandboxVersion.SandboxId)
  348. if err != nil {
  349. return
  350. }
  351. // 删除最新版本,需要将上一个版本的给找出来覆盖
  352. if sandboxVersion.CurrVersion == sandboxInfo.CurrVersion {
  353. lastSandboxVersion, tmpErr := sandbox.GetLastSandboxVersionBySandbox2VersionId(sandboxInfo.SandboxId, sandboxVersion.CurrVersion)
  354. if tmpErr != nil {
  355. // 如果找不到,说明是删除整个沙盘,不仅仅是某个版本
  356. if tmpErr.Error() == utils.ErrNoRow() {
  357. sandboxInfo.IsDelete = 1
  358. var updateSandboxColumn = []string{"IsDelete"}
  359. err = sandboxInfo.Update(updateSandboxColumn)
  360. return
  361. }
  362. err = tmpErr
  363. return
  364. } else {
  365. //将当前沙盘信息修复到上一个版本
  366. sandboxInfo.Content = lastSandboxVersion.Content
  367. sandboxInfo.CurrVersion = lastSandboxVersion.CurrVersion
  368. sandboxInfo.PicUrl = lastSandboxVersion.PicUrl
  369. err = sandboxInfo.Update([]string{"Content", "CurrVersion", "PicUrl"})
  370. if err != nil {
  371. return
  372. }
  373. }
  374. }
  375. //将原来的版本标记删除
  376. sandboxVersion.IsDelete = 1
  377. err = sandboxVersion.Update([]string{"IsDelete"})
  378. return
  379. }
  380. // GetSandboxVersionDetailByCode 获取沙盘的版本数据
  381. func GetSandboxVersionDetailByCode(sandboxVersionCode string) (sandboxVersionInfo *sandbox.SandboxVersion, err error) {
  382. // 获取沙盘版本信息
  383. sandboxVersionInfo, err = sandbox.GetSandboxVersionBySandboxVersionCode(sandboxVersionCode)
  384. return
  385. }
  386. // GetLastSandboxInfo 获取最后一次操作的沙盘数据
  387. func GetLastSandboxInfo(sandboxId int) (sandboxInfo *sandbox.Sandbox, err error) {
  388. // 获取沙盘主表信息
  389. sandboxInfo, err = sandbox.GetSandboxById(sandboxId)
  390. return
  391. //if err != nil {
  392. // return
  393. //}
  394. //
  395. ////获取最近一条草稿箱的数据(写到一半没有保存,然后退出去了)
  396. //lastSandboxDraft, err := sandbox.GetLastSandboxDraftById(sandboxId)
  397. //if err != nil && err.Error() != utils.ErrNoRow() {
  398. // return
  399. //}
  400. ////如果最近一条沙盘草稿数据不为空的话,那么需要校验下最近一次的图表数据是否与提交的这次一致
  401. //if lastSandboxDraft != nil {
  402. // sandboxInfo = &sandbox.Sandbox{
  403. // SandboxId: sandboxId,
  404. // Name: lastSandboxDraft.Name,
  405. // ChartPermissionId: lastSandboxDraft.ChartPermissionId,
  406. // ChartPermissionName: lastSandboxDraft.ChartPermissionName,
  407. // CurrVersion: lastSandboxDraft.CurrVersion,
  408. // Content: lastSandboxDraft.Content,
  409. // OpUserId: lastSandboxDraft.OpUserId,
  410. // OpUserName: lastSandboxDraft.OpUserName,
  411. // IsDelete: 0,
  412. // ModifyTime: lastSandboxDraft.CreateTime,
  413. // CreateTime: lastSandboxDraft.CreateTime,
  414. // }
  415. //}
  416. return
  417. }
  418. // GenerateCode 生成沙盘code
  419. func GenerateCode() string {
  420. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  421. return utils.MD5(fmt.Sprint("sandbox_") + timestamp)
  422. }
  423. // GenerateVersionCode 生成沙盘版本code
  424. func GenerateVersionCode(sandboxId, sandboxVersion int) string {
  425. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  426. return utils.MD5(fmt.Sprint("sandbox_version_", sandboxId, "_", sandboxVersion) + timestamp)
  427. }
  428. // ContentStruct 沙盘内容结构体
  429. type ContentStruct struct {
  430. Cells []struct {
  431. Attrs struct {
  432. Line struct {
  433. SourceMarker bool `json:"sourceMarker"`
  434. Stroke string `json:"stroke"`
  435. StrokeDasharray string `json:"strokeDasharray"`
  436. } `json:"line"`
  437. Rect struct {
  438. Fill string `json:"fill"`
  439. Stroke string `json:"stroke"`
  440. StrokeDasharray interface{} `json:"strokeDasharray"`
  441. StrokeWidth int64 `json:"strokeWidth"`
  442. } `json:"rect"`
  443. Text struct {
  444. Fill string `json:"fill"`
  445. FontSize float64 `json:"fontSize"`
  446. FontWeight string `json:"fontWeight"`
  447. LineHeight float64 `json:"lineHeight"`
  448. Text string `json:"text"`
  449. TextWrap struct {
  450. Text string `json:"text"`
  451. Width int64 `json:"width"`
  452. } `json:"textWrap"`
  453. } `json:"text"`
  454. } `json:"attrs"`
  455. Data struct {
  456. Key string `json:"key"`
  457. } `json:"data"`
  458. ID string `json:"id"`
  459. Ports struct {
  460. Groups struct {
  461. Port_bottom struct {
  462. Attrs struct {
  463. Circle struct {
  464. Fill string `json:"fill"`
  465. Magnet bool `json:"magnet"`
  466. R int64 `json:"r"`
  467. Stroke string `json:"stroke"`
  468. StrokeWidth int64 `json:"strokeWidth"`
  469. } `json:"circle"`
  470. } `json:"attrs"`
  471. Position string `json:"position"`
  472. ZIndex int64 `json:"zIndex"`
  473. } `json:"port-bottom"`
  474. Port_left struct {
  475. Attrs struct {
  476. Circle struct {
  477. Fill string `json:"fill"`
  478. Magnet bool `json:"magnet"`
  479. R int64 `json:"r"`
  480. Stroke string `json:"stroke"`
  481. StrokeWidth int64 `json:"strokeWidth"`
  482. } `json:"circle"`
  483. } `json:"attrs"`
  484. Position string `json:"position"`
  485. ZIndex int64 `json:"zIndex"`
  486. } `json:"port-left"`
  487. Port_right struct {
  488. Attrs struct {
  489. Circle struct {
  490. Fill string `json:"fill"`
  491. Magnet bool `json:"magnet"`
  492. R int64 `json:"r"`
  493. Stroke string `json:"stroke"`
  494. StrokeWidth int64 `json:"strokeWidth"`
  495. } `json:"circle"`
  496. } `json:"attrs"`
  497. Position string `json:"position"`
  498. ZIndex int64 `json:"zIndex"`
  499. } `json:"port-right"`
  500. Port_top struct {
  501. Attrs struct {
  502. Circle struct {
  503. Fill string `json:"fill"`
  504. Magnet bool `json:"magnet"`
  505. R int64 `json:"r"`
  506. Stroke string `json:"stroke"`
  507. StrokeWidth int64 `json:"strokeWidth"`
  508. } `json:"circle"`
  509. } `json:"attrs"`
  510. Position string `json:"position"`
  511. ZIndex int64 `json:"zIndex"`
  512. } `json:"port-top"`
  513. } `json:"groups"`
  514. Items []struct {
  515. Group string `json:"group"`
  516. ID string `json:"id"`
  517. } `json:"items"`
  518. } `json:"ports"`
  519. Position struct {
  520. X float64 `json:"x"`
  521. Y float64 `json:"y"`
  522. } `json:"position"`
  523. Shape string `json:"shape"`
  524. Size struct {
  525. Height float64 `json:"height"`
  526. Width float64 `json:"width"`
  527. } `json:"size"`
  528. Source struct {
  529. Cell string `json:"cell"`
  530. Port string `json:"port"`
  531. } `json:"source"`
  532. Target struct {
  533. Cell string `json:"cell"`
  534. Port string `json:"port"`
  535. } `json:"target"`
  536. ZIndex int64 `json:"zIndex"`
  537. } `json:"cells"`
  538. }
  539. // checkoutContent 校验内容是否变更
  540. func checkoutContent(oldContent, reqContent string) (isUpdate bool) {
  541. defer func() {
  542. // 沙盘内容md5比对,不一致则代表有做更改
  543. if utils.MD5(oldContent) != utils.MD5(reqContent) {
  544. isUpdate = true
  545. }
  546. }()
  547. var oldContentInfo, reqContentInfo ContentStruct
  548. err := json.Unmarshal([]byte(oldContent), &oldContentInfo)
  549. if err != nil {
  550. fmt.Println("old json.Unmarshal err:", err)
  551. return
  552. }
  553. oldContentInfoByte, err := json.Marshal(oldContentInfo)
  554. if err != nil {
  555. fmt.Println("old json.Marshal err:", err)
  556. return
  557. }
  558. oldContent = string(oldContentInfoByte)
  559. err = json.Unmarshal([]byte(reqContent), &reqContentInfo)
  560. if err != nil {
  561. fmt.Println("req json.Unmarshal err:", err)
  562. return
  563. }
  564. reqContentInfoByte, err := json.Marshal(reqContentInfo)
  565. if err != nil {
  566. fmt.Println("req json.Marshal err:", err)
  567. return
  568. }
  569. reqContent = string(reqContentInfoByte)
  570. return
  571. }