|
@@ -1,19 +1,20 @@
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
+ sql2 "database/sql"
|
|
|
"errors"
|
|
|
+ "eta/eta_api/global"
|
|
|
"eta/eta_api/models/data_manage/excel"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
)
|
|
|
|
|
|
type EnglishReport struct {
|
|
|
- Id int `orm:"column(id)" description:"报告Id"`
|
|
|
+ Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告Id"`
|
|
|
AddType int `description:"新增方式:1:新增报告,2:继承报告"`
|
|
|
ClassifyIdFirst int `description:"一级分类id"`
|
|
|
ClassifyNameFirst string `description:"一级分类名称"`
|
|
@@ -53,41 +54,67 @@ type EnglishReport struct {
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := ``
|
|
|
+ var countNull sql2.NullInt64
|
|
|
if classifyIdSecond > 0 {
|
|
|
sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_second=? "
|
|
|
- o.Raw(sql, classifyIdSecond).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, classifyIdSecond).Scan(&countNull).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countNull.Valid {
|
|
|
+ count = int(countNull.Int64)
|
|
|
+ }
|
|
|
} else {
|
|
|
sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_first=? "
|
|
|
- o.Raw(sql, classifyIdFirst).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, classifyIdFirst).Scan(&countNull).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countNull.Valid {
|
|
|
+ count = int(countNull.Int64)
|
|
|
+ }
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := ``
|
|
|
+ var countNull sql2.NullInt64
|
|
|
if classifyIdSecond > 0 {
|
|
|
sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_second=? AND id<>? "
|
|
|
- o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, classifyIdSecond, reportId).Scan(&countNull).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countNull.Valid {
|
|
|
+ count = int(countNull.Int64)
|
|
|
+ }
|
|
|
} else {
|
|
|
sql = "SELECT MAX(stage) AS max_stage FROM english_report WHERE classify_id_first=? AND id<>? "
|
|
|
- o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, classifyIdFirst, reportId).Scan(&countNull).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countNull.Valid {
|
|
|
+ count = int(countNull.Int64)
|
|
|
+ }
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func AddEnglishReport(item *EnglishReport) (lastId int64, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- lastId, err = o.Insert(item)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Create(item).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ lastId = int64(item.Id)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ModifyEnglishReportCode(reportId int64, reportCode string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `UPDATE english_report SET report_code=? WHERE id=? `
|
|
|
- _, err = o.Raw(sql, reportCode, reportId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameReport].Exec(sql, reportCode, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -166,7 +193,6 @@ type ElasticEnglishReportDetail struct {
|
|
|
}
|
|
|
|
|
|
func EditEnglishReport(item *EnglishReport, reportId int64) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `UPDATE english_report
|
|
|
SET
|
|
|
classify_id_first =?,
|
|
@@ -185,13 +211,13 @@ func EditEnglishReport(item *EnglishReport, reportId int64) (err error) {
|
|
|
modify_time = ?,
|
|
|
overview = ?
|
|
|
WHERE id = ? `
|
|
|
- _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
|
|
|
- item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), item.Overview, reportId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameReport].Exec(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
|
|
|
+ item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), item.Overview, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
type EnglishReportDetail struct {
|
|
|
- Id int `orm:"column(id)" description:"报告Id"`
|
|
|
+ Id int `gorm:"column:id;primaryKey" description:"报告Id"`
|
|
|
AddType int `description:"新增方式:1:新增报告,2:继承报告"`
|
|
|
ClassifyIdFirst int `description:"一级分类id"`
|
|
|
ClassifyNameFirst string `description:"一级分类名称"`
|
|
@@ -223,16 +249,14 @@ type EnglishReportDetail struct {
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportById(reportId int) (item *EnglishReportDetail, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `SELECT * FROM english_report WHERE id=?`
|
|
|
- err = o.Raw(sql, reportId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, reportId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportItemById(reportId int) (item *EnglishReport, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
|
|
|
- err = o.Raw(sql, reportId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, reportId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -293,17 +317,22 @@ func GetEnglishReportListCount(condition string, pars []interface{}, companyType
|
|
|
companyTypeSqlStr = " AND classify_id_first = 40 "
|
|
|
}
|
|
|
|
|
|
- oRddp := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `SELECT COUNT(1) AS count FROM english_report WHERE 1=1 ` + companyTypeSqlStr
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- err = oRddp.Raw(sql, pars).QueryRow(&count)
|
|
|
+ var countNull sql2.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Scan(&countNull).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countNull.Valid {
|
|
|
+ count = int(countNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int, fieldArr []string) (items []*EnglishReport, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
//产品权限
|
|
|
companyTypeSqlStr := ``
|
|
|
if companyType == "ficc" {
|
|
@@ -323,61 +352,63 @@ func GetEnglishReportList(condition string, pars []interface{}, companyType stri
|
|
|
}
|
|
|
// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
|
|
|
sql += ` ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
|
|
|
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportByCondition(condition string, pars []interface{}) (items []*EnglishReport, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `SELECT *
|
|
|
FROM english_report WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `SELECT count(*)
|
|
|
FROM english_report WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
+ var countNull sql2.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Scan(&countNull).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countNull.Valid {
|
|
|
+ count = int(countNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// PublishEnglishReportById 发布报告
|
|
|
func PublishEnglishReportById(reportId int, publishTime string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `UPDATE english_report SET state=2,publish_time=?,pre_publish_time=null,modify_time=NOW() WHERE id = ? `
|
|
|
- _, err = o.Raw(sql, publishTime, reportId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameReport].Exec(sql, publishTime, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// ResetEnglishReportById 重置报告状态
|
|
|
func ResetEnglishReportById(reportId, state int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `UPDATE english_report SET state = ?, pre_publish_time = null, modify_time = NOW() WHERE id = ?`
|
|
|
- _, err = o.Raw(sql, state, reportId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameReport].Exec(sql, state, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// PublishCancelEnglishReport 取消发布报告
|
|
|
func PublishCancelEnglishReport(reportIds, state int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := ` UPDATE english_report SET state=?, pre_publish_time=null WHERE id =? `
|
|
|
- _, err = o.Raw(sql, state, reportIds).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameReport].Exec(sql, state, reportIds).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// SetPrePublishEnglishReportById 设置定时发布
|
|
|
func SetPrePublishEnglishReportById(reportId int, prePublishTime string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `UPDATE english_report SET pre_publish_time=? WHERE id = ? and state = 1 `
|
|
|
- _, err = o.Raw(sql, prePublishTime, reportId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameReport].Exec(sql, prePublishTime, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -399,23 +430,20 @@ func DeleteEnglishReportAndChapter(reportInfo *EnglishReportDetail) (err error)
|
|
|
|
|
|
// 删除报告
|
|
|
func DeleteEnglishReport(reportIds int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := ` DELETE FROM english_report WHERE id =? `
|
|
|
- _, err = o.Raw(sql, reportIds).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameReport].Exec(sql, reportIds).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func EditEnglishReportContent(reportId int, content, contentSub string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := ` UPDATE english_report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
|
|
|
- _, err = o.Raw(sql, content, contentSub, reportId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameReport].Exec(sql, content, contentSub, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func AddEnglishReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
sql := ` INSERT INTO english_report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
|
|
|
- _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameReport].Exec(sql, reportId, content, contentSub, adminId, adminName).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -444,7 +472,6 @@ type EnglishClassifyListResp struct {
|
|
|
// GetEnglishClassifyRootId 获取一级分类列表
|
|
|
func GetEnglishClassifyRootId(keyword string, enabled int) (items []*EnglishClassifyList, err error) {
|
|
|
sql := ``
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
cond := ""
|
|
|
if enabled == 1 {
|
|
|
cond = " AND enabled=1 "
|
|
@@ -459,10 +486,10 @@ func GetEnglishClassifyRootId(keyword string, enabled int) (items []*EnglishClas
|
|
|
WHERE parent_id>0 ` + cond + ` AND classify_name LIKE ? )
|
|
|
)AS t
|
|
|
ORDER BY sort ASC,create_time ASC`
|
|
|
- _, err = o.Raw(sql, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword)).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword)).Find(&items).Error
|
|
|
} else {
|
|
|
sql = `SELECT * FROM english_classify WHERE parent_id=0 ` + cond + ` ORDER BY sort ASC,create_time ASC `
|
|
|
- _, err = o.Raw(sql).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql).Find(&items).Error
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -471,7 +498,7 @@ func GetEnglishClassifyListByRootId(rootIds []int, keyword string, enabled int)
|
|
|
sql := ``
|
|
|
pars := make([]interface{}, 0)
|
|
|
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
cond := ""
|
|
|
if enabled == 1 {
|
|
|
cond = " AND enabled=1 "
|
|
@@ -486,55 +513,58 @@ FROM
|
|
|
WHERE a.parent_id>0 ` + cond + ` and a.classify_name LIKE ? and a.root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `)`
|
|
|
pars = append(pars, utils.GetLikeKeyword(keyword))
|
|
|
pars = append(pars, rootIds)
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, pars...).Find(&items).Error
|
|
|
} else {
|
|
|
sql = `SELECT * FROM english_classify WHERE parent_id>0 ` + cond + ` and root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `) `
|
|
|
- _, err = o.Raw(sql, rootIds).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, rootIds).Find(&items).Error
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishClassifyChildByIds(ids []int) (items []*EnglishClassifyList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(ids)) + `) ORDER BY create_time ASC `
|
|
|
- _, err = o.Raw(sql, ids).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, ids).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *EnglishReportDetail, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := ` SELECT * FROM english_report WHERE 1=1 `
|
|
|
if classifyIdSecond > 0 {
|
|
|
sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
|
|
|
- err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, classifyIdSecond).First(&item).Error
|
|
|
} else {
|
|
|
sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
|
|
|
- err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, classifyIdFirst).First(&item).Error
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// Update 更新
|
|
|
func (item *EnglishReport) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- _, err = o.Update(item, cols...)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Select(cols).Updates(item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// ModifyEnglishReportAuthor 更改英文报告作者
|
|
|
func ModifyEnglishReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
|
|
|
//产品权限
|
|
|
- oRddp := orm.NewOrmUsingDB("rddp")
|
|
|
sql := `UPDATE english_report set author = ? WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
|
|
|
+ res := global.DbMap[utils.DbNameReport].Exec(sql, utils.ForwardPars(pars, authorName)...)
|
|
|
+ if res.Error != nil {
|
|
|
+ err = res.Error
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count = int(res.RowsAffected)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
type EnglishClassify struct {
|
|
|
- Id int `orm:"column(id);pk"`
|
|
|
+ Id int `gorm:"column:id;primaryKey"`
|
|
|
ClassifyName string `description:"分类名称"`
|
|
|
Sort int `description:"排序"`
|
|
|
ParentId int `description:"父级分类id"`
|
|
@@ -549,10 +579,7 @@ type EnglishClassify struct {
|
|
|
}
|
|
|
|
|
|
func (e *EnglishClassify) Delete() (err error) {
|
|
|
- tx, err := orm.NewOrmUsingDB("rddp").Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ tx := global.DbMap[utils.DbNameReport].Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
tx.Rollback()
|
|
@@ -560,14 +587,14 @@ func (e *EnglishClassify) Delete() (err error) {
|
|
|
tx.Commit()
|
|
|
}
|
|
|
}()
|
|
|
- _, err = tx.Delete(e)
|
|
|
+ err = tx.Delete(e).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
if e.Id == e.RootId {
|
|
|
// 删除一级分类时,删除其下所有子分类
|
|
|
sql := `DELETE FROM english_classify WHERE root_id = ?`
|
|
|
- _, err = tx.Raw(sql, e.Id).Exec()
|
|
|
+ err = tx.Exec(sql, e.Id).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -575,7 +602,7 @@ func (e *EnglishClassify) Delete() (err error) {
|
|
|
if e.ParentId == e.RootId {
|
|
|
// 删除二级分类时,更新其父级分类的子分类数量
|
|
|
sql := `DELETE FROM english_classify WHERE id = ? OR parent_id = ?`
|
|
|
- _, err = tx.Raw(sql, e.Id, e.ParentId).Exec()
|
|
|
+ err = tx.Exec(sql, e.Id, e.ParentId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -584,13 +611,16 @@ func (e *EnglishClassify) Delete() (err error) {
|
|
|
}
|
|
|
|
|
|
func AddEnglishClassify(item *EnglishClassify) (lastId int64, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- lastId, err = o.Insert(item)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Create(item).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ lastId = int64(item.Id)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ModifyEnglishClassify(item *EnglishClassify) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `UPDATE english_classify
|
|
|
SET
|
|
|
classify_name = ?,
|
|
@@ -599,129 +629,145 @@ func ModifyEnglishClassify(item *EnglishClassify) (err error) {
|
|
|
root_id = ?,
|
|
|
modify_time = ?
|
|
|
WHERE id = ? `
|
|
|
- _, err = o.Raw(sql, item.ClassifyName, item.Sort, item.ParentId, item.RootId, item.ModifyTime, item.Id).Exec()
|
|
|
+ err = o.Exec(sql, item.ClassifyName, item.Sort, item.ParentId, item.RootId, item.ModifyTime, item.Id).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdateEnglishClassifyRootIdByParentId 更新报告分类的顶级ID
|
|
|
func UpdateEnglishClassifyRootIdByParentId(parentId, rootId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := " UPDATE english_classify SET root_id = ? WHERE parent_id=? "
|
|
|
- _, err = o.Raw(sql, rootId, parentId).Exec()
|
|
|
+ err = o.Exec(sql, rootId, parentId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// UpdateClassify 更新分类
|
|
|
+// UpdateEnglishClassify 更新分类
|
|
|
func (classifyInfo *EnglishClassify) UpdateEnglishClassify(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- _, err = o.Update(classifyInfo, cols...)
|
|
|
-
|
|
|
+ err = global.DbMap[utils.DbNameReport].Select(cols).Updates(classifyInfo).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// DeleteEnglishClassify 删除英文分类
|
|
|
-func DeleteEnglishClassify(classifyId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := ` DELETE FROM english_classify WHERE id =? `
|
|
|
- _, err = o.Raw(sql, classifyId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func GetEnglishClassifyChildCounts(parentId int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=? `
|
|
|
- err = o.Raw(sql, parentId).QueryRow(&count)
|
|
|
- return
|
|
|
-}
|
|
|
+//func DeleteEnglishClassify(classifyId int) (err error) {
|
|
|
+// o := global.DbMap[utils.DbNameReport]
|
|
|
+// sql := ` DELETE FROM english_classify WHERE id =? `
|
|
|
+// _, err = o.Raw(sql, classifyId).Error
|
|
|
+// return
|
|
|
+//}
|
|
|
+
|
|
|
+//func GetEnglishClassifyChildCounts(parentId int) (count int, err error) {
|
|
|
+// o := global.DbMap[utils.DbNameReport]
|
|
|
+// sql := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=? `
|
|
|
+// err = o.Raw(sql, parentId).QueryRow(&count)
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
func GetEnglishReportCounts(classifyId, parentId int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ var countNull sql2.NullInt64
|
|
|
sql := ``
|
|
|
if parentId == 0 {
|
|
|
sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_first=? `
|
|
|
} else {
|
|
|
sql = `SELECT COUNT(1) AS count FROM english_report WHERE classify_id_second=? `
|
|
|
}
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, classifyId).Scan(&countNull).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countNull.Valid {
|
|
|
+ count = int(countNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishClassifyCountsByName(name string, parentId int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ var countNull sql2.NullInt64
|
|
|
sql := `SELECT COUNT(1) AS count FROM english_classify WHERE classify_name=? AND parent_id = ? `
|
|
|
- err = o.Raw(sql, name, parentId).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sql, name, parentId).Scan(&countNull).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countNull.Valid {
|
|
|
+ count = int(countNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEnglishFirstClassifyList 获取一级、二级分类列表
|
|
|
func GetEnglishFirstClassifyList() (items []*EnglishClassifyList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `SELECT * FROM english_classify WHERE parent_id=0 ORDER BY sort ASC,create_time`
|
|
|
- _, err = o.Raw(sql).QueryRows(&items)
|
|
|
+ err = o.Raw(sql).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEnglishSecondClassifyList 获取一级、二级分类列表
|
|
|
func GetEnglishSecondClassifyList(rootIds []int) (items []*EnglishClassifyList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `SELECT * FROM english_classify WHERE root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `) and parent_id>0 and root_id=parent_id ORDER BY sort ASC,create_time ASC`
|
|
|
- _, err = o.Raw(sql, rootIds).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, rootIds).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishFirstClassifyListCount() (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ var countNull sql2.NullInt64
|
|
|
sqlCount := `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0`
|
|
|
- err = o.Raw(sqlCount).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameReport].Raw(sqlCount).Scan(&countNull).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countNull.Valid {
|
|
|
+ count = int(countNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportClassifyById(classifyId int) (item *EnglishClassify, err error) {
|
|
|
sql := `SELECT * FROM english_classify WHERE id=?`
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&item)
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
+ err = o.Raw(sql, classifyId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEnglishReportClassifyByIds(classifyIds []int) (list []*EnglishClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
|
|
|
- _, err = o.Raw(sql, classifyIds).QueryRows(&list)
|
|
|
+ err = o.Raw(sql, classifyIds).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdateEnglishReportSecondClassifyNameByClassifyId 更新报告分类名称字段
|
|
|
-func UpdateEnglishReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := " UPDATE english_report SET classify_name_second = ? WHERE classify_id_second = ? "
|
|
|
- _, err = o.Raw(sql, classifyName, classifyId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
+//func UpdateEnglishReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
|
|
|
+// o := global.DbMap[utils.DbNameReport]
|
|
|
+// sql := " UPDATE english_report SET classify_name_second = ? WHERE classify_id_second = ? "
|
|
|
+// _, err = o.Raw(sql, classifyName, classifyId).Error
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
// UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
|
|
|
-func UpdateEnglishReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := " UPDATE english_report SET classify_name_first = ? WHERE classify_id_first = ? "
|
|
|
- _, err = o.Raw(sql, classifyName, classifyId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
+//func UpdateEnglishReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
|
|
|
+// o := global.DbMap[utils.DbNameReport]
|
|
|
+// sql := " UPDATE english_report SET classify_name_first = ? WHERE classify_id_first = ? "
|
|
|
+// _, err = o.Raw(sql, classifyName, classifyId).Error
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
// UpdateEnglishReportFirstClassifyNameByClassifyId 更新报告分类名称字段
|
|
|
-func UpdateEnglishReportByClassifyId(classifyFirstName, classifySecondName string, firstClassifyId, secondClassifyId int, ids string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := " UPDATE english_report SET classify_name_first = ?,classify_name_second = ?,classify_id_first=?, classify_id_second =? WHERE id IN (" + ids + ") "
|
|
|
- _, err = o.Raw(sql, classifyFirstName, classifySecondName, firstClassifyId, secondClassifyId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
+//func UpdateEnglishReportByClassifyId(classifyFirstName, classifySecondName string, firstClassifyId, secondClassifyId int, ids string) (err error) {
|
|
|
+// o := global.DbMap[utils.DbNameReport]
|
|
|
+// sql := " UPDATE english_report SET classify_name_first = ?,classify_name_second = ?,classify_id_first=?, classify_id_second =? WHERE id IN (" + ids + ") "
|
|
|
+// _, err = o.Raw(sql, classifyFirstName, classifySecondName, firstClassifyId, secondClassifyId).Error
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
func UpdateEnglishReportClassifyByFirstSecondClassifyId(classifyId, parentId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
// 更新相关联的二级分类的parentId,和classify_name_second
|
|
|
sql := `update english_report r
|
|
|
LEFT JOIN english_classify c ON r.classify_id_second = c.id
|
|
|
SET r.classify_id_first=c.parent_id, r.classify_name_second=c.classify_name
|
|
|
where (r.classify_id_first != c.parent_id or r.classify_name_second != c.classify_name) and r.classify_id_second =?`
|
|
|
- _, err = o.Raw(sql, classifyId).Exec()
|
|
|
+ err = o.Exec(sql, classifyId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -730,7 +776,7 @@ where (r.classify_id_first != c.parent_id or r.classify_name_second != c.classif
|
|
|
LEFT JOIN english_classify c ON r.classify_id_first = c.id
|
|
|
SET r.classify_name_first=c.classify_name
|
|
|
where r.classify_name_first != c.classify_name and r.classify_id_first=?`
|
|
|
- _, err = o.Raw(sql, parentId).Exec()
|
|
|
+ err = o.Exec(sql, parentId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -739,31 +785,29 @@ where r.classify_name_first != c.classify_name and r.classify_id_first=?`
|
|
|
LEFT JOIN english_classify c ON r.classify_id_first = c.id
|
|
|
SET r.classify_name_first=c.classify_name
|
|
|
where r.classify_name_first != c.classify_name and r.classify_id_first=?`
|
|
|
- _, err = o.Raw(sql, classifyId).Exec()
|
|
|
+ err = o.Exec(sql, classifyId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// FetchEnglishReportById 主键获取英文报告
|
|
|
-func FetchEnglishReportById(reportId int) (item *EnglishReport, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := `SELECT * FROM english_report WHERE id=?`
|
|
|
- err = o.Raw(sql, reportId).QueryRow(&item)
|
|
|
- return
|
|
|
-}
|
|
|
+//func FetchEnglishReportById(reportId int) (item *EnglishReport, err error) {
|
|
|
+// o := global.DbMap[utils.DbNameReport]
|
|
|
+// sql := `SELECT * FROM english_report WHERE id=?`
|
|
|
+// err = o.Raw(sql, reportId).QueryRow(&item)
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
// UpdateReport 更新英文报告
|
|
|
func (reportInfo *EnglishReport) UpdateReport(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- _, err = o.Update(reportInfo, cols...)
|
|
|
-
|
|
|
+ err = global.DbMap[utils.DbNameReport].Select(cols).Updates(reportInfo).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetAllEnglishClassify 获取所有英文分类
|
|
|
func GetAllEnglishClassify() (list []*Classify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := ` SELECT * FROM english_classify `
|
|
|
- _, err = o.Raw(sql).QueryRows(&list)
|
|
|
+ err = o.Raw(sql).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -777,9 +821,9 @@ func GetEnglishReportByIds(reportIds []int, fieldArr []string) (list []*EnglishR
|
|
|
if len(fieldArr) > 0 {
|
|
|
fields = strings.Join(fieldArr, ",")
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `SELECT ` + fields + ` FROM english_report WHERE id IN (` + utils.GetOrmInReplace(listLen) + `)`
|
|
|
- _, err = o.Raw(sql, reportIds).QueryRows(&list)
|
|
|
+ err = o.Raw(sql, reportIds).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -803,9 +847,9 @@ type EnglishClassifyNameParentName struct {
|
|
|
}
|
|
|
|
|
|
func GetEnglishClassifyByClassifyNameAndParentName(parentClassiyName, classifyName string) (item EnglishClassifyNameParentName, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := "SELECT c1.*, c2.classify_name as parent_classify_name FROM english_classify c1 LEFT JOIN english_classify c2 on c1.parent_id = c2.id where c1.parent_id > 0 and c2.classify_name = ? and c1.classify_name= ?"
|
|
|
- err = o.Raw(sql, parentClassiyName, classifyName).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, parentClassiyName, classifyName).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -839,9 +883,9 @@ func (m RSChildClassifyList) Swap(i, j int) {
|
|
|
|
|
|
// GetEnglishClassifyByClassifyNameParentId 获取英文分类
|
|
|
func GetEnglishClassifyByClassifyNameParentId(classifyName string, parentId int) (item *Classify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := ` SELECT * FROM english_classify where classify_name = ? and parent_id = ? `
|
|
|
- err = o.Raw(sql, classifyName, parentId).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, classifyName, parentId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -856,7 +900,7 @@ type EnglishClassifyFullName struct {
|
|
|
|
|
|
// GetEnglishClassifyFullNameByIds 获取英文分类名一级/二级/三级
|
|
|
func GetEnglishClassifyFullNameByIds(classifyIds []int) (list []*EnglishClassifyFullName, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := ` SELECT
|
|
|
a.id,
|
|
|
a.parent_id,
|
|
@@ -869,36 +913,36 @@ FROM
|
|
|
LEFT JOIN english_classify b ON a.root_id = b.id
|
|
|
LEFT JOIN english_classify c ON a.parent_id = c.id
|
|
|
where a.id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
|
|
|
- _, err = o.Raw(sql, classifyIds).QueryRows(&list)
|
|
|
+ err = o.Raw(sql, classifyIds).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *EnglishReport) GetItemById(id int) (item *EnglishReport, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
|
|
|
- err = o.Raw(sql, id).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, id).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEnglishClassifies 获取所有英文分类
|
|
|
func GetEnglishClassifies() (list []*EnglishClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := ` SELECT * FROM english_classify `
|
|
|
- _, err = o.Raw(sql).QueryRows(&list)
|
|
|
+ err = o.Raw(sql).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEnglishReportStateCount 获取指定状态的报告数量
|
|
|
func GetEnglishReportStateCount(state int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `SELECT COUNT(1) AS count FROM english_report WHERE state = ?`
|
|
|
- err = o.Raw(sql, state).QueryRow(&count)
|
|
|
+ err = o.Raw(sql, state).First(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdateEnglishReportsStateByCond 批量更新报告状态
|
|
|
func UpdateEnglishReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
cond := ``
|
|
|
if classifyFirstId > 0 {
|
|
|
cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
|
|
@@ -907,7 +951,7 @@ func UpdateEnglishReportsStateByCond(classifyFirstId, classifySecondId, oldState
|
|
|
cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
|
|
|
}
|
|
|
sql := fmt.Sprintf(`UPDATE english_report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
|
|
|
- _, err = o.Raw(sql, newState, oldState).Exec()
|
|
|
+ err = o.Exec(sql, newState, oldState).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -916,16 +960,16 @@ func UpdateEnglishReportsStateBySecondIds(oldState, newState int, secondIds []in
|
|
|
if len(secondIds) <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
// (有审批流的)未发布->待提交
|
|
|
sql := fmt.Sprintf(`UPDATE english_report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
|
|
|
- _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
|
|
|
+ err = o.Exec(sql, newState, oldState, secondIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
// (无审批流的)待提交->未发布
|
|
|
sql = fmt.Sprintf(`UPDATE english_report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
|
|
|
- _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
|
|
|
+ err = o.Exec(sql, oldState, newState, secondIds).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -935,11 +979,7 @@ type EnglishClassifySetEnabledReq struct {
|
|
|
}
|
|
|
|
|
|
func (classifyInfo *EnglishClassify) SetEnabled(id, enabled int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- to, err := o.Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ to := global.DbMap[utils.DbNameReport].Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
_ = to.Rollback()
|
|
@@ -948,12 +988,12 @@ func (classifyInfo *EnglishClassify) SetEnabled(id, enabled int) (err error) {
|
|
|
}
|
|
|
}()
|
|
|
sql := ` UPDATE english_classify SET enabled =? WHERE id = ?`
|
|
|
- _, err = to.Raw(sql, enabled, id).Exec()
|
|
|
+ err = to.Exec(sql, enabled, id).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
sql = ` UPDATE english_classify SET enabled =? WHERE parent_id = ? or root_id = ?`
|
|
|
- _, err = to.Raw(sql, enabled, id, id).Exec()
|
|
|
+ err = to.Exec(sql, enabled, id, id).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -961,16 +1001,16 @@ func (classifyInfo *EnglishClassify) SetEnabled(id, enabled int) (err error) {
|
|
|
}
|
|
|
|
|
|
func ModifyEnglishReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `UPDATE english_report SET detail_pdf_url=? WHERE id=? `
|
|
|
- _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
|
|
|
+ err = o.Exec(sql, detailPdfUrl, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ModifyEnglishReportImgUrl(reportId int, detailImgUrl string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `UPDATE english_report SET detail_img_url=? WHERE id=? `
|
|
|
- _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
|
|
|
+ err = o.Exec(sql, detailImgUrl, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1023,17 +1063,17 @@ func FormatEnglishReport2ListItem(origin *EnglishReport) (item *EnglishReportLis
|
|
|
|
|
|
// UpdateEnglishReportEmailHasFail 标记报告邮件发送失败
|
|
|
func UpdateEnglishReportEmailHasFail(reportId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `UPDATE english_report SET email_has_fail = 1 WHERE id = ?`
|
|
|
- _, err = o.Raw(sql, reportId).Exec()
|
|
|
+ err = o.Exec(sql, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdatePdfUrlEnglishReportById 清空pdf相关字段
|
|
|
func UpdatePdfUrlEnglishReportById(reportId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `UPDATE english_report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
|
|
|
- _, err = o.Raw(sql, reportId).Exec()
|
|
|
+ err = o.Exec(sql, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1041,13 +1081,13 @@ func GetEnglishReportFieldsByIds(ids []int, fields []string) (items []*EnglishRe
|
|
|
if len(ids) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
field := " * "
|
|
|
if len(fields) > 0 {
|
|
|
field = fmt.Sprintf(" %s ", strings.Join(fields, ","))
|
|
|
}
|
|
|
sql := fmt.Sprintf(`SELECT %s FROM english_report WHERE id IN (%s)`, field, utils.GetOrmInReplace(len(ids)))
|
|
|
- _, err = o.Raw(sql, ids).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, ids).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1055,10 +1095,10 @@ func GetExistEnglishReportClassifyIdByClassifyIds(classifyIds []int) (existClass
|
|
|
if len(classifyIds) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ o := global.DbMap[utils.DbNameReport]
|
|
|
sql := `SELECT classify_id_first, classify_id_second FROM english_report WHERE 1=1 `
|
|
|
sql += fmt.Sprintf(` AND (classify_id_first IN (%s) OR classify_id_second IN (%s))`, utils.GetOrmInReplace(len(classifyIds)), utils.GetOrmInReplace(len(classifyIds)))
|
|
|
|
|
|
- _, err = o.Raw(sql, classifyIds, classifyIds).QueryRows(&existClassifyIds)
|
|
|
+ err = o.Raw(sql, classifyIds, classifyIds).Find(&existClassifyIds).Error
|
|
|
return
|
|
|
}
|