作者 唐旭辉

日常提交保存

... ... @@ -50,3 +50,12 @@ func CreateOrderGoodRepository(options map[string]interface{}) (domain.OrderGood
}
return repository.NewOrderGoodRepository(transactionContext)
}
//CreateOrderGoodRepository 订单信息
func CreateUsersRepository(options map[string]interface{}) (domain.UsersRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return repository.NewUsersRepository(transactionContext)
}
... ...
package command
import (
"encoding/json"
"fmt"
)
type SyncCallbackCommand struct {
//position:职位,department:部门,employee:员工,company:公司
Module string `json:"module"`
//add:添加,edit:编辑,delete删除,batchDelete:批量删除,
//setCompanyCharge:更改公司主管,batchForbid:批量禁用用户,
//batchRemove:批量更改用户部门,changeAdmin换管理员
Action string `json:"action"`
//具体的对象JSON数据
Data json.RawMessage `json:"data" `
}
func (command *SyncCallbackCommand) ValidateCommand() error {
if len(command.Module) == 0 {
return fmt.Errorf("module 必填")
}
if len(command.Action) == 0 {
return fmt.Errorf("action 必填")
}
return nil
}
... ...
package service
type SyncCompanyService struct{}
func (service SyncCompanyService) DoAction(action string, data []byte) error {
return nil
}
... ...
package service
import (
"encoding/json"
"errors"
"fmt"
)
// UserDepartData 用户的部门数据
type UserDepartData struct {
Id int64 `json:"id"`
CompanyId int64 `json:"company_id"`
DepartmentId int64 `json:"department_id"`
UserId int64 `json:"user_id"`
}
//UserPositionData 用户的职位数据
type UserPositionData struct {
Id int64 `json:"id"`
CompanyId int64 `json:"company_id"`
PositionId int64 `json:"position_id"`
UserId int64 `json:"user_id"`
}
//EmployeeData 从平台平台接收的数据
type EmployeeData struct {
Id int64 `json:"id"` //用户的id,对应本地的user_company_id
OpenId int64 `json:"open_id"` //同一用户中心的用户id
Phone string `json:"phone"`
Name string `json:"name"`
Sex int8 `json:"sex"`
JobNum string `json:"job_num"`
PrivatePhone string `json:"private_phone"` //私人手机
CompanyId int64 `json:"company_id"` //总后台的company_id
Email string `json:"email"`
ExtensionNum string `json:"extension_num"` //分机号
EntryTime string `json:"entry_time"` //入职时间
WorkSpace string `json:"workspace"`
IsBusiness int8 `json:"is_business"` //
Status int8 `json:"status"`
Avatar string `json:"avatar"`
ExtraText string `json:"extra_text"`
Remarks string `json:"remarks"`
AdminType int8 `json:"admin_type"`
ChargeStatus int8 `json:"charge_status"`
UserDepartments []UserDepartData `json:"user_departments"`
UserPositions []UserPositionData `json:"user_positions"`
}
//SyncEmployeeService 同步用户数据
type SyncEmployeeService struct{}
func (service SyncEmployeeService) DoAction(action string, byteData []byte) error {
switch action {
case "add":
var (
data EmployeeData
err error
)
err = json.Unmarshal(byteData, &data)
if err != nil {
return fmt.Errorf("数据解析失败:%s", err)
}
err = service.AddEmployeeData(data)
return err
case "edit":
var (
data EmployeeData
err error
)
err = json.Unmarshal(byteData, &data)
if err != nil {
return fmt.Errorf("数据解析失败:%s", err)
}
err = service.UpdateEmployeeData(data)
return err
case "batchDelete":
case "batchForbid":
case "batchRemove":
case "import":
default:
return errors.New("action not found")
}
return nil
}
func (service SyncEmployeeService) AddEmployeeData(data EmployeeData) error {
return nil
}
func (service SyncEmployeeService) UpdateEmployeeData(data EmployeeData) error {
return nil
}
... ...
package service
import "errors"
//PlatformAction 企业平台数据同步服务 接口设定
type PlatformAction interface {
DoAction(string, []byte) error
}
var actionmap = map[string]PlatformAction{
// "department":
// "position":
"employee": SyncEmployeeService{},
"company": SyncCompanyService{},
}
func NewPlatformAction(module string) (PlatformAction, error) {
if v, ok := actionmap[module]; ok {
return v, nil
}
return nil, errors.New("module cannot found")
}
... ...
package domain
import "time"
// 公司的状态 1正常 2禁用
const (
companyStatusUsable int8 = 1
companyStatusUnusable int8 = 2
)
//是否开启机会模块,是否有效【1:有效】【2:无效】
const (
CompanyEnableYes int8 = 1
CompanyEnableNo int8 = 2
)
// 公司信息
type Company struct {
// 唯一标识
Id int64 `json:"id"`
// 名称
Name string `json:"name"`
// 手机号码
Phone string `json:"phone"`
// 公司logo
Logo string `json:"logo"`
// 备注
Remarks string `json:"remarks"`
// 总后台的公司id
AdminCompanyId int `json:"adminCompanyId"`
// 状态 1正常 2禁用
Status int8 `json:"status"`
//是否开启机会模块,是否有效【1:有效】【2:无效】
Enable int8 `json:"enable"`
// 创建时间
CreateAt time.Time `json:"createAt"`
// 更新时间
UpdateAt time.Time `json:"updateAt"`
// 删除时间
DeleteAt time.Time `json:"deleteAt"`
}
func (c Company) StatusIsOk() bool {
return c.Status == companyStatusUsable
}
func (c Company) EnableIsOk() bool {
return c.Enable == CompanyEnableYes
}
type CompanyRepository interface {
Add(*Company) error
Edit(*Company) error
FindOne(queryOptions map[string]interface{}) (Company, error)
Find(queryOptions map[string]interface{}) (int64, []Company, error)
}
... ...
package domain
// 合伙人分类信息
type PartnerCategoryInfo struct {
// 唯一标识
Id int64 `json:"id"`
// 名称
Name string `json:"name"`
}
type PartnerCategoryInfoRepository interface {
Find(queryOptions map[string]interface{}) (int64, []*PartnerCategoryInfo, error)
}
... ...
... ... @@ -28,8 +28,6 @@ var partnerCategoryMap = map[int]string{
type PartnerInfo struct {
Partner Partner `json:"partner"`
//合伙类别
PartnerCategory int `json:"partnerCategory"`
// 登录密码
Password string `json:"password"`
// 状态(1:启用或者0:禁用)
... ... @@ -40,10 +38,14 @@ type PartnerInfo struct {
UpdateAt time.Time `json:"updateAt"`
//合作时间
CooperateTime time.Time `json:"cooperateTime"`
//关联业务员//所属区域信息
//所属区域信息
RegionInfo *RegionInfo `json:"regionInfo"`
//关联业务员
Salesman []Salesman `json:"salesman"`
//合伙人分类
PartnerCategoryInfos []PartnerCategoryInfo `json:"partnerCategoryInfos"`
//合伙类别
PartnerCategory int `json:"partnerCategory"`
}
func (p *PartnerInfo) GetPartnerCategory() map[int]string {
... ...
... ... @@ -16,25 +16,26 @@ const (
//Users 企业平台的用户
type Users struct {
Id int64 //用户id
CompanyId int64 //公司id
OpenId int64 //统一用户中心
Name string //用户名称
Sex int8 //性别:【0:未知】【1:男】【2:女】
JobNum string //工号
Phone string //手机号,同账号
PrivatePhone string //私人手机号
Email string //邮件
ExtensionNum string //分机号
EntryTime time.Time //入职时间
Workspace string //工作地
Status int8 //状态:【1:正常】【 2:禁用】
Avatar string ///头像
Remarks string //备注
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
CreateAt time.Time
UpdateAt time.Time
Permission []AdminPermissionBase //权限
Id int64 //用户id
CompanyId int64 //公司id
OpenId int64 //统一用户中心
Name string //用户名称
Sex int8 //性别:【0:未知】【1:男】【2:女】
JobNum string //工号
Phone string //手机号,同账号
PrivatePhone string //私人手机号
Email string //邮件
ExtensionNum string //分机号
EntryTime time.Time //入职时间
Workspace string //工作地
Status int8 //状态:【1:正常】【 2:禁用】
Avatar string ///头像
Remarks string //备注
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
CreateAt time.Time
UpdateAt time.Time
Permission []AdminPermissionBase //权限
AccessPartners []Partner
}
//IsUsable 用户是否可用
... ... @@ -46,3 +47,25 @@ func (u Users) IsUsable() bool {
func (u Users) IsCharge() bool {
return u.ChargeStatus == userIsCharge
}
func (u Users) InCompany(companyid int64) bool {
return u.CompanyId == companyid
}
type UsersFindOneQuery struct {
Id int64
Phone string
}
type UsersFindQuery struct {
Ids []int64
Offset int
Limit int
}
type UsersRepository interface {
Add(*Users) error
Edit(*Users) error
Remove([]int64) error
FindOne(UsersFindOneQuery) (Users, error)
Find(UsersFindQuery) (int, []Users, error)
}
... ...
package models
import (
"context"
"time"
"github.com/go-pg/pg/v10"
)
// 业务分红信息
type BusinessBonus struct {
tableName struct{} `pg:"business_bonus"`
// 唯一标识
Id int64
// 公司编号
CompanyId int64
// 合伙人信息Id
PartnerInfoId string
// 应收分红
Bonus float64
// 未收分红
BonusNot float64
// 分红支出
BonusExpense float64
// 是否关闭【0;否】【1:是】
IsDisable int8
// 分红状态 1:待支付分红 2:已支付分红
BonusStatus int8
// 创建时间
CreateAt time.Time
// 更新时间
UpdateAt time.Time
// 删除时间
DeleteAt time.Time
}
var _ pg.BeforeUpdateHook = (*BusinessBonus)(nil)
func (bonus *BusinessBonus) BeforeUpdate(ctx context.Context) (context.Context, error) {
bonus.UpdateAt = time.Now()
return ctx, nil
}
var _ pg.BeforeInsertHook = (*BusinessBonus)(nil)
func (bonus *BusinessBonus) BeforeInsert(ctx context.Context) (context.Context, error) {
bonus.CreateAt = time.Now()
bonus.UpdateAt = time.Now()
return ctx, nil
}
... ...
package models
import "time"
// 公司信息
type Company struct {
tableName struct{} `pg:"company"`
// 唯一标识
Id int64
// 名称
Name string
// 手机号码
Phone string
// 公司logo
Logo string
// 备注
Remarks string
// 总后台的公司id
AdminCompanyId int
// 状态 1正常 2禁用
Status int8
//是否开启机会模块,是否有效【1:有效】【2:无效】
Enable int8
// 创建时间
CreateAt time.Time
// 更新时间
UpdateAt time.Time
// 删除时间
DeleteAt time.Time
}
... ...
package models
// 合伙人分类信息
type PartnerCategoryInfo struct {
tableName struct{} `pg:"partner_category_info"`
// 唯一标识
Id int64
// 名称
Name string
}
... ...
... ... @@ -20,8 +20,7 @@ type PartnerInfo struct {
Password string
// 状态(1:启用或者0:禁用)
Status int `pg:",use_zero"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `pg:",default:1"` //partner_category
//所属区域信息
RegionInfo *domain.RegionInfo
//创建时间
... ... @@ -32,6 +31,10 @@ type PartnerInfo struct {
CooperateTime time.Time
//关联业务员
Salesman []domain.Salesman
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `pg:",default:1"` //partner_category
//合伙类别
PartnerCategoryInfos []PartnerCategoryInfo
}
var _ pg.BeforeUpdateHook = (*PartnerInfo)(nil)
... ...
package models
import (
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type Users struct {
tableName struct{} `pg:"users"`
Id int64 //用户id
CompanyId int64 //公司id
OpenId int64 //统一用户中心
Name string //用户名称
Sex int8 //性别:【0:未知】【1:男】【2:女】
JobNum string //工号
Phone string //手机号,同账号
PrivatePhone string //私人手机号
Email string //邮件
ExtensionNum string //分机号
EntryTime time.Time //入职时间
Workspace string //工作地
Status int8 //状态:【1:正常】【 2:禁用】
Avatar string ///头像
Remarks string //备注
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
Permission []domain.AdminPermissionBase //权限
AccessPartners []domain.Partner //可查看的合伙人
CreateAt time.Time
UpdateAt time.Time
DeleteAt time.Time
}
... ...
package repository
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type CompanyRepository struct {
transactionContext *transaction.TransactionContext
}
var (
_ domain.CompanyRepository = (*CompanyRepository)(nil)
)
func NewCompanyRepository(transactionContext *transaction.TransactionContext) (*CompanyRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &CompanyRepository{transactionContext: transactionContext}, nil
}
func (repository CompanyRepository) transformPgModelToDomainModel(m *models.Company) (domain.Company, error) {
return domain.Company{
Id: m.Id,
Name: m.Name,
Phone: m.Phone,
Logo: m.Logo,
Remarks: m.Remarks,
AdminCompanyId: m.AdminCompanyId,
Status: m.Status,
Enable: m.Enable,
CreateAt: m.CreateAt,
UpdateAt: m.UpdateAt,
}, nil
}
func (reponsitory CompanyRepository) Add(m *domain.Company) error {
var (
err error
tx = reponsitory.transactionContext.PgTx
)
companyModel := models.Company{
Id: m.Id,
Name: m.Name,
Phone: m.Phone,
Logo: m.Logo,
Remarks: m.Remarks,
AdminCompanyId: m.AdminCompanyId,
Status: m.Status,
Enable: m.Enable,
CreateAt: m.CreateAt,
UpdateAt: m.UpdateAt,
}
_, err = tx.Model(&companyModel).Insert()
return err
}
func (reponsitory CompanyRepository) Edit(m *domain.Company) error {
var (
err error
tx = reponsitory.transactionContext.PgTx
)
companyModel := models.Company{
Id: m.Id,
Name: m.Name,
Phone: m.Phone,
Logo: m.Logo,
Remarks: m.Remarks,
AdminCompanyId: m.AdminCompanyId,
Status: m.Status,
Enable: m.Enable,
CreateAt: m.CreateAt,
DeleteAt: m.DeleteAt,
UpdateAt: m.UpdateAt,
}
_, err = tx.Model(&companyModel).Update()
return err
}
func (reponsitory CompanyRepository) FindOne(queryOptions map[string]interface{}) (domain.Company, error) {
return domain.Company{}, nil
}
func (reponsitory CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []domain.Company, error) {
return 0, nil, nil
}
... ...
package repository
import (
"fmt"
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type UsersRepository struct {
transactionContext *transaction.TransactionContext
}
var (
_ domain.UsersRepository = (*UsersRepository)(nil)
)
func NewUsersRepository(transactionContext *transaction.TransactionContext) (*UsersRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &UsersRepository{transactionContext: transactionContext}, nil
}
func (repository UsersRepository) transformPgModelToDomainModel(m *models.Users) (domain.Users, error) {
return domain.Users{
Id: m.Id,
CompanyId: m.CompanyId,
OpenId: m.OpenId,
Name: m.Name,
Sex: m.Sex,
JobNum: m.JobNum,
Phone: m.Phone,
PrivatePhone: m.PrivatePhone,
Email: m.Email,
ExtensionNum: m.ExtensionNum,
EntryTime: m.EntryTime,
Workspace: m.Workspace,
Status: m.Status,
Avatar: m.Avatar,
Remarks: m.Remarks,
ChargeStatus: m.ChargeStatus,
CreateAt: m.CreateAt,
UpdateAt: m.UpdateAt,
Permission: m.Permission,
}, nil
}
func (reponsitory UsersRepository) Add(u *domain.Users) error {
var (
err error
tx = reponsitory.transactionContext.PgTx
)
m := &models.Users{
Id: u.Id,
CompanyId: u.CompanyId,
OpenId: u.OpenId,
Name: u.Name,
Sex: u.Sex,
JobNum: u.JobNum,
Phone: u.Phone,
PrivatePhone: u.PrivatePhone,
Email: u.Email,
ExtensionNum: u.ExtensionNum,
EntryTime: u.EntryTime,
Workspace: u.Workspace,
Status: u.Status,
Avatar: u.Avatar,
Remarks: u.Remarks,
ChargeStatus: u.ChargeStatus,
CreateAt: u.CreateAt,
UpdateAt: u.UpdateAt,
Permission: u.Permission,
AccessPartners: u.AccessPartners,
}
_, err = tx.Model(m).Insert()
return err
}
func (reponsitory UsersRepository) Edit(u *domain.Users) error {
var (
err error
tx = reponsitory.transactionContext.PgTx
)
m := &models.Users{
Id: u.Id,
CompanyId: u.CompanyId,
OpenId: u.OpenId,
Name: u.Name,
Sex: u.Sex,
JobNum: u.JobNum,
Phone: u.Phone,
PrivatePhone: u.PrivatePhone,
Email: u.Email,
ExtensionNum: u.ExtensionNum,
EntryTime: u.EntryTime,
Workspace: u.Workspace,
Status: u.Status,
Avatar: u.Avatar,
Remarks: u.Remarks,
ChargeStatus: u.ChargeStatus,
CreateAt: u.CreateAt,
UpdateAt: u.UpdateAt,
Permission: u.Permission,
AccessPartners: u.AccessPartners,
}
_, err = tx.Model(m).WherePK().Update()
return err
}
func (reponsitory UsersRepository) FindOne(queryOptions domain.UsersFindOneQuery) (domain.Users, error) {
var (
err error
tx = reponsitory.transactionContext.PgTx
m models.Users
hasWhere bool
)
query := tx.Model(&m)
if queryOptions.Id > 0 {
query = query.Where("id=?", queryOptions.Id)
hasWhere = true
}
if len(queryOptions.Phone) > 0 {
query = query.Where("phone=?", queryOptions.Id)
hasWhere = true
}
if !hasWhere {
return domain.Users{}, fmt.Errorf("queryOptions 中没有搜索条件")
}
err = query.First()
if err != nil {
return domain.Users{}, err
}
return reponsitory.transformPgModelToDomainModel(&m)
}
func (reponsitory UsersRepository) Find(queryOption domain.UsersFindQuery) (int, []domain.Users, error) {
db := reponsitory.transactionContext.PgTx
usersModels := []models.Users{}
query := db.Model(&usersModels)
if queryOption.Offset > -1 {
query = query.Offset(queryOption.Offset)
}
if queryOption.Limit > 0 {
query = query.Limit(queryOption.Limit)
} else {
query = query.Limit(20)
}
var (
err error
usersReturn = make([]domain.Users, 0)
cnt int
)
query = query.Order("id DESC")
cnt, err = query.SelectAndCount()
if err != nil {
return 0, usersReturn, err
}
for i := range usersModels {
domainUsers, err := reponsitory.transformPgModelToDomainModel(&usersModels[i])
if err != nil {
return 0, usersReturn, err
}
usersReturn = append(usersReturn, domainUsers)
}
return cnt, usersReturn, nil
}
func (reponsitory UsersRepository) Remove(ids []int64) error {
if len(ids) == 0 {
return nil
}
var (
err error
tx = reponsitory.transactionContext.PgTx
)
_, err = tx.Model(&models.Users{}).
Set("delete_at=?", time.Now()).
WhereIn("id in(?)", ids).
Update()
return err
}
... ...