作者 yangfu

设备管理修改

... ... @@ -36,7 +36,7 @@ type CreateDeviceCommand struct {
}
func (createDeviceCommand *CreateDeviceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createDeviceCommand *CreateDeviceCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type RemoveDeviceCommand struct {
}
func (removeDeviceCommand *RemoveDeviceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeDeviceCommand *RemoveDeviceCommand) ValidateCommand() error {
... ...
... ... @@ -34,7 +34,7 @@ type UpdateDeviceCommand struct {
}
func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateDeviceCommand *UpdateDeviceCommand) ValidateCommand() error {
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type DeviceDto struct {
// 设备Id
DeviceId int `json:"deviceId,omitempty"`
// 设备编号
DeviceCode string `json:"deviceCode,omitempty"`
// 设备名称
DeviceName string `json:"deviceName,omitempty"`
// 设备型号
DeviceModel string `json:"deviceModel,omitempty"`
// 设备类型
DeviceType string `json:"deviceType,omitempty"`
// 品牌
Brand string `json:"brand,omitempty"`
// 设备状态 1:正常 2:封存 3:报废
DeviceStatus int `json:"deviceStatus,omitempty"`
// 风险等级 1:高 2:中 3:低
RiskLevel int `json:"riskLevel,omitempty"`
// 所属位置
*domain.WorkStation
}
func (d *DeviceDto) LoadDto(m *domain.Device) *DeviceDto {
d.DeviceId = m.DeviceId
d.DeviceCode = m.DeviceCode
d.DeviceName = m.DeviceName
d.DeviceType = m.DeviceType
d.Brand = m.Brand
d.DeviceStatus = m.DeviceStatus
d.RiskLevel = m.RiskLevel
d.WorkStation = m.WorkStation
return d
}
... ...
... ... @@ -14,7 +14,7 @@ type GetDeviceQuery struct {
}
func (getDeviceQuery *GetDeviceQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getDeviceQuery *GetDeviceQuery) ValidateQuery() error {
... ...
... ... @@ -10,13 +10,13 @@ import (
type ListDeviceQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listDeviceQuery *ListDeviceQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listDeviceQuery *ListDeviceQuery) 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 SearchDeviceQuery 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" valid:"Required"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 设备名称
DeviceName string `json:"deviceName,omitempty"`
// 设备状态 1:正常 2:封存 3:报废
DeviceStatus int `json:"deviceStatus,omitempty"`
}
func (cmd *SearchDeviceQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
}
func (cmd *SearchDeviceQuery) 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
}
... ...
... ... @@ -5,9 +5,12 @@ import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
// 设备服务
... ... @@ -15,8 +18,10 @@ type DeviceService struct {
}
// 创建设备服务
func (deviceService *DeviceService) CreateDevice(createDeviceCommand *command.CreateDeviceCommand) (interface{}, error) {
if err := createDeviceCommand.ValidateCommand(); err != nil {
func (deviceService *DeviceService) CreateDevice(operateInfo *domain.OperateInfo, cmd *command.CreateDeviceCommand) (interface{}, error) {
cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -29,27 +34,40 @@ func (deviceService *DeviceService) CreateDevice(createDeviceCommand *command.Cr
defer func() {
transactionContext.RollbackTransaction()
}()
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
newDevice := &domain.Device{
CompanyId: createDeviceCommand.CompanyId,
OrgId: createDeviceCommand.OrgId,
DeviceCode: createDeviceCommand.DeviceCode,
DeviceName: createDeviceCommand.DeviceName,
DeviceModel: createDeviceCommand.DeviceModel,
DeviceType: createDeviceCommand.DeviceType,
//WorkshopId: createDeviceCommand.WorkshopId,
//LineId: createDeviceCommand.LineId,
//SectionId: createDeviceCommand.SectionId,
Brand: createDeviceCommand.Brand,
DeviceStatus: createDeviceCommand.DeviceStatus,
RiskLevel: createDeviceCommand.RiskLevel,
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
DeviceCode: cmd.DeviceCode,
DeviceName: cmd.DeviceName,
DeviceModel: cmd.DeviceModel,
DeviceType: cmd.DeviceType,
WorkStation: workStation,
Brand: cmd.Brand,
DeviceStatus: cmd.DeviceStatus,
RiskLevel: cmd.RiskLevel,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
if total, _, err := deviceRepository.Find(map[string]interface{}{
"deviceCode": cmd.DeviceCode,
"companyId": cmd.CompanyId,
"orgId": cmd.OrgId,
"limit": 1,
}); err == nil && total > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "设备编号重复")
}
var deviceRepository domain.DeviceRepository
if value, err := factory.CreateDeviceRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
if err := newDevice.Valid(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceRepository = value
}
if device, err := deviceRepository.Save(newDevice); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -94,7 +112,10 @@ func (deviceService *DeviceService) GetDevice(getDeviceQuery *query.GetDeviceQue
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return device, nil
result := &dto.DeviceDto{}
result.LoadDto(device)
return result, nil
}
}
... ... @@ -175,8 +196,8 @@ func (deviceService *DeviceService) RemoveDevice(removeDeviceCommand *command.Re
}
// 更新设备服务
func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.UpdateDeviceCommand) (interface{}, error) {
if err := updateDeviceCommand.ValidateCommand(); err != nil {
func (deviceService *DeviceService) UpdateDevice(cmd *command.UpdateDeviceCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -190,23 +211,35 @@ func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.Up
transactionContext.RollbackTransaction()
}()
var deviceRepository domain.DeviceRepository
if value, err := factory.CreateDeviceRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
var device *domain.Device
deviceRepository, device, err = factory.FastPgDevice(transactionContext, cmd.DeviceId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceRepository = value
}
device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": updateDeviceCommand.DeviceId})
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if device == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDeviceCommand.DeviceId)))
device.WorkStation = workStation
if cmd.DeviceCode != device.DeviceCode {
if total, _, err := deviceRepository.Find(map[string]interface{}{
"deviceCode": cmd.DeviceCode,
"companyId": device.CompanyId,
"orgId": device.OrgId,
"limit": 1,
}); err == nil && total > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "设备编号重复")
}
}
if err := device.Update(tool_funs.SimpleStructToMap(updateDeviceCommand)); err != nil {
if err := device.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if err := device.Valid(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if device, err := deviceRepository.Save(device); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -217,6 +250,43 @@ func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.Up
}
}
// 返回设备服务列表
func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo, listDeviceQuery *query.SearchDeviceQuery) (int64, interface{}, error) {
listDeviceQuery.OrgId = operateInfo.OrgId
listDeviceQuery.CompanyId = operateInfo.CompanyId
if err := listDeviceQuery.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()
}()
deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
count, devices, err := deviceRepository.Find(utils.ObjectToMap(listDeviceQuery))
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.DeviceDto, 0)
for i := range devices {
item := devices[i]
newJobDto := &dto.DeviceDto{}
newJobDto.LoadDto(item)
result = append(result, newJobDto)
}
return count, result, nil
}
func NewDeviceService(options map[string]interface{}) *DeviceService {
newDeviceService := &DeviceService{}
return newDeviceService
... ...
... ... @@ -2,6 +2,7 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
... ... @@ -20,23 +21,17 @@ type CreateUnitConversionCommand struct {
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 物料名称
MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`
// 物料类别
MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
Material *domain.Material `cname:"物料" json:"material" valid:"Required"`
// 转换前单位数量
FromUnitQuantity *domain.UnitQuantity `cname:"转换前单位数量" json:"fromUnitQuantity,omitempty"`
// 转换后单位数量
ToUnitQuantity *domain.UnitQuantity `cname:"转换后单位数量" json:"toUnitQuantity,omitempty"`
// 智能称重标识
IntelligentWeighingFlag bool `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
IntelligentWeighingFlag int `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
}
func (createUnitConversionCommand *CreateUnitConversionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createUnitConversionCommand *CreateUnitConversionCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type RemoveUnitConversionCommand struct {
}
func (removeUnitConversionCommand *RemoveUnitConversionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeUnitConversionCommand *RemoveUnitConversionCommand) ValidateCommand() error {
... ...
... ... @@ -2,6 +2,7 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
... ... @@ -11,10 +12,6 @@ import (
type UpdateUnitConversionCommand struct {
// 单位换算ID
UnitConversionId int `cname:"单位换算ID" json:"unitConversionId" valid:"Required"`
// 企业id
CompanyId int `cname:"企业id" json:"companyId,omitempty"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId,omitempty"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
... ... @@ -22,23 +19,17 @@ type UpdateUnitConversionCommand struct {
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 物料名称
MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`
// 物料类别
MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
Material *domain.Material `cname:"物料" json:"material" valid:"Required"`
// 转换前单位数量
FromUnitQuantity *domain.UnitQuantity `cname:"转换前单位数量" json:"fromUnitQuantity,omitempty"`
// 转换后单位数量
ToUnitQuantity *domain.UnitQuantity `cname:"转换后单位数量" json:"toUnitQuantity,omitempty"`
// 智能称重标识
IntelligentWeighingFlag bool `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
IntelligentWeighingFlag int `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
}
func (updateUnitConversionCommand *UpdateUnitConversionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateUnitConversionCommand *UpdateUnitConversionCommand) ValidateCommand() error {
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
type UnitConversionDto struct {
// 单位换算ID
UnitConversionId int `json:"unitConversionId,omitempty"`
// 企业id
//CompanyId int `json:"companyId,omitempty"`
// 组织ID
//OrgId int `json:"orgId,omitempty"`
// 工作位置
*domain.WorkStation `json:"workStation,omitempty"`
// material
*domain.Material `json:"material,omitempty"`
// 转换前单位数量
FromUnitQuantity *domain.UnitQuantity `json:"fromUnitQuantity,omitempty"`
// 转换后单位数量
ToUnitQuantity *domain.UnitQuantity `json:"toUnitQuantity,omitempty"`
// 智能称重标识 1:是 2:否
IntelligentWeighingFlag int `json:"intelligentWeighingFlag,omitempty"`
}
func (d *UnitConversionDto) LoadDto(m *domain.UnitConversion) *UnitConversionDto {
d.UnitConversionId = m.UnitConversionId
d.WorkStation = m.WorkStation
d.Material = m.Material
d.FromUnitQuantity = m.FromUnitQuantity
d.ToUnitQuantity = m.ToUnitQuantity
d.IntelligentWeighingFlag = m.IntelligentWeighingFlag
return d
}
... ...
... ... @@ -14,7 +14,7 @@ type GetUnitConversionQuery struct {
}
func (getUnitConversionQuery *GetUnitConversionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getUnitConversionQuery *GetUnitConversionQuery) ValidateQuery() error {
... ...
... ... @@ -10,13 +10,13 @@ import (
type ListUnitConversionQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listUnitConversionQuery *ListUnitConversionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listUnitConversionQuery *ListUnitConversionQuery) 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 SearchUnitConversionQuery 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" valid:"Required"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 物料名称
MaterialName string `cname:"物料名称" json:"materialName"`
// 智能称重标识 0:全部 1:是 2:否
IntelligentWeighingFlag int `cname:"智能称重标识" json:"intelligentWeighingFlag"`
}
func (cmd *SearchUnitConversionQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
}
func (cmd *SearchUnitConversionQuery) 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,11 @@ 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/unitConversion/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
// 单位换算服务
... ... @@ -15,8 +18,10 @@ type UnitConversionService struct {
}
// 创建单位换算服务
func (unitConversionService *UnitConversionService) CreateUnitConversion(createUnitConversionCommand *command.CreateUnitConversionCommand) (interface{}, error) {
if err := createUnitConversionCommand.ValidateCommand(); err != nil {
func (unitConversionService *UnitConversionService) CreateUnitConversion(operateInfo *domain.OperateInfo, cmd *command.CreateUnitConversionCommand) (interface{}, error) {
cmd.CompanyId = operateInfo.CompanyId
cmd.OrgId = operateInfo.OrgId
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -29,25 +34,26 @@ func (unitConversionService *UnitConversionService) CreateUnitConversion(createU
defer func() {
transactionContext.RollbackTransaction()
}()
newUnitConversion := &domain.UnitConversion{
CompanyId: createUnitConversionCommand.CompanyId,
OrgId: createUnitConversionCommand.OrgId,
//WorkshopId: createUnitConversionCommand.WorkshopId,
//LineId: createUnitConversionCommand.LineId,
//SectionId: createUnitConversionCommand.SectionId,
//Material: createUnitConversionCommand.Material,
//FromUnitQuantity: createUnitConversionCommand.FromUnitQuantity,
//ToUnitQuantity: createUnitConversionCommand.ToUnitQuantity,
IntelligentWeighingFlag: createUnitConversionCommand.IntelligentWeighingFlag,
}
var unitConversionRepository domain.UnitConversionRepository
if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
unitConversionRepository = value
}
newUnitConversion := &domain.UnitConversion{
CompanyId: cmd.CompanyId,
OrgId: cmd.OrgId,
Material: cmd.Material,
FromUnitQuantity: cmd.FromUnitQuantity,
ToUnitQuantity: cmd.ToUnitQuantity,
IntelligentWeighingFlag: cmd.IntelligentWeighingFlag,
WorkStation: workStation,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
unitConversionRepository, _, _ := factory.FastPgUnitConversion(transactionContext, 0)
if unitConversion, err := unitConversionRepository.Save(newUnitConversion); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -73,26 +79,17 @@ func (unitConversionService *UnitConversionService) GetUnitConversion(getUnitCon
defer func() {
transactionContext.RollbackTransaction()
}()
var unitConversionRepository domain.UnitConversionRepository
if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
unitConversionRepository = value
}
unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": getUnitConversionQuery.UnitConversionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if unitConversion == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getUnitConversionQuery.UnitConversionId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return unitConversion, nil
//var unitConversionRepository domain.UnitConversionRepository
var unitConversion *domain.UnitConversion
_, unitConversion, err = factory.FastPgUnitConversion(transactionContext, getUnitConversionQuery.UnitConversionId)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result := &dto.UnitConversionDto{}
result.LoadDto(unitConversion)
return result, nil
}
// 返回单位换算服务列表
... ... @@ -172,8 +169,8 @@ func (unitConversionService *UnitConversionService) RemoveUnitConversion(removeU
}
// 更新单位换算服务
func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateUnitConversionCommand *command.UpdateUnitConversionCommand) (interface{}, error) {
if err := updateUnitConversionCommand.ValidateCommand(); err != nil {
func (unitConversionService *UnitConversionService) UpdateUnitConversion(cmd *command.UpdateUnitConversionCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -187,21 +184,21 @@ func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateU
transactionContext.RollbackTransaction()
}()
var unitConversionRepository domain.UnitConversionRepository
if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
unitConversionRepository = value
}
unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": updateUnitConversionCommand.UnitConversionId})
var unitConversion *domain.UnitConversion
unitConversionRepository, unitConversion, err = factory.FastPgUnitConversion(transactionContext, cmd.UnitConversionId)
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if unitConversion == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateUnitConversionCommand.UnitConversionId)))
}
if err := unitConversion.Update(tool_funs.SimpleStructToMap(updateUnitConversionCommand)); err != nil {
unitConversion.WorkStation = workStation
unitConversion.Material = cmd.Material
unitConversion.FromUnitQuantity = cmd.FromUnitQuantity
unitConversion.ToUnitQuantity = cmd.ToUnitQuantity
unitConversion.IntelligentWeighingFlag = cmd.IntelligentWeighingFlag
if err := unitConversion.Update(utils.ObjectToMap(cmd)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if unitConversion, err := unitConversionRepository.Save(unitConversion); err != nil {
... ... @@ -214,6 +211,42 @@ func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateU
}
}
// 返回单位换算服务列表
func (unitConversionService *UnitConversionService) SearchUnitConversion(operateInfo *domain.OperateInfo, listUnitConversionQuery *query.SearchUnitConversionQuery) (int64, interface{}, error) {
listUnitConversionQuery.OrgId = operateInfo.OrgId
listUnitConversionQuery.CompanyId = operateInfo.CompanyId
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.UnitConversionDto, 0)
for i := range unitConversions {
item := unitConversions[i]
newItem := &dto.UnitConversionDto{}
newItem.LoadDto(item)
result = append(result, newItem)
}
return count, result, nil
}
func NewUnitConversionService(options map[string]interface{}) *UnitConversionService {
newUnitConversionService := &UnitConversionService{}
return newUnitConversionService
... ...
package domain
import "time"
import (
"fmt"
"time"
)
// 风险等级
const (
RiskLevelHigh = 1 // 1:高
RiskLevelMiddle = 2 // 2:中
RiskLevelLow = 3 // 3:低
)
const (
DeviceStatusNormal = 1 // 1:正常
DeviceStatusArchive = 2 // 2:封存
DeviceStatusScrapped = 3 // 3:报废
)
// 设备
type Device struct {
... ... @@ -49,12 +65,6 @@ func (device *Device) Identify() interface{} {
}
func (device *Device) Update(data map[string]interface{}) error {
if companyId, ok := data["companyId"]; ok {
device.CompanyId = companyId.(int)
}
if orgId, ok := data["orgId"]; ok {
device.OrgId = orgId.(int)
}
if deviceCode, ok := data["deviceCode"]; ok {
device.DeviceCode = deviceCode.(string)
}
... ... @@ -76,35 +86,16 @@ func (device *Device) Update(data map[string]interface{}) error {
if riskLevel, ok := data["riskLevel"]; ok {
device.RiskLevel = riskLevel.(int)
}
if createdAt, ok := data["createdAt"]; ok {
device.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
device.UpdatedAt = updatedAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
device.DeletedAt = deletedAt.(time.Time)
}
if workStationId, ok := data["workStationId"]; ok {
device.WorkStation.WorkStationId = workStationId.(string)
}
if workshopId, ok := data["workshopId"]; ok {
device.WorkStation.WorkshopId = workshopId.(int)
}
if workshopName, ok := data["workshopName"]; ok {
device.WorkStation.WorkshopName = workshopName.(string)
}
if lineId, ok := data["lineId"]; ok {
device.WorkStation.LineId = lineId.(int)
}
if lineName, ok := data["lineName"]; ok {
device.WorkStation.LineName = lineName.(string)
}
if sectionId, ok := data["sectionId"]; ok {
device.WorkStation.SectionId = sectionId.(int)
device.UpdatedAt = time.Now()
return nil
}
func (device *Device) Valid() error {
if !(device.RiskLevel == RiskLevelHigh || device.RiskLevel == RiskLevelMiddle || device.RiskLevel == RiskLevelLow) {
return fmt.Errorf("风险等级参数有误")
}
if sectionName, ok := data["sectionName"]; ok {
device.WorkStation.SectionName = sectionName.(string)
if !(device.DeviceStatus == DeviceStatusNormal || device.DeviceStatus == DeviceStatusArchive || device.DeviceStatus == DeviceStatusScrapped) {
return fmt.Errorf("设备状态参数有误")
}
return nil
}
... ...
... ... @@ -4,6 +4,7 @@ import "fmt"
const MaxQueryRow = 10000
// 班次
const (
WorkOnFullDay = 1 //全天
WorkOnDay = 2 //白班
... ...
... ... @@ -18,8 +18,8 @@ type UnitConversion struct {
FromUnitQuantity *UnitQuantity `json:"fromUnitQuantity,omitempty"`
// 转换后单位数量
ToUnitQuantity *UnitQuantity `json:"toUnitQuantity,omitempty"`
// 智能称重标识
IntelligentWeighingFlag bool `json:"intelligentWeighingFlag,omitempty"`
// 智能称重标识 1:是 2:否
IntelligentWeighingFlag int `json:"intelligentWeighingFlag,omitempty"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
... ... @@ -43,77 +43,15 @@ func (unitConversion *UnitConversion) Identify() interface{} {
}
func (unitConversion *UnitConversion) Update(data map[string]interface{}) error {
if unitConversionId, ok := data["unitConversionId"]; ok {
unitConversion.UnitConversionId = unitConversionId.(int)
}
if companyId, ok := data["companyId"]; ok {
unitConversion.CompanyId = companyId.(int)
}
if orgId, ok := data["orgId"]; ok {
unitConversion.OrgId = orgId.(int)
}
if workStationId, ok := data["workStationId"]; ok {
unitConversion.WorkStation.WorkStationId = workStationId.(string)
}
if workshopId, ok := data["workshopId"]; ok {
unitConversion.WorkStation.WorkshopId = workshopId.(int)
}
if workshopName, ok := data["workshopName"]; ok {
unitConversion.WorkStation.WorkshopName = workshopName.(string)
}
if lineId, ok := data["lineId"]; ok {
unitConversion.WorkStation.LineId = lineId.(int)
}
if lineName, ok := data["lineName"]; ok {
unitConversion.WorkStation.LineName = lineName.(string)
}
if sectionId, ok := data["sectionId"]; ok {
unitConversion.WorkStation.SectionId = sectionId.(int)
}
if sectionName, ok := data["sectionName"]; ok {
unitConversion.WorkStation.SectionName = sectionName.(string)
}
if materialName, ok := data["materialName"]; ok {
unitConversion.Material.MaterialName = materialName.(string)
}
if materialCategory, ok := data["materialCategory"]; ok {
unitConversion.Material.MaterialCategory = materialCategory.(string)
}
if quantity, ok := data["quantity"]; ok {
unitConversion.FromUnitQuantity.Quantity = quantity.(float64)
}
if unit, ok := data["unit"]; ok {
unitConversion.FromUnitQuantity.Unit = unit.(string)
}
if unitWeight, ok := data["unitWeight"]; ok {
unitConversion.FromUnitQuantity.UnitWeight = unitWeight.(float64)
}
if weight, ok := data["weight"]; ok {
unitConversion.FromUnitQuantity.Weight = weight.(float64)
}
//if quantity, ok := data["quantity"]; ok {
// unitConversion.ToUnitQuantity.FromUnitQuantity.Quantity = quantity.(float64)
//if materialName, ok := data["materialName"]; ok {
// unitConversion.Material.MaterialName = materialName.(string)
//}
//if unit, ok := data["unit"]; ok {
// unitConversion.ToUnitQuantity.FromUnitQuantity.Unit = unit.(string)
//}
//if unitWeight, ok := data["unitWeight"]; ok {
// unitConversion.ToUnitQuantity.FromUnitQuantity.UnitWeight = unitWeight.(float64)
//}
//if weight, ok := data["weight"]; ok {
// unitConversion.ToUnitQuantity.FromUnitQuantity.Weight = weight.(float64)
//if materialCategory, ok := data["materialCategory"]; ok {
// unitConversion.Material.MaterialCategory = materialCategory.(string)
//}
//if intelligentWeighingFlag, ok := data["intelligentWeighingFlag"]; ok {
// unitConversion.IntelligentWeighingFlag = intelligentWeighingFlag.(boolean)
// unitConversion.IntelligentWeighingFlag = intelligentWeighingFlag.(bool)
//}
if createdAt, ok := data["createdAt"]; ok {
unitConversion.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
unitConversion.UpdatedAt = updatedAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
unitConversion.DeletedAt = deletedAt.(time.Time)
}
unitConversion.UpdatedAt = time.Now()
return nil
}
... ...
... ... @@ -21,8 +21,8 @@ type UnitConversion struct {
FromUnitQuantity *domain.UnitQuantity `comment:"转换前单位数量"`
// 转换后单位数量
ToUnitQuantity *domain.UnitQuantity `comment:"转换后单位数量"`
// 智能称重标识
IntelligentWeighingFlag bool `comment:"智能称重标识"`
// 智能称重标识 1:是 2:否
IntelligentWeighingFlag int `comment:"智能称重标识 1:是 2:否"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 更新时间
... ...
... ... @@ -41,19 +41,13 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
"deleted_at",
"work_station",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_id")
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_id", "deleted_at")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if device.Identify() == nil {
deviceId, err := repository.nextIdentify()
if err != nil {
return device, err
} else {
device.DeviceId = int(deviceId)
}
if _, err := tx.QueryOne(
pg.Scan(
&device.DeviceId,
... ... @@ -71,8 +65,8 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
&device.DeletedAt,
&device.WorkStation,
),
fmt.Sprintf("INSERT INTO devices (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
device.DeviceId,
fmt.Sprintf("INSERT INTO manufacture.device (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
//device.DeviceId,
device.CompanyId,
device.OrgId,
device.DeviceCode,
... ... @@ -84,7 +78,7 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
device.RiskLevel,
device.CreatedAt,
device.UpdatedAt,
device.DeletedAt,
//device.DeletedAt,
device.WorkStation,
); err != nil {
return device, err
... ... @@ -107,8 +101,7 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
&device.DeletedAt,
&device.WorkStation,
),
fmt.Sprintf("UPDATE devices SET %s WHERE device_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
device.DeviceId,
fmt.Sprintf("UPDATE manufacture.device SET %s WHERE device_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
device.CompanyId,
device.OrgId,
device.DeviceCode,
... ... @@ -120,7 +113,6 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
device.RiskLevel,
device.CreatedAt,
device.UpdatedAt,
device.DeletedAt,
device.WorkStation,
device.Identify(),
); err != nil {
... ... @@ -142,7 +134,10 @@ func (repository *DeviceRepository) FindOne(queryOptions map[string]interface{})
tx := repository.transactionContext.PgTx
deviceModel := new(models.Device)
query := sqlbuilder.BuildQuery(tx.Model(deviceModel), queryOptions)
query.SetWhereByQueryOption("device.device_id = ?", "deviceId")
query.SetWhereByQueryOption("device_id = ?", "deviceId")
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("device_code = ?", "deviceCode")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ... @@ -163,6 +158,13 @@ func (repository *DeviceRepository) Find(queryOptions map[string]interface{}) (i
query := sqlbuilder.BuildQuery(tx.Model(&deviceModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("device_id", "DESC")
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("device_code = ?", "deviceCode")
query.SetWhereByQueryOption("device_status = ?", "deviceStatus")
if v, ok := queryOptions["deviceName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`device_name like '%%%v%%'`, v))
}
if count, err := query.SelectAndCount(); err != nil {
return 0, devices, err
} else {
... ...
... ... @@ -40,19 +40,13 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
"updated_at",
"deleted_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "productCalendar_id")
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if productCalendar.Identify() == nil {
productCalendarId, err := repository.nextIdentify()
if err != nil {
return productCalendar, err
} else {
productCalendar.ProductCalendarId = int(productCalendarId)
}
if _, err := tx.QueryOne(
pg.Scan(
&productCalendar.ProductCalendarId,
... ... @@ -60,7 +54,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
&productCalendar.OrgId,
&productCalendar.WorkStation,
&productCalendar.WorkOn,
pg.Array(&productCalendar.CalendarSelected),
&productCalendar.CalendarSelected,
&productCalendar.InWorkAt,
&productCalendar.OutWorkAt,
&productCalendar.BreakTime,
... ... @@ -70,19 +64,17 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
&productCalendar.DeletedAt,
),
fmt.Sprintf("INSERT INTO product_calendars (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
productCalendar.ProductCalendarId,
productCalendar.CompanyId,
productCalendar.OrgId,
productCalendar.WorkStation,
productCalendar.WorkOn,
pg.Array(productCalendar.CalendarSelected),
productCalendar.CalendarSelected,
productCalendar.InWorkAt,
productCalendar.OutWorkAt,
productCalendar.BreakTime,
productCalendar.WorkTime,
productCalendar.CreatedAt,
productCalendar.UpdatedAt,
productCalendar.DeletedAt,
); err != nil {
return productCalendar, err
}
... ... @@ -94,7 +86,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
&productCalendar.OrgId,
&productCalendar.WorkStation,
&productCalendar.WorkOn,
pg.Array(&productCalendar.CalendarSelected),
&productCalendar.CalendarSelected,
&productCalendar.InWorkAt,
&productCalendar.OutWorkAt,
&productCalendar.BreakTime,
... ... @@ -104,19 +96,17 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
&productCalendar.DeletedAt,
),
fmt.Sprintf("UPDATE product_calendars SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
productCalendar.ProductCalendarId,
productCalendar.CompanyId,
productCalendar.OrgId,
productCalendar.WorkStation,
productCalendar.WorkOn,
pg.Array(productCalendar.CalendarSelected),
productCalendar.CalendarSelected,
productCalendar.InWorkAt,
productCalendar.OutWorkAt,
productCalendar.BreakTime,
productCalendar.WorkTime,
productCalendar.CreatedAt,
productCalendar.UpdatedAt,
productCalendar.DeletedAt,
productCalendar.Identify(),
); err != nil {
return productCalendar, err
... ...
... ... @@ -139,6 +139,14 @@ func (repository *ProductRepository) Find(queryOptions map[string]interface{}) (
var productModels []*models.Product
products := make([]*domain.Product, 0)
query := sqlbuilder.BuildQuery(tx.Model(&productModels), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
if v, ok := queryOptions["productName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_name like '%%%v%%'`, v))
}
if v, ok := queryOptions["productCategory"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_category like '%%%v%%'`, v))
}
query.SetOffsetAndLimit(20)
query.SetOrderDirect("product_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
... ... @@ -38,19 +38,13 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
"updated_at",
"deleted_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "unit_conversion_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "unit_conversion_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "unitConversion_id")
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "unit_conversion_id", "deleted_at")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if unitConversion.Identify() == nil {
unitConversionId, err := repository.nextIdentify()
if err != nil {
return unitConversion, err
} else {
unitConversion.UnitConversionId = int(unitConversionId)
}
if _, err := tx.QueryOne(
pg.Scan(
&unitConversion.UnitConversionId,
... ... @@ -65,8 +59,7 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
&unitConversion.UpdatedAt,
&unitConversion.DeletedAt,
),
fmt.Sprintf("INSERT INTO unit_conversions (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
unitConversion.UnitConversionId,
fmt.Sprintf("INSERT INTO manufacture.unit_conversion (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
unitConversion.CompanyId,
unitConversion.OrgId,
unitConversion.WorkStation,
... ... @@ -76,7 +69,6 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
unitConversion.IntelligentWeighingFlag,
unitConversion.CreatedAt,
unitConversion.UpdatedAt,
unitConversion.DeletedAt,
); err != nil {
return unitConversion, err
}
... ... @@ -95,8 +87,7 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
&unitConversion.UpdatedAt,
&unitConversion.DeletedAt,
),
fmt.Sprintf("UPDATE unit_conversions SET %s WHERE unit_conversion_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
unitConversion.UnitConversionId,
fmt.Sprintf("UPDATE manufacture.unit_conversion SET %s WHERE unit_conversion_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
unitConversion.CompanyId,
unitConversion.OrgId,
unitConversion.WorkStation,
... ... @@ -106,7 +97,6 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
unitConversion.IntelligentWeighingFlag,
unitConversion.CreatedAt,
unitConversion.UpdatedAt,
unitConversion.DeletedAt,
unitConversion.Identify(),
); err != nil {
return unitConversion, err
... ... @@ -146,7 +136,13 @@ func (repository *UnitConversionRepository) Find(queryOptions map[string]interfa
var unitConversionModels []*models.UnitConversion
unitConversions := make([]*domain.UnitConversion, 0)
query := sqlbuilder.BuildQuery(tx.Model(&unitConversionModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("intelligent_weighing_flag = ?", "intelligentWeighingFlag")
if v, ok := queryOptions["materialName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`material->>'materialName' like '%%%v%%'`, v))
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("unit_conversion_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, unitConversions, err
... ...
... ... @@ -15,7 +15,7 @@ func (controller *DeviceController) CreateDevice() {
deviceService := service.NewDeviceService(nil)
createDeviceCommand := &command.CreateDeviceCommand{}
controller.Unmarshal(createDeviceCommand)
data, err := deviceService.CreateDevice(createDeviceCommand)
data, err := deviceService.CreateDevice(ParseOperateInfo(controller.BaseController), createDeviceCommand)
controller.Response(data, err)
}
... ... @@ -58,3 +58,11 @@ func (controller *DeviceController) ListDevice() {
data, err := deviceService.ListDevice(listDeviceQuery)
controller.Response(data, err)
}
func (controller *DeviceController) SearchDevice() {
deviceService := service.NewDeviceService(nil)
listDeviceQuery := &query.SearchDeviceQuery{}
controller.Unmarshal(listDeviceQuery)
total, data, err := deviceService.SearchDevice(ParseOperateInfo(controller.BaseController), listDeviceQuery)
ResponseGrid(controller.BaseController, total, data, err)
}
... ...
... ... @@ -14,8 +14,8 @@ type UnitConversionController struct {
func (controller *UnitConversionController) CreateUnitConversion() {
unitConversionService := service.NewUnitConversionService(nil)
createUnitConversionCommand := &command.CreateUnitConversionCommand{}
controller.Unmarshal(createUnitConversionCommand)
data, err := unitConversionService.CreateUnitConversion(createUnitConversionCommand)
Must(controller.Unmarshal(createUnitConversionCommand))
data, err := unitConversionService.CreateUnitConversion(ParseOperateInfo(controller.BaseController), createUnitConversionCommand)
controller.Response(data, err)
}
... ... @@ -58,3 +58,11 @@ func (controller *UnitConversionController) ListUnitConversion() {
data, err := unitConversionService.ListUnitConversion(listUnitConversionQuery)
controller.Response(data, err)
}
func (controller *UnitConversionController) SearchUnitConversion() {
unitConversionService := service.NewUnitConversionService(nil)
listUnitConversionQuery := &query.SearchUnitConversionQuery{}
controller.Unmarshal(listUnitConversionQuery)
total, data, err := unitConversionService.SearchUnitConversion(ParseOperateInfo(controller.BaseController), listUnitConversionQuery)
ResponseGrid(controller.BaseController, total, data, err)
}
... ...
... ... @@ -11,4 +11,5 @@ func init() {
web.Router("/devices/:deviceId", &controllers.DeviceController{}, "Get:GetDevice")
web.Router("/devices/:deviceId", &controllers.DeviceController{}, "Delete:RemoveDevice")
web.Router("/devices/", &controllers.DeviceController{}, "Get:ListDevice")
web.Router("/devices/search", &controllers.DeviceController{}, "Post:SearchDevice")
}
... ...
... ... @@ -11,4 +11,5 @@ func init() {
web.Router("/unit-conversions/:unitConversionId", &controllers.UnitConversionController{}, "Get:GetUnitConversion")
web.Router("/unit-conversions/:unitConversionId", &controllers.UnitConversionController{}, "Delete:RemoveUnitConversion")
web.Router("/unit-conversions/", &controllers.UnitConversionController{}, "Get:ListUnitConversion")
web.Router("/unit-conversions/search", &controllers.UnitConversionController{}, "Post:SearchUnitConversion")
}
... ...