|
@@ -1,9 +1,7 @@
|
|
|
package material
|
|
|
|
|
|
import (
|
|
|
- "eta/eta_api/models/system"
|
|
|
"eta/eta_api/utils"
|
|
|
- "fmt"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"time"
|
|
@@ -60,28 +58,6 @@ func AddMultiMaterial(materialInfoList []*Material) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// UpdateMaterial 更新素材
|
|
|
-func UpdateMaterial(materialInfo *Material, updateMaterialColumn []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- to, err := o.Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- _ = to.Rollback()
|
|
|
- } else {
|
|
|
- _ = to.Commit()
|
|
|
- }
|
|
|
- }()
|
|
|
-
|
|
|
- _, err = to.Update(materialInfo, updateMaterialColumn...)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
// MaterialListItem 素材推演列表数据
|
|
|
type MaterialListItem struct {
|
|
|
MaterialId int `description:"素材id"`
|
|
@@ -99,55 +75,6 @@ type MaterialSaveResp struct {
|
|
|
*Material
|
|
|
}
|
|
|
|
|
|
-func GetMaterialAll() (list []*MaterialClassifyItems, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := `SELECT material_id,classify_id,material_name AS classify_name, sort
|
|
|
- FROM material `
|
|
|
- _, err = o.Raw(sql).QueryRows(&list)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// CheckOpMaterialPermission 判断素材操作权限
|
|
|
-func CheckOpMaterialPermission(sysUser *system.Admin, createUserId int) (ok bool) {
|
|
|
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- // 如果图表创建人与当前操作人相同的话,那么就是允许操作
|
|
|
- if ok == false && createUserId == sysUser.AdminId {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// GetMaterialInfoByAdminId 获取所有我创建的素材,用于分类展示
|
|
|
-func GetMaterialInfoByAdminId(adminId int) (items []*MaterialClassifyItems, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := ` SELECT material_id,classify_id,material_name AS classify_name,code,
|
|
|
- sys_user_id,sys_user_real_name
|
|
|
- FROM material where sys_user_id = ? ORDER BY sort asc,create_time ASC `
|
|
|
- _, err = o.Raw(sql, adminId).QueryRows(&items)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func GetMaterialClassify(classifyId int) (classify_id string, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := `SELECT GROUP_CONCAT(t.classify_id) AS classify_id FROM (
|
|
|
- SELECT a.classify_id FROM material_classify AS a
|
|
|
- WHERE a.classify_id=?
|
|
|
- UNION ALL
|
|
|
- SELECT a.classify_id FROM material_classify AS a
|
|
|
- WHERE a.parent_id=? UNION ALL
|
|
|
- SELECT
|
|
|
- classify_id
|
|
|
- FROM
|
|
|
- material_classify
|
|
|
-WHERE
|
|
|
- parent_id IN ( SELECT classify_id FROM material_classify WHERE parent_id = ? )
|
|
|
- )AS t`
|
|
|
- err = o.Raw(sql, classifyId, classifyId, classifyId).QueryRow(&classify_id)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
type MaterialListItems struct {
|
|
|
Material
|
|
|
ModifyTime string `description:"修改时间"`
|
|
@@ -198,20 +125,6 @@ func AddMaterial(item *Material) (lastId int64, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-type MoveMaterialReq struct {
|
|
|
- MaterialId int `description:"素材ID"`
|
|
|
- PrevMaterialId int `description:"上一个素材ID"`
|
|
|
- NextMaterialId int `description:"下一个素材ID"`
|
|
|
- ClassifyId int `description:"分类id"`
|
|
|
-}
|
|
|
-
|
|
|
-func GetMaterialClassifyCountById(classifyId int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := `SELECT count(1) AS count FROM material_classify WHERE classify_id=? `
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&count)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
// GetMaterialByClassifyIdAndName 根据分类id和素材名获取图表信息
|
|
|
func GetMaterialByClassifyIdAndName(classifyId int, name string) (item *Material, err error) {
|
|
|
o := orm.NewOrmUsingDB("rddp")
|
|
@@ -228,31 +141,6 @@ func GetMaterialByIds(ids []int) (items []*MaterialListItems, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// UpdateMaterialSortByClassifyId 根据素材id更新排序
|
|
|
-func UpdateMaterialSortByClassifyId(classifyId, nowSort, prevMaterialId int, updateSort string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := ` UPDATE material set sort = ` + updateSort + ` WHERE classify_id=? AND `
|
|
|
- if prevMaterialId > 0 {
|
|
|
- sql += ` (sort > ? or (material_id > ` + fmt.Sprint(prevMaterialId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
|
|
|
- }
|
|
|
- _, err = o.Raw(sql, classifyId, nowSort).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// GetFirstMaterialByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
|
|
|
-func GetFirstMaterialByClassifyId(classifyId int) (item *Material, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := ` SELECT * FROM material WHERE classify_id=? order by sort asc,material_id asc limit 1`
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&item)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-type DetailParams struct {
|
|
|
- Code string `json:"code"`
|
|
|
- Id int `json:"id"`
|
|
|
- ClassifyId int `json:"classifyId"`
|
|
|
-}
|
|
|
-
|
|
|
// SaveAsMaterialReq 添加素材的请求数据
|
|
|
type SaveAsMaterialReq struct {
|
|
|
MaterialName string `description:"素材名称"`
|
|
@@ -348,20 +236,6 @@ func GetMaterialByNameEn(materialName string) (item *Material, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetMaterialCountByName(materialName string) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := `SELECT COUNT(1) AS count FROM material WHERE material_name=? `
|
|
|
- err = o.Raw(sql, materialName).QueryRow(&count)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func GetMaterialCountByNameEn(materialName string) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := `SELECT COUNT(1) AS count FROM material WHERE material_name_en=? `
|
|
|
- err = o.Raw(sql, materialName).QueryRow(&count)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
// GetMaterialMaxSort 获取最大的排序数
|
|
|
func GetMaterialMaxSort() (sort int, err error) {
|
|
|
o := orm.NewOrmUsingDB("rddp")
|