...
|
...
|
@@ -363,6 +363,67 @@ func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo |
|
|
return count, result, nil
|
|
|
}
|
|
|
|
|
|
// 返回设备服务列表
|
|
|
func (deviceService *DeviceService) SelectorDeviceUnbounded(operateInfo *domain.OperateInfo, listDeviceQuery *query.SearchDeviceQuery) (int64, interface{}, error) {
|
|
|
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())
|
|
|
}
|
|
|
workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
|
|
|
|
|
|
productJobRepository, _, _ := factory.FastPgProductJob(transactionContext, 0)
|
|
|
_, productJobs, _ := productJobRepository.Find(map[string]interface{}{"companyId": listDeviceQuery.CompanyId})
|
|
|
var excludeMap = make(map[int]int)
|
|
|
var allBoundedDevice = make([]int, 0)
|
|
|
for i := range productJobs {
|
|
|
allBoundedDevice = append(allBoundedDevice, productJobs[i].RelatedDevices...)
|
|
|
}
|
|
|
for _, v := range allBoundedDevice {
|
|
|
exclude := false
|
|
|
for _, j := range listDeviceQuery.IncludeDevices {
|
|
|
if j == v {
|
|
|
exclude = true
|
|
|
}
|
|
|
}
|
|
|
if exclude {
|
|
|
continue
|
|
|
}
|
|
|
excludeMap[v] = v
|
|
|
}
|
|
|
var result = make([]*dto.DeviceDto, 0)
|
|
|
for i := range devices {
|
|
|
item := devices[i]
|
|
|
newJobDto := &dto.DeviceDto{}
|
|
|
if _, ok := excludeMap[item.DeviceId]; ok {
|
|
|
continue
|
|
|
}
|
|
|
if item.WorkStation != nil && item.WorkStation.WorkshopId > 0 {
|
|
|
newJobDto.WorkStation = workshops.FindWorkStationOrNil(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
|
|
|
}
|
|
|
newJobDto.LoadDto(item, operateInfo.OrgId)
|
|
|
result = append(result, newJobDto)
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return count, result, nil
|
|
|
}
|
|
|
|
|
|
// 批量添加产品服务
|
|
|
func (deviceService *DeviceService) BatchAddProduct(opt *domain.OperateInfo, list []*domain.ImportDeviceItem) ([]interface{}, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
|