作者 Administrator

合并分支 'test' 到 'master'

Test



查看合并请求 !5
FROM 192.168.0.243:5000/mmm/allied-creation-user:20210809
ENV APP_DIR $GOPATH/src/project-20210906
ENV APP_DIR $GOPATH/src/project-20211220
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR/
COPY ./pkg pkg
... ... @@ -9,7 +9,7 @@ COPY ./go.sum go.sum
COPY ./main.go main.go
RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
ENV GO111MODULE on
ENV GOPROXY https://goproxy.io
ENV GOPROXY https://goproxy.cn
RUN ["go","mod","tidy"]
RUN ["go","build"]
RUN ["ls"]
... ...
... ... @@ -15,6 +15,8 @@ type UserSignUpCommand struct {
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 密码
Password string `cname:"密码" json:"password" valid:"Required"`
// 推荐人
Referrer string `cname:"推荐人" json:"referrer"`
}
func (companySignUpCommand *UserSignUpCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -84,6 +84,7 @@ func (authService *AuthService) UserSignUp(companySignUpCommand *command.UserSig
userInfo := &domain.UserInfo{
UserName: companySignUpCommand.Name,
Phone: companySignUpCommand.Phone,
Referer: companySignUpCommand.Referrer,
}
if _, err = signUpPersonService.SignUp(companySignUpCommand.Phone, companySignUpCommand.Password, userInfo); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -13,6 +13,8 @@ type GetOrgQuery struct {
OperateInfo *domain.OperateInfo `json:"-"`
// 组织ID
OrgId int64 `cname:"组织ID" json:"orgId" valid:"Required"`
// 获取标记 bit 0:获取企业数据
FetchFlag int `cname:"获取标记" json:"fetchFlag,omitempty"`
}
func (getOrgQuery *GetOrgQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -9,6 +9,10 @@ import (
"github.com/beego/beego/v2/core/validation"
)
const (
FetchCompanyInfo = 1 << iota
)
type ListOrgQuery struct {
OperateInfo *domain.OperateInfo `json:"-"`
// 查询偏离量
... ...
... ... @@ -154,12 +154,18 @@ func (orgService *OrgService) GetOrg(getOrgQuery *query.GetOrgQuery) (interface{
}
if org == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getOrgQuery.OrgId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if getOrgQuery.FetchFlag&query.FetchCompanyInfo > 0 && org.CompanyId > 0 {
companyRepository, _, _ := factory.FastPgCompany(transactionContext, 0)
if company, err := companyRepository.FindOne(map[string]interface{}{"companyId": org.CompanyId}); err == nil && company != nil {
org.Company = company.ToCompanyVisible()
}
return org, nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return org, nil
}
// 获取组织的子部门(通用部门列表使用)
... ... @@ -215,25 +221,18 @@ func (orgService *OrgService) ListOrg(listOrgQuery *query.ListOrgQuery) (interfa
defer func() {
transactionContext.RollbackTransaction()
}()
var orgRepository domain.OrgRepository
if value, err := factory.CreateOrgRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
orgRepository, _, _ := factory.FastPgOrg(transactionContext, 0)
count, orgs, err := orgRepository.Find(utils.ObjectToMap(listOrgQuery))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
orgRepository = value
}
if count, orgs, err := orgRepository.Find(utils.ObjectToMap(listOrgQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"orgs": orgs,
}, nil
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"orgs": orgs,
}, nil
}
// 移除组织
... ...
package domain
import "time"
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
"time"
)
// 公司状态状态 1:已注册 2:待认证 3:已认证
const (
... ... @@ -76,9 +80,8 @@ func (company *Company) Update(data map[string]interface{}) error {
if createdAt, ok := data["createdAt"]; ok {
company.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
company.UpdatedAt = updatedAt.(time.Time)
}
company.UpdatedAt = time.Now()
return nil
}
... ... @@ -89,3 +92,34 @@ func (company *Company) CloneSample() *Company {
CompanyInfo: company.CompanyInfo,
}
}
func (company *Company) ToCompanyVisible() *CompanyVisible {
return &CompanyVisible{
CompanyId: company.CompanyId,
CompanyInfo: *company.CompanyInfo,
Status: company.Status,
SystemName: company.CompanyConfig.SystemName,
}
}
/***** 2.缓存模块 *****/
func (company *Company) CacheKeyFunc() string {
if constant.DISABLE_REPOSITORY_CACHE {
return ""
}
if company.CompanyId == 0 {
return ""
}
return fmt.Sprintf("%v:cache:company:id:%v", constant.CACHE_PREFIX, company.CompanyId)
}
type CompanyVisible struct {
// 企业id
CompanyId int64 `json:"companyId"`
// 企业基本信息
CompanyInfo
Status int `json:"status"`
// 系统名称
SystemName string `json:"systemName,omitempty"`
}
... ...
... ... @@ -46,6 +46,9 @@ type Org struct {
ParentId int64 `json:"parentId,omitempty"`
// 父级节点路径("0,11,12,")
ParentPath string `json:"parentPath,omitempty"`
// 企业id
Company *CompanyVisible `json:"company,omitempty"`
}
type OrgRepository interface {
... ...
... ... @@ -44,6 +44,7 @@ type UserBase struct {
type Favorite struct {
OrgItems []int64 `json:"orgItems"`
Referer string `json:"referer"`
}
type UserBaseRepository interface {
... ...
... ... @@ -10,4 +10,6 @@ type UserInfo struct {
Avatar string `json:"avatar,omitempty"`
// 邮箱
Email string `json:"email,omitempty"`
Referer string `json:"-"`
}
... ...
... ... @@ -35,6 +35,10 @@ func (ptr *PgCreateUserAccountService) CreateUserAccount(registerAccount string,
Status: int(domain.UserStatusEnable),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Favorite: &domain.Favorite{
OrgItems: make([]int64, 0),
Referer: userInfo.Referer,
},
}
if existsUserBase, e := userBaseRepository.FindOne(map[string]interface{}{"account": registerAccount}); e == nil && existsUserBase != nil {
return existsUserBase, nil
... ...
... ... @@ -3,6 +3,8 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/cache"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -13,6 +15,7 @@ import (
)
type CompanyRepository struct {
*cache.CachedRepository
transactionContext *pgTransaction.TransactionContext
}
... ... @@ -66,23 +69,29 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp
return company, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&company.CompanyId,
&company.CompanyConfig,
&company.CompanyInfo,
&company.Status,
&company.CreatedAt,
&company.UpdatedAt,
),
fmt.Sprintf("UPDATE users.company SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
company.CompanyConfig,
company.CompanyInfo,
company.Status,
company.CreatedAt,
company.UpdatedAt,
company.Identify(),
); err != nil {
queryFunc := func() (interface{}, error) {
if _, err := tx.QueryOne(
pg.Scan(
&company.CompanyId,
&company.CompanyConfig,
&company.CompanyInfo,
&company.Status,
&company.CreatedAt,
&company.UpdatedAt,
),
fmt.Sprintf("UPDATE users.company SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
company.CompanyConfig,
company.CompanyInfo,
company.Status,
company.CreatedAt,
company.UpdatedAt,
company.Identify(),
); err != nil {
return company, err
}
return company, nil
}
if _, err := repository.Query(queryFunc, company.CacheKeyFunc()); err != nil {
return company, err
}
}
... ... @@ -92,7 +101,13 @@ func (repository *CompanyRepository) Remove(company *domain.Company) (*domain.Co
tx := repository.transactionContext.PgTx
companyModel := new(models.Company)
companyModel.CompanyId = company.Identify().(int64)
if _, err := tx.Model(companyModel).WherePK().Delete(); err != nil {
queryFunc := func() (interface{}, error) {
if _, err := tx.Model(companyModel).WherePK().Delete(); err != nil {
return company, err
}
return company, nil
}
if _, err := repository.Query(queryFunc, company.CacheKeyFunc()); err != nil {
return company, err
}
return company, nil
... ... @@ -100,18 +115,28 @@ func (repository *CompanyRepository) Remove(company *domain.Company) (*domain.Co
func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}) (*domain.Company, error) {
tx := repository.transactionContext.PgTx
companyModel := new(models.Company)
query := sqlbuilder.BuildQuery(tx.Model(companyModel), queryOptions)
query.SetWhereByQueryOption("company.company_id = ?", "companyId")
queryFunc := func() (interface{}, error) {
query := sqlbuilder.BuildQuery(tx.Model(companyModel), queryOptions)
query.SetWhereByQueryOption("company.company_id = ?", "companyId")
if v, ok := queryOptions["companyName"]; ok {
query.Where(fmt.Sprintf(`company_info @>'{"companyName":"%v"}'`, v))
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
} else {
return nil, err
if v, ok := queryOptions["companyName"]; ok {
query.Where(fmt.Sprintf(`company_info @>'{"companyName":"%v"}'`, v))
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
} else {
return nil, err
}
}
return companyModel, nil
}
var cacheModel = &domain.Company{}
if _, ok := queryOptions["companyId"]; ok {
cacheModel.CompanyId = queryOptions["companyId"].(int64)
}
if err := repository.QueryCache(cacheModel.CacheKeyFunc, companyModel, queryFunc, cache.WithObjectToExpire(constant.REPOSITORY_CACHE_EXPIRE)); err != nil {
return nil, err
}
if companyModel.CompanyId == 0 {
return nil, nil
... ... @@ -145,6 +170,7 @@ func NewCompanyRepository(transactionContext *pgTransaction.TransactionContext)
} else {
return &CompanyRepository{
transactionContext: transactionContext,
CachedRepository: cache.NewDefaultCachedRepository(),
}, nil
}
}
... ...
... ... @@ -36,6 +36,7 @@ func (controller *OrgController) GetOrg() {
getOrgQuery := &query.GetOrgQuery{}
orgId, _ := controller.GetInt64(":orgId")
getOrgQuery.OrgId = orgId
getOrgQuery.FetchFlag, _ = controller.GetInt("fetchFlag")
getOrgQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
data, err := orgService.GetOrg(getOrgQuery)
controller.Response(data, err)
... ...