作者 yangfu

设备管理修改

@@ -36,7 +36,7 @@ type CreateDeviceCommand struct { @@ -36,7 +36,7 @@ type CreateDeviceCommand struct {
36 } 36 }
37 37
38 func (createDeviceCommand *CreateDeviceCommand) Valid(validation *validation.Validation) { 38 func (createDeviceCommand *CreateDeviceCommand) Valid(validation *validation.Validation) {
39 - validation.SetError("CustomValid", "未实现的自定义认证") 39 + //validation.SetError("CustomValid", "未实现的自定义认证")
40 } 40 }
41 41
42 func (createDeviceCommand *CreateDeviceCommand) ValidateCommand() error { 42 func (createDeviceCommand *CreateDeviceCommand) ValidateCommand() error {
@@ -14,7 +14,7 @@ type RemoveDeviceCommand struct { @@ -14,7 +14,7 @@ type RemoveDeviceCommand struct {
14 } 14 }
15 15
16 func (removeDeviceCommand *RemoveDeviceCommand) Valid(validation *validation.Validation) { 16 func (removeDeviceCommand *RemoveDeviceCommand) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (removeDeviceCommand *RemoveDeviceCommand) ValidateCommand() error { 20 func (removeDeviceCommand *RemoveDeviceCommand) ValidateCommand() error {
@@ -34,7 +34,7 @@ type UpdateDeviceCommand struct { @@ -34,7 +34,7 @@ type UpdateDeviceCommand struct {
34 } 34 }
35 35
36 func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) { 36 func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) {
37 - validation.SetError("CustomValid", "未实现的自定义认证") 37 + //validation.SetError("CustomValid", "未实现的自定义认证")
38 } 38 }
39 39
40 func (updateDeviceCommand *UpdateDeviceCommand) ValidateCommand() error { 40 func (updateDeviceCommand *UpdateDeviceCommand) ValidateCommand() error {
  1 +package dto
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 +)
  6 +
  7 +type DeviceDto struct {
  8 + // 设备Id
  9 + DeviceId int `json:"deviceId,omitempty"`
  10 + // 设备编号
  11 + DeviceCode string `json:"deviceCode,omitempty"`
  12 + // 设备名称
  13 + DeviceName string `json:"deviceName,omitempty"`
  14 + // 设备型号
  15 + DeviceModel string `json:"deviceModel,omitempty"`
  16 + // 设备类型
  17 + DeviceType string `json:"deviceType,omitempty"`
  18 + // 品牌
  19 + Brand string `json:"brand,omitempty"`
  20 + // 设备状态 1:正常 2:封存 3:报废
  21 + DeviceStatus int `json:"deviceStatus,omitempty"`
  22 + // 风险等级 1:高 2:中 3:低
  23 + RiskLevel int `json:"riskLevel,omitempty"`
  24 + // 所属位置
  25 + *domain.WorkStation
  26 +}
  27 +
  28 +func (d *DeviceDto) LoadDto(m *domain.Device) *DeviceDto {
  29 + d.DeviceId = m.DeviceId
  30 + d.DeviceCode = m.DeviceCode
  31 + d.DeviceName = m.DeviceName
  32 + d.DeviceType = m.DeviceType
  33 + d.Brand = m.Brand
  34 + d.DeviceStatus = m.DeviceStatus
  35 + d.RiskLevel = m.RiskLevel
  36 + d.WorkStation = m.WorkStation
  37 + return d
  38 +}
@@ -14,7 +14,7 @@ type GetDeviceQuery struct { @@ -14,7 +14,7 @@ type GetDeviceQuery struct {
14 } 14 }
15 15
16 func (getDeviceQuery *GetDeviceQuery) Valid(validation *validation.Validation) { 16 func (getDeviceQuery *GetDeviceQuery) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (getDeviceQuery *GetDeviceQuery) ValidateQuery() error { 20 func (getDeviceQuery *GetDeviceQuery) ValidateQuery() error {
@@ -10,13 +10,13 @@ import ( @@ -10,13 +10,13 @@ import (
10 10
11 type ListDeviceQuery struct { 11 type ListDeviceQuery struct {
12 // 查询偏离量 12 // 查询偏离量
13 - Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` 13 + Offset int `cname:"查询偏离量" json:"offset"`
14 // 查询限制 14 // 查询限制
15 Limit int `cname:"查询限制" json:"limit" valid:"Required"` 15 Limit int `cname:"查询限制" json:"limit" valid:"Required"`
16 } 16 }
17 17
18 func (listDeviceQuery *ListDeviceQuery) Valid(validation *validation.Validation) { 18 func (listDeviceQuery *ListDeviceQuery) Valid(validation *validation.Validation) {
19 - validation.SetError("CustomValid", "未实现的自定义认证") 19 + //validation.SetError("CustomValid", "未实现的自定义认证")
20 } 20 }
21 21
22 func (listDeviceQuery *ListDeviceQuery) ValidateQuery() error { 22 func (listDeviceQuery *ListDeviceQuery) ValidateQuery() error {
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type SearchDeviceQuery struct {
  13 + // 查询偏离量
  14 + Offset int `cname:"查询偏离量" json:"offset"`
  15 + // 查询限制
  16 + Limit int `cname:"查询限制" json:"limit"`
  17 + // 当前公司
  18 + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
  19 + // 当前登录的组织
  20 + OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" valid:"Required"`
  21 + // 页码
  22 + PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
  23 + // 页数
  24 + PageSize int `cname:"页数" json:"pageSize,omitempty"`
  25 + // 设备名称
  26 + DeviceName string `json:"deviceName,omitempty"`
  27 + // 设备状态 1:正常 2:封存 3:报废
  28 + DeviceStatus int `json:"deviceStatus,omitempty"`
  29 +}
  30 +
  31 +func (cmd *SearchDeviceQuery) Valid(validation *validation.Validation) {
  32 + cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
  33 +}
  34 +
  35 +func (cmd *SearchDeviceQuery) ValidateQuery() error {
  36 + valid := validation.Validation{}
  37 + b, err := valid.Valid(cmd)
  38 + if err != nil {
  39 + return err
  40 + }
  41 + if !b {
  42 + elem := reflect.TypeOf(cmd).Elem()
  43 + for _, validErr := range valid.Errors {
  44 + field, isExist := elem.FieldByName(validErr.Field)
  45 + if isExist {
  46 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  47 + } else {
  48 + return fmt.Errorf(validErr.Message)
  49 + }
  50 + }
  51 + }
  52 + return nil
  53 +}
@@ -5,9 +5,12 @@ import ( @@ -5,9 +5,12 @@ import (
5 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
6 "github.com/linmadan/egglib-go/utils/tool_funs" 6 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/command" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/dto"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/query" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/query"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  13 + "time"
11 ) 14 )
12 15
13 // 设备服务 16 // 设备服务
@@ -15,8 +18,10 @@ type DeviceService struct { @@ -15,8 +18,10 @@ type DeviceService struct {
15 } 18 }
16 19
17 // 创建设备服务 20 // 创建设备服务
18 -func (deviceService *DeviceService) CreateDevice(createDeviceCommand *command.CreateDeviceCommand) (interface{}, error) {  
19 - if err := createDeviceCommand.ValidateCommand(); err != nil { 21 +func (deviceService *DeviceService) CreateDevice(operateInfo *domain.OperateInfo, cmd *command.CreateDeviceCommand) (interface{}, error) {
  22 + cmd.OrgId = operateInfo.OrgId
  23 + cmd.CompanyId = operateInfo.CompanyId
  24 + if err := cmd.ValidateCommand(); err != nil {
20 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 25 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
21 } 26 }
22 transactionContext, err := factory.CreateTransactionContext(nil) 27 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -29,27 +34,40 @@ func (deviceService *DeviceService) CreateDevice(createDeviceCommand *command.Cr @@ -29,27 +34,40 @@ func (deviceService *DeviceService) CreateDevice(createDeviceCommand *command.Cr
29 defer func() { 34 defer func() {
30 transactionContext.RollbackTransaction() 35 transactionContext.RollbackTransaction()
31 }() 36 }()
  37 +
  38 + var workStation *domain.WorkStation
  39 + _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
  40 + if err != nil {
  41 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  42 + }
  43 +
32 newDevice := &domain.Device{ 44 newDevice := &domain.Device{
33 - CompanyId: createDeviceCommand.CompanyId,  
34 - OrgId: createDeviceCommand.OrgId,  
35 - DeviceCode: createDeviceCommand.DeviceCode,  
36 - DeviceName: createDeviceCommand.DeviceName,  
37 - DeviceModel: createDeviceCommand.DeviceModel,  
38 - DeviceType: createDeviceCommand.DeviceType,  
39 - //WorkshopId: createDeviceCommand.WorkshopId,  
40 - //LineId: createDeviceCommand.LineId,  
41 - //SectionId: createDeviceCommand.SectionId,  
42 - Brand: createDeviceCommand.Brand,  
43 - DeviceStatus: createDeviceCommand.DeviceStatus,  
44 - RiskLevel: createDeviceCommand.RiskLevel, 45 + CompanyId: cmd.CompanyId,
  46 + OrgId: cmd.OrgId,
  47 + DeviceCode: cmd.DeviceCode,
  48 + DeviceName: cmd.DeviceName,
  49 + DeviceModel: cmd.DeviceModel,
  50 + DeviceType: cmd.DeviceType,
  51 + WorkStation: workStation,
  52 + Brand: cmd.Brand,
  53 + DeviceStatus: cmd.DeviceStatus,
  54 + RiskLevel: cmd.RiskLevel,
  55 + CreatedAt: time.Now(),
  56 + UpdatedAt: time.Now(),
  57 + }
  58 + deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
  59 +
  60 + if total, _, err := deviceRepository.Find(map[string]interface{}{
  61 + "deviceCode": cmd.DeviceCode,
  62 + "companyId": cmd.CompanyId,
  63 + "orgId": cmd.OrgId,
  64 + "limit": 1,
  65 + }); err == nil && total > 0 {
  66 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "设备编号重复")
45 } 67 }
46 - var deviceRepository domain.DeviceRepository  
47 - if value, err := factory.CreateDeviceRepository(map[string]interface{}{  
48 - "transactionContext": transactionContext,  
49 - }); err != nil { 68 +
  69 + if err := newDevice.Valid(); err != nil {
50 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 70 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
51 - } else {  
52 - deviceRepository = value  
53 } 71 }
54 if device, err := deviceRepository.Save(newDevice); err != nil { 72 if device, err := deviceRepository.Save(newDevice); err != nil {
55 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 73 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -94,7 +112,10 @@ func (deviceService *DeviceService) GetDevice(getDeviceQuery *query.GetDeviceQue @@ -94,7 +112,10 @@ func (deviceService *DeviceService) GetDevice(getDeviceQuery *query.GetDeviceQue
94 if err := transactionContext.CommitTransaction(); err != nil { 112 if err := transactionContext.CommitTransaction(); err != nil {
95 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 113 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
96 } 114 }
97 - return device, nil 115 +
  116 + result := &dto.DeviceDto{}
  117 + result.LoadDto(device)
  118 + return result, nil
98 } 119 }
99 } 120 }
100 121
@@ -175,8 +196,8 @@ func (deviceService *DeviceService) RemoveDevice(removeDeviceCommand *command.Re @@ -175,8 +196,8 @@ func (deviceService *DeviceService) RemoveDevice(removeDeviceCommand *command.Re
175 } 196 }
176 197
177 // 更新设备服务 198 // 更新设备服务
178 -func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.UpdateDeviceCommand) (interface{}, error) {  
179 - if err := updateDeviceCommand.ValidateCommand(); err != nil { 199 +func (deviceService *DeviceService) UpdateDevice(cmd *command.UpdateDeviceCommand) (interface{}, error) {
  200 + if err := cmd.ValidateCommand(); err != nil {
180 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 201 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
181 } 202 }
182 transactionContext, err := factory.CreateTransactionContext(nil) 203 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -190,23 +211,35 @@ func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.Up @@ -190,23 +211,35 @@ func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.Up
190 transactionContext.RollbackTransaction() 211 transactionContext.RollbackTransaction()
191 }() 212 }()
192 var deviceRepository domain.DeviceRepository 213 var deviceRepository domain.DeviceRepository
193 - if value, err := factory.CreateDeviceRepository(map[string]interface{}{  
194 - "transactionContext": transactionContext,  
195 - }); err != nil { 214 + var device *domain.Device
  215 + deviceRepository, device, err = factory.FastPgDevice(transactionContext, cmd.DeviceId)
  216 + if err != nil {
196 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 217 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
197 - } else {  
198 - deviceRepository = value  
199 } 218 }
200 - device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": updateDeviceCommand.DeviceId}) 219 +
  220 + var workStation *domain.WorkStation
  221 + _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
201 if err != nil { 222 if err != nil {
202 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 223 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
203 } 224 }
204 - if device == nil {  
205 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDeviceCommand.DeviceId))) 225 + device.WorkStation = workStation
  226 +
  227 + if cmd.DeviceCode != device.DeviceCode {
  228 + if total, _, err := deviceRepository.Find(map[string]interface{}{
  229 + "deviceCode": cmd.DeviceCode,
  230 + "companyId": device.CompanyId,
  231 + "orgId": device.OrgId,
  232 + "limit": 1,
  233 + }); err == nil && total > 0 {
  234 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "设备编号重复")
  235 + }
206 } 236 }
207 - if err := device.Update(tool_funs.SimpleStructToMap(updateDeviceCommand)); err != nil { 237 + if err := device.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
208 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 238 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
209 } 239 }
  240 + if err := device.Valid(); err != nil {
  241 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  242 + }
210 if device, err := deviceRepository.Save(device); err != nil { 243 if device, err := deviceRepository.Save(device); err != nil {
211 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 244 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
212 } else { 245 } else {
@@ -217,6 +250,43 @@ func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.Up @@ -217,6 +250,43 @@ func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.Up
217 } 250 }
218 } 251 }
219 252
  253 +// 返回设备服务列表
  254 +func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo, listDeviceQuery *query.SearchDeviceQuery) (int64, interface{}, error) {
  255 + listDeviceQuery.OrgId = operateInfo.OrgId
  256 + listDeviceQuery.CompanyId = operateInfo.CompanyId
  257 + if err := listDeviceQuery.ValidateQuery(); err != nil {
  258 + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
  259 + }
  260 + transactionContext, err := factory.CreateTransactionContext(nil)
  261 + if err != nil {
  262 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  263 + }
  264 + if err := transactionContext.StartTransaction(); err != nil {
  265 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  266 + }
  267 + defer func() {
  268 + transactionContext.RollbackTransaction()
  269 + }()
  270 + deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0)
  271 + count, devices, err := deviceRepository.Find(utils.ObjectToMap(listDeviceQuery))
  272 + if err != nil {
  273 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  274 + }
  275 +
  276 + if err := transactionContext.CommitTransaction(); err != nil {
  277 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  278 + }
  279 +
  280 + var result = make([]*dto.DeviceDto, 0)
  281 + for i := range devices {
  282 + item := devices[i]
  283 + newJobDto := &dto.DeviceDto{}
  284 + newJobDto.LoadDto(item)
  285 + result = append(result, newJobDto)
  286 + }
  287 + return count, result, nil
  288 +}
  289 +
220 func NewDeviceService(options map[string]interface{}) *DeviceService { 290 func NewDeviceService(options map[string]interface{}) *DeviceService {
221 newDeviceService := &DeviceService{} 291 newDeviceService := &DeviceService{}
222 return newDeviceService 292 return newDeviceService
@@ -2,6 +2,7 @@ package command @@ -2,6 +2,7 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
5 "reflect" 6 "reflect"
6 "strings" 7 "strings"
7 8
@@ -20,23 +21,17 @@ type CreateUnitConversionCommand struct { @@ -20,23 +21,17 @@ type CreateUnitConversionCommand struct {
20 // 工段ID 21 // 工段ID
21 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` 22 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
22 // 物料名称 23 // 物料名称
23 - MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`  
24 - // 物料类别  
25 - MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`  
26 - // 数量(保留两位小数)  
27 - Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`  
28 - // 单位  
29 - Unit string `cname:"单位" json:"unit" valid:"Required"`  
30 - // 单份重量(原材料)  
31 - UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`  
32 - // 重量  
33 - Weight float64 `cname:"重量" json:"weight" valid:"Required"` 24 + Material *domain.Material `cname:"物料" json:"material" valid:"Required"`
  25 + // 转换前单位数量
  26 + FromUnitQuantity *domain.UnitQuantity `cname:"转换前单位数量" json:"fromUnitQuantity,omitempty"`
  27 + // 转换后单位数量
  28 + ToUnitQuantity *domain.UnitQuantity `cname:"转换后单位数量" json:"toUnitQuantity,omitempty"`
34 // 智能称重标识 29 // 智能称重标识
35 - IntelligentWeighingFlag bool `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"` 30 + IntelligentWeighingFlag int `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
36 } 31 }
37 32
38 func (createUnitConversionCommand *CreateUnitConversionCommand) Valid(validation *validation.Validation) { 33 func (createUnitConversionCommand *CreateUnitConversionCommand) Valid(validation *validation.Validation) {
39 - validation.SetError("CustomValid", "未实现的自定义认证") 34 + //validation.SetError("CustomValid", "未实现的自定义认证")
40 } 35 }
41 36
42 func (createUnitConversionCommand *CreateUnitConversionCommand) ValidateCommand() error { 37 func (createUnitConversionCommand *CreateUnitConversionCommand) ValidateCommand() error {
@@ -14,7 +14,7 @@ type RemoveUnitConversionCommand struct { @@ -14,7 +14,7 @@ type RemoveUnitConversionCommand struct {
14 } 14 }
15 15
16 func (removeUnitConversionCommand *RemoveUnitConversionCommand) Valid(validation *validation.Validation) { 16 func (removeUnitConversionCommand *RemoveUnitConversionCommand) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (removeUnitConversionCommand *RemoveUnitConversionCommand) ValidateCommand() error { 20 func (removeUnitConversionCommand *RemoveUnitConversionCommand) ValidateCommand() error {
@@ -2,6 +2,7 @@ package command @@ -2,6 +2,7 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
5 "reflect" 6 "reflect"
6 "strings" 7 "strings"
7 8
@@ -11,10 +12,6 @@ import ( @@ -11,10 +12,6 @@ import (
11 type UpdateUnitConversionCommand struct { 12 type UpdateUnitConversionCommand struct {
12 // 单位换算ID 13 // 单位换算ID
13 UnitConversionId int `cname:"单位换算ID" json:"unitConversionId" valid:"Required"` 14 UnitConversionId int `cname:"单位换算ID" json:"unitConversionId" valid:"Required"`
14 - // 企业id  
15 - CompanyId int `cname:"企业id" json:"companyId,omitempty"`  
16 - // 组织ID  
17 - OrgId int `cname:"组织ID" json:"orgId,omitempty"`  
18 // 车间ID 15 // 车间ID
19 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` 16 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
20 // 生产线ID 17 // 生产线ID
@@ -22,23 +19,17 @@ type UpdateUnitConversionCommand struct { @@ -22,23 +19,17 @@ type UpdateUnitConversionCommand struct {
22 // 工段ID 19 // 工段ID
23 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` 20 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
24 // 物料名称 21 // 物料名称
25 - MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`  
26 - // 物料类别  
27 - MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`  
28 - // 数量(保留两位小数)  
29 - Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`  
30 - // 单位  
31 - Unit string `cname:"单位" json:"unit" valid:"Required"`  
32 - // 单份重量(原材料)  
33 - UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`  
34 - // 重量  
35 - Weight float64 `cname:"重量" json:"weight" valid:"Required"` 22 + Material *domain.Material `cname:"物料" json:"material" valid:"Required"`
  23 + // 转换前单位数量
  24 + FromUnitQuantity *domain.UnitQuantity `cname:"转换前单位数量" json:"fromUnitQuantity,omitempty"`
  25 + // 转换后单位数量
  26 + ToUnitQuantity *domain.UnitQuantity `cname:"转换后单位数量" json:"toUnitQuantity,omitempty"`
36 // 智能称重标识 27 // 智能称重标识
37 - IntelligentWeighingFlag bool `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"` 28 + IntelligentWeighingFlag int `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
38 } 29 }
39 30
40 func (updateUnitConversionCommand *UpdateUnitConversionCommand) Valid(validation *validation.Validation) { 31 func (updateUnitConversionCommand *UpdateUnitConversionCommand) Valid(validation *validation.Validation) {
41 - validation.SetError("CustomValid", "未实现的自定义认证") 32 + //validation.SetError("CustomValid", "未实现的自定义认证")
42 } 33 }
43 34
44 func (updateUnitConversionCommand *UpdateUnitConversionCommand) ValidateCommand() error { 35 func (updateUnitConversionCommand *UpdateUnitConversionCommand) ValidateCommand() error {
  1 +package dto
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  4 +
  5 +type UnitConversionDto struct {
  6 + // 单位换算ID
  7 + UnitConversionId int `json:"unitConversionId,omitempty"`
  8 + // 企业id
  9 + //CompanyId int `json:"companyId,omitempty"`
  10 + // 组织ID
  11 + //OrgId int `json:"orgId,omitempty"`
  12 + // 工作位置
  13 + *domain.WorkStation `json:"workStation,omitempty"`
  14 + // material
  15 + *domain.Material `json:"material,omitempty"`
  16 + // 转换前单位数量
  17 + FromUnitQuantity *domain.UnitQuantity `json:"fromUnitQuantity,omitempty"`
  18 + // 转换后单位数量
  19 + ToUnitQuantity *domain.UnitQuantity `json:"toUnitQuantity,omitempty"`
  20 + // 智能称重标识 1:是 2:否
  21 + IntelligentWeighingFlag int `json:"intelligentWeighingFlag,omitempty"`
  22 +}
  23 +
  24 +func (d *UnitConversionDto) LoadDto(m *domain.UnitConversion) *UnitConversionDto {
  25 + d.UnitConversionId = m.UnitConversionId
  26 + d.WorkStation = m.WorkStation
  27 + d.Material = m.Material
  28 + d.FromUnitQuantity = m.FromUnitQuantity
  29 + d.ToUnitQuantity = m.ToUnitQuantity
  30 + d.IntelligentWeighingFlag = m.IntelligentWeighingFlag
  31 + return d
  32 +}
@@ -14,7 +14,7 @@ type GetUnitConversionQuery struct { @@ -14,7 +14,7 @@ type GetUnitConversionQuery struct {
14 } 14 }
15 15
16 func (getUnitConversionQuery *GetUnitConversionQuery) Valid(validation *validation.Validation) { 16 func (getUnitConversionQuery *GetUnitConversionQuery) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (getUnitConversionQuery *GetUnitConversionQuery) ValidateQuery() error { 20 func (getUnitConversionQuery *GetUnitConversionQuery) ValidateQuery() error {
@@ -10,13 +10,13 @@ import ( @@ -10,13 +10,13 @@ import (
10 10
11 type ListUnitConversionQuery struct { 11 type ListUnitConversionQuery struct {
12 // 查询偏离量 12 // 查询偏离量
13 - Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` 13 + Offset int `cname:"查询偏离量" json:"offset"`
14 // 查询限制 14 // 查询限制
15 Limit int `cname:"查询限制" json:"limit" valid:"Required"` 15 Limit int `cname:"查询限制" json:"limit" valid:"Required"`
16 } 16 }
17 17
18 func (listUnitConversionQuery *ListUnitConversionQuery) Valid(validation *validation.Validation) { 18 func (listUnitConversionQuery *ListUnitConversionQuery) Valid(validation *validation.Validation) {
19 - validation.SetError("CustomValid", "未实现的自定义认证") 19 + //validation.SetError("CustomValid", "未实现的自定义认证")
20 } 20 }
21 21
22 func (listUnitConversionQuery *ListUnitConversionQuery) ValidateQuery() error { 22 func (listUnitConversionQuery *ListUnitConversionQuery) ValidateQuery() error {
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type SearchUnitConversionQuery struct {
  13 + // 查询偏离量
  14 + Offset int `cname:"查询偏离量" json:"offset"`
  15 + // 查询限制
  16 + Limit int `cname:"查询限制" json:"limit"`
  17 + // 当前公司
  18 + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
  19 + // 当前登录的组织
  20 + OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" valid:"Required"`
  21 + // 页码
  22 + PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
  23 + // 页数
  24 + PageSize int `cname:"页数" json:"pageSize,omitempty"`
  25 + // 物料名称
  26 + MaterialName string `cname:"物料名称" json:"materialName"`
  27 + // 智能称重标识 0:全部 1:是 2:否
  28 + IntelligentWeighingFlag int `cname:"智能称重标识" json:"intelligentWeighingFlag"`
  29 +}
  30 +
  31 +func (cmd *SearchUnitConversionQuery) Valid(validation *validation.Validation) {
  32 + cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
  33 +}
  34 +
  35 +func (cmd *SearchUnitConversionQuery) ValidateQuery() error {
  36 + valid := validation.Validation{}
  37 + b, err := valid.Valid(cmd)
  38 + if err != nil {
  39 + return err
  40 + }
  41 + if !b {
  42 + elem := reflect.TypeOf(cmd).Elem()
  43 + for _, validErr := range valid.Errors {
  44 + field, isExist := elem.FieldByName(validErr.Field)
  45 + if isExist {
  46 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  47 + } else {
  48 + return fmt.Errorf(validErr.Message)
  49 + }
  50 + }
  51 + }
  52 + return nil
  53 +}
@@ -6,8 +6,11 @@ import ( @@ -6,8 +6,11 @@ import (
6 "github.com/linmadan/egglib-go/utils/tool_funs" 6 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/command" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/dto"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/query" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/query"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  13 + "time"
11 ) 14 )
12 15
13 // 单位换算服务 16 // 单位换算服务
@@ -15,8 +18,10 @@ type UnitConversionService struct { @@ -15,8 +18,10 @@ type UnitConversionService struct {
15 } 18 }
16 19
17 // 创建单位换算服务 20 // 创建单位换算服务
18 -func (unitConversionService *UnitConversionService) CreateUnitConversion(createUnitConversionCommand *command.CreateUnitConversionCommand) (interface{}, error) {  
19 - if err := createUnitConversionCommand.ValidateCommand(); err != nil { 21 +func (unitConversionService *UnitConversionService) CreateUnitConversion(operateInfo *domain.OperateInfo, cmd *command.CreateUnitConversionCommand) (interface{}, error) {
  22 + cmd.CompanyId = operateInfo.CompanyId
  23 + cmd.OrgId = operateInfo.OrgId
  24 + if err := cmd.ValidateCommand(); err != nil {
20 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 25 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
21 } 26 }
22 transactionContext, err := factory.CreateTransactionContext(nil) 27 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -29,25 +34,26 @@ func (unitConversionService *UnitConversionService) CreateUnitConversion(createU @@ -29,25 +34,26 @@ func (unitConversionService *UnitConversionService) CreateUnitConversion(createU
29 defer func() { 34 defer func() {
30 transactionContext.RollbackTransaction() 35 transactionContext.RollbackTransaction()
31 }() 36 }()
32 - newUnitConversion := &domain.UnitConversion{  
33 - CompanyId: createUnitConversionCommand.CompanyId,  
34 - OrgId: createUnitConversionCommand.OrgId,  
35 - //WorkshopId: createUnitConversionCommand.WorkshopId,  
36 - //LineId: createUnitConversionCommand.LineId,  
37 - //SectionId: createUnitConversionCommand.SectionId,  
38 - //Material: createUnitConversionCommand.Material,  
39 - //FromUnitQuantity: createUnitConversionCommand.FromUnitQuantity,  
40 - //ToUnitQuantity: createUnitConversionCommand.ToUnitQuantity,  
41 - IntelligentWeighingFlag: createUnitConversionCommand.IntelligentWeighingFlag,  
42 - }  
43 - var unitConversionRepository domain.UnitConversionRepository  
44 - if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{  
45 - "transactionContext": transactionContext,  
46 - }); err != nil { 37 +
  38 + var workStation *domain.WorkStation
  39 + _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
  40 + if err != nil {
47 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 41 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
48 - } else {  
49 - unitConversionRepository = value  
50 } 42 }
  43 +
  44 + newUnitConversion := &domain.UnitConversion{
  45 + CompanyId: cmd.CompanyId,
  46 + OrgId: cmd.OrgId,
  47 + Material: cmd.Material,
  48 + FromUnitQuantity: cmd.FromUnitQuantity,
  49 + ToUnitQuantity: cmd.ToUnitQuantity,
  50 + IntelligentWeighingFlag: cmd.IntelligentWeighingFlag,
  51 + WorkStation: workStation,
  52 + CreatedAt: time.Now(),
  53 + UpdatedAt: time.Now(),
  54 + }
  55 + unitConversionRepository, _, _ := factory.FastPgUnitConversion(transactionContext, 0)
  56 +
51 if unitConversion, err := unitConversionRepository.Save(newUnitConversion); err != nil { 57 if unitConversion, err := unitConversionRepository.Save(newUnitConversion); err != nil {
52 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 58 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
53 } else { 59 } else {
@@ -73,26 +79,17 @@ func (unitConversionService *UnitConversionService) GetUnitConversion(getUnitCon @@ -73,26 +79,17 @@ func (unitConversionService *UnitConversionService) GetUnitConversion(getUnitCon
73 defer func() { 79 defer func() {
74 transactionContext.RollbackTransaction() 80 transactionContext.RollbackTransaction()
75 }() 81 }()
76 - var unitConversionRepository domain.UnitConversionRepository  
77 - if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{  
78 - "transactionContext": transactionContext,  
79 - }); err != nil {  
80 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
81 - } else {  
82 - unitConversionRepository = value  
83 - }  
84 - unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": getUnitConversionQuery.UnitConversionId})  
85 - if err != nil {  
86 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
87 - }  
88 - if unitConversion == nil {  
89 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getUnitConversionQuery.UnitConversionId)))  
90 - } else {  
91 - if err := transactionContext.CommitTransaction(); err != nil {  
92 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
93 - }  
94 - return unitConversion, nil 82 + //var unitConversionRepository domain.UnitConversionRepository
  83 + var unitConversion *domain.UnitConversion
  84 + _, unitConversion, err = factory.FastPgUnitConversion(transactionContext, getUnitConversionQuery.UnitConversionId)
  85 +
  86 + if err := transactionContext.CommitTransaction(); err != nil {
  87 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
95 } 88 }
  89 + result := &dto.UnitConversionDto{}
  90 + result.LoadDto(unitConversion)
  91 + return result, nil
  92 +
96 } 93 }
97 94
98 // 返回单位换算服务列表 95 // 返回单位换算服务列表
@@ -172,8 +169,8 @@ func (unitConversionService *UnitConversionService) RemoveUnitConversion(removeU @@ -172,8 +169,8 @@ func (unitConversionService *UnitConversionService) RemoveUnitConversion(removeU
172 } 169 }
173 170
174 // 更新单位换算服务 171 // 更新单位换算服务
175 -func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateUnitConversionCommand *command.UpdateUnitConversionCommand) (interface{}, error) {  
176 - if err := updateUnitConversionCommand.ValidateCommand(); err != nil { 172 +func (unitConversionService *UnitConversionService) UpdateUnitConversion(cmd *command.UpdateUnitConversionCommand) (interface{}, error) {
  173 + if err := cmd.ValidateCommand(); err != nil {
177 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 174 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
178 } 175 }
179 transactionContext, err := factory.CreateTransactionContext(nil) 176 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -187,21 +184,21 @@ func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateU @@ -187,21 +184,21 @@ func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateU
187 transactionContext.RollbackTransaction() 184 transactionContext.RollbackTransaction()
188 }() 185 }()
189 var unitConversionRepository domain.UnitConversionRepository 186 var unitConversionRepository domain.UnitConversionRepository
190 - if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{  
191 - "transactionContext": transactionContext,  
192 - }); err != nil {  
193 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
194 - } else {  
195 - unitConversionRepository = value  
196 - }  
197 - unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": updateUnitConversionCommand.UnitConversionId}) 187 + var unitConversion *domain.UnitConversion
  188 + unitConversionRepository, unitConversion, err = factory.FastPgUnitConversion(transactionContext, cmd.UnitConversionId)
  189 +
  190 + var workStation *domain.WorkStation
  191 + _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
198 if err != nil { 192 if err != nil {
199 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 193 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
200 } 194 }
201 - if unitConversion == nil {  
202 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateUnitConversionCommand.UnitConversionId)))  
203 - }  
204 - if err := unitConversion.Update(tool_funs.SimpleStructToMap(updateUnitConversionCommand)); err != nil { 195 + unitConversion.WorkStation = workStation
  196 + unitConversion.Material = cmd.Material
  197 + unitConversion.FromUnitQuantity = cmd.FromUnitQuantity
  198 + unitConversion.ToUnitQuantity = cmd.ToUnitQuantity
  199 + unitConversion.IntelligentWeighingFlag = cmd.IntelligentWeighingFlag
  200 +
  201 + if err := unitConversion.Update(utils.ObjectToMap(cmd)); err != nil {
205 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 202 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
206 } 203 }
207 if unitConversion, err := unitConversionRepository.Save(unitConversion); err != nil { 204 if unitConversion, err := unitConversionRepository.Save(unitConversion); err != nil {
@@ -214,6 +211,42 @@ func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateU @@ -214,6 +211,42 @@ func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateU
214 } 211 }
215 } 212 }
216 213
  214 +// 返回单位换算服务列表
  215 +func (unitConversionService *UnitConversionService) SearchUnitConversion(operateInfo *domain.OperateInfo, listUnitConversionQuery *query.SearchUnitConversionQuery) (int64, interface{}, error) {
  216 + listUnitConversionQuery.OrgId = operateInfo.OrgId
  217 + listUnitConversionQuery.CompanyId = operateInfo.CompanyId
  218 + if err := listUnitConversionQuery.ValidateQuery(); err != nil {
  219 + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
  220 + }
  221 + transactionContext, err := factory.CreateTransactionContext(nil)
  222 + if err != nil {
  223 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  224 + }
  225 + if err := transactionContext.StartTransaction(); err != nil {
  226 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  227 + }
  228 + defer func() {
  229 + transactionContext.RollbackTransaction()
  230 + }()
  231 + unitConversionRepository, _, _ := factory.FastPgUnitConversion(transactionContext, 0)
  232 + count, unitConversions, err := unitConversionRepository.Find(utils.ObjectToMap(listUnitConversionQuery))
  233 + if err != nil {
  234 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  235 + }
  236 + if err := transactionContext.CommitTransaction(); err != nil {
  237 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  238 + }
  239 +
  240 + var result = make([]*dto.UnitConversionDto, 0)
  241 + for i := range unitConversions {
  242 + item := unitConversions[i]
  243 + newItem := &dto.UnitConversionDto{}
  244 + newItem.LoadDto(item)
  245 + result = append(result, newItem)
  246 + }
  247 + return count, result, nil
  248 +}
  249 +
217 func NewUnitConversionService(options map[string]interface{}) *UnitConversionService { 250 func NewUnitConversionService(options map[string]interface{}) *UnitConversionService {
218 newUnitConversionService := &UnitConversionService{} 251 newUnitConversionService := &UnitConversionService{}
219 return newUnitConversionService 252 return newUnitConversionService
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "fmt"
  5 + "time"
  6 +)
  7 +
  8 +// 风险等级
  9 +const (
  10 + RiskLevelHigh = 1 // 1:高
  11 + RiskLevelMiddle = 2 // 2:中
  12 + RiskLevelLow = 3 // 3:低
  13 +)
  14 +
  15 +const (
  16 + DeviceStatusNormal = 1 // 1:正常
  17 + DeviceStatusArchive = 2 // 2:封存
  18 + DeviceStatusScrapped = 3 // 3:报废
  19 +)
4 20
5 // 设备 21 // 设备
6 type Device struct { 22 type Device struct {
@@ -49,12 +65,6 @@ func (device *Device) Identify() interface{} { @@ -49,12 +65,6 @@ func (device *Device) Identify() interface{} {
49 } 65 }
50 66
51 func (device *Device) Update(data map[string]interface{}) error { 67 func (device *Device) Update(data map[string]interface{}) error {
52 - if companyId, ok := data["companyId"]; ok {  
53 - device.CompanyId = companyId.(int)  
54 - }  
55 - if orgId, ok := data["orgId"]; ok {  
56 - device.OrgId = orgId.(int)  
57 - }  
58 if deviceCode, ok := data["deviceCode"]; ok { 68 if deviceCode, ok := data["deviceCode"]; ok {
59 device.DeviceCode = deviceCode.(string) 69 device.DeviceCode = deviceCode.(string)
60 } 70 }
@@ -76,35 +86,16 @@ func (device *Device) Update(data map[string]interface{}) error { @@ -76,35 +86,16 @@ func (device *Device) Update(data map[string]interface{}) error {
76 if riskLevel, ok := data["riskLevel"]; ok { 86 if riskLevel, ok := data["riskLevel"]; ok {
77 device.RiskLevel = riskLevel.(int) 87 device.RiskLevel = riskLevel.(int)
78 } 88 }
79 - if createdAt, ok := data["createdAt"]; ok {  
80 - device.CreatedAt = createdAt.(time.Time)  
81 - }  
82 - if updatedAt, ok := data["updatedAt"]; ok {  
83 - device.UpdatedAt = updatedAt.(time.Time)  
84 - }  
85 - if deletedAt, ok := data["deletedAt"]; ok {  
86 - device.DeletedAt = deletedAt.(time.Time)  
87 - }  
88 - if workStationId, ok := data["workStationId"]; ok {  
89 - device.WorkStation.WorkStationId = workStationId.(string)  
90 - }  
91 - if workshopId, ok := data["workshopId"]; ok {  
92 - device.WorkStation.WorkshopId = workshopId.(int)  
93 - }  
94 - if workshopName, ok := data["workshopName"]; ok {  
95 - device.WorkStation.WorkshopName = workshopName.(string)  
96 - }  
97 - if lineId, ok := data["lineId"]; ok {  
98 - device.WorkStation.LineId = lineId.(int)  
99 - }  
100 - if lineName, ok := data["lineName"]; ok {  
101 - device.WorkStation.LineName = lineName.(string)  
102 - }  
103 - if sectionId, ok := data["sectionId"]; ok {  
104 - device.WorkStation.SectionId = sectionId.(int) 89 + device.UpdatedAt = time.Now()
  90 + return nil
  91 +}
  92 +
  93 +func (device *Device) Valid() error {
  94 + if !(device.RiskLevel == RiskLevelHigh || device.RiskLevel == RiskLevelMiddle || device.RiskLevel == RiskLevelLow) {
  95 + return fmt.Errorf("风险等级参数有误")
105 } 96 }
106 - if sectionName, ok := data["sectionName"]; ok {  
107 - device.WorkStation.SectionName = sectionName.(string) 97 + if !(device.DeviceStatus == DeviceStatusNormal || device.DeviceStatus == DeviceStatusArchive || device.DeviceStatus == DeviceStatusScrapped) {
  98 + return fmt.Errorf("设备状态参数有误")
108 } 99 }
109 return nil 100 return nil
110 } 101 }
@@ -4,6 +4,7 @@ import "fmt" @@ -4,6 +4,7 @@ import "fmt"
4 4
5 const MaxQueryRow = 10000 5 const MaxQueryRow = 10000
6 6
  7 +// 班次
7 const ( 8 const (
8 WorkOnFullDay = 1 //全天 9 WorkOnFullDay = 1 //全天
9 WorkOnDay = 2 //白班 10 WorkOnDay = 2 //白班
@@ -18,8 +18,8 @@ type UnitConversion struct { @@ -18,8 +18,8 @@ type UnitConversion struct {
18 FromUnitQuantity *UnitQuantity `json:"fromUnitQuantity,omitempty"` 18 FromUnitQuantity *UnitQuantity `json:"fromUnitQuantity,omitempty"`
19 // 转换后单位数量 19 // 转换后单位数量
20 ToUnitQuantity *UnitQuantity `json:"toUnitQuantity,omitempty"` 20 ToUnitQuantity *UnitQuantity `json:"toUnitQuantity,omitempty"`
21 - // 智能称重标识  
22 - IntelligentWeighingFlag bool `json:"intelligentWeighingFlag,omitempty"` 21 + // 智能称重标识 1:是 2:否
  22 + IntelligentWeighingFlag int `json:"intelligentWeighingFlag,omitempty"`
23 // 创建时间 23 // 创建时间
24 CreatedAt time.Time `json:"createdAt,omitempty"` 24 CreatedAt time.Time `json:"createdAt,omitempty"`
25 // 更新时间 25 // 更新时间
@@ -43,77 +43,15 @@ func (unitConversion *UnitConversion) Identify() interface{} { @@ -43,77 +43,15 @@ func (unitConversion *UnitConversion) Identify() interface{} {
43 } 43 }
44 44
45 func (unitConversion *UnitConversion) Update(data map[string]interface{}) error { 45 func (unitConversion *UnitConversion) Update(data map[string]interface{}) error {
46 - if unitConversionId, ok := data["unitConversionId"]; ok {  
47 - unitConversion.UnitConversionId = unitConversionId.(int)  
48 - }  
49 - if companyId, ok := data["companyId"]; ok {  
50 - unitConversion.CompanyId = companyId.(int)  
51 - }  
52 - if orgId, ok := data["orgId"]; ok {  
53 - unitConversion.OrgId = orgId.(int)  
54 - }  
55 - if workStationId, ok := data["workStationId"]; ok {  
56 - unitConversion.WorkStation.WorkStationId = workStationId.(string)  
57 - }  
58 - if workshopId, ok := data["workshopId"]; ok {  
59 - unitConversion.WorkStation.WorkshopId = workshopId.(int)  
60 - }  
61 - if workshopName, ok := data["workshopName"]; ok {  
62 - unitConversion.WorkStation.WorkshopName = workshopName.(string)  
63 - }  
64 - if lineId, ok := data["lineId"]; ok {  
65 - unitConversion.WorkStation.LineId = lineId.(int)  
66 - }  
67 - if lineName, ok := data["lineName"]; ok {  
68 - unitConversion.WorkStation.LineName = lineName.(string)  
69 - }  
70 - if sectionId, ok := data["sectionId"]; ok {  
71 - unitConversion.WorkStation.SectionId = sectionId.(int)  
72 - }  
73 - if sectionName, ok := data["sectionName"]; ok {  
74 - unitConversion.WorkStation.SectionName = sectionName.(string)  
75 - }  
76 - if materialName, ok := data["materialName"]; ok {  
77 - unitConversion.Material.MaterialName = materialName.(string)  
78 - }  
79 - if materialCategory, ok := data["materialCategory"]; ok {  
80 - unitConversion.Material.MaterialCategory = materialCategory.(string)  
81 - }  
82 - if quantity, ok := data["quantity"]; ok {  
83 - unitConversion.FromUnitQuantity.Quantity = quantity.(float64)  
84 - }  
85 - if unit, ok := data["unit"]; ok {  
86 - unitConversion.FromUnitQuantity.Unit = unit.(string)  
87 - }  
88 - if unitWeight, ok := data["unitWeight"]; ok {  
89 - unitConversion.FromUnitQuantity.UnitWeight = unitWeight.(float64)  
90 - }  
91 - if weight, ok := data["weight"]; ok {  
92 - unitConversion.FromUnitQuantity.Weight = weight.(float64)  
93 - }  
94 - //if quantity, ok := data["quantity"]; ok {  
95 - // unitConversion.ToUnitQuantity.FromUnitQuantity.Quantity = quantity.(float64) 46 + //if materialName, ok := data["materialName"]; ok {
  47 + // unitConversion.Material.MaterialName = materialName.(string)
96 //} 48 //}
97 - //if unit, ok := data["unit"]; ok {  
98 - // unitConversion.ToUnitQuantity.FromUnitQuantity.Unit = unit.(string)  
99 - //}  
100 - //if unitWeight, ok := data["unitWeight"]; ok {  
101 - // unitConversion.ToUnitQuantity.FromUnitQuantity.UnitWeight = unitWeight.(float64)  
102 - //}  
103 - //if weight, ok := data["weight"]; ok {  
104 - // unitConversion.ToUnitQuantity.FromUnitQuantity.Weight = weight.(float64) 49 + //if materialCategory, ok := data["materialCategory"]; ok {
  50 + // unitConversion.Material.MaterialCategory = materialCategory.(string)
105 //} 51 //}
106 //if intelligentWeighingFlag, ok := data["intelligentWeighingFlag"]; ok { 52 //if intelligentWeighingFlag, ok := data["intelligentWeighingFlag"]; ok {
107 - // unitConversion.IntelligentWeighingFlag = intelligentWeighingFlag.(boolean) 53 + // unitConversion.IntelligentWeighingFlag = intelligentWeighingFlag.(bool)
108 //} 54 //}
109 - if createdAt, ok := data["createdAt"]; ok {  
110 - unitConversion.CreatedAt = createdAt.(time.Time)  
111 - }  
112 - if updatedAt, ok := data["updatedAt"]; ok {  
113 - unitConversion.UpdatedAt = updatedAt.(time.Time)  
114 - }  
115 - if deletedAt, ok := data["deletedAt"]; ok {  
116 - unitConversion.DeletedAt = deletedAt.(time.Time)  
117 - } 55 + unitConversion.UpdatedAt = time.Now()
118 return nil 56 return nil
119 } 57 }
@@ -21,8 +21,8 @@ type UnitConversion struct { @@ -21,8 +21,8 @@ type UnitConversion struct {
21 FromUnitQuantity *domain.UnitQuantity `comment:"转换前单位数量"` 21 FromUnitQuantity *domain.UnitQuantity `comment:"转换前单位数量"`
22 // 转换后单位数量 22 // 转换后单位数量
23 ToUnitQuantity *domain.UnitQuantity `comment:"转换后单位数量"` 23 ToUnitQuantity *domain.UnitQuantity `comment:"转换后单位数量"`
24 - // 智能称重标识  
25 - IntelligentWeighingFlag bool `comment:"智能称重标识"` 24 + // 智能称重标识 1:是 2:否
  25 + IntelligentWeighingFlag int `comment:"智能称重标识 1:是 2:否"`
26 // 创建时间 26 // 创建时间
27 CreatedAt time.Time `comment:"创建时间"` 27 CreatedAt time.Time `comment:"创建时间"`
28 // 更新时间 28 // 更新时间
@@ -41,19 +41,13 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device, @@ -41,19 +41,13 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
41 "deleted_at", 41 "deleted_at",
42 "work_station", 42 "work_station",
43 } 43 }
44 - insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)  
45 - insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) 44 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_id", "deleted_at"))
  45 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_id", "deleted_at"))
46 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 46 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
47 - updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_id") 47 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "device_id", "deleted_at")
48 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) 48 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
49 tx := repository.transactionContext.PgTx 49 tx := repository.transactionContext.PgTx
50 if device.Identify() == nil { 50 if device.Identify() == nil {
51 - deviceId, err := repository.nextIdentify()  
52 - if err != nil {  
53 - return device, err  
54 - } else {  
55 - device.DeviceId = int(deviceId)  
56 - }  
57 if _, err := tx.QueryOne( 51 if _, err := tx.QueryOne(
58 pg.Scan( 52 pg.Scan(
59 &device.DeviceId, 53 &device.DeviceId,
@@ -71,8 +65,8 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device, @@ -71,8 +65,8 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
71 &device.DeletedAt, 65 &device.DeletedAt,
72 &device.WorkStation, 66 &device.WorkStation,
73 ), 67 ),
74 - fmt.Sprintf("INSERT INTO devices (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),  
75 - device.DeviceId, 68 + fmt.Sprintf("INSERT INTO manufacture.device (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  69 + //device.DeviceId,
76 device.CompanyId, 70 device.CompanyId,
77 device.OrgId, 71 device.OrgId,
78 device.DeviceCode, 72 device.DeviceCode,
@@ -84,7 +78,7 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device, @@ -84,7 +78,7 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
84 device.RiskLevel, 78 device.RiskLevel,
85 device.CreatedAt, 79 device.CreatedAt,
86 device.UpdatedAt, 80 device.UpdatedAt,
87 - device.DeletedAt, 81 + //device.DeletedAt,
88 device.WorkStation, 82 device.WorkStation,
89 ); err != nil { 83 ); err != nil {
90 return device, err 84 return device, err
@@ -107,8 +101,7 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device, @@ -107,8 +101,7 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
107 &device.DeletedAt, 101 &device.DeletedAt,
108 &device.WorkStation, 102 &device.WorkStation,
109 ), 103 ),
110 - fmt.Sprintf("UPDATE devices SET %s WHERE device_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),  
111 - device.DeviceId, 104 + fmt.Sprintf("UPDATE manufacture.device SET %s WHERE device_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
112 device.CompanyId, 105 device.CompanyId,
113 device.OrgId, 106 device.OrgId,
114 device.DeviceCode, 107 device.DeviceCode,
@@ -120,7 +113,6 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device, @@ -120,7 +113,6 @@ func (repository *DeviceRepository) Save(device *domain.Device) (*domain.Device,
120 device.RiskLevel, 113 device.RiskLevel,
121 device.CreatedAt, 114 device.CreatedAt,
122 device.UpdatedAt, 115 device.UpdatedAt,
123 - device.DeletedAt,  
124 device.WorkStation, 116 device.WorkStation,
125 device.Identify(), 117 device.Identify(),
126 ); err != nil { 118 ); err != nil {
@@ -142,7 +134,10 @@ func (repository *DeviceRepository) FindOne(queryOptions map[string]interface{}) @@ -142,7 +134,10 @@ func (repository *DeviceRepository) FindOne(queryOptions map[string]interface{})
142 tx := repository.transactionContext.PgTx 134 tx := repository.transactionContext.PgTx
143 deviceModel := new(models.Device) 135 deviceModel := new(models.Device)
144 query := sqlbuilder.BuildQuery(tx.Model(deviceModel), queryOptions) 136 query := sqlbuilder.BuildQuery(tx.Model(deviceModel), queryOptions)
145 - query.SetWhereByQueryOption("device.device_id = ?", "deviceId") 137 + query.SetWhereByQueryOption("device_id = ?", "deviceId")
  138 + query.SetWhereByQueryOption("company_id = ?", "companyId")
  139 + query.SetWhereByQueryOption("org_id = ?", "orgId")
  140 + query.SetWhereByQueryOption("device_code = ?", "deviceCode")
146 if err := query.First(); err != nil { 141 if err := query.First(); err != nil {
147 if err.Error() == "pg: no rows in result set" { 142 if err.Error() == "pg: no rows in result set" {
148 return nil, fmt.Errorf("没有此资源") 143 return nil, fmt.Errorf("没有此资源")
@@ -163,6 +158,13 @@ func (repository *DeviceRepository) Find(queryOptions map[string]interface{}) (i @@ -163,6 +158,13 @@ func (repository *DeviceRepository) Find(queryOptions map[string]interface{}) (i
163 query := sqlbuilder.BuildQuery(tx.Model(&deviceModels), queryOptions) 158 query := sqlbuilder.BuildQuery(tx.Model(&deviceModels), queryOptions)
164 query.SetOffsetAndLimit(20) 159 query.SetOffsetAndLimit(20)
165 query.SetOrderDirect("device_id", "DESC") 160 query.SetOrderDirect("device_id", "DESC")
  161 + query.SetWhereByQueryOption("company_id = ?", "companyId")
  162 + query.SetWhereByQueryOption("org_id = ?", "orgId")
  163 + query.SetWhereByQueryOption("device_code = ?", "deviceCode")
  164 + query.SetWhereByQueryOption("device_status = ?", "deviceStatus")
  165 + if v, ok := queryOptions["deviceName"]; ok && len(v.(string)) > 0 {
  166 + query.Where(fmt.Sprintf(`device_name like '%%%v%%'`, v))
  167 + }
166 if count, err := query.SelectAndCount(); err != nil { 168 if count, err := query.SelectAndCount(); err != nil {
167 return 0, devices, err 169 return 0, devices, err
168 } else { 170 } else {
@@ -40,19 +40,13 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc @@ -40,19 +40,13 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
40 "updated_at", 40 "updated_at",
41 "deleted_at", 41 "deleted_at",
42 } 42 }
43 - insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)  
44 - insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) 43 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at"))
  44 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at"))
45 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 45 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
46 - updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "productCalendar_id") 46 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")
47 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) 47 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
48 tx := repository.transactionContext.PgTx 48 tx := repository.transactionContext.PgTx
49 if productCalendar.Identify() == nil { 49 if productCalendar.Identify() == nil {
50 - productCalendarId, err := repository.nextIdentify()  
51 - if err != nil {  
52 - return productCalendar, err  
53 - } else {  
54 - productCalendar.ProductCalendarId = int(productCalendarId)  
55 - }  
56 if _, err := tx.QueryOne( 50 if _, err := tx.QueryOne(
57 pg.Scan( 51 pg.Scan(
58 &productCalendar.ProductCalendarId, 52 &productCalendar.ProductCalendarId,
@@ -60,7 +54,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc @@ -60,7 +54,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
60 &productCalendar.OrgId, 54 &productCalendar.OrgId,
61 &productCalendar.WorkStation, 55 &productCalendar.WorkStation,
62 &productCalendar.WorkOn, 56 &productCalendar.WorkOn,
63 - pg.Array(&productCalendar.CalendarSelected), 57 + &productCalendar.CalendarSelected,
64 &productCalendar.InWorkAt, 58 &productCalendar.InWorkAt,
65 &productCalendar.OutWorkAt, 59 &productCalendar.OutWorkAt,
66 &productCalendar.BreakTime, 60 &productCalendar.BreakTime,
@@ -70,19 +64,17 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc @@ -70,19 +64,17 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
70 &productCalendar.DeletedAt, 64 &productCalendar.DeletedAt,
71 ), 65 ),
72 fmt.Sprintf("INSERT INTO product_calendars (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), 66 fmt.Sprintf("INSERT INTO product_calendars (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
73 - productCalendar.ProductCalendarId,  
74 productCalendar.CompanyId, 67 productCalendar.CompanyId,
75 productCalendar.OrgId, 68 productCalendar.OrgId,
76 productCalendar.WorkStation, 69 productCalendar.WorkStation,
77 productCalendar.WorkOn, 70 productCalendar.WorkOn,
78 - pg.Array(productCalendar.CalendarSelected), 71 + productCalendar.CalendarSelected,
79 productCalendar.InWorkAt, 72 productCalendar.InWorkAt,
80 productCalendar.OutWorkAt, 73 productCalendar.OutWorkAt,
81 productCalendar.BreakTime, 74 productCalendar.BreakTime,
82 productCalendar.WorkTime, 75 productCalendar.WorkTime,
83 productCalendar.CreatedAt, 76 productCalendar.CreatedAt,
84 productCalendar.UpdatedAt, 77 productCalendar.UpdatedAt,
85 - productCalendar.DeletedAt,  
86 ); err != nil { 78 ); err != nil {
87 return productCalendar, err 79 return productCalendar, err
88 } 80 }
@@ -94,7 +86,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc @@ -94,7 +86,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
94 &productCalendar.OrgId, 86 &productCalendar.OrgId,
95 &productCalendar.WorkStation, 87 &productCalendar.WorkStation,
96 &productCalendar.WorkOn, 88 &productCalendar.WorkOn,
97 - pg.Array(&productCalendar.CalendarSelected), 89 + &productCalendar.CalendarSelected,
98 &productCalendar.InWorkAt, 90 &productCalendar.InWorkAt,
99 &productCalendar.OutWorkAt, 91 &productCalendar.OutWorkAt,
100 &productCalendar.BreakTime, 92 &productCalendar.BreakTime,
@@ -104,19 +96,17 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc @@ -104,19 +96,17 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
104 &productCalendar.DeletedAt, 96 &productCalendar.DeletedAt,
105 ), 97 ),
106 fmt.Sprintf("UPDATE product_calendars SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 98 fmt.Sprintf("UPDATE product_calendars SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
107 - productCalendar.ProductCalendarId,  
108 productCalendar.CompanyId, 99 productCalendar.CompanyId,
109 productCalendar.OrgId, 100 productCalendar.OrgId,
110 productCalendar.WorkStation, 101 productCalendar.WorkStation,
111 productCalendar.WorkOn, 102 productCalendar.WorkOn,
112 - pg.Array(productCalendar.CalendarSelected), 103 + productCalendar.CalendarSelected,
113 productCalendar.InWorkAt, 104 productCalendar.InWorkAt,
114 productCalendar.OutWorkAt, 105 productCalendar.OutWorkAt,
115 productCalendar.BreakTime, 106 productCalendar.BreakTime,
116 productCalendar.WorkTime, 107 productCalendar.WorkTime,
117 productCalendar.CreatedAt, 108 productCalendar.CreatedAt,
118 productCalendar.UpdatedAt, 109 productCalendar.UpdatedAt,
119 - productCalendar.DeletedAt,  
120 productCalendar.Identify(), 110 productCalendar.Identify(),
121 ); err != nil { 111 ); err != nil {
122 return productCalendar, err 112 return productCalendar, err
@@ -139,6 +139,14 @@ func (repository *ProductRepository) Find(queryOptions map[string]interface{}) ( @@ -139,6 +139,14 @@ func (repository *ProductRepository) Find(queryOptions map[string]interface{}) (
139 var productModels []*models.Product 139 var productModels []*models.Product
140 products := make([]*domain.Product, 0) 140 products := make([]*domain.Product, 0)
141 query := sqlbuilder.BuildQuery(tx.Model(&productModels), queryOptions) 141 query := sqlbuilder.BuildQuery(tx.Model(&productModels), queryOptions)
  142 + query.SetWhereByQueryOption("company_id = ?", "companyId")
  143 + query.SetWhereByQueryOption("org_id = ?", "orgId")
  144 + if v, ok := queryOptions["productName"]; ok && len(v.(string)) > 0 {
  145 + query.Where(fmt.Sprintf(`product_name like '%%%v%%'`, v))
  146 + }
  147 + if v, ok := queryOptions["productCategory"]; ok && len(v.(string)) > 0 {
  148 + query.Where(fmt.Sprintf(`product_category like '%%%v%%'`, v))
  149 + }
142 query.SetOffsetAndLimit(20) 150 query.SetOffsetAndLimit(20)
143 query.SetOrderDirect("product_id", "DESC") 151 query.SetOrderDirect("product_id", "DESC")
144 if count, err := query.SelectAndCount(); err != nil { 152 if count, err := query.SelectAndCount(); err != nil {
@@ -38,19 +38,13 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv @@ -38,19 +38,13 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
38 "updated_at", 38 "updated_at",
39 "deleted_at", 39 "deleted_at",
40 } 40 }
41 - insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)  
42 - insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) 41 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "unit_conversion_id", "deleted_at"))
  42 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "unit_conversion_id", "deleted_at"))
43 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 43 returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
44 - updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "unitConversion_id") 44 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "unit_conversion_id", "deleted_at")
45 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) 45 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
46 tx := repository.transactionContext.PgTx 46 tx := repository.transactionContext.PgTx
47 if unitConversion.Identify() == nil { 47 if unitConversion.Identify() == nil {
48 - unitConversionId, err := repository.nextIdentify()  
49 - if err != nil {  
50 - return unitConversion, err  
51 - } else {  
52 - unitConversion.UnitConversionId = int(unitConversionId)  
53 - }  
54 if _, err := tx.QueryOne( 48 if _, err := tx.QueryOne(
55 pg.Scan( 49 pg.Scan(
56 &unitConversion.UnitConversionId, 50 &unitConversion.UnitConversionId,
@@ -65,8 +59,7 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv @@ -65,8 +59,7 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
65 &unitConversion.UpdatedAt, 59 &unitConversion.UpdatedAt,
66 &unitConversion.DeletedAt, 60 &unitConversion.DeletedAt,
67 ), 61 ),
68 - fmt.Sprintf("INSERT INTO unit_conversions (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),  
69 - unitConversion.UnitConversionId, 62 + fmt.Sprintf("INSERT INTO manufacture.unit_conversion (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
70 unitConversion.CompanyId, 63 unitConversion.CompanyId,
71 unitConversion.OrgId, 64 unitConversion.OrgId,
72 unitConversion.WorkStation, 65 unitConversion.WorkStation,
@@ -76,7 +69,6 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv @@ -76,7 +69,6 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
76 unitConversion.IntelligentWeighingFlag, 69 unitConversion.IntelligentWeighingFlag,
77 unitConversion.CreatedAt, 70 unitConversion.CreatedAt,
78 unitConversion.UpdatedAt, 71 unitConversion.UpdatedAt,
79 - unitConversion.DeletedAt,  
80 ); err != nil { 72 ); err != nil {
81 return unitConversion, err 73 return unitConversion, err
82 } 74 }
@@ -95,8 +87,7 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv @@ -95,8 +87,7 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
95 &unitConversion.UpdatedAt, 87 &unitConversion.UpdatedAt,
96 &unitConversion.DeletedAt, 88 &unitConversion.DeletedAt,
97 ), 89 ),
98 - fmt.Sprintf("UPDATE unit_conversions SET %s WHERE unit_conversion_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),  
99 - unitConversion.UnitConversionId, 90 + fmt.Sprintf("UPDATE manufacture.unit_conversion SET %s WHERE unit_conversion_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
100 unitConversion.CompanyId, 91 unitConversion.CompanyId,
101 unitConversion.OrgId, 92 unitConversion.OrgId,
102 unitConversion.WorkStation, 93 unitConversion.WorkStation,
@@ -106,7 +97,6 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv @@ -106,7 +97,6 @@ func (repository *UnitConversionRepository) Save(unitConversion *domain.UnitConv
106 unitConversion.IntelligentWeighingFlag, 97 unitConversion.IntelligentWeighingFlag,
107 unitConversion.CreatedAt, 98 unitConversion.CreatedAt,
108 unitConversion.UpdatedAt, 99 unitConversion.UpdatedAt,
109 - unitConversion.DeletedAt,  
110 unitConversion.Identify(), 100 unitConversion.Identify(),
111 ); err != nil { 101 ); err != nil {
112 return unitConversion, err 102 return unitConversion, err
@@ -146,7 +136,13 @@ func (repository *UnitConversionRepository) Find(queryOptions map[string]interfa @@ -146,7 +136,13 @@ func (repository *UnitConversionRepository) Find(queryOptions map[string]interfa
146 var unitConversionModels []*models.UnitConversion 136 var unitConversionModels []*models.UnitConversion
147 unitConversions := make([]*domain.UnitConversion, 0) 137 unitConversions := make([]*domain.UnitConversion, 0)
148 query := sqlbuilder.BuildQuery(tx.Model(&unitConversionModels), queryOptions) 138 query := sqlbuilder.BuildQuery(tx.Model(&unitConversionModels), queryOptions)
149 - query.SetOffsetAndLimit(20) 139 + query.SetWhereByQueryOption("company_id = ?", "companyId")
  140 + query.SetWhereByQueryOption("org_id = ?", "orgId")
  141 + query.SetWhereByQueryOption("intelligent_weighing_flag = ?", "intelligentWeighingFlag")
  142 + if v, ok := queryOptions["materialName"]; ok && len(v.(string)) > 0 {
  143 + query.Where(fmt.Sprintf(`material->>'materialName' like '%%%v%%'`, v))
  144 + }
  145 + query.SetOffsetAndLimit(domain.MaxQueryRow)
150 query.SetOrderDirect("unit_conversion_id", "DESC") 146 query.SetOrderDirect("unit_conversion_id", "DESC")
151 if count, err := query.SelectAndCount(); err != nil { 147 if count, err := query.SelectAndCount(); err != nil {
152 return 0, unitConversions, err 148 return 0, unitConversions, err
@@ -15,7 +15,7 @@ func (controller *DeviceController) CreateDevice() { @@ -15,7 +15,7 @@ func (controller *DeviceController) CreateDevice() {
15 deviceService := service.NewDeviceService(nil) 15 deviceService := service.NewDeviceService(nil)
16 createDeviceCommand := &command.CreateDeviceCommand{} 16 createDeviceCommand := &command.CreateDeviceCommand{}
17 controller.Unmarshal(createDeviceCommand) 17 controller.Unmarshal(createDeviceCommand)
18 - data, err := deviceService.CreateDevice(createDeviceCommand) 18 + data, err := deviceService.CreateDevice(ParseOperateInfo(controller.BaseController), createDeviceCommand)
19 controller.Response(data, err) 19 controller.Response(data, err)
20 } 20 }
21 21
@@ -58,3 +58,11 @@ func (controller *DeviceController) ListDevice() { @@ -58,3 +58,11 @@ func (controller *DeviceController) ListDevice() {
58 data, err := deviceService.ListDevice(listDeviceQuery) 58 data, err := deviceService.ListDevice(listDeviceQuery)
59 controller.Response(data, err) 59 controller.Response(data, err)
60 } 60 }
  61 +
  62 +func (controller *DeviceController) SearchDevice() {
  63 + deviceService := service.NewDeviceService(nil)
  64 + listDeviceQuery := &query.SearchDeviceQuery{}
  65 + controller.Unmarshal(listDeviceQuery)
  66 + total, data, err := deviceService.SearchDevice(ParseOperateInfo(controller.BaseController), listDeviceQuery)
  67 + ResponseGrid(controller.BaseController, total, data, err)
  68 +}
@@ -14,8 +14,8 @@ type UnitConversionController struct { @@ -14,8 +14,8 @@ type UnitConversionController struct {
14 func (controller *UnitConversionController) CreateUnitConversion() { 14 func (controller *UnitConversionController) CreateUnitConversion() {
15 unitConversionService := service.NewUnitConversionService(nil) 15 unitConversionService := service.NewUnitConversionService(nil)
16 createUnitConversionCommand := &command.CreateUnitConversionCommand{} 16 createUnitConversionCommand := &command.CreateUnitConversionCommand{}
17 - controller.Unmarshal(createUnitConversionCommand)  
18 - data, err := unitConversionService.CreateUnitConversion(createUnitConversionCommand) 17 + Must(controller.Unmarshal(createUnitConversionCommand))
  18 + data, err := unitConversionService.CreateUnitConversion(ParseOperateInfo(controller.BaseController), createUnitConversionCommand)
19 controller.Response(data, err) 19 controller.Response(data, err)
20 } 20 }
21 21
@@ -58,3 +58,11 @@ func (controller *UnitConversionController) ListUnitConversion() { @@ -58,3 +58,11 @@ func (controller *UnitConversionController) ListUnitConversion() {
58 data, err := unitConversionService.ListUnitConversion(listUnitConversionQuery) 58 data, err := unitConversionService.ListUnitConversion(listUnitConversionQuery)
59 controller.Response(data, err) 59 controller.Response(data, err)
60 } 60 }
  61 +
  62 +func (controller *UnitConversionController) SearchUnitConversion() {
  63 + unitConversionService := service.NewUnitConversionService(nil)
  64 + listUnitConversionQuery := &query.SearchUnitConversionQuery{}
  65 + controller.Unmarshal(listUnitConversionQuery)
  66 + total, data, err := unitConversionService.SearchUnitConversion(ParseOperateInfo(controller.BaseController), listUnitConversionQuery)
  67 + ResponseGrid(controller.BaseController, total, data, err)
  68 +}
@@ -11,4 +11,5 @@ func init() { @@ -11,4 +11,5 @@ func init() {
11 web.Router("/devices/:deviceId", &controllers.DeviceController{}, "Get:GetDevice") 11 web.Router("/devices/:deviceId", &controllers.DeviceController{}, "Get:GetDevice")
12 web.Router("/devices/:deviceId", &controllers.DeviceController{}, "Delete:RemoveDevice") 12 web.Router("/devices/:deviceId", &controllers.DeviceController{}, "Delete:RemoveDevice")
13 web.Router("/devices/", &controllers.DeviceController{}, "Get:ListDevice") 13 web.Router("/devices/", &controllers.DeviceController{}, "Get:ListDevice")
  14 + web.Router("/devices/search", &controllers.DeviceController{}, "Post:SearchDevice")
14 } 15 }
@@ -11,4 +11,5 @@ func init() { @@ -11,4 +11,5 @@ func init() {
11 web.Router("/unit-conversions/:unitConversionId", &controllers.UnitConversionController{}, "Get:GetUnitConversion") 11 web.Router("/unit-conversions/:unitConversionId", &controllers.UnitConversionController{}, "Get:GetUnitConversion")
12 web.Router("/unit-conversions/:unitConversionId", &controllers.UnitConversionController{}, "Delete:RemoveUnitConversion") 12 web.Router("/unit-conversions/:unitConversionId", &controllers.UnitConversionController{}, "Delete:RemoveUnitConversion")
13 web.Router("/unit-conversions/", &controllers.UnitConversionController{}, "Get:ListUnitConversion") 13 web.Router("/unit-conversions/", &controllers.UnitConversionController{}, "Get:ListUnitConversion")
  14 + web.Router("/unit-conversions/search", &controllers.UnitConversionController{}, "Post:SearchUnitConversion")
14 } 15 }