作者 tangxuhui

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-manufacture into dev
... ... @@ -11,7 +11,7 @@ require (
github.com/go-pg/pg/v10 v10.9.0
github.com/go-redis/redis v6.15.7+incompatible
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.0
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7
github.com/moul/http2curl v1.0.0 // indirect
... ... @@ -20,7 +20,7 @@ require (
github.com/sergi/go-diff v1.2.0 // indirect
github.com/smartystreets/goconvey v1.7.2 // indirect
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.13.0 // indirect
github.com/tidwall/gjson v1.13.0
github.com/valyala/fasthttp v1.32.0 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
... ...
... ... @@ -160,7 +160,6 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/gops v0.3.7/go.mod h1:bj0cwMmX1X4XIJFTjR99R5sCxNssNJ8HebFNvoQlmgY=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
... ...
... ... @@ -28,11 +28,14 @@ type CreateDeviceCommand struct {
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 品牌
Brand string `cname:"品牌" json:"brand" valid:"Required"`
Brand string `cname:"品牌" json:"brand"`
// 设备状态 1:正常 2:封存 3:报废
DeviceStatus int `cname:"设备状态 1:正常 2:封存 3:报废" json:"deviceStatus" valid:"Required"`
// 风险等级 1:高 2:中 3:低
RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
// 标准工时 生产单个产品的时间(单位:秒)
UnitProductionSecTime int `cname:"标准工时" json:"unitProductionSecTime"`
}
func (createDeviceCommand *CreateDeviceCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -31,6 +31,8 @@ type UpdateDeviceCommand struct {
DeviceStatus int `cname:"设备状态 1:正常 2:封存 3:报废" json:"deviceStatus" valid:"Required"`
// 风险等级 1:高 2:中 3:低
RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
// 标准工时
UnitProductionSecTime int `cname:"标准工时" json:"unitProductionSecTime"`
}
func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -23,6 +23,8 @@ type DeviceDto struct {
RiskLevel int `json:"riskLevel,omitempty"`
// 所属位置
*domain.WorkStation
// 生产单个产品的时间(单位:秒)
UnitProductionSecTime int `json:"unitProductionSecTime"`
// 组织名称
OrgName string `json:"orgName"`
... ... @@ -43,5 +45,8 @@ func (d *DeviceDto) LoadDto(m *domain.Device, orgId int) *DeviceDto {
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
}
if m.Ext != nil && m.Ext.DeviceExt != nil {
d.UnitProductionSecTime = m.Ext.DeviceExt.UnitProductionSecTime
}
return d
}
... ...
... ... @@ -63,7 +63,7 @@ func (deviceService *DeviceService) CreateDevice(operateInfo *domain.OperateInfo
RiskLevel: cmd.RiskLevel,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName),
Ext: domain.NewExt(org.OrgName).WithDeviceExt(&domain.DeviceExt{UnitProductionSecTime: cmd.UnitProductionSecTime}),
}
deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
... ... @@ -334,18 +334,20 @@ func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
var result = make([]*dto.DeviceDto, 0)
for i := range devices {
item := devices[i]
newJobDto := &dto.DeviceDto{}
item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
newJobDto.LoadDto(item, operateInfo.OrgId)
result = append(result, newJobDto)
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return count, result, nil
}
... ...
... ... @@ -119,12 +119,17 @@ func (productGroupService *ProductGroupService) GetProductGroup(getProductGroupQ
}
if productGroup == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductGroupQuery.ProductGroupId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productGroup, nil
}
_, workshop, err := factory.FastPgWorkshop(transactionContext, productGroup.WorkStation.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productGroup.WorkStation, _ = workshop.FindWorkStation(productGroup.WorkStation.WorkshopId, productGroup.WorkStation.LineId, productGroup.WorkStation.SectionId)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productGroup, nil
}
// 返回生产班组服务列表
... ... @@ -323,8 +328,8 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(cmd *command.
}
// 返回生产班组服务列表
func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *domain.OperateInfo, q *query.SearchProductGroupQuery) (int64, interface{}, error) {
if err := q.ValidateQuery(); err != nil {
func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *domain.OperateInfo, cmd *query.SearchProductGroupQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -337,16 +342,24 @@ func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *
defer func() {
transactionContext.RollbackTransaction()
}()
workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
queryOptions := utils.ObjectToMap(cmd)
queryOptions = workshops.FindByNameWithQuery(queryOptions, cmd.WorkshopName, cmd.LineName, "")
var productGroupRepository domain.ProductGroupRepository
productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
count, productGroups, err := productGroupRepository.Find(utils.ObjectToMap(q))
count, productGroups, err := productGroupRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var results = make([]*dto.ProductGroupDto, 0)
for i := range productGroups {
item := productGroups[i]
newItem := &dto.ProductGroupDto{}
results = append(results, newItem.LoadDto(productGroups[i], operateInfo.OrgId))
newItem.LoadDto(productGroups[i], operateInfo.OrgId)
item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
results = append(results, newItem)
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -6,6 +6,8 @@ import (
)
type ProductPlanDto struct {
// 生产计划ID
ProductPlanId int `json:"productPlanId,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 生产日期
... ... @@ -41,6 +43,7 @@ type ProductPlanDto struct {
}
func (d *ProductPlanDto) LoadDto(m *domain.ProductPlan, orgId int) *ProductPlanDto {
d.ProductPlanId = m.ProductPlanId
d.BatchNumber = m.BatchNumber
d.ProductDate = m.ProductDate.Format("2006/01/02")
d.WorkshopId = m.Workshop.WorkshopId
... ...
... ... @@ -305,7 +305,7 @@ func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductR
}
// 换单
func (productPlanService *ProductPlanService) Switch(switchCommand *command.SwitchCommand) (interface{}, error) {
func (productPlanService *ProductPlanService) Exchange(switchCommand *command.SwitchCommand) (interface{}, error) {
if err := switchCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ...
... ... @@ -103,10 +103,16 @@ func (device *Device) Update(data map[string]interface{}) error {
}
if device.Ext == nil {
device.Ext = &Ext{}
if device.Ext.DeviceExt == nil {
device.Ext.DeviceExt = &DeviceExt{}
}
}
if orgName, ok := data["orgName"]; ok {
device.Ext.OrgName = orgName.(string)
}
if unitProductionSecTime, ok := data["unitProductionSecTime"]; ok {
device.Ext.DeviceExt.UnitProductionSecTime = unitProductionSecTime.(int)
}
device.UpdatedAt = time.Now()
return nil
}
... ...
package domain
// DeviceExt 设备扩展
type DeviceExt struct {
// 生产单个产品的时间(单位:秒)
UnitProductionSecTime int `json:"unitProductionSecTime"`
}
... ...
... ... @@ -4,6 +4,9 @@ package domain
type Ext struct {
// 组织名称
OrgName string `json:"orgName,omitempty"`
// 设备扩展数据
DeviceExt *DeviceExt `json:"deviceExt"`
}
func NewExt(orgName string) *Ext {
... ... @@ -11,3 +14,8 @@ func NewExt(orgName string) *Ext {
OrgName: orgName,
}
}
func (e *Ext) WithDeviceExt(deviceExt *DeviceExt) *Ext {
e.DeviceExt = deviceExt
return e
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -153,6 +154,18 @@ func (repository *ProductGroupRepository) Find(queryOptions map[string]interface
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
if v, ok := queryOptions["inWorkshopIds"]; ok && len(v.([]int)) > 0 {
query.Where(`work_station->>'workshopId' in (?)`, pg.In(utils.ToArrayString(v.([]int))))
}
if v, ok := queryOptions["inLineIds"]; ok && len(v.([]int)) > 0 {
query.Where(`work_station->>'lineId' in (?)`, pg.In(utils.ToArrayString(v.([]int))))
}
if v, ok := queryOptions["inSectionIds"]; ok && len(v.([]int)) > 0 {
query.Where(`work_station->>'sectionId' in (?)`, pg.In(utils.ToArrayString(v.([]int))))
}
if v, ok := queryOptions["groupName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`group_name like '%%%v%%'`, v))
}
query.SetOffsetAndLimit(20)
query.SetOrderDirect("product_group_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
... ... @@ -90,7 +90,7 @@ func (controller *ProductPlanController) Switch() {
productPlanService := service.NewProductPlanService(nil)
switchCommand := &command.SwitchCommand{}
Must(controller.Unmarshal(switchCommand))
data, err := productPlanService.Switch(switchCommand)
data, err := productPlanService.Exchange(switchCommand)
controller.Response(data, err)
}
... ...