From ad345a8690e1fbbaaf1cbdef600350d10116cbfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Tue, 18 Jul 2023 10:21:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=A4=E7=A5=A8=E7=BB=9F=E8=AE=A1=E5=88=86?= =?UTF-8?q?=E6=9E=90=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FirstWorkTicketController.java | 2 + .../twoTicket/scheduled/TicketCountScheduled.java | 55 +++++++++++++++++ .../twoTicket/service/TicketCountService.java | 7 +++ .../service/impl/TicketCountServiceImpl.java | 72 ++++++++++++++++++++++ .../ticket/src/main/resources/application.yml | 12 +++- 5 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/scheduled/TicketCountScheduled.java diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java index e68946b..a9a142c 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java @@ -19,6 +19,8 @@ import org.springblade.core.tool.api.R; import org.springblade.flow.core.vo.ComleteTask; import org.springframework.web.bind.annotation.*; +import java.time.YearMonth; + /** * @author hx */ diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/scheduled/TicketCountScheduled.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/scheduled/TicketCountScheduled.java new file mode 100644 index 0000000..fa059a4 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/scheduled/TicketCountScheduled.java @@ -0,0 +1,55 @@ +package com.hnac.hzims.ticket.twoTicket.scheduled; + +import com.hnac.hzims.ticket.twoTicket.service.TicketCountService; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.Func; +import org.springframework.stereotype.Component; + +import java.time.Duration; +import java.time.Instant; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/7/17 17:19 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class TicketCountScheduled { + + private final TicketCountService ticketCountService; + + + + /** + * 集中监控数据处理 + * + * @return ReturnT + */ + @XxlJob("getTicketCount") + public ReturnT getTicketCount(String param) { + Instant start = Instant.now(); + if (Func.isBlank(param)) { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM"); + YearMonth yearMonth = YearMonth.now(); + YearMonth newYearMonth = yearMonth.minusMonths(1); + param = newYearMonth.format(dateTimeFormatter); + } + ticketCountService.allLoadMonthReport(param); + + Duration between = Duration.between(start, Instant.now()); + log.info("================================================================"); + log.info("耗时: " + (between.getSeconds()) + "秒"); + log.info("耗时: " + (between.toMillis()) + "毫秒"); + log.info("================================================================"); + log.info("两票生成月报统计成功"); + return new ReturnT<>("SUCCESS"); + } +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketCountService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketCountService.java index 02f9562..8d10883 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketCountService.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketCountService.java @@ -36,4 +36,11 @@ public interface TicketCountService extends BaseService { * @param response */ void exportTicketCount(String dateTime, HttpServletResponse response); + + + + /** + * 定时任务两票生成月报统计 + */ + void allLoadMonthReport(String dateTime); } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketCountServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketCountServiceImpl.java index 06e48ed..950a486 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketCountServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketCountServiceImpl.java @@ -20,6 +20,7 @@ import com.hnac.hzims.ticket.twoTicket.vo.ticket.TicketCountResponseVo; import com.hnac.hzims.ticket.twoTicket.vo.ticket.TicketCountVo; import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; import com.hnac.hzims.ticket.workTicket.service.IWorkTicketInfoService; +import io.micrometer.core.instrument.binder.BaseUnits; import jodd.util.ObjectUtil; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -35,7 +36,9 @@ import org.springblade.core.secure.BladeUser; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; @@ -76,6 +79,7 @@ public class TicketCountServiceImpl extends BaseServiceImpl> allUserList = userClient.getAllUserList("200000"); + if (!allUserList.isSuccess()) { + log.error("获取不到数据"); + return; + } + List userList = allUserList.getData(); + + for (User user : userList) { + BladeUser bladeUser = new BladeUser(); + BeanUtils.copyProperties(user, bladeUser); + bladeUser.setUserId(user.getId()); + List createDept = userClient.getDataScope(bladeUser.getUserId()); + //根据月份查询统计的数据 + CompletableFuture> ticketCountsCompletableFuture = CompletableFuture.supplyAsync(() -> { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(TicketCount::getDateTime, dateTime); + List ticketCounts = baseMapper.selectList(queryWrapper); + return ticketCounts; + }, executor); + + //第一种工作票 + CompletableFuture oneTicketCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> { + //查询第一种工作票 + List ticketCountList = getTicketCountList(createDept, items, "6", dateTime, bladeUser); + if (CollectionUtils.isNotEmpty(ticketCountList)) { + this.saveBatch(ticketCountList); + } + }, executor); + //第二种工作票 + CompletableFuture twoTicketCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> { + //查询第一种工作票 + List ticketCountList = getTicketCountList(createDept, items, "7", dateTime, bladeUser); + if (CollectionUtils.isNotEmpty(ticketCountList)) { + this.saveBatch(ticketCountList); + } + }, executor); + //水力机械工作票 + CompletableFuture threeTicketCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> { + //查询第一种工作票 + List ticketCountList = getTicketCountList(createDept, items, "8", dateTime, bladeUser); + if (CollectionUtils.isNotEmpty(ticketCountList)) { + this.saveBatch(ticketCountList); + } + }, executor); + //操作票 + CompletableFuture standardCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> { + //操作票 + List ticketCountList = getStandardTicketCountList(createDept, items, "3", dateTime, bladeUser); + if (CollectionUtils.isNotEmpty(ticketCountList)) { + this.saveBatch(ticketCountList); + } + + }, executor); + //执行线程操作 + CompletableFuture.allOf(ticketCountsCompletableFuture, oneTicketCompletableFuture, twoTicketCompletableFuture + , threeTicketCompletableFuture, standardCompletableFuture).get(); + } + } + /** * 列表封装 diff --git a/hzims-service/ticket/src/main/resources/application.yml b/hzims-service/ticket/src/main/resources/application.yml index 1de0a34..2af9d8e 100644 --- a/hzims-service/ticket/src/main/resources/application.yml +++ b/hzims-service/ticket/src/main/resources/application.yml @@ -57,5 +57,15 @@ swagger: # segment: 工作票延期 - +xxl: + job: + accessToken: '' + admin: + addresses: http://192.168.1.20:7009/xxl-job-admin + executor: + appname: hzims-ticket + ip: 192.168.1.3 + logpath: /data/applogs/xxl-job/jobhandler + logretentiondays: -1 + port: 28601