MARK FOR PULL
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package com.cnbm.processInspection.service;
|
||||
|
||||
import com.cnbm.basic.dto.ProductFeaturesDTO;
|
||||
import com.cnbm.common.page.PageData;
|
||||
import com.cnbm.common.service.CrudService;
|
||||
import com.cnbm.influx.param.QueryDataParam;
|
||||
import com.cnbm.influx.template.Event;
|
||||
import com.cnbm.processInspection.dto.InspectionSampleDTO;
|
||||
import com.cnbm.processInspection.dto.InspectionSheetDTO;
|
||||
import com.cnbm.processInspection.entity.InspectionSheet;
|
||||
@@ -31,8 +33,10 @@ public interface IInspectionSheetService extends CrudService<InspectionSheet, In
|
||||
|
||||
List<InspectionSheetDTO> list(Map<String, Object> params);
|
||||
|
||||
List<FluxTable> getFluxParamList(Map<String, Object> params);
|
||||
List<Event> getFluxParamList(Map<String, Object> params);
|
||||
|
||||
void saveFluxParamList(InspectionSampleDTO dto);
|
||||
void saveFluxParamList(InspectionSampleDTO[] lists);
|
||||
|
||||
List<ProductFeaturesDTO> getInspectionSheetFeaturesList(Map<String, Object> params);
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.cnbm.basic.dto.ProductFeaturesDTO;
|
||||
import com.cnbm.basic.entity.Machine;
|
||||
import com.cnbm.basic.entity.Product;
|
||||
import com.cnbm.basic.entity.Shift;
|
||||
@@ -15,16 +16,20 @@ import com.cnbm.basic.service.impl.ShiftServiceImpl;
|
||||
import com.cnbm.basic.service.impl.WorkingProcedureServiceImpl;
|
||||
import com.cnbm.common.page.PageData;
|
||||
import com.cnbm.common.service.impl.CrudServiceImpl;
|
||||
import com.cnbm.common.spc.util.DataUtils;
|
||||
import com.cnbm.common.utils.ConvertUtils;
|
||||
import com.cnbm.influx.config.InfluxClient;
|
||||
import com.cnbm.influx.param.PageInfo;
|
||||
import com.cnbm.influx.param.QueryDataParam;
|
||||
import com.cnbm.influx.param.Range;
|
||||
import com.cnbm.influx.param.Tag;
|
||||
import com.cnbm.influx.template.Event;
|
||||
import com.cnbm.processInspection.dto.InspectionSampleDTO;
|
||||
import com.cnbm.processInspection.dto.InspectionSheetDTO;
|
||||
import com.cnbm.processInspection.entity.InspectionSheet;
|
||||
import com.cnbm.processInspection.mapper.InspectionSheetMapper;
|
||||
import com.cnbm.processInspection.service.IInspectionSheetService;
|
||||
import com.influxdb.query.FluxRecord;
|
||||
import com.influxdb.query.FluxTable;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -37,6 +42,7 @@ import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 检验单 表
|
||||
@@ -128,11 +134,21 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(InspectionSheetDTO dto) {
|
||||
//分组样本数=样本大小=检验特性分组数的最大值
|
||||
Integer numbersOfSamples = getNumberOfSamples(dto.getProductId());
|
||||
if(numbersOfSamples!=null){
|
||||
dto.setNumberOfGroupedSamples(numbersOfSamples);
|
||||
dto.setNumberOfSamples(numbersOfSamples);
|
||||
// 验证是否有检验参数
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("productId",dto.getProductId());
|
||||
params.put("workingProcedureId",dto.getWorkingProcedureId());
|
||||
params.put("inspectionStage",dto.getInspectionStage());
|
||||
List<ProductFeaturesDTO> inspectionSheetFeaturesList = getInspectionSheetFeaturesList(params);
|
||||
if(inspectionSheetFeaturesList==null || inspectionSheetFeaturesList.size()==0){
|
||||
throw new RuntimeException("没有发现检验参数");
|
||||
}else{
|
||||
//分组样本数=样本大小=检验特性分组数的最大值
|
||||
Integer numbersOfSamples = inspectionSheetFeaturesList.stream().max(Comparator.comparing(ProductFeaturesDTO::getSampleSize)).get().getSampleSize();
|
||||
if(numbersOfSamples!=null){
|
||||
dto.setNumberOfGroupedSamples(numbersOfSamples);
|
||||
dto.setNumberOfSamples(numbersOfSamples);
|
||||
}
|
||||
}
|
||||
InspectionSheet entity = ConvertUtils.sourceToTarget(dto, InspectionSheet.class);
|
||||
insert(entity);
|
||||
@@ -163,47 +179,129 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FluxTable> getFluxParamList(Map<String, Object> params){
|
||||
public List<Event> getFluxParamList(Map<String, Object> params){
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
String workingProcedureName = (String)params.get("workingProcedureName");
|
||||
String inspectionSheetId = (String)params.get("inspectionSheetId");
|
||||
queryDataParam.setMeasurement(workingProcedureName);
|
||||
queryDataParam.setInspectionSheetId(inspectionSheetId);
|
||||
queryDataParam.setBucket("qgs-bucket");
|
||||
|
||||
Instant startTime = (Instant) params.get("startTime");
|
||||
Instant endTime = (Instant) params.get("endTime");
|
||||
Range range = new Range(startTime,endTime);
|
||||
queryDataParam.setRange(range);
|
||||
// Instant startTime = (Instant) params.get("startTime");
|
||||
// Instant endTime = (Instant) params.get("endTime");
|
||||
// Range range = new Range(startTime,endTime);
|
||||
// queryDataParam.setRange(range);
|
||||
List<String> dropNames = new ArrayList<>();
|
||||
dropNames.add("transationId");
|
||||
// dropNames.add("inspectionSheetId");
|
||||
queryDataParam.setDropedTagNames(dropNames);
|
||||
// queryDataParam.setTag(new Tag("argName","forUpdate"));
|
||||
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(),DataUtils.getAfterDate(999).toInstant()));
|
||||
queryDataParam.setPageInfo(new PageInfo(1,10));
|
||||
|
||||
List<FluxTable> list = InfluxClient.Client.query(queryDataParam);
|
||||
return list;
|
||||
List<FluxTable> fluxTableList = InfluxClient.Client.query(queryDataParam);
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
|
||||
for (FluxTable fluxTable : fluxTableList) {
|
||||
List<FluxRecord> records = fluxTable.getRecords(); // 获取实际的记录操作
|
||||
// List<FluxColumn> columns = fluxTable.getColumns(); // 获取返回的列
|
||||
// System.out.println(columns); // 下面的数据显示是按照当前的column中的label名称获取的数据
|
||||
//System.out.println(records);
|
||||
for (FluxRecord fluxRecord : records) {
|
||||
Instant time = fluxRecord.getTime();
|
||||
String argName = (String)fluxRecord.getValueByKey("argName");
|
||||
Double argValue = Double.valueOf(fluxRecord.getValueByKey("_value").toString());
|
||||
String batchNum = (String)fluxRecord.getValueByKey("batchNum");
|
||||
String sampleNo = (String)fluxRecord.getValueByKey("sampleNo");
|
||||
// System.out.println(fluxRecord.getTime() + ": " + fluxRecord.getValueByKey("argName") + ":"
|
||||
// + fluxRecord.getValueByKey("_value") + ": " + fluxRecord.getValueByKey("batchNum"));
|
||||
eventList.add(newEvent(time,inspectionSheetId,argName,argValue,batchNum,sampleNo));
|
||||
}
|
||||
}
|
||||
|
||||
//更新检验单缺陷数不良数
|
||||
//根据样本号分组
|
||||
Map<String,List<Event>> map = eventList.stream().collect(Collectors.groupingBy(Event::getSampleNumber));
|
||||
//获取的产品特性参照值
|
||||
InspectionSheetDTO dto = get((Long) params.get("inspectionSheetId"));
|
||||
Map<String, Object> params2 = new HashMap<>();
|
||||
params2.put("productId",dto.getProductId());
|
||||
params2.put("workingProcedureId",dto.getWorkingProcedureId());
|
||||
params2.put("inspectionStage",dto.getInspectionStage());
|
||||
//缺陷
|
||||
Integer numberOfDefects = 0;
|
||||
//不良
|
||||
Integer defectiveQuantity = 0;
|
||||
|
||||
List<ProductFeaturesDTO> featuresList = getInspectionSheetFeaturesList(params2);
|
||||
//循环每个样本组
|
||||
for (Map.Entry<String, List<Event>> entry : map.entrySet()) {
|
||||
//该样本的缺陷数
|
||||
Integer eventDefects = 0;
|
||||
//该样本的属性列表
|
||||
List<Event> eventList1 = entry.getValue();
|
||||
for(Event event : eventList1){
|
||||
String featureName = event.getArgName();
|
||||
ProductFeaturesDTO feature = featuresList.stream().filter(u -> u.getName().equals(featureName)).findAny().orElse(null);
|
||||
if(feature!=null){
|
||||
//1 计量型;2 计数型
|
||||
if(feature.getType()==1){
|
||||
Double featureValue = Double.valueOf(event.getArgValue());
|
||||
if(featureValue>feature.getUsl()||featureValue<feature.getLsl()) {
|
||||
eventDefects = eventDefects + 1;
|
||||
}
|
||||
}
|
||||
if(feature.getType()==2){
|
||||
Integer featureValue = Integer.valueOf(event.getArgValue());
|
||||
if(featureValue==1){
|
||||
eventDefects = eventDefects + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(eventDefects!=0){
|
||||
numberOfDefects = numberOfDefects + eventDefects;
|
||||
defectiveQuantity = defectiveQuantity + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
InspectionSheetDTO updateDto = new InspectionSheetDTO();
|
||||
updateDto.setId((Long)params.get("inspectionSheetId"));
|
||||
updateDto.setNumberOfDefects(numberOfDefects);
|
||||
updateDto.setDefectiveQuantity(defectiveQuantity);
|
||||
update(updateDto);
|
||||
|
||||
return eventList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFluxParamList(InspectionSampleDTO dto){
|
||||
//String jsonData = {"workingProcedureName":"test","inspectionSheetId":"116","param1":"0.47","param2":"0.687","param2":"0.53"};
|
||||
String workingProcedureName = dto.getWorkingProcedureName();
|
||||
String inspectionSheetId = dto.getInspectionSheetId();
|
||||
String batchNum = dto.getBatchNum();
|
||||
String jsonData = dto.getJsonData();
|
||||
JSONObject json = JSON.parseObject(jsonData);
|
||||
// LocalDateTime sampleTime = dto.getSampleTime();
|
||||
// Instant eventTime = sampleTime.toInstant(ZoneOffset.UTC);
|
||||
Instant eventTime = new Date().toInstant();
|
||||
public void saveFluxParamList(InspectionSampleDTO[] lists){
|
||||
for(InspectionSampleDTO dto:lists) {
|
||||
//String jsonData = {"workingProcedureName":"test","inspectionSheetId":"116","param1":"0.47","param2":"0.687","param2":"0.53"};
|
||||
String workingProcedureName = dto.getWorkingProcedureName();
|
||||
String inspectionSheetId = dto.getInspectionSheetId();
|
||||
String batchNum = dto.getBatchNum();
|
||||
String sampleNumber = dto.getSampleNumber();
|
||||
String jsonData = dto.getJsonData();
|
||||
JSONObject json = JSON.parseObject(jsonData);
|
||||
LocalDateTime sampleTime = dto.getSampleTime();
|
||||
Instant eventTime = sampleTime.toInstant(ZoneOffset.UTC);
|
||||
|
||||
List<Event> list = new ArrayList<>();
|
||||
for (Map.Entry entry : json.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
Double v = Double.valueOf(entry.getValue().toString());
|
||||
list.add(newEvent(eventTime,inspectionSheetId,key,v,batchNum));
|
||||
List<Event> list = new ArrayList<>();
|
||||
for (Map.Entry entry : json.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
Double v = Double.valueOf(entry.getValue().toString());
|
||||
list.add(newEvent(eventTime, inspectionSheetId, key, v, batchNum, sampleNumber));
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list, workingProcedureName);
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list,workingProcedureName);
|
||||
}
|
||||
|
||||
private Event newEvent(Instant time,String inspectionSheetId,String argName,Double argValue,String batchNum){
|
||||
private Event newEvent(Instant time,String inspectionSheetId,String argName,Double argValue,String batchNum,String sampleNo){
|
||||
Event event = new Event();
|
||||
event.setInspectionSheetId(inspectionSheetId);
|
||||
event.setTime(time);
|
||||
event.setBatchNum(batchNum);
|
||||
event.setSampleNumber(sampleNo);
|
||||
event.setArgName(argName);
|
||||
if(!Objects.equals(argValue, "") && argValue != null ){
|
||||
event.setArgValue(argValue.toString());
|
||||
@@ -211,7 +309,13 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
|
||||
return event;
|
||||
}
|
||||
|
||||
public Integer getNumberOfSamples(Long id) {
|
||||
return mapper.getNumberOfSamples(id);
|
||||
// @Override
|
||||
// public Integer getNumberOfSamples(Map<String, Object> params) {
|
||||
// return mapper.getNumberOfSamples(params);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<ProductFeaturesDTO> getInspectionSheetFeaturesList(Map<String, Object> params) {
|
||||
return mapper.getInspectionSheetFeaturesList(params);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user