tree_contract_dao.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*
  2. * @description: 合同项目节相关数据库操作
  3. * @Author: CP
  4. * @Date: 2020-11-02 11:37:32
  5. * @FilePath: \construction_management\dao\tree_contract_dao.go
  6. */
  7. package dao
  8. import (
  9. "errors"
  10. "fmt"
  11. "log"
  12. "strings"
  13. "github.com/go-xorm/xorm"
  14. "go.mod/models"
  15. )
  16. //数据库操作引擎
  17. type TreeContractDao struct {
  18. engine *xorm.Engine
  19. }
  20. //获得一个DAO对象
  21. func NewTreeContractDao(engine *xorm.Engine) *TreeContractDao {
  22. return &TreeContractDao{
  23. engine: engine,
  24. }
  25. }
  26. // 获得本项目的合同项目节
  27. func (d *TreeContractDao) Get(treeId int, bidsectionId int, projectId int, treeType int) *models.CmTreeContracts {
  28. data := &models.CmTreeContracts{}
  29. _, err := d.engine.
  30. Where("tree_id=? and bidsection_id =? and project_id=? and tree_type=?", treeId, bidsectionId, projectId, treeType).
  31. Get(data)
  32. if err != nil {
  33. data.Id = 0
  34. return data
  35. }
  36. return data
  37. }
  38. // 获得项目下的项目节
  39. func (d *TreeContractDao) GetAll(bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
  40. datalist := make([]models.CmTreeContracts, 0)
  41. err := d.engine.
  42. Asc("id").
  43. Where("bidsection_id =? and project_id=? and tree_type=?", bidsectionId, projectId, treeType).
  44. Limit(5000, 0).
  45. Find(&datalist)
  46. if err != nil {
  47. return datalist
  48. } else {
  49. return datalist
  50. }
  51. }
  52. // 获得项目下的项目节不包含合同
  53. func (d *TreeContractDao) GetAllNotContract(bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
  54. datalist := make([]models.CmTreeContracts, 0)
  55. err := d.engine.
  56. Asc("id").
  57. Where("bidsection_id =? and project_id=? and tree_type=? and contract_id=0", bidsectionId, projectId, treeType).
  58. Limit(5000, 0).
  59. Find(&datalist)
  60. if err != nil {
  61. return datalist
  62. } else {
  63. return datalist
  64. }
  65. }
  66. // 获得最新ID
  67. func (d *TreeContractDao) GetLastId() *models.CmTreeContracts {
  68. data := &models.CmTreeContracts{}
  69. _, err := d.engine.
  70. Desc("id").
  71. Get(data)
  72. if err != nil {
  73. data.Id = 0
  74. return data
  75. }
  76. return data
  77. }
  78. // 获得项目节所有合同
  79. func (d *TreeContractDao) GetContractAll(bidsectionId int, projectId int) []models.CmTreeContracts {
  80. datalist := make([]models.CmTreeContracts, 0)
  81. err := d.engine.
  82. Asc("id").
  83. Where("bidsection_id =? and project_id=? and contract_id!=0 ", bidsectionId, projectId).
  84. Find(&datalist)
  85. if err != nil {
  86. return datalist
  87. } else {
  88. return datalist
  89. }
  90. }
  91. // 获得标段 项目节中已有的合同
  92. func (d *TreeContractDao) GetContract(bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
  93. datalist := make([]models.CmTreeContracts, 0)
  94. err := d.engine.
  95. Asc("id").
  96. Where("bidsection_id =? and project_id=? and contract_id!=0 and tree_type=?", bidsectionId, projectId, treeType).
  97. Find(&datalist)
  98. if err != nil {
  99. return datalist
  100. } else {
  101. return datalist
  102. }
  103. }
  104. // 获得节点的孩子
  105. func (d *TreeContractDao) GetChildren(parentId int, bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
  106. datalist := make([]models.CmTreeContracts, 0)
  107. err := d.engine.
  108. Asc("serial").
  109. Where("parent_id=? and bidsection_id=? and project_id=? and tree_type=?", parentId, bidsectionId, projectId, treeType).
  110. Find(&datalist)
  111. if err != nil {
  112. return datalist
  113. } else {
  114. return datalist
  115. }
  116. }
  117. // 获得节点的孩子-是项目节
  118. func (d *TreeContractDao) GetChildrenBySection(parentId int, bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
  119. datalist := make([]models.CmTreeContracts, 0)
  120. err := d.engine.
  121. Asc("serial").
  122. Where("parent_id=? and bidsection_id=? and project_id=? and tree_type=? and contract_id=0", parentId, bidsectionId, projectId, treeType).
  123. Find(&datalist)
  124. if err != nil {
  125. return datalist
  126. } else {
  127. return datalist
  128. }
  129. }
  130. //根据序号和深度获得前一个兄弟节点
  131. func (d *TreeContractDao) GetElderBrother(serial int, depth int, parentId int, bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
  132. datalist := make([]models.CmTreeContracts, 0)
  133. err := d.engine.
  134. Desc("serial").
  135. Where("serial < ? and depth = ? and parent_id =? and bidsection_id=? and project_id=? and tree_type=?", serial, depth, parentId, bidsectionId, projectId, treeType).
  136. Find(&datalist)
  137. if err != nil {
  138. return datalist
  139. } else {
  140. return datalist
  141. }
  142. }
  143. //根据序号和深度获得后一个兄弟节点
  144. func (d *TreeContractDao) GetYoungerBrother(serial int, depth int, parentId int, bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
  145. datalist := make([]models.CmTreeContracts, 0)
  146. err := d.engine.
  147. Asc("serial").
  148. Where("serial > ? and depth = ? and parent_id =? and bidsection_id=? and project_id=? and tree_type=?", serial, depth, parentId, bidsectionId, projectId, treeType).
  149. Find(&datalist)
  150. if err != nil {
  151. return datalist
  152. } else {
  153. return datalist
  154. }
  155. }
  156. // 获得最后一条项目节
  157. func (d *TreeContractDao) GetLast(projectId int, treeType int) *models.CmTreeContracts {
  158. data := &models.CmTreeContracts{}
  159. _, err := d.engine.
  160. Desc("id").
  161. Where("project_id=? and tree_type=?", projectId, treeType).
  162. Get(data)
  163. if err != nil {
  164. data.Id = 0
  165. return data
  166. }
  167. return data
  168. }
  169. // 获得谋归属下的项目节
  170. func (d *TreeContractDao) GetAttribution(attribution string, projectId int, bidsectionId int, treeType int) []models.CmTreeContracts {
  171. datalist := make([]models.CmTreeContracts, 0)
  172. err := d.engine.
  173. Asc("serial").
  174. Where("attribution like ? and project_id=? and bidsection_id=? and tree_type=?", attribution+"%", projectId, bidsectionId, treeType).
  175. Find(&datalist)
  176. if err != nil {
  177. return datalist
  178. } else {
  179. return datalist
  180. }
  181. }
  182. // 获得谋归属下的项目节-合同
  183. func (d *TreeContractDao) GetAttributionContract(section *models.CmTreeContracts, treeType int) []models.CmTreeContracts {
  184. // attribution := section.Attribution
  185. attribution := fmt.Sprintf("%s-", section.Code)
  186. projectId := section.ProjectId
  187. bidsectionId := section.BidsectionId
  188. datalist := make([]models.CmTreeContracts, 0)
  189. err := d.engine.
  190. Asc("serial").
  191. Where("(attribution like ? or id =? ) and project_id=? and bidsection_id=? and tree_type=? and contract_id!=0", attribution+"%", section.Id, projectId, bidsectionId, treeType).
  192. Find(&datalist)
  193. if err != nil {
  194. return datalist
  195. } else {
  196. return datalist
  197. }
  198. }
  199. // 项目节升降级
  200. func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrother *models.CmTreeContracts, operation string, bidsectionId int, projectId int, treeType int) error {
  201. session := d.engine.NewSession()
  202. defer session.Close()
  203. err := session.Begin()
  204. if err != nil {
  205. return errors.New("操作失败-db")
  206. }
  207. // 降级
  208. if operation == "downDepth" {
  209. // 1.前一个兄弟节点
  210. // fmt.Println(elderBrother)
  211. // 2.把节点移动到兄弟节点的下级,成为兄弟的孩子
  212. // 2-1 节点的父亲为兄弟的ID
  213. // 2-2 节点的深度 +1
  214. // 2-3 节点归属为兄弟归属+序号
  215. attribution := fmt.Sprintf("%s%d-", elderBrother.Attribution, elderBrother.Serial)
  216. // 2-4 序号 没有孩子序号为1,有孩子 最大孩子序号+1
  217. // 2-4-1 获得上一位哥的孩子们
  218. elderBrotherChildren := d.GetChildren(elderBrother.TreeId, bidsectionId, projectId, treeType)
  219. serial := 1
  220. if len(elderBrotherChildren) != 0 {
  221. serial = elderBrotherChildren[len(elderBrotherChildren)-1].Serial + 1
  222. }
  223. // 2-5 项目节编号
  224. // 原编号
  225. // section.Code
  226. // 移动后编号
  227. moveCode := fmt.Sprintf("%s%d", attribution, serial)
  228. _, err = session.Exec("UPDATE cm_tree_contracts SET `parent_id` = ?,attribution= ? , serial = ? ,`code` = replace(`code`, '"+section.Code+"', '"+moveCode+"')"+
  229. ",`depth` =`depth` + ? where id = ? and tree_type=? ", elderBrother.TreeId, attribution, serial, 1, section.Id, treeType)
  230. if err != nil {
  231. session.Rollback()
  232. return errors.New("降级失败")
  233. }
  234. // 3.更新节点下的归属
  235. // 3-1 节点的所有孩子的归属
  236. // 原节点 孩子的归属
  237. attributionChildren := fmt.Sprintf("%s%d-", section.Attribution, section.Serial)
  238. // 降级后的 孩子归属
  239. moveAttributionChildren := fmt.Sprintf("%s%d-", attribution, serial)
  240. // 3-2 降级 深度+1
  241. _, err = session.Exec("UPDATE cm_tree_contracts SET "+
  242. "`depth` =`depth` + ? where attribution like ? and project_id=? and bidsection_id=? and tree_type=? ", 1, attributionChildren+"%", projectId, bidsectionId, treeType)
  243. if err != nil {
  244. session.Rollback()
  245. return errors.New("降级失败")
  246. }
  247. // 3-3--替换 归属和编号
  248. // "`attribution` = replace(`attribution`, '"+attributionChildren+"', '"+moveAttributionChildren+"') ,`code` = replace(`code`, '"+section.Code+"', '"+moveCode+"'),"
  249. err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, section.Code, moveCode, projectId, bidsectionId, treeType)
  250. if err != nil {
  251. session.Rollback()
  252. return errors.New("降级失败")
  253. }
  254. } else if operation == "upDepth" {
  255. // 升级
  256. // 1.父亲节点
  257. sectionFather := d.Get(section.ParentId, bidsectionId, projectId, treeType)
  258. if sectionFather.Id == 0 {
  259. session.Rollback()
  260. return errors.New("升级-未找到上级项目节")
  261. }
  262. // 2.原节点的父亲ID字段升级为爷爷ID
  263. // 2-1 升级 深度-1
  264. // 2-2 序号 爷爷的孩子们的 序号+1
  265. grandpaChildren := d.GetChildren(sectionFather.ParentId, bidsectionId, projectId, treeType)
  266. serial := 1
  267. if len(grandpaChildren) != 0 {
  268. serial = grandpaChildren[len(grandpaChildren)-1].Serial + 1
  269. }
  270. // 2-3 归属 原父亲的归属
  271. // 移动后编号-需替换原编号 节点2-1-1 升级后的父节点归属 2- 加上爷爷最大孩子的序号+1
  272. moveCode := fmt.Sprintf("%s%d", sectionFather.Attribution, serial)
  273. // 升级的项目节
  274. _, err = session.Exec("UPDATE cm_tree_contracts SET `parent_id` = ?,attribution= ? , serial = ? ,`code` = replace(`code`, '"+section.Code+"', '"+moveCode+"')"+
  275. ",`depth` =`depth` - ? where id = ? and tree_type=? ", sectionFather.ParentId, sectionFather.Attribution, serial, 1, section.Id, treeType)
  276. if err != nil {
  277. session.Rollback()
  278. return errors.New("升级失败")
  279. }
  280. // 3.更新节点下的归属,深度
  281. // 原节点 孩子的归属
  282. attributionChildren := fmt.Sprintf("%s%d-", section.Attribution, section.Serial)
  283. // 升级后的 孩子归属
  284. moveAttributionChildren := fmt.Sprintf("%s%d-", sectionFather.Attribution, serial)
  285. // 深度 -1
  286. _, err = session.Exec("UPDATE cm_tree_contracts SET `attribution` = replace(`attribution`, '"+attributionChildren+"', '"+moveAttributionChildren+"') "+
  287. ",`depth` =`depth` - ? where attribution like ? and project_id=? and bidsection_id=? and tree_type=? ", 1, attributionChildren+"%", projectId, bidsectionId, treeType)
  288. if err != nil {
  289. session.Rollback()
  290. return errors.New("升级失败")
  291. }
  292. // 3-1
  293. err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, section.Code, moveCode, projectId, bidsectionId, treeType)
  294. if err != nil {
  295. session.Rollback()
  296. return errors.New("升级失败")
  297. }
  298. } else {
  299. return errors.New("参数错误")
  300. }
  301. err = session.Commit()
  302. if err != nil {
  303. session.Rollback()
  304. return errors.New("操作失败-db")
  305. }
  306. return nil
  307. }
  308. // 合同项目节上下移动
  309. func (d *TreeContractDao) MoveSerial(section *models.CmTreeContracts, brother *models.CmTreeContracts, operation string, bidsectionId int, projectId int, treeType int) error {
  310. session := d.engine.NewSession()
  311. defer session.Close()
  312. err := session.Begin()
  313. if err != nil {
  314. return errors.New("操作失败-db")
  315. }
  316. //1.上下移
  317. // 1.项目节序号替换为兄弟序号
  318. _, err = session.Exec("UPDATE cm_tree_contracts SET serial = ? , `code` = replace(`code`, '"+section.Code+"', '"+brother.Code+"') where id = ? and tree_type=? ", brother.Serial, section.Id, treeType)
  319. if err != nil {
  320. session.Rollback()
  321. return errors.New("移动失败")
  322. }
  323. // 兄弟序号替换为项目节序号
  324. _, err = session.Exec("UPDATE cm_tree_contracts SET serial = ? , `code` = replace(`code`, '"+brother.Code+"', '"+section.Code+"') where id = ? and tree_type=? ", section.Serial, brother.Id, treeType)
  325. if err != nil {
  326. session.Rollback()
  327. return errors.New("移动失败")
  328. }
  329. //2.项目节孩子们 归属设置
  330. // 原节点 孩子的归属
  331. attributionChildren := fmt.Sprintf("%s%d-", section.Attribution, section.Serial)
  332. // 移动后的 孩子归属和编号
  333. moveAttributionChildren := fmt.Sprintf("%s%d-", brother.Attribution, brother.Serial)
  334. err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, section.Code, brother.Code, projectId, bidsectionId, treeType)
  335. if err != nil {
  336. session.Rollback()
  337. return errors.New("移动失败")
  338. }
  339. // _, err = session.Exec("UPDATE cm_tree_contracts SET `attribution` = replace(`attribution`, '"+attributionChildren+"', '"+moveAttributionChildren+"') "+
  340. // "`code` = replace(`code`, '"+attributionChildren+"', '"+moveAttributionChildren+"') where attribution like ? and project_id=? and bidsection_id=? ", attributionChildren+"%", projectId, bidsectionId)
  341. // if err != nil {
  342. // session.Rollback()
  343. // return errors.New("移动失败")
  344. // }
  345. // 3.兄弟节点孩子们 归属设置
  346. // 兄弟节点 孩子的归属
  347. attributionChildren = fmt.Sprintf("%s%d-", brother.Attribution, brother.Serial)
  348. // 移动后的 孩子归属
  349. moveAttributionChildren = fmt.Sprintf("%s%d-", section.Attribution, section.Serial)
  350. err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, brother.Code, section.Code, projectId, bidsectionId, treeType)
  351. if err != nil {
  352. session.Rollback()
  353. return errors.New("移动失败")
  354. }
  355. err = session.Commit()
  356. if err != nil {
  357. session.Rollback()
  358. return errors.New("操作失败-db")
  359. }
  360. return nil
  361. }
  362. // 修改项目节序号
  363. func (d *TreeContractDao) UpdateSerial(section *models.CmTreeContracts, serial int, treeType int) error {
  364. session := d.engine.NewSession()
  365. defer session.Close()
  366. err := session.Begin()
  367. if err != nil {
  368. return errors.New("操作失败-db")
  369. }
  370. // 1.更新项目节序号和项目节编号
  371. moveCode := fmt.Sprintf("%s%d", section.Attribution, serial)
  372. _, err = session.Exec("UPDATE cm_tree_contracts SET serial = ? , `code` = ? where id = ? and tree_type=? ", serial, moveCode, section.Id, treeType)
  373. if err != nil {
  374. session.Rollback()
  375. log.Println("合同项目节序号更新 error=", err)
  376. return errors.New("更新序号失败")
  377. }
  378. // 2.更新项目节子孙们的序号和归属
  379. // 2-1归属 项目节 孩子归属
  380. attributionChildren := fmt.Sprintf("%s%d-", section.Attribution, section.Serial)
  381. // 2-2 序号更新后的 孩子归属
  382. moveAttributionChildren := fmt.Sprintf("%s%d-", section.Attribution, serial)
  383. // 2-3 项目节 孩子的编号
  384. code := fmt.Sprintf("%s%d", section.Attribution, section.Serial)
  385. err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, code, moveCode, section.ProjectId, section.BidsectionId, treeType)
  386. if err != nil {
  387. session.Rollback()
  388. log.Println("合同项目节序号更新 error=", err)
  389. return errors.New("更新序号失败")
  390. }
  391. err = session.Commit()
  392. if err != nil {
  393. session.Rollback()
  394. return errors.New("操作失败-db")
  395. }
  396. return nil
  397. }
  398. // 插入多条数据
  399. func (d *TreeContractDao) CreateAll(data []*models.CmTreeContracts) error {
  400. session := d.engine.NewSession()
  401. defer session.Close()
  402. err := session.Begin()
  403. if err != nil {
  404. return errors.New("新增失败-db")
  405. }
  406. // 新增
  407. for _, item := range data {
  408. _, err := session.Insert(item)
  409. if err != nil {
  410. log.Println(" error=", err)
  411. session.Rollback()
  412. return errors.New("新增失败")
  413. }
  414. }
  415. err = session.Commit()
  416. if err != nil {
  417. session.Rollback()
  418. return errors.New("新增失败-db")
  419. }
  420. return nil
  421. }
  422. // 新增项目节
  423. func (d *TreeContractDao) Create(data *models.CmTreeContracts) (*models.CmTreeContracts, error) {
  424. session := d.engine.NewSession()
  425. defer session.Close()
  426. err := session.Begin()
  427. if err != nil {
  428. return nil, errors.New("新增失败-db")
  429. }
  430. _, err = session.Insert(data)
  431. if err != nil {
  432. log.Println(" error=", err)
  433. return nil, errors.New("新增失败")
  434. }
  435. // 插入成功后,ID自动赋值到data.Id里
  436. // fmt.Println("=======================================")
  437. // fmt.Println(data)
  438. // 更新合同节树ID
  439. // data.TreeId = data.Id
  440. // _, err = session.Id(data.Id).Update(data)
  441. // if err != nil {
  442. // log.Println(" error=", err)
  443. // return errors.New("新增失败")
  444. // }
  445. err = session.Commit()
  446. if err != nil {
  447. session.Rollback()
  448. return nil, errors.New("新增失败-db")
  449. }
  450. return data, nil
  451. }
  452. // 保存项目节
  453. func (d *TreeContractDao) Save(section *models.CmTreeContracts, columns []string) error {
  454. _, err := d.engine.Id(section.Id).MustCols(columns...).Update(section)
  455. if err != nil {
  456. return errors.New("保存失败")
  457. }
  458. return nil
  459. }
  460. // 删除项目节
  461. func (d *TreeContractDao) Delete(section *models.CmTreeContracts) error {
  462. session := d.engine.NewSession()
  463. defer session.Close()
  464. err := session.Begin()
  465. if err != nil {
  466. return errors.New("删除失败-db")
  467. }
  468. // 1. 删除项目节
  469. _, err = session.Where("id = ? ", section.Id).Delete(section)
  470. if err != nil {
  471. session.Rollback()
  472. return errors.New("删除失败")
  473. }
  474. // 孩子们的归属
  475. attribution := fmt.Sprintf("%s%d-", section.Attribution, section.Serial)
  476. // 2. 删除项目节孩子们
  477. _, err = session.Exec("DELETE FROM `cm_tree_contracts` WHERE attribution like ? and project_id=? and bidsection_id=? and tree_type=? ", attribution+"%", section.ProjectId, section.BidsectionId, section.TreeType)
  478. if err != nil {
  479. session.Rollback()
  480. return errors.New("删除失败")
  481. }
  482. err = session.Commit()
  483. if err != nil {
  484. session.Rollback()
  485. return errors.New("删除失败-db")
  486. }
  487. return nil
  488. }
  489. //替换项目节归属
  490. func (d *TreeContractDao) replaceContractAttribution(session *xorm.Session, attributionChildren string, moveAttributionChildren string, code string, moveCode string, projectId int, bidsectionId int, treeType int) error {
  491. // 1.获得需要替换的数据
  492. sectionData := d.GetAttribution(attributionChildren, projectId, bidsectionId, treeType)
  493. if len(sectionData) == 0 {
  494. return nil
  495. }
  496. attributionSql := " attribution = case id "
  497. codeSql := " code = case id "
  498. idList := make([]int, 0)
  499. for _, item := range sectionData {
  500. // section := &models.CmTreeContracts{}
  501. // section.Id = item.Id
  502. // 替换归属
  503. attributionSql += fmt.Sprintf("when %d then '%s' ", item.Id, strings.Replace(item.Attribution, attributionChildren, moveAttributionChildren, 1))
  504. //section.Attribution = strings.Replace(item.Attribution, attributionChildren, moveAttributionChildren, 1)
  505. // 替换编号
  506. codeSql += fmt.Sprintf("when %d then '%s' ", item.Id, strings.Replace(item.Code, code, moveCode, 1))
  507. // section.Code = strings.Replace(item.Code, code, moveCode, 1)
  508. idList = append(idList, item.Id)
  509. }
  510. attributionSql += " end, "
  511. codeSql += " end "
  512. id := strings.Replace(strings.Trim(fmt.Sprint(idList), "[]"), " ", ",", -1)
  513. sql := "update cm_tree_contracts set " + attributionSql + codeSql + " WHERE id IN (" + id + ")"
  514. _, err := session.Exec(sql)
  515. if err != nil {
  516. log.Println("替换项目节归属, error=", err)
  517. return err
  518. }
  519. return nil
  520. }