Browse Source

1、接口调定时任务执行

2、测试环境mysql连接加参数
develop
bobol 7 months ago
parent
commit
3f10cef01e
  1. 2
      lzbi-admin/src/main/java/com/lzbi/RuoYiApplication.java
  2. 2
      lzbi-admin/src/main/resources/application-test.yml
  3. 5
      lzbi-module/src/main/java/com/lzbi/draft/service/DcBusiParamBillMasterService.java
  4. 15
      lzbi-module/src/main/java/com/lzbi/task/TaskParamDfratProcess.java
  5. 19
      lzbi-module/src/main/java/com/lzbi/task/TaskWorkParamRead.java
  6. 6
      lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml
  7. 38
      lzbi-quartz/src/main/java/com/lzbi/quartz/controller/BizJobController.java
  8. 16
      lzbi-quartz/src/main/java/com/lzbi/quartz/service/IBizJobService.java
  9. 39
      lzbi-quartz/src/main/java/com/lzbi/quartz/service/impl/BizJobServiceImpl.java
  10. 4
      lzbi-quartz/src/main/java/com/lzbi/quartz/task/SyncIotSystemTask.java

2
lzbi-admin/src/main/java/com/lzbi/RuoYiApplication.java

@ -5,12 +5,14 @@ import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.scheduling.annotation.EnableAsync;
/**
* 启动程序
*
* @author ruoyi
*/
@EnableAsync
@EnableKnife4j
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class })
public class RuoYiApplication

2
lzbi-admin/src/main/resources/application-test.yml

@ -76,7 +76,7 @@ spring:
datasource:
# 主库数据源
master:
url: jdbc:mysql://10.10.10.56:13306/lzdc_bi_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
url: jdbc:mysql://10.10.10.56:13306/lzdc_bi_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&keepAlive=true&autoReconnect=true&autoReconnectForPools=true&connectTimeout=30000&socketTimeout=60000
username: luenmei
password: 123456
# # 计费数据库

5
lzbi-module/src/main/java/com/lzbi/draft/service/DcBusiParamBillMasterService.java

@ -5,6 +5,7 @@ import java.util.List;
import com.lzbi.draft.domain.DcBusiParamBillMaster;
import com.lzbi.draft.domain.DcBusiParamBillSub;
import com.lzbi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.lzbi.common.utils.DateUtils;
@ -21,6 +22,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class DcBusiParamBillMasterService extends ServiceImpl<DcBusiParamBillMasterMapper, DcBusiParamBillMaster> implements IService<DcBusiParamBillMaster>
{
@Autowired
private DcBusiParamBillSubService dcBusiParamBillSubService;
/**
* 查询参数采集录入单据主
@ -123,7 +126,7 @@ public class DcBusiParamBillMasterService extends ServiceImpl<DcBusiParamBillMas
}
if (list.size() > 0)
{
baseMapper.batchDcBusiParamBillSubDao(list);
dcBusiParamBillSubService.saveBatch(list);
}
}
}

15
lzbi-module/src/main/java/com/lzbi/task/TaskParamDfratProcess.java

@ -46,8 +46,7 @@ public class TaskParamDfratProcess {
List<DcBusiParamBillSub> dcBusiParamBillSubs = dcBusiParamBillSubService.selectByVo(billSub);
if (CollectionUtils.isEmpty(dcBusiParamBillSubs)) {
log.error("单据无数据");
return;
}
} else {
List<String> assetCodeList = dcBusiParamBillSubs.stream().map(DcBusiParamBillSub::getAssetCode).collect(Collectors.toList());
List<String> paramCodeList = dcBusiParamBillSubs.stream().map(DcBusiParamBillSub::getParamCode).collect(Collectors.toList());
List<String> paramFieldCodeList = dcBusiParamBillSubs.stream().map(DcBusiParamBillSub::getFieldCode).collect(Collectors.toList());
@ -60,7 +59,7 @@ public class TaskParamDfratProcess {
List<DcBusiParamDraftDay> paramDraftDayList = dBusiParamDraftDayService.list(queryWrapper);
Map<String, DcBusiParamDraftDay> paramDraftDayMap;
if (CollectionUtils.isEmpty(paramDraftDayList)) {
log.info("底稿表无数据");
log.info("底稿表无数据,日期为:【{}】", billMasterDao.getBillIncomeDate());
paramDraftDayMap = new HashMap<>();
} else {
paramDraftDayMap = paramDraftDayList.stream().collect(Collectors.toMap(gp -> gp.getAssetCode() + ":" + gp.getParamCode() + ":" + gp.getParamFieldCode() + ":" + gp.getCountDate(), gp -> gp));
@ -106,13 +105,19 @@ public class TaskParamDfratProcess {
dBusiParamDraftDayService.updateBatchById(updateDataList);
}
}
billMasterDao.setCheckStatus("1");
dcBusiParamBillMasterService.updateById(billMasterDao);
}
public void doBills() {
DcBusiParamBillMaster dcBusiParamBillMasterDao = new DcBusiParamBillMaster();
dcBusiParamBillMasterDao.setCheckStatus("0");
List<DcBusiParamBillMaster> dcBusiParamBillMasterDaos = dcBusiParamBillMasterService.selectDcBusiParamBillMasterDaoList(dcBusiParamBillMasterDao);
dcBusiParamBillMasterDaos.forEach(item -> {
log.info("一共有【{}】个单据需要审核", dcBusiParamBillMasterDaos.size());
for (int i = 0, len = dcBusiParamBillMasterDaos.size(); i < len; i++) {
DcBusiParamBillMaster item = dcBusiParamBillMasterDaos.get(i);
log.info("正在处理日期为:【{}】的单据", item.getBillIncomeDate());
doBill(item);
});
}
}
}

19
lzbi-module/src/main/java/com/lzbi/task/TaskWorkParamRead.java

@ -20,6 +20,7 @@ import com.lzbi.task.service.DcBusiWorkReadLogService;
import com.lzbi.task.service.WorkParamReadService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
@ -112,6 +113,17 @@ public class TaskWorkParamRead {
private final String SOURCE = "work";
public int createParamBill(String inComeDate) {
List<DcBusiParamBillSub> billSub = new ArrayList<>();
DcBusiWorkReadConfig dwrc = new DcBusiWorkReadConfig();
dwrc.setGoalSource(SOURCE);
List<DcBusiWorkReadConfig> dcBusiWorkReadConfigs = dcBusiWorkReadConfigService.selectDcBusiWorkReadConfigList(dwrc);
Set<String> pcl = dcBusiWorkReadConfigs.parallelStream().filter(o -> StringUtils.isNotEmpty(o.getGoalParamCode())).map(DcBusiWorkReadConfig::getGoalParamCode).collect(Collectors.toSet());
// Set<String> dcl = dcBusiWorkReadConfigs.parallelStream().filter(o -> StringUtils.isNotEmpty(o.getGoalParamExt1())).map(DcBusiWorkReadConfig::getGoalParamExt1).collect(Collectors.toSet());
List<DcBusiWorkReadLog> listRow = getWorkReadVo(inComeDate, pcl);
if (CollectionUtils.isEmpty(listRow)) {
return 0;
}
DcBusiCoderuleConfigDao ruleIdByBusicode = dcBaseCoderuleDefineService.getRuleIdByBusicode(BUSICODE);
DcBaseCoderuleDefineDao ruleDao = dcBaseCoderuleDefineService.selectDcBaseCoderuleDefineDaoById(ruleIdByBusicode.getRuleId());
DcBusiParamBillMaster billm = new DcBusiParamBillMaster();
@ -126,13 +138,6 @@ public class TaskWorkParamRead {
billm.setBillType("2");
billm.setCheckType("1");
billm.setCheckStatus("0");
List<DcBusiParamBillSub> billSub = new ArrayList<>();
DcBusiWorkReadConfig dwrc = new DcBusiWorkReadConfig();
dwrc.setGoalSource(SOURCE);
List<DcBusiWorkReadConfig> dcBusiWorkReadConfigs = dcBusiWorkReadConfigService.selectDcBusiWorkReadConfigList(dwrc);
Set<String> pcl = dcBusiWorkReadConfigs.parallelStream().filter(o -> StringUtils.isNotEmpty(o.getGoalParamCode())).map(DcBusiWorkReadConfig::getGoalParamCode).collect(Collectors.toSet());
// Set<String> dcl = dcBusiWorkReadConfigs.parallelStream().filter(o -> StringUtils.isNotEmpty(o.getGoalParamExt1())).map(DcBusiWorkReadConfig::getGoalParamExt1).collect(Collectors.toSet());
List<DcBusiWorkReadLog> listRow = getWorkReadVo(inComeDate, pcl);
final String billNo_c = billNo;
listRow.forEach(item -> {
Optional<DcBusiWorkReadConfig> find = dcBusiWorkReadConfigs.parallelStream().filter(info -> {

6
lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml

@ -26,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
first(param_value_num, timestamp_key) AS firstVal,
last(param_value_num,timestamp_key) AS lastVal,
min(param_value_num) AS minVal
FROM dc_base_log_history_level1 AS his
FROM dc_base_log_history_level3 AS his
<where>
timestamp_key BETWEEN to_timestamp(#{beginTime},'yyyy-MM-dd hh24:mi:ss') and
to_timestamp(#{endTime},'yyyy-MM-dd hh24:mi:ss')
@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SUM ( CASE WHEN t1.param_value_num > 0.00 THEN 1 ELSE 0 END ) AS countsz,
LAST ( t1.param_value_num, timestamp_key ) AS lastVal
FROM
dc_base_log_history_level1 t1
dc_base_log_history_level3 t1
INNER JOIN dc_base_device_param t2 ON t1.param_code = t2.param_code
AND t2.param_model_id IN
<foreach item="item" index="index" collection="paramCodes" open="(" close=")" separator=",">
@ -113,7 +113,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SUM ( CASE WHEN t1.param_value_num > 0.00 THEN 1 ELSE 0 END ) AS countsz,
LAST ( t1.param_value_num, timestamp_key ) AS lastVal
FROM
dc_base_log_history_level1 t1
dc_base_log_history_level3 t1
INNER JOIN dc_base_device_param t2 ON t1.param_code = t2.param_code
AND t2.param_model_id IN
<foreach item="item" index="index" collection="paramCodes" open="(" close=")" separator=",">

38
lzbi-quartz/src/main/java/com/lzbi/quartz/controller/BizJobController.java

@ -0,0 +1,38 @@
package com.lzbi.quartz.controller;
import com.lzbi.common.core.domain.AjaxResult;
import com.lzbi.quartz.service.IBizJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/bizJob")
public class BizJobController {
@Autowired
private IBizJobService bizJobService;
/**
* 执行同步iot数据任务
* @param startDate
* @param endDate
* @return
*/
@GetMapping("/syncIotSystemTask")
public AjaxResult syncIotSystemTask(String startDate, String endDate) {
bizJobService.syncIotSystemTask(startDate, endDate);
return AjaxResult.success();
}
/**
* 执行自动审核任务
* @return
*/
@GetMapping("/autoAuditTask")
public AjaxResult autoAuditTask() {
bizJobService.autoAuditTask();
return AjaxResult.success();
}
}

16
lzbi-quartz/src/main/java/com/lzbi/quartz/service/IBizJobService.java

@ -0,0 +1,16 @@
package com.lzbi.quartz.service;
public interface IBizJobService {
/**
* 执行同步iot数据
* @param startDateStr
* @param endDateStr
*/
void syncIotSystemTask(String startDateStr, String endDateStr);
/**
* 执行自动审核任务
*/
void autoAuditTask();
}

39
lzbi-quartz/src/main/java/com/lzbi/quartz/service/impl/BizJobServiceImpl.java

@ -0,0 +1,39 @@
package com.lzbi.quartz.service.impl;
import com.lzbi.quartz.service.IBizJobService;
import com.lzbi.quartz.task.AutoAuditTask;
import com.lzbi.quartz.task.SyncIotSystemTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@Service
public class BizJobServiceImpl implements IBizJobService {
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@Autowired
private SyncIotSystemTask syncIotSystemTask;
@Autowired
private AutoAuditTask autoAuditTask;
@Async
@Override
public void syncIotSystemTask(String startDateStr, String endDateStr) {
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
for (LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER); startDate.isBefore(endDate) ; startDate = startDate.plusDays(1)) {
syncIotSystemTask.syncIotParams(false, startDate.format(DATE_FORMATTER));
}
}
@Async
@Override
public void autoAuditTask() {
autoAuditTask.auditParamsBill();
}
}

4
lzbi-quartz/src/main/java/com/lzbi/quartz/task/SyncIotSystemTask.java

@ -21,8 +21,8 @@ public class SyncIotSystemTask {
* @param dateStr 同步数据的日期字符串
*/
public void syncIotParams(Boolean ifLog, String dateStr) {
log.info("===========同步IOT参数开始,是否存入日志:{}============", ifLog);
log.info("===========同步IOT参数开始,是否存入日志:{},日期:{}============", ifLog, dateStr);
taskWorkParamRead.runTask(ifLog, dateStr);
log.info("===========同步IOT参数结束,是否存入日志:{}============", ifLog);
log.info("===========同步IOT参数结束,是否存入日志:{},日期:{}============", ifLog, dateStr);
}
}

Loading…
Cancel
Save