|
@@ -1,6 +1,7 @@
|
|
|
package excel
|
|
|
|
|
|
import (
|
|
|
+ "eta/eta_api/global"
|
|
|
"eta/eta_api/models/data_manage"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
@@ -11,7 +12,7 @@ import (
|
|
|
|
|
|
|
|
|
type ExcelInfo struct {
|
|
|
- ExcelInfoId int `orm:"column(excel_info_id);pk"`
|
|
|
+ ExcelInfoId int `orm:"column(excel_info_id);pk" gorm:"primaryKey" `
|
|
|
Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
|
|
|
ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
|
|
|
ExcelName string `description:"表格名称"`
|
|
@@ -39,13 +40,12 @@ type ExcelInfo struct {
|
|
|
|
|
|
|
|
|
func (excelInfo *ExcelInfo) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Update(excelInfo, cols...)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(excelInfo).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
type MyExcelInfoList struct {
|
|
|
- ExcelInfoId int `orm:"column(excel_info_id);pk"`
|
|
|
+ ExcelInfoId int `orm:"column(excel_info_id);pk" gorm:"primaryKey" `
|
|
|
Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
|
|
|
ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
|
|
|
ExcelName string `description:"表格名称"`
|
|
@@ -62,40 +62,38 @@ type MyExcelInfoList struct {
|
|
|
HaveOperaAuth bool `description:"是否有数据权限"`
|
|
|
UpdateUserId int `description:"更新人id"`
|
|
|
UpdateUserRealName string `description:"更新人真实姓名"`
|
|
|
- Button ExcelInfoDetailButton `description:"操作权限"`
|
|
|
+ Button ExcelInfoDetailButton `description:"操作权限" gorm:"-"`
|
|
|
CanEdit bool `description:"是否可编辑"`
|
|
|
Editor string `description:"编辑人"`
|
|
|
}
|
|
|
|
|
|
|
|
|
func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping, childExcel *ExcelInfo) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ to := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- _ = o.Rollback()
|
|
|
+ _ = to.Rollback()
|
|
|
} else {
|
|
|
- _ = o.Commit()
|
|
|
+ _ = to.Commit()
|
|
|
}
|
|
|
}()
|
|
|
+
|
|
|
|
|
|
- lastId, err := o.Insert(excelInfo)
|
|
|
+ err = to.Create(excelInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- excelInfo.ExcelInfoId = int(lastId)
|
|
|
+
|
|
|
|
|
|
if childExcel != nil {
|
|
|
|
|
|
childExcel.ParentId = excelInfo.ExcelInfoId
|
|
|
- childId, e := o.Insert(childExcel)
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("新增子表失败:%v", e)
|
|
|
+ err = to.Create(childExcel).Error
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("新增子表失败:%v", err)
|
|
|
return
|
|
|
}
|
|
|
- childExcel.ExcelInfoId = int(childId)
|
|
|
}
|
|
|
|
|
|
dataNum := len(excelEdbMappingList)
|
|
@@ -104,7 +102,7 @@ func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping,
|
|
|
v.ExcelInfoId = excelInfo.ExcelInfoId
|
|
|
excelEdbMappingList[k] = v
|
|
|
}
|
|
|
- _, err = o.InsertMulti(dataNum, excelEdbMappingList)
|
|
|
+ err = to.CreateInBatches(excelEdbMappingList, utils.MultiAddNum).Error
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -112,20 +110,17 @@ func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping,
|
|
|
|
|
|
|
|
|
func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEdbMappingList []*ExcelEdbMapping) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ to := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- _ = o.Rollback()
|
|
|
+ _ = to.Rollback()
|
|
|
} else {
|
|
|
- _ = o.Commit()
|
|
|
+ _ = to.Commit()
|
|
|
}
|
|
|
}()
|
|
|
-
|
|
|
|
|
|
- _, err = o.Update(excelInfo, updateExcelInfoParams...)
|
|
|
+ err = to.Select(updateExcelInfoParams).Updates(excelInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -133,11 +128,12 @@ func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEd
|
|
|
if excelInfo.Source == utils.BALANCE_TABLE && excelInfo.ParentId == 0 {
|
|
|
|
|
|
sql := `UPDATE FROM excel_info set excel_classify_id = ? WHERE parent_id=? `
|
|
|
- _, err = o.Raw(sql, excelInfo.ExcelClassifyId, excelInfo.ExcelInfoId).Exec()
|
|
|
+ err = to.Exec(sql, excelInfo.ExcelClassifyId, excelInfo.ExcelInfoId).Error
|
|
|
}
|
|
|
|
|
|
+
|
|
|
sql := `DELETE FROM excel_edb_mapping WHERE excel_info_id=? `
|
|
|
- _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
|
|
|
+ err = to.Exec(sql, excelInfo.ExcelInfoId).Error
|
|
|
|
|
|
|
|
|
dataNum := len(excelEdbMappingList)
|
|
@@ -146,7 +142,7 @@ func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEd
|
|
|
v.ExcelInfoId = excelInfo.ExcelInfoId
|
|
|
excelEdbMappingList[k] = v
|
|
|
}
|
|
|
- _, err = o.InsertMulti(dataNum, excelEdbMappingList)
|
|
|
+ err = to.CreateInBatches(excelEdbMappingList, utils.MultiAddNum).Error
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -164,7 +160,6 @@ func GetExcelInfoAll() (items []*ExcelClassifyItems, err error) {
|
|
|
|
|
|
|
|
|
func GetNoContentExcelInfoAll(source, userId int) (items []*ExcelClassifyItems, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
|
|
|
unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission
|
|
|
FROM excel_info where is_delete=0 AND source = ? `
|
|
@@ -176,13 +171,12 @@ func GetNoContentExcelInfoAll(source, userId int) (items []*ExcelClassifyItems,
|
|
|
pars = append(pars, userId)
|
|
|
}
|
|
|
sql += ` ORDER BY sort asc,excel_info_id desc `
|
|
|
- _, err = o.Raw(sql, pars...).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func GetBalanceNoContentExcelInfoAll(source int, excelInfoIds []int, userId int) (items []*ExcelClassifyItems, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
|
|
|
unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission
|
|
|
FROM excel_info where is_delete=0 AND source = ? AND parent_id = 0 AND balance_type=0 `
|
|
@@ -200,7 +194,7 @@ func GetBalanceNoContentExcelInfoAll(source int, excelInfoIds []int, userId int)
|
|
|
}
|
|
|
|
|
|
sql += ` ORDER BY sort asc,excel_info_id desc `
|
|
|
- _, err = o.Raw(sql, pars...).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -214,17 +208,15 @@ func GetAllExcelInfoBySource(source int) (items []*ExcelInfo, err error) {
|
|
|
|
|
|
|
|
|
func GetExcelInfoById(excelInfoId int) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, excelInfoId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func GetExcelInfoByUnicode(unicode string) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE unique_code = ? AND is_delete = 0 `
|
|
|
- err = o.Raw(sql, unicode).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, unicode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -236,74 +228,72 @@ func GetExcelInfoViewById(excelInfoId int) (item *ExcelInfoView, err error) {
|
|
|
}
|
|
|
|
|
|
func GetExcelInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Scan(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetNoContentExcelInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ExcelClassifyItems, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
|
|
|
- unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission FROM excel_info WHERE 1=1 `
|
|
|
+ unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission FROM excel_info WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
|
|
|
sql += ` AND is_delete=0 ORDER BY excel_info_id DESC LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
+
|
|
|
+ pars = append(pars, startSize)
|
|
|
+ pars = append(pars, pageSize)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetNoContentExcelInfoListByConditionNoPage(condition string, pars []interface{}) (items []*ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT excel_info_id,excel_classify_id,excel_name,
|
|
|
- unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission, parent_id, balance_type, update_user_id,update_user_real_name,rel_excel_info_id,version_name FROM excel_info WHERE is_delete=0 `
|
|
|
+ unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission, parent_id, balance_type, update_user_id,update_user_real_name,rel_excel_info_id,version_name FROM excel_info WHERE is_delete=0 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
|
|
|
sql += ` ORDER BY excel_info_id DESC `
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetExcelInfoListByCondition(condition string, pars []interface{}) (items []*ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` ORDER BY sort asc, excel_info_id asc`
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func GetNextExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += " ORDER BY sort asc , create_time desc LIMIT 1 "
|
|
|
- err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func GetNextExcelInfo(classifyId, classifySort, source int) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT b.* FROM excel_classify AS a
|
|
|
INNER JOIN excel_info AS b ON a.excel_classify_id=b.excel_classify_id
|
|
|
WHERE (a.sort>? OR (a.sort=? and a.excel_classify_id>?) ) AND a.is_delete=0 AND b.is_delete=0
|
|
|
AND a.source = ? AND b.source = ?
|
|
|
ORDER BY a.sort ASC,b.sort asc,b.create_time desc
|
|
|
LIMIT 1 `
|
|
|
- err = o.Raw(sql, classifySort, classifySort, classifyId, source, source).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifySort, classifySort, classifyId, source, source).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -323,35 +313,32 @@ func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
|
|
|
|
|
|
|
|
|
func GetExcelInfoByUniqueCode(uniqueCode string) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE unique_code=? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, uniqueCode).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, uniqueCode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func GetFirstExcelInfoByClassifyId(classifyId int) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE excel_classify_id=? AND is_delete=0 order by sort asc,excel_info_id desc limit 1`
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func UpdateExcelInfoSortByClassifyId(classifyId, nowSort, prevExcelInfoId int, updateSort string, source int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` update excel_info set sort = ` + updateSort + ` WHERE excel_classify_id=? AND source=? AND is_delete=0 AND ( sort > ? `
|
|
|
|
|
|
if prevExcelInfoId > 0 {
|
|
|
sql += ` or (excel_info_id < ` + fmt.Sprint(prevExcelInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
|
|
|
}
|
|
|
sql += `)`
|
|
|
- _, err = o.Raw(sql, classifyId, source, nowSort).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, classifyId, source, nowSort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
type ExcelInfoView struct {
|
|
|
- ExcelInfoId int `orm:"column(excel_info_id);pk"`
|
|
|
+ ExcelInfoId int `orm:"column(excel_info_id);pk" gorm:"primaryKey" `
|
|
|
ExcelName string `description:"来源名称"`
|
|
|
ExcelClassifyId int `description:"表格分类id"`
|
|
|
ExcelClassifyName string `description:"表格名称"`
|
|
@@ -392,39 +379,39 @@ func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *Ex
|
|
|
|
|
|
|
|
|
func GetNoContentExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name,excel_image,file_url,sort,create_time,modify_time,is_join_permission,update_user_id,update_user_real_name
|
|
|
-FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
+ FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
|
|
|
sql += " ORDER BY create_time DESC LIMIT ?,? "
|
|
|
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
|
|
|
+
|
|
|
+ pars = append(pars, startSize)
|
|
|
+ pars = append(pars, pageSize)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func GetNoContentExcelListByConditionNoPage(condition string, pars []interface{}) (item []*MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name,excel_image,file_url,sort,create_time,modify_time,is_join_permission,update_user_id,update_user_real_name
|
|
|
-FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
+ FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
|
|
|
sql += " ORDER BY create_time DESC"
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetExcelListCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Scan(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -438,9 +425,8 @@ func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err
|
|
|
|
|
|
|
|
|
func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT count(1) total FROM excel_info WHERE excel_classify_id = ? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&total)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId).First(&total).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -455,53 +441,45 @@ func UpdateExcelInfoClassifyId(classifyId, excelInfoId int) (err error) {
|
|
|
|
|
|
|
|
|
func GetNoContentExcelInfoByName(excelName string, source, adminId int) (item *MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name,excel_image,file_url,sort,create_time,modify_time,is_join_permission,update_user_id,update_user_real_name
|
|
|
- FROM excel_info WHERE excel_name = ? AND source = ? AND is_delete=0 AND sys_user_id = ? `
|
|
|
- err = o.Raw(sql, excelName, source, adminId).QueryRow(&item)
|
|
|
-
|
|
|
+ FROM excel_info WHERE excel_name = ? AND source = ? AND is_delete=0 AND sys_user_id = ? `
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelName, source, adminId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func GetNoContentExcelInfoByUniqueCode(uniqueCode string) (item *MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name,excel_image,file_url,sort,create_time,modify_time,is_join_permission,update_user_id,update_user_real_name
|
|
|
- FROM excel_info WHERE unique_code=? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, uniqueCode).QueryRow(&item)
|
|
|
+ FROM excel_info WHERE unique_code=? AND is_delete=0 `
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, uniqueCode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func GetNoContentExcelInfoByExcelId(excelInfoId int) (item *MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name,excel_image,file_url,sort,create_time,modify_time,is_join_permission,update_user_id,update_user_real_name
|
|
|
- FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, excelInfoId).QueryRow(&item)
|
|
|
+ FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetParams) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ to := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- _ = o.Rollback()
|
|
|
+ _ = to.Rollback()
|
|
|
} else {
|
|
|
- _ = o.Commit()
|
|
|
+ _ = to.Commit()
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
|
|
|
- lastId, err := o.Insert(excelInfo)
|
|
|
+ err = to.Create(excelInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- excelInfo.ExcelInfoId = int(lastId)
|
|
|
-
|
|
|
|
|
|
for _, sheetInfo := range sheetParamsList {
|
|
|
dataNum := len(sheetInfo.DataList)
|
|
@@ -519,12 +497,12 @@ func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetP
|
|
|
ModifyTime: time.Now(),
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
- sheetId, tmpErr := o.Insert(excelSheetInfo)
|
|
|
+
|
|
|
+ tmpErr := to.Create(excelSheetInfo).Error
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
- excelSheetInfo.ExcelSheetId = int(sheetId)
|
|
|
|
|
|
|
|
|
if dataNum > 0 {
|
|
@@ -532,7 +510,8 @@ func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetP
|
|
|
sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
|
|
|
sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
|
|
|
}
|
|
|
- _, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
|
|
|
+
|
|
|
+ tmpErr = to.CreateInBatches(sheetInfo.DataList, utils.MultiAddNum).Error
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
@@ -545,34 +524,33 @@ func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetP
|
|
|
|
|
|
|
|
|
func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string, sheetParamsList []AddExcelSheetParams) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ to := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- _ = o.Rollback()
|
|
|
+ _ = to.Rollback()
|
|
|
} else {
|
|
|
- _ = o.Commit()
|
|
|
+ _ = to.Commit()
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
|
|
|
- _, err = o.Update(excelInfo, updateExcelInfoParam...)
|
|
|
+ err = to.Select(updateExcelInfoParam).Updates(excelInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
sql := `DELETE FROM excel_sheet WHERE excel_info_id = ?`
|
|
|
- _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
|
|
|
+ err = to.Exec(sql, excelInfo.ExcelInfoId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
sql = `DELETE FROM excel_sheet_data WHERE excel_info_id = ?`
|
|
|
- _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
|
|
|
+ err = to.Exec(sql, excelInfo.ExcelInfoId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -594,24 +572,19 @@ func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string,
|
|
|
ModifyTime: time.Now(),
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
- sheetId, tmpErr := o.Insert(excelSheetInfo)
|
|
|
+
|
|
|
+ tmpErr := to.Create(excelSheetInfo).Error
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
- excelSheetInfo.ExcelSheetId = int(sheetId)
|
|
|
-
|
|
|
|
|
|
if dataNum > 0 {
|
|
|
for k, _ := range sheetInfo.DataList {
|
|
|
sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
|
|
|
sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
|
|
|
}
|
|
|
- _, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
+ tmpErr = to.CreateInBatches(sheetInfo.DataList, utils.MultiAddNum).Error
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -628,9 +601,8 @@ type BatchRefreshExcelReq struct {
|
|
|
|
|
|
|
|
|
func GetExcelMaxSortByClassifyId(classifyId int, source int) (sort int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- sql := ` SELECT Max(sort) AS sort FROM excel_info WHERE excel_classify_id=? AND source = ? AND is_delete=0 order by sort desc,excel_info_id desc limit 1`
|
|
|
- err = o.Raw(sql, classifyId, source).QueryRow(&sort)
|
|
|
+ sql := ` SELECT COALESCE(MAX(sort),0) AS sort FROM excel_info WHERE excel_classify_id=? AND source = ? AND is_delete=0 order by sort desc,excel_info_id desc limit 1`
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId, source).Scan(&sort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -644,10 +616,8 @@ func GetNoContentExcelListByExcelInfoIdList(excelInfoIdList []string) (items []*
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
|
|
|
- _, err = o.Raw(sql, excelInfoIdList).QueryRows(&items)
|
|
|
-
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoIdList).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -656,10 +626,8 @@ func GetNoContentExcelListByExcelInfoIdAndParentId(excelInfoIdList []string) (it
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) OR parent_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
|
|
|
- _, err = o.Raw(sql, excelInfoIdList, excelInfoIdList).QueryRows(&items)
|
|
|
-
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoIdList, excelInfoIdList).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -673,9 +641,8 @@ func GetNoContentExcelListByUserId(userIdList []int) (items []*MyExcelInfoList,
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
|
|
|
- _, err = o.Raw(sql, userIdList).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, userIdList).Find(&items).Error
|
|
|
|
|
|
return
|
|
|
}
|
|
@@ -693,9 +660,8 @@ func ModifyExcelInfoUserIdByCodeList(excelIdList []string, userId int, userName
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) `
|
|
|
- _, err = o.Raw(sql, userId, userName, excelIdList).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, userId, userName, excelIdList).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -712,9 +678,9 @@ func ModifyExcelInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+
|
|
|
sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
|
|
|
- _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, userId, userName, oldUserIdList).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -723,10 +689,9 @@ func GetExcelBaseInfoByExcelInfoIdList(excelInfoIdList []int) (items []*data_man
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
|
|
|
- _, err = o.Raw(sql, excelInfoIdList).QueryRows(&items)
|
|
|
|
|
|
+ sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoIdList).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -735,11 +700,8 @@ func ReplaceEdbInExcel(oldEdbInfoId, newEdbInfoId int, updateExcelList []*ExcelI
|
|
|
var errmsg string
|
|
|
logMsg := ``
|
|
|
replaceTotal := 0
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- to, err := o.Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ to := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
_ = to.Rollback()
|
|
@@ -760,7 +722,7 @@ func ReplaceEdbInExcel(oldEdbInfoId, newEdbInfoId int, updateExcelList []*ExcelI
|
|
|
for _, excelInfo := range updateExcelList {
|
|
|
|
|
|
sql := `UPDATE excel_info SET content=?, modify_time=? WHERE excel_info_id=?`
|
|
|
- _, err = to.Raw(sql, excelInfo.Content, time.Now(), excelInfo.ExcelInfoId).Exec()
|
|
|
+ err = to.Exec(sql, excelInfo.Content, time.Now(), excelInfo.ExcelInfoId).Error
|
|
|
if err != nil {
|
|
|
errmsg = "更新表格内容失败:Err:" + err.Error()
|
|
|
return
|
|
@@ -768,14 +730,14 @@ func ReplaceEdbInExcel(oldEdbInfoId, newEdbInfoId int, updateExcelList []*ExcelI
|
|
|
|
|
|
|
|
|
sql = `DELETE FROM excel_edb_mapping WHERE excel_info_id=? and edb_info_id=?`
|
|
|
- _, err = to.Raw(sql, excelInfo.ExcelInfoId, newEdbInfoId).Exec()
|
|
|
+ err = to.Exec(sql, excelInfo.ExcelInfoId, newEdbInfoId).Error
|
|
|
if err != nil {
|
|
|
errmsg = "删除指标B关联图表配置信息失败:Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
sql = `UPDATE excel_edb_mapping SET edb_info_id=?, modify_time=? WHERE excel_info_id=? and edb_info_id=?`
|
|
|
- _, err = to.Raw(sql, newEdbInfoId, time.Now(), excelInfo.ExcelInfoId, oldEdbInfoId).Exec()
|
|
|
+ err = to.Exec(sql, newEdbInfoId, time.Now(), excelInfo.ExcelInfoId, oldEdbInfoId).Error
|
|
|
if err != nil {
|
|
|
errmsg = "更新指标B关联图表配置信息失败:Err:" + err.Error()
|
|
|
return
|
|
@@ -788,9 +750,8 @@ func ReplaceEdbInExcel(oldEdbInfoId, newEdbInfoId int, updateExcelList []*ExcelI
|
|
|
|
|
|
|
|
|
func GetChildExcelInfoByParentId(parentId int) (items []*ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name,excel_image,file_url,sort,create_time,modify_time,is_join_permission, parent_id, balance_type, update_user_id,update_user_real_name FROM excel_info WHERE parent_id=? AND is_delete=0 order by sort asc, excel_info_id asc`
|
|
|
- _, err = o.Raw(sql, parentId).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, parentId).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -810,9 +771,8 @@ func UpdateExcelInfoClassifyIdByIds(classifyId int, excelIds []int) (err error)
|
|
|
if len(excelIds) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := fmt.Sprintf(`UPDATE excel_info SET excel_classify_id = ? WHERE excel_info_id IN (%s)`, utils.GetOrmInReplace(len(excelIds)))
|
|
|
- _, err = o.Raw(sql, classifyId, excelIds).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, classifyId, excelIds).Error
|
|
|
return
|
|
|
}
|
|
|
|