作者 yangfu

feat: 增加物料分组编码自动生成

1 package dto 1 package dto
2 2
3 -import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  6 +)
4 7
5 type MaterialGroupDto struct { 8 type MaterialGroupDto struct {
6 // 物料分组ID 9 // 物料分组ID
@@ -26,3 +29,30 @@ func (d *MaterialGroupDto) LoadDto(m *domain.ProductMaterialGroup, orgId int) *M @@ -26,3 +29,30 @@ func (d *MaterialGroupDto) LoadDto(m *domain.ProductMaterialGroup, orgId int) *M
26 d.MaterialGroupNumber = m.MaterialGroupNumber 29 d.MaterialGroupNumber = m.MaterialGroupNumber
27 return d 30 return d
28 } 31 }
  32 +
  33 +func (productMaterialGroup *MaterialGroupDto) PID() string {
  34 + return fmt.Sprintf("%d", productMaterialGroup.Pid)
  35 +}
  36 +func (productMaterialGroup *MaterialGroupDto) ID() string {
  37 + return fmt.Sprintf("%d", productMaterialGroup.ProductMaterialGroupId)
  38 +}
  39 +
  40 +type MaterialGroupDtos []*MaterialGroupDto
  41 +
  42 +func (tree MaterialGroupDtos) Len() int {
  43 + return len(tree)
  44 +}
  45 +
  46 +func (tree MaterialGroupDtos) Less(i, j int) bool {
  47 + if tree[i].Pid < tree[j].Pid {
  48 + return true
  49 + }
  50 + if tree[i].Pid == tree[j].Pid {
  51 + return tree[i].ProductMaterialGroupId < tree[j].ProductMaterialGroupId
  52 + }
  53 + return false
  54 +}
  55 +
  56 +func (tree MaterialGroupDtos) Swap(i, j int) {
  57 + tree[i], tree[j] = tree[j], tree[i]
  58 +}
  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 SelectorProductMaterialGroupQuery struct {
  12 + // 查询偏离量
  13 + //Offset int `cname:"查询偏离量" json:"offset"`
  14 + // 查询限制
  15 + //Limit int `cname:"查询限制" json:"limit"`
  16 + // options 'tree' 'list' default tree
  17 + Style string `json:"style"`
  18 + // 当前公司
  19 + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
  20 + // 页码
  21 + //PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
  22 + // 页数
  23 + //PageSize int `cname:"页数" json:"pageSize,omitempty"`
  24 +}
  25 +
  26 +func (cmd *SelectorProductMaterialGroupQuery) Valid(validation *validation.Validation) {
  27 + //cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
  28 + cmd.Style = "tree"
  29 +}
  30 +
  31 +func (cmd *SelectorProductMaterialGroupQuery) ValidateQuery() error {
  32 + valid := validation.Validation{}
  33 + b, err := valid.Valid(cmd)
  34 + if err != nil {
  35 + return err
  36 + }
  37 + if !b {
  38 + elem := reflect.TypeOf(cmd).Elem()
  39 + for _, validErr := range valid.Errors {
  40 + field, isExist := elem.FieldByName(validErr.Field)
  41 + if isExist {
  42 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  43 + } else {
  44 + return fmt.Errorf(validErr.Message)
  45 + }
  46 + }
  47 + }
  48 + return nil
  49 +}
@@ -12,6 +12,7 @@ import ( @@ -12,6 +12,7 @@ import (
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  15 + "sort"
15 ) 16 )
16 17
17 // 物料分组服务 18 // 物料分组服务
@@ -38,6 +39,7 @@ func (productMaterialGroupService *ProductMaterialGroupService) CreateProductMat @@ -38,6 +39,7 @@ func (productMaterialGroupService *ProductMaterialGroupService) CreateProductMat
38 MaterialGroupName: createProductMaterialGroupCommand.MaterialGroupName, 39 MaterialGroupName: createProductMaterialGroupCommand.MaterialGroupName,
39 MaterialGroupNumber: createProductMaterialGroupCommand.MaterialGroupNumber, 40 MaterialGroupNumber: createProductMaterialGroupCommand.MaterialGroupNumber,
40 } 41 }
  42 +
41 var productMaterialGroup *domain.ProductMaterialGroup 43 var productMaterialGroup *domain.ProductMaterialGroup
42 materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) 44 materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
43 if productMaterialGroup, err = materialService.AddMaterialGroup(operateInfo, newProductMaterialGroup); err != nil { 45 if productMaterialGroup, err = materialService.AddMaterialGroup(operateInfo, newProductMaterialGroup); err != nil {
@@ -185,7 +187,7 @@ func (productMaterialGroupService *ProductMaterialGroupService) UpdateProductMat @@ -185,7 +187,7 @@ func (productMaterialGroupService *ProductMaterialGroupService) UpdateProductMat
185 productMaterialGroup := &domain.ProductMaterialGroup{ 187 productMaterialGroup := &domain.ProductMaterialGroup{
186 ProductMaterialGroupId: cmd.ProductMaterialGroupId, 188 ProductMaterialGroupId: cmd.ProductMaterialGroupId,
187 MaterialGroupName: cmd.MaterialGroupName, 189 MaterialGroupName: cmd.MaterialGroupName,
188 - MaterialGroupNumber: cmd.MaterialGroupNumber, 190 + //MaterialGroupNumber: cmd.MaterialGroupNumber,
189 } 191 }
190 materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) 192 materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
191 if productMaterialGroup, err := materialService.UpdateMaterialGroup(operateInfo, productMaterialGroup); err != nil { 193 if productMaterialGroup, err := materialService.UpdateMaterialGroup(operateInfo, productMaterialGroup); err != nil {
@@ -233,6 +235,48 @@ func (productMaterialGroupService *ProductMaterialGroupService) SearchProductMat @@ -233,6 +235,48 @@ func (productMaterialGroupService *ProductMaterialGroupService) SearchProductMat
233 return count, results, nil 235 return count, results, nil
234 } 236 }
235 237
  238 +func (productMaterialGroupService *ProductMaterialGroupService) SelectorProductMaterialGroup(operateInfo *domain.OperateInfo, cmd *query.SelectorProductMaterialGroupQuery) (int64, interface{}, error) {
  239 + if err := cmd.ValidateQuery(); err != nil {
  240 + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
  241 + }
  242 + transactionContext, err := factory.CreateTransactionContext(nil)
  243 + if err != nil {
  244 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  245 + }
  246 + if err := transactionContext.StartTransaction(); err != nil {
  247 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  248 + }
  249 + defer func() {
  250 + transactionContext.RollbackTransaction()
  251 + }()
  252 + var productMaterialGroupRepository domain.ProductMaterialGroupRepository
  253 + productMaterialGroupRepository, _, _ = factory.FastProductMaterialGroup(transactionContext, 0)
  254 + queryOptions := utils.ObjectToMap(cmd)
  255 + count, productGroups, err := productMaterialGroupRepository.Find(queryOptions)
  256 + if err != nil {
  257 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  258 + }
  259 + var results = make([]*dto.MaterialGroupDto, 0)
  260 + for i := range productGroups {
  261 + newItem := &dto.MaterialGroupDto{}
  262 + newItem.LoadDto(productGroups[i], operateInfo.OrgId)
  263 + results = append(results, newItem)
  264 + }
  265 + if err := transactionContext.CommitTransaction(); err != nil {
  266 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  267 + }
  268 + if cmd.Style == "tree" {
  269 + sort.Stable(dto.MaterialGroupDtos(results))
  270 + nodes := make([]utils.TreeNode, 0)
  271 + for i := range results {
  272 + nodes = append(nodes, results[i])
  273 + }
  274 + tree := utils.NewTree(nodes)
  275 + return count, tree.Nodes, nil
  276 + }
  277 + return count, results, nil
  278 +}
  279 +
236 func NewProductMaterialGroupService(options map[string]interface{}) *ProductMaterialGroupService { 280 func NewProductMaterialGroupService(options map[string]interface{}) *ProductMaterialGroupService {
237 newProductMaterialGroupService := &ProductMaterialGroupService{} 281 newProductMaterialGroupService := &ProductMaterialGroupService{}
238 return newProductMaterialGroupService 282 return newProductMaterialGroupService
@@ -2,6 +2,7 @@ package domain @@ -2,6 +2,7 @@ package domain
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strconv"
5 "time" 6 "time"
6 ) 7 )
7 8
@@ -49,6 +50,27 @@ func (productMaterialGroup *ProductMaterialGroup) Update(data map[string]interfa @@ -49,6 +50,27 @@ func (productMaterialGroup *ProductMaterialGroup) Update(data map[string]interfa
49 return nil 50 return nil
50 } 51 }
51 52
  53 +func (productMaterialGroup *ProductMaterialGroup) GroupNumberComposeUp(parent *ProductMaterialGroup, latestNumber string, total int) string {
  54 + iNumber, err := strconv.ParseInt(latestNumber, 10, 64)
  55 +
  56 + if err == nil {
  57 + iNumber += 1
  58 + return formatFunc(iNumber)
  59 + }
  60 + if parent != nil {
  61 + return parent.MaterialGroupNumber + formatFunc(int64(total+1))
  62 + }
  63 + return formatFunc(int64(total + 1))
  64 +}
  65 +
  66 +func formatFunc(iNumber int64) string {
  67 + sNumber := fmt.Sprintf("%d", iNumber)
  68 + if len(sNumber)%2 == 1 {
  69 + return "0" + sNumber
  70 + }
  71 + return sNumber
  72 +}
  73 +
52 /***** 1.实现树 *****/ 74 /***** 1.实现树 *****/
53 75
54 func (productMaterialGroup *ProductMaterialGroup) PID() string { 76 func (productMaterialGroup *ProductMaterialGroup) PID() string {
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
  7 +)
  8 +
  9 +type ProductMaterialGroupDao struct {
  10 + transactionContext *pgTransaction.TransactionContext
  11 +}
  12 +
  13 +func (dao *ProductMaterialGroupDao) CurrentGroupLatestNumber(companyId int, productMaterialGroupId int) (string, int, error) {
  14 + m := new(models.ProductMaterialGroup)
  15 + var result string
  16 + var total int
  17 + query := dao.transactionContext.PgTx.Model(m).Where("company_id = ?", companyId)
  18 + query.Where("pid = ?", productMaterialGroupId)
  19 + query.ColumnExpr("max(material_group_number) number")
  20 + query.ColumnExpr("count(material_group_number) total")
  21 + query.AllWithDeleted()
  22 + err := query.Select(&result, &total)
  23 + return result, total, err
  24 +}
  25 +
  26 +func NewProductMaterialGroupDao(transactionContext *pgTransaction.TransactionContext) (*ProductMaterialGroupDao, error) {
  27 + if transactionContext == nil {
  28 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  29 + } else {
  30 + return &ProductMaterialGroupDao{
  31 + transactionContext: transactionContext,
  32 + }, nil
  33 + }
  34 +}
@@ -123,10 +123,10 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ @@ -123,10 +123,10 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[
123 } 123 }
124 124
125 type HourProductiveStatisticsRequest struct { 125 type HourProductiveStatisticsRequest struct {
126 - CompanyId int `json:"companyId" valid:"Required"`  
127 - OrgId int `json:"orgId" valid:"Required"`  
128 - WorkshopId int `json:"workshopId" valid:"Required"`  
129 - Date time.Time `json:"date"` 126 + CompanyId int `json:"companyId" valid:"Required"`
  127 + OrgId int `json:"orgId" valid:"Required"`
  128 + WorkshopId int `json:"workshopId" valid:"Required"`
  129 + Date utils.TimeString `json:"date"`
130 } 130 }
131 131
132 func NewXYData(xData []string, values interface{}) interface{} { 132 func NewXYData(xData []string, values interface{}) interface{} {
@@ -154,8 +154,8 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map @@ -154,8 +154,8 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map
154 Total float64 `json:"total"` 154 Total float64 `json:"total"`
155 } 155 }
156 var date = time.Now() 156 var date = time.Now()
157 - if !xtime.IsZero(request.Date) {  
158 - date = request.Date 157 + if !xtime.IsZero(time.Time(request.Date)) {
  158 + date = time.Time(request.Date)
159 } 159 }
160 workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) 160 workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId})
161 if err != nil || workshop == nil { 161 if err != nil || workshop == nil {
@@ -213,8 +213,8 @@ func (ptr *PGCommonStatisticsService) ProportionOfSecondLevelStatistics(queryOpt @@ -213,8 +213,8 @@ func (ptr *PGCommonStatisticsService) ProportionOfSecondLevelStatistics(queryOpt
213 } 213 }
214 productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext) 214 productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext)
215 var date = time.Now() 215 var date = time.Now()
216 - if !xtime.IsZero(request.Date) {  
217 - date = request.Date 216 + if !xtime.IsZero(time.Time(request.Date)) {
  217 + date = time.Time(request.Date)
218 } 218 }
219 var input = []struct { 219 var input = []struct {
220 name string 220 name string
@@ -262,8 +262,8 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que @@ -262,8 +262,8 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que
262 } 262 }
263 productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) 263 productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext)
264 var date = time.Now() 264 var date = time.Now()
265 - if !xtime.IsZero(request.Date) {  
266 - date = request.Date 265 + if !xtime.IsZero(time.Time(request.Date)) {
  266 + date = time.Time(request.Date)
267 } 267 }
268 var input = []struct { 268 var input = []struct {
269 name string 269 name string
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
9 "sort" 10 "sort"
@@ -66,6 +67,10 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do @@ -66,6 +67,10 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do
66 parent *domain.ProductMaterialGroup 67 parent *domain.ProductMaterialGroup
67 newProductMaterialGroup *domain.ProductMaterialGroup 68 newProductMaterialGroup *domain.ProductMaterialGroup
68 productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) 69 productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext)
  70 +
  71 + productMaterialGroupDao *dao.ProductMaterialGroupDao
  72 + latestNumber string
  73 + total int
69 ) 74 )
70 if user, err = NewUserService().User(opt.UserId); err != nil { 75 if user, err = NewUserService().User(opt.UserId); err != nil {
71 return nil, err 76 return nil, err
@@ -81,6 +86,12 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do @@ -81,6 +86,12 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do
81 if newProductMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || newProductMaterialGroup != nil { 86 if newProductMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || newProductMaterialGroup != nil {
82 return nil, fmt.Errorf("物料分组编码已存在") 87 return nil, fmt.Errorf("物料分组编码已存在")
83 } 88 }
  89 + productMaterialGroupDao, _ = dao.NewProductMaterialGroupDao(ptr.transactionContext)
  90 + latestNumber, total, err = productMaterialGroupDao.CurrentGroupLatestNumber(opt.CompanyId, item.Pid)
  91 + if err != nil {
  92 + return nil, err
  93 + }
  94 +
84 newProductMaterialGroup = &domain.ProductMaterialGroup{ 95 newProductMaterialGroup = &domain.ProductMaterialGroup{
85 CompanyId: opt.CompanyId, 96 CompanyId: opt.CompanyId,
86 OrgId: opt.OrgId, 97 OrgId: opt.OrgId,
@@ -92,16 +103,17 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do @@ -92,16 +103,17 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do
92 UpdatedAt: time.Now(), 103 UpdatedAt: time.Now(),
93 Ext: domain.NewExt(org.OrgName).WithOperator(user), 104 Ext: domain.NewExt(org.OrgName).WithOperator(user),
94 } 105 }
  106 + newProductMaterialGroup.MaterialGroupNumber = newProductMaterialGroup.GroupNumberComposeUp(parent, latestNumber, total)
95 newProductMaterialGroup, err = productMaterialGroupRepository.Save(newProductMaterialGroup) 107 newProductMaterialGroup, err = productMaterialGroupRepository.Save(newProductMaterialGroup)
96 return newProductMaterialGroup, err 108 return newProductMaterialGroup, err
97 } 109 }
98 110
99 func (ptr *PGMaterialService) UpdateMaterialGroup(opt *domain.OperateInfo, item *domain.ProductMaterialGroup) (*domain.ProductMaterialGroup, error) { 111 func (ptr *PGMaterialService) UpdateMaterialGroup(opt *domain.OperateInfo, item *domain.ProductMaterialGroup) (*domain.ProductMaterialGroup, error) {
100 var ( 112 var (
101 - user *domain.User  
102 - org *domain.Org  
103 - err error  
104 - parent *domain.ProductMaterialGroup 113 + user *domain.User
  114 + org *domain.Org
  115 + err error
  116 + //parent *domain.ProductMaterialGroup
105 productMaterialGroup *domain.ProductMaterialGroup 117 productMaterialGroup *domain.ProductMaterialGroup
106 productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) 118 productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext)
107 ) 119 )
@@ -111,24 +123,25 @@ func (ptr *PGMaterialService) UpdateMaterialGroup(opt *domain.OperateInfo, item @@ -111,24 +123,25 @@ func (ptr *PGMaterialService) UpdateMaterialGroup(opt *domain.OperateInfo, item
111 if org, err = NewUserService().Organization(opt.OrgId); err != nil { 123 if org, err = NewUserService().Organization(opt.OrgId); err != nil {
112 return nil, err 124 return nil, err
113 } 125 }
114 - if item.ProductMaterialGroupId == item.Pid {  
115 - return nil, fmt.Errorf("当前物料分组不能做为自己上级")  
116 - } 126 + //if item.ProductMaterialGroupId == item.Pid {
  127 + // return nil, fmt.Errorf("当前物料分组不能做为自己上级")
  128 + //}
117 if productMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.ProductMaterialGroupId}); err != nil || productMaterialGroup == nil { 129 if productMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.ProductMaterialGroupId}); err != nil || productMaterialGroup == nil {
118 return nil, fmt.Errorf("物料分组不存在") 130 return nil, fmt.Errorf("物料分组不存在")
119 } 131 }
120 - if item.Pid != productMaterialGroup.ProductMaterialGroupId && item.Pid != 0 {  
121 - if parent, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.Pid}); err != nil || parent == nil {  
122 - return nil, fmt.Errorf("上级物料分组不存在")  
123 - }  
124 - }  
125 - if productMaterialGroup.MaterialGroupNumber != item.MaterialGroupNumber {  
126 - if group, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || group != nil {  
127 - return nil, fmt.Errorf("物料分组编码已存在")  
128 - }  
129 - }  
130 132
131 - productMaterialGroup.MaterialGroupNumber = item.MaterialGroupNumber 133 + //if item.Pid != productMaterialGroup.ProductMaterialGroupId && item.Pid != 0 {
  134 + // if parent, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.Pid}); err != nil || parent == nil {
  135 + // return nil, fmt.Errorf("上级物料分组不存在")
  136 + // }
  137 + //}
  138 + //if productMaterialGroup.MaterialGroupNumber != item.MaterialGroupNumber {
  139 + // if group, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || group != nil {
  140 + // return nil, fmt.Errorf("物料分组编码已存在")
  141 + // }
  142 + //}
  143 + //productMaterialGroup.MaterialGroupNumber = item.MaterialGroupNumber
  144 +
132 productMaterialGroup.MaterialGroupName = item.MaterialGroupName 145 productMaterialGroup.MaterialGroupName = item.MaterialGroupName
133 productMaterialGroup.UpdatedAt = item.UpdatedAt 146 productMaterialGroup.UpdatedAt = item.UpdatedAt
134 productMaterialGroup.Ext = domain.NewExt(org.OrgName).WithOperator(user) 147 productMaterialGroup.Ext = domain.NewExt(org.OrgName).WithOperator(user)
1 package utils 1 package utils
2 2
3 import ( 3 import (
  4 + "github.com/linmadan/egglib-go/utils/xtime"
4 "strconv" 5 "strconv"
5 "time" 6 "time"
6 ) 7 )
@@ -103,3 +104,32 @@ func TimeBeforeEqual(t1, t2 time.Time) bool { @@ -103,3 +104,32 @@ func TimeBeforeEqual(t1, t2 time.Time) bool {
103 } 104 }
104 return false 105 return false
105 } 106 }
  107 +
  108 +type TimeString time.Time
  109 +
  110 +func (timeString *TimeString) UnmarshalJSON(data []byte) error {
  111 + if len(data) == 2 {
  112 + return nil
  113 + }
  114 + t, err := xtime.Parse(string(data[1 : len(data)-1]))
  115 + if err != nil {
  116 + return err
  117 + }
  118 + *timeString = TimeString(t)
  119 + return nil
  120 +}
  121 +
  122 +func (timeString TimeString) MarshalJSON() ([]byte, error) {
  123 + if xtime.IsZero(time.Time(timeString)) {
  124 + return []byte(`""`), nil
  125 + }
  126 + b := make([]byte, 0)
  127 + b = append(b, '"')
  128 + b = time.Time(timeString).AppendFormat(b, time.RFC3339)
  129 + b = append(b, '"')
  130 + return b, nil
  131 +}
  132 +
  133 +func (timeString TimeString) Time() time.Time {
  134 + return time.Time(timeString)
  135 +}
@@ -78,14 +78,10 @@ func (controller *ProductMaterialGroupController) SearchProductMaterialGroup() { @@ -78,14 +78,10 @@ func (controller *ProductMaterialGroupController) SearchProductMaterialGroup() {
78 78
79 func (controller *ProductMaterialGroupController) SelectorProductMaterialGroup() { 79 func (controller *ProductMaterialGroupController) SelectorProductMaterialGroup() {
80 productMaterialGroupService := service.NewProductMaterialGroupService(nil) 80 productMaterialGroupService := service.NewProductMaterialGroupService(nil)
81 - cmd := &query.SearchProductMaterialGroupQuery{}  
82 - offset, _ := controller.GetInt("offset")  
83 - cmd.Offset = offset  
84 - limit, _ := controller.GetInt("limit")  
85 - cmd.Limit = limit 81 + cmd := &query.SelectorProductMaterialGroupQuery{}
86 operateInfo := ParseOperateInfo(controller.BaseController) 82 operateInfo := ParseOperateInfo(controller.BaseController)
87 cmd.CompanyId = operateInfo.CompanyId 83 cmd.CompanyId = operateInfo.CompanyId
88 - count, data, err := productMaterialGroupService.SearchProductMaterialGroup(ParseOperateInfo(controller.BaseController), cmd) 84 + count, data, err := productMaterialGroupService.SelectorProductMaterialGroup(ParseOperateInfo(controller.BaseController), cmd)
89 controller.Response(map[string]interface{}{ 85 controller.Response(map[string]interface{}{
90 "groups": data, 86 "groups": data,
91 "count": count, 87 "count": count,