...
|
...
|
@@ -2,6 +2,10 @@ package department |
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
...
|
...
|
@@ -24,7 +28,42 @@ func NewSystemUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Syst |
|
|
}
|
|
|
|
|
|
func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (resp *types.DepartmentGetResponse, err error) {
|
|
|
// todo: add your logic here and delete this line
|
|
|
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
|
|
|
return
|
|
|
_, list, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
|
|
WithOffsetLimit(1, 1).WithCountOnly().
|
|
|
WithKV("companyId", userToken.CompanyId).
|
|
|
WithKV("notId", req.Id). // 排除自己
|
|
|
WithKV("name", req.Name))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if len(list) > 0 {
|
|
|
return nil, xerr.NewErrMsg("该分组名称已存在(不能重复)")
|
|
|
}
|
|
|
|
|
|
one, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("分组修改失败", err)
|
|
|
}
|
|
|
one.Name = req.Name
|
|
|
|
|
|
// 更新
|
|
|
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
|
|
|
_, err = l.svcCtx.DepartmentRepository.UpdateWithVersion(l.ctx, conn, one)
|
|
|
return err
|
|
|
}, true)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("分组修改失败", err)
|
|
|
}
|
|
|
resp = &types.DepartmentGetResponse{
|
|
|
Department: types.Department{
|
|
|
Id: one.Id,
|
|
|
CompanyId: one.CompanyId,
|
|
|
ParentId: one.ParentId,
|
|
|
Name: one.Name,
|
|
|
},
|
|
|
}
|
|
|
return resp, nil
|
|
|
} |
...
|
...
|
|