作者 tangxuhui

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

…ion-manufacture into dev

# Conflicts:
#	main.go
正在显示 42 个修改的文件 包含 764 行增加165 行删除
... ... @@ -5,6 +5,7 @@ go 1.16
require (
github.com/ajg/form v1.5.1 // indirect
github.com/beego/beego/v2 v2.0.1
github.com/eclipse/paho.mqtt.golang v1.3.5
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/gavv/httpexpect v2.0.0+incompatible
... ...
... ... @@ -68,6 +68,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/eclipse/paho.mqtt.golang v1.3.5 h1:sWtmgNxYM9P2sP+xEItMozsR3w0cqZFlqnNN1bdl41Y=
github.com/eclipse/paho.mqtt.golang v1.3.5/go.mod h1:eTzb4gxwwyWpqBUHGQZ4ABAV7+Jgm1PklsYT/eo8Hcc=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
... ... @@ -474,6 +476,7 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
... ... @@ -32,11 +33,10 @@ func main() {
})
log.Logger.AddHook(bw)
redis.InitRedis()
//设置定时任务
go mqtt.Start()
cron := crontab.NewCrontabService(nil)
cron.StartCrontabTask()
defer cron.StopCrontabTask()
//
log.Logger.Info("server start!")
web.Run()
}
... ...
... ... @@ -79,7 +79,7 @@ func FastPgWorkstation(transactionContext application.TransactionContext, worksh
if mod, err = rep.FindOne(map[string]interface{}{"workshopId": workshopId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该工作位置不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -113,7 +113,7 @@ func FastPgProductJob(transactionContext application.TransactionContext, id int,
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该工位不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -142,7 +142,7 @@ func FastPgProductGroup(transactionContext application.TransactionContext, id in
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该生产班组不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -171,7 +171,7 @@ func FastPgProduct(transactionContext application.TransactionContext, id int, op
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该产品不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -197,7 +197,7 @@ func FastPgDevice(transactionContext application.TransactionContext, id int, opt
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该设备档案不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -223,7 +223,7 @@ func FastPgProductCalendar(transactionContext application.TransactionContext, id
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间日历不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -249,7 +249,7 @@ func FastPgUnitConversion(transactionContext application.TransactionContext, id
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该单位换算不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -273,9 +273,9 @@ func FastPgProductPlan(transactionContext application.TransactionContext, id int
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if mod, err = rep.FindOne(map[string]interface{}{"productPlanId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该生产计划不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"strings"
)
// 生产班组员工
type ProductGroupEmployeesDto struct {
// 用户Id 用户唯一标识
UserId int `json:"userId,omitempty"`
// 用户姓名
UserName string `json:"userName,omitempty"`
// 班组名称
GroupName string `json:"groupName,omitempty"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOnDescription string `json:"workOn,omitempty"`
// 工作位置键值 (车间ID+'.'+生产线ID+'.'+工段ID)
//WorkStationId string `json:"workStationId,omitempty"`
}
func NewProductGroupEmployeesDto(group *domain.ProductGroup) []*ProductGroupEmployeesDto {
employees := make([]*ProductGroupEmployeesDto, 0)
if group.GroupLeader != nil {
employees = append(employees, NewGroupEmployee(group, group.GroupLeader))
}
for i := range group.GroupMembers {
employees = append(employees, NewGroupEmployee(group, group.GroupMembers[i]))
}
return employees
}
func NewGroupEmployee(group *domain.ProductGroup, u *domain.User) *ProductGroupEmployeesDto {
item := &ProductGroupEmployeesDto{}
item.UserId = u.UserId
item.UserName = u.UserName
item.GroupName = group.GroupName
workOns := domain.WorkOnDescription(group.WorkOn)
item.WorkOnDescription = strings.Join(workOns, ",")
//item.WorkStationId = group.WorkStation.WorkStationId
return item
}
type ProductGroupEmployeesDtos struct {
Result []*ProductGroupEmployeesDto
MapResult map[int]*ProductGroupEmployeesDto
}
func (d *ProductGroupEmployeesDtos) Append(items ...*ProductGroupEmployeesDto) {
for i := range items {
if _, ok := d.MapResult[items[i].UserId]; ok {
continue
}
d.MapResult[items[i].UserId] = items[i]
d.Result = append(d.Result, items[i])
}
}
func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) {
for i := range groups {
items := NewProductGroupEmployeesDto(groups[i])
d.Append(items...)
}
}
func NewProductGroupEmployeesDtos() *ProductGroupEmployeesDtos {
return &ProductGroupEmployeesDtos{
Result: make([]*ProductGroupEmployeesDto, 0),
MapResult: make(map[int]*ProductGroupEmployeesDto),
}
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
)
type SearchProductGroupEmployeesQuery struct {
// 查询偏离量
//Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
//Limit int `cname:"查询限制" json:"limit"`
// 页码
//PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
//PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"`
// 车间ID
WorkshopId int `cname:"车间ID" json: workshopId,omitempty"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId,omitempty"`
// 工段ID
SectionId int `json:"sectionId,omitempty"`
}
func (listProductGroupQuery *SearchProductGroupEmployeesQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductGroupQuery *SearchProductGroupEmployeesQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductGroupQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductGroupQuery).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
}
... ...
... ... @@ -367,6 +367,48 @@ func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *
return count, results, nil
}
// 返回生产班组服务列表
func (productGroupService *ProductGroupService) SearchProductGroupEmployees(operateInfo *domain.OperateInfo, cmd *query.SearchProductGroupEmployeesQuery) (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()
}()
//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)
_, productGroups, err := productGroupRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var results = dto.NewProductGroupEmployeesDtos()
for i := range productGroups {
item := productGroups[i]
//workStation := workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
//item.WorkStation = workStation
items := dto.NewProductGroupEmployeesDto(item)
results.Append(items...)
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return int64(len(results.Result)), map[string]interface{}{
"employees": results.Result,
}, nil
}
func NewProductGroupService(options map[string]interface{}) *ProductGroupService {
newProductGroupService := &ProductGroupService{}
return newProductGroupService
... ...
... ... @@ -14,7 +14,7 @@ type SetOnlineCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
//LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
}
... ...
... ... @@ -39,7 +39,7 @@ type UpdateProductPlanCommand struct {
// 备注
Remark string `cname:"备注" json:"remark" valid:"Required"`
// 生产日期
ProductDateTime time.Time `cname:"生产日期" json:"-" `
ProductDateTime time.Time `cname:"生产日期" json:"productDateTime" `
}
func (updateProductPlanCommand *UpdateProductPlanCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -19,7 +19,7 @@ type SearchProductPlanQuery struct {
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"`
// 匹配多个组织
InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty" valid:"Required"`
InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
... ...
... ... @@ -256,15 +256,28 @@ func (productPlanService *ProductPlanService) SetOffline(setOfflineCommand *comm
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
var productPlan *domain.ProductPlan
productPlanRepository, productPlan, _ = factory.FastPgProductPlan(transactionContext, setOfflineCommand.ProductPlanId)
if err = productPlan.ChangeStatus(domain.PlanOffline); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productPlan, err = productPlanRepository.Save(productPlan); 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 nil, nil
return productPlan, nil
}
// 计划上线
func (productPlanService *ProductPlanService) SetOnline(setOnlineCommand *command.SetOnlineCommand) (interface{}, error) {
if err := setOnlineCommand.ValidateCommand(); err != nil {
func (productPlanService *ProductPlanService) SetOnline(cmd *command.SetOnlineCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -277,10 +290,45 @@ func (productPlanService *ProductPlanService) SetOnline(setOnlineCommand *comman
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
var productPlan *domain.ProductPlan
productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = productPlan.ChangeStatus(domain.PlanOnline); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var workshop *domain.Workshop
_, workshop, err = factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
line, section, err := workshop.FindSectionById(cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var workStation *domain.WorkStation
workStation, err = workshop.FindWorkStation(workshop.WorkshopId, line.LineId, section.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productPlan.WorkStation = workStation
if productPlan, err = productPlanRepository.Save(productPlan); 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 nil, nil
return productPlan, nil
}
// 提交成品记录 (成品 二级品)
... ... @@ -319,15 +367,49 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw
defer func() {
transactionContext.RollbackTransaction()
}()
var fromPlan, toPlan *domain.ProductPlan
var productPlanRepository domain.ProductPlanRepository
productPlanRepository, fromPlan, err = factory.FastPgProductPlan(transactionContext, switchCommand.FromProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, toPlan, err = factory.FastPgProductPlan(transactionContext, switchCommand.ToProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 计划下线
if err = fromPlan.ChangeStatus(domain.PlanOffline); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err = productPlanRepository.Save(fromPlan); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var workStation *domain.WorkStation
fromWorkStation := fromPlan.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, fromWorkStation.WorkshopId, fromWorkStation.LineId, fromWorkStation.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 计划上线
toPlan.WorkStation = workStation
if err = toPlan.ChangeStatus(domain.PlanOnline); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err = productPlanRepository.Save(toPlan); 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 nil, nil
return struct{}{}, nil
}
// 更新生产计划服务
func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPlanCommand *command.UpdateProductPlanCommand) (interface{}, error) {
if err := updateProductPlanCommand.ValidateCommand(); err != nil {
func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.UpdateProductPlanCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -341,31 +423,38 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPla
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
var productPlan *domain.ProductPlan
productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
productPlan, err := productPlanRepository.FindOne(map[string]interface{}{"productPlanId": updateProductPlanCommand.ProductPlanId})
//if productPlan.Workshop.WorkshopId != cmd.WorkshopId{
// // 检查批次号是否有重复的
// 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())
}
if productPlan == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductPlanCommand.ProductPlanId)))
}
if err := productPlan.Update(tool_funs.SimpleStructToMap(updateProductPlanCommand)); err != nil {
productPlan.Workshop = workshop.CloneSample()
if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if productPlan, err := productPlanRepository.Save(productPlan); err != nil {
if productPlan, err = productPlanRepository.Save(productPlan); 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
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result := &dto.ProductPlanDto{}
return result.LoadDto(productPlan, cmd.OrgId), nil
}
// 搜索生产计划服务列表
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
type MaterialUnitConversionDto struct {
// 单位换算ID
UnitConversionId int `json:"unitConversionId,omitempty"`
// 物料名称
MaterialName string `json:"materialName,omitempty"`
// 转换前单位数量
FromUnitQuantity *domain.UnitQuantity `json:"fromUnitQuantity,omitempty"`
// 转换后单位数量
ToUnitQuantity *domain.UnitQuantity `json:"toUnitQuantity,omitempty"`
}
func (d *MaterialUnitConversionDto) LoadDto(m *domain.UnitConversion) *MaterialUnitConversionDto {
d.UnitConversionId = m.UnitConversionId
d.MaterialName = m.Material.MaterialName
d.FromUnitQuantity = m.FromUnitQuantity
d.ToUnitQuantity = m.ToUnitQuantity
return d
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
)
type SearchMaterialsQuery struct {
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"`
// 车间ID
WorkshopId int `cname:"车间ID" json: workshopId,omitempty"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId,omitempty"`
// 工段ID
SectionId int `json:"sectionId,omitempty"`
}
func (listProductGroupQuery *SearchMaterialsQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductGroupQuery *SearchMaterialsQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductGroupQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductGroupQuery).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
}
... ...
... ... @@ -307,6 +307,42 @@ func (unitConversionService *UnitConversionService) SearchUnitConversion(operate
return count, result, nil
}
// 返回单位换算服务列表
func (unitConversionService *UnitConversionService) SearchMaterial(operateInfo *domain.OperateInfo, listUnitConversionQuery *query.SearchMaterialsQuery) (int64, interface{}, error) {
if err := listUnitConversionQuery.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()
}()
unitConversionRepository, _, _ := factory.FastPgUnitConversion(transactionContext, 0)
count, unitConversions, err := unitConversionRepository.Find(utils.ObjectToMap(listUnitConversionQuery))
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.MaterialUnitConversionDto, 0)
for i := range unitConversions {
item := unitConversions[i]
newItem := &dto.MaterialUnitConversionDto{}
newItem.LoadDto(item)
result = append(result, newItem)
}
return count, map[string]interface{}{
"materials": result,
}, nil
}
func NewUnitConversionService(options map[string]interface{}) *UnitConversionService {
newUnitConversionService := &UnitConversionService{}
return newUnitConversionService
... ...
... ... @@ -326,6 +326,38 @@ func (workshopService *WorkshopService) SelectorWorkshop(operateInfo *domain.Ope
}
// 车间工段列表
func (workshopService *WorkshopService) SelectorWorkshopSection(operateInfo *domain.OperateInfo, getWorkshopQuery *query.GetWorkshopQuery) (interface{}, error) {
if err := getWorkshopQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var workshop *domain.Workshop
_, workshop, err = factory.FastPgWorkshop(transactionContext, getWorkshopQuery.WorkshopId)
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())
}
sections := workshop.AllProductSections(domain.All)
return map[string]interface{}{
"count": len(sections),
"sections": sections,
}, nil
}
func NewWorkshopService(options map[string]interface{}) *WorkshopService {
newWorkshopService := &WorkshopService{}
return newWorkshopService
... ...
package constant
import "os"
//设备商提供的测试地址
var MQTT_HOST = "175.24.122.87"
//内网测试地址
//var MQTT_HOST = "192.168.100.222"
var MQTT_PORT = "1883"
var MQTT_USER = ""
var MQTT_PASSWORD = ""
func init(){
if os.Getenv("MQTT_HOST") != "" {
MQTT_HOST = os.Getenv("MQTT_HOST")
}
if os.Getenv("MQTT_PORT") != "" {
MQTT_PORT = os.Getenv("MQTT_PORT")
}
if os.Getenv("MQTT_USER") != "" {
MQTT_USER = os.Getenv("MQTT_USER")
}
if os.Getenv("MQTT_PASSWORD") != "" {
MQTT_PASSWORD = os.Getenv("MQTT_PASSWORD")
}
}
\ No newline at end of file
... ...
package domain
import "fmt"
// 生产线
type ProductLine struct {
// 生产线ID
... ... @@ -12,6 +14,17 @@ type ProductLine struct {
Removed int `json:"removed,omitempty"`
}
// 查询生产线
func (productLine *ProductLine) FindSection(sectionId int) (*ProductSection, error) {
for i := range productLine.ProductSections {
item := productLine.ProductSections[i]
if item.SectionId == sectionId {
return item, nil
}
}
return nil, fmt.Errorf("工段不存在")
}
func (productLine *ProductLine) GetProductSections(removed int) []*ProductSection {
var result = make([]*ProductSection, 0)
for i := range productLine.ProductSections {
... ...
package domain
import "time"
import (
"errors"
"time"
)
const (
PlanOnline = 1 // 计划上线
... ... @@ -60,119 +63,47 @@ func (productPlan *ProductPlan) Identify() interface{} {
}
func (productPlan *ProductPlan) Update(data map[string]interface{}) error {
//if productPlanId, ok := data["productPlanId"]; ok {
// productPlan.ProductPlanId = productPlanId.(int)
//}
//if companyId, ok := data["companyId"]; ok {
// productPlan.CompanyId = companyId.(int)
//}
//if orgId, ok := data["orgId"]; ok {
// productPlan.OrgId = orgId.(int)
//}
//if batchNumber, ok := data["batchNumber"]; ok {
// productPlan.BatchNumber = batchNumber.(string)
//}
//if productDate, ok := data["productDate"]; ok {
// productPlan.ProductDate = productDate.(time.Time)
//}
//if companyId, ok := data["companyId"]; ok {
// productPlan.Workshop.CompanyId = companyId.(int)
//}
//if orgId, ok := data["orgId"]; ok {
// productPlan.Workshop.OrgId = orgId.(int)
//}
//if workshopId, ok := data["workshopId"]; ok {
// productPlan.Workshop.WorkshopId = workshopId.(int)
//}
//if workshopName, ok := data["workshopName"]; ok {
// productPlan.Workshop.WorkshopName = workshopName.(string)
//}
//if userId, ok := data["userId"]; ok {
// productPlan.Workshop.Principal.UserId = userId.(int)
//}
//if userName, ok := data["userName"]; ok {
// productPlan.Workshop.Principal.UserName = userName.(string)
//}
//if employeeType, ok := data["employeeType"]; ok {
// productPlan.Workshop.Principal.EmployeeType = employeeType.(int)
//}
//if icCardNumber, ok := data["icCardNumber"]; ok {
// productPlan.Workshop.Principal.IcCardNumber = icCardNumber.(string)
//}
//if avatar, ok := data["avatar"]; ok {
// productPlan.Workshop.Principal.Avatar = avatar.(string)
//}
//if phone, ok := data["phone"]; ok {
// productPlan.Workshop.Principal.Phone = phone.(string)
//}
//if productLines, ok := data["productLines"]; ok {
// productPlan.Workshop.ProductLines = productLines.(array)
//}
//if createdAt, ok := data["createdAt"]; ok {
// productPlan.Workshop.CreatedAt = createdAt.(time.Time)
//}
//if updatedAt, ok := data["updatedAt"]; ok {
// productPlan.Workshop.UpdatedAt = updatedAt.(time.Time)
//}
//if deletedAt, ok := data["deletedAt"]; ok {
// productPlan.Workshop.DeletedAt = deletedAt.(time.Time)
//}
//if workOn, ok := data["workOn"]; ok {
// productPlan.WorkOn = workOn.(int)
//}
//if machine, ok := data["machine"]; ok {
// productPlan.Machine = machine.(string)
//}
//if planProductName, ok := data["planProductName"]; ok {
// productPlan.PlanProductName = planProductName.(string)
//}
//if quantity, ok := data["quantity"]; ok {
// productPlan.PlanDevoted.Quantity = quantity.(float64)
//}
//if unit, ok := data["unit"]; ok {
// productPlan.PlanDevoted.Unit = unit.(string)
//}
//if unitWeight, ok := data["unitWeight"]; ok {
// productPlan.PlanDevoted.UnitWeight = unitWeight.(float64)
//}
//if weight, ok := data["weight"]; ok {
// productPlan.PlanDevoted.Weight = weight.(float64)
//}
//if planStatus, ok := data["planStatus"]; ok {
// productPlan.PlanStatus = planStatus.(int)
//}
//if workStationId, ok := data["workStationId"]; ok {
// productPlan.WorkStation.WorkStationId = workStationId.(string)
//}
//if workshopId, ok := data["workshopId"]; ok {
// productPlan.WorkStation.WorkshopId = workshopId.(int)
//}
//if workshopName, ok := data["workshopName"]; ok {
// productPlan.WorkStation.WorkshopName = workshopName.(string)
//}
//if lineId, ok := data["lineId"]; ok {
// productPlan.WorkStation.LineId = lineId.(int)
//}
//if lineName, ok := data["lineName"]; ok {
// productPlan.WorkStation.LineName = lineName.(string)
//}
//if sectionId, ok := data["sectionId"]; ok {
// productPlan.WorkStation.SectionId = sectionId.(int)
//}
//if sectionName, ok := data["sectionName"]; ok {
// productPlan.WorkStation.SectionName = sectionName.(string)
//}
//if remark, ok := data["remark"]; ok {
// productPlan.Remark = remark.(string)
//}
//if createdAt, ok := data["createdAt"]; ok {
// productPlan.CreatedAt = createdAt.(time.Time)
//}
//if updatedAt, ok := data["updatedAt"]; ok {
// productPlan.UpdatedAt = updatedAt.(time.Time)
//}
//if deletedAt, ok := data["deletedAt"]; ok {
// productPlan.DeletedAt = deletedAt.(time.Time)
//}
if productDate, ok := data["productDateTime"]; ok {
productPlan.ProductDate = productDate.(time.Time)
}
if workOn, ok := data["workOn"]; ok {
productPlan.WorkOn = workOn.(int)
}
if machine, ok := data["machine"]; ok {
productPlan.Machine = machine.(string)
}
if planProductName, ok := data["planProductName"]; ok {
productPlan.PlanProductName = planProductName.(string)
}
if quantity, ok := data["quantity"]; ok {
productPlan.PlanDevoted.Quantity = quantity.(float64)
}
if unit, ok := data["unit"]; ok {
productPlan.PlanDevoted.Unit = unit.(string)
}
if weight, ok := data["weight"]; ok {
productPlan.PlanDevoted.Weight = weight.(float64)
}
if remark, ok := data["remark"]; ok {
productPlan.Remark = remark.(string)
}
productPlan.UpdatedAt = time.Now()
return nil
}
func (productPlan *ProductPlan) ChangeStatus(status int) error {
if productPlan.PlanStatus == status && status == PlanOnline {
return errors.New("计划已经上线")
}
if productPlan.PlanStatus == status && status == PlanOffline {
return errors.New("计划已经下线")
}
if !(status == PlanOnline || status == PlanOffline) {
return errors.New("计划状态有误")
}
productPlan.PlanStatus = status
return nil
}
... ...
... ... @@ -9,3 +9,16 @@ type ProductSection struct {
// 已删除标识 1:正常 2:已删除
Removed int `json:"removed,omitempty"`
}
func (m *ProductSection) CloneSample() *ProductSection {
return &ProductSection{
SectionId: m.SectionId,
SectionName: m.SectionName,
}
}
type ProductSections []*ProductSection
func (ms ProductSections) Len() int { return len(ms) }
func (ms ProductSections) Less(i, j int) bool { return ms[i].SectionId < ms[j].SectionId }
func (ms ProductSections) Swap(i, j int) { ms[i], ms[j] = ms[j], ms[i] }
... ...
... ... @@ -31,6 +31,6 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation
LineName: l.LineName,
SectionId: s.SectionId,
SectionName: s.SectionName,
Principal: w.Principal,
//Principal: w.Principal,
}
}
... ...
... ... @@ -2,10 +2,13 @@ package domain
import (
"fmt"
"sort"
"time"
)
const (
// 所有
All = 0
// 未删除
NotDeleted = 1
// 已删除
... ... @@ -220,6 +223,36 @@ func (workshop *Workshop) GetProductLines(removed int) []*ProductLine {
return result
}
func (workshop *Workshop) AllProductSections(removed int) []*ProductSection {
var result ProductSections = make([]*ProductSection, 0)
lines := workshop.GetProductLines(removed)
for i := range lines {
for j := range lines[i].ProductSections {
section := lines[i].ProductSections[j]
if removed > 0 && section.Removed != removed {
continue
}
result = append(result, section.CloneSample())
}
}
sort.Stable(result)
return result
}
// 查询生产线
func (workshop *Workshop) FindSectionById(sectionId int) (*ProductLine, *ProductSection, error) {
lines := workshop.GetProductLines(0)
for k := range lines {
line := lines[k]
section, _ := line.FindSection(sectionId)
if section != nil {
return line, section, nil
}
}
return nil, nil, fmt.Errorf("工段不存在")
}
func (workshop *Workshop) CloneSample() *Workshop {
return &Workshop{
WorkshopId: workshop.WorkshopId,
... ...
package mqtt
import (
"fmt"
pahomqtt "github.com/eclipse/paho.mqtt.golang"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"time"
)
type ProduceClient struct {
client pahomqtt.Client
}
func NewProduceClient() *ProduceClient {
return &ProduceClient{}
}
func (produceClient *ProduceClient) options() *pahomqtt.ClientOptions {
opts := pahomqtt.NewClientOptions().AddBroker(fmt.Sprintf("tcp://%v:%v", constant.MQTT_HOST, constant.MQTT_PORT))
opts.SetUsername(constant.MQTT_USER)
opts.SetPassword(constant.MQTT_PASSWORD)
opts.SetKeepAlive(2 * time.Second)
opts.SetPingTimeout(1 * time.Second)
return opts
}
func (produceClient *ProduceClient) connect(){
opts := produceClient.options()
produceClient.client = pahomqtt.NewClient(opts)
token := produceClient.client.Connect()
token.Wait()
}
func (produceClient *ProduceClient) Publish(topic string,data interface{}) error {
produceClient.connect()
token := produceClient.client.Publish(topic,0,false,data)
token.Wait()
return token.Error()
}
\ No newline at end of file
... ...
package mqtt
import (
"fmt"
pahomqtt "github.com/eclipse/paho.mqtt.golang"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"time"
)
type SubscribeClient struct {
topic string
handler pahomqtt.MessageHandler
client pahomqtt.Client
}
type MessageHandler pahomqtt.MessageHandler
func NewSubscribeClient() *SubscribeClient {
return &SubscribeClient{}
}
func (subscribeClient *SubscribeClient) options() *pahomqtt.ClientOptions {
opts := pahomqtt.NewClientOptions().AddBroker(fmt.Sprintf("tcp://%v:%v", constant.MQTT_HOST, constant.MQTT_PORT))
opts.SetUsername(constant.MQTT_USER)
opts.SetPassword(constant.MQTT_PASSWORD)
opts.SetKeepAlive(2 * time.Second)
opts.SetPingTimeout(1 * time.Second)
return opts
}
func (subscribeClient *SubscribeClient) Connect() *SubscribeClient{
opts := subscribeClient.options()
fmt.Println("start connect......")
opts.OnConnectionLost = func(c pahomqtt.Client, err error) {
fmt.Println("Connect error:", err)
for {
fmt.Println("reconnect server")
token := subscribeClient.client.Connect()
token.Wait()
fmt.Println("server Connect status:",subscribeClient.client.IsConnectionOpen())
if subscribeClient.client.IsConnectionOpen() {
break
}
time.Sleep(3 * time.Second)
}
}
opts.OnConnect = func(c pahomqtt.Client) {
c.Subscribe(subscribeClient.topic,0,subscribeClient.handler)
}
subscribeClient.client = pahomqtt.NewClient(opts)
token := subscribeClient.client.Connect()
token.Wait()
return subscribeClient
}
func (subscribeClient *SubscribeClient) Subscribe(topic string, messageHandler pahomqtt.MessageHandler){
subscribeClient.topic = topic
subscribeClient.handler = messageHandler
token := subscribeClient.client.Subscribe(topic,0,messageHandler)
token.Wait()
token.Done()
}
func StartSubscribe(topic string,handler MessageHandler){
defer func() {
if err := recover();err != nil {
fmt.Println(err)
StartSubscribe(topic,handler)
}
}()
fmt.Println("start subscribe...")
NewSubscribeClient().Connect().Subscribe(topic,pahomqtt.MessageHandler(handler))
}
\ No newline at end of file
... ...
... ... @@ -148,7 +148,7 @@ func (repository *DeviceRepository) FindOne(queryOptions map[string]interface{})
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -153,7 +153,7 @@ func (repository *ProductAttendanceRecordRepository) FindOne(queryOptions map[st
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -138,7 +138,7 @@ func (repository *ProductCalendarRepository) FindOne(queryOptions map[string]int
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -133,7 +133,7 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ... @@ -166,7 +166,10 @@ func (repository *ProductGroupRepository) Find(queryOptions map[string]interface
if v, ok := queryOptions["groupName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`group_name like '%%%v%%'`, v))
}
query.SetOffsetAndLimit(20)
query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId")
query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId")
query.SetWhereByQueryOption("work_station->>'sectionId'='?'", "sectionId")
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_group_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, productGroups, err
... ...
... ... @@ -128,7 +128,7 @@ func (repository *ProductJobRepository) FindOne(queryOptions map[string]interfac
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -156,7 +156,7 @@ func (repository *ProductPlanRepository) FindOne(queryOptions map[string]interfa
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ... @@ -172,7 +172,18 @@ func (repository *ProductPlanRepository) Find(queryOptions map[string]interface{
var productPlanModels []*models.ProductPlan
productPlans := make([]*domain.ProductPlan, 0)
query := sqlbuilder.BuildQuery(tx.Model(&productPlanModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("batch_number=?", "batchNumber")
if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`batch_number like '%%%v%%'`, v))
}
if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`workshop->>'workshopName' like '%%%v%%'`, v))
}
query.SetWhereByQueryOption("plan_status=?", "planStatus")
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_plan_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, productPlans, err
... ...
... ... @@ -133,7 +133,7 @@ func (repository *ProductRecordRepository) FindOne(queryOptions map[string]inter
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ... @@ -149,7 +149,7 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac
var productRecordModels []*models.ProductRecord
productRecords := make([]*domain.ProductRecord, 0)
query := sqlbuilder.BuildQuery(tx.Model(&productRecordModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_record_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, productRecords, err
... ...
... ... @@ -130,7 +130,7 @@ func (repository *ProductRepository) FindOne(queryOptions map[string]interface{}
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ... @@ -157,7 +157,7 @@ func (repository *ProductRepository) Find(queryOptions map[string]interface{}) (
if v, ok := queryOptions["productCategory"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_category like '%%%v%%'`, v))
}
query.SetOffsetAndLimit(20)
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, products, err
... ...
... ... @@ -128,7 +128,7 @@ func (repository *UnitConversionRepository) FindOne(queryOptions map[string]inte
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ... @@ -146,6 +146,9 @@ func (repository *UnitConversionRepository) Find(queryOptions map[string]interfa
query := sqlbuilder.BuildQuery(tx.Model(&unitConversionModels), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId")
query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId")
query.SetWhereByQueryOption("work_station->>'sectionId'='?'", "sectionId")
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
... ...
... ... @@ -121,7 +121,7 @@ func (repository *WorkshopRepository) FindOne(queryOptions map[string]interface{
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -78,3 +78,14 @@ func (controller *ProductGroupController) SearchProductGroup() {
total, data, err := productGroupService.SearchProductGroup(ParseOperateInfo(controller.BaseController), cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *ProductGroupController) SearchProductGroupEmployees() {
productGroupService := service.NewProductGroupService(nil)
cmd := &query.SearchProductGroupEmployeesQuery{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
_, data, err := productGroupService.SearchProductGroupEmployees(operateInfo, cmd)
controller.Response(data, err)
}
... ...
... ... @@ -86,6 +86,14 @@ func (controller *ProductPlanController) SetOnline() {
controller.Response(data, err)
}
func (controller *ProductPlanController) SetOffline() {
productPlanService := service.NewProductPlanService(nil)
setOnlineCommand := &command.SetOfflineCommand{}
Must(controller.Unmarshal(setOnlineCommand))
data, err := productPlanService.SetOffline(setOnlineCommand)
controller.Response(data, err)
}
func (controller *ProductPlanController) Switch() {
productPlanService := service.NewProductPlanService(nil)
switchCommand := &command.SwitchCommand{}
... ...
... ... @@ -78,3 +78,14 @@ func (controller *UnitConversionController) SearchUnitConversion() {
total, data, err := unitConversionService.SearchUnitConversion(ParseOperateInfo(controller.BaseController), cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *UnitConversionController) SearchMaterial() {
unitConversionService := service.NewUnitConversionService(nil)
cmd := &query.SearchMaterialsQuery{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
_, data, err := unitConversionService.SearchMaterial(ParseOperateInfo(controller.BaseController), cmd)
controller.Response(data, err)
}
... ...
... ... @@ -74,3 +74,11 @@ func (controller *WorkshopController) SelectorWorkshop() {
data, err := workshopService.SearchWorkshop(ParseOperateInfo(controller.BaseController), listWorkshopQuery)
controller.Response(data, err)
}
func (controller *WorkshopController) SelectorWorkshopSection() {
workshopService := service.NewWorkshopService(nil)
getWorkshopQuery := &query.GetWorkshopQuery{}
Must(controller.Unmarshal(getWorkshopQuery))
data, err := workshopService.SelectorWorkshopSection(ParseOperateInfo(controller.BaseController), getWorkshopQuery)
controller.Response(data, err)
}
... ...
... ... @@ -13,4 +13,5 @@ func init() {
web.Router("/product-groups/batch-remove", &controllers.ProductGroupController{}, "Post:BatchRemoveProductGroup")
web.Router("/product-groups/", &controllers.ProductGroupController{}, "Get:ListProductGroup")
web.Router("/product-groups/search", &controllers.ProductGroupController{}, "Post:SearchProductGroup")
web.Router("/product-groups/employees", &controllers.ProductGroupController{}, "Post:SearchProductGroupEmployees")
}
... ...
... ... @@ -14,7 +14,8 @@ func init() {
web.Router("/product-plans/receive-material", &controllers.ProductPlanController{}, "Post:ReceiveMaterial")
web.Router("/product-plans/return-material", &controllers.ProductPlanController{}, "Post:ReturnMaterial")
web.Router("/product-plans/set-online", &controllers.ProductPlanController{}, "Post:SetOnline")
web.Router("/product-plans/switch", &controllers.ProductPlanController{}, "Post:Switch")
web.Router("/product-plans/set-offline", &controllers.ProductPlanController{}, "Post:SetOffline")
web.Router("/product-plans/exchange", &controllers.ProductPlanController{}, "Post:Switch")
web.Router("/product-plans/submit-product-record", &controllers.ProductPlanController{}, "Post:SubmitProductRecord")
web.Router("/product-plans/search", &controllers.ProductPlanController{}, "Post:SearchProductPlan")
}
... ...
... ... @@ -13,4 +13,6 @@ func init() {
web.Router("/unit-conversions/batch-remove", &controllers.UnitConversionController{}, "Post:BatchRemoveUnitConversion")
web.Router("/unit-conversions/", &controllers.UnitConversionController{}, "Get:ListUnitConversion")
web.Router("/unit-conversions/search", &controllers.UnitConversionController{}, "Post:SearchUnitConversion")
web.Router("/unit-conversions/materials", &controllers.UnitConversionController{}, "Post:SearchMaterial")
}
... ...
... ... @@ -13,4 +13,5 @@ func init() {
web.Router("/workshops/", &controllers.WorkshopController{}, "Get:ListWorkshop")
web.Router("/workshops/search", &controllers.WorkshopController{}, "Post:SearchWorkshop")
web.Router("/workshops/selector", &controllers.WorkshopController{}, "Post:SelectorWorkshop")
web.Router("/workshops/sections-selector", &controllers.WorkshopController{}, "Post:SelectorWorkshopSection")
}
... ...
package mqtt
import (
"fmt"
pahomqtt "github.com/eclipse/paho.mqtt.golang"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/mqtt"
"strconv"
"time"
)
func Start(){
mqtt.StartSubscribe("test", func(client pahomqtt.Client, message pahomqtt.Message) {
fmt.Println(time.Now(),"Topic:"+message.Topic()+" MessageId:"+ strconv.Itoa(int(message.MessageID()))+" Message:"+ string(message.Payload()))
})
}
\ No newline at end of file
... ...