作者 yangfu

增加车间管理功能

正在显示 36 个修改的文件 包含 1234 行增加269 行删除
package factory
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// FastPgWorkshop 快速返回车间对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgWorkshop(transactionContext application.TransactionContext, id int, options ...option) (domain.WorkshopRepository, *domain.Workshop, error) {
var rep domain.WorkshopRepository
var mod *domain.Workshop
var err error
if value, err := CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"workshopId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
//if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
// return nil, nil, err
//}
return rep, mod, err
}
/***** 2.配置 *****/
type FastOptions struct {
DataAuthRequired bool
OperateInfo *domain.OperateInfo
}
func NewFastOptions(options ...option) *FastOptions {
o := &FastOptions{
DataAuthRequired: false,
}
for i := 0; i < len(options); i++ {
options[i](o)
}
return o
}
type option func(options *FastOptions)
// 需要数据权限
func WithDataAuthRequired() option {
return func(options *FastOptions) {
options.DataAuthRequired = true
}
}
// WithOperator 操作人
func WithOperator(op *domain.OperateInfo) option {
return func(options *FastOptions) {
options.OperateInfo = op
}
}
... ...
... ... @@ -16,7 +16,7 @@ type CreateProductLineCommand struct {
}
func (createProductLineCommand *CreateProductLineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductLineCommand *CreateProductLineCommand) ValidateCommand() error {
... ...
... ... @@ -16,7 +16,7 @@ type RemoveProductLineCommand struct {
}
func (removeProductLineCommand *RemoveProductLineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductLineCommand *RemoveProductLineCommand) ValidateCommand() error {
... ...
... ... @@ -18,7 +18,7 @@ type UpdateProductLineCommand struct {
}
func (updateProductLineCommand *UpdateProductLineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductLineCommand *UpdateProductLineCommand) ValidateCommand() error {
... ...
... ... @@ -16,7 +16,7 @@ type GetProductLineQuery struct {
}
func (getProductLineQuery *GetProductLineQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductLineQuery *GetProductLineQuery) ValidateQuery() error {
... ...
... ... @@ -16,7 +16,7 @@ type ListProductLineQuery struct {
}
func (listProductLineQuery *ListProductLineQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductLineQuery *ListProductLineQuery) ValidateQuery() error {
... ...
... ... @@ -2,10 +2,12 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productLine/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productLine/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
)
// 生产线服务
... ... @@ -27,26 +29,34 @@ func (productLineService *ProductLineService) CreateProductLine(createProductLin
defer func() {
transactionContext.RollbackTransaction()
}()
uniqueIdDao, _ := dao.NewUniqueIdDao(transactionContext.(*pgTransaction.TransactionContext))
uniqueId, err := uniqueIdDao.GenerateUniqueId()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
newProductLine := &domain.ProductLine{
//WorkshopId: createProductLineCommand.WorkshopId,
LineName: createProductLineCommand.LineName,
LineId: uniqueId,
LineName: createProductLineCommand.LineName,
ProductSections: []*domain.ProductSection{},
Removed: domain.NotDeleted,
}
var workshopRepository domain.WorkshopRepository
var workshop *domain.Workshop
workshopRepository, workshop, err = factory.FastPgWorkshop(transactionContext, createProductLineCommand.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = workshop.AddLine(newProductLine); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop, err = workshopRepository.Save(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//var productLineRepository domain
//if value, err := factory.CreateProductLineRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productLineRepository = value
//}
//if productLine, err := productLineRepository.Save(newProductLine); 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 productLine, nil
//}
return newProductLine, nil
}
... ... @@ -65,27 +75,20 @@ func (productLineService *ProductLineService) GetProductLine(getProductLineQuery
defer func() {
transactionContext.RollbackTransaction()
}()
//var productLineRepository productLine.ProductLineRepository
//if value, err := factory.CreateProductLineRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productLineRepository = value
//}
//productLine, err := productLineRepository.FindOne(map[string]interface{}{"productLineId": getProductLineQuery.ProductLineId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productLine == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductLineQuery.ProductLineId)))
//} else {
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return productLine, nil
//}
return nil, nil
//var workshopRepository domain.WorkshopRepository
var workshop *domain.Workshop
_, workshop, err = factory.FastPgWorkshop(transactionContext, getProductLineQuery.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
line, err := workshop.FindLine(getProductLineQuery.LineId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return line, nil
}
// 返回生产线列表
... ... @@ -140,30 +143,22 @@ func (productLineService *ProductLineService) RemoveProductLine(removeProductLin
defer func() {
transactionContext.RollbackTransaction()
}()
//var productLineRepository productLine.ProductLineRepository
//if value, err := factory.CreateProductLineRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productLineRepository = value
//}
//productLine, err := productLineRepository.FindOne(map[string]interface{}{"productLineId": removeProductLineCommand.ProductLineId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productLine == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductLineCommand.ProductLineId)))
//}
//if productLine, err := productLineRepository.Remove(productLine); 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 productLine, nil
//}
return nil, nil
var workshopRepository domain.WorkshopRepository
var workshop *domain.Workshop
workshopRepository, workshop, err = factory.FastPgWorkshop(transactionContext, removeProductLineCommand.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err = workshop.RemoveLine(removeProductLineCommand.LineId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop, err = workshopRepository.Save(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
// 更新生产线
... ... @@ -181,33 +176,22 @@ func (productLineService *ProductLineService) UpdateProductLine(updateProductLin
defer func() {
transactionContext.RollbackTransaction()
}()
//var productLineRepository productLine.ProductLineRepository
//if value, err := factory.CreateProductLineRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productLineRepository = value
//}
//productLine, err := productLineRepository.FindOne(map[string]interface{}{"productLineId": updateProductLineCommand.ProductLineId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productLine == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductLineCommand.ProductLineId)))
//}
//if err := productLine.Update(tool_funs.SimpleStructToMap(updateProductLineCommand)); err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
//if productLine, err := productLineRepository.Save(productLine); 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 productLine, nil
//}
return nil, nil
var workshopRepository domain.WorkshopRepository
var workshop *domain.Workshop
workshopRepository, workshop, err = factory.FastPgWorkshop(transactionContext, updateProductLineCommand.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = workshop.UpdateLine(updateProductLineCommand.LineId, updateProductLineCommand.LineName); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop, err = workshopRepository.Save(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return updateProductLineCommand, nil
}
func NewProductLineService(options map[string]interface{}) *ProductLineService {
... ...
... ... @@ -18,7 +18,7 @@ type CreateProductSectionCommand struct {
}
func (createProductSectionCommand *CreateProductSectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductSectionCommand *CreateProductSectionCommand) ValidateCommand() error {
... ...
... ... @@ -11,12 +11,14 @@ import (
type RemoveProductSectionCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
}
func (removeProductSectionCommand *RemoveProductSectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductSectionCommand *RemoveProductSectionCommand) ValidateCommand() error {
... ...
... ... @@ -11,6 +11,8 @@ import (
type UpdateProductSectionCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 工段名称
... ... @@ -18,7 +20,7 @@ type UpdateProductSectionCommand struct {
}
func (updateProductSectionCommand *UpdateProductSectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductSectionCommand *UpdateProductSectionCommand) ValidateCommand() error {
... ...
... ... @@ -16,7 +16,7 @@ type GetProductSectionQuery struct {
}
func (getProductSectionQuery *GetProductSectionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductSectionQuery *GetProductSectionQuery) ValidateQuery() error {
... ...
... ... @@ -16,7 +16,7 @@ type ListProductSectionQuery struct {
}
func (listProductSectionQuery *ListProductSectionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductSectionQuery *ListProductSectionQuery) ValidateQuery() error {
... ...
... ... @@ -2,9 +2,12 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productSection/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productSection/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
)
// 工段服务
... ... @@ -26,28 +29,32 @@ func (productSectionService *ProductSectionService) CreateProductSection(createP
defer func() {
transactionContext.RollbackTransaction()
}()
//newProductSection := &productSection.ProductSection{
// WorkshopId: createProductSectionCommand.WorkshopId,
// LineId: createProductSectionCommand.LineId,
// SectionName: createProductSectionCommand.SectionName,
//}
//var productSectionRepository productSection.ProductSectionRepository
//if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productSectionRepository = value
//}
//if productSection, err := productSectionRepository.Save(newProductSection); 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 productSection, nil
//}
return nil, nil
uniqueIdDao, _ := dao.NewUniqueIdDao(transactionContext.(*pgTransaction.TransactionContext))
uniqueId, err := uniqueIdDao.GenerateUniqueId()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
newProductSection := &domain.ProductSection{
SectionId: uniqueId,
SectionName: createProductSectionCommand.SectionName,
}
var workshopRepository domain.WorkshopRepository
var workshop *domain.Workshop
workshopRepository, workshop, err = factory.FastPgWorkshop(transactionContext, createProductSectionCommand.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = workshop.AddSection(createProductSectionCommand.LineId, newProductSection); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop, err = workshopRepository.Save(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return newProductSection, nil
}
// 返回工段服务
... ... @@ -140,30 +147,23 @@ func (productSectionService *ProductSectionService) RemoveProductSection(removeP
defer func() {
transactionContext.RollbackTransaction()
}()
//var productSectionRepository productSection.ProductSectionRepository
//if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productSectionRepository = value
//}
//productSection, err := productSectionRepository.FindOne(map[string]interface{}{"productSectionId": removeProductSectionCommand.ProductSectionId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productSection == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductSectionCommand.ProductSectionId)))
//}
//if productSection, err := productSectionRepository.Remove(productSection); 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 productSection, nil
//}
return nil, nil
var workshopRepository domain.WorkshopRepository
var workshop *domain.Workshop
workshopRepository, workshop, err = factory.FastPgWorkshop(transactionContext, removeProductSectionCommand.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = workshop.RemoveSection(removeProductSectionCommand.LineId, removeProductSectionCommand.SectionId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop, err = workshopRepository.Save(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct {
}{}, nil
}
// 更新工段服务
... ... @@ -181,33 +181,22 @@ func (productSectionService *ProductSectionService) UpdateProductSection(updateP
defer func() {
transactionContext.RollbackTransaction()
}()
//var productSectionRepository productSection.ProductSectionRepository
//if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productSectionRepository = value
//}
//productSection, err := productSectionRepository.FindOne(map[string]interface{}{"productSectionId": updateProductSectionCommand.ProductSectionId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productSection == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductSectionCommand.ProductSectionId)))
//}
//if err := productSection.Update(tool_funs.SimpleStructToMap(updateProductSectionCommand)); err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
//if productSection, err := productSectionRepository.Save(productSection); 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 productSection, nil
//}
return nil, nil
var workshopRepository domain.WorkshopRepository
var workshop *domain.Workshop
workshopRepository, workshop, err = factory.FastPgWorkshop(transactionContext, updateProductSectionCommand.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = workshop.UpdateSection(updateProductSectionCommand.LineId, updateProductSectionCommand.SectionId, updateProductSectionCommand.SectionName); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop, err = workshopRepository.Save(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return updateProductSectionCommand, nil
}
func NewProductSectionService(options map[string]interface{}) *ProductSectionService {
... ...
... ... @@ -9,14 +9,15 @@ import (
)
type CreateWorkshopCommand struct {
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName" valid:"Required"`
// 负责人ID
PrincipalId int `cname:"负责人ID" json:"principalId,omitempty"`
PrincipalId int `cname:"负责人" json:"principalId,omitempty" valid:"Required"`
}
func (createWorkshopCommand *CreateWorkshopCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createWorkshopCommand *CreateWorkshopCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type RemoveWorkshopCommand struct {
}
func (removeWorkshopCommand *RemoveWorkshopCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeWorkshopCommand *RemoveWorkshopCommand) ValidateCommand() error {
... ...
... ... @@ -14,11 +14,13 @@ type UpdateWorkshopCommand struct {
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName" valid:"Required"`
// 负责人ID
PrincipalId int `cname:"负责人ID" json:"principalId" valid:"Required"`
PrincipalId int `cname:"负责人" json:"principalId" valid:"Required"`
// 负责人 (用户对象)
//Principal *domain.User `json:"principal,omitempty"`
}
func (updateWorkshopCommand *UpdateWorkshopCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateWorkshopCommand *UpdateWorkshopCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type GetWorkshopQuery struct {
}
func (getWorkshopQuery *GetWorkshopQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getWorkshopQuery *GetWorkshopQuery) ValidateQuery() error {
... ...
... ... @@ -10,13 +10,13 @@ import (
type ListWorkshopQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
Limit int `cname:"查询限制" json:"limit"`
}
func (listWorkshopQuery *ListWorkshopQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listWorkshopQuery *ListWorkshopQuery) ValidateQuery() error {
... ...
... ... @@ -8,6 +8,9 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"strings"
"time"
)
// 车间服务
... ... @@ -15,7 +18,7 @@ type WorkshopService struct {
}
// 创建车间服务
func (workshopService *WorkshopService) CreateWorkshop(createWorkshopCommand *command.CreateWorkshopCommand) (interface{}, error) {
func (workshopService *WorkshopService) CreateWorkshop(operateInfo *domain.OperateInfo, createWorkshopCommand *command.CreateWorkshopCommand) (interface{}, error) {
if err := createWorkshopCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -29,17 +32,32 @@ func (workshopService *WorkshopService) CreateWorkshop(createWorkshopCommand *co
defer func() {
transactionContext.RollbackTransaction()
}()
var user *domain.User
userService := domainService.NewUserService()
user, err = userService.User(createWorkshopCommand.PrincipalId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
newWorkshop := &domain.Workshop{
CompanyId: operateInfo.CompanyId,
OrgId: operateInfo.OrgId,
WorkshopName: createWorkshopCommand.WorkshopName,
//PrincipalId: createWorkshopCommand.PrincipalId,
Principal: user,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
ProductLines: []*domain.ProductLine{},
}
var workshopRepository domain.WorkshopRepository
if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
workshopRepository = value
workshopRepository, _, _ = factory.FastPgWorkshop(transactionContext, 0)
if item, err := workshopRepository.FindOne(map[string]interface{}{
"workshopName": createWorkshopCommand.WorkshopName,
"companyId": operateInfo.CompanyId,
"orgId": operateInfo.OrgId,
}); err == nil && item != nil && strings.EqualFold(item.WorkshopName, createWorkshopCommand.WorkshopName) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "车间名称已存在")
}
if workshop, err := workshopRepository.Save(newWorkshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -103,25 +121,23 @@ func (workshopService *WorkshopService) ListWorkshop(listWorkshopQuery *query.Li
defer func() {
transactionContext.RollbackTransaction()
}()
var workshopRepository domain.WorkshopRepository
if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
workshopRepository, _, err := factory.FastPgWorkshop(transactionContext, 0)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
workshopRepository = value
}
if count, workshops, err := workshopRepository.Find(tool_funs.SimpleStructToMap(listWorkshopQuery)); err != nil {
var count int64
var workshops []*domain.Workshop
if count, workshops, err = workshopRepository.Find(tool_funs.SimpleStructToMap(listWorkshopQuery)); 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,
"workshops": workshops,
}, nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"workshops": workshops,
}, nil
}
// 移除车间服务
... ... @@ -154,6 +170,9 @@ func (workshopService *WorkshopService) RemoveWorkshop(removeWorkshopCommand *co
if workshop == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeWorkshopCommand.WorkshopId)))
}
if !workshop.CanRemove() {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当车间下存在线别")
}
if workshop, err := workshopRepository.Remove(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -179,24 +198,32 @@ func (workshopService *WorkshopService) UpdateWorkshop(updateWorkshopCommand *co
defer func() {
transactionContext.RollbackTransaction()
}()
var workshopRepository domain.WorkshopRepository
if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
workshopRepository = value
}
workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": updateWorkshopCommand.WorkshopId})
var workshop *domain.Workshop
workshopRepository, workshop, err = factory.FastPgWorkshop(transactionContext, updateWorkshopCommand.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateWorkshopCommand.WorkshopId)))
if workshop.WorkshopName != updateWorkshopCommand.WorkshopName {
if item, err := workshopRepository.FindOne(map[string]interface{}{
"workshopName": updateWorkshopCommand.WorkshopName,
}); err == nil && item != nil && strings.EqualFold(item.WorkshopName, updateWorkshopCommand.WorkshopName) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "车间名称已存在")
}
workshop.WorkshopName = updateWorkshopCommand.WorkshopName
}
if err := workshop.Update(tool_funs.SimpleStructToMap(updateWorkshopCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
if workshop.Principal.UserId != updateWorkshopCommand.PrincipalId && updateWorkshopCommand.PrincipalId > 0 {
var user *domain.User
userService := domainService.NewUserService()
user, err = userService.User(updateWorkshopCommand.PrincipalId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
workshop.Principal = user
}
if workshop, err := workshopRepository.Save(workshop); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -14,6 +14,15 @@ var CACHE_PREFIX = "allied-creation-manufacture-dev"
var LOG_LEVEL = "debug"
var LOG_FILE = "app.log"
//天联共创基础模块
var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com"
//天联共创用户模块
var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com"
//天联共创业务模块
var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com"
var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384}
const CUSTOMER_ACCOUNT_DELIMITER = ","
... ... @@ -42,6 +51,20 @@ func init() {
CUSTOMER_ACCOUNT = tmpAccounts
}
}
if os.Getenv("ALLIED_CREATION_BASIC_HOST") != "" {
ALLIED_CREATION_BASIC_HOST = os.Getenv("ALLIED_CREATION_BASIC_HOST")
}
if os.Getenv("ALLIED_CREATION_USER_HOST") != "" {
ALLIED_CREATION_USER_HOST = os.Getenv("ALLIED_CREATION_USER_HOST")
}
if os.Getenv("ALLIED_CREATION_COOPERATION_HOST") != "" {
ALLIED_CREATION_COOPERATION_HOST = os.Getenv("ALLIED_CREATION_COOPERATION_HOST")
}
//if os.Getenv("SMS_SERVE_HOST") != "" {
// SMS_SERVE_HOST = os.Getenv("SMS_SERVE_HOST")
//}
if os.Getenv("SERVICE_ENV") != "" {
SERVICE_ENV = os.Getenv("SERVICE_ENV")
}
... ...
package domain
import "fmt"
const MaxQueryRow = 10000
var (
ErrorNotFound = fmt.Errorf("没有此资源")
)
/***** 1.数据权限 *****/
// DataAuthor 数据验证器
type DataAuthor interface {
DataAuth(options OperateInfo, data AuthedData) error
}
// AuthedData 需要认证的数据
type AuthedData interface {
// 数据所属组织
BelongOrg() int64
}
// 验证参数
type OperateInfo struct {
// 当前操作人
UserId int
// 当前公司
CompanyId int
// 当前登录的组织
OrgId int
// 菜单模块
MenuCode string
}
func NewCheckOptions(optUser, org int) OperateInfo {
return OperateInfo{
UserId: optUser,
OrgId: org,
}
}
func (info OperateInfo) Valid() bool {
if info.UserId == 0 || info.CompanyId == 0 || info.OrgId == 0 {
return false
}
return true
}
func (info OperateInfo) GetCompanyId(companyId int) int {
if companyId != 0 {
return companyId
}
return info.CompanyId
}
func (info OperateInfo) GetOrgId(orgId int) int {
if orgId != 0 {
return orgId
}
return info.OrgId
}
func (info OperateInfo) GetUserId(userId int) int {
if userId != 0 {
return userId
}
return info.UserId
}
func (info OperateInfo) String() string {
return fmt.Sprintf("UserId: %v OrgId:%v CompanyId:%v", info.UserId, info.OrgId, info.CompanyId)
}
... ...
... ... @@ -8,4 +8,6 @@ type ProductLine struct {
LineName string `json:"lineName,omitempty"`
// 工段列表
ProductSections []*ProductSection `json:"productSections,omitempty"`
// 已删除标识 0:正常 1:已删除
Removed int `json:"removed,omitempty"`
}
... ...
... ... @@ -6,4 +6,6 @@ type ProductSection struct {
SectionId int `json:"sectionId,omitempty"`
// 工段名称
SectionName string `json:"sectionName,omitempty"`
// 已删除标识 0:正常 1:已删除
Removed int `json:"removed,omitempty"`
}
... ...
package domain
import "time"
import (
"fmt"
"time"
)
const (
// 未删除
NotDeleted = 0
// 已删除
Deleted = 1
)
// 车间
type Workshop struct {
... ... @@ -39,47 +49,141 @@ func (workshop *Workshop) Identify() interface{} {
}
func (workshop *Workshop) Update(data map[string]interface{}) error {
//if companyId, ok := data["companyId"]; ok {
// workshop.CompanyId = companyId.(int)
//}
//if orgId, ok := data["orgId"]; ok {
// workshop.OrgId = orgId.(int)
//}
//if workshopId, ok := data["workshopId"]; ok {
// workshop.WorkshopId = workshopId.(int)
//}
if workshopName, ok := data["workshopName"]; ok {
workshop.WorkshopName = workshopName.(string)
}
if userId, ok := data["userId"]; ok {
workshop.Principal.UserId = userId.(int)
}
if userName, ok := data["userName"]; ok {
workshop.Principal.UserName = userName.(string)
if principal, ok := data["principal"]; ok {
workshop.Principal = principal.(*User)
}
if employeeType, ok := data["employeeType"]; ok {
workshop.Principal.EmployeeType = employeeType.(int)
workshop.UpdatedAt = time.Now()
return nil
}
// AddLine 添加生产线
func (workshop *Workshop) AddLine(line *ProductLine) error {
for i := range workshop.ProductLines {
item := workshop.ProductLines[i]
if item.Removed == Deleted {
continue
}
if item.LineName == line.LineName {
return fmt.Errorf("生产线:%v已存在", line.LineName)
}
}
if icCardNumber, ok := data["icCardNumber"]; ok {
workshop.Principal.IcCardNumber = icCardNumber.(string)
workshop.ProductLines = append(workshop.ProductLines, line)
return nil
}
// RemoveLine 移除生产线
func (workshop *Workshop) RemoveLine(lineId int) (*ProductLine, error) {
line, err := workshop.FindLine(lineId)
if err != nil {
return nil, err
}
if avatar, ok := data["avatar"]; ok {
workshop.Principal.Avatar = avatar.(string)
if line.Removed == 1 {
return nil, fmt.Errorf("生产线:%v已删除", line.LineName)
}
if phone, ok := data["phone"]; ok {
workshop.Principal.Phone = phone.(string)
line.Removed = 1
return line, nil
}
// RemoveLine 更新生产线
func (workshop *Workshop) UpdateLine(lineId int, lineName string) error {
line, err := workshop.FindLine(lineId)
if err != nil {
return err
}
//if productLines, ok := data["productLines"]; ok {
// workshop.ProductLines = productLines.(array)
//}
if createdAt, ok := data["createdAt"]; ok {
workshop.CreatedAt = createdAt.(time.Time)
if line.Removed == 1 {
return fmt.Errorf("生产线:%v已删除", line.LineName)
}
if updatedAt, ok := data["updatedAt"]; ok {
workshop.UpdatedAt = updatedAt.(time.Time)
line.LineName = lineName
return nil
}
// FindLine 查询生产线
func (workshop *Workshop) FindLine(lineId int) (*ProductLine, error) {
for i := range workshop.ProductLines {
item := workshop.ProductLines[i]
if item.LineId == lineId {
return workshop.ProductLines[i], nil
}
}
return nil, fmt.Errorf("生产线不存在")
}
// RemoveLine 车间是否可删除 (存在任意一个生产线时,可删除)
func (workshop *Workshop) CanRemove() bool {
for i := range workshop.ProductLines {
item := workshop.ProductLines[i]
if item.Removed == NotDeleted {
return false
}
}
if deletedAt, ok := data["deletedAt"]; ok {
workshop.DeletedAt = deletedAt.(time.Time)
return true
}
// AddLine 添加生产线
func (workshop *Workshop) AddSection(lineId int, section *ProductSection) error {
line, err := workshop.FindLine(lineId)
if err != nil {
return err
}
if line.Removed == 1 {
return fmt.Errorf("生产线:%v已删除", line.LineName)
}
for i := range line.ProductSections {
item := line.ProductSections[i]
if item.Removed == Deleted {
continue
}
if item.SectionName == section.SectionName {
return fmt.Errorf("工段:%v已存在", section.SectionName)
}
}
line.ProductSections = append(line.ProductSections, section)
return nil
}
// RemoveLine 移除生产线
func (workshop *Workshop) RemoveSection(lineId, sectionId int) error {
section, err := workshop.FindSection(lineId, sectionId)
if err != nil {
return err
}
if section.Removed == 1 {
return fmt.Errorf("工段:%v已删除", section.SectionName)
}
section.Removed = 1
return nil
}
// RemoveLine 更新生产线
func (workshop *Workshop) UpdateSection(lineId, sectionId int, sectionName string) error {
section, err := workshop.FindSection(lineId, sectionId)
if err != nil {
return err
}
if section.Removed == 1 {
return fmt.Errorf("工段:%v已删除", section.SectionName)
}
section.SectionName = sectionName
return nil
}
// 查询生产线
func (workshop *Workshop) FindSection(lineId, sectionId int) (*ProductSection, error) {
line, err := workshop.FindLine(lineId)
if err != nil {
return nil, err
}
for i := range line.ProductSections {
item := line.ProductSections[i]
if item.SectionId == sectionId {
return item, nil
}
}
return nil, fmt.Errorf("工段不存在")
}
... ...
package example
import (
"github.com/linmadan/egglib-go/utils/json"
"gitlab.fjmaimaimai.com/allied-creation/allied-lib/gateway/allied_creation_user"
"testing"
)
var host = "http://127.0.0.1:8081"
func TestAlliedUserGatewayLib(t *testing.T) {
creation := allied_creation_user.NewHttpLibAlliedCreationUser(host)
user, _ := creation.UserGet(allied_creation_user.ReqGetUser{
UserId: 2,
})
t.Log(json.MarshalToString(user))
_, users, _ := creation.UserSearch(allied_creation_user.ReqUserSearch{
Offset: 60,
})
t.Log(json.MarshalToString(users))
company, _ := creation.CompanyGet(allied_creation_user.ReqCompanyGet{
CompanyId: 2,
})
t.Log(json.MarshalToString(company))
_, companies, _ := creation.CompanySearch(allied_creation_user.ReqCompanySearch{})
t.Log(json.MarshalToString(companies))
org, _ := creation.OrgGet(allied_creation_user.ReqOrgGet{
OrgId: 2,
})
t.Log(json.MarshalToString(org))
_, orgs, _ := creation.OrgSearch(allied_creation_user.ReqOrgSearch{})
t.Log(json.MarshalToString(orgs))
}
func TestAlliedUserGatewayLibQuick(t *testing.T) {
creation := allied_creation_user.NewHttpLibAlliedCreationUser(host)
user, _ := creation.User(2)
t.Log(json.MarshalToString(user))
users, _ := creation.Users([]int{2})
t.Log(json.MarshalToString(users))
company, _ := creation.Company(2)
t.Log(json.MarshalToString(company))
companies, _ := creation.Companies([]int{2})
t.Log(json.MarshalToString(companies))
org, _ := creation.Organization(2)
t.Log(json.MarshalToString(org))
orgs, _ := creation.Organizations([]int{2})
t.Log(json.MarshalToString(orgs))
}
... ...
package allied_creation_user
import (
"fmt"
gatewayLib "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/models"
"strconv"
"time"
)
// HttpLibAlliedCreationUser 用户模块
type HttpLibAlliedCreationUser struct {
gatewayLib.BaseServiceGateway
baseUrL string
}
func NewHttpLibAlliedCreationUser(host string) *HttpLibAlliedCreationUser {
gt := gatewayLib.NewBaseServiceGateway(host)
gt.ConnectTimeout = 10 * time.Second
gt.ReadWriteTimeout = 10 * time.Second
return &HttpLibAlliedCreationUser{
BaseServiceGateway: gt,
}
}
// 快速查询
// 用户
func (gateway HttpLibAlliedCreationUser) User(userId int) (*models.User, error) {
return gateway.UserGet(ReqGetUser{UserId: userId})
}
func (gateway HttpLibAlliedCreationUser) Users(userIds []int) ([]*models.User, error) {
var list = make([]*models.User, 0)
for i := range userIds {
item, err := gateway.User(userIds[i])
if err != nil {
return list, err
}
list = append(list, item)
}
return list, nil
}
// 公司
func (gateway HttpLibAlliedCreationUser) Company(companyId int) (*models.Company, error) {
return gateway.CompanyGet(ReqCompanyGet{CompanyId: companyId})
}
func (gateway HttpLibAlliedCreationUser) Companies(companyIds []int) ([]*models.Company, error) {
var list = make([]*models.Company, 0)
for i := range companyIds {
item, err := gateway.Company(companyIds[i])
if err != nil {
return list, err
}
list = append(list, item)
}
return list, nil
}
// 组织
func (gateway HttpLibAlliedCreationUser) Organization(orgId int) (*models.Organization, error) {
return gateway.OrgGet(ReqOrgGet{OrgId: orgId})
}
func (gateway HttpLibAlliedCreationUser) Organizations(orgIds []int) ([]*models.Organization, error) {
var list = make([]*models.Organization, 0)
for i := range orgIds {
item, err := gateway.Organization(orgIds[i])
if err != nil {
return list, err
}
list = append(list, item)
}
return list, nil
}
// 部门
func (gateway HttpLibAlliedCreationUser) Department(departmentId int) (*models.Department, error) {
o, err := gateway.OrgGet(ReqOrgGet{OrgId: departmentId})
if err != nil {
return nil, err
}
return o.ToDepartment(), err
}
func (gateway HttpLibAlliedCreationUser) Departments(departmentIds []int) ([]*models.Department, error) {
organizations, err := gateway.Organizations(departmentIds)
if err != nil {
return nil, err
}
var list = make([]*models.Department, 0)
for i := range organizations {
list = append(list, organizations[i].ToDepartment())
}
return list, nil
}
//UserGet 获取用户
func (gateway HttpLibAlliedCreationUser) UserGet(param ReqGetUser) (*models.User, error) {
url := fmt.Sprintf("%s%s%d", gateway.Host(), "/user/", param.UserId)
method := "get"
var data models.User
err := gateway.FastDoRequest(url, method, param, &data)
return &data, err
}
//UserSearch 搜索用户列表
func (gateway HttpLibAlliedCreationUser) UserSearch(param ReqUserSearch) (int, []*models.User, error) {
url := gateway.Host() + "/user/search"
method := "post"
var data DataUserSearch
err := gateway.FastDoRequest(url, method, param, &data)
return data.Count, data.Users, err
}
// CompanyGet 返回企业
func (gateway HttpLibAlliedCreationUser) CompanyGet(param ReqCompanyGet) (*models.Company, error) {
url := gateway.Host() + "/company/" + strconv.Itoa(param.CompanyId)
method := "GET"
var data CompanyItem
err := gateway.FastDoRequest(url, method, param, &data)
return data.ToCompany(), err
}
// CompanySearch 返回企业列表
func (gateway HttpLibAlliedCreationUser) CompanySearch(param ReqCompanySearch) (int, []*models.Company, error) {
url := gateway.Host() + "/company/search"
method := "post"
var data DataCompanySearch
err := gateway.FastDoRequest(url, method, param, &data)
if err != nil {
return data.Count, nil, err
}
cs := make([]*models.Company, 0)
for i := range data.Companys {
cs = append(cs, data.Companys[i].ToCompany())
}
return data.Count, cs, err
}
// Org[orgId} 返回组织
func (gateway HttpLibAlliedCreationUser) OrgGet(param ReqOrgGet) (*models.Organization, error) {
url := gateway.Host() + "/org/" + strconv.Itoa(param.OrgId)
if param.FetchFlag > 0 {
url += fmt.Sprintf("?fetchFlag=%v", param.FetchFlag)
}
method := "get"
var data models.Organization
err := gateway.FastDoRequest(url, method, param, &data)
return &data, err
}
// OrgSearch 返回组织列表
func (gateway HttpLibAlliedCreationUser) OrgSearch(param ReqOrgSearch) (int, []*models.Organization, error) {
url := gateway.Host() + "/org/search"
method := "post"
var data DataOrgSearch
err := gateway.FastDoRequest(url, method, param, &data)
return data.Count, data.Orgs, err
}
... ...
package allied_creation_user
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/models"
"time"
)
//搜索用户列表
type (
ReqUserSearch struct {
// 查询偏离量
Offset int `json:"offset"`
// 查询限制
Limit int `json:"limit"`
// 用户基础id
UserBaseId int64 ` json:"userBaseId"`
// 企业id
CompanyId int64 ` json:"companyId"`
// 组织ID
OrganizationId int64 `json:"organizationId"`
// 部门编号
DepartmentId int64 `json:"departmentId"`
// 用户姓名
UserName string `json:"userName"`
// 共创公司
CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"`
// 部门名称
DepName string `json:"depName"`
// 手机号码
Phone string `json:"phone"`
// 用户类型
UserType int `cname:"用户类型 1:普通用户 2:共创用户 1024:企业注册用户" json:"userType,omitempty"`
// 匹配多个组织
InOrgIds []int64 `cname:"匹配多个组织" json:"inOrgIds,omitempty"`
// 实时拉取数据 (获取最新的)
PullRealTime bool `cname:"拉取最新数据" json:"pullRealTime,omitempty"`
// 状态(1:启用 2:禁用 3:注销)
EnableStatus int `cname:"状态(1:启用 2:禁用 3:注销)" json:"enableStatus,omitempty"`
// 状态(1:启用 2:禁用 3:注销)
InEnableStatus []int `cname:"状态(1:启用 2:禁用 3:注销)" json:"inEnableStatus,omitempty"`
// 匹配多个公司
InCompanyIds []interface{} `json:"inCompanyIds,omitempty"`
// 自定义高级查询
AdvancedQuery string `json:"advancedQuery"`
}
//DataUserSearch 搜索用户列表
DataUserSearch struct {
Count int `json:"count"`
Users []*models.User `json:"users"`
}
)
//获取用户
type (
ReqGetUser struct {
UserId int `json:"userId"`
}
DataGateUser struct {
models.User
}
)
//返回企业
type (
ReqCompanyGet struct {
CompanyId int `json:"companyId"`
}
DataCompanyGet CompanyItem
CompanyItem struct {
CompanyId int `json:"companyId"`
CompanyConfig struct {
SystemName string `json:"systemName"`
Theme string `json:"theme"`
} `json:"companyConfig"`
CompanyInfo struct {
Logo string `json:"logo"`
CompanyName string `json:"companyName"`
Scale string `json:"scale"`
IndustryCategory string `json:"industryCategory"`
RegisteredTime time.Time `json:"registeredTime"`
//Legal struct {
// LegalPerson string `json:"legalPerson"`
// SocialCreditCode string `json:"socialCreditCode"`
// BusinessLicenseAddress struct {
// Province string `json:"province"`
// City string `json:"city"`
// Address string `json:"address"`
// } `json:"businessLicenseAddress"`
// BusinessLicenseAttachments []domain.Attachment `json:"businessLicenseAttachments"`
//} `json:"legal"`
Remark string `json:"备注"`
} `json:"companyInfo"`
Status int `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
)
func (item CompanyItem) ToCompany() *models.Company {
return &models.Company{
CompanyId: item.CompanyId,
CompanyName: item.CompanyInfo.CompanyName,
Status: item.Status,
Logo: item.CompanyInfo.Logo,
}
}
//返回企业列表
type (
ReqCompanySearch struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset,omitempty"`
// 查询限制
Limit int `cname:"查询限制" json:"limit,omitempty"`
// 状态
Status int `cname:"状态" json:"status,omitempty"`
// 企业名称
CompanyName string `cname:"企业名称" json:"companyName,omitempty"`
}
DataCompanySearch struct {
Companys []CompanyItem `json:"companys"`
Count int `json:"count"`
}
)
//返回组织
type (
ReqOrgGet struct {
OrgId int `json:"orgId"`
// 获取标记 bit 0:获取企业数据
FetchFlag int `json:"fetchFlag"`
}
DataOrgGet models.Organization
)
//返回组织列表
type (
ReqOrgSearch struct {
CompanyId int `json:"companyId"`
DepName string `json:"depName"`
IsOrg int `json:"isOrg"` //否是组织(是:1 不是:2)
Limit int `json:"limit"`
Offset int `json:"offset"`
OrgCode string `json:"orgCode"`
ParentId int `json:"parentId"`
// 模糊匹配组织名称
MatchOrgName string `cname:"部门名称" json:"matchOrgName,omitempty"`
}
DataOrgSearch struct {
Count int `json:"count"`
Orgs []*models.Organization `json:"orgs"`
}
)
... ...
package service_gateway
import (
rawjson "encoding/json"
"errors"
"fmt"
"github.com/linmadan/egglib-go/utils/json"
"time"
"github.com/beego/beego/v2/client/httplib"
)
type MessageCode struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
//GatewayResponse 统一消息返回格式
type Response struct {
MessageCode
Data rawjson.RawMessage `json:"data"`
}
type BaseServiceGateway struct {
ConnectTimeout time.Duration
ReadWriteTimeout time.Duration
host string
}
type Request struct {
Url string
Method string
Param interface{}
}
func (gateway BaseServiceGateway) CreateRequest(url string, method string) *httplib.BeegoHTTPRequest {
var request *httplib.BeegoHTTPRequest
switch method {
case "get", "GET":
request = httplib.Get(url)
case "post", "POST":
request = httplib.Post(url)
case "put", "PUT":
request = httplib.Put(url)
case "delete", "DELETE":
request = httplib.Delete(url)
case "head", "HEADER":
request = httplib.Head(url)
default:
request = httplib.Get(url)
}
return request.SetTimeout(gateway.ConnectTimeout, gateway.ReadWriteTimeout)
}
func (gateway BaseServiceGateway) GetResponseData(result Response, data interface{}) error {
if result.Code != 0 {
return fmt.Errorf(result.Msg)
}
err := json.Unmarshal(result.Data, data)
if err != nil {
return err
}
return nil
}
func (gateway BaseServiceGateway) FastDoRequest(url, method string, param interface{}, data interface{}) error {
err := gateway.DoRequest(Request{
Url: url,
Method: method,
Param: param,
}, &data)
if err != nil {
return err
}
return nil
}
func (gateway BaseServiceGateway) DoRequest(requestParam Request, val interface{}) error {
r := gateway.CreateRequest(requestParam.Url, requestParam.Method)
req, err := r.JSONBody(requestParam.Param)
if err != nil {
return err
}
byteResult, err := req.Bytes()
if err != nil {
return err
}
var result Response
err = json.Unmarshal(byteResult, &result)
if err != nil {
return err
}
if result.Code != 0 && len(result.Msg) > 0 {
return errors.New(result.Msg)
}
err = gateway.GetResponseData(result, val)
return nil
}
func (gateway BaseServiceGateway) Host() string {
return gateway.host
}
func NewBaseServiceGateway(host string) BaseServiceGateway {
return BaseServiceGateway{
host: host,
}
}
... ...
package models
//单体用户详情数据
type User struct {
// 用户Id
UserId int `json:"userId,omitempty"`
// 基础信息ID
UserBaseId int `json:"userBaseId,omitempty"`
// 用户类型
UserType int `json:"userType,omitempty"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `json:"employeeType,omitempty"`
// IC卡号
IcCardNumber string `json:"icCardNumber,omitempty"`
// 用户编号
UserCode string `json:"userCode,omitempty"`
// 启用状态
EnableStatus int `json:"enableStatus,omitempty"`
// 用户信息
UserInfo UserInfo `json:"userInfo,omitempty"`
// 所属公司
Company *Company `json:"company,omitempty"`
// 所属组织
Org *Organization `json:"org,omitempty"`
// 部门
Department *Department `json:"department,omitempty"`
}
// UserInfo 用户信息
type UserInfo struct {
Phone string `json:"phone,omitempty"`
UserCode string `json:"userCode,omitempty"`
Email string `json:"email,omitempty"`
UserName string `json:"userName,omitempty"`
Avatar string `json:"avatar,omitempty"`
}
// Company 公司信息
type Company struct {
CompanyId int `json:"companyId,omitempty"`
CompanyName string `json:"companyName,omitempty"`
Status int `json:"status,omitempty"`
Logo string `json:"logo,omitempty"`
}
// Org 组织
type Organization struct {
OrgId int `json:"orgId,omitempty"`
OrgCode string `json:"orgCode,omitempty"`
OrgName string `json:"orgName,omitempty"`
}
// Department 部门
type Department struct {
DepartmentId int `json:"departmentId,omitempty"`
DepartmentName string `json:"departmentName,omitempty"`
DepartmentNumber string `json:"departmentNumber,omitempty"`
}
func (org Organization) ToDepartment() *Department {
return &Department{
DepartmentId: org.OrgId,
DepartmentName: org.OrgName,
DepartmentNumber: org.OrgCode,
}
}
... ...
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type UniqueIdDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (d *UniqueIdDao) GenerateUniqueId() (int, error) {
sql := " SELECT nextval('manufacture.manufacture_seq_id_seq') id;"
var data = struct {
Id int
}{}
_, err := d.transactionContext.PgTx.Query(&data, sql)
if err != nil {
return 0, err
}
return data.Id, nil
}
func NewUniqueIdDao(transactionContext *pgTransaction.TransactionContext) (*UniqueIdDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &UniqueIdDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
package domainService
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/allied_creation_user"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/models"
)
type UserService struct {
internalUserService *allied_creation_user.HttpLibAlliedCreationUser
}
func (svr *UserService) User(id int) (*domain.User, error) {
rsp, err := svr.internalUserService.User(id)
if err != nil {
return nil, err
}
return svr.ToUser(rsp), nil
}
//func(svr *UserService)Organization(id int)(*domain.Org,error){
// rsp,err:= svr.internalUserService.Organization(id)
// if err!=nil{
// return nil, err
// }
// return svr.ToUser(rsp), nil
//}
func (svr *UserService) ToUser(from *models.User) *domain.User {
return &domain.User{
UserId: from.UserId,
UserName: from.UserInfo.UserName,
EmployeeType: from.EmployeeType,
IcCardNumber: from.IcCardNumber,
Avatar: from.UserInfo.Avatar,
Phone: from.UserInfo.Phone,
}
}
//func(svr *UserService) ToOrg(from *models.Organization)*domain.Org{
//
//}
func NewUserService() *UserService {
return &UserService{
internalUserService: allied_creation_user.NewHttpLibAlliedCreationUser(constant.ALLIED_CREATION_USER_HOST),
}
}
... ...
... ... @@ -36,19 +36,13 @@ func (repository *WorkshopRepository) Save(workshop *domain.Workshop) (*domain.W
"updated_at",
"deleted_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_id")
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_id", "deleted_at")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if workshop.Identify() == nil {
workshopId, err := repository.nextIdentify()
if err != nil {
return workshop, err
} else {
workshop.WorkshopId = int(workshopId)
}
if _, err := tx.QueryOne(
pg.Scan(
&workshop.CompanyId,
... ... @@ -56,21 +50,19 @@ func (repository *WorkshopRepository) Save(workshop *domain.Workshop) (*domain.W
&workshop.WorkshopId,
&workshop.WorkshopName,
&workshop.Principal,
pg.Array(&workshop.ProductLines),
&workshop.ProductLines,
&workshop.CreatedAt,
&workshop.UpdatedAt,
&workshop.DeletedAt,
),
fmt.Sprintf("INSERT INTO workshops (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
fmt.Sprintf("INSERT INTO manufacture.workshop (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
workshop.CompanyId,
workshop.OrgId,
workshop.WorkshopId,
workshop.WorkshopName,
workshop.Principal,
pg.Array(workshop.ProductLines),
workshop.ProductLines,
workshop.CreatedAt,
workshop.UpdatedAt,
workshop.DeletedAt,
); err != nil {
return workshop, err
}
... ... @@ -82,21 +74,19 @@ func (repository *WorkshopRepository) Save(workshop *domain.Workshop) (*domain.W
&workshop.WorkshopId,
&workshop.WorkshopName,
&workshop.Principal,
pg.Array(&workshop.ProductLines),
&workshop.ProductLines,
&workshop.CreatedAt,
&workshop.UpdatedAt,
&workshop.DeletedAt,
),
fmt.Sprintf("UPDATE workshops SET %s WHERE workshop_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
fmt.Sprintf("UPDATE manufacture.workshop SET %s WHERE workshop_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
workshop.CompanyId,
workshop.OrgId,
workshop.WorkshopId,
workshop.WorkshopName,
workshop.Principal,
pg.Array(workshop.ProductLines),
workshop.ProductLines,
workshop.CreatedAt,
workshop.UpdatedAt,
workshop.DeletedAt,
workshop.Identify(),
); err != nil {
return workshop, err
... ... @@ -117,7 +107,11 @@ func (repository *WorkshopRepository) FindOne(queryOptions map[string]interface{
tx := repository.transactionContext.PgTx
workshopModel := new(models.Workshop)
query := sqlbuilder.BuildQuery(tx.Model(workshopModel), queryOptions)
query.SetWhereByQueryOption("workshop.workshop_id = ?", "workshopId")
query.AllWithDeleted()
query.SetWhereByQueryOption("workshop_id = ?", "workshopId")
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("workshop_name=?", "workshopName")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ... @@ -136,7 +130,7 @@ func (repository *WorkshopRepository) Find(queryOptions map[string]interface{})
var workshopModels []*models.Workshop
workshops := make([]*domain.Workshop, 0)
query := sqlbuilder.BuildQuery(tx.Model(&workshopModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("workshop_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, workshops, err
... ...
package controllers
import (
"github.com/beego/beego/v2/server/web/context"
"github.com/linmadan/egglib-go/web/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"strconv"
)
func ResponseGrid(c beego.BaseController, data interface{}, err error) {
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(c.Ctx, err)
} else {
response = ResponseGridData(c.Ctx, data)
}
c.Data["json"] = response
c.ServeJSON()
}
func ResponseGridData(ctx *context.Context, data interface{}) utils.JsonResponse {
jsonResponse := utils.JsonResponse{}
jsonResponse["code"] = 0
jsonResponse["msg"] = "ok"
jsonResponse["data"] = map[string]interface{}{"grid": data}
ctx.Input.SetData("outputData", jsonResponse)
return jsonResponse
}
func Must(err error) {
if err != nil {
log.Logger.Error(err.Error())
}
}
// ParseOperateInfo 从头部解析操作对象信息
func ParseOperateInfo(c beego.BaseController) *domain.OperateInfo {
opt := &domain.OperateInfo{}
opt.UserId = header(c, constant.HeaderUserId)
opt.CompanyId = header(c, constant.HeaderCompanyId)
opt.OrgId = header(c, constant.HeaderOrgId)
return opt
}
func header(c beego.BaseController, key string) int {
if len(c.Ctx.Input.Header(key)) == 0 {
return 0
}
res, err := strconv.Atoi(c.Ctx.Input.Header(key))
if err != nil {
log.Logger.Error(err.Error())
return 0
}
return res
}
... ...
... ... @@ -41,9 +41,11 @@ func (controller *ProductLineController) GetProductLine() {
func (controller *ProductLineController) RemoveProductLine() {
productLineService := service.NewProductLineService(nil)
removeProductLineCommand := &command.RemoveProductLineCommand{}
controller.Unmarshal(removeProductLineCommand)
//controller.Unmarshal(removeProductLineCommand)
lineId, _ := controller.GetInt(":lineId")
workshopId, _ := controller.GetInt("workshopId")
removeProductLineCommand.LineId = lineId
removeProductLineCommand.WorkshopId = workshopId
data, err := productLineService.RemoveProductLine(removeProductLineCommand)
controller.Response(data, err)
}
... ...
... ... @@ -44,6 +44,10 @@ func (controller *ProductSectionController) RemoveProductSection() {
controller.Unmarshal(removeProductSectionCommand)
sectionId, _ := controller.GetInt(":sectionId")
removeProductSectionCommand.SectionId = sectionId
lineId, _ := controller.GetInt("lineId")
workshopId, _ := controller.GetInt("workshopId")
removeProductSectionCommand.LineId = lineId
removeProductSectionCommand.WorkshopId = workshopId
data, err := productSectionService.RemoveProductSection(removeProductSectionCommand)
controller.Response(data, err)
}
... ...
... ... @@ -15,7 +15,7 @@ func (controller *WorkshopController) CreateWorkshop() {
workshopService := service.NewWorkshopService(nil)
createWorkshopCommand := &command.CreateWorkshopCommand{}
controller.Unmarshal(createWorkshopCommand)
data, err := workshopService.CreateWorkshop(createWorkshopCommand)
data, err := workshopService.CreateWorkshop(ParseOperateInfo(controller.BaseController), createWorkshopCommand)
controller.Response(data, err)
}
... ...