|
|
|
@@ -33,6 +33,7 @@ import com.google.gson.JsonObject;
|
|
|
|
import com.influxdb.query.FluxRecord;
|
|
|
|
import com.influxdb.query.FluxRecord;
|
|
|
|
import com.influxdb.query.FluxTable;
|
|
|
|
import com.influxdb.query.FluxTable;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
@@ -140,13 +141,22 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void save(InspectionSheetDTO dto) {
|
|
|
|
public InspectionSheet saveSheet(InspectionSheetDTO dto) {
|
|
|
|
// 验证是否有检验参数
|
|
|
|
// 验证是否有检验参数
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
params.put("productId", dto.getProductId());
|
|
|
|
params.put("productId", dto.getProductId());
|
|
|
|
params.put("workingProcedureId", dto.getWorkingProcedureId());
|
|
|
|
params.put("workingProcedureId", dto.getWorkingProcedureId());
|
|
|
|
params.put("inspectionStage", dto.getInspectionStage());
|
|
|
|
params.put("inspectionStage", dto.getInspectionStage());
|
|
|
|
List<ProductFeaturesDTO> inspectionSheetFeaturesList = getInspectionSheetFeaturesList(params);
|
|
|
|
List<ProductFeaturesDTO> inspectionSheetFeaturesList = getInspectionSheetFeaturesList(params);
|
|
|
|
|
|
|
|
if (inspectionSheetFeaturesList != null && inspectionSheetFeaturesList.size() != 0) {
|
|
|
|
|
|
|
|
//分组样本数=样本大小=检验特性分组数的最大值
|
|
|
|
|
|
|
|
Integer numbersOfSamples = inspectionSheetFeaturesList.stream().max(Comparator.comparing(ProductFeaturesDTO::getSampleSize)).get().getSampleSize();
|
|
|
|
|
|
|
|
if (numbersOfSamples != null) {
|
|
|
|
|
|
|
|
dto.setNumberOfGroupedSamples(numbersOfSamples);
|
|
|
|
|
|
|
|
dto.setNumberOfSamples(numbersOfSamples);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (inspectionSheetFeaturesList == null || inspectionSheetFeaturesList.size() == 0) {
|
|
|
|
if (inspectionSheetFeaturesList == null || inspectionSheetFeaturesList.size() == 0) {
|
|
|
|
throw new RuntimeException("没有发现检验参数");
|
|
|
|
throw new RuntimeException("没有发现检验参数");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@@ -157,8 +167,11 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
|
|
|
dto.setNumberOfSamples(numbersOfSamples);
|
|
|
|
dto.setNumberOfSamples(numbersOfSamples);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InspectionSheet entity = ConvertUtils.sourceToTarget(dto, InspectionSheet.class);
|
|
|
|
*/
|
|
|
|
insert(entity);
|
|
|
|
//InspectionSheet entity = ConvertUtils.sourceToTarget(dto, InspectionSheet.class);
|
|
|
|
|
|
|
|
InspectionSheet entity = new InspectionSheet();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(dto, entity);
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@@ -210,9 +223,8 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
|
|
|
Instant time = fluxRecord.getTime();
|
|
|
|
Instant time = fluxRecord.getTime();
|
|
|
|
String argName = (String) fluxRecord.getValueByKey("argName");
|
|
|
|
String argName = (String) fluxRecord.getValueByKey("argName");
|
|
|
|
String argValue = (String)fluxRecord.getValueByKey("_value");
|
|
|
|
String argValue = (String)fluxRecord.getValueByKey("_value");
|
|
|
|
String batchNum = (String) fluxRecord.getValueByKey("batchNum");
|
|
|
|
|
|
|
|
String sampleNo = (String) fluxRecord.getValueByKey("sampleNumber");
|
|
|
|
String sampleNo = (String) fluxRecord.getValueByKey("sampleNumber");
|
|
|
|
eventList.add(newEvent(time, inspectionSheetId, argName, argValue, batchNum, sampleNo));
|
|
|
|
eventList.add(newEvent(time, inspectionSheetId, argName, argValue, sampleNo));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -227,7 +239,7 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
|
|
|
InspectionSampleDTO sampleDTO = new InspectionSampleDTO();
|
|
|
|
InspectionSampleDTO sampleDTO = new InspectionSampleDTO();
|
|
|
|
sampleDTO.setSampleNumber(sampleNumber);
|
|
|
|
sampleDTO.setSampleNumber(sampleNumber);
|
|
|
|
sampleDTO.setSampleTime(LocalDateTime.ofInstant(events.get(0).getTime(), ZoneId.systemDefault()));
|
|
|
|
sampleDTO.setSampleTime(LocalDateTime.ofInstant(events.get(0).getTime(), ZoneId.systemDefault()));
|
|
|
|
sampleDTO.setBatchNum(events.get(0).getBatchNum());
|
|
|
|
sampleDTO.setBatchNum(dto.getBatchNumber());
|
|
|
|
sampleDTO.setInspectionSheetId(events.get(0).getInspectionSheetId());
|
|
|
|
sampleDTO.setInspectionSheetId(events.get(0).getInspectionSheetId());
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
@@ -235,8 +247,8 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
|
|
|
jsonObject.put(event.getArgName(),event.getArgValue());
|
|
|
|
jsonObject.put(event.getArgName(),event.getArgValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sampleDTO.setJsonData(jsonObject.toString());
|
|
|
|
sampleDTO.setJsonData(jsonObject.toString());
|
|
|
|
|
|
|
|
//System.out.println(entry);
|
|
|
|
System.out.println(entry);
|
|
|
|
list.add(sampleDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
return list;
|
|
|
|
@@ -248,7 +260,7 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
|
|
|
//String jsonData = {"workingProcedureName":"test","inspectionSheetId":"116","param1":"0.47","param2":"0.687","param2":"0.53"};
|
|
|
|
//String jsonData = {"workingProcedureName":"test","inspectionSheetId":"116","param1":"0.47","param2":"0.687","param2":"0.53"};
|
|
|
|
String workingProcedureName = dto.getWorkingProcedureName();
|
|
|
|
String workingProcedureName = dto.getWorkingProcedureName();
|
|
|
|
String inspectionSheetId = dto.getInspectionSheetId();
|
|
|
|
String inspectionSheetId = dto.getInspectionSheetId();
|
|
|
|
String batchNum = dto.getBatchNum();
|
|
|
|
// String batchNum = dto.getBatchNum();
|
|
|
|
String sampleNumber = dto.getSampleNumber();
|
|
|
|
String sampleNumber = dto.getSampleNumber();
|
|
|
|
String jsonData = dto.getJsonData();
|
|
|
|
String jsonData = dto.getJsonData();
|
|
|
|
JSONObject json = JSON.parseObject(jsonData);
|
|
|
|
JSONObject json = JSON.parseObject(jsonData);
|
|
|
|
@@ -263,7 +275,7 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
|
|
|
// v= Double.valueOf(entry.getValue().toString());
|
|
|
|
// v= Double.valueOf(entry.getValue().toString());
|
|
|
|
// }catch (Exception e){
|
|
|
|
// }catch (Exception e){
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
list.add(newEvent(eventTime, inspectionSheetId, key, v, batchNum, sampleNumber));
|
|
|
|
list.add(newEvent(eventTime, inspectionSheetId, key, v, sampleNumber));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InfluxClient.Client.batchInsert(list, workingProcedureName);
|
|
|
|
InfluxClient.Client.batchInsert(list, workingProcedureName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -272,11 +284,11 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
|
|
|
// calculate(Long.valueOf(lists[0].getInspectionSheetId()));
|
|
|
|
// calculate(Long.valueOf(lists[0].getInspectionSheetId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Event newEvent(Instant time, String inspectionSheetId, String argName, String argValue, String batchNum, String sampleNo) {
|
|
|
|
private Event newEvent(Instant time, String inspectionSheetId, String argName, String argValue, String sampleNo) {
|
|
|
|
Event event = new Event();
|
|
|
|
Event event = new Event();
|
|
|
|
event.setInspectionSheetId(inspectionSheetId);
|
|
|
|
event.setInspectionSheetId(inspectionSheetId);
|
|
|
|
event.setTime(time);
|
|
|
|
event.setTime(time);
|
|
|
|
event.setBatchNum(batchNum);
|
|
|
|
// event.setBatchNum(batchNum);
|
|
|
|
event.setSampleNumber(sampleNo);
|
|
|
|
event.setSampleNumber(sampleNo);
|
|
|
|
event.setArgName(argName);
|
|
|
|
event.setArgName(argName);
|
|
|
|
event.setArgValue(argValue);
|
|
|
|
event.setArgValue(argValue);
|
|
|
|
|