作者 yangfu

生产班组管理

... ... @@ -99,6 +99,165 @@ func FastPgProductJob(transactionContext application.TransactionContext, id int,
return rep, mod, err
}
// FastPgProductGroup 快速返回生产组对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductGroup(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductGroupRepository, *domain.ProductGroup, error) {
var rep domain.ProductGroupRepository
var mod *domain.ProductGroup
var err error
if value, err := CreateProductGroupRepository(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{}{"productJobId": 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
}
// FastPgProduct 快速返回产品对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProduct(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductRepository, *domain.Product, error) {
var rep domain.ProductRepository
var mod *domain.Product
var err error
if value, err := CreateProductRepository(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{}{"productJobId": 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())
}
}
return rep, mod, err
}
// FastPgDevice 快速返回设备对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgDevice(transactionContext application.TransactionContext, id int, options ...option) (domain.DeviceRepository, *domain.Device, error) {
var rep domain.DeviceRepository
var mod *domain.Device
var err error
if value, err := CreateDeviceRepository(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{}{"productJobId": 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())
}
}
return rep, mod, err
}
// FastPgProductCalendar 快速返回设备对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductCalendar(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductCalendarRepository, *domain.ProductCalendar, error) {
var rep domain.ProductCalendarRepository
var mod *domain.ProductCalendar
var err error
if value, err := CreateProductCalendarRepository(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{}{"productJobId": 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())
}
}
return rep, mod, err
}
// FastPgUnitConversion 快速返回单位换算对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgUnitConversion(transactionContext application.TransactionContext, id int, options ...option) (domain.UnitConversionRepository, *domain.UnitConversion, error) {
var rep domain.UnitConversionRepository
var mod *domain.UnitConversion
var err error
if value, err := CreateUnitConversionRepository(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{}{"productJobId": 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())
}
}
return rep, mod, err
}
// FastPgProductPlan 快速返回生产计划对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductPlan(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductPlanRepository, *domain.ProductPlan, error) {
var rep domain.ProductPlanRepository
var mod *domain.ProductPlan
var err error
if value, err := CreateProductPlanRepository(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{}{"productJobId": 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())
}
}
return rep, mod, err
}
/***** 2.配置 *****/
type FastOptions struct {
... ...
... ... @@ -2,7 +2,6 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
... ... @@ -11,9 +10,9 @@ import (
type CreateProductGroupCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
//CompanyId int `cname:"企业id" json:"companyId"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
//OrgId int `cname:"组织ID" json:"orgId"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
... ... @@ -22,26 +21,16 @@ type CreateProductGroupCommand struct {
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 班组名称
GroupName string `cname:"班组名称" json:"groupName" valid:"Required"`
// 用户Id 用户唯一标识
UserId int `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType" valid:"Required"`
// IC卡号
IcCardNumber string `cname:"IC卡号" json:"icCardNumber" valid:"Required"`
// 头像
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 班组长Id
GroupLeaderId int `cname:"班组长" json:"groupLeaderId,omitempty"`
// 帮组成员列表
GroupMembers []*domain.User `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
GroupMembers []int `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
}
func (createProductGroupCommand *CreateProductGroupCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductGroupCommand *CreateProductGroupCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type RemoveProductGroupCommand struct {
}
func (removeProductGroupCommand *RemoveProductGroupCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductGroupCommand *RemoveProductGroupCommand) ValidateCommand() error {
... ...
... ... @@ -2,7 +2,6 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
... ... @@ -20,26 +19,16 @@ type UpdateProductGroupCommand struct {
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 班组名称
GroupName string `cname:"班组名称" json:"groupName" valid:"Required"`
// 用户Id 用户唯一标识
UserId int `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType" valid:"Required"`
// IC卡号
IcCardNumber string `cname:"IC卡号" json:"icCardNumber" valid:"Required"`
// 头像
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 班组长Id
GroupLeaderId int `cname:"班组长" json:"groupLeaderId,omitempty"`
// 帮组成员列表
GroupMembers []*domain.User `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
GroupMembers []int `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
}
func (updateProductGroupCommand *UpdateProductGroupCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductGroupCommand *UpdateProductGroupCommand) ValidateCommand() error {
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"strings"
)
// 生产班组
type ProductGroupDto struct {
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
// 企业id
//CompanyId int `json:"companyId,omitempty"`
// 组织ID
//OrgId int `json:"orgId,omitempty"`
// 班组名称
GroupName string `json:"groupName,omitempty"`
// 班组长
GroupLeader string `json:"groupLeader,omitempty"`
// 帮组成员列表
GroupMembers string `json:"groupMembers,omitempty"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn,omitempty"`
// 工作位置
*domain.WorkStation
// 创建时间
//CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
//UpdatedAt time.Time `json:"updatedAt,omitempty"`
// 删除时间
//DeletedAt time.Time `json:"deletedAt,omitempty"`
}
func (d *ProductGroupDto) LoadDto(m *domain.ProductGroup) *ProductGroupDto {
d.ProductGroupId = m.ProductGroupId
d.GroupName = m.GroupName
d.GroupLeader = m.GroupLeader.UserName
var members []string
for i := range m.GroupMembers {
members = append(members, m.GroupMembers[i].UserName)
}
d.GroupMembers = strings.Join(members, ",")
d.WorkOn = m.WorkOn
d.WorkStation = m.WorkStation
return d
}
... ...
... ... @@ -14,7 +14,7 @@ type GetProductGroupQuery struct {
}
func (getProductGroupQuery *GetProductGroupQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductGroupQuery *GetProductGroupQuery) ValidateQuery() error {
... ...
... ... @@ -10,13 +10,27 @@ import (
type ListProductGroupQuery 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"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" valid:"Required"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 班组名称
GroupName string `cname:"班组名称" json:"groupName,omitempty"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName,omitempty"`
}
func (listProductGroupQuery *ListProductGroupQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductGroupQuery *ListProductGroupQuery) ValidateQuery() error {
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchProductGroupQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" valid:"Required"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 班组名称
GroupName string `cname:"班组名称" json:"groupName,omitempty"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName,omitempty"`
}
func (listProductGroupQuery *SearchProductGroupQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductGroupQuery *SearchProductGroupQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductGroupQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductGroupQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -6,8 +6,12 @@ import (
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
// 生产班组服务
... ... @@ -15,8 +19,8 @@ type ProductGroupService struct {
}
// 创建生产班组服务
func (productGroupService *ProductGroupService) CreateProductGroup(createProductGroupCommand *command.CreateProductGroupCommand) (interface{}, error) {
if err := createProductGroupCommand.ValidateCommand(); err != nil {
func (productGroupService *ProductGroupService) CreateProductGroup(operateInfo *domain.OperateInfo, cmd *command.CreateProductGroupCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -29,25 +33,47 @@ func (productGroupService *ProductGroupService) CreateProductGroup(createProduct
defer func() {
transactionContext.RollbackTransaction()
}()
newProductGroup := &domain.ProductGroup{
CompanyId: createProductGroupCommand.CompanyId,
OrgId: createProductGroupCommand.OrgId,
//WorkshopId: createProductGroupCommand.WorkshopId,
//LineId: createProductGroupCommand.LineId,
//SectionId: createProductGroupCommand.SectionId,
GroupName: createProductGroupCommand.GroupName,
//GroupLeader: createProductGroupCommand.GroupLeader,
GroupMembers: createProductGroupCommand.GroupMembers,
WorkOn: createProductGroupCommand.WorkOn,
}
var productGroupRepository domain.ProductGroupRepository
if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var leader *domain.User
var members []*domain.User
userService := domainService.NewUserService()
leader, err = userService.User(cmd.GroupLeaderId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productGroupRepository = value
}
members, err = userService.Users(cmd.GroupMembers)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
newProductGroup := &domain.ProductGroup{
CompanyId: operateInfo.CompanyId,
OrgId: operateInfo.OrgId,
GroupName: cmd.GroupName,
GroupLeader: leader,
GroupMembers: members,
WorkStation: workStation,
WorkOn: cmd.WorkOn,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if group, err := productGroupRepository.FindOne(map[string]interface{}{
"groupName": cmd.GroupName,
"workshopId": workStation.WorkshopId,
"lineId": workStation.LineId,
}); err == nil && group != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "有重复的生产班组")
}
if productGroup, err := productGroupRepository.Save(newProductGroup); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -172,8 +198,8 @@ func (productGroupService *ProductGroupService) RemoveProductGroup(removeProduct
}
// 更新生产班组服务
func (productGroupService *ProductGroupService) UpdateProductGroup(updateProductGroupCommand *command.UpdateProductGroupCommand) (interface{}, error) {
if err := updateProductGroupCommand.ValidateCommand(); err != nil {
func (productGroupService *ProductGroupService) UpdateProductGroup(cmd *command.UpdateProductGroupCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -187,21 +213,44 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(updateProduct
transactionContext.RollbackTransaction()
}()
var productGroupRepository domain.ProductGroupRepository
if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
var productGroup *domain.ProductGroup
productGroupRepository, productGroup, err = factory.FastPgProductGroup(transactionContext, cmd.ProductGroupId)
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productGroupRepository = value
}
productGroup, err := productGroupRepository.FindOne(map[string]interface{}{"productGroupId": updateProductGroupCommand.ProductGroupId})
// 更新名称
if productGroup.GroupName != cmd.GroupName {
if group, err := productGroupRepository.FindOne(map[string]interface{}{
"groupName": cmd.GroupName,
"workshopId": workStation.WorkshopId,
"lineId": workStation.LineId,
}); err == nil && group != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "有重复的生产班组")
}
}
var leader *domain.User
var members []*domain.User
userService := domainService.NewUserService()
leader, err = userService.User(cmd.GroupLeaderId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productGroup == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductGroupCommand.ProductGroupId)))
members, err = userService.Users(cmd.GroupMembers)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := productGroup.Update(tool_funs.SimpleStructToMap(updateProductGroupCommand)); err != nil {
productGroup.GroupLeader = leader
productGroup.GroupMembers = members
productGroup.WorkOn = cmd.WorkOn
productGroup.WorkStation = workStation
productGroup.GroupName = cmd.GroupName
if err := productGroup.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if productGroup, err := productGroupRepository.Save(productGroup); err != nil {
... ... @@ -214,6 +263,40 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(updateProduct
}
}
// 返回生产班组服务列表
func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *domain.OperateInfo, q *query.SearchProductGroupQuery) (int64, interface{}, error) {
q.OrgId = operateInfo.OrgId
q.CompanyId = operateInfo.CompanyId
if err := q.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var productGroupRepository domain.ProductGroupRepository
productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
count, productGroups, err := productGroupRepository.Find(utils.ObjectToMap(q))
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var results = make([]*dto.ProductGroupDto, 0)
for i := range productGroups {
newItem := &dto.ProductGroupDto{}
results = append(results, newItem.LoadDto(productGroups[i]))
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return count, results, nil
}
func NewProductGroupService(options map[string]interface{}) *ProductGroupService {
newProductGroupService := &ProductGroupService{}
return newProductGroupService
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 车间
type WorkshopDto struct {
// 企业id
//CompanyId int `json:"companyId,omitempty"`
// 组织ID
//OrgId int `json:"orgId,omitempty"`
// 车间ID
WorkshopId int `json:"workshopId,omitempty"`
// 车间名称
WorkshopName string `json:"workshopName,omitempty"`
// 负责人 (用户对象)
Principal *domain.User `json:"principal,omitempty"`
// 生产线
ProductLines []*domain.ProductLine `json:"productLines,omitempty"`
// 创建时间
//CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
//UpdatedAt time.Time `json:"updatedAt,omitempty"`
// 删除时间
//DeletedAt time.Time `json:"deletedAt,omitempty"`
}
func (dto *WorkshopDto) LoadDto(m *domain.Workshop) *WorkshopDto {
dto.WorkshopId = m.WorkshopId
dto.WorkshopName = m.WorkshopName
dto.Principal = m.Principal
dto.ProductLines = m.ProductLines
return dto
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchWorkshopQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit"`
}
func (listWorkshopQuery *SearchWorkshopQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listWorkshopQuery *SearchWorkshopQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listWorkshopQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listWorkshopQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -6,9 +6,11 @@ import (
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/dto"
"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"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"strings"
"time"
)
... ... @@ -234,6 +236,49 @@ func (workshopService *WorkshopService) UpdateWorkshop(updateWorkshopCommand *co
}
}
// 搜索车间服务列表
func (workshopService *WorkshopService) SearchWorkshop(operateInfo *domain.OperateInfo, listWorkshopQuery *query.SearchWorkshopQuery) (interface{}, error) {
if err := listWorkshopQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
workshopRepository, _, err := factory.FastPgWorkshop(transactionContext, 0)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var count int64
var workshops []*domain.Workshop
options := utils.ObjectToMap(listWorkshopQuery)
options["companyId"] = operateInfo.CompanyId
options["orgId"] = operateInfo.OrgId
if count, workshops, err = workshopRepository.Find(options); 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 results = make([]*dto.WorkshopDto, 0)
for i := range workshops {
newItem := &dto.WorkshopDto{}
results = append(results, newItem.LoadDto(workshops[i]))
}
return map[string]interface{}{
"count": count,
"workshops": results,
}, nil
}
func NewWorkshopService(options map[string]interface{}) *WorkshopService {
newWorkshopService := &WorkshopService{}
return newWorkshopService
... ...
... ... @@ -43,71 +43,9 @@ func (productGroup *ProductGroup) Identify() interface{} {
}
func (productGroup *ProductGroup) Update(data map[string]interface{}) error {
if productGroupId, ok := data["productGroupId"]; ok {
productGroup.ProductGroupId = productGroupId.(int)
}
if companyId, ok := data["companyId"]; ok {
productGroup.CompanyId = companyId.(int)
}
if orgId, ok := data["orgId"]; ok {
productGroup.OrgId = orgId.(int)
}
if groupName, ok := data["groupName"]; ok {
productGroup.GroupName = groupName.(string)
}
if userId, ok := data["userId"]; ok {
productGroup.GroupLeader.UserId = userId.(int)
}
if userName, ok := data["userName"]; ok {
productGroup.GroupLeader.UserName = userName.(string)
}
if employeeType, ok := data["employeeType"]; ok {
productGroup.GroupLeader.EmployeeType = employeeType.(int)
}
if icCardNumber, ok := data["icCardNumber"]; ok {
productGroup.GroupLeader.IcCardNumber = icCardNumber.(string)
}
if avatar, ok := data["avatar"]; ok {
productGroup.GroupLeader.Avatar = avatar.(string)
}
if phone, ok := data["phone"]; ok {
productGroup.GroupLeader.Phone = phone.(string)
}
//if groupMembers, ok := data["groupMembers"]; ok {
// productGroup.GroupMembers = groupMembers.(array)
//}
if workOn, ok := data["workOn"]; ok {
productGroup.WorkOn = workOn.(int)
}
if workStationId, ok := data["workStationId"]; ok {
productGroup.WorkStation.WorkStationId = workStationId.(string)
}
if workshopId, ok := data["workshopId"]; ok {
productGroup.WorkStation.WorkshopId = workshopId.(int)
}
if workshopName, ok := data["workshopName"]; ok {
productGroup.WorkStation.WorkshopName = workshopName.(string)
}
if lineId, ok := data["lineId"]; ok {
productGroup.WorkStation.LineId = lineId.(int)
}
if lineName, ok := data["lineName"]; ok {
productGroup.WorkStation.LineName = lineName.(string)
}
if sectionId, ok := data["sectionId"]; ok {
productGroup.WorkStation.SectionId = sectionId.(int)
}
if sectionName, ok := data["sectionName"]; ok {
productGroup.WorkStation.SectionName = sectionName.(string)
}
if createdAt, ok := data["createdAt"]; ok {
productGroup.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
productGroup.UpdatedAt = updatedAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
productGroup.DeletedAt = deletedAt.(time.Time)
}
productGroup.UpdatedAt = time.Now()
return nil
}
... ...
... ... @@ -19,6 +19,18 @@ func (svr *UserService) User(id int) (*domain.User, error) {
return svr.ToUser(rsp), nil
}
func (svr *UserService) Users(id []int) ([]*domain.User, error) {
rsp, err := svr.internalUserService.Users(id)
if err != nil {
return nil, err
}
result := make([]*domain.User, 0)
for i := range rsp {
result = append(result, svr.ToUser(rsp[i]))
}
return result, nil
}
//func(svr *UserService)Organization(id int)(*domain.Org,error){
// rsp,err:= svr.internalUserService.Organization(id)
// if err!=nil{
... ...
... ... @@ -38,19 +38,13 @@ func (repository *ProductGroupRepository) Save(productGroup *domain.ProductGroup
"updated_at",
"deleted_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_group_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_group_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "productGroup_id")
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_group_id", "deleted_at")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if productGroup.Identify() == nil {
productGroupId, err := repository.nextIdentify()
if err != nil {
return productGroup, err
} else {
productGroup.ProductGroupId = int(productGroupId)
}
if _, err := tx.QueryOne(
pg.Scan(
&productGroup.ProductGroupId,
... ... @@ -58,25 +52,23 @@ func (repository *ProductGroupRepository) Save(productGroup *domain.ProductGroup
&productGroup.OrgId,
&productGroup.GroupName,
&productGroup.GroupLeader,
pg.Array(&productGroup.GroupMembers),
&productGroup.GroupMembers,
&productGroup.WorkOn,
&productGroup.WorkStation,
&productGroup.CreatedAt,
&productGroup.UpdatedAt,
&productGroup.DeletedAt,
),
fmt.Sprintf("INSERT INTO product_groups (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
productGroup.ProductGroupId,
fmt.Sprintf("INSERT INTO manufacture.product_group (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
productGroup.CompanyId,
productGroup.OrgId,
productGroup.GroupName,
productGroup.GroupLeader,
pg.Array(productGroup.GroupMembers),
productGroup.GroupMembers,
productGroup.WorkOn,
productGroup.WorkStation,
productGroup.CreatedAt,
productGroup.UpdatedAt,
productGroup.DeletedAt,
); err != nil {
return productGroup, err
}
... ... @@ -88,25 +80,23 @@ func (repository *ProductGroupRepository) Save(productGroup *domain.ProductGroup
&productGroup.OrgId,
&productGroup.GroupName,
&productGroup.GroupLeader,
pg.Array(&productGroup.GroupMembers),
&productGroup.GroupMembers,
&productGroup.WorkOn,
&productGroup.WorkStation,
&productGroup.CreatedAt,
&productGroup.UpdatedAt,
&productGroup.DeletedAt,
),
fmt.Sprintf("UPDATE product_groups SET %s WHERE product_group_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
productGroup.ProductGroupId,
fmt.Sprintf("UPDATE manufacture.product_group SET %s WHERE product_group_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
productGroup.CompanyId,
productGroup.OrgId,
productGroup.GroupName,
productGroup.GroupLeader,
pg.Array(productGroup.GroupMembers),
productGroup.GroupMembers,
productGroup.WorkOn,
productGroup.WorkStation,
productGroup.CreatedAt,
productGroup.UpdatedAt,
productGroup.DeletedAt,
productGroup.Identify(),
); err != nil {
return productGroup, err
... ... @@ -128,6 +118,10 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf
productGroupModel := new(models.ProductGroup)
query := sqlbuilder.BuildQuery(tx.Model(productGroupModel), queryOptions)
query.SetWhereByQueryOption("product_group.product_group_id = ?", "productGroupId")
query.SetWhereByQueryOption("group_name=?", "groupName")
query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId")
query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId")
query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ...
... ... @@ -132,6 +132,8 @@ func (repository *WorkshopRepository) Find(queryOptions map[string]interface{})
query := sqlbuilder.BuildQuery(tx.Model(&workshopModels), queryOptions)
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("workshop_id", "DESC")
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
if count, err := query.SelectAndCount(); err != nil {
return 0, workshops, err
} else {
... ...
... ... @@ -25,7 +25,10 @@ func ResponseGridData(ctx *context.Context, total int64, data interface{}) utils
jsonResponse := utils.JsonResponse{}
jsonResponse["code"] = 0
jsonResponse["msg"] = "ok"
jsonResponse["data"] = map[string]interface{}{"total": total, "grid": data}
jsonResponse["data"] = map[string]interface{}{"grid": map[string]interface{}{
"total": total,
"list": data,
}}
ctx.Input.SetData("outputData", jsonResponse)
return jsonResponse
}
... ... @@ -43,12 +46,12 @@ func ParseOperateInfo(c beego.BaseController) *domain.OperateInfo {
opt.CompanyId = header(c, constant.HeaderCompanyId)
opt.OrgId = header(c, constant.HeaderOrgId)
// 默认公司组织
if opt.CompanyId == 0 {
opt.CompanyId = 1
}
if opt.OrgId == 0 {
opt.OrgId = 1
}
//if opt.CompanyId == 0 {
// opt.CompanyId = 1
//}
//if opt.OrgId == 0 {
// opt.OrgId = 1
//}
return opt
}
... ...
... ... @@ -15,7 +15,7 @@ func (controller *ProductGroupController) CreateProductGroup() {
productGroupService := service.NewProductGroupService(nil)
createProductGroupCommand := &command.CreateProductGroupCommand{}
controller.Unmarshal(createProductGroupCommand)
data, err := productGroupService.CreateProductGroup(createProductGroupCommand)
data, err := productGroupService.CreateProductGroup(ParseOperateInfo(controller.BaseController), createProductGroupCommand)
controller.Response(data, err)
}
... ... @@ -58,3 +58,11 @@ func (controller *ProductGroupController) ListProductGroup() {
data, err := productGroupService.ListProductGroup(listProductGroupQuery)
controller.Response(data, err)
}
func (controller *ProductGroupController) SearchProductGroup() {
productGroupService := service.NewProductGroupService(nil)
listProductGroupQuery := &query.SearchProductGroupQuery{}
controller.Unmarshal(listProductGroupQuery)
total, data, err := productGroupService.SearchProductGroup(ParseOperateInfo(controller.BaseController), listProductGroupQuery)
ResponseGrid(controller.BaseController, total, data, err)
}
... ...
... ... @@ -58,3 +58,11 @@ func (controller *WorkshopController) ListWorkshop() {
data, err := workshopService.ListWorkshop(listWorkshopQuery)
controller.Response(data, err)
}
func (controller *WorkshopController) SearchWorkshop() {
workshopService := service.NewWorkshopService(nil)
listWorkshopQuery := &query.SearchWorkshopQuery{}
controller.Unmarshal(listWorkshopQuery)
data, err := workshopService.SearchWorkshop(ParseOperateInfo(controller.BaseController), listWorkshopQuery)
controller.Response(data, err)
}
... ...
... ... @@ -11,4 +11,5 @@ func init() {
web.Router("/product-groups/:productGroupId", &controllers.ProductGroupController{}, "Get:GetProductGroup")
web.Router("/product-groups/:productGroupId", &controllers.ProductGroupController{}, "Delete:RemoveProductGroup")
web.Router("/product-groups/", &controllers.ProductGroupController{}, "Get:ListProductGroup")
web.Router("/product-groups/search", &controllers.ProductGroupController{}, "Post:SearchProductGroup")
}
... ...
... ... @@ -11,4 +11,5 @@ func init() {
web.Router("/workshops/:workshopId", &controllers.WorkshopController{}, "Get:GetWorkshop")
web.Router("/workshops/:workshopId", &controllers.WorkshopController{}, "Delete:RemoveWorkshop")
web.Router("/workshops/", &controllers.WorkshopController{}, "Get:ListWorkshop")
web.Router("/workshops/search", &controllers.WorkshopController{}, "Post:SearchWorkshop")
}
... ...