|
@@ -2,6 +2,7 @@ package models
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
+ "eta_gn/eta_api/global"
|
|
|
"eta_gn/eta_api/models/report"
|
|
|
"eta_gn/eta_api/utils"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
@@ -17,8 +18,9 @@ import (
|
|
|
// @return reportId int64
|
|
|
// @return err error
|
|
|
func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGrant, addReportChapterList []AddReportChapter) (reportId int64, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- to, err := o.Begin()
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //to, err := o.Begin()
|
|
|
+ to := global.DmSQL["rddp"].Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -31,7 +33,9 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
|
|
|
}()
|
|
|
|
|
|
// 新增报告
|
|
|
- reportId, err = to.Insert(reportItem)
|
|
|
+ //reportId, err = to.Insert(reportItem)
|
|
|
+ err = to.Create(reportItem).Error
|
|
|
+ reportId = int64(reportItem.Id)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -42,7 +46,8 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
|
|
|
for _, v := range allGrantUserList {
|
|
|
v.ReportId = reportItem.Id
|
|
|
}
|
|
|
- _, err = to.InsertMulti(500, allGrantUserList)
|
|
|
+ //_, err = to.InsertMulti(500, allGrantUserList)
|
|
|
+ err = to.CreateInBatches(allGrantUserList, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -54,11 +59,13 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
|
|
|
// 新增章节
|
|
|
chapterItem := addReportChapter.ReportChapter
|
|
|
chapterItem.ReportId = int(reportId)
|
|
|
- cpId, tmpErr := to.Insert(chapterItem)
|
|
|
+ //cpId, tmpErr := to.Insert(chapterItem)
|
|
|
+ tmpErr := to.Create(chapterItem).Error
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
+ cpId := chapterItem.ReportChapterId
|
|
|
chapterItem.ReportChapterId = int(cpId)
|
|
|
|
|
|
// 新增章节授权
|
|
@@ -67,7 +74,8 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
|
|
|
for _, v := range grantList {
|
|
|
v.ReportChapterId = chapterItem.ReportChapterId
|
|
|
}
|
|
|
- _, err = to.InsertMulti(500, grantList)
|
|
|
+ //_, err = to.InsertMulti(500, grantList)
|
|
|
+ err = to.CreateInBatches(grantList, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -79,7 +87,8 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
|
|
|
for _, v := range permissionList {
|
|
|
v.ReportChapterId = chapterItem.ReportChapterId
|
|
|
}
|
|
|
- _, err = to.InsertMulti(500, permissionList)
|
|
|
+ //_, err = to.InsertMulti(500, permissionList)
|
|
|
+ err = to.CreateInBatches(permissionList, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -101,8 +110,9 @@ func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGr
|
|
|
// @param delReportGrantIdList []int
|
|
|
// @return err error
|
|
|
func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportGrantList []*report.ReportGrant, delReportGrantIdList []int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- to, err := o.Begin()
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //to, err := o.Begin()
|
|
|
+ to := global.DmSQL["rddp"].Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -116,7 +126,8 @@ func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportG
|
|
|
|
|
|
// 变更报告章节信息
|
|
|
if len(updateCols) > 0 {
|
|
|
- _, err = to.Update(reportInfo, updateCols...)
|
|
|
+ //_, err = to.Update(reportInfo, updateCols...)
|
|
|
+ err = to.Select(updateCols).Updates(reportInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -124,7 +135,8 @@ func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportG
|
|
|
|
|
|
// 新增报告授权用户
|
|
|
if len(addReportGrantList) > 0 {
|
|
|
- _, err = to.InsertMulti(500, addReportGrantList)
|
|
|
+ //_, err = to.InsertMulti(500, addReportGrantList)
|
|
|
+ err = to.CreateInBatches(addReportGrantList, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -134,7 +146,8 @@ func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportG
|
|
|
delNum := len(delReportGrantIdList)
|
|
|
if delNum > 0 {
|
|
|
sql := `DELETE FROM report_grant WHERE grant_id IN (` + utils.GetOrmInReplace(delNum) + `)`
|
|
|
- _, err = to.Raw(sql, delReportGrantIdList).Exec()
|
|
|
+ //_, err = to.Raw(sql, delReportGrantIdList).Exec()
|
|
|
+ err = to.Exec(sql, delReportGrantIdList).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -152,8 +165,9 @@ func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportG
|
|
|
// @param addChapterPermissionMap []*report.ReportChapterPermissionMapping
|
|
|
// @return err error
|
|
|
func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReportChapterGrantList []*report.ReportChapterGrant, addChapterPermissionMap []*report.ReportChapterPermissionMapping) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- to, err := o.Begin()
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //to, err := o.Begin()
|
|
|
+ to := global.DmSQL["rddp"].Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -165,10 +179,12 @@ func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReport
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- lastId, err := to.Insert(reportChapterInfo)
|
|
|
+ //lastId, err := to.Insert(reportChapterInfo)
|
|
|
+ err = to.Create(reportChapterInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
+ lastId := reportChapterInfo.ReportChapterId
|
|
|
reportChapterInfo.ReportChapterId = int(lastId)
|
|
|
|
|
|
// 新增报告章节授权用户
|
|
@@ -176,7 +192,8 @@ func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReport
|
|
|
for k, _ := range addReportChapterGrantList {
|
|
|
addReportChapterGrantList[k].ReportChapterId = reportChapterInfo.ReportChapterId
|
|
|
}
|
|
|
- _, err = to.InsertMulti(500, addReportChapterGrantList)
|
|
|
+ //_, err = to.InsertMulti(500, addReportChapterGrantList)
|
|
|
+ err = to.CreateInBatches(addReportChapterGrantList, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -188,7 +205,8 @@ func AddChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, addReport
|
|
|
addChapterPermissionMap[k].ReportChapterId = reportChapterInfo.ReportChapterId
|
|
|
}
|
|
|
|
|
|
- _, err = to.InsertMulti(500, addChapterPermissionMap)
|
|
|
+ //_, err = to.InsertMulti(500, addChapterPermissionMap)
|
|
|
+ err = to.CreateInBatches(addChapterPermissionMap, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|