|
@@ -3,20 +3,34 @@ package com.gyee.ghost.controller.ghost;/*
|
|
|
@date 2022/8/3-16:36
|
|
|
*/
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.gyee.common.config.R;
|
|
|
import com.gyee.common.model.StringUtils;
|
|
|
+import com.gyee.common.util.DateUtils;
|
|
|
import com.gyee.ghost.init.CacheContext;
|
|
|
import com.gyee.ghost.model.auto.*;
|
|
|
+import com.gyee.ghost.model.auto.vo.FaultrecordCheckeVo;
|
|
|
+import com.gyee.ghost.model.auto.vo.FaultrecordVo;
|
|
|
import com.gyee.ghost.service.auto.GhostService;
|
|
|
-import com.gyee.ghost.vo.FaultinputVo;
|
|
|
+import com.gyee.ghost.service.auto.IFaultrecordService;
|
|
|
+import com.gyee.ghost.service.auto.IWindturbineinfodayService;
|
|
|
+import com.gyee.ghost.util.realtimesource.ExcelUtils;
|
|
|
import com.gyee.ghost.vo.InvolvedVo;
|
|
|
import com.gyee.ghost.vo.NatureVo;
|
|
|
import com.gyee.ghost.vo.WindturbineVo;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
@@ -25,7 +39,10 @@ public class GhostController {
|
|
|
|
|
|
@Resource
|
|
|
private GhostService ghostService;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private IWindturbineinfodayService windturbineinfodayService;
|
|
|
+ @Resource
|
|
|
+ private IFaultrecordService faultrecordService;
|
|
|
@GetMapping("/wplist")
|
|
|
@ResponseBody
|
|
|
@CrossOrigin(origins = "*", maxAge = 3600)
|
|
@@ -316,7 +333,158 @@ public class GhostController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/get-import-template")
|
|
|
+ @ApiOperation(value = "获得导入模板")
|
|
|
+ public void importTemplate(HttpServletResponse response) throws IOException, ParseException {
|
|
|
+ // 手动创建导出 demo
|
|
|
+
|
|
|
+ SimpleDateFormat sf= new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<FaultrecordVo> list = Arrays.asList(
|
|
|
+ FaultrecordVo.builder().wtname("").begindate(sf.parse("2023-09-09 00:00:00")).enddate(sf.parse("2023-09-09 00:03:00")).faulttype("").faultphenomenon("").defecteliminating("").processingresults("").faultduration(0.3).impactcapacity(0.3).type("").build(),
|
|
|
+
|
|
|
+ FaultrecordVo.builder().wtname("").enddate(sf.parse("2023-09-09 00:00:00")).enddate(sf.parse("2023-09-09 00:06:00")).faulttype("").faultphenomenon("").defecteliminating("").processingresults("").faultduration(0.5).impactcapacity(0.3).type("").build()
|
|
|
+
|
|
|
+ );
|
|
|
+
|
|
|
+ // 输出
|
|
|
+ ExcelUtils.write(response, "导入模板.xls", "导入模板", FaultrecordVo.class, list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/checking")
|
|
|
+ @ApiOperation(value = "验证", notes = "验证")
|
|
|
+ public R checking(@RequestParam("file") MultipartFile file) throws Exception {
|
|
|
+ List<FaultrecordVo> list = ExcelUtils.read(file, FaultrecordVo.class);
|
|
|
+ List<FaultrecordCheckeVo> vos = new ArrayList<>();
|
|
|
+ if (StringUtils.notEmp(list) && !list.isEmpty()) {
|
|
|
+ for (FaultrecordVo vo : list) {
|
|
|
+
|
|
|
+ FaultrecordCheckeVo po=new FaultrecordCheckeVo();
|
|
|
+ BeanUtil.copyProperties(vo, po);
|
|
|
+ if(!CacheContext.wtnamemap.containsKey(vo.getWtname()))
|
|
|
+ {
|
|
|
+
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append("风机名称错误——");
|
|
|
+ sb.append(vo.getWtname());
|
|
|
+ po.setChecke(false);
|
|
|
+ po.setError(vo.getWtname());
|
|
|
+ }else if(StringUtils.empty(vo.getBegindate()))
|
|
|
+ {
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append("开始时间没有——");
|
|
|
+ sb.append(vo.getBegindate());
|
|
|
+ po.setChecke(false);
|
|
|
+ po.setError(String.valueOf(vo.getBegindate()));
|
|
|
+
|
|
|
+ }else if(StringUtils.empty(vo.getEnddate()))
|
|
|
+ {
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append("结束时间没有——");
|
|
|
+ sb.append(vo.getEnddate());
|
|
|
+ po.setChecke(false);
|
|
|
+ po.setError(String.valueOf(vo.getEnddate()));
|
|
|
+
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ po.setChecke(true);
|
|
|
+ }
|
|
|
+ vos.add(po);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotNull(vos)) {
|
|
|
+ return R.ok().data(vos);
|
|
|
+ }else{
|
|
|
+ return R.error().message("访问失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/import")
|
|
|
+ @ApiOperation(value = "导入", notes = "导入")
|
|
|
+ public R importExcel(@RequestParam("file") MultipartFile file) throws Exception {
|
|
|
+ List<FaultrecordVo> list = ExcelUtils.read(file, FaultrecordVo.class);
|
|
|
+
|
|
|
+ if (StringUtils.notEmp(list) && !list.isEmpty()) {
|
|
|
+
|
|
|
+
|
|
|
+ Faultrecord po=new Faultrecord();
|
|
|
+ for (FaultrecordVo vo : list) {
|
|
|
+
|
|
|
+
|
|
|
+ BeanUtil.copyProperties(vo, po);
|
|
|
|
|
|
+ po.setId(StringUtils.getUUID());
|
|
|
+ if(CacheContext.wtnamemap.containsKey(vo.getWtname()))
|
|
|
+ {
|
|
|
+
|
|
|
+ Windturbine wt=CacheContext.wtnamemap.get(vo.getWtname());
|
|
|
+ po.setWtid(wt.getId());
|
|
|
+
|
|
|
+ if(CacheContext.promap.containsKey(wt.getProjectid()))
|
|
|
+ {
|
|
|
+ Project pj=CacheContext.promap.get(wt.getProjectid());
|
|
|
+ po.setProjectid(pj.getId());
|
|
|
+ po.setProjectname(pj.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(CacheContext.wpmap.containsKey(wt.getWindpowerstationid()))
|
|
|
+ {
|
|
|
+ Windpowerstation wp=CacheContext.wpmap.get(wt.getWindpowerstationid());
|
|
|
+ po.setWpid(wp.getId());
|
|
|
+ po.setWpname(wp.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.notEmp(vo.getFaultduration()) && StringUtils.notEmp(vo.getBegindate()) && StringUtils.notEmp(vo.getEnddate()))
|
|
|
+ {
|
|
|
+ po.setFaultduration(DateUtils.hoursDiff1(vo.getBegindate(),vo.getEnddate()));
|
|
|
+
|
|
|
+
|
|
|
+ List<Faultrecord> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ Date begin =vo.getBegindate();
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<Windturbineinfoday> windturbineinfodayQueryWrapper = new QueryWrapper<>();
|
|
|
+ windturbineinfodayQueryWrapper.eq("recorddate",begin);
|
|
|
+ List<Windturbineinfoday> windturbineinfodayList = windturbineinfodayService.list(windturbineinfodayQueryWrapper);
|
|
|
+
|
|
|
+ Map<String,Windturbineinfoday> wtdaymap=new HashMap<>();
|
|
|
+ if(!windturbineinfodayList.isEmpty())
|
|
|
+ {
|
|
|
+ for ( Windturbineinfoday wtday:windturbineinfodayList)
|
|
|
+ {
|
|
|
+ wtdaymap.put(wtday.getWindturbineid(),wtday);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(Faultrecord fr:resultList)
|
|
|
+ {
|
|
|
+ if(StringUtils.notEmp(fr.getFaultduration()))
|
|
|
+ {
|
|
|
+ double gzsc=fr.getFaultduration();
|
|
|
+
|
|
|
+ if(wtdaymap.containsKey(fr.getWtid()))
|
|
|
+ {
|
|
|
+ Windturbineinfoday wtday=wtdaymap.get(fr.getWtid());
|
|
|
+
|
|
|
+ double rfdl= wtday.getGeneratingcapacity();
|
|
|
+ double ssdl = new BigDecimal(rfdl).divide(new BigDecimal(24), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(gzsc)).doubleValue();
|
|
|
+ fr.setPowerloss(StringUtils.round(ssdl,2));
|
|
|
+
|
|
|
+ faultrecordService.saveOrUpdate(fr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotNull("ok")) {
|
|
|
+ return R.ok().data("ok");
|
|
|
+ }else{
|
|
|
+ return R.error().message("访问失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@GetMapping("/mainrecord")
|
|
|
@ResponseBody
|