package com.cnbm.processInspection.controller; import com.cnbm.basic.dto.ProductFeaturesDTO; import com.cnbm.basic.entity.ProductFeatures; import com.cnbm.basic.service.IProductFeaturesService; import com.cnbm.common.spc.math.StandardDiviation; import com.cnbm.common.spc.util.DataUtils; import com.cnbm.common.vo.R; import com.cnbm.influx.constant.Constant; import com.cnbm.influx.param.QueryDataGroupByTimeParam; import com.cnbm.influx.param.QueryDataParam; import com.cnbm.influx.param.Range; import com.cnbm.processInspection.dto.*; import com.cnbm.processInspection.graphAnalyzed.forCount.c.CGraph; import com.cnbm.processInspection.graphAnalyzed.forCount.np.NPGraph; import com.cnbm.processInspection.graphAnalyzed.forCount.p.PGraph; import com.cnbm.processInspection.graphAnalyzed.forCount.u.UGraph; import com.cnbm.processInspection.graphAnalyzed.forMeterage.mr.MeanRGraph; import com.cnbm.processInspection.graphAnalyzed.forMeterage.ms.MeanStandardDeviationGraph; import com.cnbm.processInspection.graphAnalyzed.forMeterage.xmr.XMRGraph; import com.cnbm.qualityPlanning.entity.ControlLimitDetail; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; @RestController @RequestMapping("/processInspection") public class ProcessInspectionController { private static final Logger logger = LoggerFactory.getLogger(ProcessInspectionController.class); @Autowired IProductFeaturesService productFeaturesService; @PostMapping("/XbarSGraphTest") public R xbarSGraphTest() throws Exception { ProductFeatures productFeatures = new ProductFeatures(); productFeatures.setSl(new Float(65)); productFeatures.setUsl(new Float(66)); productFeatures.setLsl(new Float(69)); productFeatures.setName("LTWeight"); productFeatures.setSampleSize(10); MeanStandardDeviationGraph meanStandardDeviationGraph = new MeanStandardDeviationGraph(productFeatures); //判读方案 List interpretationScheme = new ArrayList<>(); interpretationScheme.add(new InterpretationListArg(1,null,null)); interpretationScheme.add(new InterpretationListArg(5,3,2)); meanStandardDeviationGraph.isNeedInterpretation(interpretationScheme); QueryDataParam queryDataParam = new QueryDataParam(); queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); meanStandardDeviationGraph.initialDate(queryDataParam); XbarSGraphData xbarSGraphData = new XbarSGraphData( meanStandardDeviationGraph.getMsdGraphEntity()==null?null:meanStandardDeviationGraph.getMsdGraphEntity(), meanStandardDeviationGraph.getXbarCL()==null?null:new ControlLimitDetail(meanStandardDeviationGraph.getXbarCL().getUCL(), meanStandardDeviationGraph.getXbarCL().getCL(), meanStandardDeviationGraph.getXbarCL().getLCL()), meanStandardDeviationGraph.getSCL()==null?null:new ControlLimitDetail(meanStandardDeviationGraph.getSCL().getUCL(), meanStandardDeviationGraph.getSCL().getCL(), meanStandardDeviationGraph.getSCL().getLCL()), meanStandardDeviationGraph.getSpecificationLimit()==null?null:meanStandardDeviationGraph.getSpecificationLimit(), meanStandardDeviationGraph.getProcessCapacity()==null?null:meanStandardDeviationGraph.getProcessCapacity(), (meanStandardDeviationGraph.getXigma()==null||meanStandardDeviationGraph.getTotalXigma()==null)?null:new StandardDiviation(meanStandardDeviationGraph.getXigma(),meanStandardDeviationGraph.getTotalXigma()) ); return R.ok("成功",xbarSGraphData); } @PostMapping("/XbarRGraphTest") public R XbarRGraphTest() throws Exception { //todo SL/USL/LSL 和 sampleSize 需要从外面传过来。 ProductFeatures productFeatures = new ProductFeatures(); productFeatures.setSl(new Float(65)); productFeatures.setUsl(new Float(66)); productFeatures.setLsl(new Float(69)); productFeatures.setName("LTWeight"); productFeatures.setSampleSize(10); MeanRGraph meanRGraph = new MeanRGraph(productFeatures); //判读方案 List interpretationScheme = new ArrayList<>(); interpretationScheme.add(new InterpretationListArg(1,null,null)); interpretationScheme.add(new InterpretationListArg(5,3,2)); meanRGraph.isNeedInterpretation(interpretationScheme); QueryDataParam queryDataParam = new QueryDataParam(); queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); meanRGraph.initialDate(queryDataParam); XbarRGraphData xbarSGraphData = new XbarRGraphData( meanRGraph.getMrGraphEntity()==null?null:meanRGraph.getMrGraphEntity(), meanRGraph.getXbarCL()==null?null:new ControlLimitDetail(meanRGraph.getXbarCL().getUCL(), meanRGraph.getXbarCL().getCL(), meanRGraph.getXbarCL().getLCL()), meanRGraph.getRCL()==null?null:new ControlLimitDetail(meanRGraph.getRCL().getUCL(), meanRGraph.getRCL().getCL(), meanRGraph.getRCL().getLCL()), meanRGraph.getSpecificationLimit()==null?null:meanRGraph.getSpecificationLimit(), meanRGraph.getProcessCapacity()==null?null:meanRGraph.getProcessCapacity(), (meanRGraph.getXigma()==null||meanRGraph.getTotalXigma()==null)?null:new StandardDiviation(meanRGraph.getXigma(),meanRGraph.getTotalXigma()) ); return R.ok("成功",xbarSGraphData); } @PostMapping("/XMRGraphTest") public R XMRGraphTest() throws Exception { ProductFeatures productFeatures = new ProductFeatures(); productFeatures.setSl(new Float(65)); productFeatures.setUsl(new Float(66)); productFeatures.setLsl(new Float(69)); productFeatures.setName("LTWeight"); productFeatures.setSampleSize(1); XMRGraph xmrGraph = new XMRGraph(productFeatures); //判读方案 List interpretationScheme = new ArrayList<>(); interpretationScheme.add(new InterpretationListArg(1,null,null)); interpretationScheme.add(new InterpretationListArg(5,3,2)); xmrGraph.isNeedInterpretation(interpretationScheme); QueryDataParam queryDataParam = new QueryDataParam(); queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); xmrGraph.initialDate(queryDataParam); XMRGraphData xmrGraphData = new XMRGraphData( xmrGraph.getXmrGraphEntity()==null?null:xmrGraph.getXmrGraphEntity(), xmrGraph.getXCL()==null?null:new ControlLimitDetail(xmrGraph.getXCL().getUCL(), xmrGraph.getXCL().getCL(), xmrGraph.getXCL().getLCL()), xmrGraph.getRSCL()==null?null:new ControlLimitDetail(xmrGraph.getRSCL().getUCL(), xmrGraph.getRSCL().getCL(), xmrGraph.getRSCL().getLCL()), xmrGraph.getSpecificationLimit()==null?null:xmrGraph.getSpecificationLimit(), xmrGraph.getProcessCapacity()==null?null:xmrGraph.getProcessCapacity(), (xmrGraph.getXigma()==null||xmrGraph.getTotalXigma()==null)?null:new StandardDiviation(xmrGraph.getXigma(),xmrGraph.getTotalXigma()) ); return R.ok("成功",xmrGraphData); } // @PostMapping("/getBatchs") // public R> getBatchs() throws InterruptedException { // List list = new ArrayList<>(); // Random r = new Random(); // Instant instant = DataUtils.getBeforeDate(400).toInstant(); // List res = new ArrayList<>(); // // QueryDataParam queryDataParam = new QueryDataParam(); // queryDataParam.setBucket("qgs-bucket"); // queryDataParam.setMeasurement("Weight"); // List dropNames = new ArrayList<>(); // dropNames.add("transationId"); // dropNames.add("_value"); // dropNames.add("_start"); // dropNames.add("_stop"); // dropNames.add("_time"); // dropNames.add("_field"); // dropNames.add("_measurement"); // dropNames.add("inspectionSheetId"); // dropNames.add("argName"); // queryDataParam.setDropedTagNames(dropNames); // // queryDataParam.setTags(Arrays.asList(new Tag("argName","LTWeight"))); // // queryDataParam.setRange(new Range(DataUtils.getBeforeDate(100).toInstant(),Instant.now())); //// queryDataParam.setPageInfo(new PageInfo(1,10)); // List query = InfluxClient.Client.queryByGroup(queryDataParam); // // // for (FluxTable fluxTable : query) { // List records = fluxTable.getRecords(); // if(records.size()!=0){ // res.add((String) records.get(0).getValueByKey("batchNum")); // continue; // } // } // return R.ok(res); // } @PostMapping("/NPGraphTest") public R NPGraphTest() throws Exception { ProductFeatures productFeatures = new ProductFeatures(); productFeatures.setSl(new Float(65)); productFeatures.setUsl(new Float(66)); productFeatures.setLsl(new Float(69)); productFeatures.setName("failDay"); NPGraph npGraph = new NPGraph(productFeatures); QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setRange(new Range(DataUtils.getBeforeDate(9999).toInstant(), DataUtils.getAfterDate(9999).toInstant() )); queryDataParam.setTimeType(2); npGraph.initialDate(queryDataParam); NPGraphData npGraph1 = new NPGraphData( npGraph.getList()==null?null:npGraph.getList(), npGraph.getArgName()==null?null:npGraph.getArgName() ); return R.ok("成功",npGraph1); } @PostMapping("/NPGraph") public R NPGraph(@RequestBody GraphArg graphArg) throws Exception { ProductFeatures productFeatures = setRealSampleSize(graphArg); if(productFeatures == null){ return R.failed("检验参数异常"); } NPGraph npGraph = new NPGraph(productFeatures); QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); // queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setMeasurement(graphArg.getProcedureName()); queryDataParam.setRange(new Range( graphArg.getBegin().toInstant() , graphArg.getEnd().toInstant() )); queryDataParam.setTimeType(graphArg.getGroupType()); npGraph.initialDate(queryDataParam); NPGraphData npGraph1 = new NPGraphData( npGraph.getList()==null?null:npGraph.getList(), npGraph.getArgName()==null?null:npGraph.getArgName() ); return R.ok("成功",npGraph1); } @PostMapping("/PGraphTest") public R PGraphTest() throws Exception { ProductFeatures productFeatures = new ProductFeatures(); productFeatures.setSl(new Float(65)); productFeatures.setUsl(new Float(66)); productFeatures.setLsl(new Float(69)); productFeatures.setName("failDay"); PGraph pGraph = new PGraph(productFeatures); QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); queryDataParam.setTimeType(2); pGraph.initialDate(queryDataParam); PGraphData npGraph1 = new PGraphData( pGraph.getList()==null?null:pGraph.getList(), pGraph.getArgName()==null?null:pGraph.getArgName() ); return R.ok("成功",npGraph1); } @PostMapping("/CGraphTest") public R CGraphTest() throws Exception { ProductFeatures productFeatures = new ProductFeatures(); productFeatures.setSl(new Float(65)); productFeatures.setUsl(new Float(66)); productFeatures.setLsl(new Float(69)); productFeatures.setName("failDay"); CGraph cGraph = new CGraph(productFeatures); QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); //到时候 要看前端 传的,这里的measurement 其实就是 设备名。 queryDataParam.setMeasurement(Constant.measurement); // queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now())); queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); queryDataParam.setTimeType(2); cGraph.initialDate(queryDataParam); CGraphData npGraph1 = new CGraphData( cGraph.getList()==null?null:cGraph.getList(), cGraph.getArgName()==null?null:cGraph.getArgName() ); return R.ok("成功",npGraph1); } @PostMapping("/UGraphTest") public R UGraphTest() throws Exception { ProductFeatures productFeatures = new ProductFeatures(); productFeatures.setSl(new Float(65)); productFeatures.setUsl(new Float(66)); productFeatures.setLsl(new Float(69)); productFeatures.setName("failDay"); UGraph uGraph = new UGraph(productFeatures); QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); queryDataParam.setTimeType(2); uGraph.initialDate(queryDataParam); UGraphData npGraph1 = new UGraphData( uGraph.getList()==null?null:uGraph.getList(), uGraph.getArgName()==null?null:uGraph.getArgName() ); return R.ok("成功",npGraph1); } private ProductFeatures setRealSampleSize(GraphArg graphArg){ ProductFeaturesDTO productFeaturesDTO = productFeaturesService.get(graphArg.getProductFeaturesId()); if(productFeaturesDTO == null){ return null; } if(graphArg.getSampleSize()!=null){ productFeaturesDTO.setSampleSize(graphArg.getSampleSize()); } ProductFeatures productFeatures = new ProductFeatures(); BeanUtils.copyProperties(productFeaturesDTO, productFeatures); return productFeatures; } //筛选条件顺序: // ① 先工厂(产品表) => ② 检验类型(产品表)=> ③ 产品名(产品表)=> ④ 工序(产品表)=> ⑤ 特性(检验参数name)( product_features 表) ;; // ① 时间段(influxdb,必填);② 样本大小(界面上可以设置,如果要自己设置,就要更新 ProductFeatures.name) //条件:1.检验时间段(influxdb里面) ; 7.样本大小(这个可选,也可以 用默认,产品那里配置。) // 2.工厂(先放一下) ; // 3.检验类型(产品表) ; 4.产品名 (产品表); 5.工艺流程(就是工序 ,也是设备名,用到工序表); 6.特性(product_features.name ,也是influxdb中的argName) ; @PostMapping("/XbarSGraph") public R xbarSGraph(@RequestBody GraphArg graphArg) throws Exception { ProductFeatures productFeatures = setRealSampleSize(graphArg); if(productFeatures == null){ return R.failed("检验参数异常"); }else { if(productFeatures.getSampleSize()==null || productFeatures.getName()==null){ return R.failed("ProductFeatures 参数异常"); } } MeanStandardDeviationGraph meanStandardDeviationGraph = new MeanStandardDeviationGraph(productFeatures); if(graphArg.getInterpretationScheme()!=null){ meanStandardDeviationGraph.isNeedInterpretation(graphArg.getInterpretationScheme()); } QueryDataParam queryDataParam = new QueryDataParam(); // queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setMeasurement(graphArg.getProcedureName()); queryDataParam.setRange(new Range(graphArg.getBegin().toInstant(), graphArg.getEnd().toInstant())); meanStandardDeviationGraph.initialDate(queryDataParam); XbarSGraphData xbarSGraphData = new XbarSGraphData( meanStandardDeviationGraph.getMsdGraphEntity()==null?null:meanStandardDeviationGraph.getMsdGraphEntity(), meanStandardDeviationGraph.getXbarCL()==null?null:new ControlLimitDetail(meanStandardDeviationGraph.getXbarCL().getUCL(), meanStandardDeviationGraph.getXbarCL().getCL(), meanStandardDeviationGraph.getXbarCL().getLCL()), meanStandardDeviationGraph.getSCL()==null?null:new ControlLimitDetail(meanStandardDeviationGraph.getSCL().getUCL(), meanStandardDeviationGraph.getSCL().getCL(), meanStandardDeviationGraph.getSCL().getLCL()), meanStandardDeviationGraph.getSpecificationLimit()==null?null:meanStandardDeviationGraph.getSpecificationLimit(), meanStandardDeviationGraph.getProcessCapacity()==null?null:meanStandardDeviationGraph.getProcessCapacity(), (meanStandardDeviationGraph.getXigma()==null||meanStandardDeviationGraph.getTotalXigma()==null)?null:new StandardDiviation(meanStandardDeviationGraph.getXigma(),meanStandardDeviationGraph.getTotalXigma()) ); return R.ok("成功",xbarSGraphData); } @PostMapping("/XbarRGraph") public R XbarRGraph(@RequestBody GraphArg graphArg) throws Exception { ProductFeatures productFeatures = setRealSampleSize(graphArg); if(productFeatures == null){ return R.failed("检验参数异常"); }else { if(productFeatures.getSampleSize()==null || productFeatures.getName()==null){ return R.failed("ProductFeatures 参数异常"); } } MeanRGraph meanRGraph = new MeanRGraph(productFeatures); //如果要检验,,那么set 判读方案 if(graphArg.getInterpretationScheme()!=null){ meanRGraph.isNeedInterpretation(graphArg.getInterpretationScheme()); } QueryDataParam queryDataParam = new QueryDataParam(); // queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setMeasurement(graphArg.getProcedureName()); queryDataParam.setRange(new Range(graphArg.getBegin().toInstant(), graphArg.getEnd().toInstant())); meanRGraph.initialDate(queryDataParam); XbarRGraphData xbarSGraphData = new XbarRGraphData( meanRGraph.getMrGraphEntity()==null?null:meanRGraph.getMrGraphEntity(), meanRGraph.getXbarCL()==null?null:new ControlLimitDetail(meanRGraph.getXbarCL().getUCL(), meanRGraph.getXbarCL().getCL(), meanRGraph.getXbarCL().getLCL()), meanRGraph.getRCL()==null?null:new ControlLimitDetail(meanRGraph.getRCL().getUCL(), meanRGraph.getRCL().getCL(), meanRGraph.getRCL().getLCL()), meanRGraph.getSpecificationLimit()==null?null:meanRGraph.getSpecificationLimit(), meanRGraph.getProcessCapacity()==null?null:meanRGraph.getProcessCapacity(), (meanRGraph.getXigma()==null||meanRGraph.getTotalXigma()==null)?null:new StandardDiviation(meanRGraph.getXigma(),meanRGraph.getTotalXigma()) ); return R.ok("成功",xbarSGraphData); } @PostMapping("/XMRGraph") public R XMRGraph(@RequestBody GraphArg graphArg) throws Exception { ProductFeatures productFeatures = setRealSampleSize(graphArg); if(productFeatures == null){ return R.failed("检验参数异常"); } XMRGraph xmrGraph = new XMRGraph(productFeatures); //如果要检验,,那么set 判读方案 if(graphArg.getInterpretationScheme()!=null){ xmrGraph.isNeedInterpretation(graphArg.getInterpretationScheme()); } QueryDataParam queryDataParam = new QueryDataParam(); // queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setMeasurement(graphArg.getProcedureName()); queryDataParam.setRange(new Range(graphArg.getBegin().toInstant(), graphArg.getEnd().toInstant())); xmrGraph.initialDate(queryDataParam); XMRGraphData xmrGraphData = new XMRGraphData( xmrGraph.getXmrGraphEntity()==null?null:xmrGraph.getXmrGraphEntity(), xmrGraph.getXCL()==null?null:new ControlLimitDetail(xmrGraph.getXCL().getUCL(), xmrGraph.getXCL().getCL(), xmrGraph.getXCL().getLCL()), xmrGraph.getRSCL()==null?null:new ControlLimitDetail(xmrGraph.getRSCL().getUCL(), xmrGraph.getRSCL().getCL(), xmrGraph.getRSCL().getLCL()), xmrGraph.getSpecificationLimit()==null?null:xmrGraph.getSpecificationLimit(), xmrGraph.getProcessCapacity()==null?null:xmrGraph.getProcessCapacity(), (xmrGraph.getXigma()==null||xmrGraph.getTotalXigma()==null)?null:new StandardDiviation(xmrGraph.getXigma(),xmrGraph.getTotalXigma()) ); return R.ok("成功",xmrGraphData); } @PostMapping("/PGraph") public R PGraph(@RequestBody GraphArg graphArg) throws Exception { ProductFeatures productFeatures = setRealSampleSize(graphArg); if(productFeatures == null){ return R.failed("检验参数异常"); } PGraph pGraph = new PGraph(productFeatures); QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); // queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setMeasurement(graphArg.getProcedureName()); queryDataParam.setRange(new Range( graphArg.getBegin().toInstant() , graphArg.getEnd().toInstant() )); queryDataParam.setTimeType(graphArg.getGroupType()); pGraph.initialDate(queryDataParam); PGraphData npGraph1 = new PGraphData( pGraph.getList()==null?null:pGraph.getList(), pGraph.getArgName()==null?null:pGraph.getArgName() ); return R.ok("成功",npGraph1); } @PostMapping("/CGraph") public R CGraph(@RequestBody GraphArg graphArg) throws Exception { ProductFeatures productFeatures = setRealSampleSize(graphArg); if(productFeatures == null){ return R.failed("检验参数异常"); } CGraph cGraph = new CGraph(productFeatures); QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); // queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setMeasurement(graphArg.getProcedureName()); queryDataParam.setRange(new Range( graphArg.getBegin().toInstant() , graphArg.getEnd().toInstant() )); queryDataParam.setTimeType(graphArg.getGroupType()); cGraph.initialDate(queryDataParam); CGraphData npGraph1 = new CGraphData( cGraph.getList()==null?null:cGraph.getList(), cGraph.getArgName()==null?null:cGraph.getArgName() ); return R.ok("成功",npGraph1); } @PostMapping("/UGraph") public R UGraph(@RequestBody GraphArg graphArg) throws Exception { ProductFeatures productFeatures = setRealSampleSize(graphArg); if(productFeatures == null){ return R.failed("检验参数异常"); } UGraph uGraph = new UGraph(productFeatures); QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); // queryDataParam.setMeasurement(Constant.measurement); queryDataParam.setMeasurement(graphArg.getProcedureName()); queryDataParam.setRange(new Range( graphArg.getBegin().toInstant() , graphArg.getEnd().toInstant() )); queryDataParam.setTimeType(graphArg.getGroupType()); uGraph.initialDate(queryDataParam); UGraphData uGraphData = new UGraphData( uGraph.getList()==null?null:uGraph.getList(), uGraph.getArgName()==null?null:uGraph.getArgName() ); return R.ok("成功",uGraphData); } }