|
|
@@ -1,6 +1,8 @@
|
|
|
package cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
|
|
@@ -11,7 +13,9 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
|
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotattachment.vo.IotAttachmentPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotcarzhbd.vo.IotCarZhbdPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdailyreportattrs.vo.IotDailyReportAttrsPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdailyreportfuel.vo.IotDailyReportFuelPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotprojectinfo.vo.IotProjectInfoPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotprojecttask.vo.IotProjectTaskPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotprojecttask.vo.IotProjectTaskPlatformVO;
|
|
|
@@ -24,19 +28,25 @@ import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSimpleRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotattachment.IotAttachmentDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotcarzhbd.IotCarZhbdDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdailyreportattrs.IotDailyReportAttrsDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdailyreportfuel.IotDailyReportFuelDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojectinfo.IotProjectInfoDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojecttask.IotProjectTaskDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojecttaskattrs.IotTaskAttrModelProperty;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotrddailyreport.IotRdDailyReportDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotcarzhbd.IotCarZhbdMapper;
|
|
|
import cn.iocoder.yudao.module.pms.enums.AttachmentCategoryEnum;
|
|
|
import cn.iocoder.yudao.module.pms.enums.AttachmentTypeEnum;
|
|
|
+import cn.iocoder.yudao.module.pms.job.IotDeviceCarFuelVO;
|
|
|
import cn.iocoder.yudao.module.pms.service.IotDeviceService;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotattachment.IotAttachmentService;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotdailyreportattrs.IotDailyReportAttrsService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotdailyreportfuel.IotDailyReportFuelService;
|
|
|
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.iotrddailyreport.IotRdDailyReportService;
|
|
|
+import cn.iocoder.yudao.module.pms.util.ZHBDUtil;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
@@ -46,6 +56,7 @@ import cn.iocoder.yudao.module.system.service.dict.DictDataService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import lombok.extern.log4j.Log4j;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
@@ -55,6 +66,10 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -67,6 +82,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAnd
|
|
|
@RestController
|
|
|
@RequestMapping("/pms/iot-rd-daily-report")
|
|
|
@Validated
|
|
|
+@Log4j
|
|
|
public class IotRdDailyReportController {
|
|
|
|
|
|
@Resource
|
|
|
@@ -95,6 +111,12 @@ public class IotRdDailyReportController {
|
|
|
|
|
|
@Resource
|
|
|
private DictDataService dictDataService;
|
|
|
+ @Resource
|
|
|
+ private IotCarZhbdMapper iotCarZhbdMapper;
|
|
|
+ @Resource
|
|
|
+ private ZHBDUtil zhbdUtil;
|
|
|
+ @Resource
|
|
|
+ private IotDailyReportFuelService iotDailyReportFuelService;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建瑞都日报")
|
|
|
@@ -142,7 +164,7 @@ public class IotRdDailyReportController {
|
|
|
@PreAuthorize("@ss.hasPermission('pms:iot-rd-daily-report:query')")
|
|
|
public CommonResult<IotRdDailyReportRespVO> getIotRdDailyReport(@RequestParam("id") Long id) {
|
|
|
IotRdDailyReportDO iotRdDailyReport = iotRdDailyReportService.getIotRdDailyReport(id);
|
|
|
- // 查询日报相关的 项目 任务 施工工艺
|
|
|
+ // 查询日报相关的 项目 任务 施工工艺 车辆油耗...
|
|
|
return success(buildDailyReport(iotRdDailyReport));
|
|
|
}
|
|
|
|
|
|
@@ -174,6 +196,17 @@ public class IotRdDailyReportController {
|
|
|
// 虚拟项目标识
|
|
|
dailyReportVO.setVirtualProject(project.getContractSubject());
|
|
|
}
|
|
|
+ // 查询当前日报是否已经绑定了油耗信息
|
|
|
+ boolean hasFuels = false;
|
|
|
+ IotDailyReportFuelPageReqVO fuelPageReqVO = new IotDailyReportFuelPageReqVO();
|
|
|
+ fuelPageReqVO.setType("RD");
|
|
|
+ fuelPageReqVO.setReportId(dailyReport.getId());
|
|
|
+ List<IotDailyReportFuelDO> reportFuels = iotDailyReportFuelService.getIotDailyReportFuels(fuelPageReqVO);
|
|
|
+ if (CollUtil.isNotEmpty(reportFuels)) {
|
|
|
+ hasFuels = true;
|
|
|
+ dailyReportVO.setReportedFuels(reportFuels);
|
|
|
+ } else {
|
|
|
+ }
|
|
|
// 查询日报对应的任务信息
|
|
|
if (ObjUtil.isNotEmpty(dailyReport.getTaskId())) {
|
|
|
IotProjectTaskDO task = iotProjectTaskService.getIotProjectTask(dailyReport.getTaskId());
|
|
|
@@ -182,6 +215,16 @@ public class IotRdDailyReportController {
|
|
|
dailyReportVO.setLocation(task.getLocation());
|
|
|
Set<Long> deviceIds = task.getDeviceIds();
|
|
|
Set<Long> responsiblePersonIds = task.getResponsiblePerson();
|
|
|
+ // 日报对应的任务中的设备列表
|
|
|
+ Set<String> carDeviceCodes = new HashSet<>();
|
|
|
+ // 中航北斗车辆id集合
|
|
|
+ Set<String> zhbdCarIds = new HashSet<>();
|
|
|
+ // key中航北斗carId value设备编码
|
|
|
+ Map<String, String> carIdDeviceCodePair = new HashMap<>();
|
|
|
+ // key设备编码 value设备对象
|
|
|
+ Map<String, IotDeviceRespVO> devicePair = new HashMap<>();
|
|
|
+ // 生成 carId 与 IotDeviceDO 的对应关系Map
|
|
|
+ Map<String, IotDeviceRespVO> carIdDevicePair = new HashMap<>();
|
|
|
if (CollUtil.isNotEmpty(deviceIds)) {
|
|
|
// 查询设备id集合对应的设备详情
|
|
|
List<IotDeviceRespVO> devices = iotDeviceService.getDeviceList(deviceIds);
|
|
|
@@ -190,8 +233,48 @@ public class IotRdDailyReportController {
|
|
|
.map(IotDeviceRespVO::getDeviceName) // 提取每个设备的deviceName
|
|
|
.collect(Collectors.joining(",")); // 用逗号拼接所有名称
|
|
|
dailyReportVO.setDeviceNames(deviceNames);
|
|
|
+
|
|
|
+ // 组装任务关联的 设备编码 进而查询 中航北斗carId集合
|
|
|
+ if (!hasFuels) {
|
|
|
+ devices.forEach(device -> {
|
|
|
+ carDeviceCodes.add(device.getDeviceCode());
|
|
|
+ if (ObjUtil.isNotEmpty(device.getCarId())) {
|
|
|
+ zhbdCarIds.add(String.valueOf(device.getCarId()));
|
|
|
+ carIdDeviceCodePair.put(String.valueOf(device.getCarId()), device.getDeviceCode());
|
|
|
+ }
|
|
|
+ devicePair.put(device.getDeviceCode(), device);
|
|
|
+ });
|
|
|
+ // 查询中航北斗表中的设备车辆
|
|
|
+ IotCarZhbdPageReqVO customDeviceReqVO = new IotCarZhbdPageReqVO();
|
|
|
+ // 设备表中存在的设备编码
|
|
|
+ customDeviceReqVO.setDeviceCodes(carDeviceCodes);
|
|
|
+ List<IotCarZhbdDO> deviceCars = iotCarZhbdMapper.selectList(customDeviceReqVO);
|
|
|
+ if (CollUtil.isNotEmpty(deviceCars)) {
|
|
|
+ deviceCars.forEach(car -> {
|
|
|
+ zhbdCarIds.add(car.getCarId());
|
|
|
+ carIdDeviceCodePair.put(car.getCarId(), car.getDeviceCode());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 额外匹配的 RA 与 设备表对应的编码
|
|
|
+ customDeviceReqVO.setDeviceCodes(null);
|
|
|
+ customDeviceReqVO.setCustomDeviceCodes(carDeviceCodes);
|
|
|
+ List<IotCarZhbdDO> raCars = iotCarZhbdMapper.selectList(customDeviceReqVO);
|
|
|
+ if (CollUtil.isNotEmpty(raCars)) {
|
|
|
+ raCars.forEach(car -> {
|
|
|
+ zhbdCarIds.add(car.getCarId());
|
|
|
+ carIdDeviceCodePair.put(car.getCarId(), car.getUserName());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 生成 carId 与 IotDeviceDO 的对应关系Map
|
|
|
+ carIdDevicePair = carIdDeviceCodePair.entrySet().stream()
|
|
|
+ .filter(entry -> devicePair.containsKey(entry.getValue()))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ entry -> devicePair.get(entry.getValue())
|
|
|
+ ));
|
|
|
+ }
|
|
|
}
|
|
|
- // 查询设备id集合关联的设备列表
|
|
|
+ // 查询设备id集合关联的设备列表 施工队伍下的设备+瑞都所有设备
|
|
|
IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
|
|
|
deviceReqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
|
List<IotDeviceDO> selectedDevices = iotDeviceService.getDevicesByDepts(deviceReqVO);
|
|
|
@@ -205,6 +288,65 @@ public class IotRdDailyReportController {
|
|
|
.collect(Collectors.joining(",")); // 用逗号拼接所有名称
|
|
|
dailyReportVO.setResponsiblePersonNames(userNames);
|
|
|
}
|
|
|
+ // 填报日报时 查询当前日报关联的任务中的车辆 查询中航北斗指定日报区间范围内的油耗数据 子表 主表
|
|
|
+ List<IotDailyReportFuelDO> tobeAddedReportFuels = new ArrayList<>();
|
|
|
+ if (!hasFuels) {
|
|
|
+ // 取1个任务的车辆信息 就算是平台井 所有关联井的车辆信息是相同的
|
|
|
+ // 获取中航北斗车辆的油耗信息
|
|
|
+ LocalDateTime createTime = dailyReport.getCreateTime();
|
|
|
+ // 获得昨天的日期
|
|
|
+ String yesterdayDateStr = StrUtil.EMPTY;
|
|
|
+ LocalDateTime yesterday = createTime.minusDays(1);
|
|
|
+ yesterdayDateStr = LocalDateTimeUtil.format(yesterday, DatePattern.NORM_DATE_PATTERN);
|
|
|
+
|
|
|
+ // 当前日报总油耗
|
|
|
+ BigDecimal totalOilUsage = BigDecimal.ZERO;
|
|
|
+ if (CollUtil.isNotEmpty(zhbdCarIds)) {
|
|
|
+ if (StrUtil.isNotBlank(yesterdayDateStr)) {
|
|
|
+ try {
|
|
|
+ Map<Integer, IotDeviceCarFuelVO> carFuels = zhbdUtil.carFuels(StrUtil.join(",", zhbdCarIds),
|
|
|
+ StrUtil.join(" ", yesterdayDateStr, "00:00:00"), StrUtil.join(" ", yesterdayDateStr, "23:59:59"));
|
|
|
+ System.out.println("请求参数:" + zhbdCarIds.size() + " -开始时间: "
|
|
|
+ + StrUtil.join(" ", yesterdayDateStr, "00:00:00") + " -开始时间: "
|
|
|
+ + StrUtil.join(" ", yesterdayDateStr, "23:59:59"));
|
|
|
+ if (CollUtil.isNotEmpty(carFuels)) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ Map<String, IotDeviceRespVO> finalCarIdDevicePair = carIdDevicePair;
|
|
|
+ for (Map.Entry<Integer, IotDeviceCarFuelVO> carFuelEntry : carFuels.entrySet()) {
|
|
|
+ Integer carId = carFuelEntry.getKey();
|
|
|
+ IotDeviceCarFuelVO carFuel = carFuelEntry.getValue();
|
|
|
+ // carId中航北斗车辆id value车辆油耗
|
|
|
+ IotDailyReportFuelDO reportFuel = new IotDailyReportFuelDO();
|
|
|
+ reportFuel.setType("RD");
|
|
|
+ reportFuel.setReportId(dailyReport.getId());
|
|
|
+ reportFuel.setCarId(String.valueOf(carId));
|
|
|
+ // 使用 carIdDeviceMap 获取对应的设备对象并设置deviceId
|
|
|
+ IotDeviceRespVO device = finalCarIdDevicePair.get(String.valueOf(carId));
|
|
|
+ reportFuel.setDeviceId(device.getId());
|
|
|
+ reportFuel.setDeviceCode(device.getDeviceCode());
|
|
|
+ reportFuel.setDeviceName(device.getDeviceName());
|
|
|
+ BigDecimal tempOil = new BigDecimal(carFuel.getOil());
|
|
|
+ totalOilUsage = totalOilUsage.add(tempOil);
|
|
|
+ reportFuel.setZhbdFuel(tempOil);
|
|
|
+ // 将字符串转换为LocalDateTime
|
|
|
+ try {
|
|
|
+ LocalDateTime queryDate = LocalDate.parse(carFuel.getCreatetime(), formatter).atStartOfDay();;
|
|
|
+ reportFuel.setQueryDate(queryDate);
|
|
|
+ } catch (DateTimeParseException e) {
|
|
|
+ log.error("瑞都日报-中航北斗油耗-日期格式解析失败: {}", e);
|
|
|
+ // 根据业务需求设置默认值或抛出异常
|
|
|
+ reportFuel.setQueryDate(null);
|
|
|
+ }
|
|
|
+ tobeAddedReportFuels.add(reportFuel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("获取油耗数据失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dailyReportVO.setReportFuels(tobeAddedReportFuels);
|
|
|
}
|
|
|
// 查询当前日报关联的附件信息
|
|
|
IotAttachmentPageReqVO reqVO = new IotAttachmentPageReqVO();
|