Răsfoiți Sursa

pms 瑞鹰 日报 工作量统计。

zhangcl 2 zile în urmă
părinte
comite
8ce339311f

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotrhdailyreport/vo/IotRhDailyReportStatisticsRespVO.java

@@ -60,4 +60,8 @@ public class IotRhDailyReportStatisticsRespVO {
     @ExcelProperty("累计油耗(吨)")
     private BigDecimal cumulativeFuelConsumption = BigDecimal.ZERO;
 
+    @Schema(description = "运行时效")
+    @ExcelProperty("运行时效")
+    private BigDecimal transitTime = BigDecimal.ZERO;
+
 }

+ 70 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotrydailyreport/IotRyDailyReportController.java

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
@@ -269,6 +270,75 @@ public class IotRyDailyReportController {
         });
     }
 
+    @GetMapping("/totalWorkload")
+    @Operation(summary = "累计工作量统计")
+    @PreAuthorize("@ss.hasPermission('pms:iot-ry-daily-report:query')")
+    public CommonResult<Map<String, BigDecimal>> totalWorkload(@Valid IotRyDailyReportPageReqVO pageReqVO) {
+        // 查询所有数据不分页
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        // 根据查询参数筛选出 符合条件 的记录id 再传入 分页查询
+        Set<Long> projectIds = new HashSet<>();
+        Set<Long> taskIds = new HashSet<>();
+        if (StrUtil.isNotBlank(pageReqVO.getContractName())) {
+            IotProjectInfoPageReqVO reqVO = new IotProjectInfoPageReqVO();
+            reqVO.setContractName(pageReqVO.getContractName());
+            List<IotProjectInfoDO> projects = iotProjectInfoService.getIotProjectInfos(reqVO);
+            if (CollUtil.isNotEmpty(projects)) {
+                projects.forEach(project -> {
+                    projectIds.add(project.getId());
+                });
+                pageReqVO.setProjectIds(projectIds);
+            }
+        }
+        if (StrUtil.isNotBlank(pageReqVO.getTaskName())) {
+            IotProjectTaskPageReqVO reqVO = new IotProjectTaskPageReqVO();
+            reqVO.setSearchKey(pageReqVO.getTaskName());
+            List<IotProjectTaskDO> tasks = iotProjectTaskService.projectTasks(reqVO);
+            if (CollUtil.isNotEmpty(tasks)) {
+                tasks.forEach(task -> {
+                    taskIds.add(task.getId());
+                });
+                pageReqVO.setTaskIds(taskIds);
+            }
+        }
+        List<IotRyDailyReportDO> list = iotRyDailyReportService.getIotRyDailyReportPage(pageReqVO).getList();
+        Map<String, BigDecimal> result = new HashMap<>();
+        // 总进尺
+        BigDecimal totalFootage = BigDecimal.ZERO;
+        // 总用电量
+        BigDecimal totalPowerConsumption = BigDecimal.ZERO;
+        // 总油耗
+        BigDecimal totalFuelConsumption = BigDecimal.ZERO;
+        if (CollUtil.isNotEmpty(list)) {
+            for (IotRyDailyReportDO report : list) {
+                BigDecimal dailyFootage = report.getDailyFootage();
+                BigDecimal powerConsumption = report.getDailyPowerUsage();
+                BigDecimal fuelConsumption = report.getDailyFuel();
+                if (ObjUtil.isNotEmpty(dailyFootage)) {
+                    totalFootage = totalFootage.add(dailyFootage);
+                }
+                if (ObjUtil.isNotEmpty(powerConsumption)) {
+                    totalPowerConsumption = totalPowerConsumption.add(powerConsumption);
+                }
+                if (ObjUtil.isNotEmpty(fuelConsumption)) {
+                    totalFuelConsumption = totalFuelConsumption.add(fuelConsumption);
+                }
+
+            }
+            // 汇总 指定搜索时间段内的 总进尺  累计用电量 累计油耗
+            if ("1".equals(pageReqVO.getProjectClassification())) {
+                // 钻井日报
+                result.put("totalFootage", totalFootage);
+            } else if ("2".equals(pageReqVO.getProjectClassification())) {
+                // 修井日报
+                result.put("totalFootage", totalFootage);
+            }
+            result.put("totalPowerConsumption", totalPowerConsumption);
+            result.put("totalFuelConsumption", totalFuelConsumption);
+        }
+        return success(result);
+    }
+
     @GetMapping("/export-excel")
     @Operation(summary = "导出瑞鹰日报 Excel")
     @PreAuthorize("@ss.hasPermission('pms:iot-ry-daily-report:export')")

+ 129 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/IotZHBDController.java

@@ -0,0 +1,129 @@
+package cn.iocoder.yudao.module.pms.job;
+
+import cn.hutool.json.JSONObject;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportRespVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportSaveReqVO;
+import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.TDDeviceMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillMapper;
+import cn.iocoder.yudao.module.pms.service.iotprojectinfo.IotProjectInfoService;
+import cn.iocoder.yudao.module.pms.service.iotprojecttask.IotProjectTaskService;
+import cn.iocoder.yudao.module.pms.service.iotrhdailyreport.IotRhDailyReportService;
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
+import cn.iocoder.yudao.module.system.service.dict.DictDataService;
+import com.alibaba.fastjson.JSON;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.http.HttpHeaders;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
+
+import javax.annotation.Resource;
+import javax.validation.Valid;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+@Tag(name = "中航北斗")
+@RestController
+@RequestMapping("/pms/iot-zhbd")
+@Validated
+public class IotZHBDController {
+
+    @Resource
+    private IotRhDailyReportService iotRhDailyReportService;
+    @Resource
+    private DeptService deptService;
+    @Resource
+    private IotProjectInfoService iotProjectInfoService;
+    @Resource
+    private IotProjectTaskService iotProjectTaskService;
+    @Resource
+    private DictDataService dictDataService;
+
+    private static final String ID = "NjI1LjUyNS42ODg";
+    private static final String SECRET = "3897865b70d7bf29fcca5029147f7d0a";
+    private static final String TOKEN_URL = "https://zhbdgps.cn/video/webapi/user/login";
+    private static final String LOCATION_URL="https://zhbdgps.cn/video/webapi/report/fuel/daily/detail";
+    private static final String parameter = "lng,lat,today_distance,distance,todayoil,totaloil,online,oil1,oil2,oil3,oil4,vehicle_name";
+    @Autowired
+    private StringRedisTemplate redisTemplate;
+    @Autowired
+    private RestTemplate restTemplate;
+    @Autowired
+    private IotOpeationFillMapper zhbdmapper;
+    @Autowired
+    private TDDeviceMapper deviceMapper;
+    @Autowired
+    private IotDeviceMapper iotDeviceMapper;
+
+    @PostMapping("/create")
+    @Operation(summary = "创建瑞恒日报")
+    @PreAuthorize("@ss.hasPermission('pms:iot-rh-daily-report:create')")
+    public CommonResult<Long> createIotRhDailyReport(@Valid @RequestBody IotRhDailyReportSaveReqVO createReqVO) {
+        return success(iotRhDailyReportService.createIotRhDailyReport(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新瑞恒日报")
+    @PreAuthorize("@ss.hasPermission('pms:iot-rh-daily-report:update')")
+    public CommonResult<Boolean> updateIotRhDailyReport(@Valid @RequestBody IotRhDailyReportSaveReqVO updateReqVO) {
+        iotRhDailyReportService.updateIotRhDailyReport(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "删除瑞恒日报")
+    @Parameter(name = "id", description = "编号", required = true)
+    @PreAuthorize("@ss.hasPermission('pms:iot-rh-daily-report:delete')")
+    public CommonResult<Boolean> deleteIotRhDailyReport(@RequestParam("id") Long id) {
+        iotRhDailyReportService.deleteIotRhDailyReport(id);
+        return success(true);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得车辆油耗")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('pms:iot-rh-daily-report:query')")
+    public CommonResult<IotRhDailyReportRespVO> getIotRhDailyReport(@RequestParam("id") Long id) {
+        IotRhDailyReportRespVO result = new IotRhDailyReportRespVO();
+
+        String zhbdtoken = redisTemplate.opsForValue().get("zhbdtoken");
+        if (StringUtils.isBlank(zhbdtoken)) {
+            Map<String, String> map = new HashMap<>();
+            map.put("id", ID);
+            map.put("secret", SECRET);
+            JSONObject entries = restTemplate.postForObject(TOKEN_URL, map, JSONObject.class);
+            if (Objects.nonNull(entries)&&entries.get("code") != null&&Integer.parseInt(String.valueOf(entries.get("code")))==200) {
+                com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(entries.get("data")));
+                zhbdtoken = jsonObject.get("token").toString();
+                redisTemplate.opsForValue().set("zhbdtoken", zhbdtoken, 80000, TimeUnit.SECONDS);
+            }
+        }
+        // 1. 设置请求头
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Authorization", zhbdtoken); // 添加自定义头信息
+        // headers.addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
+        headers.add("Content-Type", "application/json");
+        headers.add("Accept", "*/*");
+        headers.add("Host", "zhbdgps.cn");
+        headers.add("Connection", "keep-alive");
+        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
+        params.add("client_ids", "8203");
+        params.add("vehicle_ids", "8203");
+        return success(result);
+    }
+
+}

+ 54 - 8
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrhdailyreport/IotRhDailyReportServiceImpl.java

@@ -394,14 +394,6 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 pageReqVO.getTaskIds(), pageReqVO.getProjectIds(), ids);
         List<IotRhDailyReportDO> dailyReports = page.getRecords();
 
-        // key队伍id/项目部id   value累计注气量
-        Map<Long, BigDecimal> cumulativeGasInjectionPair = new HashMap<>();
-        // key队伍id/项目部id   value累计注水量
-        Map<Long, BigDecimal> cumulativeWaterInjectionPair = new HashMap<>();
-        // key队伍id/项目部id   value累计用电
-        Map<Long, BigDecimal> cumulativePowerConsumptionPair = new HashMap<>();
-        // key队伍id/项目部id   value累计油耗
-        Map<Long, BigDecimal> cumulativeFuelConsumptionPair = new HashMap<>();
         // 默认显示所有项目部的汇总数据(新疆分公司也展示 下属各项目部的数据)
         // 点击项目部 显示 下属队伍的数据
         // 首先判断点击的部门是属于 公司 还是 队伍 如果没有点击任何部门 默认查询所有项目部数据
@@ -456,6 +448,10 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         Map<Long, BigDecimal> cumulativeWaterInjectionPair = new HashMap<>();
         // key队伍id/项目部id   value累计用电
         Map<Long, BigDecimal> cumulativePowerConsumptionPair = new HashMap<>();
+        // key队伍id/项目部id   value对应项目部的总产能
+        Map<Long, BigDecimal> cumulativeCapacityPair = new HashMap<>();
+        // key队伍id/项目部id   value累计运行时效   累计注气量/累计产能
+        Map<Long, BigDecimal> cumulativeTransitTimePair = new HashMap<>();
 
         // 以项目部为维度统计数据
         // 找到所有项目部与队伍的对应关系
@@ -474,6 +470,10 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             teamProjectIdPair.put(dept.getId(), dept.getParentId());
         });
 
+        // 查询指定部门下相关设备的产能
+        // key队伍id   value队伍下相关设备产能
+        Map<Long, BigDecimal> teamCapacityPair = queryCapacities(new ArrayList<>(allRhChildDeptIds));
+
         // 累计计算各项指标
         if (CollUtil.isNotEmpty(dailyReports)) {
             dailyReports.forEach(report -> {
@@ -486,9 +486,28 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                         cumulativeWaterInjectionPair.merge(projectDeptId, report.getDailyWaterInjection(), BigDecimal::add);
                         // 累计用电量
                         cumulativePowerConsumptionPair.merge(projectDeptId, report.getDailyPowerUsage(), BigDecimal::add);
+                        if (teamCapacityPair.containsKey(report.getDeptId())) {
+                            BigDecimal tempCapacity = teamCapacityPair.get(report.getDeptId());
+                            cumulativeCapacityPair.merge(projectDeptId, tempCapacity, BigDecimal::add);
+                        }
                     }
                 }
             });
+            // 根据 累计注气量 累计产能 计算指定项目部下的平均产能
+            if (CollUtil.isNotEmpty(cumulativeGasInjectionPair) && CollUtil.isNotEmpty(cumulativeCapacityPair)) {
+                cumulativeGasInjectionPair.forEach((projectDeptId, cumulativeGasInjection) -> {
+                    if (cumulativeCapacityPair.containsKey(projectDeptId)) {
+                        BigDecimal tempCapacity = cumulativeCapacityPair.get(projectDeptId);
+                        if (tempCapacity.compareTo(BigDecimal.ZERO) > 0) {
+                            // 指定项目部的累计运行时效
+                            BigDecimal tempTransitTime = cumulativeGasInjection.divide(tempCapacity, 4, RoundingMode.HALF_UP);
+                            cumulativeTransitTimePair.put(projectDeptId, tempTransitTime);
+                        } else {
+                            cumulativeTransitTimePair.put(projectDeptId, BigDecimal.ZERO);
+                        }
+                    }
+                });
+            }
         }
 
         // 生成返回的数据列表集合
@@ -501,6 +520,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             statistics.setCumulativeGasInjection(cumulativeGasInjectionPair.get(deptId));
             statistics.setCumulativeWaterInjection(cumulativeWaterInjectionPair.get(deptId));
             statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(deptId));
+            statistics.setTransitTime(cumulativeTransitTimePair.get(deptId));
             result.add(statistics);
         });
 
@@ -530,6 +550,10 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         Map<Long, BigDecimal> cumulativeWaterInjectionPair = new HashMap<>();
         // key队伍id   value累计用电
         Map<Long, BigDecimal> cumulativePowerConsumptionPair = new HashMap<>();
+        // key队伍id/项目部id   value对应项目部的总产能
+        Map<Long, BigDecimal> cumulativeCapacityPair = new HashMap<>();
+        // key队伍id/项目部id   value累计运行时效   累计注气量/累计产能
+        Map<Long, BigDecimal> cumulativeTransitTimePair = new HashMap<>();
 
         // 以 队伍 为维度统计数据
         // 找到所有项目部与队伍的对应关系
@@ -549,6 +573,10 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             teamProjectIdPair.put(dept.getId(), dept.getParentId());
         });
 
+        // 查询指定部门下相关设备的产能
+        // key队伍id   value队伍下相关设备产能
+        Map<Long, BigDecimal> teamCapacityPair = queryCapacities(new ArrayList<>(allRhChildDeptIds));
+
         // 累计计算各项指标
         if (CollUtil.isNotEmpty(dailyReports)) {
             dailyReports.forEach(report -> {
@@ -559,8 +587,25 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     cumulativeWaterInjectionPair.merge(report.getDeptId(), report.getDailyWaterInjection(), BigDecimal::add);
                     // 累计用电量
                     cumulativePowerConsumptionPair.merge(report.getDeptId(), report.getDailyPowerUsage(), BigDecimal::add);
+                    if (teamCapacityPair.containsKey(report.getDeptId())) {
+                        BigDecimal tempCapacity = teamCapacityPair.get(report.getDeptId());
+                        cumulativeCapacityPair.merge(report.getDeptId(), tempCapacity, BigDecimal::add);
+                    }
                 }
             });
+            // 根据 累计注气量 累计产能 计算指定队伍下的平均产能
+            if (CollUtil.isNotEmpty(cumulativeGasInjectionPair) && CollUtil.isNotEmpty(cumulativeCapacityPair)) {
+                cumulativeGasInjectionPair.forEach((teamDeptId, cumulativeGasInjection) -> {
+                    if (cumulativeCapacityPair.containsKey(teamDeptId)) {
+                        BigDecimal tempCapacity = cumulativeCapacityPair.get(teamDeptId);
+                        if (tempCapacity.compareTo(BigDecimal.ZERO) > 0) {
+                            // 指定队伍的累计运行时效
+                            BigDecimal tempTransitTime = cumulativeGasInjection.divide(tempCapacity);
+                            cumulativeTransitTimePair.put(teamDeptId, tempTransitTime);
+                        }
+                    }
+                });
+            }
         }
 
         // 生成返回的数据列表集合
@@ -573,6 +618,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             statistics.setCumulativeGasInjection(cumulativeGasInjectionPair.get(teamDeptId));
             statistics.setCumulativeWaterInjection(cumulativeWaterInjectionPair.get(teamDeptId));
             statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(teamDeptId));
+            statistics.setTransitTime(cumulativeTransitTimePair.get(teamDeptId));
             result.add(statistics);
         });