作者 13655977079

feat:增加物料管理

... ... @@ -2,3 +2,6 @@
-- 表product_material_group 增加唯一索引 idx_unq_product_material_group_company_id_org_id_material_group_number
create UNIQUE INDEX idx_unq_product_material_group_company_id_org_id_material_group_number on manufacture.product_material_group using btree(company_id,org_id,material_group_number);
-- 表product_material 增加唯一索引 idx_unq_product_material_company_id_material_number
create UNIQUE INDEX idx_unq_product_material_company_id_material_number on manufacture.product_material using btree(company_id,material_number);
\ No newline at end of file
... ...
... ... @@ -14,19 +14,15 @@ type CreateProductCommand struct {
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001
ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode"`
ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode" valid:"Required"`
// 产品名称
ProductName string `cname:"产品名称" json:"productName" valid:"Required"`
// ProductName string `cname:"产品名称" json:"productName" valid:"Required"`
// 产品类别
ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"`
// 数量(保留两位小数)
//Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
//Weight float64 `cname:"重量" json:"weight" valid:"Required"`
}
func (createProductCommand *CreateProductCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -12,19 +12,15 @@ type UpdateProductCommand struct {
// 产品ID
ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
// 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001
ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode"`
//ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode"`
// 产品名称
ProductName string `cname:"产品名称" json:"productName" valid:"Required"`
ProductName string `cname:"产品名称" json:"productName" `
// 产品类别
ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"`
// 数量(保留两位小数)
//Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
ProductCategory string `cname:"产品类别" json:"productCategory"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
Unit string `cname:"单位" json:"unit"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
//Weight float64 `cname:"重量" json:"weight" valid:"Required"`
}
func (updateProductCommand *UpdateProductCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -14,7 +14,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
// 产品服务
... ... @@ -22,7 +21,7 @@ type ProductService struct {
}
// 创建产品服务
func (productService *ProductService) CreateProduct(createProductCommand *command.CreateProductCommand) (interface{}, error) {
func (productService *ProductService) CreateProduct(opt *domain.OperateInfo, createProductCommand *command.CreateProductCommand) (interface{}, error) {
if err := createProductCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -37,50 +36,23 @@ func (productService *ProductService) CreateProduct(createProductCommand *comman
transactionContext.RollbackTransaction()
}()
if len(createProductCommand.ProductCode) == 0 {
generator := redis.NewProductCodeCache(createProductCommand.CompanyId)
code, err := redis.GenCode(generator)
if err != nil {
log.Logger.Error(err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "服务器异常")
}
createProductCommand.ProductCode = code
batchAddProductService, _ := domainService.NewPGBatchAddProductService(transactionContext.(*pgTransaction.TransactionContext))
item := &domain.ImportProductItem{
ProductCode: createProductCommand.ProductCode,
UnitWeight: utils.AssertString(createProductCommand.UnitWeight),
}
var userService = domainService.NewUserService()
var org *domain.Org
org, err = userService.Organization(createProductCommand.OrgId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if _, err = batchAddProductService.BatchAddProduct(opt, []*domain.ImportProductItem{
item,
}, false); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
newProduct := &domain.Product{
CompanyId: createProductCommand.CompanyId,
OrgId: createProductCommand.OrgId,
ProductCode: createProductCommand.ProductCode,
ProductName: createProductCommand.ProductName,
ProductCategory: createProductCommand.ProductCategory,
ProductSpec: &domain.UnitQuantity{
Unit: createProductCommand.Unit,
UnitWeight: createProductCommand.UnitWeight,
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName),
}
productRepository, _, _ := factory.FastPgProduct(transactionContext, 0)
if item, err := productRepository.FindOne(map[string]interface{}{"companyId": createProductCommand.CompanyId, "productCode": createProductCommand.ProductCode}); err == nil && item != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "产品编号重复,请重新提交")
if len(item.FailReason) > 0 {
return nil, application.ThrowError(application.TRANSACTION_ERROR, item.FailReason)
}
if product, err := productRepository.Save(newProduct); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return product, nil
}
return struct{}{}, nil
}
// 返回产品服务
... ... @@ -242,7 +214,7 @@ func (productService *ProductService) BatchRemoveProduct(cmd *command.BatchRemov
}
// 更新产品服务
func (productService *ProductService) UpdateProduct(updateProductCommand *command.UpdateProductCommand) (interface{}, error) {
func (productService *ProductService) UpdateProduct(opt *domain.OperateInfo, updateProductCommand *command.UpdateProductCommand) (interface{}, error) {
if err := updateProductCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -260,19 +232,11 @@ func (productService *ProductService) UpdateProduct(updateProductCommand *comman
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(updateProductCommand.ProductCode) == 0 {
generator := redis.NewProductCodeCache(product.CompanyId)
code, err := redis.GenCode(generator)
if err != nil {
log.Logger.Error(err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "服务器异常")
}
updateProductCommand.ProductCode = code
}
if updateProductCommand.ProductCode != product.ProductCode {
if item, err := productRepository.FindOne(map[string]interface{}{"companyId": product.CompanyId, "productCode": updateProductCommand.ProductCode}); err == nil && item != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "产品编号重复,请重新提交")
}
var material *domain.ProductMaterial
productMaterialRepository, _, _ := factory.FastProductMaterial(transactionContext, 0)
if material, err = productMaterialRepository.FindOne(map[string]interface{}{"companyId": product.CompanyId, "materialNumber": product.ProductCode}); err != nil || material == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "物料不存在")
}
var userService = domainService.NewUserService()
... ... @@ -281,8 +245,13 @@ func (productService *ProductService) UpdateProduct(updateProductCommand *comman
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
updateProductCommand.ProductName = material.MaterialName
updateProductCommand.Unit = material.ProductMaterialExt.Unit
updateProductCommand.ProductCategory = material.MaterialCategory.Category
data := tool_funs.SimpleStructToMap(updateProductCommand)
data["orgName"] = org.OrgName
if err := product.Update(data); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type MaterialGroupDto struct {
// 物料分组ID
... ... @@ -26,3 +29,30 @@ func (d *MaterialGroupDto) LoadDto(m *domain.ProductMaterialGroup, orgId int) *M
d.MaterialGroupNumber = m.MaterialGroupNumber
return d
}
func (productMaterialGroup *MaterialGroupDto) PID() string {
return fmt.Sprintf("%d", productMaterialGroup.Pid)
}
func (productMaterialGroup *MaterialGroupDto) ID() string {
return fmt.Sprintf("%d", productMaterialGroup.ProductMaterialGroupId)
}
type MaterialGroupDtos []*MaterialGroupDto
func (tree MaterialGroupDtos) Len() int {
return len(tree)
}
func (tree MaterialGroupDtos) Less(i, j int) bool {
if tree[i].Pid < tree[j].Pid {
return true
}
if tree[i].Pid == tree[j].Pid {
return tree[i].ProductMaterialGroupId < tree[j].ProductMaterialGroupId
}
return false
}
func (tree MaterialGroupDtos) Swap(i, j int) {
tree[i], tree[j] = tree[j], tree[i]
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SelectorProductMaterialGroupQuery struct {
// 查询偏离量
//Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
//Limit int `cname:"查询限制" json:"limit"`
// options 'tree' 'list' default tree
Style string `json:"style"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 页码
//PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
//PageSize int `cname:"页数" json:"pageSize,omitempty"`
}
func (cmd *SelectorProductMaterialGroupQuery) Valid(validation *validation.Validation) {
//cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
cmd.Style = "tree"
}
func (cmd *SelectorProductMaterialGroupQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).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
}
... ...
... ... @@ -12,6 +12,7 @@ import (
"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"
"sort"
)
// 物料分组服务
... ... @@ -38,6 +39,7 @@ func (productMaterialGroupService *ProductMaterialGroupService) CreateProductMat
MaterialGroupName: createProductMaterialGroupCommand.MaterialGroupName,
MaterialGroupNumber: createProductMaterialGroupCommand.MaterialGroupNumber,
}
var productMaterialGroup *domain.ProductMaterialGroup
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
if productMaterialGroup, err = materialService.AddMaterialGroup(operateInfo, newProductMaterialGroup); err != nil {
... ... @@ -185,7 +187,7 @@ func (productMaterialGroupService *ProductMaterialGroupService) UpdateProductMat
productMaterialGroup := &domain.ProductMaterialGroup{
ProductMaterialGroupId: cmd.ProductMaterialGroupId,
MaterialGroupName: cmd.MaterialGroupName,
MaterialGroupNumber: cmd.MaterialGroupNumber,
//MaterialGroupNumber: cmd.MaterialGroupNumber,
}
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
if productMaterialGroup, err := materialService.UpdateMaterialGroup(operateInfo, productMaterialGroup); err != nil {
... ... @@ -233,6 +235,48 @@ func (productMaterialGroupService *ProductMaterialGroupService) SearchProductMat
return count, results, nil
}
func (productMaterialGroupService *ProductMaterialGroupService) SelectorProductMaterialGroup(operateInfo *domain.OperateInfo, cmd *query.SelectorProductMaterialGroupQuery) (int64, interface{}, error) {
if err := cmd.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 productMaterialGroupRepository domain.ProductMaterialGroupRepository
productMaterialGroupRepository, _, _ = factory.FastProductMaterialGroup(transactionContext, 0)
queryOptions := utils.ObjectToMap(cmd)
count, productGroups, err := productMaterialGroupRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var results = make([]*dto.MaterialGroupDto, 0)
for i := range productGroups {
newItem := &dto.MaterialGroupDto{}
newItem.LoadDto(productGroups[i], operateInfo.OrgId)
results = append(results, newItem)
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if cmd.Style == "tree" {
sort.Stable(dto.MaterialGroupDtos(results))
nodes := make([]utils.TreeNode, 0)
for i := range results {
nodes = append(nodes, results[i])
}
tree := utils.NewTree(nodes)
return count, tree.Nodes, nil
}
return count, results, nil
}
func NewProductMaterialGroupService(options map[string]interface{}) *ProductMaterialGroupService {
newProductMaterialGroupService := &ProductMaterialGroupService{}
return newProductMaterialGroupService
... ...
... ... @@ -2,6 +2,7 @@ package domain
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"strconv"
"time"
)
... ... @@ -99,15 +100,18 @@ type ImportProductItem struct {
}
func (item *ImportProductItem) Valid() error {
if len(item.ProductName) == 0 {
return fmt.Errorf("品名不能为空")
}
if len(item.Unit) == 0 {
return fmt.Errorf("规格不能为空")
}
if len(item.ProductCategory) == 0 {
return fmt.Errorf("类别不能为空")
if len(item.ProductCode) == 0 {
return fmt.Errorf("产品编号不能为空")
}
//if len(item.ProductName) == 0 {
// return fmt.Errorf("品名不能为空")
//}
//if len(item.Unit) == 0 {
// return fmt.Errorf("规格不能为空")
//}
//if len(item.ProductCategory) == 0 {
// return fmt.Errorf("类别不能为空")
//}
if len(item.UnitWeight) == 0 {
item.UnitWeight = "0"
}
... ... @@ -116,3 +120,13 @@ func (item *ImportProductItem) Valid() error {
}
return nil
}
type Products []*Product
func (products Products) ProductCodes() []string {
var result = utils.NewSet()
for _, v := range products {
result.Add(v.ProductCode)
}
return result.KeysStr()
}
... ...
... ... @@ -59,3 +59,11 @@ func (productMaterials ProductMaterials) ToMapById() map[int]*ProductMaterial {
}
return mapProductMaterial
}
func (productMaterials ProductMaterials) ToMapByNumber() map[string]*ProductMaterial {
var mapProductMaterial = make(map[string]*ProductMaterial, 0)
for _, v := range productMaterials {
mapProductMaterial[v.MaterialNumber] = v
}
return mapProductMaterial
}
... ...
... ... @@ -2,6 +2,7 @@ package domain
import (
"fmt"
"strconv"
"time"
)
... ... @@ -49,6 +50,27 @@ func (productMaterialGroup *ProductMaterialGroup) Update(data map[string]interfa
return nil
}
func (productMaterialGroup *ProductMaterialGroup) GroupNumberComposeUp(parent *ProductMaterialGroup, latestNumber string, total int) string {
iNumber, err := strconv.ParseInt(latestNumber, 10, 64)
if err == nil {
iNumber += 1
return formatFunc(iNumber)
}
if parent != nil {
return parent.MaterialGroupNumber + formatFunc(int64(total+1))
}
return formatFunc(int64(total + 1))
}
func formatFunc(iNumber int64) string {
sNumber := fmt.Sprintf("%d", iNumber)
if len(sNumber)%2 == 1 {
return "0" + sNumber
}
return sNumber
}
/***** 1.实现树 *****/
func (productMaterialGroup *ProductMaterialGroup) PID() string {
... ...
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
)
type ProductMaterialGroupDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (dao *ProductMaterialGroupDao) CurrentGroupLatestNumber(companyId int, productMaterialGroupId int) (string, int, error) {
m := new(models.ProductMaterialGroup)
var result string
var total int
query := dao.transactionContext.PgTx.Model(m).Where("company_id = ?", companyId)
query.Where("pid = ?", productMaterialGroupId)
query.ColumnExpr("max(material_group_number) number")
query.ColumnExpr("count(material_group_number) total")
query.AllWithDeleted()
err := query.Select(&result, &total)
return result, total, err
}
func NewProductMaterialGroupDao(transactionContext *pgTransaction.TransactionContext) (*ProductMaterialGroupDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ProductMaterialGroupDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -6,8 +6,8 @@ import (
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"strconv"
"time"
... ... @@ -36,10 +36,22 @@ func (ptr *PGBatchAddProductService) BatchAddProduct(opt *domain.OperateInfo, li
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var generator = redis.NewProductCodeCache(opt.CompanyId)
var materials domain.ProductMaterials
if materials, err = ptr.GetProductMaterialByImportItems(opt.CompanyId, list); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
mapMaterials := materials.ToMapByNumber()
for i := range list {
item := list[i]
if v, ok := mapMaterials[item.ProductCode]; !ok {
item.FailReason = "导入的产品编号不存在"
failRows = append(failRows, item)
continue
} else {
item.Unit = v.ProductMaterialExt.Unit
item.ProductName = v.MaterialName
item.ProductCategory = v.MaterialCategory.Category
}
if err := item.Valid(); err != nil {
item.FailReason = err.Error()
failRows = append(failRows, item)
... ... @@ -69,14 +81,6 @@ func (ptr *PGBatchAddProductService) BatchAddProduct(opt *domain.OperateInfo, li
continue
}
}
if len(newItem.ProductCode) == 0 {
code, err := redis.GenCode(generator)
if err != nil {
log.Logger.Error(err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "服务器异常")
}
newItem.ProductCode = code
}
if _, ok := mapProduct[newItem.ProductCode]; !ok {
mapProduct[newItem.ProductCode] = newItem
... ... @@ -105,6 +109,28 @@ func (ptr *PGBatchAddProductService) updateProduct(opt *domain.OperateInfo, item
return nil
}
func (ptr *PGBatchAddProductService) GetProductMaterialByProductCodes(companyId int, productCodes []string) ([]*domain.ProductMaterial, error) {
productMaterialRepository, _ := repository.NewProductMaterialRepository(ptr.transactionContext)
_, productMaterials, err := productMaterialRepository.Find(map[string]interface{}{"companyId": companyId, "materialNumbers": productCodes})
return productMaterials, err
}
func (ptr *PGBatchAddProductService) GetProductMaterialByImportItems(companyId int, list []*domain.ImportProductItem) ([]*domain.ProductMaterial, error) {
productCodes := ptr.GetProductCodesByImportItems(list)
if len(productCodes) == 0 {
return []*domain.ProductMaterial{}, nil
}
return ptr.GetProductMaterialByProductCodes(companyId, productCodes)
}
func (ptr *PGBatchAddProductService) GetProductCodesByImportItems(list []*domain.ImportProductItem) []string {
var result = utils.NewSet()
for _, v := range list {
result.Add(v.ProductCode)
}
return result.KeysStr()
}
func NewPGBatchAddProductService(transactionContext *pgTransaction.TransactionContext) (*PGBatchAddProductService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -126,7 +126,7 @@ type HourProductiveStatisticsRequest struct {
CompanyId int `json:"companyId" valid:"Required"`
OrgId int `json:"orgId" valid:"Required"`
WorkshopId int `json:"workshopId" valid:"Required"`
Date time.Time `json:"date"`
Date utils.TimeString `json:"date"`
}
func NewXYData(xData []string, values interface{}) interface{} {
... ... @@ -154,8 +154,8 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map
Total float64 `json:"total"`
}
var date = time.Now()
if !xtime.IsZero(request.Date) {
date = request.Date
if !xtime.IsZero(time.Time(request.Date)) {
date = time.Time(request.Date)
}
workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId})
if err != nil || workshop == nil {
... ... @@ -213,8 +213,8 @@ func (ptr *PGCommonStatisticsService) ProportionOfSecondLevelStatistics(queryOpt
}
productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext)
var date = time.Now()
if !xtime.IsZero(request.Date) {
date = request.Date
if !xtime.IsZero(time.Time(request.Date)) {
date = time.Time(request.Date)
}
var input = []struct {
name string
... ... @@ -262,8 +262,8 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que
}
productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext)
var date = time.Now()
if !xtime.IsZero(request.Date) {
date = request.Date
if !xtime.IsZero(time.Time(request.Date)) {
date = time.Time(request.Date)
}
var input = []struct {
name string
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"sort"
... ... @@ -66,6 +67,10 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do
parent *domain.ProductMaterialGroup
newProductMaterialGroup *domain.ProductMaterialGroup
productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext)
productMaterialGroupDao *dao.ProductMaterialGroupDao
latestNumber string
total int
)
if user, err = NewUserService().User(opt.UserId); err != nil {
return nil, err
... ... @@ -81,6 +86,12 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do
if newProductMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || newProductMaterialGroup != nil {
return nil, fmt.Errorf("物料分组编码已存在")
}
productMaterialGroupDao, _ = dao.NewProductMaterialGroupDao(ptr.transactionContext)
latestNumber, total, err = productMaterialGroupDao.CurrentGroupLatestNumber(opt.CompanyId, item.Pid)
if err != nil {
return nil, err
}
newProductMaterialGroup = &domain.ProductMaterialGroup{
CompanyId: opt.CompanyId,
OrgId: opt.OrgId,
... ... @@ -92,6 +103,7 @@ func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *do
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName).WithOperator(user),
}
newProductMaterialGroup.MaterialGroupNumber = newProductMaterialGroup.GroupNumberComposeUp(parent, latestNumber, total)
newProductMaterialGroup, err = productMaterialGroupRepository.Save(newProductMaterialGroup)
return newProductMaterialGroup, err
}
... ... @@ -101,7 +113,7 @@ func (ptr *PGMaterialService) UpdateMaterialGroup(opt *domain.OperateInfo, item
user *domain.User
org *domain.Org
err error
parent *domain.ProductMaterialGroup
//parent *domain.ProductMaterialGroup
productMaterialGroup *domain.ProductMaterialGroup
productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext)
)
... ... @@ -111,24 +123,25 @@ func (ptr *PGMaterialService) UpdateMaterialGroup(opt *domain.OperateInfo, item
if org, err = NewUserService().Organization(opt.OrgId); err != nil {
return nil, err
}
if item.ProductMaterialGroupId == item.Pid {
return nil, fmt.Errorf("当前物料分组不能做为自己上级")
}
//if item.ProductMaterialGroupId == item.Pid {
// return nil, fmt.Errorf("当前物料分组不能做为自己上级")
//}
if productMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.ProductMaterialGroupId}); err != nil || productMaterialGroup == nil {
return nil, fmt.Errorf("物料分组不存在")
}
if item.Pid != productMaterialGroup.ProductMaterialGroupId && item.Pid != 0 {
if parent, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.Pid}); err != nil || parent == nil {
return nil, fmt.Errorf("上级物料分组不存在")
}
}
if productMaterialGroup.MaterialGroupNumber != item.MaterialGroupNumber {
if group, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || group != nil {
return nil, fmt.Errorf("物料分组编码已存在")
}
}
productMaterialGroup.MaterialGroupNumber = item.MaterialGroupNumber
//if item.Pid != productMaterialGroup.ProductMaterialGroupId && item.Pid != 0 {
// if parent, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.Pid}); err != nil || parent == nil {
// return nil, fmt.Errorf("上级物料分组不存在")
// }
//}
//if productMaterialGroup.MaterialGroupNumber != item.MaterialGroupNumber {
// if group, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || group != nil {
// return nil, fmt.Errorf("物料分组编码已存在")
// }
//}
//productMaterialGroup.MaterialGroupNumber = item.MaterialGroupNumber
productMaterialGroup.MaterialGroupName = item.MaterialGroupName
productMaterialGroup.UpdatedAt = item.UpdatedAt
productMaterialGroup.Ext = domain.NewExt(org.OrgName).WithOperator(user)
... ...
... ... @@ -166,6 +166,9 @@ func (repository *ProductMaterialRepository) Find(queryOptions map[string]interf
if v, ok := queryOptions["materialCategory"]; ok && v != "" {
query.Where(fmt.Sprintf(`material_category->>'category' like '%%%v%%'`, v))
}
if v, ok := queryOptions["materialNumbers"]; ok && len(v.([]string)) > 0 {
query.Where("material_number in (?)", pg.In(v))
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_material_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
package utils
import (
"github.com/linmadan/egglib-go/utils/xtime"
"strconv"
"time"
)
... ... @@ -103,3 +104,32 @@ func TimeBeforeEqual(t1, t2 time.Time) bool {
}
return false
}
type TimeString time.Time
func (timeString *TimeString) UnmarshalJSON(data []byte) error {
if len(data) == 2 {
return nil
}
t, err := xtime.Parse(string(data[1 : len(data)-1]))
if err != nil {
return err
}
*timeString = TimeString(t)
return nil
}
func (timeString TimeString) MarshalJSON() ([]byte, error) {
if xtime.IsZero(time.Time(timeString)) {
return []byte(`""`), nil
}
b := make([]byte, 0)
b = append(b, '"')
b = time.Time(timeString).AppendFormat(b, time.RFC3339)
b = append(b, '"')
return b, nil
}
func (timeString TimeString) Time() time.Time {
return time.Time(timeString)
}
... ...
... ... @@ -19,7 +19,7 @@ func (controller *ProductController) CreateProduct() {
op := ParseOperateInfo(controller.BaseController)
createProductCommand.CompanyId = op.CompanyId
createProductCommand.OrgId = op.OrgId
data, err := productService.CreateProduct(createProductCommand)
data, err := productService.CreateProduct(ParseOperateInfo(controller.BaseController), createProductCommand)
controller.Response(data, err)
}
... ... @@ -29,7 +29,7 @@ func (controller *ProductController) UpdateProduct() {
Must(controller.Unmarshal(updateProductCommand))
productId, _ := controller.GetInt(":productId")
updateProductCommand.ProductId = productId
data, err := productService.UpdateProduct(updateProductCommand)
data, err := productService.UpdateProduct(ParseOperateInfo(controller.BaseController), updateProductCommand)
controller.Response(data, err)
}
... ...
... ... @@ -78,14 +78,10 @@ func (controller *ProductMaterialGroupController) SearchProductMaterialGroup() {
func (controller *ProductMaterialGroupController) SelectorProductMaterialGroup() {
productMaterialGroupService := service.NewProductMaterialGroupService(nil)
cmd := &query.SearchProductMaterialGroupQuery{}
offset, _ := controller.GetInt("offset")
cmd.Offset = offset
limit, _ := controller.GetInt("limit")
cmd.Limit = limit
cmd := &query.SelectorProductMaterialGroupQuery{}
operateInfo := ParseOperateInfo(controller.BaseController)
cmd.CompanyId = operateInfo.CompanyId
count, data, err := productMaterialGroupService.SearchProductMaterialGroup(ParseOperateInfo(controller.BaseController), cmd)
count, data, err := productMaterialGroupService.SelectorProductMaterialGroup(ParseOperateInfo(controller.BaseController), cmd)
controller.Response(map[string]interface{}{
"groups": data,
"count": count,
... ...