作者 yangfu

1.增加日子记录

2.工作位置实时查询
正在显示 35 个修改的文件 包含 618 行增加97 行删除
FROM 192.168.0.243:5000/mmm/allied-creation-manufacture:20210809
FROM 192.168.0.243:5000/mmm/allied-creation-user:20210809
ENV APP_DIR $GOPATH/src/project-20211220
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR/
... ...
... ... @@ -52,12 +52,54 @@ spec:
- mountPath: /opt/logs
name: accesslogs
env:
- name: POSTGRESQL_DB_NAME
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresqlalliedcreation.dbname
- name: POSTGRESQL_USER
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.user
- name: POSTGRESQL_PASSWORD
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.password
- name: POSTGRESQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.host
- name: POSTGRESQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.port
- name: REDIS_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.ip
- name: REDIS_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.port
- name: REDIS_AUTH
value: ""
- name: LOG_LEVEL
value: "debug"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
volumes:
value: "2000"
- name: ENABLE_KAFKA_LOG
value: "true"
- name: HTTP_PORT
value: "8082"
- name: SERVICE_ENV
value: "dev"
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
... ... @@ -34,6 +34,31 @@ func FastPgWorkshop(transactionContext application.TransactionContext, id int, o
return rep, mod, err
}
// FastPgWorkshop 快速返回车间对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgWorkshops(transactionContext application.TransactionContext, companyId int, options ...option) (domain.Workshops, error) {
var rep domain.WorkshopRepository
//var mod *domain.Workshop
var err error
if value, err := CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
_, workshops, err := rep.Find(map[string]interface{}{"companyId": companyId})
if err != nil {
return nil, err
}
if len(workshops) == 0 {
workshops = make([]*domain.Workshop, 0)
}
return workshops, err
}
// FastPgWorkstation 快速返回工作定位对象
//
// transactionContext 事务
... ...
... ... @@ -91,11 +91,19 @@ func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *qu
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
_, workshop, err := factory.FastPgWorkshop(transactionContext, productJob.WorkStation.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productJob.WorkStation, _ = workshop.FindWorkStation(productJob.WorkStation.WorkshopId, productJob.WorkStation.LineId, productJob.WorkStation.SectionId)
newJobDto := &dto.ProductJobDto{}
newJobDto.LoadDto(productJob, 0)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return newJobDto, nil
}
... ... @@ -279,8 +287,8 @@ func (productJobService *ProductJobService) UpdateProductJob(cmd *command.Update
}
// 搜索工位服务列表
func (productJobService *ProductJobService) SearchProductJob(operateInfo *domain.OperateInfo, listProductJobQuery *query.SearchProductJobQuery) (int64, interface{}, error) {
if err := listProductJobQuery.ValidateQuery(); err != nil {
func (productJobService *ProductJobService) SearchProductJob(operateInfo *domain.OperateInfo, cmd *query.SearchProductJobQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -301,14 +309,18 @@ func (productJobService *ProductJobService) SearchProductJob(operateInfo *domain
} else {
productJobRepository = value
}
count, productJobs, err := productJobRepository.Find(utils.ObjectToMap(listProductJobQuery))
workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
queryOptions := utils.ObjectToMap(cmd)
queryOptions = workshops.FindByNameWithQuery(queryOptions, cmd.WorkshopName, cmd.LineName, cmd.SectionName)
count, productJobs, err := productJobRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var result = make([]*dto.ProductJobDto, 0)
for i := range productJobs {
item := productJobs[i]
item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
newJobDto := &dto.ProductJobDto{}
newJobDto.LoadDto(item, operateInfo.OrgId)
result = append(result, newJobDto)
... ...
... ... @@ -13,6 +13,8 @@ type UpdateProductLineCommand struct {
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 旧生产线ID
//OldWorkshopId int `cname:"生产线ID" json:"-" valid:"Required"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName" valid:"Required"`
}
... ...
... ... @@ -57,7 +57,7 @@ func (productLineService *ProductLineService) CreateProductLine(createProductLin
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return newProductLine, nil
return createProductLineCommand, nil
}
// 返回生产线
... ...
... ... @@ -2,11 +2,11 @@ package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CreateProductPlanCommand struct {
... ... @@ -19,7 +19,7 @@ type CreateProductPlanCommand struct {
// 批号
BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
// 生产日期
ProductDate time.Time `cname:"生产日期" json:"productDate" valid:"Required"`
ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
// 机台 (A、B、C、D 区分机器大小)
... ... @@ -31,15 +31,28 @@ type CreateProductPlanCommand struct {
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
//nitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
// 备注
Remark string `cname:"备注" json:"remark" valid:"Required"`
Remark string `cname:"备注" json:"remark"`
// 生产日期
ProductDateTime time.Time `cname:"生产日期" json:"-" `
}
func (createProductPlanCommand *CreateProductPlanCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
if err := domain.ValidWorkOn(createProductPlanCommand.WorkOn); err != nil {
validation.Error(err.Error())
return
}
if t, err := time.Parse("2006/01/02", createProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误 2006/01/02")
return
} else {
createProductPlanCommand.ProductDateTime = t
}
}
func (createProductPlanCommand *CreateProductPlanCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type ReceiveMaterialCommand struct {
}
func (receiveMaterialCommand *ReceiveMaterialCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (receiveMaterialCommand *ReceiveMaterialCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type RemoveProductPlanCommand struct {
}
func (removeProductPlanCommand *RemoveProductPlanCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductPlanCommand *RemoveProductPlanCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type ReturnMaterialCommand struct {
}
func (returnMaterialCommand *ReturnMaterialCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (returnMaterialCommand *ReturnMaterialCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type SetOfflineCommand struct {
}
func (setOfflineCommand *SetOfflineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (setOfflineCommand *SetOfflineCommand) ValidateCommand() error {
... ...
... ... @@ -20,7 +20,7 @@ type SetOnlineCommand struct {
}
func (setOnlineCommand *SetOnlineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (setOnlineCommand *SetOnlineCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type SubmitProductRecordCommand struct {
}
func (submitProductRecordCommand *SubmitProductRecordCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (submitProductRecordCommand *SubmitProductRecordCommand) ValidateCommand() error {
... ...
... ... @@ -16,7 +16,7 @@ type SwitchCommand struct {
}
func (switchCommand *SwitchCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (switchCommand *SwitchCommand) ValidateCommand() error {
... ...
... ... @@ -2,11 +2,11 @@ package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type UpdateProductPlanCommand struct {
... ... @@ -21,7 +21,7 @@ type UpdateProductPlanCommand struct {
// 批号
BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
// 生产日期
ProductDate time.Time `cname:"生产日期" json:"productDate" valid:"Required"`
ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
// 机台 (A、B、C、D 区分机器大小)
... ... @@ -33,15 +33,26 @@ type UpdateProductPlanCommand struct {
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
//UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
// 备注
Remark string `cname:"备注" json:"remark" valid:"Required"`
// 生产日期
ProductDateTime time.Time `cname:"生产日期" json:"-" `
}
func (updateProductPlanCommand *UpdateProductPlanCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
if err := domain.ValidWorkOn(updateProductPlanCommand.WorkOn); err != nil {
validation.Error(err.Error())
return
}
if t, err := time.Parse("2006/01/02", updateProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误 2006/01/02")
return
} else {
updateProductPlanCommand.ProductDateTime = t
}
}
func (updateProductPlanCommand *UpdateProductPlanCommand) ValidateCommand() error {
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"strings"
)
type ProductPlanDto struct {
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 生产日期
ProductDate string `json:"productDate,omitempty"`
// 车间
//*domain.Workshop
// 车间ID
WorkshopId int `json:"workshopId,omitempty"`
// 车间名称
WorkshopName string `json:"workshopName,omitempty"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn,omitempty"`
// 上班班次描述
WorkOnDescription string `json:"workOnDescription"`
// 机台 (A、B、C、D 区分机器大小)
Machine string `json:"machine,omitempty"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 计划投入
*domain.UnitQuantity
// 计划状态 (1:上线 2:下线 默认下线)
PlanStatus int `json:"planStatus,omitempty"`
// 工作位置
//WorkStation *WorkStation `json:"workStation,omitempty"`
// 总产能
TotalProduct float64 `json:"totalProduct"`
// 备注
Remark string `json:"remark,omitempty"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
func (d *ProductPlanDto) LoadDto(m *domain.ProductPlan, orgId int) *ProductPlanDto {
d.BatchNumber = m.BatchNumber
d.ProductDate = m.ProductDate.Format("2006/01/02")
d.WorkshopId = m.Workshop.WorkshopId
d.WorkshopName = m.Workshop.WorkshopName
d.WorkOn = m.WorkOn
d.PlanProductName = m.PlanProductName
d.UnitQuantity = m.PlanDevoted
d.PlanStatus = m.PlanStatus
d.TotalProduct = 0
d.Remark = m.Remark
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
}
workOnDesc := domain.WorkOnDescription(m.WorkOn)
d.WorkOnDescription = strings.Join(workOnDesc, ",")
return d
}
... ...
... ... @@ -14,7 +14,7 @@ type GetProductPlanQuery struct {
}
func (getProductPlanQuery *GetProductPlanQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductPlanQuery *GetProductPlanQuery) ValidateQuery() error {
... ...
... ... @@ -16,7 +16,7 @@ type ListProductPlanQuery struct {
}
func (listProductPlanQuery *ListProductPlanQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductPlanQuery *ListProductPlanQuery) ValidateQuery() error {
... ...
package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchProductPlanQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"`
// 匹配多个组织
InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty" valid:"Required"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 批号
BatchNumber string `cname:"批号" json:"batchNumber"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName"`
}
func (cmd *SearchProductPlanQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
}
func (cmd *SearchProductPlanQuery) 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
}
... ...
... ... @@ -6,8 +6,12 @@ import (
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
// 生产计划服务
... ... @@ -15,8 +19,8 @@ type ProductPlanService struct {
}
// 创建生产计划服务
func (productPlanService *ProductPlanService) CreateProductPlan(createProductPlanCommand *command.CreateProductPlanCommand) (interface{}, error) {
if err := createProductPlanCommand.ValidateCommand(); err != nil {
func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.CreateProductPlanCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -29,34 +33,55 @@ func (productPlanService *ProductPlanService) CreateProductPlan(createProductPla
defer func() {
transactionContext.RollbackTransaction()
}()
newProductPlan := &domain.ProductPlan{
CompanyId: createProductPlanCommand.CompanyId,
OrgId: createProductPlanCommand.OrgId,
//WorkshopId: createProductPlanCommand.WorkshopId,
BatchNumber: createProductPlanCommand.BatchNumber,
ProductDate: createProductPlanCommand.ProductDate,
WorkOn: createProductPlanCommand.WorkOn,
Machine: createProductPlanCommand.Machine,
PlanProductName: createProductPlanCommand.PlanProductName,
//PlanDevoted: createProductPlanCommand.PlanDevoted,
Remark: createProductPlanCommand.Remark,
}
var productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
var productPlan *domain.ProductPlan
productPlanRepository, _, _ = factory.FastPgProductPlan(transactionContext, 0)
// 检查批次号是否有重复的
if item, err := productPlanRepository.FindOne(map[string]interface{}{"companyId": cmd.CompanyId, "orgId": cmd.OrgId, "batchNumber": cmd.BatchNumber}); err == nil && item != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "批次号重复")
}
_, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
if productPlan, err := productPlanRepository.Save(newProductPlan); err != nil {
var userService = domainService.NewUserService()
var org *domain.Org
org, err = userService.Organization(cmd.OrgId)
if 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 productPlan, nil
}
newProductPlan := &domain.ProductPlan{
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
BatchNumber: cmd.BatchNumber,
ProductDate: cmd.ProductDateTime,
Workshop: workshop.CloneSample(),
WorkOn: cmd.WorkOn,
Machine: cmd.Machine,
PlanProductName: cmd.PlanProductName,
PlanDevoted: &domain.UnitQuantity{
Unit: cmd.Unit,
Quantity: cmd.Quantity,
Weight: cmd.Weight,
},
PlanStatus: domain.PlanOffline,
WorkStation: &domain.WorkStation{},
Remark: cmd.Remark,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName),
}
if productPlan, err = productPlanRepository.Save(newProductPlan); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productPlan, nil
}
// 返回生产计划服务
... ... @@ -92,7 +117,9 @@ func (productPlanService *ProductPlanService) GetProductPlan(getProductPlanQuery
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productPlan, nil
result := &dto.ProductPlanDto{}
result.LoadDto(productPlan, 0)
return result, nil
}
}
... ... @@ -341,6 +368,46 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPla
}
}
// 搜索生产计划服务列表
func (productPlanService *ProductPlanService) SearchProductPlan(operateInfo *domain.OperateInfo, cmd *query.SearchProductPlanQuery) (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 productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
count, productPlans, err := productPlanRepository.Find(utils.ObjectToMap(cmd))
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())
}
var result = make([]*dto.ProductPlanDto, 0)
for i := range productPlans {
item := productPlans[i]
newItem := &dto.ProductPlanDto{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
}
return count, result, nil
}
func NewProductPlanService(options map[string]interface{}) *ProductPlanService {
newProductPlanService := &ProductPlanService{}
return newProductPlanService
... ...
... ... @@ -103,3 +103,20 @@ func ValidWorkOn(workOn int) error {
}
return nil
}
func WorkOnDescription(workOn int) []string {
result := make([]string, 0)
if workOn&WorkOnFullDay > 0 {
result = append(result, "全天")
}
if workOn&WorkOnDay > 0 {
result = append(result, "白班")
}
if workOn&WorkOnMidDay > 0 {
result = append(result, "中班")
}
if workOn&WorkOnNight > 0 {
result = append(result, "夜班")
}
return result
}
... ...
... ... @@ -2,6 +2,11 @@ package domain
import "time"
const (
PlanOnline = 1 // 计划上线
PlanOffline = 2 // 计划下线
)
// 生产计划
type ProductPlan struct {
// 生产计划ID
... ...
... ... @@ -31,5 +31,6 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation
LineName: l.LineName,
SectionId: s.SectionId,
SectionName: s.SectionName,
Principal: w.Principal,
}
}
... ...
... ... @@ -85,10 +85,10 @@ func (workshop *Workshop) RemoveLine(lineId int) (*ProductLine, error) {
if err != nil {
return nil, err
}
if line.Removed == 1 {
if line.Removed == Deleted {
return nil, fmt.Errorf("生产线:%v已删除", line.LineName)
}
line.Removed = 1
line.Removed = Deleted
return line, nil
}
... ... @@ -98,7 +98,7 @@ func (workshop *Workshop) UpdateLine(lineId int, lineName string) error {
if err != nil {
return err
}
if line.Removed == 1 {
if line.Removed == Deleted {
return fmt.Errorf("生产线:%v已删除", line.LineName)
}
line.LineName = lineName
... ... @@ -133,7 +133,7 @@ func (workshop *Workshop) AddSection(lineId int, section *ProductSection) error
if err != nil {
return err
}
if line.Removed == 1 {
if line.Removed == Deleted {
return fmt.Errorf("生产线:%v已删除", line.LineName)
}
for i := range line.ProductSections {
... ... @@ -155,10 +155,10 @@ func (workshop *Workshop) RemoveSection(lineId, sectionId int) error {
if err != nil {
return err
}
if section.Removed == 1 {
if section.Removed == Deleted {
return fmt.Errorf("工段:%v已删除", section.SectionName)
}
section.Removed = 1
section.Removed = Deleted
return nil
}
... ... @@ -168,7 +168,7 @@ func (workshop *Workshop) UpdateSection(lineId, sectionId int, sectionName strin
if err != nil {
return err
}
if section.Removed == 1 {
if section.Removed == Deleted {
return fmt.Errorf("工段:%v已删除", section.SectionName)
}
section.SectionName = sectionName
... ... @@ -219,3 +219,10 @@ func (workshop *Workshop) GetProductLines(removed int) []*ProductLine {
}
return result
}
func (workshop *Workshop) CloneSample() *Workshop {
return &Workshop{
WorkshopId: workshop.WorkshopId,
WorkshopName: workshop.WorkshopName,
}
}
... ...
package domain
import "strings"
/*车间列表*/
type Workshops []*Workshop
func (m Workshops) FindWorkStation(workshopId, lineId, sectionId int) *WorkStation {
for i := range m {
item := m[i]
workstation, err := item.FindWorkStation(workshopId, lineId, sectionId)
if err == nil && workstation != nil {
return workstation
}
}
return &WorkStation{} //返回空的对象
}
func (m Workshops) FindWorkshopsByName(workshopName string) []int {
result := make([]int, 0)
if len(workshopName) == 0 {
return result
}
for i := range m {
item := m[i]
if strings.Contains(item.WorkshopName, workshopName) {
result = append(result, item.WorkshopId)
}
}
return result
}
func (m Workshops) FindProductLinesByName(lineName string) []int {
result := make([]int, 0)
if len(lineName) == 0 {
return result
}
for i := range m {
item := m[i]
for j := range item.ProductLines {
line := item.ProductLines[j]
if line.Removed == Deleted {
continue
}
if strings.Contains(line.LineName, lineName) {
result = append(result, line.LineId)
}
}
}
return result
}
func (m Workshops) FindProductSectionsByName(sectionName string) []int {
result := make([]int, 0)
if len(sectionName) == 0 {
return result
}
for i := range m {
item := m[i]
for j := range item.ProductLines {
line := item.ProductLines[j]
if line.Removed == Deleted {
continue
}
for z := range line.ProductSections {
section := line.ProductSections[z]
if section.Removed == Deleted {
continue
}
if strings.Contains(section.SectionName, sectionName) {
result = append(result, section.SectionId)
}
}
}
}
return result
}
func (m Workshops) FindByName(workshopName, lineName, sectionName string) (workshops []int, lines []int, sections []int) {
workshops = m.FindWorkshopsByName(workshopName)
lines = m.FindProductLinesByName(lineName)
sections = m.FindProductSectionsByName(sectionName)
return
}
func (m Workshops) FindByNameWithQuery(query map[string]interface{}, workshopName, lineName, sectionName string) map[string]interface{} {
var workshops, lines, sections []int
workshops = m.FindWorkshopsByName(workshopName)
lines = m.FindProductLinesByName(lineName)
sections = m.FindProductSectionsByName(sectionName)
defaultValue := []int{0}
if len(workshops) > 0 {
query["inWorkshopIds"] = workshops
} else {
if len(workshopName) > 0 {
query["inWorkshopIds"] = defaultValue
}
}
if len(lines) > 0 {
query["inLineIds"] = lines
} else {
if len(lineName) > 0 {
query["inLineIds"] = defaultValue
}
}
if len(sections) > 0 {
query["inSectionIds"] = sections
} else {
if len(sectionName) > 0 {
query["inSectionIds"] = defaultValue
}
}
return query
}
... ...
package domainService
//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/repository"
//)
//
//type PGWorkshopService struct {
// transactionContext *pgTransaction.TransactionContext
//}
//
//func(ptr *PGWorkshopService)CompanyWorkshops(companyId int)(domain.Workshops,error){
// workshopRepository,_:= repository.NewWorkshopRepository(ptr.transactionContext)
// _,workshops,err:= workshopRepository.Find(map[string]interface{}{"companyId":companyId})
// if err!=nil{
// return nil,err
// }
// if len(workshops)==0{
// workshops = make([]*domain.Workshop,0)
// }
// return workshops,nil
//}
//
//func NewPGWorkshopService(transactionContext *pgTransaction.TransactionContext) (*PGWorkshopService, error) {
// if transactionContext == nil {
// return nil, fmt.Errorf("transactionContext参数不能为nil")
// } else {
// return &PGWorkshopService{
// transactionContext: transactionContext,
// }, nil
// }
//}
... ...
... ... @@ -6,7 +6,7 @@ import (
)
type ProductPlan struct {
tableName string `comment:"生产计划" pg:"product_plans,alias:manufacture.product_plan"`
tableName string `comment:"生产计划" pg:"manufacture.product_plan"`
// 生产计划ID
ProductPlanId int `comment:"生产计划ID" pg:"pk:product_plan_id"`
// 企业id
... ...
... ... @@ -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"
... ... @@ -154,18 +155,28 @@ func (repository *ProductJobRepository) Find(queryOptions map[string]interface{}
query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId")
query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId")
query.SetWhereByQueryOption("work_station->>'sectionId'='?'", "sectionId")
if v, ok := queryOptions["jobName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`job_name like '%%%v%%'`, 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["workshopName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v))
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["lineName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`work_station->>'lineName' like '%%%v%%'`, v))
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["sectionName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v))
if v, ok := queryOptions["jobName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`job_name like '%%%v%%'`, v))
}
//if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
// query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v))
//}
//if v, ok := queryOptions["lineName"]; ok && len(v.(string)) > 0 {
// query.Where(fmt.Sprintf(`work_station->>'lineName' like '%%%v%%'`, v))
//}
//if v, ok := queryOptions["sectionName"]; ok && len(v.(string)) > 0 {
// query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v))
//}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_job_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
... ... @@ -44,19 +44,13 @@ func (repository *ProductPlanRepository) Save(productPlan *domain.ProductPlan) (
"deleted_at",
"ext",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_plan_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_plan_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "productPlan_id")
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_plan_id", "deleted_at")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if productPlan.Identify() == nil {
productPlanId, err := repository.nextIdentify()
if err != nil {
return productPlan, err
} else {
productPlan.ProductPlanId = int(productPlanId)
}
if _, err := tx.QueryOne(
pg.Scan(
&productPlan.ProductPlanId,
... ... @@ -77,8 +71,7 @@ func (repository *ProductPlanRepository) Save(productPlan *domain.ProductPlan) (
&productPlan.DeletedAt,
&productPlan.Ext,
),
fmt.Sprintf("INSERT INTO product_plans (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
productPlan.ProductPlanId,
fmt.Sprintf("INSERT INTO manufacture.product_plan (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
productPlan.CompanyId,
productPlan.OrgId,
productPlan.BatchNumber,
... ... @@ -93,7 +86,6 @@ func (repository *ProductPlanRepository) Save(productPlan *domain.ProductPlan) (
productPlan.Remark,
productPlan.CreatedAt,
productPlan.UpdatedAt,
productPlan.DeletedAt,
productPlan.Ext,
); err != nil {
return productPlan, err
... ... @@ -119,8 +111,7 @@ func (repository *ProductPlanRepository) Save(productPlan *domain.ProductPlan) (
&productPlan.DeletedAt,
&productPlan.Ext,
),
fmt.Sprintf("UPDATE product_plans SET %s WHERE product_plan_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
productPlan.ProductPlanId,
fmt.Sprintf("UPDATE manufacture.product_plan SET %s WHERE product_plan_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
productPlan.CompanyId,
productPlan.OrgId,
productPlan.BatchNumber,
... ... @@ -135,7 +126,6 @@ func (repository *ProductPlanRepository) Save(productPlan *domain.ProductPlan) (
productPlan.Remark,
productPlan.CreatedAt,
productPlan.UpdatedAt,
productPlan.DeletedAt,
productPlan.Ext,
productPlan.Identify(),
); err != nil {
... ... @@ -157,7 +147,10 @@ func (repository *ProductPlanRepository) FindOne(queryOptions map[string]interfa
tx := repository.transactionContext.PgTx
productPlanModel := new(models.ProductPlan)
query := sqlbuilder.BuildQuery(tx.Model(productPlanModel), queryOptions)
query.SetWhereByQueryOption("product_plan.product_plan_id = ?", "productPlanId")
query.SetWhereByQueryOption("product_plan_id = ?", "productPlanId")
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("batch_number=?", "batchNumber")
if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) {
query.AllWithDeleted()
}
... ...
... ... @@ -48,6 +48,15 @@ func ObjectToMap(o interface{}) map[string]interface{} {
return m
}
func DeleteMapKeys(options map[string]interface{}, keys ...string) map[string]interface{} {
for i := range keys {
if _, ok := options[keys[i]]; ok {
delete(options, keys[i])
}
}
return options
}
// AssertString convert v to string value
func AssertString(v interface{}) string {
if v == nil {
... ... @@ -315,3 +324,11 @@ func ComputeTimeDuration(t1, t2 string) (result time.Duration, err error) {
ts := t2t.Sub(t1t)
return ts, nil
}
func ToArrayString(inputs []int) []string {
result := make([]string, 0)
for i := range inputs {
result = append(result, strconv.Itoa(inputs[i]))
}
return result
}
... ...
... ... @@ -24,7 +24,9 @@ func (controller *ProductLineController) UpdateProductLine() {
updateProductLineCommand := &command.UpdateProductLineCommand{}
Must(controller.Unmarshal(updateProductLineCommand))
lineId, _ := controller.GetInt(":lineId")
workshopId, _ := controller.GetInt("workshopId")
updateProductLineCommand.LineId = lineId
updateProductLineCommand.WorkshopId = workshopId
data, err := productLineService.UpdateProductLine(updateProductLineCommand)
controller.Response(data, err)
}
... ...
... ... @@ -13,16 +13,19 @@ type ProductPlanController struct {
func (controller *ProductPlanController) CreateProductPlan() {
productPlanService := service.NewProductPlanService(nil)
createProductPlanCommand := &command.CreateProductPlanCommand{}
controller.Unmarshal(createProductPlanCommand)
data, err := productPlanService.CreateProductPlan(createProductPlanCommand)
cmd := &command.CreateProductPlanCommand{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
cmd.CompanyId = operateInfo.CompanyId
cmd.OrgId = operateInfo.OrgId
data, err := productPlanService.CreateProductPlan(cmd)
controller.Response(data, err)
}
func (controller *ProductPlanController) UpdateProductPlan() {
productPlanService := service.NewProductPlanService(nil)
updateProductPlanCommand := &command.UpdateProductPlanCommand{}
controller.Unmarshal(updateProductPlanCommand)
Must(controller.Unmarshal(updateProductPlanCommand))
productPlanId, _ := controller.GetInt(":productPlanId")
updateProductPlanCommand.ProductPlanId = productPlanId
data, err := productPlanService.UpdateProductPlan(updateProductPlanCommand)
... ... @@ -62,7 +65,7 @@ func (controller *ProductPlanController) ListProductPlan() {
func (controller *ProductPlanController) ReceiveMaterial() {
productPlanService := service.NewProductPlanService(nil)
receiveMaterialCommand := &command.ReceiveMaterialCommand{}
controller.Unmarshal(receiveMaterialCommand)
Must(controller.Unmarshal(receiveMaterialCommand))
data, err := productPlanService.ReceiveMaterial(receiveMaterialCommand)
controller.Response(data, err)
}
... ... @@ -70,7 +73,7 @@ func (controller *ProductPlanController) ReceiveMaterial() {
func (controller *ProductPlanController) ReturnMaterial() {
productPlanService := service.NewProductPlanService(nil)
returnMaterialCommand := &command.ReturnMaterialCommand{}
controller.Unmarshal(returnMaterialCommand)
Must(controller.Unmarshal(returnMaterialCommand))
data, err := productPlanService.ReturnMaterial(returnMaterialCommand)
controller.Response(data, err)
}
... ... @@ -78,7 +81,7 @@ func (controller *ProductPlanController) ReturnMaterial() {
func (controller *ProductPlanController) SetOnline() {
productPlanService := service.NewProductPlanService(nil)
setOnlineCommand := &command.SetOnlineCommand{}
controller.Unmarshal(setOnlineCommand)
Must(controller.Unmarshal(setOnlineCommand))
data, err := productPlanService.SetOnline(setOnlineCommand)
controller.Response(data, err)
}
... ... @@ -86,7 +89,7 @@ func (controller *ProductPlanController) SetOnline() {
func (controller *ProductPlanController) Switch() {
productPlanService := service.NewProductPlanService(nil)
switchCommand := &command.SwitchCommand{}
controller.Unmarshal(switchCommand)
Must(controller.Unmarshal(switchCommand))
data, err := productPlanService.Switch(switchCommand)
controller.Response(data, err)
}
... ... @@ -94,7 +97,19 @@ func (controller *ProductPlanController) Switch() {
func (controller *ProductPlanController) SubmitProductRecord() {
productPlanService := service.NewProductPlanService(nil)
submitProductRecordCommand := &command.SubmitProductRecordCommand{}
controller.Unmarshal(submitProductRecordCommand)
Must(controller.Unmarshal(submitProductRecordCommand))
data, err := productPlanService.SubmitProductRecord(submitProductRecordCommand)
controller.Response(data, err)
}
func (controller *ProductPlanController) SearchProductPlan() {
productPlanService := service.NewProductPlanService(nil)
cmd := &query.SearchProductPlanQuery{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
//cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
cmd.InOrgIds = operateInfo.OrgIds
total, data, err := productPlanService.SearchProductPlan(ParseOperateInfo(controller.BaseController), cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
... ...
... ... @@ -24,7 +24,11 @@ func (controller *ProductSectionController) UpdateProductSection() {
updateProductSectionCommand := &command.UpdateProductSectionCommand{}
Must(controller.Unmarshal(updateProductSectionCommand))
sectionId, _ := controller.GetInt(":sectionId")
lineId, _ := controller.GetInt("lineId")
workshopId, _ := controller.GetInt("workshopId")
updateProductSectionCommand.SectionId = sectionId
updateProductSectionCommand.WorkshopId = workshopId
updateProductSectionCommand.LineId = lineId
data, err := productSectionService.UpdateProductSection(updateProductSectionCommand)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
)
func init() {
web.SetStaticPath("/log", constant.LOG_FILE)
}
... ...
... ... @@ -16,4 +16,5 @@ func init() {
web.Router("/product-plans/set-online", &controllers.ProductPlanController{}, "Post:SetOnline")
web.Router("/product-plans/switch", &controllers.ProductPlanController{}, "Post:Switch")
web.Router("/product-plans/submit-product-record", &controllers.ProductPlanController{}, "Post:SubmitProductRecord")
web.Router("/product-plans/search", &controllers.ProductPlanController{}, "Post:SearchProductPlan")
}
... ...