|
@@ -1,15 +1,16 @@
|
|
|
package excel
|
|
|
|
|
|
import (
|
|
|
+ "eta/eta_chart_lib/global"
|
|
|
"eta/eta_chart_lib/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// ExcelInfo excel表格详情表
|
|
|
type ExcelInfo struct {
|
|
|
- ExcelInfoId int `orm:"column(excel_info_id);pk"`
|
|
|
+ //ExcelInfoId int `orm:"column(excel_info_id);pk"`
|
|
|
+ ExcelInfoId int `gorm:"column:excel_info_id;primaryKey"`
|
|
|
Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
|
|
|
ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
|
|
|
ExcelName string `description:"表格名称"`
|
|
@@ -34,13 +35,15 @@ type ExcelInfo struct {
|
|
|
|
|
|
// Update 更新 excel表格基础信息
|
|
|
func (excelInfo *ExcelInfo) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Update(excelInfo, cols...)
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
+ //_, err = o.Update(excelInfo, cols...)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Model(&excelInfo).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"`
|
|
|
+ ExcelInfoId int `gorm:"column:excel_info_id;primaryKey"`
|
|
|
Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
|
|
|
ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
|
|
|
ExcelName string `description:"表格名称"`
|
|
@@ -59,7 +62,8 @@ type MyExcelInfoList struct {
|
|
|
|
|
|
// AddExcelInfo 新增表格
|
|
|
func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+ //o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+ o := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -71,12 +75,15 @@ func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping)
|
|
|
}
|
|
|
}()
|
|
|
// 表格信息入库
|
|
|
- lastId, err := o.Insert(excelInfo)
|
|
|
+ //lastId, err := o.Insert(excelInfo)
|
|
|
+ //if err != nil {
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //excelInfo.ExcelInfoId = int(lastId)
|
|
|
+ err = o.Create(&excelInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- excelInfo.ExcelInfoId = int(lastId)
|
|
|
-
|
|
|
// excel与指标的关联关系
|
|
|
dataNum := len(excelEdbMappingList)
|
|
|
if dataNum > 0 {
|
|
@@ -84,7 +91,8 @@ func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping)
|
|
|
v.ExcelInfoId = excelInfo.ExcelInfoId
|
|
|
excelEdbMappingList[k] = v
|
|
|
}
|
|
|
- _, err = o.InsertMulti(dataNum, excelEdbMappingList)
|
|
|
+ //_, err = o.InsertMulti(dataNum, excelEdbMappingList)
|
|
|
+ err = o.CreateInBatches(excelEdbMappingList, dataNum).Error
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -92,7 +100,8 @@ func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping)
|
|
|
|
|
|
// EditExcelInfo 编辑表格
|
|
|
func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEdbMappingList []*ExcelEdbMapping) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+ //o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+ o := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -105,14 +114,16 @@ func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEd
|
|
|
}()
|
|
|
|
|
|
// ETA表格信息变更
|
|
|
- _, err = o.Update(excelInfo, updateExcelInfoParams...)
|
|
|
+ //_, err = o.Update(excelInfo, updateExcelInfoParams...)
|
|
|
+ err = o.Model(&excelInfo).Select(updateExcelInfoParams).Updates(&excelInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 删除关系表
|
|
|
sql := `DELETE FROM excel_edb_mapping WHERE excel_info_id=? `
|
|
|
- _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
|
|
|
+ //_, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
|
|
|
+ err = o.Exec(sql, excelInfo.ExcelInfoId).Error
|
|
|
|
|
|
// excel与指标的关联关系
|
|
|
dataNum := len(excelEdbMappingList)
|
|
@@ -121,7 +132,8 @@ func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEd
|
|
|
v.ExcelInfoId = excelInfo.ExcelInfoId
|
|
|
excelEdbMappingList[k] = v
|
|
|
}
|
|
|
- _, err = o.InsertMulti(dataNum, excelEdbMappingList)
|
|
|
+ //_, err = o.InsertMulti(dataNum, excelEdbMappingList)
|
|
|
+ err = o.CreateInBatches(excelEdbMappingList, dataNum).Error
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -129,17 +141,18 @@ func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEd
|
|
|
|
|
|
// GetExcelInfoAll 获取所有表格列表,用于分类展示
|
|
|
func GetExcelInfoAll() (items []*ExcelClassifyItems, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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,is_join_permission
|
|
|
FROM excel_info where is_delete=0 ORDER BY sort asc,create_time ASC `
|
|
|
- _, err = o.Raw(sql).QueryRows(&items)
|
|
|
+ //_, err = o.Raw(sql).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetNoContentExcelInfoAll 获取不含content的表格列表 用于分类展示
|
|
|
func GetNoContentExcelInfoAll(source, userId int) (items []*ExcelClassifyItems, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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 = ? `
|
|
@@ -151,53 +164,59 @@ 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 = o.Raw(sql, pars...).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetAllExcelInfoBySource 根据来源获取包含content的表格列表
|
|
|
func GetAllExcelInfoBySource(source int) (items []*ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info where is_delete=0 AND source = ? ORDER BY sort asc,create_time desc `
|
|
|
- _, err = o.Raw(sql, source).QueryRows(&items)
|
|
|
+ //_, err = o.Raw(sql, source).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, source).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetExcelInfoById 根据id 获取eta表格详情
|
|
|
func GetExcelInfoById(excelInfoId int) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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 = o.Raw(sql, excelInfoId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetExcelInfoByUnicode 编码获取表格
|
|
|
func GetExcelInfoByUnicode(unicode string) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE unique_code = ? AND is_delete = 0 `
|
|
|
- err = o.Raw(sql, unicode).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, unicode).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, unicode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetExcelInfoViewById(excelInfoId int) (item *ExcelInfoView, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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 = o.Raw(sql, excelInfoId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetExcelInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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 = 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")
|
|
|
+ //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 `
|
|
|
if condition != "" {
|
|
@@ -205,51 +224,57 @@ func GetNoContentExcelInfoListByCondition(condition string, pars []interface{},
|
|
|
}
|
|
|
|
|
|
sql += ` AND is_delete=0 ORDER BY excel_info_id DESC LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
+ //_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetNextExcelInfoByCondition 根据条件获取下一个表格
|
|
|
func GetNextExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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 = o.Raw(sql, pars).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetNextExcelInfo 根据分类id获取下一个excel表格
|
|
|
func GetNextExcelInfo(classifyId, classifySort, source int) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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 = 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
|
|
|
}
|
|
|
|
|
|
// EditExcelInfoImage 修改excel表格的图片
|
|
|
func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
|
|
|
sql := ` UPDATE excel_info SET excel_image=?, modify_time = NOW() WHERE excel_info_id = ? AND is_delete=0 `
|
|
|
- _, err = o.Raw(sql, imageUrl, excelInfoId).Exec()
|
|
|
+ //_, err = o.Raw(sql, imageUrl, excelInfoId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, imageUrl, excelInfoId).Error
|
|
|
if err != nil {
|
|
|
fmt.Println("EditExcelInfoImage Err:", err.Error())
|
|
|
return err
|
|
@@ -260,35 +285,39 @@ func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
|
|
|
|
|
|
// GetExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
|
|
|
func GetExcelInfoByUniqueCode(uniqueCode string) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE unique_code=? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, uniqueCode).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, uniqueCode).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, uniqueCode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetFirstExcelInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
|
|
|
func GetFirstExcelInfoByClassifyId(classifyId int) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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 = o.Raw(sql, classifyId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdateExcelInfoSortByClassifyId 根据表格id更新排序
|
|
|
func UpdateExcelInfoSortByClassifyId(classifyId, nowSort, prevExcelInfoId int, updateSort string, source int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` update excel_info set sort = ` + updateSort + ` WHERE excel_classify_id=? AND source=? AND is_delete=0 AND ( sort > ? `
|
|
|
// todo 前一个兄弟节点后移
|
|
|
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 = 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"`
|
|
|
+ ExcelInfoId int `gorm:"column:excel_info_id;primaryKey"`
|
|
|
ExcelName string `description:"来源名称"`
|
|
|
ExcelClassifyId int `description:"表格分类id"`
|
|
|
ExcelClassifyName string `description:"表格名称"`
|
|
@@ -321,15 +350,16 @@ type ExcelInfoView struct {
|
|
|
|
|
|
// GetExcelInfoByClassifyIdAndName 根据分类id和表格名获取表格信息
|
|
|
func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *ExcelInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM excel_info WHERE excel_classify_id = ? and excel_name=? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, classifyId, excelName).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, classifyId, excelName).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId, excelName).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetNoContentExcelListByCondition 获取没有content的excel表格列表数据
|
|
|
func GetNoContentExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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
|
|
|
FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
if condition != "" {
|
|
@@ -337,76 +367,84 @@ FROM excel_info WHERE 1=1 AND is_delete=0 `
|
|
|
}
|
|
|
//sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
|
|
|
sql += " ORDER BY create_time DESC LIMIT ?,? "
|
|
|
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
|
|
|
+ //_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
|
|
|
+ pars = append(pars, pageSize, startSize)
|
|
|
+ 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")
|
|
|
+ //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 = o.Raw(sql, pars).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Scan(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetExcelViewInfoByExcelInfoId 根据excelInfoId 获取ETA表格详情
|
|
|
func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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 FROM excel_info WHERE excel_info_id = ? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, excelInfoId).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, excelInfoId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetExcelInfoCountByClassifyId 根据分类id获取名下表格数量
|
|
|
func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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 = o.Raw(sql, classifyId).QueryRow(&total)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId).Count(&total).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdateExcelInfoClassifyId 更改表格分类
|
|
|
func UpdateExcelInfoClassifyId(classifyId, excelInfoId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` update excel_info set excel_classify_id = ? WHERE excel_info_id=? `
|
|
|
- _, err = o.Raw(sql, classifyId, excelInfoId).Exec()
|
|
|
-
|
|
|
+ //_, err = o.Raw(sql, classifyId, excelInfoId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, classifyId, excelInfoId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetNoContentExcelInfoByName 根据名称 获取eta表格详情
|
|
|
func GetNoContentExcelInfoByName(excelName string, source int) (item *MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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
|
|
|
FROM excel_info WHERE excel_name = ? AND source = ? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, excelName, source).QueryRow(&item)
|
|
|
-
|
|
|
+ //err = o.Raw(sql, excelName, source).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelName, source).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetNoContentExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
|
|
|
func GetNoContentExcelInfoByUniqueCode(uniqueCode string) (item *MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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
|
|
|
FROM excel_info WHERE unique_code=? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, uniqueCode).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, uniqueCode).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, uniqueCode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetNoContentExcelInfoByExcelId 根据表格id来获取excel表格详情
|
|
|
func GetNoContentExcelInfoByExcelId(excelInfoId int) (item *MyExcelInfoList, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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
|
|
|
FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
|
|
|
- err = o.Raw(sql, excelInfoId).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, excelInfoId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// AddExcelInfoAndSheet 新增excel
|
|
|
func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetParams) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+ //o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+ o := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -419,11 +457,15 @@ func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetP
|
|
|
}()
|
|
|
|
|
|
// 表格信息入库
|
|
|
- lastId, err := o.Insert(excelInfo)
|
|
|
+ //lastId, err := o.Insert(excelInfo)
|
|
|
+ //if err != nil {
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //excelInfo.ExcelInfoId = int(lastId)
|
|
|
+ err = o.Create(&excelInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- excelInfo.ExcelInfoId = int(lastId)
|
|
|
|
|
|
// sheet信息入库
|
|
|
for _, sheetInfo := range sheetParamsList {
|
|
@@ -442,12 +484,13 @@ func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetP
|
|
|
ModifyTime: time.Now(),
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
- sheetId, tmpErr := o.Insert(excelSheetInfo)
|
|
|
+ //sheetId, tmpErr := o.Insert(excelSheetInfo)
|
|
|
+ tmpErr := o.Create(&excelSheetInfo).Error
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
- excelSheetInfo.ExcelSheetId = int(sheetId)
|
|
|
+ //excelSheetInfo.ExcelSheetId = int(sheetId)
|
|
|
|
|
|
// data信息入库
|
|
|
if dataNum > 0 {
|
|
@@ -455,7 +498,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 = o.InsertMulti(dataNum, sheetInfo.DataList)
|
|
|
+ tmpErr = o.CreateInBatches(sheetInfo.DataList, dataNum).Error
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
@@ -468,7 +512,8 @@ func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetP
|
|
|
|
|
|
// SaveExcelInfoAndSheet 编辑保存
|
|
|
func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string, sheetParamsList []AddExcelSheetParams) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+ //o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+ o := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -481,21 +526,24 @@ func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string,
|
|
|
}()
|
|
|
|
|
|
// 表格信息入库
|
|
|
- _, err = o.Update(excelInfo, updateExcelInfoParam...)
|
|
|
+ //_, err = o.Update(excelInfo, updateExcelInfoParam...)
|
|
|
+ err = o.Model(&excelInfo).Select(updateExcelInfoParam).Updates(&excelInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 先删除历史的sheet信息
|
|
|
sql := `DELETE FROM excel_sheet WHERE excel_info_id = ?`
|
|
|
- _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
|
|
|
+ //_, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
|
|
|
+ err = o.Exec(sql, excelInfo.ExcelInfoId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 再删除历史sheet中的cell data信息
|
|
|
sql = `DELETE FROM excel_sheet_data WHERE excel_info_id = ?`
|
|
|
- _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
|
|
|
+ //_, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
|
|
|
+ err = o.Exec(sql, excelInfo.ExcelInfoId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -517,12 +565,13 @@ func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string,
|
|
|
ModifyTime: time.Now(),
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
- sheetId, tmpErr := o.Insert(excelSheetInfo)
|
|
|
+ //sheetId, tmpErr := o.Insert(excelSheetInfo)
|
|
|
+ tmpErr := o.Create(&excelSheetInfo).Error
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
- excelSheetInfo.ExcelSheetId = int(sheetId)
|
|
|
+ //excelSheetInfo.ExcelSheetId = int(sheetId)
|
|
|
|
|
|
// data信息入库
|
|
|
if dataNum > 0 {
|
|
@@ -530,7 +579,8 @@ func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string,
|
|
|
sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
|
|
|
sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
|
|
|
}
|
|
|
- _, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
|
|
|
+ //_, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
|
|
|
+ tmpErr = o.CreateInBatches(sheetInfo.DataList, dataNum).Error
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
@@ -551,9 +601,10 @@ type BatchRefreshExcelReq struct {
|
|
|
|
|
|
// GetExcelMaxSortByClassifyId 获取当前分类下,且排序数最大的excel
|
|
|
func GetExcelMaxSortByClassifyId(classifyId int, source int) (sort int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //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)
|
|
|
+ //err = o.Raw(sql, classifyId, source).QueryRow(&sort)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId, source).Scan(&sort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -567,10 +618,11 @@ 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)
|
|
|
-
|
|
|
+ //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)
|
|
|
+ sql := ` SELECT * FROM excel_info WHERE excel_info_id in ? order by excel_info_id DESC `
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, excelInfoIdList).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -584,10 +636,11 @@ func GetNoContentExcelListByUserId(userIdList []int) (items []*MyExcelInfoList,
|
|
|
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, userIdList).QueryRows(&items)
|
|
|
-
|
|
|
+ //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, userIdList).QueryRows(&items)
|
|
|
+ sql := ` SELECT * FROM excel_info WHERE excel_info_id in ? order by excel_info_id DESC `
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, userIdList).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -604,9 +657,11 @@ 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()
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
+ //sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) `
|
|
|
+ sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE excel_info_id in ? `
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, userId, userName, excelIdList).Error
|
|
|
+ //_, err = o.Raw(sql, userId, userName, excelIdList).Exec()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -623,15 +678,18 @@ 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()
|
|
|
+ //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) + `) `
|
|
|
+ sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in ?`
|
|
|
+ //_, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, userId, userName, oldUserIdList).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// ExcelInfoDetail excel表格详情(前端使用)
|
|
|
type ExcelInfoDetail struct {
|
|
|
- ExcelInfoId int `orm:"column(excel_info_id);pk"`
|
|
|
+ //ExcelInfoId int `orm:"column(excel_info_id);pk"`
|
|
|
+ ExcelInfoId int `gorm:"column:excel_info_id;primaryKey"`
|
|
|
Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
|
|
|
ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
|
|
|
ExcelName string `description:"表格名称"`
|