作者 yangfu

生产班组管理

@@ -99,6 +99,165 @@ func FastPgProductJob(transactionContext application.TransactionContext, id int, @@ -99,6 +99,165 @@ func FastPgProductJob(transactionContext application.TransactionContext, id int,
99 return rep, mod, err 99 return rep, mod, err
100 } 100 }
101 101
  102 +// FastPgProductGroup 快速返回生产组对象
  103 +//
  104 +// transactionContext 事务
  105 +// id 对象唯一标识
  106 +func FastPgProductGroup(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductGroupRepository, *domain.ProductGroup, error) {
  107 + var rep domain.ProductGroupRepository
  108 + var mod *domain.ProductGroup
  109 + var err error
  110 + if value, err := CreateProductGroupRepository(map[string]interface{}{
  111 + "transactionContext": transactionContext,
  112 + }); err != nil {
  113 + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  114 + } else {
  115 + rep = value
  116 + }
  117 + if id > 0 {
  118 + if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
  119 + if err == domain.ErrorNotFound {
  120 + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
  121 + }
  122 + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  123 + }
  124 + }
  125 + //if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
  126 + // return nil, nil, err
  127 + //}
  128 + return rep, mod, err
  129 +}
  130 +
  131 +// FastPgProduct 快速返回产品对象
  132 +//
  133 +// transactionContext 事务
  134 +// id 对象唯一标识
  135 +func FastPgProduct(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductRepository, *domain.Product, error) {
  136 + var rep domain.ProductRepository
  137 + var mod *domain.Product
  138 + var err error
  139 + if value, err := CreateProductRepository(map[string]interface{}{
  140 + "transactionContext": transactionContext,
  141 + }); err != nil {
  142 + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  143 + } else {
  144 + rep = value
  145 + }
  146 + if id > 0 {
  147 + if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
  148 + if err == domain.ErrorNotFound {
  149 + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
  150 + }
  151 + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  152 + }
  153 + }
  154 + return rep, mod, err
  155 +}
  156 +
  157 +// FastPgDevice 快速返回设备对象
  158 +//
  159 +// transactionContext 事务
  160 +// id 对象唯一标识
  161 +func FastPgDevice(transactionContext application.TransactionContext, id int, options ...option) (domain.DeviceRepository, *domain.Device, error) {
  162 + var rep domain.DeviceRepository
  163 + var mod *domain.Device
  164 + var err error
  165 + if value, err := CreateDeviceRepository(map[string]interface{}{
  166 + "transactionContext": transactionContext,
  167 + }); err != nil {
  168 + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  169 + } else {
  170 + rep = value
  171 + }
  172 + if id > 0 {
  173 + if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
  174 + if err == domain.ErrorNotFound {
  175 + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
  176 + }
  177 + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  178 + }
  179 + }
  180 + return rep, mod, err
  181 +}
  182 +
  183 +// FastPgProductCalendar 快速返回设备对象
  184 +//
  185 +// transactionContext 事务
  186 +// id 对象唯一标识
  187 +func FastPgProductCalendar(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductCalendarRepository, *domain.ProductCalendar, error) {
  188 + var rep domain.ProductCalendarRepository
  189 + var mod *domain.ProductCalendar
  190 + var err error
  191 + if value, err := CreateProductCalendarRepository(map[string]interface{}{
  192 + "transactionContext": transactionContext,
  193 + }); err != nil {
  194 + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  195 + } else {
  196 + rep = value
  197 + }
  198 + if id > 0 {
  199 + if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
  200 + if err == domain.ErrorNotFound {
  201 + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
  202 + }
  203 + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  204 + }
  205 + }
  206 + return rep, mod, err
  207 +}
  208 +
  209 +// FastPgUnitConversion 快速返回单位换算对象
  210 +//
  211 +// transactionContext 事务
  212 +// id 对象唯一标识
  213 +func FastPgUnitConversion(transactionContext application.TransactionContext, id int, options ...option) (domain.UnitConversionRepository, *domain.UnitConversion, error) {
  214 + var rep domain.UnitConversionRepository
  215 + var mod *domain.UnitConversion
  216 + var err error
  217 + if value, err := CreateUnitConversionRepository(map[string]interface{}{
  218 + "transactionContext": transactionContext,
  219 + }); err != nil {
  220 + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  221 + } else {
  222 + rep = value
  223 + }
  224 + if id > 0 {
  225 + if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
  226 + if err == domain.ErrorNotFound {
  227 + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
  228 + }
  229 + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  230 + }
  231 + }
  232 + return rep, mod, err
  233 +}
  234 +
  235 +// FastPgProductPlan 快速返回生产计划对象
  236 +//
  237 +// transactionContext 事务
  238 +// id 对象唯一标识
  239 +func FastPgProductPlan(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductPlanRepository, *domain.ProductPlan, error) {
  240 + var rep domain.ProductPlanRepository
  241 + var mod *domain.ProductPlan
  242 + var err error
  243 + if value, err := CreateProductPlanRepository(map[string]interface{}{
  244 + "transactionContext": transactionContext,
  245 + }); err != nil {
  246 + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  247 + } else {
  248 + rep = value
  249 + }
  250 + if id > 0 {
  251 + if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
  252 + if err == domain.ErrorNotFound {
  253 + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
  254 + }
  255 + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  256 + }
  257 + }
  258 + return rep, mod, err
  259 +}
  260 +
102 /***** 2.配置 *****/ 261 /***** 2.配置 *****/
103 262
104 type FastOptions struct { 263 type FastOptions struct {
@@ -2,7 +2,6 @@ package command @@ -2,7 +2,6 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"  
6 "reflect" 5 "reflect"
7 "strings" 6 "strings"
8 7
@@ -11,9 +10,9 @@ import ( @@ -11,9 +10,9 @@ import (
11 10
12 type CreateProductGroupCommand struct { 11 type CreateProductGroupCommand struct {
13 // 企业id 12 // 企业id
14 - CompanyId int `cname:"企业id" json:"companyId" valid:"Required"` 13 + //CompanyId int `cname:"企业id" json:"companyId"`
15 // 组织ID 14 // 组织ID
16 - OrgId int `cname:"组织ID" json:"orgId" valid:"Required"` 15 + //OrgId int `cname:"组织ID" json:"orgId"`
17 // 车间ID 16 // 车间ID
18 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` 17 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
19 // 生产线ID 18 // 生产线ID
@@ -22,26 +21,16 @@ type CreateProductGroupCommand struct { @@ -22,26 +21,16 @@ type CreateProductGroupCommand struct {
22 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` 21 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
23 // 班组名称 22 // 班组名称
24 GroupName string `cname:"班组名称" json:"groupName" valid:"Required"` 23 GroupName string `cname:"班组名称" json:"groupName" valid:"Required"`
25 - // 用户Id 用户唯一标识  
26 - UserId int `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`  
27 - // 用户姓名  
28 - UserName string `cname:"用户姓名" json:"userName" valid:"Required"`  
29 - // 员工类型 1:固定 2:派遣 3.临时  
30 - EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType" valid:"Required"`  
31 - // IC卡号  
32 - IcCardNumber string `cname:"IC卡号" json:"icCardNumber" valid:"Required"`  
33 - // 头像  
34 - Avatar string `cname:"头像" json:"avatar" valid:"Required"`  
35 - // 手机号码  
36 - Phone string `cname:"手机号码" json:"phone" valid:"Required"` 24 + // 班组长Id
  25 + GroupLeaderId int `cname:"班组长" json:"groupLeaderId,omitempty"`
37 // 帮组成员列表 26 // 帮组成员列表
38 - GroupMembers []*domain.User `cname:"帮组成员列表" json:"groupMembers" valid:"Required"` 27 + GroupMembers []int `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
39 // 上班班次 1:全天 2:白班 4:中班 8:夜班 28 // 上班班次 1:全天 2:白班 4:中班 8:夜班
40 WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` 29 WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
41 } 30 }
42 31
43 func (createProductGroupCommand *CreateProductGroupCommand) Valid(validation *validation.Validation) { 32 func (createProductGroupCommand *CreateProductGroupCommand) Valid(validation *validation.Validation) {
44 - validation.SetError("CustomValid", "未实现的自定义认证") 33 + //validation.SetError("CustomValid", "未实现的自定义认证")
45 } 34 }
46 35
47 func (createProductGroupCommand *CreateProductGroupCommand) ValidateCommand() error { 36 func (createProductGroupCommand *CreateProductGroupCommand) ValidateCommand() error {
@@ -14,7 +14,7 @@ type RemoveProductGroupCommand struct { @@ -14,7 +14,7 @@ type RemoveProductGroupCommand struct {
14 } 14 }
15 15
16 func (removeProductGroupCommand *RemoveProductGroupCommand) Valid(validation *validation.Validation) { 16 func (removeProductGroupCommand *RemoveProductGroupCommand) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (removeProductGroupCommand *RemoveProductGroupCommand) ValidateCommand() error { 20 func (removeProductGroupCommand *RemoveProductGroupCommand) ValidateCommand() error {
@@ -2,7 +2,6 @@ package command @@ -2,7 +2,6 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"  
6 "reflect" 5 "reflect"
7 "strings" 6 "strings"
8 7
@@ -20,26 +19,16 @@ type UpdateProductGroupCommand struct { @@ -20,26 +19,16 @@ type UpdateProductGroupCommand struct {
20 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` 19 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
21 // 班组名称 20 // 班组名称
22 GroupName string `cname:"班组名称" json:"groupName" valid:"Required"` 21 GroupName string `cname:"班组名称" json:"groupName" valid:"Required"`
23 - // 用户Id 用户唯一标识  
24 - UserId int `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`  
25 - // 用户姓名  
26 - UserName string `cname:"用户姓名" json:"userName" valid:"Required"`  
27 - // 员工类型 1:固定 2:派遣 3.临时  
28 - EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType" valid:"Required"`  
29 - // IC卡号  
30 - IcCardNumber string `cname:"IC卡号" json:"icCardNumber" valid:"Required"`  
31 - // 头像  
32 - Avatar string `cname:"头像" json:"avatar" valid:"Required"`  
33 - // 手机号码  
34 - Phone string `cname:"手机号码" json:"phone" valid:"Required"` 22 + // 班组长Id
  23 + GroupLeaderId int `cname:"班组长" json:"groupLeaderId,omitempty"`
35 // 帮组成员列表 24 // 帮组成员列表
36 - GroupMembers []*domain.User `cname:"帮组成员列表" json:"groupMembers" valid:"Required"` 25 + GroupMembers []int `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
37 // 上班班次 1:全天 2:白班 4:中班 8:夜班 26 // 上班班次 1:全天 2:白班 4:中班 8:夜班
38 WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` 27 WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
39 } 28 }
40 29
41 func (updateProductGroupCommand *UpdateProductGroupCommand) Valid(validation *validation.Validation) { 30 func (updateProductGroupCommand *UpdateProductGroupCommand) Valid(validation *validation.Validation) {
42 - validation.SetError("CustomValid", "未实现的自定义认证") 31 + //validation.SetError("CustomValid", "未实现的自定义认证")
43 } 32 }
44 33
45 func (updateProductGroupCommand *UpdateProductGroupCommand) ValidateCommand() error { 34 func (updateProductGroupCommand *UpdateProductGroupCommand) ValidateCommand() error {
  1 +package dto
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 + "strings"
  6 +)
  7 +
  8 +// 生产班组
  9 +type ProductGroupDto struct {
  10 + // 生产小组ID
  11 + ProductGroupId int `json:"productGroupId,omitempty"`
  12 + // 企业id
  13 + //CompanyId int `json:"companyId,omitempty"`
  14 + // 组织ID
  15 + //OrgId int `json:"orgId,omitempty"`
  16 + // 班组名称
  17 + GroupName string `json:"groupName,omitempty"`
  18 + // 班组长
  19 + GroupLeader string `json:"groupLeader,omitempty"`
  20 + // 帮组成员列表
  21 + GroupMembers string `json:"groupMembers,omitempty"`
  22 + // 上班班次 1:全天 2:白班 4:中班 8:夜班
  23 + WorkOn int `json:"workOn,omitempty"`
  24 + // 工作位置
  25 + *domain.WorkStation
  26 + // 创建时间
  27 + //CreatedAt time.Time `json:"createdAt,omitempty"`
  28 + // 更新时间
  29 + //UpdatedAt time.Time `json:"updatedAt,omitempty"`
  30 + // 删除时间
  31 + //DeletedAt time.Time `json:"deletedAt,omitempty"`
  32 +}
  33 +
  34 +func (d *ProductGroupDto) LoadDto(m *domain.ProductGroup) *ProductGroupDto {
  35 + d.ProductGroupId = m.ProductGroupId
  36 + d.GroupName = m.GroupName
  37 + d.GroupLeader = m.GroupLeader.UserName
  38 + var members []string
  39 + for i := range m.GroupMembers {
  40 + members = append(members, m.GroupMembers[i].UserName)
  41 + }
  42 + d.GroupMembers = strings.Join(members, ",")
  43 + d.WorkOn = m.WorkOn
  44 + d.WorkStation = m.WorkStation
  45 + return d
  46 +}
@@ -14,7 +14,7 @@ type GetProductGroupQuery struct { @@ -14,7 +14,7 @@ type GetProductGroupQuery struct {
14 } 14 }
15 15
16 func (getProductGroupQuery *GetProductGroupQuery) Valid(validation *validation.Validation) { 16 func (getProductGroupQuery *GetProductGroupQuery) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (getProductGroupQuery *GetProductGroupQuery) ValidateQuery() error { 20 func (getProductGroupQuery *GetProductGroupQuery) ValidateQuery() error {
@@ -10,13 +10,27 @@ import ( @@ -10,13 +10,27 @@ import (
10 10
11 type ListProductGroupQuery struct { 11 type ListProductGroupQuery struct {
12 // 查询偏离量 12 // 查询偏离量
13 - Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` 13 + Offset int `cname:"查询偏离量" json:"offset"`
14 // 查询限制 14 // 查询限制
15 - Limit int `cname:"查询限制" json:"limit" valid:"Required"` 15 + Limit int `cname:"查询限制" json:"limit"`
  16 + // 当前公司
  17 + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
  18 + // 当前登录的组织
  19 + OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" valid:"Required"`
  20 + // 页码
  21 + PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
  22 + // 页数
  23 + PageSize int `cname:"页数" json:"pageSize,omitempty"`
  24 + // 班组名称
  25 + GroupName string `cname:"班组名称" json:"groupName,omitempty"`
  26 + // 车间名称
  27 + WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
  28 + // 生产线名称
  29 + LineName string `cname:"生产线名称" json:"lineName,omitempty"`
16 } 30 }
17 31
18 func (listProductGroupQuery *ListProductGroupQuery) Valid(validation *validation.Validation) { 32 func (listProductGroupQuery *ListProductGroupQuery) Valid(validation *validation.Validation) {
19 - validation.SetError("CustomValid", "未实现的自定义认证") 33 + //validation.SetError("CustomValid", "未实现的自定义认证")
20 } 34 }
21 35
22 func (listProductGroupQuery *ListProductGroupQuery) ValidateQuery() error { 36 func (listProductGroupQuery *ListProductGroupQuery) ValidateQuery() error {
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type SearchProductGroupQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit"`
  16 + // 当前公司
  17 + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
  18 + // 当前登录的组织
  19 + OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" valid:"Required"`
  20 + // 页码
  21 + PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
  22 + // 页数
  23 + PageSize int `cname:"页数" json:"pageSize,omitempty"`
  24 + // 班组名称
  25 + GroupName string `cname:"班组名称" json:"groupName,omitempty"`
  26 + // 车间名称
  27 + WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
  28 + // 生产线名称
  29 + LineName string `cname:"生产线名称" json:"lineName,omitempty"`
  30 +}
  31 +
  32 +func (listProductGroupQuery *SearchProductGroupQuery) Valid(validation *validation.Validation) {
  33 + //validation.SetError("CustomValid", "未实现的自定义认证")
  34 +}
  35 +
  36 +func (listProductGroupQuery *SearchProductGroupQuery) ValidateQuery() error {
  37 + valid := validation.Validation{}
  38 + b, err := valid.Valid(listProductGroupQuery)
  39 + if err != nil {
  40 + return err
  41 + }
  42 + if !b {
  43 + elem := reflect.TypeOf(listProductGroupQuery).Elem()
  44 + for _, validErr := range valid.Errors {
  45 + field, isExist := elem.FieldByName(validErr.Field)
  46 + if isExist {
  47 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  48 + } else {
  49 + return fmt.Errorf(validErr.Message)
  50 + }
  51 + }
  52 + }
  53 + return nil
  54 +}
@@ -6,8 +6,12 @@ import ( @@ -6,8 +6,12 @@ import (
6 "github.com/linmadan/egglib-go/utils/tool_funs" 6 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/command" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/dto"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/query" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/query"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  14 + "time"
11 ) 15 )
12 16
13 // 生产班组服务 17 // 生产班组服务
@@ -15,8 +19,8 @@ type ProductGroupService struct { @@ -15,8 +19,8 @@ type ProductGroupService struct {
15 } 19 }
16 20
17 // 创建生产班组服务 21 // 创建生产班组服务
18 -func (productGroupService *ProductGroupService) CreateProductGroup(createProductGroupCommand *command.CreateProductGroupCommand) (interface{}, error) {  
19 - if err := createProductGroupCommand.ValidateCommand(); err != nil { 22 +func (productGroupService *ProductGroupService) CreateProductGroup(operateInfo *domain.OperateInfo, cmd *command.CreateProductGroupCommand) (interface{}, error) {
  23 + if err := cmd.ValidateCommand(); err != nil {
20 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 24 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
21 } 25 }
22 transactionContext, err := factory.CreateTransactionContext(nil) 26 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -29,25 +33,47 @@ func (productGroupService *ProductGroupService) CreateProductGroup(createProduct @@ -29,25 +33,47 @@ func (productGroupService *ProductGroupService) CreateProductGroup(createProduct
29 defer func() { 33 defer func() {
30 transactionContext.RollbackTransaction() 34 transactionContext.RollbackTransaction()
31 }() 35 }()
32 - newProductGroup := &domain.ProductGroup{  
33 - CompanyId: createProductGroupCommand.CompanyId,  
34 - OrgId: createProductGroupCommand.OrgId,  
35 - //WorkshopId: createProductGroupCommand.WorkshopId,  
36 - //LineId: createProductGroupCommand.LineId,  
37 - //SectionId: createProductGroupCommand.SectionId,  
38 - GroupName: createProductGroupCommand.GroupName,  
39 - //GroupLeader: createProductGroupCommand.GroupLeader,  
40 - GroupMembers: createProductGroupCommand.GroupMembers,  
41 - WorkOn: createProductGroupCommand.WorkOn,  
42 - } 36 +
43 var productGroupRepository domain.ProductGroupRepository 37 var productGroupRepository domain.ProductGroupRepository
44 - if value, err := factory.CreateProductGroupRepository(map[string]interface{}{  
45 - "transactionContext": transactionContext,  
46 - }); err != nil { 38 + productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
  39 +
  40 + var workStation *domain.WorkStation
  41 + _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
  42 + if err != nil {
  43 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  44 + }
  45 +
  46 + var leader *domain.User
  47 + var members []*domain.User
  48 + userService := domainService.NewUserService()
  49 + leader, err = userService.User(cmd.GroupLeaderId)
  50 + if err != nil {
47 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 51 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
48 - } else {  
49 - productGroupRepository = value  
50 } 52 }
  53 + members, err = userService.Users(cmd.GroupMembers)
  54 + if err != nil {
  55 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  56 + }
  57 +
  58 + newProductGroup := &domain.ProductGroup{
  59 + CompanyId: operateInfo.CompanyId,
  60 + OrgId: operateInfo.OrgId,
  61 + GroupName: cmd.GroupName,
  62 + GroupLeader: leader,
  63 + GroupMembers: members,
  64 + WorkStation: workStation,
  65 + WorkOn: cmd.WorkOn,
  66 + CreatedAt: time.Now(),
  67 + UpdatedAt: time.Now(),
  68 + }
  69 + if group, err := productGroupRepository.FindOne(map[string]interface{}{
  70 + "groupName": cmd.GroupName,
  71 + "workshopId": workStation.WorkshopId,
  72 + "lineId": workStation.LineId,
  73 + }); err == nil && group != nil {
  74 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "有重复的生产班组")
  75 + }
  76 +
51 if productGroup, err := productGroupRepository.Save(newProductGroup); err != nil { 77 if productGroup, err := productGroupRepository.Save(newProductGroup); err != nil {
52 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 78 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
53 } else { 79 } else {
@@ -172,8 +198,8 @@ func (productGroupService *ProductGroupService) RemoveProductGroup(removeProduct @@ -172,8 +198,8 @@ func (productGroupService *ProductGroupService) RemoveProductGroup(removeProduct
172 } 198 }
173 199
174 // 更新生产班组服务 200 // 更新生产班组服务
175 -func (productGroupService *ProductGroupService) UpdateProductGroup(updateProductGroupCommand *command.UpdateProductGroupCommand) (interface{}, error) {  
176 - if err := updateProductGroupCommand.ValidateCommand(); err != nil { 201 +func (productGroupService *ProductGroupService) UpdateProductGroup(cmd *command.UpdateProductGroupCommand) (interface{}, error) {
  202 + if err := cmd.ValidateCommand(); err != nil {
177 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 203 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
178 } 204 }
179 transactionContext, err := factory.CreateTransactionContext(nil) 205 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -187,21 +213,44 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(updateProduct @@ -187,21 +213,44 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(updateProduct
187 transactionContext.RollbackTransaction() 213 transactionContext.RollbackTransaction()
188 }() 214 }()
189 var productGroupRepository domain.ProductGroupRepository 215 var productGroupRepository domain.ProductGroupRepository
190 - if value, err := factory.CreateProductGroupRepository(map[string]interface{}{  
191 - "transactionContext": transactionContext,  
192 - }); err != nil { 216 + var productGroup *domain.ProductGroup
  217 + productGroupRepository, productGroup, err = factory.FastPgProductGroup(transactionContext, cmd.ProductGroupId)
  218 +
  219 + var workStation *domain.WorkStation
  220 + _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
  221 + if err != nil {
193 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 222 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
194 - } else {  
195 - productGroupRepository = value  
196 } 223 }
197 - productGroup, err := productGroupRepository.FindOne(map[string]interface{}{"productGroupId": updateProductGroupCommand.ProductGroupId}) 224 +
  225 + // 更新名称
  226 + if productGroup.GroupName != cmd.GroupName {
  227 + if group, err := productGroupRepository.FindOne(map[string]interface{}{
  228 + "groupName": cmd.GroupName,
  229 + "workshopId": workStation.WorkshopId,
  230 + "lineId": workStation.LineId,
  231 + }); err == nil && group != nil {
  232 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "有重复的生产班组")
  233 + }
  234 + }
  235 +
  236 + var leader *domain.User
  237 + var members []*domain.User
  238 + userService := domainService.NewUserService()
  239 + leader, err = userService.User(cmd.GroupLeaderId)
198 if err != nil { 240 if err != nil {
199 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 241 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
200 } 242 }
201 - if productGroup == nil {  
202 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductGroupCommand.ProductGroupId))) 243 + members, err = userService.Users(cmd.GroupMembers)
  244 + if err != nil {
  245 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
203 } 246 }
204 - if err := productGroup.Update(tool_funs.SimpleStructToMap(updateProductGroupCommand)); err != nil { 247 + productGroup.GroupLeader = leader
  248 + productGroup.GroupMembers = members
  249 + productGroup.WorkOn = cmd.WorkOn
  250 + productGroup.WorkStation = workStation
  251 + productGroup.GroupName = cmd.GroupName
  252 +
  253 + if err := productGroup.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
205 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 254 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
206 } 255 }
207 if productGroup, err := productGroupRepository.Save(productGroup); err != nil { 256 if productGroup, err := productGroupRepository.Save(productGroup); err != nil {
@@ -214,6 +263,40 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(updateProduct @@ -214,6 +263,40 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(updateProduct
214 } 263 }
215 } 264 }
216 265
  266 +// 返回生产班组服务列表
  267 +func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *domain.OperateInfo, q *query.SearchProductGroupQuery) (int64, interface{}, error) {
  268 + q.OrgId = operateInfo.OrgId
  269 + q.CompanyId = operateInfo.CompanyId
  270 + if err := q.ValidateQuery(); err != nil {
  271 + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
  272 + }
  273 + transactionContext, err := factory.CreateTransactionContext(nil)
  274 + if err != nil {
  275 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  276 + }
  277 + if err := transactionContext.StartTransaction(); err != nil {
  278 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  279 + }
  280 + defer func() {
  281 + transactionContext.RollbackTransaction()
  282 + }()
  283 + var productGroupRepository domain.ProductGroupRepository
  284 + productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
  285 + count, productGroups, err := productGroupRepository.Find(utils.ObjectToMap(q))
  286 + if err != nil {
  287 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  288 + }
  289 + var results = make([]*dto.ProductGroupDto, 0)
  290 + for i := range productGroups {
  291 + newItem := &dto.ProductGroupDto{}
  292 + results = append(results, newItem.LoadDto(productGroups[i]))
  293 + }
  294 + if err := transactionContext.CommitTransaction(); err != nil {
  295 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  296 + }
  297 + return count, results, nil
  298 +}
  299 +
217 func NewProductGroupService(options map[string]interface{}) *ProductGroupService { 300 func NewProductGroupService(options map[string]interface{}) *ProductGroupService {
218 newProductGroupService := &ProductGroupService{} 301 newProductGroupService := &ProductGroupService{}
219 return newProductGroupService 302 return newProductGroupService
  1 +package dto
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 +)
  6 +
  7 +// 车间
  8 +type WorkshopDto struct {
  9 + // 企业id
  10 + //CompanyId int `json:"companyId,omitempty"`
  11 + // 组织ID
  12 + //OrgId int `json:"orgId,omitempty"`
  13 + // 车间ID
  14 + WorkshopId int `json:"workshopId,omitempty"`
  15 + // 车间名称
  16 + WorkshopName string `json:"workshopName,omitempty"`
  17 + // 负责人 (用户对象)
  18 + Principal *domain.User `json:"principal,omitempty"`
  19 + // 生产线
  20 + ProductLines []*domain.ProductLine `json:"productLines,omitempty"`
  21 + // 创建时间
  22 + //CreatedAt time.Time `json:"createdAt,omitempty"`
  23 + // 更新时间
  24 + //UpdatedAt time.Time `json:"updatedAt,omitempty"`
  25 + // 删除时间
  26 + //DeletedAt time.Time `json:"deletedAt,omitempty"`
  27 +}
  28 +
  29 +func (dto *WorkshopDto) LoadDto(m *domain.Workshop) *WorkshopDto {
  30 + dto.WorkshopId = m.WorkshopId
  31 + dto.WorkshopName = m.WorkshopName
  32 + dto.Principal = m.Principal
  33 + dto.ProductLines = m.ProductLines
  34 + return dto
  35 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type SearchWorkshopQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit"`
  16 +}
  17 +
  18 +func (listWorkshopQuery *SearchWorkshopQuery) Valid(validation *validation.Validation) {
  19 + //validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listWorkshopQuery *SearchWorkshopQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listWorkshopQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listWorkshopQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
@@ -6,9 +6,11 @@ import ( @@ -6,9 +6,11 @@ import (
6 "github.com/linmadan/egglib-go/utils/tool_funs" 6 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/command" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/dto"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/query" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/query"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
12 "strings" 14 "strings"
13 "time" 15 "time"
14 ) 16 )
@@ -234,6 +236,49 @@ func (workshopService *WorkshopService) UpdateWorkshop(updateWorkshopCommand *co @@ -234,6 +236,49 @@ func (workshopService *WorkshopService) UpdateWorkshop(updateWorkshopCommand *co
234 } 236 }
235 } 237 }
236 238
  239 +// 搜索车间服务列表
  240 +func (workshopService *WorkshopService) SearchWorkshop(operateInfo *domain.OperateInfo, listWorkshopQuery *query.SearchWorkshopQuery) (interface{}, error) {
  241 + if err := listWorkshopQuery.ValidateQuery(); err != nil {
  242 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  243 + }
  244 + transactionContext, err := factory.CreateTransactionContext(nil)
  245 + if err != nil {
  246 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  247 + }
  248 + if err := transactionContext.StartTransaction(); err != nil {
  249 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  250 + }
  251 + defer func() {
  252 + transactionContext.RollbackTransaction()
  253 + }()
  254 + workshopRepository, _, err := factory.FastPgWorkshop(transactionContext, 0)
  255 + if err != nil {
  256 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  257 + }
  258 + var count int64
  259 + var workshops []*domain.Workshop
  260 + options := utils.ObjectToMap(listWorkshopQuery)
  261 + options["companyId"] = operateInfo.CompanyId
  262 + options["orgId"] = operateInfo.OrgId
  263 + if count, workshops, err = workshopRepository.Find(options); err != nil {
  264 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  265 + }
  266 + if err := transactionContext.CommitTransaction(); err != nil {
  267 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  268 + }
  269 +
  270 + var results = make([]*dto.WorkshopDto, 0)
  271 + for i := range workshops {
  272 + newItem := &dto.WorkshopDto{}
  273 + results = append(results, newItem.LoadDto(workshops[i]))
  274 + }
  275 + return map[string]interface{}{
  276 + "count": count,
  277 + "workshops": results,
  278 + }, nil
  279 +
  280 +}
  281 +
237 func NewWorkshopService(options map[string]interface{}) *WorkshopService { 282 func NewWorkshopService(options map[string]interface{}) *WorkshopService {
238 newWorkshopService := &WorkshopService{} 283 newWorkshopService := &WorkshopService{}
239 return newWorkshopService 284 return newWorkshopService
@@ -43,71 +43,9 @@ func (productGroup *ProductGroup) Identify() interface{} { @@ -43,71 +43,9 @@ func (productGroup *ProductGroup) Identify() interface{} {
43 } 43 }
44 44
45 func (productGroup *ProductGroup) Update(data map[string]interface{}) error { 45 func (productGroup *ProductGroup) Update(data map[string]interface{}) error {
46 - if productGroupId, ok := data["productGroupId"]; ok {  
47 - productGroup.ProductGroupId = productGroupId.(int)  
48 - }  
49 - if companyId, ok := data["companyId"]; ok {  
50 - productGroup.CompanyId = companyId.(int)  
51 - }  
52 - if orgId, ok := data["orgId"]; ok {  
53 - productGroup.OrgId = orgId.(int)  
54 - }  
55 if groupName, ok := data["groupName"]; ok { 46 if groupName, ok := data["groupName"]; ok {
56 productGroup.GroupName = groupName.(string) 47 productGroup.GroupName = groupName.(string)
57 } 48 }
58 - if userId, ok := data["userId"]; ok {  
59 - productGroup.GroupLeader.UserId = userId.(int)  
60 - }  
61 - if userName, ok := data["userName"]; ok {  
62 - productGroup.GroupLeader.UserName = userName.(string)  
63 - }  
64 - if employeeType, ok := data["employeeType"]; ok {  
65 - productGroup.GroupLeader.EmployeeType = employeeType.(int)  
66 - }  
67 - if icCardNumber, ok := data["icCardNumber"]; ok {  
68 - productGroup.GroupLeader.IcCardNumber = icCardNumber.(string)  
69 - }  
70 - if avatar, ok := data["avatar"]; ok {  
71 - productGroup.GroupLeader.Avatar = avatar.(string)  
72 - }  
73 - if phone, ok := data["phone"]; ok {  
74 - productGroup.GroupLeader.Phone = phone.(string)  
75 - }  
76 - //if groupMembers, ok := data["groupMembers"]; ok {  
77 - // productGroup.GroupMembers = groupMembers.(array)  
78 - //}  
79 - if workOn, ok := data["workOn"]; ok {  
80 - productGroup.WorkOn = workOn.(int)  
81 - }  
82 - if workStationId, ok := data["workStationId"]; ok {  
83 - productGroup.WorkStation.WorkStationId = workStationId.(string)  
84 - }  
85 - if workshopId, ok := data["workshopId"]; ok {  
86 - productGroup.WorkStation.WorkshopId = workshopId.(int)  
87 - }  
88 - if workshopName, ok := data["workshopName"]; ok {  
89 - productGroup.WorkStation.WorkshopName = workshopName.(string)  
90 - }  
91 - if lineId, ok := data["lineId"]; ok {  
92 - productGroup.WorkStation.LineId = lineId.(int)  
93 - }  
94 - if lineName, ok := data["lineName"]; ok {  
95 - productGroup.WorkStation.LineName = lineName.(string)  
96 - }  
97 - if sectionId, ok := data["sectionId"]; ok {  
98 - productGroup.WorkStation.SectionId = sectionId.(int)  
99 - }  
100 - if sectionName, ok := data["sectionName"]; ok {  
101 - productGroup.WorkStation.SectionName = sectionName.(string)  
102 - }  
103 - if createdAt, ok := data["createdAt"]; ok {  
104 - productGroup.CreatedAt = createdAt.(time.Time)  
105 - }  
106 - if updatedAt, ok := data["updatedAt"]; ok {  
107 - productGroup.UpdatedAt = updatedAt.(time.Time)  
108 - }  
109 - if deletedAt, ok := data["deletedAt"]; ok {  
110 - productGroup.DeletedAt = deletedAt.(time.Time)  
111 - } 49 + productGroup.UpdatedAt = time.Now()
112 return nil 50 return nil
113 } 51 }
@@ -19,6 +19,18 @@ func (svr *UserService) User(id int) (*domain.User, error) { @@ -19,6 +19,18 @@ func (svr *UserService) User(id int) (*domain.User, error) {
19 return svr.ToUser(rsp), nil 19 return svr.ToUser(rsp), nil
20 } 20 }
21 21
  22 +func (svr *UserService) Users(id []int) ([]*domain.User, error) {
  23 + rsp, err := svr.internalUserService.Users(id)
  24 + if err != nil {
  25 + return nil, err
  26 + }
  27 + result := make([]*domain.User, 0)
  28 + for i := range rsp {
  29 + result = append(result, svr.ToUser(rsp[i]))
  30 + }
  31 + return result, nil
  32 +}
  33 +
22 //func(svr *UserService)Organization(id int)(*domain.Org,error){ 34 //func(svr *UserService)Organization(id int)(*domain.Org,error){
23 // rsp,err:= svr.internalUserService.Organization(id) 35 // rsp,err:= svr.internalUserService.Organization(id)
24 // if err!=nil{ 36 // if err!=nil{
@@ -38,19 +38,13 @@ func (repository *ProductGroupRepository) Save(productGroup *domain.ProductGroup @@ -38,19 +38,13 @@ func (repository *ProductGroupRepository) Save(productGroup *domain.ProductGroup
38 "updated_at", 38 "updated_at",
39 "deleted_at", 39 "deleted_at",
40 } 40 }
41 - insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)  
42 - insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) 41 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_group_id", "deleted_at"))
  42 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_group_id", "deleted_at"))
43 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 43 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
44 - updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "productGroup_id") 44 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_group_id", "deleted_at")
45 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) 45 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
46 tx := repository.transactionContext.PgTx 46 tx := repository.transactionContext.PgTx
47 if productGroup.Identify() == nil { 47 if productGroup.Identify() == nil {
48 - productGroupId, err := repository.nextIdentify()  
49 - if err != nil {  
50 - return productGroup, err  
51 - } else {  
52 - productGroup.ProductGroupId = int(productGroupId)  
53 - }  
54 if _, err := tx.QueryOne( 48 if _, err := tx.QueryOne(
55 pg.Scan( 49 pg.Scan(
56 &productGroup.ProductGroupId, 50 &productGroup.ProductGroupId,
@@ -58,25 +52,23 @@ func (repository *ProductGroupRepository) Save(productGroup *domain.ProductGroup @@ -58,25 +52,23 @@ func (repository *ProductGroupRepository) Save(productGroup *domain.ProductGroup
58 &productGroup.OrgId, 52 &productGroup.OrgId,
59 &productGroup.GroupName, 53 &productGroup.GroupName,
60 &productGroup.GroupLeader, 54 &productGroup.GroupLeader,
61 - pg.Array(&productGroup.GroupMembers), 55 + &productGroup.GroupMembers,
62 &productGroup.WorkOn, 56 &productGroup.WorkOn,
63 &productGroup.WorkStation, 57 &productGroup.WorkStation,
64 &productGroup.CreatedAt, 58 &productGroup.CreatedAt,
65 &productGroup.UpdatedAt, 59 &productGroup.UpdatedAt,
66 &productGroup.DeletedAt, 60 &productGroup.DeletedAt,
67 ), 61 ),
68 - fmt.Sprintf("INSERT INTO product_groups (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),  
69 - productGroup.ProductGroupId, 62 + fmt.Sprintf("INSERT INTO manufacture.product_group (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
70 productGroup.CompanyId, 63 productGroup.CompanyId,
71 productGroup.OrgId, 64 productGroup.OrgId,
72 productGroup.GroupName, 65 productGroup.GroupName,
73 productGroup.GroupLeader, 66 productGroup.GroupLeader,
74 - pg.Array(productGroup.GroupMembers), 67 + productGroup.GroupMembers,
75 productGroup.WorkOn, 68 productGroup.WorkOn,
76 productGroup.WorkStation, 69 productGroup.WorkStation,
77 productGroup.CreatedAt, 70 productGroup.CreatedAt,
78 productGroup.UpdatedAt, 71 productGroup.UpdatedAt,
79 - productGroup.DeletedAt,  
80 ); err != nil { 72 ); err != nil {
81 return productGroup, err 73 return productGroup, err
82 } 74 }
@@ -88,25 +80,23 @@ func (repository *ProductGroupRepository) Save(productGroup *domain.ProductGroup @@ -88,25 +80,23 @@ func (repository *ProductGroupRepository) Save(productGroup *domain.ProductGroup
88 &productGroup.OrgId, 80 &productGroup.OrgId,
89 &productGroup.GroupName, 81 &productGroup.GroupName,
90 &productGroup.GroupLeader, 82 &productGroup.GroupLeader,
91 - pg.Array(&productGroup.GroupMembers), 83 + &productGroup.GroupMembers,
92 &productGroup.WorkOn, 84 &productGroup.WorkOn,
93 &productGroup.WorkStation, 85 &productGroup.WorkStation,
94 &productGroup.CreatedAt, 86 &productGroup.CreatedAt,
95 &productGroup.UpdatedAt, 87 &productGroup.UpdatedAt,
96 &productGroup.DeletedAt, 88 &productGroup.DeletedAt,
97 ), 89 ),
98 - fmt.Sprintf("UPDATE product_groups SET %s WHERE product_group_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),  
99 - productGroup.ProductGroupId, 90 + fmt.Sprintf("UPDATE manufacture.product_group SET %s WHERE product_group_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
100 productGroup.CompanyId, 91 productGroup.CompanyId,
101 productGroup.OrgId, 92 productGroup.OrgId,
102 productGroup.GroupName, 93 productGroup.GroupName,
103 productGroup.GroupLeader, 94 productGroup.GroupLeader,
104 - pg.Array(productGroup.GroupMembers), 95 + productGroup.GroupMembers,
105 productGroup.WorkOn, 96 productGroup.WorkOn,
106 productGroup.WorkStation, 97 productGroup.WorkStation,
107 productGroup.CreatedAt, 98 productGroup.CreatedAt,
108 productGroup.UpdatedAt, 99 productGroup.UpdatedAt,
109 - productGroup.DeletedAt,  
110 productGroup.Identify(), 100 productGroup.Identify(),
111 ); err != nil { 101 ); err != nil {
112 return productGroup, err 102 return productGroup, err
@@ -128,6 +118,10 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf @@ -128,6 +118,10 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf
128 productGroupModel := new(models.ProductGroup) 118 productGroupModel := new(models.ProductGroup)
129 query := sqlbuilder.BuildQuery(tx.Model(productGroupModel), queryOptions) 119 query := sqlbuilder.BuildQuery(tx.Model(productGroupModel), queryOptions)
130 query.SetWhereByQueryOption("product_group.product_group_id = ?", "productGroupId") 120 query.SetWhereByQueryOption("product_group.product_group_id = ?", "productGroupId")
  121 + query.SetWhereByQueryOption("group_name=?", "groupName")
  122 + query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId")
  123 + query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId")
  124 + query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId")
131 if err := query.First(); err != nil { 125 if err := query.First(); err != nil {
132 if err.Error() == "pg: no rows in result set" { 126 if err.Error() == "pg: no rows in result set" {
133 return nil, fmt.Errorf("没有此资源") 127 return nil, fmt.Errorf("没有此资源")
@@ -132,6 +132,8 @@ func (repository *WorkshopRepository) Find(queryOptions map[string]interface{}) @@ -132,6 +132,8 @@ func (repository *WorkshopRepository) Find(queryOptions map[string]interface{})
132 query := sqlbuilder.BuildQuery(tx.Model(&workshopModels), queryOptions) 132 query := sqlbuilder.BuildQuery(tx.Model(&workshopModels), queryOptions)
133 query.SetOffsetAndLimit(domain.MaxQueryRow) 133 query.SetOffsetAndLimit(domain.MaxQueryRow)
134 query.SetOrderDirect("workshop_id", "DESC") 134 query.SetOrderDirect("workshop_id", "DESC")
  135 + query.SetWhereByQueryOption("company_id = ?", "companyId")
  136 + query.SetWhereByQueryOption("org_id = ?", "orgId")
135 if count, err := query.SelectAndCount(); err != nil { 137 if count, err := query.SelectAndCount(); err != nil {
136 return 0, workshops, err 138 return 0, workshops, err
137 } else { 139 } else {
@@ -25,7 +25,10 @@ func ResponseGridData(ctx *context.Context, total int64, data interface{}) utils @@ -25,7 +25,10 @@ func ResponseGridData(ctx *context.Context, total int64, data interface{}) utils
25 jsonResponse := utils.JsonResponse{} 25 jsonResponse := utils.JsonResponse{}
26 jsonResponse["code"] = 0 26 jsonResponse["code"] = 0
27 jsonResponse["msg"] = "ok" 27 jsonResponse["msg"] = "ok"
28 - jsonResponse["data"] = map[string]interface{}{"total": total, "grid": data} 28 + jsonResponse["data"] = map[string]interface{}{"grid": map[string]interface{}{
  29 + "total": total,
  30 + "list": data,
  31 + }}
29 ctx.Input.SetData("outputData", jsonResponse) 32 ctx.Input.SetData("outputData", jsonResponse)
30 return jsonResponse 33 return jsonResponse
31 } 34 }
@@ -43,12 +46,12 @@ func ParseOperateInfo(c beego.BaseController) *domain.OperateInfo { @@ -43,12 +46,12 @@ func ParseOperateInfo(c beego.BaseController) *domain.OperateInfo {
43 opt.CompanyId = header(c, constant.HeaderCompanyId) 46 opt.CompanyId = header(c, constant.HeaderCompanyId)
44 opt.OrgId = header(c, constant.HeaderOrgId) 47 opt.OrgId = header(c, constant.HeaderOrgId)
45 // 默认公司组织 48 // 默认公司组织
46 - if opt.CompanyId == 0 {  
47 - opt.CompanyId = 1  
48 - }  
49 - if opt.OrgId == 0 {  
50 - opt.OrgId = 1  
51 - } 49 + //if opt.CompanyId == 0 {
  50 + // opt.CompanyId = 1
  51 + //}
  52 + //if opt.OrgId == 0 {
  53 + // opt.OrgId = 1
  54 + //}
52 return opt 55 return opt
53 } 56 }
54 57
@@ -15,7 +15,7 @@ func (controller *ProductGroupController) CreateProductGroup() { @@ -15,7 +15,7 @@ func (controller *ProductGroupController) CreateProductGroup() {
15 productGroupService := service.NewProductGroupService(nil) 15 productGroupService := service.NewProductGroupService(nil)
16 createProductGroupCommand := &command.CreateProductGroupCommand{} 16 createProductGroupCommand := &command.CreateProductGroupCommand{}
17 controller.Unmarshal(createProductGroupCommand) 17 controller.Unmarshal(createProductGroupCommand)
18 - data, err := productGroupService.CreateProductGroup(createProductGroupCommand) 18 + data, err := productGroupService.CreateProductGroup(ParseOperateInfo(controller.BaseController), createProductGroupCommand)
19 controller.Response(data, err) 19 controller.Response(data, err)
20 } 20 }
21 21
@@ -58,3 +58,11 @@ func (controller *ProductGroupController) ListProductGroup() { @@ -58,3 +58,11 @@ func (controller *ProductGroupController) ListProductGroup() {
58 data, err := productGroupService.ListProductGroup(listProductGroupQuery) 58 data, err := productGroupService.ListProductGroup(listProductGroupQuery)
59 controller.Response(data, err) 59 controller.Response(data, err)
60 } 60 }
  61 +
  62 +func (controller *ProductGroupController) SearchProductGroup() {
  63 + productGroupService := service.NewProductGroupService(nil)
  64 + listProductGroupQuery := &query.SearchProductGroupQuery{}
  65 + controller.Unmarshal(listProductGroupQuery)
  66 + total, data, err := productGroupService.SearchProductGroup(ParseOperateInfo(controller.BaseController), listProductGroupQuery)
  67 + ResponseGrid(controller.BaseController, total, data, err)
  68 +}
@@ -58,3 +58,11 @@ func (controller *WorkshopController) ListWorkshop() { @@ -58,3 +58,11 @@ func (controller *WorkshopController) ListWorkshop() {
58 data, err := workshopService.ListWorkshop(listWorkshopQuery) 58 data, err := workshopService.ListWorkshop(listWorkshopQuery)
59 controller.Response(data, err) 59 controller.Response(data, err)
60 } 60 }
  61 +
  62 +func (controller *WorkshopController) SearchWorkshop() {
  63 + workshopService := service.NewWorkshopService(nil)
  64 + listWorkshopQuery := &query.SearchWorkshopQuery{}
  65 + controller.Unmarshal(listWorkshopQuery)
  66 + data, err := workshopService.SearchWorkshop(ParseOperateInfo(controller.BaseController), listWorkshopQuery)
  67 + controller.Response(data, err)
  68 +}
@@ -11,4 +11,5 @@ func init() { @@ -11,4 +11,5 @@ func init() {
11 web.Router("/product-groups/:productGroupId", &controllers.ProductGroupController{}, "Get:GetProductGroup") 11 web.Router("/product-groups/:productGroupId", &controllers.ProductGroupController{}, "Get:GetProductGroup")
12 web.Router("/product-groups/:productGroupId", &controllers.ProductGroupController{}, "Delete:RemoveProductGroup") 12 web.Router("/product-groups/:productGroupId", &controllers.ProductGroupController{}, "Delete:RemoveProductGroup")
13 web.Router("/product-groups/", &controllers.ProductGroupController{}, "Get:ListProductGroup") 13 web.Router("/product-groups/", &controllers.ProductGroupController{}, "Get:ListProductGroup")
  14 + web.Router("/product-groups/search", &controllers.ProductGroupController{}, "Post:SearchProductGroup")
14 } 15 }
@@ -11,4 +11,5 @@ func init() { @@ -11,4 +11,5 @@ func init() {
11 web.Router("/workshops/:workshopId", &controllers.WorkshopController{}, "Get:GetWorkshop") 11 web.Router("/workshops/:workshopId", &controllers.WorkshopController{}, "Get:GetWorkshop")
12 web.Router("/workshops/:workshopId", &controllers.WorkshopController{}, "Delete:RemoveWorkshop") 12 web.Router("/workshops/:workshopId", &controllers.WorkshopController{}, "Delete:RemoveWorkshop")
13 web.Router("/workshops/", &controllers.WorkshopController{}, "Get:ListWorkshop") 13 web.Router("/workshops/", &controllers.WorkshopController{}, "Get:ListWorkshop")
  14 + web.Router("/workshops/search", &controllers.WorkshopController{}, "Post:SearchWorkshop")
14 } 15 }