|
@@ -3,6 +3,7 @@ package contact_field_template
|
|
|
import (
|
|
|
"context"
|
|
|
"github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
|
+ "wechat-api/ent/contactfieldtemplate"
|
|
|
"wechat-api/ent/custom_types"
|
|
|
"wechat-api/internal/utils/dberrorhandler"
|
|
|
|
|
@@ -27,17 +28,23 @@ func NewCreateContactFieldTemplateLogic(ctx context.Context, svcCtx *svc.Service
|
|
|
|
|
|
func (l *CreateContactFieldTemplateLogic) CreateContactFieldTemplate(req *types.ContactFieldTemplateInfo) (resp *types.BaseMsgResp, err error) {
|
|
|
organizationId := l.ctx.Value("organizationId").(uint64)
|
|
|
-
|
|
|
+ data, _ := l.svcCtx.DB.ContactFieldTemplate.Query().Where(contactfieldtemplate.OrganizationID(organizationId)).First(l.ctx)
|
|
|
template := ConvertContactFieldTemplates(req.Template)
|
|
|
- _, err = l.svcCtx.DB.ContactFieldTemplate.Create().
|
|
|
- SetOrganizationID(organizationId).
|
|
|
- SetTemplate(template).
|
|
|
- Save(l.ctx)
|
|
|
-
|
|
|
+ if data != nil {
|
|
|
+ err = l.svcCtx.DB.ContactFieldTemplate.
|
|
|
+ Update().
|
|
|
+ Where(contactfieldtemplate.OrganizationID(organizationId)).
|
|
|
+ SetTemplate(template).
|
|
|
+ Exec(l.ctx)
|
|
|
+ } else {
|
|
|
+ _, err = l.svcCtx.DB.ContactFieldTemplate.Create().
|
|
|
+ SetOrganizationID(organizationId).
|
|
|
+ SetTemplate(template).
|
|
|
+ Save(l.ctx)
|
|
|
+ }
|
|
|
if err != nil {
|
|
|
return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
}
|
|
|
-
|
|
|
return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
|
|
|
}
|
|
|
|