|
|
@@ -0,0 +1,641 @@
|
|
|
+package cn.iocoder.yudao.module.pms.job.dailyreport;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
|
|
+import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
|
|
+import cn.iocoder.yudao.module.pms.constant.PmsConstants;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotfivedailyreport.vo.IotFiveDailyReportPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportStatisticsRespVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotfivedailyreport.IotFiveDailyReportDO;
|
|
|
+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.dataobject.iotrhdailyreport.IotRhDailyReportDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotrydailyreport.IotRyDailyReportDO;
|
|
|
+import cn.iocoder.yudao.module.pms.message.PmsMessage;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotfivedailyreport.IotFiveDailyReportService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotrddailyreport.IotRdDailyReportService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotrhdailyreport.IotRhDailyReportService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotrydailyreport.IotRyDailyReportService;
|
|
|
+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;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
+import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleMapper;
|
|
|
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
+import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
|
|
+import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.module.pms.framework.config.MultiThreadConfiguration.PMS_THREAD_POOL_TASK_EXECUTOR;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 油服每天生成昨日的日报汇总 钉钉 推送消息
|
|
|
+ * 瑞恒 瑞都 瑞鹰 5#
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class CreateYfDailyReportStatisticsJob implements JobHandler {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+ @Resource
|
|
|
+ private IotRhDailyReportService iotRhDailyReportService;
|
|
|
+ @Resource
|
|
|
+ private IotRyDailyReportService iotRyDailyReportService;
|
|
|
+ @Resource
|
|
|
+ private IotRdDailyReportService iotRdDailyReportService;
|
|
|
+ @Resource
|
|
|
+ private IotFiveDailyReportService iotFiveDailyReportService;
|
|
|
+ @Resource(name = PMS_THREAD_POOL_TASK_EXECUTOR)
|
|
|
+ private ThreadPoolTaskExecutor pmsThreadPoolTaskExecutor;
|
|
|
+ @Resource
|
|
|
+ private PmsMessage pmsMessage;
|
|
|
+ @Resource
|
|
|
+ private DeptService deptService;
|
|
|
+ @Resource
|
|
|
+ private AdminUserService adminUserService;
|
|
|
+ @Resource
|
|
|
+ private RoleService roleService;
|
|
|
+ @Resource
|
|
|
+ private UserRoleMapper userRoleMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ // @TenantIgnore
|
|
|
+ public String execute(String param) throws Exception {
|
|
|
+ TenantUtils.execute(1L, () -> {
|
|
|
+
|
|
|
+ // 获取当前时间
|
|
|
+ LocalDateTime currentDate = LocalDateTime.now();
|
|
|
+ // 根据当前日期生成前一天的日期
|
|
|
+ // LocalDateTime yesterday = currentDate.minusDays(1);
|
|
|
+ // 测试数据 2026年8月29日
|
|
|
+ LocalDateTime yesterday = LocalDateTime.of(2026, 8, 29, 0, 0);
|
|
|
+
|
|
|
+ LocalDateTime createTimeStart = yesterday.toLocalDate().atStartOfDay();
|
|
|
+ LocalDateTime createTimeEnd = yesterday.toLocalDate().atTime(23, 59, 59);
|
|
|
+ // 前一天的日期 所在月的起始时间 月开始日期 - 当前日期
|
|
|
+ LocalDateTime monthStart = yesterday.toLocalDate().withDayOfMonth(1).atStartOfDay();
|
|
|
+ // 前一天的日期 所在月的起始时间 年开始日期 - 当前日期
|
|
|
+ LocalDateTime yearStart = yesterday.toLocalDate().withDayOfYear(1).atStartOfDay();
|
|
|
+
|
|
|
+ // 计算瑞恒的 日注气量 月注气量 年注气量 设备利用率
|
|
|
+ // 瑞恒前一天的日报 日累计注气量 单位 万方
|
|
|
+ BigDecimal daySumWanGas = BigDecimal.ZERO;
|
|
|
+ // 瑞恒设备利用率 % 格式
|
|
|
+ String rhDeviceUtilization = StrUtil.EMPTY;
|
|
|
+ /* IotRhDailyReportPageReqVO rhYesterdayReqVO = new IotRhDailyReportPageReqVO();
|
|
|
+ rhYesterdayReqVO.setCreateTime(new LocalDateTime[]{createTimeStart, createTimeEnd});
|
|
|
+ List<IotRhDailyReportDO> rhYesterdayReports = iotRhDailyReportService.getDailyReports(rhYesterdayReqVO);
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(rhYesterdayReports)) {
|
|
|
+ // 求和:所有日报当日注气量(原始:方) → 换算成万方
|
|
|
+ BigDecimal totalGasCube = rhYesterdayReports.stream()
|
|
|
+ .map(IotRhDailyReportDO::getDailyGasInjection)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ daySumWanGas = totalGasCube.divide(new BigDecimal("10000"), 2, java.math.RoundingMode.HALF_UP);
|
|
|
+ } */
|
|
|
+ // 计算瑞恒前一天日报的设备利用率
|
|
|
+ IotRhDailyReportPageReqVO rhWorkloadReqVO = new IotRhDailyReportPageReqVO();
|
|
|
+ rhWorkloadReqVO.setDeptId(157l);
|
|
|
+ rhWorkloadReqVO.setCreateTime(new LocalDateTime[]{createTimeStart, createTimeEnd});
|
|
|
+ Map<String, BigDecimal> totalWorkload = iotRhDailyReportService.totalWorkload(rhWorkloadReqVO);
|
|
|
+ BigDecimal rhReportCount = BigDecimal.ZERO;
|
|
|
+ BigDecimal rhTeamDeptIds = BigDecimal.ZERO;
|
|
|
+ if (CollUtil.isNotEmpty(totalWorkload)) {
|
|
|
+ if (totalWorkload.containsKey("totalGasInjection")) {
|
|
|
+ // 日累计注气量
|
|
|
+ BigDecimal totalGasCube = totalWorkload.get("totalGasInjection");
|
|
|
+ daySumWanGas = totalGasCube.divide(new BigDecimal("10000"), 2, java.math.RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ if (totalWorkload.containsKey("utilizationRate")) {
|
|
|
+ // 日设备利用率
|
|
|
+ BigDecimal totalGasInjection = totalWorkload.get("utilizationRate");
|
|
|
+ BigDecimal percent = totalGasInjection.multiply(new BigDecimal("100"))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ rhDeviceUtilization = percent + " %";
|
|
|
+ }
|
|
|
+ if (totalWorkload.containsKey("reportCount")) {
|
|
|
+ rhReportCount = totalWorkload.get("reportCount");
|
|
|
+ }
|
|
|
+ if (totalWorkload.containsKey("teamDeptIds")) {
|
|
|
+ rhTeamDeptIds = totalWorkload.get("teamDeptIds");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 瑞恒前一天所在月份的日报
|
|
|
+ IotRhDailyReportPageReqVO rhMonthReqVO = new IotRhDailyReportPageReqVO();
|
|
|
+ rhMonthReqVO.setCreateTime(new LocalDateTime[]{monthStart, createTimeEnd});
|
|
|
+ List<IotRhDailyReportDO> rhYesterdayMonthReports = iotRhDailyReportService.getDailyReports(rhMonthReqVO);
|
|
|
+ BigDecimal monthSumWanGas = BigDecimal.ZERO;
|
|
|
+ if (CollUtil.isNotEmpty(rhYesterdayMonthReports)) {
|
|
|
+ // 求和:所有日报当日注气量(原始:方) → 换算成万方
|
|
|
+ BigDecimal totalGasCube = rhYesterdayMonthReports.stream()
|
|
|
+ .map(IotRhDailyReportDO::getDailyGasInjection)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ monthSumWanGas = totalGasCube.divide(new BigDecimal("10000"), 2, java.math.RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ // 瑞恒前一天所在年的日报
|
|
|
+ IotRhDailyReportPageReqVO rhYearReqVO = new IotRhDailyReportPageReqVO();
|
|
|
+ rhYearReqVO.setCreateTime(new LocalDateTime[]{yearStart, createTimeEnd});
|
|
|
+ List<IotRhDailyReportDO> rhYesterdayYearReports = iotRhDailyReportService.getDailyReports(rhYearReqVO);
|
|
|
+ BigDecimal yearSumWanGas = BigDecimal.ZERO;
|
|
|
+ if (CollUtil.isNotEmpty(rhYesterdayYearReports)) {
|
|
|
+ // 求和:所有日报当日注气量(原始:方) → 换算成万方
|
|
|
+ BigDecimal totalGasCube = rhYesterdayYearReports.stream()
|
|
|
+ .map(IotRhDailyReportDO::getDailyGasInjection)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ yearSumWanGas = totalGasCube.divide(new BigDecimal("10000"), 2, java.math.RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算瑞鹰的 日进尺 月进尺 年进尺 日施工井 月完工井 年完工井 设备利用率
|
|
|
+ // 瑞鹰前一天的日报
|
|
|
+ IotRyDailyReportPageReqVO ryYesterdayReqVO = new IotRyDailyReportPageReqVO();
|
|
|
+ ryYesterdayReqVO.setCreateTime(new LocalDateTime[]{createTimeStart, createTimeEnd});
|
|
|
+ List<IotRyDailyReportDO> ryYesterdayReports = iotRyDailyReportService.getDailyReports(ryYesterdayReqVO);
|
|
|
+ BigDecimal daySumFootage = BigDecimal.ZERO;
|
|
|
+ // 日施工井
|
|
|
+ Integer dayConstructWell = 0;
|
|
|
+ if (CollUtil.isNotEmpty(ryYesterdayReports)) {
|
|
|
+ // 求和:所有日报当日进尺 米
|
|
|
+ daySumFootage = ryYesterdayReports.stream()
|
|
|
+ .map(IotRyDailyReportDO::getDailyFootage)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ // 计算 修井 日施工井数量
|
|
|
+ dayConstructWell = (int) ryYesterdayReports.stream()
|
|
|
+ .filter(r -> "2".equals(r.getProjectClassification()))
|
|
|
+ .map(IotRyDailyReportDO::getTaskId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .count();
|
|
|
+ }
|
|
|
+ // 计算瑞鹰前一天的设备利用率 钻井 修井 分子相加 分母相加
|
|
|
+ // 钻井
|
|
|
+ IotRyDailyReportPageReqVO ryZjUtilizationReqVO = new IotRyDailyReportPageReqVO();
|
|
|
+ ryZjUtilizationReqVO.setDeptId(158l);
|
|
|
+ ryZjUtilizationReqVO.setProjectClassification("1");
|
|
|
+ ryZjUtilizationReqVO.setCreateTime(new LocalDateTime[]{createTimeStart, createTimeEnd});
|
|
|
+ Map<String, BigDecimal> ryZjTotalWorkload = iotRyDailyReportService.totalWorkload(ryZjUtilizationReqVO);
|
|
|
+ BigDecimal zjReportCount = BigDecimal.ZERO;
|
|
|
+ BigDecimal zjTeamDeptIds = BigDecimal.ZERO;
|
|
|
+ BigDecimal xjReportCount = BigDecimal.ZERO;
|
|
|
+ BigDecimal xjTeamDeptIds = BigDecimal.ZERO;
|
|
|
+ if (CollUtil.isNotEmpty(ryZjTotalWorkload)) {
|
|
|
+ if (ryZjTotalWorkload.containsKey("zjReportCount")) {
|
|
|
+ zjReportCount = ryZjTotalWorkload.get("zjReportCount");
|
|
|
+ }
|
|
|
+ if (ryZjTotalWorkload.containsKey("zjTeamDeptIds")) {
|
|
|
+ zjTeamDeptIds = ryZjTotalWorkload.get("zjTeamDeptIds");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 修井
|
|
|
+ IotRyDailyReportPageReqVO ryXjUtilizationReqVO = new IotRyDailyReportPageReqVO();
|
|
|
+ ryXjUtilizationReqVO.setDeptId(158l);
|
|
|
+ ryXjUtilizationReqVO.setProjectClassification("2");
|
|
|
+ ryXjUtilizationReqVO.setCreateTime(new LocalDateTime[]{createTimeStart, createTimeEnd});
|
|
|
+ Map<String, BigDecimal> ryXjTotalWorkload = iotRyDailyReportService.totalWorkload(ryXjUtilizationReqVO);
|
|
|
+ if (CollUtil.isNotEmpty(ryXjTotalWorkload)) {
|
|
|
+ if (ryXjTotalWorkload.containsKey("xjReportCount")) {
|
|
|
+ xjReportCount = ryXjTotalWorkload.get("xjReportCount");
|
|
|
+ }
|
|
|
+ if (ryXjTotalWorkload.containsKey("xjTeamDeptIds")) {
|
|
|
+ xjTeamDeptIds = ryXjTotalWorkload.get("xjTeamDeptIds");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 钻井 修井 分子 分母 分别相加
|
|
|
+ BigDecimal ryReportCount = BigDecimal.ZERO;
|
|
|
+ BigDecimal ryTeamDeptIds = BigDecimal.ZERO;
|
|
|
+ ryReportCount = zjReportCount.add(xjReportCount);
|
|
|
+ ryTeamDeptIds = zjTeamDeptIds.add(xjTeamDeptIds);
|
|
|
+ // 计算瑞鹰总的设备利用率
|
|
|
+ BigDecimal ryDeviceUtilizationRate = BigDecimal.ZERO;
|
|
|
+ // 瑞鹰设备利用统治
|
|
|
+ String ryDeviceUtilization = StrUtil.EMPTY;
|
|
|
+ if (ryTeamDeptIds.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ ryDeviceUtilizationRate = ryReportCount.divide(ryTeamDeptIds, 4, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal percent = ryDeviceUtilizationRate.multiply(new BigDecimal("100"))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ ryDeviceUtilization = percent + " %";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 瑞鹰前一天所在月份的日报
|
|
|
+ IotRyDailyReportPageReqVO ryYesterdayMonthReqVO = new IotRyDailyReportPageReqVO();
|
|
|
+ ryYesterdayMonthReqVO.setCreateTime(new LocalDateTime[]{monthStart, createTimeEnd});
|
|
|
+ List<IotRyDailyReportDO> ryYesterdayMonthReports = iotRyDailyReportService.getDailyReports(ryYesterdayMonthReqVO);
|
|
|
+ BigDecimal monthSumFootage = BigDecimal.ZERO;
|
|
|
+ // 月完工井
|
|
|
+ Integer monthCompleteWell = 0;
|
|
|
+ if (CollUtil.isNotEmpty(ryYesterdayMonthReports)) {
|
|
|
+ // 求和:所有日报当日进尺 米
|
|
|
+ monthSumFootage = ryYesterdayMonthReports.stream()
|
|
|
+ .map(IotRyDailyReportDO::getDailyFootage)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ // 计算 修井 月完工井数量
|
|
|
+ monthCompleteWell = (int) ryYesterdayMonthReports.stream()
|
|
|
+ .filter(r -> "2".equals(r.getProjectClassification()))
|
|
|
+ .filter(r -> "wg".equals(r.getRepairStatus()))
|
|
|
+ .map(IotRyDailyReportDO::getTaskId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .count();
|
|
|
+ }
|
|
|
+ // 瑞鹰前一天所在年份的日报
|
|
|
+ IotRyDailyReportPageReqVO ryYesterdayYearReqVO = new IotRyDailyReportPageReqVO();
|
|
|
+ ryYesterdayYearReqVO.setCreateTime(new LocalDateTime[]{yearStart, createTimeEnd});
|
|
|
+ List<IotRyDailyReportDO> ryYesterdayYearReports = iotRyDailyReportService.getDailyReports(ryYesterdayYearReqVO);
|
|
|
+ BigDecimal yearSumFootage = BigDecimal.ZERO;
|
|
|
+ // 年完工井
|
|
|
+ Integer yearCompleteWell = 0;
|
|
|
+ if (CollUtil.isNotEmpty(ryYesterdayYearReports)) {
|
|
|
+ // 求和:所有日报当日进尺 米
|
|
|
+ yearSumFootage = ryYesterdayYearReports.stream()
|
|
|
+ .map(IotRyDailyReportDO::getDailyFootage)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ // 计算 修井 年完工井数量
|
|
|
+ yearCompleteWell = (int) ryYesterdayYearReports.stream()
|
|
|
+ .filter(r -> "2".equals(r.getProjectClassification()))
|
|
|
+ .filter(r -> "wg".equals(r.getRepairStatus()))
|
|
|
+ .map(IotRyDailyReportDO::getTaskId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .count();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询瑞都各队伍 压裂 or 连油 属性
|
|
|
+ // 先查询瑞都所有部门 163l
|
|
|
+ Set<Long> rdChildDeptIds = deptService.getChildDeptIdListFromCache(163l);
|
|
|
+ List<DeptDO> departments =deptService.getDeptList(rdChildDeptIds);
|
|
|
+ Set<Long> lyTeamIds = new HashSet<>();
|
|
|
+ if (CollUtil.isNotEmpty(departments)) {
|
|
|
+ departments.forEach(dept -> {
|
|
|
+ if ("3".equals(dept.getType()) && "LY".equals(dept.getEmail())) {
|
|
|
+ lyTeamIds.add(dept.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 查询瑞都昨天的日报列表
|
|
|
+ IotRdDailyReportPageReqVO reqVO = new IotRdDailyReportPageReqVO();
|
|
|
+ reqVO.setDeptId(163l);
|
|
|
+ reqVO.setCreateTime(new LocalDateTime[]{createTimeStart, createTimeEnd});
|
|
|
+ reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ PageResult<IotRdDailyReportDO> pageReports = iotRdDailyReportService.getIotRdDailyReportPage(reqVO);
|
|
|
+ List<IotRdDailyReportDO> dailyReports = pageReports.getList();
|
|
|
+ // 累计 段数 累计施工-层
|
|
|
+ BigDecimal totalCumulativeWorkingLayers = BigDecimal.ZERO;
|
|
|
+ // 累计施工井
|
|
|
+ Set<Long> taskIds = new HashSet<>();
|
|
|
+ if (CollUtil.isNotEmpty(dailyReports)) {
|
|
|
+ for (IotRdDailyReportDO report : dailyReports) {
|
|
|
+ // 日施工井
|
|
|
+ Long deptId = report.getDeptId();
|
|
|
+ Long taskId = report.getTaskId();
|
|
|
+ if (ObjUtil.isNotEmpty(deptId) && ObjUtil.isNotEmpty(taskId) && lyTeamIds.contains(deptId)) {
|
|
|
+ taskIds.add(taskId);
|
|
|
+ }
|
|
|
+ List<IotTaskAttrModelProperty> properties = report.getExtProperty();
|
|
|
+ if (CollUtil.isNotEmpty(properties)) {
|
|
|
+ for (IotTaskAttrModelProperty property : properties) {
|
|
|
+ // 工作量单位
|
|
|
+ String unit = property.getUnit();
|
|
|
+ // 工作量属性的实际值
|
|
|
+ String actualValueStr = property.getActualValue();
|
|
|
+ BigDecimal actualValue = BigDecimal.ZERO;
|
|
|
+ if (StrUtil.isNotBlank(actualValueStr)) {
|
|
|
+ try {
|
|
|
+ actualValue = new BigDecimal(actualValueStr);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ // 若字符串格式错误,默认按0处理(可根据业务调整)
|
|
|
+ actualValue = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("段数".equals(unit)) {
|
|
|
+ totalCumulativeWorkingLayers = totalCumulativeWorkingLayers.add(actualValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 设置瑞都的设备利用率
|
|
|
+ String rdDeviceUtilization = StrUtil.EMPTY;
|
|
|
+ BigDecimal rdReportCount = BigDecimal.ZERO;
|
|
|
+ BigDecimal rdTeamDeptIds = BigDecimal.ZERO;
|
|
|
+ IotRdDailyReportPageReqVO rdPageReqVO = new IotRdDailyReportPageReqVO();
|
|
|
+ rdPageReqVO.setDeptId(163l);
|
|
|
+ rdPageReqVO.setCreateTime(new LocalDateTime[]{createTimeStart, createTimeEnd});
|
|
|
+ List<IotRdDailyReportStatisticsRespVO> rdTotalWorkloads = iotRdDailyReportService.totalWorkload(rdPageReqVO);
|
|
|
+ if (CollUtil.isNotEmpty(rdTotalWorkloads)) {
|
|
|
+ for (IotRdDailyReportStatisticsRespVO rdTotalWorkload : rdTotalWorkloads) {
|
|
|
+ if ("utilizationRate".equals(rdTotalWorkload.getDeptName())) {
|
|
|
+ BigDecimal rdUtilization = rdTotalWorkload.getUtilizationRate();
|
|
|
+ BigDecimal percent = rdUtilization.multiply(new BigDecimal("100"))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ rdDeviceUtilization = percent + " %";
|
|
|
+ }
|
|
|
+ if ("reportCount".equals(rdTotalWorkload.getDeptName())) {
|
|
|
+ rdReportCount = rdTotalWorkload.getUtilizationRate();
|
|
|
+ }
|
|
|
+ if ("teamDeptIds".equals(rdTotalWorkload.getDeptName())) {
|
|
|
+ rdTeamDeptIds = rdTotalWorkload.getUtilizationRate();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询瑞都前一天日期所在的月度日报列表
|
|
|
+ IotRdDailyReportPageReqVO monthReqVO = new IotRdDailyReportPageReqVO();
|
|
|
+ monthReqVO.setDeptId(163l);
|
|
|
+ monthReqVO.setCreateTime(new LocalDateTime[]{monthStart, createTimeEnd});
|
|
|
+ monthReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ PageResult<IotRdDailyReportDO> monthPageReports = iotRdDailyReportService.getIotRdDailyReportPage(monthReqVO);
|
|
|
+ List<IotRdDailyReportDO> monthDailyReports = monthPageReports.getList();
|
|
|
+ // 累计 段数 累计施工-层
|
|
|
+ BigDecimal monthTotalCumulativeWorkingLayers = BigDecimal.ZERO;
|
|
|
+ // 月累计完工井
|
|
|
+ Set<Long> monthCompleteTaskIds = new HashSet<>();
|
|
|
+ if (CollUtil.isNotEmpty(monthDailyReports)) {
|
|
|
+ for (IotRdDailyReportDO report : monthDailyReports) {
|
|
|
+ // 月完工井
|
|
|
+ Long deptId = report.getDeptId();
|
|
|
+ Long taskId = report.getTaskId();
|
|
|
+ String rdStatus = report.getRdStatus();
|
|
|
+ if (ObjUtil.isNotEmpty(deptId) && ObjUtil.isNotEmpty(taskId) && lyTeamIds.contains(deptId) && "wg".equals(rdStatus)) {
|
|
|
+ monthCompleteTaskIds.add(taskId);
|
|
|
+ }
|
|
|
+ List<IotTaskAttrModelProperty> properties = report.getExtProperty();
|
|
|
+ if (CollUtil.isNotEmpty(properties)) {
|
|
|
+ for (IotTaskAttrModelProperty property : properties) {
|
|
|
+ // 工作量单位
|
|
|
+ String unit = property.getUnit();
|
|
|
+ // 工作量属性的实际值
|
|
|
+ String actualValueStr = property.getActualValue();
|
|
|
+ BigDecimal actualValue = BigDecimal.ZERO;
|
|
|
+ if (StrUtil.isNotBlank(actualValueStr)) {
|
|
|
+ try {
|
|
|
+ actualValue = new BigDecimal(actualValueStr);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ // 若字符串格式错误,默认按0处理(可根据业务调整)
|
|
|
+ actualValue = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("段数".equals(unit)) {
|
|
|
+ monthTotalCumulativeWorkingLayers = monthTotalCumulativeWorkingLayers.add(actualValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询瑞都前一天日期所在的年度日报列表
|
|
|
+ IotRdDailyReportPageReqVO yearReqVO = new IotRdDailyReportPageReqVO();
|
|
|
+ yearReqVO.setDeptId(163l);
|
|
|
+ yearReqVO.setCreateTime(new LocalDateTime[]{yearStart, createTimeEnd});
|
|
|
+ yearReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ PageResult<IotRdDailyReportDO> yearPageReports = iotRdDailyReportService.getIotRdDailyReportPage(yearReqVO);
|
|
|
+ List<IotRdDailyReportDO> yearDailyReports = yearPageReports.getList();
|
|
|
+ // 累计 段数 累计施工-层
|
|
|
+ BigDecimal yearTotalCumulativeWorkingLayers = BigDecimal.ZERO;
|
|
|
+ // 年累计完工井
|
|
|
+ Set<Long> yearCompleteTaskIds = new HashSet<>();
|
|
|
+ if (CollUtil.isNotEmpty(yearDailyReports)) {
|
|
|
+ for (IotRdDailyReportDO report : yearDailyReports) {
|
|
|
+ // 月完工井
|
|
|
+ Long deptId = report.getDeptId();
|
|
|
+ Long taskId = report.getTaskId();
|
|
|
+ String rdStatus = report.getRdStatus();
|
|
|
+ if (ObjUtil.isNotEmpty(deptId) && ObjUtil.isNotEmpty(taskId) && lyTeamIds.contains(deptId) && "wg".equals(rdStatus)) {
|
|
|
+ yearCompleteTaskIds.add(taskId);
|
|
|
+ }
|
|
|
+ List<IotTaskAttrModelProperty> properties = report.getExtProperty();
|
|
|
+ if (CollUtil.isNotEmpty(properties)) {
|
|
|
+ for (IotTaskAttrModelProperty property : properties) {
|
|
|
+ // 工作量单位
|
|
|
+ String unit = property.getUnit();
|
|
|
+ // 工作量属性的实际值
|
|
|
+ String actualValueStr = property.getActualValue();
|
|
|
+ BigDecimal actualValue = BigDecimal.ZERO;
|
|
|
+ if (StrUtil.isNotBlank(actualValueStr)) {
|
|
|
+ try {
|
|
|
+ actualValue = new BigDecimal(actualValueStr);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ // 若字符串格式错误,默认按0处理(可根据业务调整)
|
|
|
+ actualValue = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("段数".equals(unit)) {
|
|
|
+ yearTotalCumulativeWorkingLayers = yearTotalCumulativeWorkingLayers.add(actualValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询 5#公司 昨天的日报列表
|
|
|
+ IotFiveDailyReportPageReqVO fiveReqVO = new IotFiveDailyReportPageReqVO();
|
|
|
+ fiveReqVO.setDeptId(388l);
|
|
|
+ fiveReqVO.setCreateTime(new LocalDateTime[]{createTimeStart, createTimeEnd});
|
|
|
+ fiveReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ PageResult<IotFiveDailyReportDO> pageFiveReports = iotFiveDailyReportService.getIotFiveDailyReportPage(fiveReqVO);
|
|
|
+ List<IotFiveDailyReportDO> fiveReports = pageFiveReports.getList();
|
|
|
+ // 5号公司日压裂层
|
|
|
+ BigDecimal fiveDaySumLayers = BigDecimal.ZERO;
|
|
|
+ // 5号公司 日设备利用率
|
|
|
+ String fiveDeviceUtilization = StrUtil.EMPTY;
|
|
|
+ // 日报累计施工设备数量
|
|
|
+ BigDecimal fiveWorkDeviceNum = BigDecimal.ZERO;
|
|
|
+ // 日报累计主设备数量
|
|
|
+ BigDecimal fiveMainDeviceNum = BigDecimal.ZERO;
|
|
|
+ if (CollUtil.isNotEmpty(fiveReports)) {
|
|
|
+ // 求和:所有日报压裂层 单位:层
|
|
|
+ fiveDaySumLayers = fiveReports.stream()
|
|
|
+ .map(IotFiveDailyReportDO::getDailyWorkingLayers)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ // 求和:所有日报施工设备数量
|
|
|
+ fiveWorkDeviceNum = fiveReports.stream()
|
|
|
+ .map(IotFiveDailyReportDO::getWokDeviceNum)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ // 求和:所有日报主设备数量
|
|
|
+ fiveMainDeviceNum = fiveReports.stream()
|
|
|
+ .map(IotFiveDailyReportDO::getMainDeviceNum)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ // 计算5#公司设备利用率
|
|
|
+ if (fiveMainDeviceNum.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal fiveDeviceUtilizationRate = fiveWorkDeviceNum.divide(fiveMainDeviceNum, 4, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal percent = fiveDeviceUtilizationRate.multiply(new BigDecimal("100"))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ fiveDeviceUtilization = percent + " %";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询 5#公司 昨天所属月份的日报列表
|
|
|
+ IotFiveDailyReportPageReqVO fiveMonthReqVO = new IotFiveDailyReportPageReqVO();
|
|
|
+ fiveMonthReqVO.setDeptId(388l);
|
|
|
+ fiveMonthReqVO.setCreateTime(new LocalDateTime[]{monthStart, createTimeEnd});
|
|
|
+ fiveMonthReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ PageResult<IotFiveDailyReportDO> pageMonthFiveReports = iotFiveDailyReportService.getIotFiveDailyReportPage(fiveMonthReqVO);
|
|
|
+ List<IotFiveDailyReportDO> fiveMonthReports = pageMonthFiveReports.getList();
|
|
|
+ // 5号公司月完工井
|
|
|
+ BigDecimal fiveMonthCompleteWells = BigDecimal.ZERO;
|
|
|
+ Set<Long> fiveMonthCompleteTaskIds = new HashSet<>();
|
|
|
+ if (CollUtil.isNotEmpty(fiveMonthReports)) {
|
|
|
+ fiveMonthReports.forEach(report -> {
|
|
|
+ Long taskId = report.getTaskId();
|
|
|
+ String fiveStatus = report.getFiveStatus();
|
|
|
+ if (ObjUtil.isNotEmpty(taskId) && "wg".equals(fiveStatus)) {
|
|
|
+ fiveMonthCompleteTaskIds.add(taskId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询 5#公司 昨天所属年份的日报列表
|
|
|
+ IotFiveDailyReportPageReqVO fiveYearReqVO = new IotFiveDailyReportPageReqVO();
|
|
|
+ fiveYearReqVO.setDeptId(388l);
|
|
|
+ fiveYearReqVO.setCreateTime(new LocalDateTime[]{yearStart, createTimeEnd});
|
|
|
+ fiveYearReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ PageResult<IotFiveDailyReportDO> pageYearFiveReports = iotFiveDailyReportService.getIotFiveDailyReportPage(fiveYearReqVO);
|
|
|
+ List<IotFiveDailyReportDO> fiveYearReports = pageYearFiveReports.getList();
|
|
|
+ // 5号公司 年完工井
|
|
|
+ BigDecimal fiveYearCompleteWells = BigDecimal.ZERO;
|
|
|
+ Set<Long> fiveYearCompleteTaskIds = new HashSet<>();
|
|
|
+ if (CollUtil.isNotEmpty(fiveYearReports)) {
|
|
|
+ fiveYearReports.forEach(report -> {
|
|
|
+ Long taskId = report.getTaskId();
|
|
|
+ String fiveStatus = report.getFiveStatus();
|
|
|
+ if (ObjUtil.isNotEmpty(taskId) && "wg".equals(fiveStatus)) {
|
|
|
+ fiveYearCompleteTaskIds.add(taskId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置集团的设备利用率总和 各公司 日报数量/主设备数量
|
|
|
+ BigDecimal totalReportCount = rhReportCount.add(ryReportCount).add(rdReportCount).add(fiveWorkDeviceNum);
|
|
|
+ BigDecimal totalMainDevices = rhTeamDeptIds.add(ryTeamDeptIds).add(rdTeamDeptIds).add(fiveMainDeviceNum);
|
|
|
+ String totalUtilization = StrUtil.EMPTY;
|
|
|
+ if (totalMainDevices.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal totalUtilizationRate = totalReportCount.divide(totalMainDevices, 4, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal percent = totalUtilizationRate.multiply(new BigDecimal("100"))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ totalUtilization = percent + " %";
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 组装推送消息 ====================
|
|
|
+
|
|
|
+ StringBuilder finalMsgBuilder = new StringBuilder();
|
|
|
+ finalMsgBuilder.append("总设备利用率:").append(totalUtilization).append(" \n");
|
|
|
+ finalMsgBuilder.append("═ ═ ═ ═ ═ ═ ═ ═ \n");
|
|
|
+ finalMsgBuilder.append("公司:瑞恒兴域 \n");
|
|
|
+ finalMsgBuilder.append("日注气量:").append(daySumWanGas).append(" 万方 \n");
|
|
|
+ finalMsgBuilder.append("月注气量:").append(monthSumWanGas).append(" 万方 \n");
|
|
|
+ finalMsgBuilder.append("年注气量:").append(yearSumWanGas).append(" 万方 \n");
|
|
|
+ finalMsgBuilder.append("设备利用率:").append(rhDeviceUtilization).append(" \n");
|
|
|
+ finalMsgBuilder.append("═ ═ ═ ═ ═ ═ ═ ═ \n");
|
|
|
+ finalMsgBuilder.append("公司:瑞鹰国际 \n");
|
|
|
+ finalMsgBuilder.append("日钻进尺:").append(daySumFootage).append(" 米 \n");
|
|
|
+ finalMsgBuilder.append("月钻进尺:").append(monthSumFootage).append(" 米 \n");
|
|
|
+ finalMsgBuilder.append("年钻进尺:").append(yearSumFootage).append(" 米 \n");
|
|
|
+ finalMsgBuilder.append("日施工井:").append(dayConstructWell).append(" 井 \n");
|
|
|
+ finalMsgBuilder.append("月完工井:").append(monthCompleteWell).append(" 井 \n");
|
|
|
+ finalMsgBuilder.append("年完工井:").append(yearCompleteWell).append(" 井 \n");
|
|
|
+ finalMsgBuilder.append("设备利用率:").append(ryDeviceUtilization).append(" \n");
|
|
|
+ finalMsgBuilder.append("═ ═ ═ ═ ═ ═ ═ ═ \n");
|
|
|
+ finalMsgBuilder.append("公司:四川瑞都 \n");
|
|
|
+ finalMsgBuilder.append("日压裂层:").append(totalCumulativeWorkingLayers).append(" 层 \n");
|
|
|
+ finalMsgBuilder.append("月压裂层:").append(monthTotalCumulativeWorkingLayers).append(" 层 \n");
|
|
|
+ finalMsgBuilder.append("年压裂层:").append(yearTotalCumulativeWorkingLayers).append(" 层 \n");
|
|
|
+ finalMsgBuilder.append("日施工井:").append(taskIds.size()).append(" 井 \n");
|
|
|
+ finalMsgBuilder.append("月完工井:").append(monthCompleteTaskIds.size()).append(" 井 \n");
|
|
|
+ finalMsgBuilder.append("年完工井:").append(yearCompleteTaskIds.size()).append(" 井 \n");
|
|
|
+ finalMsgBuilder.append("设备利用率:").append(rdDeviceUtilization).append(" \n");
|
|
|
+ finalMsgBuilder.append("═ ═ ═ ═ ═ ═ ═ ═ \n");
|
|
|
+ finalMsgBuilder.append("公司:5#项目公司 \n");
|
|
|
+ finalMsgBuilder.append("日压裂层:").append(fiveDaySumLayers).append(" 层 \n");
|
|
|
+ finalMsgBuilder.append("月完工井:").append(fiveMonthCompleteTaskIds.size()).append(" 井 \n");
|
|
|
+ finalMsgBuilder.append("年完工井:").append(fiveYearCompleteTaskIds.size()).append(" 井 \n");
|
|
|
+ finalMsgBuilder.append("设备利用率:").append(fiveDeviceUtilization).append(" \n");
|
|
|
+ finalMsgBuilder.append("═ ═ ═ ═ ═ ═ ═ ═ \n");
|
|
|
+
|
|
|
+ String finalMsgTitle = finalMsgBuilder.toString();
|
|
|
+
|
|
|
+ Set<Long> deptIds = new HashSet<>();
|
|
|
+ Set<Long> userIds = new HashSet<>();
|
|
|
+
|
|
|
+ // 查询 集团 156l 下具有 集团生产概况推送 角色的人员
|
|
|
+ deptIds.add(156l);
|
|
|
+ List<AdminUserDO> companyUsers = adminUserService.getUserListByDeptIds(deptIds);
|
|
|
+ if (CollUtil.isNotEmpty(companyUsers)) {
|
|
|
+ companyUsers.forEach(user -> {
|
|
|
+ userIds.add(user.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将当前日期的前一天转换成 long 类型的数字
|
|
|
+ Long timeStamp = cn.hutool.core.date.DateUtil.toInstant(yesterday).toEpochMilli();
|
|
|
+
|
|
|
+ RoleDO role = roleService.getRoleByCode("集团生产概况推送");
|
|
|
+ if (ObjUtil.isNotEmpty(role)) {
|
|
|
+ Set<Long> roleIds = new HashSet<>();
|
|
|
+ roleIds.add(role.getId());
|
|
|
+ List<UserRoleDO> userRoles = userRoleMapper.selectListByRoleIds(roleIds);
|
|
|
+ if (CollUtil.isNotEmpty(userRoles)) {
|
|
|
+ // 提取有审批角色的所有用户ID(去重+空值过滤)
|
|
|
+ Set<Long> roleUserIds = userRoles.stream()
|
|
|
+ .map(UserRoleDO::getUserId)
|
|
|
+ .filter(Objects::nonNull) // 过滤空userId
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ // 计算两个集合的交集,得到最终目标用户ID
|
|
|
+ Set<Long> targetUserIds = userIds.stream()
|
|
|
+ .filter(roleUserIds::contains)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ if (CollUtil.isNotEmpty(targetUserIds)) {
|
|
|
+ Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(targetUserIds);
|
|
|
+ // 给多个用户发送 相同 的 提醒消息
|
|
|
+ if (CollUtil.isNotEmpty(users)) {
|
|
|
+ // 生成消息提醒 标题内容
|
|
|
+ CountDownLatch latch = new CountDownLatch(users.size());
|
|
|
+ users.forEach((userId, user) -> {
|
|
|
+ pmsThreadPoolTaskExecutor.execute(() -> {
|
|
|
+ try {
|
|
|
+ String mobile = user.getMobile();
|
|
|
+ // 没有手机号也发送站内信消息
|
|
|
+ if (StrUtil.isNotBlank(finalMsgTitle)) {
|
|
|
+ pmsMessage.sendMessage(timeStamp, finalMsgTitle, PmsConstants.YF_PRODUCTION_STATUS,
|
|
|
+ userId, mobile);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ latch.countDown();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return "创建成功";
|
|
|
+ }
|
|
|
+}
|