From 3da521b9e0a86dd9cc0bb28b2dfa0e7084ffc00f Mon Sep 17 00:00:00 2001 From: whycxzp <perryhsu@163.com> Date: 星期四, 20 五月 2021 17:21:12 +0800 Subject: [PATCH] 更新试验接口 --- src/main/java/com/whyc/service/ExperimentService.java | 149 ++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 126 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/whyc/service/ExperimentService.java b/src/main/java/com/whyc/service/ExperimentService.java index 6380c93..8b18163 100644 --- a/src/main/java/com/whyc/service/ExperimentService.java +++ b/src/main/java/com/whyc/service/ExperimentService.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; -import com.whyc.constant.ExperimentType; import com.whyc.dto.ExperimentConditionDTO; import com.whyc.dto.Response; import com.whyc.mapper.*; @@ -18,8 +17,13 @@ import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; + +import static java.lang.Thread.sleep; @Service public class ExperimentService { @@ -34,6 +38,17 @@ private ExperimentPreconditionMapper preconditionMapper; @Resource private CommonMapper commonMapper; + + public Response exist() { + QueryWrapper<Experiment> wrapper = Wrappers.query(); + wrapper.eq("status",1); + List<Experiment> experiments = mapper.selectList(wrapper); + //涓嶅瓨鍦ㄨ瘯楠� + if (experiments.isEmpty()){ + return new Response().set(-1,"鏆傛棤璇曢獙"); + } + return new Response().set(1,experiments); + } /** * 缁曠粍:rz, @@ -80,8 +95,8 @@ public Response addKZ(Experiment experiment) { //鎻掑叆experiment鏁版嵁 experiment.setCreateTime(new Date()); - //鏂板鍒濆鍖栫姸鎬佷负1,姝e湪杩涜 - experiment.setStatus(1); + //鏂板鍒濆鍖栫姸鎬佷负0鏈紑濮�,姝e湪杩涜 + experiment.setStatus(0); mapper.insert(experiment); //鎻掑叆experiment_base_data鏁版嵁 @@ -97,32 +112,13 @@ return new Response().setMsg(1,"鏂板鎴愬姛"); } - /*======History======*/ - - public Response<PageInfo<Experiment>> getPage(Integer pageNum, Integer pageSize, ExperimentConditionDTO condition) { - PageHelper.startPage(pageNum,pageSize); - List<Experiment> experimentList = mapper.getPage(condition); - //鏌ヨ缁撴灉鐨刣uration鏄垎閽�,杞崲涓� x鏃秞鍒嗘牸寮� - experimentList.stream().forEach(experiment -> { - int duration = Integer.parseInt(experiment.getDuration()); - //鑾峰彇鏃� - int hour = duration/60; - //鑾峰彇鍒� - int minute = duration%60; - experiment.setDuration(hour+"灏忔椂"+minute+"鍒�"); - }); - - PageInfo<Experiment> pageInfo = new PageInfo<>(experimentList); - return new Response<PageInfo<Experiment>>().set(1,pageInfo); - } - /** * 妫�鏌ュ墠缃潯浠� * @param type * @return */ public Response checkPrecondition(String type) { - AtomicReference<Integer> code = new AtomicReference<>(1); + AtomicReference<Integer> code = new AtomicReference<>(1); //2绉嶆柟寮� //m1 QueryWrapper<ExperimentPrecondition> wrapper = Wrappers.query(); @@ -145,4 +141,111 @@ }); return new Response().set(code.get(),preconditions); } + + /** + * 妫�鏌ヤ腑缃潯浠�-褰撳墠鍔熺巼鍜屽綋鍓嶅畾瀛愭俯搴�,濡傛灉绗﹀悎鏍囧噯,杩斿洖褰撳墠鍊� + */ + public Response checkPreconditionStep1(String type){ + QueryWrapper<ExperimentPrecondition> wrapper = Wrappers.query(); + wrapper.eq("type",type+"_1"); + List<ExperimentPrecondition> preconditions = preconditionMapper.selectList(wrapper); + + //鑾峰彇鍒版潯浠舵暟閲� + int conditionNum = preconditions.size(); + AtomicReference<Integer> passNum = new AtomicReference(0); + while (conditionNum!=passNum.get()) { + //閲嶇疆涓�0 + passNum.set(0); + preconditions.stream().forEach(precondition -> { + //鑾峰彇瀵瑰簲鐨勫�� + Object preconditionActualValue = commonMapper.getPreconditionStatus(precondition); + //閲囩敤娴偣杩涜鏁板�煎姣� + Float actualValue = (Float) preconditionActualValue; + Float defaultValue = Float.parseFloat(precondition.getValue()); + + if (defaultValue.equals(actualValue)) { + //鏉′欢杈炬垚,杈炬垚鏁颁笂+1 + passNum.set(passNum.get()+1); + //璁板綍褰撳墠鍊� + precondition.setActualValue(actualValue.toString()); + } + }); + } + return new Response().set(1,preconditions); + } + + /** + * 寮�濮嬭瘯楠�,鏇存柊 璇曢獙鐘舵�佸拰鍚姩璇曢獙鏃堕棿 + */ + public Response updateStatus(String experimentId){ + Experiment<Object, Object> experiment = new Experiment<>(); + experiment.setId(experimentId); + experiment.setStatus(1); + experiment.setStartTime(new Date()); + mapper.updateById(experiment); + return new Response().set(1,"鐘舵�佹洿鏂版垚鍔�"); + } + + /** + * 鑾峰彇娴嬭瘯鐐� + */ + public Response<List<ExperimentPoint>> getPoint(String experimentId){ + QueryWrapper<ExperimentPoint> wrapper = Wrappers.query(); + wrapper.eq("experiment_id",experimentId); + List<ExperimentPoint> experimentPoints = pointMapper.selectList(wrapper); + return new Response<List<ExperimentPoint>>().set(1,experimentPoints); + } + + /** + * 鏇存柊娴嬭瘯鐐圭殑寮�濮嬫椂闂村拰鐘舵�� + */ + public Response updatePointStatus(ExperimentPoint experimentPoint){ + pointMapper.update(experimentPoint,null); + return new Response().set(1,"鐘舵�佹洿鏂版垚鍔�"); + } + + /** + * 鍚姩娴嬭瘯鐐�,骞跺湪娴嬭瘯鏃堕暱杩囧悗,杩斿洖娴嬭瘯缁撴灉 + * @return + */ + public Response startExperimentPoint(ExperimentPoint point){ + //鏇存柊娴嬭瘯鏃堕棿鍜屾祴璇曠偣鐘舵�� + point.setStartTime(new Date()); + point.setStatus(1); + pointMapper.update(point,null); + //绛夊緟duration鏃堕棿 + Integer duration = point.getDuration(); + Integer durationSecond = duration*60; + try { + sleep(durationSecond); + } catch (InterruptedException e) { + e.printStackTrace(); + } + pointMapper.updateEndTime(point.getId(),new Date()); + //杩斿洖杩欐鏃堕棿鐨勬祴璇曠粨鏋� + Map<String,String> resMap = new HashMap<>(); + int value = (int) (100 + Math.random() * 10); + resMap.put("骞冲潎鍔熺巼",value+"kW"); + return new Response().set(1,resMap); + } + + /*======History======*/ + + public Response<PageInfo<Experiment>> getPage(Integer pageNum, Integer pageSize, ExperimentConditionDTO condition) { + PageHelper.startPage(pageNum,pageSize); + List<Experiment> experimentList = mapper.getPage(condition); + //鏌ヨ缁撴灉鐨刣uration鏄垎閽�,杞崲涓� x鏃秞鍒嗘牸寮� + experimentList.stream().forEach(experiment -> { + int duration = Integer.parseInt(experiment.getDuration()); + //鑾峰彇鏃� + int hour = duration/60; + //鑾峰彇鍒� + int minute = duration%60; + experiment.setDuration(hour+"灏忔椂"+minute+"鍒�"); + }); + + PageInfo<Experiment> pageInfo = new PageInfo<>(experimentList); + return new Response<PageInfo<Experiment>>().set(1,pageInfo); + } + } -- Gitblit v1.9.1