MARK FOR PULL

This commit is contained in:
闫阳 2022-12-08 16:26:17 +08:00
parent 6829169a4a
commit b15ad64d76
5 changed files with 235 additions and 130 deletions

View File

@ -19,7 +19,6 @@ public class ProductFeaturesDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "ID")
private Long id;

View File

@ -31,6 +31,6 @@ public class QueryDataParam extends BaseParam{
private List<String> dropedTagNames;
private String bucket;
private String groupName;
private String inspectionSheetId;
//private String inspectionSheetId;
}

View File

@ -1,5 +1,6 @@
package com.cnbm.processInspection.controller;
import com.alibaba.fastjson.JSONObject;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.basic.dto.FeaturesProcedureDTO;
import com.cnbm.basic.dto.ProductFeaturesDTO;
@ -64,7 +65,7 @@ public class InspectionSheetController {
@ApiImplicitParam(name = "batchNumber", value = "批次号", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = "id", value = "检验单号", paramType = "query", dataTypeClass = Integer.class)
})
// @PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:page')")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:page')")
public Result<PageData<InspectionSheetDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<InspectionSheetDTO> page = inspectionSheetService.page(params);
@ -73,7 +74,7 @@ public class InspectionSheetController {
@GetMapping("{id}")
@ApiOperation("信息")
//@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:info')")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:info')")
public Result<InspectionSheetDTO> get(@PathVariable("id") Long id){
InspectionSheetDTO data = inspectionSheetService.get(id);
@ -83,7 +84,7 @@ public class InspectionSheetController {
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
// @PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:save')")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:save')")
public Result save(@RequestBody InspectionSheetDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
@ -99,7 +100,7 @@ public class InspectionSheetController {
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
//@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:update')")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:update')")
public Result<Long> update(@RequestBody InspectionSheetDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
@ -112,7 +113,7 @@ public class InspectionSheetController {
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
//@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:delete')")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
@ -125,7 +126,7 @@ public class InspectionSheetController {
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
//@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:export')")
@PreAuthorize("@ex.hasAuthority('processInspection:inspectionSheet:export')")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<InspectionSheetDTO> list = inspectionSheetService.list(params);
@ -151,14 +152,17 @@ public class InspectionSheetController {
@PostMapping(value = "getFluxParamList")
@ApiOperation(value = "从influxdb中获取检测参数")
@ApiImplicitParams({
// @ApiImplicitParams({
// @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataTypeClass = LocalDateTime.class),
// @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataTypeClass = LocalDateTime.class),
@ApiImplicitParam(name = "inspectionSheetId", value = "检验单号", paramType = "query", dataTypeClass = Long.class),
@ApiImplicitParam(name = "workingProcedureName", value = "工序名称", paramType = "query", dataTypeClass = String.class)
})
List<Event> getFluxParamList(@ApiIgnore @RequestParam Map<String, Object> params){
return inspectionSheetService.getFluxParamList(params);
// @ApiImplicitParam(name = "inspectionSheetId", value = "检验单号", paramType = "query", dataTypeClass = String.class),
// @ApiImplicitParam(name = "workingProcedureName", value = "工序名称", paramType = "query", dataTypeClass = String.class)
// })
// List<Event> getFluxParamList(@ApiIgnore @RequestParam Map<String, Object> params){
// return inspectionSheetService.getFluxParamList(params);
// }
List<InspectionSampleDTO> getFluxParamList(@RequestParam("inspectionSheetId") Long inspectionSheetId){
return inspectionSheetService.getFluxParamList(inspectionSheetId);
}
@PostMapping("saveFluxParamList")
@ -166,7 +170,8 @@ public class InspectionSheetController {
public Result saveFluxParamList(@RequestBody InspectionSampleDTO[] lists){
inspectionSheetService.saveFluxParamList(lists);
//样本数据更新后 计算检验单缺陷数不良数
inspectionSheetService.calculate(Long.valueOf(lists[0].getInspectionSheetId()));
return new Result();
}
@ -182,4 +187,11 @@ public class InspectionSheetController {
return new Result<List<ProductFeaturesDTO>>().ok(list);
}
@PostMapping(value = "calculate")
@ApiOperation(value = "检验单统计计算")
public Result<Long> calculate(@RequestParam("inspectionSheetId") Long inspectionSheetId){
inspectionSheetService.calculate(inspectionSheetId);
return new Result<Long>().ok(inspectionSheetId);
}
}

View File

@ -1,5 +1,6 @@
package com.cnbm.processInspection.service;
import com.alibaba.fastjson.JSONObject;
import com.cnbm.basic.dto.ProductFeaturesDTO;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.CrudService;
@ -33,10 +34,13 @@ public interface IInspectionSheetService extends CrudService<InspectionSheet, In
List<InspectionSheetDTO> list(Map<String, Object> params);
List<Event> getFluxParamList(Map<String, Object> params);
// List<Event> getFluxParamList(Map<String, Object> params);
List<InspectionSampleDTO> getFluxParamList(Long inspectionSheetId);
void saveFluxParamList(InspectionSampleDTO[] lists);
List<ProductFeaturesDTO> getInspectionSheetFeaturesList(Map<String, Object> params);
void calculate(Long inspectionSheetId);
}

View File

@ -29,6 +29,7 @@ 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.google.gson.JsonObject;
import com.influxdb.query.FluxRecord;
import com.influxdb.query.FluxTable;
import org.apache.commons.lang3.StringUtils;
@ -40,6 +41,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;
@ -128,7 +130,12 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
@Override
public InspectionSheetDTO get(Long id) {
InspectionSheet entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, InspectionSheetDTO.class);
InspectionSheetDTO dto = ConvertUtils.sourceToTarget(entity, InspectionSheetDTO.class);
WorkingProcedure workingProcedure = workingProcedureService.selectById(dto.getWorkingProcedureId());
if(workingProcedure!=null){
dto.setWorkingProcedureName(workingProcedure.getName());
}
return dto;
}
@Override
@ -179,51 +186,181 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
}
@Override
public List<Event> getFluxParamList(Map<String, Object> params){
public List<InspectionSampleDTO> getFluxParamList(Long id) {
List<Event> eventList = new ArrayList<>();
InspectionSheetDTO dto = get(id);
if (dto != null && dto.getWorkingProcedureName()!=null) {
QueryDataParam queryDataParam = new QueryDataParam();
String workingProcedureName = (String)params.get("workingProcedureName");
String inspectionSheetId = (String)params.get("inspectionSheetId");
String inspectionSheetId = id.toString();
String workingProcedureName = dto.getWorkingProcedureName();
queryDataParam.setMeasurement(workingProcedureName);
queryDataParam.setInspectionSheetId(inspectionSheetId);
//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);
queryDataParam.setTag(new Tag("inspectionSheetId", inspectionSheetId));
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> 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 argValue = (String)fluxRecord.getValueByKey("_value");
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"));
String sampleNo = (String) fluxRecord.getValueByKey("sampleNumber");
eventList.add(newEvent(time, inspectionSheetId, argName, argValue, batchNum, sampleNo));
}
}
}
List<InspectionSampleDTO> list = new ArrayList<>();
if (eventList != null || eventList.size() > 0) {
//根据样本号分组
Map<String, List<Event>> map = eventList.stream().collect(Collectors.groupingBy(Event::getSampleNumber));
for (Map.Entry<String, List<Event>> entry : map.entrySet()) {
String sampleNumber = entry.getKey();
List<Event> events = entry.getValue();
//更新检验单缺陷数不良数
InspectionSampleDTO sampleDTO = new InspectionSampleDTO();
sampleDTO.setSampleNumber(sampleNumber);
sampleDTO.setSampleTime(LocalDateTime.ofInstant(events.get(0).getTime(), ZoneId.systemDefault()));
sampleDTO.setBatchNum(events.get(0).getBatchNum());
sampleDTO.setInspectionSheetId(events.get(0).getInspectionSheetId());
JSONObject jsonObject = new JSONObject();
for(Event event:events){
jsonObject.put(event.getArgName(),event.getArgValue());
}
sampleDTO.setJsonData(jsonObject.toString());
System.out.println(entry);
}
}
return list;
}
@Override
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();
String v = entry.getValue().toString();
// Double v = null;
// try {
// v= Double.valueOf(entry.getValue().toString());
// }catch (Exception e){
// }
list.add(newEvent(eventTime, inspectionSheetId, key, v, batchNum, sampleNumber));
}
InfluxClient.Client.batchInsert(list, workingProcedureName);
}
// //样本数据更新后 计算检验单缺陷数不良数
// System.out.println("--------------------------------------");
// calculate(Long.valueOf(lists[0].getInspectionSheetId()));
}
private Event newEvent(Instant time, String inspectionSheetId, String argName, String argValue, String batchNum, String sampleNo) {
Event event = new Event();
event.setInspectionSheetId(inspectionSheetId);
event.setTime(time);
event.setBatchNum(batchNum);
event.setSampleNumber(sampleNo);
event.setArgName(argName);
event.setArgValue(argValue);
// if (Objects.equals(argValue, "")){
// event.setArgValue("");
// }else if (argValue != null) {
// event.setArgValue(argValue.toString());
// }
return event;
}
// @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);
}
//计算并更新检验单缺陷数不良数
@Override
public void calculate(Long inspectionSheetId) {
List<InspectionSampleDTO> sampleDTOList = getFluxParamList(inspectionSheetId);
if (sampleDTOList != null || sampleDTOList.size() > 0) {
//缺陷
Integer numberOfDefects = 0;
//不良
Integer defectiveQuantity = 0;
//获取的产品特性参照值
InspectionSheetDTO dto = get(inspectionSheetId);
Map<String, Object> params2 = new HashMap<>();
params2.put("productId", dto.getProductId());
params2.put("workingProcedureId", dto.getWorkingProcedureId());
params2.put("inspectionStage", dto.getInspectionStage());
List<ProductFeaturesDTO> featuresList = getInspectionSheetFeaturesList(params2);
//循环每个样本组
for (InspectionSampleDTO sampleDTO : sampleDTOList) {
//该样本的缺陷数
Integer eventDefects = 0;
//该样本的属性列表
String jsonData = sampleDTO.getJsonData();
JSONObject json = JSON.parseObject(jsonData);
for (ProductFeaturesDTO feature : featuresList) {
String v = (String)json.get(feature.getName());
if (!Objects.equals(v, "") && v != null) {
//1 计量型2 计数型
if (feature.getType() == 1) {
Double featureValue = Double.valueOf(v);
if (featureValue > feature.getUsl() || featureValue < feature.getLsl()) {
eventDefects = eventDefects + 1;
}
}
if (feature.getType() == 2) {
Integer featureValue = Integer.valueOf(v);
if (featureValue == 1) {
eventDefects = eventDefects + 1;
}
}
}
if (eventDefects != 0) {
numberOfDefects = numberOfDefects + eventDefects;
defectiveQuantity = defectiveQuantity + 1;
}
}
}
InspectionSheetDTO updateDto = new InspectionSheetDTO();
updateDto.setId(inspectionSheetId);
updateDto.setNumberOfDefects(numberOfDefects);
updateDto.setDefectiveQuantity(defectiveQuantity);
update(updateDto);
}
}
/*
//获取该检验单的所有样本数据
List<Event> eventList = getFluxParamList(inspectionSheetId);
if (eventList != null || eventList.size() > 0) {
//根据样本号分组
Map<String, List<Event>> map = eventList.stream().collect(Collectors.groupingBy(Event::getSampleNumber));
//获取的产品特性参照值
InspectionSheetDTO dto = get((Long) params.get("inspectionSheetId"));
InspectionSheetDTO dto = get(inspectionSheetId);
Map<String, Object> params2 = new HashMap<>();
params2.put("productId", dto.getProductId());
params2.put("workingProcedureId", dto.getWorkingProcedureId());
@ -243,7 +380,7 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
for (Event event : eventList1) {
String featureName = event.getArgName();
ProductFeaturesDTO feature = featuresList.stream().filter(u -> u.getName().equals(featureName)).findAny().orElse(null);
if(feature!=null){
if (feature != null && !Objects.equals(event.getArgValue(), "") && event.getArgValue() != null) {
//1 计量型2 计数型
if (feature.getType() == 1) {
Double featureValue = Double.valueOf(event.getArgValue());
@ -265,57 +402,10 @@ public class InspectionSheetServiceImpl extends CrudServiceImpl<InspectionSheetM
}
}
InspectionSheetDTO updateDto = new InspectionSheetDTO();
updateDto.setId((Long)params.get("inspectionSheetId"));
updateDto.setId(inspectionSheetId);
updateDto.setNumberOfDefects(numberOfDefects);
updateDto.setDefectiveQuantity(defectiveQuantity);
update(updateDto);
return eventList;
}
@Override
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, sampleNumber));
}
InfluxClient.Client.batchInsert(list, workingProcedureName);
}
}
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());
}
return event;
}
// @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);
}
}*/
}