Browse Source

两票统计分析定时任务统计

zhongwei
段飞宇 1 year ago
parent
commit
ad345a8690
  1. 2
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/FirstWorkTicketController.java
  2. 55
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/scheduled/TicketCountScheduled.java
  3. 7
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketCountService.java
  4. 72
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketCountServiceImpl.java
  5. 12
      hzims-service/ticket/src/main/resources/application.yml

2
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.springblade.flow.core.vo.ComleteTask;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.YearMonth;
/** /**
* @author hx * @author hx
*/ */

55
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<String>
*/
@XxlJob("getTicketCount")
public ReturnT<String> 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");
}
}

7
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketCountService.java

@ -36,4 +36,11 @@ public interface TicketCountService extends BaseService<TicketCount> {
* @param response * @param response
*/ */
void exportTicketCount(String dateTime, HttpServletResponse response); void exportTicketCount(String dateTime, HttpServletResponse response);
/**
* 定时任务两票生成月报统计
*/
void allLoadMonthReport(String dateTime);
} }

72
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.twoTicket.vo.ticket.TicketCountVo;
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity;
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketInfoService; import com.hnac.hzims.ticket.workTicket.service.IWorkTicketInfoService;
import io.micrometer.core.instrument.binder.BaseUnits;
import jodd.util.ObjectUtil; import jodd.util.ObjectUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
@ -35,7 +36,9 @@ import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.system.feign.ISysClient; import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -76,6 +79,7 @@ public class TicketCountServiceImpl extends BaseServiceImpl<TicketCountMapper, T
private final IStandardTicketInfoService standardTicketInfoService; private final IStandardTicketInfoService standardTicketInfoService;
/** /**
* 两票生成月报统计 * 两票生成月报统计
* *
@ -207,6 +211,74 @@ public class TicketCountServiceImpl extends BaseServiceImpl<TicketCountMapper, T
} }
} }
/**
* 定时任务两票生成月报统计
*
* @param dateTime
*/
@SneakyThrows
@Override
public void allLoadMonthReport(String dateTime) {
//根据登录人查询所属机构及下属机构
R<List<User>> allUserList = userClient.getAllUserList("200000");
if (!allUserList.isSuccess()) {
log.error("获取不到数据");
return;
}
List<User> userList = allUserList.getData();
for (User user : userList) {
BladeUser bladeUser = new BladeUser();
BeanUtils.copyProperties(user, bladeUser);
bladeUser.setUserId(user.getId());
List<Long> createDept = userClient.getDataScope(bladeUser.getUserId());
//根据月份查询统计的数据
CompletableFuture<List<TicketCount>> ticketCountsCompletableFuture = CompletableFuture.supplyAsync(() -> {
LambdaQueryWrapper<TicketCount> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TicketCount::getDateTime, dateTime);
List<TicketCount> ticketCounts = baseMapper.selectList(queryWrapper);
return ticketCounts;
}, executor);
//第一种工作票
CompletableFuture<Void> oneTicketCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> {
//查询第一种工作票
List<TicketCount> ticketCountList = getTicketCountList(createDept, items, "6", dateTime, bladeUser);
if (CollectionUtils.isNotEmpty(ticketCountList)) {
this.saveBatch(ticketCountList);
}
}, executor);
//第二种工作票
CompletableFuture<Void> twoTicketCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> {
//查询第一种工作票
List<TicketCount> ticketCountList = getTicketCountList(createDept, items, "7", dateTime, bladeUser);
if (CollectionUtils.isNotEmpty(ticketCountList)) {
this.saveBatch(ticketCountList);
}
}, executor);
//水力机械工作票
CompletableFuture<Void> threeTicketCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> {
//查询第一种工作票
List<TicketCount> ticketCountList = getTicketCountList(createDept, items, "8", dateTime, bladeUser);
if (CollectionUtils.isNotEmpty(ticketCountList)) {
this.saveBatch(ticketCountList);
}
}, executor);
//操作票
CompletableFuture<Void> standardCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> {
//操作票
List<TicketCount> ticketCountList = getStandardTicketCountList(createDept, items, "3", dateTime, bladeUser);
if (CollectionUtils.isNotEmpty(ticketCountList)) {
this.saveBatch(ticketCountList);
}
}, executor);
//执行线程操作
CompletableFuture.allOf(ticketCountsCompletableFuture, oneTicketCompletableFuture, twoTicketCompletableFuture
, threeTicketCompletableFuture, standardCompletableFuture).get();
}
}
/** /**
* 列表封装 * 列表封装

12
hzims-service/ticket/src/main/resources/application.yml

@ -57,5 +57,15 @@ swagger:
# segment: 工作票延期 # 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

Loading…
Cancel
Save