2023-06-16 15:11:37 +08:00
package gmodel
import (
"context"
)
2023-11-21 11:45:12 +08:00
func ( t * FsProductTemplateV2Model ) FindAll ( ctx context . Context ) ( resp [ ] FsProductTemplateV2 , err error ) {
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Find ( & resp ) . Error
return resp , err
}
2023-08-17 18:19:15 +08:00
func ( t * FsProductTemplateV2Model ) FindAllByProductIds ( ctx context . Context , productIds [ ] int64 , sort string , fields ... string ) ( resp [ ] FsProductTemplateV2 , err error ) {
2023-06-16 15:11:37 +08:00
if len ( productIds ) == 0 {
return
}
2023-07-17 11:42:29 +08:00
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`product_id` in (?) and `is_del` = ? and `status` = ?" , productIds , 0 , 1 )
2023-08-17 18:19:15 +08:00
if sort != "" {
db = db . Order ( sort )
}
2023-07-17 11:42:29 +08:00
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
2023-06-16 15:11:37 +08:00
}
2023-07-17 11:42:29 +08:00
err = db . Find ( & resp ) . Error
return resp , err
2023-06-16 15:11:37 +08:00
}
2023-10-17 15:33:46 +08:00
func ( t * FsProductTemplateV2Model ) FindAllByIds ( ctx context . Context , ids [ ] int64 , fields ... string ) ( resp [ ] FsProductTemplateV2 , err error ) {
2023-06-19 12:23:02 +08:00
if len ( ids ) == 0 {
return
}
2023-10-17 15:33:46 +08:00
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`id` in (?) and `is_del` = ? and `status` = ?" , ids , 0 , 1 )
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
2023-06-19 12:23:02 +08:00
}
2023-10-17 15:33:46 +08:00
err = db . Find ( & resp ) . Error
return resp , err
2023-06-19 12:23:02 +08:00
}
2023-07-04 16:48:56 +08:00
func ( t * FsProductTemplateV2Model ) FindAllByIdsWithoutStatus ( ctx context . Context , ids [ ] int64 , fields ... string ) ( resp [ ] FsProductTemplateV2 , err error ) {
2023-06-27 17:04:58 +08:00
if len ( ids ) == 0 {
return
}
2023-07-04 16:48:56 +08:00
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`id` in (?) " , ids )
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
2023-06-27 17:04:58 +08:00
}
2023-07-04 16:48:56 +08:00
err = db . Find ( & resp ) . Error
return resp , err
2023-06-27 17:04:58 +08:00
}
2023-06-20 17:28:28 +08:00
func ( t * FsProductTemplateV2Model ) FindOne ( ctx context . Context , id int64 ) ( resp * FsProductTemplateV2 , err error ) {
2023-06-19 12:23:02 +08:00
2023-08-18 12:18:56 +08:00
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`id` = ? " , id ) . Take ( & resp ) . Error
2023-06-20 17:28:28 +08:00
return resp , err
2023-06-19 12:23:02 +08:00
}
2023-06-20 19:56:18 +08:00
func ( t * FsProductTemplateV2Model ) FindByParam ( ctx context . Context , id int64 , modelId int64 , fields ... string ) ( resp * FsProductTemplateV2 , err error ) {
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`id` = ? and `model_id` = ?" , id , modelId )
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
}
err = db . Take ( & resp ) . Error
return resp , err
}
2023-06-25 12:16:01 +08:00
func ( t * FsProductTemplateV2Model ) Update ( ctx context . Context , id int64 , data * FsProductTemplateV2 ) error {
return t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`id` = ? " , id ) . Updates ( & data ) . Error
}
2023-07-17 14:40:24 +08:00
func ( t * FsProductTemplateV2Model ) FindAllByModelIds ( ctx context . Context , modelIds [ ] int64 , orderBy string , fields ... string ) ( resp [ ] FsProductTemplateV2 , err error ) {
2023-06-25 17:11:42 +08:00
if len ( modelIds ) == 0 {
return
}
2023-07-17 14:40:24 +08:00
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`model_id` in (?) and `is_del` = ? and `status` = ?" , modelIds , 0 , 1 )
2023-08-08 17:03:54 +08:00
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
}
2023-07-17 14:40:24 +08:00
switch orderBy {
case "" :
db = db . Order ( "id DESC" )
default :
db = db . Order ( orderBy )
2023-06-25 17:11:42 +08:00
}
2023-07-17 14:40:24 +08:00
err = db . Find ( & resp ) . Error
return resp , err
2023-06-25 17:11:42 +08:00
}
2023-07-06 17:43:07 +08:00
func ( t * FsProductTemplateV2Model ) FindAllByProductIdModelIds ( ctx context . Context , modelIds [ ] int64 , productId int64 ) ( resp [ ] FsProductTemplateV2 , err error ) {
if len ( modelIds ) == 0 {
2023-07-04 16:48:56 +08:00
return
}
2023-07-06 17:55:59 +08:00
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`model_id` in (?) and `product_id` = ? " , modelIds , productId ) . Find ( & resp ) . Error
2023-07-06 17:43:07 +08:00
return resp , err
}
func ( t * FsProductTemplateV2Model ) FindOneByModelId ( ctx context . Context , modelId int64 ) ( resp * FsProductTemplateV2 , err error ) {
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`model_id` = ? " , modelId ) . Take ( & resp ) . Error
2023-07-04 16:48:56 +08:00
return resp , err
}
2023-07-11 11:28:57 +08:00
type GetProductTemplateListByParamsReq struct {
2023-07-11 15:01:08 +08:00
ProductIds [ ] int64 //必传哦
2023-07-11 17:08:19 +08:00
GroupBy string
OrderBy string
Fields string
Status * int64
2023-07-11 11:28:57 +08:00
}
2023-07-11 17:08:19 +08:00
2023-07-11 11:28:57 +08:00
func ( t * FsProductTemplateV2Model ) GetProductTemplateListByParams ( ctx context . Context , req GetProductTemplateListByParamsReq ) ( resp [ ] FsProductTemplateV2 , err error ) {
2023-07-11 17:08:19 +08:00
if len ( req . ProductIds ) == 0 {
2023-07-11 15:01:08 +08:00
return
2023-07-11 11:28:57 +08:00
}
2023-07-11 17:08:19 +08:00
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`product_id` in (?)" , req . ProductIds )
if req . GroupBy != "" {
2023-07-11 11:28:57 +08:00
db = db . Group ( req . GroupBy )
}
2023-07-11 17:08:19 +08:00
if req . OrderBy != "" {
2023-07-11 11:28:57 +08:00
db = db . Order ( req . OrderBy )
}
2023-07-11 17:08:19 +08:00
if req . Fields != "" {
2023-07-11 11:28:57 +08:00
db = db . Select ( req . Fields )
}
2023-07-11 17:08:19 +08:00
if req . Status != nil {
db = db . Where ( "`status` = ?" , req . Status )
2023-07-11 11:28:57 +08:00
}
err = db . Find ( & resp ) . Error
return resp , err
2023-07-11 17:08:19 +08:00
}
2023-08-08 12:22:15 +08:00
2023-09-01 15:48:47 +08:00
// 获取开启云渲染模板
func ( t * FsProductTemplateV2Model ) FindOneCloudRenderByProductIdModelIdTemplateTag ( ctx context . Context , productId , modelId int64 , templateTag string ) ( resp * FsProductTemplateV2 , err error ) {
2023-08-22 17:12:30 +08:00
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) .
2023-09-12 17:05:41 +08:00
Where ( "product_id = ? and model_id = ? and template_tag = ? " , productId , modelId , templateTag ) .
2023-09-01 15:48:47 +08:00
Where ( "status = ? and is_del = ?" , 1 , 0 ) .
Order ( "sort ASC" ) .
Take ( & resp ) . Error
return resp , err
}
// 获取开启云渲染模板2
2023-09-12 17:26:44 +08:00
func ( t * FsProductTemplateV2Model ) FindOneCloudRenderByProductIdTemplateTag ( ctx context . Context , productId int64 , templateTag string , sort string , fields ... string ) ( resp * FsProductTemplateV2 , err error ) {
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) .
2023-09-01 15:55:22 +08:00
Where ( "product_id = ? and template_tag = ? and element_model_id > ? " , productId , templateTag , 0 ) .
2023-09-12 17:26:44 +08:00
Where ( "status = ? and is_del = ?" , 1 , 0 )
if sort != "" {
db = db . Order ( sort )
}
if len ( fields ) > 0 {
db = db . Select ( fields [ 0 ] )
}
err = db . Take ( & resp ) . Error
2023-08-08 12:22:15 +08:00
return resp , err
}
2023-08-08 17:03:54 +08:00
func ( t * FsProductTemplateV2Model ) FindAllByModelIdsTemplateTag ( ctx context . Context , modelIds [ ] int64 , templateTag string , orderBy string , fields ... string ) ( resp [ ] FsProductTemplateV2 , err error ) {
if len ( modelIds ) == 0 {
return
}
2023-08-17 11:09:59 +08:00
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`model_id` in (?) and `template_tag` = ? and `is_del` = ? and `status` = ?" , modelIds , templateTag , 0 , 1 )
2023-08-08 17:03:54 +08:00
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
}
switch orderBy {
case "" :
db = db . Order ( "id DESC" )
default :
db = db . Order ( orderBy )
}
err = db . Find ( & resp ) . Error
return resp , err
}
2023-08-11 14:52:16 +08:00
// 获取产品在指定模板标签下的所有模板
func ( t * FsProductTemplateV2Model ) GetListByProductAndTemplateTag ( ctx context . Context , templateTagId string , productId int64 , fields ... string ) ( resp [ ] FsProductTemplateV2 , err error ) {
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) .
2023-08-17 11:09:59 +08:00
Where ( "template_tag = ? and product_id = ? and status = ? and is_del = ?" , templateTagId , productId , 1 , 0 )
2023-08-11 14:52:16 +08:00
if len ( fields ) > 0 {
db = db . Select ( fields [ 0 ] )
}
err = db . Find ( & resp ) . Error
return resp , err
}
2023-08-21 10:21:02 +08:00
func ( t * FsProductTemplateV2Model ) FindAllByProductIdsTemplateTag ( ctx context . Context , productIds [ ] int64 , templateTag string , sort string , fields ... string ) ( resp [ ] FsProductTemplateV2 , err error ) {
if len ( productIds ) == 0 {
return
}
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`product_id` in (?) and `template_tag` = ? and `is_del` = ? and `status` = ?" , productIds , templateTag , 0 , 1 )
if sort != "" {
db = db . Order ( sort )
}
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
}
err = db . Find ( & resp ) . Error
return resp , err
}
2023-10-17 15:33:46 +08:00
func ( t * FsProductTemplateV2Model ) FindAllByFittingIds ( ctx context . Context , fittingIds [ ] int64 , fields ... string ) ( resp [ ] FsProductTemplateV2 , err error ) {
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`model_id` in(?) and `status` = ? and `is_del` = ? " , fittingIds , 1 , 0 )
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
}
err = db . Find ( & resp ) . Error
return resp , err
}