Browse Source

风机绩效榜接口开发

xieshengjie 2 years ago
parent
commit
14fdf1bada

+ 177 - 0
web/runeconomy-xk/src/main/java/com/gyee/runeconomy/service/bmk/BenchmarkingService.java

@@ -0,0 +1,177 @@
+package com.gyee.runeconomy.service.bmk;
+/*
+@author   谢生杰
+@date   2022/11/23-11:06
+*/
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.common.model.StringUtils;
+import com.gyee.common.util.BigDecimalUtils;
+import com.gyee.common.util.DateUtils;
+import com.gyee.common.util.DoubleUtils;
+import com.gyee.common.vo.benchmark.FjjxbVo;
+import com.gyee.runeconomy.init.CacheContext;
+import com.gyee.runeconomy.model.auto.*;
+import com.gyee.runeconomy.service.auto.IProBasicCompanyService;
+import com.gyee.runeconomy.service.auto.IProEconEquipmentInfoDay1Service;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+@Service
+public class BenchmarkingService {
+
+
+    @Resource
+    private IProEconEquipmentInfoDay1Service proEconEquipmentInfoDay1Service;
+
+    public List<ProBasicCompany> companys() {
+        List<ProBasicCompany> cpls = CacheContext.cpls;
+        Map<String, ProBasicRegion> rgmap = CacheContext.rgmap;
+        List<ProBasicCompany> result = cpls;
+        ProBasicCompany company = new ProBasicCompany();
+        Optional<ProBasicCompany> first = result.stream().findFirst();
+        if (first.isPresent()){
+            String regionId = first.get().getRegionId();
+            company.setId(regionId);
+            company.setName(rgmap.get(regionId).getAname());
+        }
+        result.add(company);
+        return result;
+    }
+    public List<ProBasicPowerstation> wpByCplist(String companyids) {
+        if (!companyids.endsWith("RGN")){
+            return CacheContext.wpls.stream().filter(wp->companyids.contains(wp.getCompanyId())).collect(Collectors.toList());
+        }else {
+            return CacheContext.wpls;
+        }
+
+    }
+
+    public List<ProBasicProject> pjByWplist(String wpids) {
+        return CacheContext.pjls.stream().filter(pj->wpids.contains(pj.getWindpowerstationId())).collect(Collectors.toList());
+    }
+
+    public List<ProBasicLine> lnByPjlist(String pjids) {
+        return CacheContext.lnls.stream().filter(ln->pjids.contains(ln.getProjectId())).collect(Collectors.toList());
+    }
+    public List<FjjxbVo> performance(String companyid, String getype, String sttype, String beginDate, String endDate, String wpids, String projectids, String lineids) {
+        List<FjjxbVo> resultList = new ArrayList<>();
+        QueryWrapper<ProEconEquipmentInfoDay1> qw = new QueryWrapper<>();
+        StringBuilder sb = new StringBuilder();
+        if (sttype.equals("1") ){
+            sb.append("windpowerstation_id,");
+        }else if (sttype.equals("2")){
+            sb.append("project_id,");
+        } else if (sttype.equals("3")){
+            sb.append("line_id,");
+        }else {
+            sb.append("windturbine_id,");
+        }
+
+        sb.append("sum(rfdl) rfdl,sum(rllfdl) rllfdl,avg(rpjfs) rpjfs,sum(rjxssdl) rjxssdl,sum(rcnsljxssdl) rcnsljxssdl,sum(rgzssdl) rgzssdl,sum(rcnslgzssdl) rcnslgzssdl,sum(rxdtjssdl) rxdtjssdl,sum(rxdjclssdl) rxdjclssdl,sum(rdjssdl) rdjssdl,sum(rqxjclssdl) rqxjclssdl,sum(rsdtjssdl) rsdtjssdl,sum(rxnssdl) rxnssdl,sum(rcwsldwssdl) rcwsldwssdl,sum(rcwsltqssdl) rcwsltqssdl");
+        qw.select(String.valueOf(sb));
+        qw.ge("record_date", DateUtils.parseDate(beginDate)).le("record_date",DateUtils.parseDate(endDate));
+        if (companyid.endsWith("ZGS")){
+            qw.eq("company_id",companyid);
+        }
+        if (getype.equals("-1")){
+            qw.like("windturbine_id","_F_WT_");
+        }else if(getype.equals("-2")){
+            qw.like("windturbine_id","_G_IN_");
+        }
+        if (StringUtils.isNotEmpty(wpids)){
+            List<String> wpList = Arrays.asList(wpids.split(","));
+            qw.in("windpowerstation_id",wpList);
+        }
+
+        if (StringUtils.isNotEmpty(projectids)){
+            List<String> proList = Arrays.asList(projectids.split(","));
+            qw.in("project_id",proList);
+        }
+        if (StringUtils.isNotEmpty(lineids)){
+            List<String> lineList = Arrays.asList(lineids.split(","));
+            qw.in("line_id",lineList);
+        }
+        if (sttype.equals("1")){
+            qw.groupBy("windpowerstation_id");
+        }else if(sttype.equals("2")){
+            qw.groupBy("project_id");
+        }else if(sttype.equals("3")){
+            qw.groupBy("line_id");
+        }else{
+            qw.groupBy("windturbine_id");
+        }
+        List<ProEconEquipmentInfoDay1> list = proEconEquipmentInfoDay1Service.list(qw);
+        AtomicReference<Double> llfdl = new AtomicReference<>((double) 0);
+        AtomicReference<Double> sjfdl = new AtomicReference<>((double) 0);
+        AtomicReference<Double> pjfs = new AtomicReference<>((double) 0);
+        AtomicReference<Double> wh = new AtomicReference<>((double) 0);
+        AtomicReference<Double> gz = new AtomicReference<>((double) 0);
+        AtomicReference<Double> xd = new AtomicReference<>((double) 0);
+        AtomicReference<Double> xn = new AtomicReference<>((double) 0);
+        AtomicReference<Double> sl = new AtomicReference<>((double) 0);
+
+
+        list.stream().forEach(i->{
+            FjjxbVo vo = new FjjxbVo();
+            if (sttype.equals("1")){
+                vo.setId(i.getWindpowerstationId());
+                vo.setName(CacheContext.wpmap.get(i.getWindpowerstationId().trim()).getName());
+            }else if(sttype.equals("2")){
+                vo.setId(i.getProjectId());
+                vo.setName(CacheContext.pjmap.get(i.getProjectId().trim()).getName());
+            }else if(sttype.equals("3")){
+                vo.setId(i.getLineId());
+                vo.setName(CacheContext.lnmap.get(i.getLineId().trim()).getName());
+            }else{
+                vo.setId(i.getWindturbineId());
+                vo.setName(CacheContext.wtmap.get(i.getWindturbineId().trim()).getName());
+            }
+            vo.setSjfdl(BigDecimalUtils.divide(new BigDecimal(i.getRfdl()),new BigDecimal(10000),2).doubleValue());
+            vo.setLlfdl(BigDecimalUtils.divide(new BigDecimal(i.getRllfdl()),new BigDecimal(10000),2).doubleValue());
+
+            vo.setSpeed(BigDecimalUtils.divide(new BigDecimal(i.getRpjfs()),new BigDecimal(1),2).doubleValue());
+            vo.setFjhjx(BigDecimalUtils.divide(new BigDecimal(i.getRgzssdl()+i.getRcnslgzssdl()),new BigDecimal(10000),2).doubleValue());
+            vo.setJhjx(BigDecimalUtils.divide(new BigDecimal(i.getRjxssdl()+i.getRcnsljxssdl()),new BigDecimal(10000),2).doubleValue());
+            vo.setXd(BigDecimalUtils.divide(new BigDecimal(i.getRxdtjssdl()+i.getRxdjclssdl()),new BigDecimal(10000),2).doubleValue());
+            vo.setSl(BigDecimalUtils.divide(new BigDecimal(i.getRcwsldwssdl()+i.getRcwsltqssdl()),new BigDecimal(10000),2).doubleValue());
+            vo.setXn(BigDecimalUtils.divide(new BigDecimal(i.getRdjssdl()+i.getRqxjclssdl()+i.getRsdtjssdl()+i.getRxnssdl()),new BigDecimal(10000),2).doubleValue());
+//            vo.setLlfdl(DoubleUtils.getRoundingNum(vo.getSjfdl()+vo.getFjhjx()+vo.getJhjx()+vo.getXd()+vo.getXn(),2));
+            vo.setFnlly(vo.getLlfdl()!=0? DoubleUtils.keepPrecision(vo.getSjfdl()/vo.getLlfdl()*100,2):0);
+
+
+            llfdl.updateAndGet(v -> new Double((double) (v + vo.getLlfdl())));
+            sjfdl.updateAndGet(v -> new Double((double) (v + vo.getSjfdl())));
+            pjfs.updateAndGet(v -> new Double((double) (v + vo.getSpeed())));
+            wh.updateAndGet(v -> new Double((double) (v + vo.getJhjx())));
+            gz.updateAndGet(v -> new Double((double) (v + vo.getFjhjx())));
+            xd.updateAndGet(v -> new Double((double) (v + vo.getXd())));
+            xn.updateAndGet(v -> new Double((double) (v + vo.getXn())));
+            sl.updateAndGet(v -> new Double((double) (v + vo.getSl())));
+            resultList.add(vo);
+        });
+        FjjxbVo vo = new FjjxbVo();
+        vo.setId("hj");
+        vo.setName("合计");
+        vo.setSjfdl(DoubleUtils.keepPrecision(sjfdl.get().doubleValue(),2));
+        vo.setLlfdl(DoubleUtils.keepPrecision(llfdl.get().doubleValue(),2));
+        vo.setSpeed(list.size()!=0?DoubleUtils.keepPrecision(pjfs.get().doubleValue()/list.size(),2):0.0);
+        vo.setJhjx(DoubleUtils.keepPrecision(wh.get().doubleValue(),2));
+        vo.setFjhjx(DoubleUtils.keepPrecision(gz.get().doubleValue(),2));
+        vo.setXd(DoubleUtils.keepPrecision(xd.get().doubleValue(),2));
+        vo.setXn(DoubleUtils.keepPrecision(xn.get().doubleValue(),2));
+        vo.setSl(DoubleUtils.keepPrecision(sl.get().doubleValue(),2));
+        vo.setFnlly(vo.getLlfdl()!=0?DoubleUtils.keepPrecision(vo.getSjfdl()/vo.getLlfdl()*100,2):0.0);
+        resultList.add(vo);
+        return resultList;
+    }
+
+    public List<FjjxbVo> performanceMX(String companyid, String getype, String sttype, String beginDate, String endDate, String wpids, String projectids, String lineids) {
+        return null;
+    }
+}