123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- package data_manage
- import (
- "eta/eta_api/utils"
- "fmt"
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- // BaseFromUsdaFasClassify UsdaFas原始数据分类表
- type BaseFromUsdaFasClassify struct {
- ClassifyId int `orm:"column(classify_id);pk"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id"`
- SysUserId int `description:"创建人id"`
- SysUserRealName string `description:"创建人姓名"`
- Level int `description:"层级"`
- Sort int `description:"排序字段,越小越靠前,默认值:10"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"创建时间"`
- }
- // AddBaseFromUsdaFasClassify 添加UsdaFas原始数据分类
- func AddBaseFromUsdaFasClassify(item *BaseFromUsdaFasClassify) (lastId int64, err error) {
- o := orm.NewOrmUsingDB("data")
- lastId, err = o.Insert(item)
- return
- }
- // GetBaseFromUsdaFasClassifyCount 获取分类名称的个数
- func GetBaseFromUsdaFasClassifyCount(classifyName string, parentId int) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT COUNT(1) AS count FROM base_from_usda_fas_classify WHERE classify_name=? AND parent_id=? `
- err = o.Raw(sql, classifyName, parentId).QueryRow(&count)
- return
- }
- // GetBaseFromUsdaFasClassifyById 通过分类id的获取分类信息
- func GetBaseFromUsdaFasClassifyById(classifyId int) (item *BaseFromUsdaFasClassify, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_usda_fas_classify WHERE classify_id=? `
- err = o.Raw(sql, classifyId).QueryRow(&item)
- return
- }
- // GetBaseFromUsdaFasClassifyById 通过分类id的获取分类信息
- func GetBaseFromUsdaFasClassifyByIds(classifyIds []int) (items []*BaseFromUsdaFasClassify, err error) {
- if len(classifyIds) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_usda_fas_classify WHERE classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) `
- _, err = o.Raw(sql, classifyIds).QueryRows(&items)
- return
- }
- // EditBaseFromUsdaFasClassify 修改UsdaFas原始数据分类
- func EditBaseFromUsdaFasClassify(classifyId int, classifyName string) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `UPDATE base_from_usda_fas_classify SET classify_name=?,modify_time=NOW() WHERE classify_id=? `
- _, err = o.Raw(sql, classifyName, classifyId).Exec()
- return
- }
- // UpdateBaseFromUsdaFasClassifySort 修改UsdaFas原始数据分类的排序
- func UpdateBaseFromUsdaFasClassifySort(classifyId int) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `UPDATE base_from_usda_fas_classify SET sort=classify_id, modify_time=NOW() WHERE classify_id=? `
- _, err = o.Raw(sql, classifyId).Exec()
- return
- }
- type BaseFromUsdaFasClassifyItems struct {
- ClassifyId int `description:"分类ID"`
- BaseFromUsdaFasIndexId int `description:"指标类型ID"`
- IndexCode string `description:"指标唯一编码"`
- ClassifyName string `description:"分类名称"`
- ClassifyNameEn string `description:"分类名称"`
- UniqueCode string `description:"分类唯一编码"`
- ParentId int `description:"父级id"`
- Level int `description:"层级"`
- Sort int `description:"排序字段,越小越靠前,默认值:10"`
- Children []*BaseFromUsdaFasClassifyItems
- }
- type BaseFromUsdaFasClassifyNameItems struct {
- ClassifyId int `description:"分类ID"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id"`
- }
- type BaseFromUsdaFasClassifyResp struct {
- List []*BaseFromUsdaFasClassifyItems
- }
- type BaseFromUsdaFasClassifyNameResp struct {
- List []*BaseFromUsdaFasClassifyNameItems
- }
- type BaseFromUsdaFasClassifyItemsButton struct {
- AddButton bool `description:"是否可添加"`
- OpButton bool `description:"是否可编辑"`
- DeleteButton bool `description:"是否可删除"`
- MoveButton bool `description:"是否可移动"`
- }
- // GetBaseFromUsdaFasClassifyByParentId 根据上级id获取当下的分类列表数据
- func GetBaseFromUsdaFasClassifyByParentId(parentId int) (items []*BaseFromUsdaFasClassifyItems, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_usda_fas_classify WHERE parent_id=? order by sort asc,classify_id asc`
- _, err = o.Raw(sql, parentId).QueryRows(&items)
- return
- }
- // GetAllBaseFromUsdaFasClassify 获取所有的分类列表数据
- func GetAllBaseFromUsdaFasClassify() (items []*BaseFromUsdaFasClassifyItems, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_usda_fas_classify order by parent_id asc, sort asc,classify_id asc`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type DeleteBaseFromUsdaFasClassifyReq struct {
- ClassifyId int `description:"分类id"`
- EdbInfoId int `description:"指标id"`
- }
- type BaseFromUsdaFasClassifyListResp struct {
- AllNodes []*BaseFromUsdaFasClassifyItems
- CanOpClassify bool `description:"是否允许操作分类"`
- }
- type BaseFromUsdaFasClassifySimplify struct {
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- ParentId int
- }
- // GetFirstBaseFromUsdaFasClassify 获取当前分类下,且排序数相同 的排序第一条的数据
- func GetFirstBaseFromUsdaFasClassify() (item *BaseFromUsdaFasClassify, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_usda_fas_classify order by sort asc,classify_id asc limit 1`
- err = o.Raw(sql).QueryRow(&item)
- return
- }
- // UpdateBaseFromUsdaFasClassifySortByClassifyId 根据分类id更新排序
- func UpdateBaseFromUsdaFasClassifySortByClassifyId(parentId, classifyId, nowSort int, updateSort string) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` update base_from_usda_fas_classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? `
- if classifyId > 0 {
- sql += ` or ( classify_id > ` + fmt.Sprint(classifyId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
- }
- _, err = o.Raw(sql, parentId, nowSort).Exec()
- return
- }
- // MoveUpUsdaFasIndexClassifyBySort 往上移动
- func MoveUpUsdaFasIndexClassifyBySort(parentId, nextSort, currentSort int) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `update base_from_usda_fas_classify set sort = sort + 1 where parent_id=? and sort >= ? and sort< ?`
- _, err = o.Raw(sql, parentId, nextSort, currentSort).Exec()
- return
- }
- // MoveDownUsdaFasIndexClassifyBySort 往下移动
- func MoveDownUsdaFasIndexClassifyBySort(parentId, prevSort, currentSort int) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `update base_from_usda_fas_classify set sort = sort - 1 where parent_id=? and sort <= ? and sort> ? `
- _, err = o.Raw(sql, parentId, prevSort, currentSort).Exec()
- return
- }
- // GetUsdaFasIndexClassifyMinSort 获取最小不等于0的排序
- func GetUsdaFasIndexClassifyMinSort(parentId int) (sort int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `select min(sort) from base_from_usda_fas_classify where parent_id=? and sort <> 0 `
- err = o.Raw(sql, parentId).QueryRow(&sort)
- return
- }
- // Update 更新分类基础信息
- func (BaseFromUsdaFasClassify *BaseFromUsdaFasClassify) Update(cols []string) (err error) {
- o := orm.NewOrmUsingDB("data")
- _, err = o.Update(BaseFromUsdaFasClassify, cols...)
- return
- }
- type AddUsdaFasClassifyResp struct {
- ClassifyId int
- }
- // DeleteUsdaFasClassifyByClassifyId 根据分类id删除对应的指标分类
- func DeleteUsdaFasClassifyByClassifyId(classifyIdList []int) (err error) {
- o := orm.NewOrmUsingDB("data")
- num := len(classifyIdList)
- if num <= 0 {
- return
- }
- //删除分类
- sql := `DELETE FROM base_from_usda_fas_classify WHERE classify_id IN (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, classifyIdList).Exec()
- return
- }
- // AddUsdaFasClassifyMulti 批量新增SMM类别
- func AddUsdaFasClassifyMulti(list []*BaseFromUsdaFasClassify) (err error) {
- o := orm.NewOrmUsingDB("data")
- _, err = o.InsertMulti(1, list)
- return
- }
- // InitUsdaFasClassifySort 初始化sort值
- func InitUsdaFasClassifySort() (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `UPDATE base_from_usda_fas_classify
- SET modify_time=NOW(), sort = classify_id`
- _, err = o.Raw(sql).Exec()
- return
- }
- // InitUsdaFasIndexClassifyId 历史数据的classifyId值
- func InitUsdaFasIndexClassifyId() (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `UPDATE base_from_UsdaFasindex s
- LEFT JOIN (
- SELECT
- c1.classify_id,
- CONCAT( c2.classify_name, c1.classify_name ) AS type_name
- FROM
- base_from_usda_fas_classify c1
- LEFT JOIN base_from_usda_fas_classify c2 ON c1.parent_id = c2.classify_id
- ) AS t ON CONCAT( s.type_2, s.type_3 ) = t.type_name
- SET s.classify_id = t.classify_id, s.modify_time=NOW() where s.type_2 <>""`
- _, err = o.Raw(sql).Exec()
- return
- }
|